@openai/codex-security 0.9.1 → 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 (387) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +2 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/artifact-storage.md +1 -1
  15. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  16. package/_bundled_plugin/references/core-scan.md +5 -42
  17. package/_bundled_plugin/references/final-report.md +1 -1
  18. package/_bundled_plugin/references/focused-investigator.md +13 -0
  19. package/_bundled_plugin/references/scan-prologue.md +2 -2
  20. package/_bundled_plugin/references/scan-runtime.md +4 -2
  21. package/_bundled_plugin/references/security-guidance.md +14 -1
  22. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  23. package/_bundled_plugin/scripts/deep_scan_workbench.py +29 -12
  24. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -3
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  30. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  31. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  32. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  33. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  34. package/_bundled_plugin/scripts/workbench_db.py +244 -217
  35. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  36. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  37. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  38. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  39. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +281 -119
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +143 -9
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  44. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  45. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_target.py +471 -84
  47. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  48. package/_bundled_plugin/shared/workbench-history-repairs.json +60 -14
  49. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  50. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  51. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -160
  52. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  53. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  54. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  55. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  56. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  57. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  58. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  60. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  61. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  62. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  63. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  64. package/bin/codex-security.mjs +2 -2
  65. package/dist/api.d.ts +6 -1
  66. package/dist/api.d.ts.map +1 -1
  67. package/dist/api.js +437 -154
  68. package/dist/api.js.map +1 -1
  69. package/dist/armorcode-findings.d.ts +9 -0
  70. package/dist/armorcode-findings.d.ts.map +1 -0
  71. package/dist/armorcode-findings.js +145 -0
  72. package/dist/armorcode-findings.js.map +1 -0
  73. package/dist/artifact-export.d.ts +2 -0
  74. package/dist/artifact-export.d.ts.map +1 -1
  75. package/dist/artifact-export.js +29 -13
  76. package/dist/artifact-export.js.map +1 -1
  77. package/dist/auth.d.ts +6 -2
  78. package/dist/auth.d.ts.map +1 -1
  79. package/dist/auth.js +33 -12
  80. package/dist/auth.js.map +1 -1
  81. package/dist/batch-cost.d.ts +18 -0
  82. package/dist/batch-cost.d.ts.map +1 -0
  83. package/dist/batch-cost.js +41 -0
  84. package/dist/batch-cost.js.map +1 -0
  85. package/dist/blackduck-findings.d.ts +1 -1
  86. package/dist/blackduck-findings.d.ts.map +1 -1
  87. package/dist/blackduck-findings.js +5 -18
  88. package/dist/blackduck-findings.js.map +1 -1
  89. package/dist/bundled-plugin.d.ts +4 -0
  90. package/dist/bundled-plugin.d.ts.map +1 -0
  91. package/dist/bundled-plugin.js +23 -0
  92. package/dist/bundled-plugin.js.map +1 -0
  93. package/dist/classify-scan-severity.d.ts +1 -1
  94. package/dist/classify-scan-severity.d.ts.map +1 -1
  95. package/dist/classify-scan-severity.js +11 -3
  96. package/dist/classify-scan-severity.js.map +1 -1
  97. package/dist/classify-severity.d.ts.map +1 -1
  98. package/dist/classify-severity.js +9 -6
  99. package/dist/classify-severity.js.map +1 -1
  100. package/dist/cli-argument.d.ts +4 -0
  101. package/dist/cli-argument.d.ts.map +1 -0
  102. package/dist/cli-argument.js +17 -0
  103. package/dist/cli-argument.js.map +1 -0
  104. package/dist/cli-help.d.ts +1 -1
  105. package/dist/cli-help.d.ts.map +1 -1
  106. package/dist/cli-help.js +71 -29
  107. package/dist/cli-help.js.map +1 -1
  108. package/dist/cli-hook.d.ts +3 -0
  109. package/dist/cli-hook.d.ts.map +1 -0
  110. package/dist/cli-hook.js +87 -0
  111. package/dist/cli-hook.js.map +1 -0
  112. package/dist/cli-integrations.d.ts +13 -0
  113. package/dist/cli-integrations.d.ts.map +1 -0
  114. package/dist/cli-integrations.js +333 -0
  115. package/dist/cli-integrations.js.map +1 -0
  116. package/dist/cli-mcp.d.ts +15 -0
  117. package/dist/cli-mcp.d.ts.map +1 -0
  118. package/dist/cli-mcp.js +178 -0
  119. package/dist/cli-mcp.js.map +1 -0
  120. package/dist/cli-token-view.d.ts +10 -0
  121. package/dist/cli-token-view.d.ts.map +1 -0
  122. package/dist/cli-token-view.js +41 -0
  123. package/dist/cli-token-view.js.map +1 -0
  124. package/dist/cli.d.ts +5 -3
  125. package/dist/cli.d.ts.map +1 -1
  126. package/dist/cli.js +1763 -894
  127. package/dist/cli.js.map +1 -1
  128. package/dist/cloud-publish.d.ts.map +1 -1
  129. package/dist/cloud-publish.js +33 -31
  130. package/dist/cloud-publish.js.map +1 -1
  131. package/dist/codex-sdk-environment.d.ts +6 -0
  132. package/dist/codex-sdk-environment.d.ts.map +1 -1
  133. package/dist/codex-sdk-environment.js +19 -0
  134. package/dist/codex-sdk-environment.js.map +1 -1
  135. package/dist/command-words.d.ts +3 -0
  136. package/dist/command-words.d.ts.map +1 -0
  137. package/dist/command-words.js +46 -0
  138. package/dist/command-words.js.map +1 -0
  139. package/dist/component-scan.d.ts +3 -1
  140. package/dist/component-scan.d.ts.map +1 -1
  141. package/dist/component-scan.js +40 -7
  142. package/dist/component-scan.js.map +1 -1
  143. package/dist/config.d.ts +1 -1
  144. package/dist/config.d.ts.map +1 -1
  145. package/dist/config.js +30 -1
  146. package/dist/config.js.map +1 -1
  147. package/dist/continuum-findings.d.ts +1 -1
  148. package/dist/continuum-findings.d.ts.map +1 -1
  149. package/dist/continuum-findings.js +93 -31
  150. package/dist/continuum-findings.js.map +1 -1
  151. package/dist/cost.d.ts.map +1 -1
  152. package/dist/cost.js +1 -45
  153. package/dist/cost.js.map +1 -1
  154. package/dist/custom-validation-prompt.d.ts +1 -1
  155. package/dist/custom-validation-prompt.d.ts.map +1 -1
  156. package/dist/custom-validation-prompt.js +29 -19
  157. package/dist/custom-validation-prompt.js.map +1 -1
  158. package/dist/deduplication/local.d.ts +3 -1
  159. package/dist/deduplication/local.d.ts.map +1 -1
  160. package/dist/deduplication/local.js +8 -1
  161. package/dist/deduplication/local.js.map +1 -1
  162. package/dist/deduplication/refusal.d.ts.map +1 -1
  163. package/dist/deduplication/refusal.js +2 -1
  164. package/dist/deduplication/refusal.js.map +1 -1
  165. package/dist/deduplication/scan.d.ts +2 -0
  166. package/dist/deduplication/scan.d.ts.map +1 -1
  167. package/dist/deduplication/scan.js +24 -7
  168. package/dist/deduplication/scan.js.map +1 -1
  169. package/dist/deep-scan.d.ts.map +1 -1
  170. package/dist/deep-scan.js +16 -15
  171. package/dist/deep-scan.js.map +1 -1
  172. package/dist/endor-findings.d.ts +2 -2
  173. package/dist/endor-findings.d.ts.map +1 -1
  174. package/dist/endor-findings.js +6 -23
  175. package/dist/endor-findings.js.map +1 -1
  176. package/dist/errors.d.ts +3 -1
  177. package/dist/errors.d.ts.map +1 -1
  178. package/dist/errors.js +7 -3
  179. package/dist/errors.js.map +1 -1
  180. package/dist/executable-path.d.ts +3 -0
  181. package/dist/executable-path.d.ts.map +1 -1
  182. package/dist/executable-path.js +26 -0
  183. package/dist/executable-path.js.map +1 -1
  184. package/dist/external-findings-import.d.ts.map +1 -1
  185. package/dist/external-findings-import.js +12 -1
  186. package/dist/external-findings-import.js.map +1 -1
  187. package/dist/external-findings-local.d.ts +66 -4
  188. package/dist/external-findings-local.d.ts.map +1 -1
  189. package/dist/external-findings-local.js +234 -53
  190. package/dist/external-findings-local.js.map +1 -1
  191. package/dist/external-findings-publish.d.ts +6 -1
  192. package/dist/external-findings-publish.d.ts.map +1 -1
  193. package/dist/external-findings-publish.js +326 -1633
  194. package/dist/external-findings-publish.js.map +1 -1
  195. package/dist/external-findings-read.d.ts +1 -0
  196. package/dist/external-findings-read.d.ts.map +1 -1
  197. package/dist/external-findings-read.js +31 -51
  198. package/dist/external-findings-read.js.map +1 -1
  199. package/dist/external-findings.d.ts +1 -1
  200. package/dist/external-findings.d.ts.map +1 -1
  201. package/dist/external-findings.js +12 -1
  202. package/dist/external-findings.js.map +1 -1
  203. package/dist/external-import-contract.d.ts +3 -11
  204. package/dist/external-import-contract.d.ts.map +1 -1
  205. package/dist/external-import-contract.js +29 -176
  206. package/dist/external-import-contract.js.map +1 -1
  207. package/dist/external-import-models.d.ts +1 -1
  208. package/dist/external-import-models.d.ts.map +1 -1
  209. package/dist/external-import-models.js.map +1 -1
  210. package/dist/finding-prompt.d.ts.map +1 -1
  211. package/dist/finding-prompt.js +2 -2
  212. package/dist/finding-prompt.js.map +1 -1
  213. package/dist/github-dependabot-findings.d.ts.map +1 -1
  214. package/dist/github-dependabot-findings.js +3 -4
  215. package/dist/github-dependabot-findings.js.map +1 -1
  216. package/dist/github-findings.d.ts.map +1 -1
  217. package/dist/github-findings.js +19 -287
  218. package/dist/github-findings.js.map +1 -1
  219. package/dist/hosted-remediation.d.ts +1 -0
  220. package/dist/hosted-remediation.d.ts.map +1 -1
  221. package/dist/hosted-remediation.js +23 -3
  222. package/dist/hosted-remediation.js.map +1 -1
  223. package/dist/index.d.ts +3 -2
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js +2 -1
  226. package/dist/index.js.map +1 -1
  227. package/dist/inspector-findings.d.ts.map +1 -1
  228. package/dist/inspector-findings.js +19 -35
  229. package/dist/inspector-findings.js.map +1 -1
  230. package/dist/knowledge-base.d.ts +1 -1
  231. package/dist/knowledge-base.d.ts.map +1 -1
  232. package/dist/knowledge-base.js +34 -27
  233. package/dist/knowledge-base.js.map +1 -1
  234. package/dist/linear.d.ts +11 -0
  235. package/dist/linear.d.ts.map +1 -1
  236. package/dist/linear.js.map +1 -1
  237. package/dist/local-git-metadata.d.ts +5 -2
  238. package/dist/local-git-metadata.d.ts.map +1 -1
  239. package/dist/local-git-metadata.js +8 -4
  240. package/dist/local-git-metadata.js.map +1 -1
  241. package/dist/multiscan.d.ts +4 -0
  242. package/dist/multiscan.d.ts.map +1 -1
  243. package/dist/multiscan.js +79 -37
  244. package/dist/multiscan.js.map +1 -1
  245. package/dist/opengrep-findings.d.ts +4 -2
  246. package/dist/opengrep-findings.d.ts.map +1 -1
  247. package/dist/opengrep-findings.js +39 -22
  248. package/dist/opengrep-findings.js.map +1 -1
  249. package/dist/private-finding-import.d.ts +8 -13
  250. package/dist/private-finding-import.d.ts.map +1 -1
  251. package/dist/private-finding-import.js +69 -129
  252. package/dist/private-finding-import.js.map +1 -1
  253. package/dist/project-config.d.ts.map +1 -1
  254. package/dist/project-config.js +53 -13
  255. package/dist/project-config.js.map +1 -1
  256. package/dist/prompt-files.d.ts +7 -2
  257. package/dist/prompt-files.d.ts.map +1 -1
  258. package/dist/prompt-files.js +42 -20
  259. package/dist/prompt-files.js.map +1 -1
  260. package/dist/provider-profile.d.ts.map +1 -1
  261. package/dist/provider-profile.js +4 -9
  262. package/dist/provider-profile.js.map +1 -1
  263. package/dist/publication.d.ts +1 -1
  264. package/dist/publication.d.ts.map +1 -1
  265. package/dist/publication.js.map +1 -1
  266. package/dist/record.d.ts +1 -5
  267. package/dist/record.d.ts.map +1 -1
  268. package/dist/record.js +3 -51
  269. package/dist/record.js.map +1 -1
  270. package/dist/remediation.d.ts.map +1 -1
  271. package/dist/remediation.js +3 -1
  272. package/dist/remediation.js.map +1 -1
  273. package/dist/runtime.d.ts +35 -7
  274. package/dist/runtime.d.ts.map +1 -1
  275. package/dist/runtime.js +778 -153
  276. package/dist/runtime.js.map +1 -1
  277. package/dist/saved-scan-bootstrap.d.ts +6 -1
  278. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  279. package/dist/saved-scan-bootstrap.js +267 -115
  280. package/dist/saved-scan-bootstrap.js.map +1 -1
  281. package/dist/scan-archive-path.d.ts +2 -0
  282. package/dist/scan-archive-path.d.ts.map +1 -0
  283. package/dist/scan-archive-path.js +5 -0
  284. package/dist/scan-archive-path.js.map +1 -0
  285. package/dist/scan-comparison.d.ts.map +1 -1
  286. package/dist/scan-comparison.js +6 -2
  287. package/dist/scan-comparison.js.map +1 -1
  288. package/dist/scan-dashboard.d.ts +1 -0
  289. package/dist/scan-dashboard.d.ts.map +1 -1
  290. package/dist/scan-dashboard.js +18 -2
  291. package/dist/scan-dashboard.js.map +1 -1
  292. package/dist/scan-executor.d.ts.map +1 -1
  293. package/dist/scan-executor.js +4 -2
  294. package/dist/scan-executor.js.map +1 -1
  295. package/dist/scan-history-renderer.d.ts +1 -0
  296. package/dist/scan-history-renderer.d.ts.map +1 -1
  297. package/dist/scan-history-renderer.js +25 -9
  298. package/dist/scan-history-renderer.js.map +1 -1
  299. package/dist/scan-logs.d.ts.map +1 -1
  300. package/dist/scan-logs.js +28 -4
  301. package/dist/scan-logs.js.map +1 -1
  302. package/dist/scanner-import.d.ts +5 -11
  303. package/dist/scanner-import.d.ts.map +1 -1
  304. package/dist/scanner-import.js +16 -89
  305. package/dist/scanner-import.js.map +1 -1
  306. package/dist/security-policy.d.ts.map +1 -1
  307. package/dist/security-policy.js +26 -6
  308. package/dist/security-policy.js.map +1 -1
  309. package/dist/semgrep-findings.d.ts.map +1 -1
  310. package/dist/semgrep-findings.js +14 -48
  311. package/dist/semgrep-findings.js.map +1 -1
  312. package/dist/semgrep-platform-findings.d.ts +20 -70
  313. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  314. package/dist/semgrep-platform-findings.js +116 -333
  315. package/dist/semgrep-platform-findings.js.map +1 -1
  316. package/dist/snyk-findings.d.ts +2 -0
  317. package/dist/snyk-findings.d.ts.map +1 -1
  318. package/dist/snyk-findings.js +5 -8
  319. package/dist/snyk-findings.js.map +1 -1
  320. package/dist/snyk-rest-findings.d.ts +3 -20
  321. package/dist/snyk-rest-findings.d.ts.map +1 -1
  322. package/dist/snyk-rest-findings.js +45 -217
  323. package/dist/snyk-rest-findings.js.map +1 -1
  324. package/dist/sonar-findings.d.ts +1 -1
  325. package/dist/sonar-findings.d.ts.map +1 -1
  326. package/dist/sonar-findings.js +2 -4
  327. package/dist/sonar-findings.js.map +1 -1
  328. package/dist/sonar-import.d.ts +3 -0
  329. package/dist/sonar-import.d.ts.map +1 -1
  330. package/dist/sonar-import.js +28 -30
  331. package/dist/sonar-import.js.map +1 -1
  332. package/dist/stored-finding-projection.d.ts +6 -0
  333. package/dist/stored-finding-projection.d.ts.map +1 -0
  334. package/dist/stored-finding-projection.js +104 -0
  335. package/dist/stored-finding-projection.js.map +1 -0
  336. package/dist/stored-findings-publication.d.ts +23 -0
  337. package/dist/stored-findings-publication.d.ts.map +1 -0
  338. package/dist/stored-findings-publication.js +169 -0
  339. package/dist/stored-findings-publication.js.map +1 -0
  340. package/dist/targets.d.ts +6 -1
  341. package/dist/targets.d.ts.map +1 -1
  342. package/dist/targets.js +76 -23
  343. package/dist/targets.js.map +1 -1
  344. package/dist/tenable-findings.d.ts +1 -4
  345. package/dist/tenable-findings.d.ts.map +1 -1
  346. package/dist/tenable-findings.js.map +1 -1
  347. package/dist/trivy-findings.d.ts.map +1 -1
  348. package/dist/trivy-findings.js +0 -11
  349. package/dist/trivy-findings.js.map +1 -1
  350. package/dist/trusted-executable.d.ts +6 -0
  351. package/dist/trusted-executable.d.ts.map +1 -1
  352. package/dist/trusted-executable.js +140 -37
  353. package/dist/trusted-executable.js.map +1 -1
  354. package/dist/veracode-findings.d.ts +1 -3
  355. package/dist/veracode-findings.d.ts.map +1 -1
  356. package/dist/veracode-findings.js +13 -38
  357. package/dist/veracode-findings.js.map +1 -1
  358. package/dist/version.d.ts +3 -1
  359. package/dist/version.d.ts.map +1 -1
  360. package/dist/version.js +184 -32
  361. package/dist/version.js.map +1 -1
  362. package/dist/wiz-findings.d.ts +2 -2
  363. package/dist/wiz-findings.d.ts.map +1 -1
  364. package/dist/wiz-findings.js +14 -92
  365. package/dist/wiz-findings.js.map +1 -1
  366. package/docs/cli.md +373 -106
  367. package/docs/findings-service.md +22 -9
  368. package/docs/hosted-remediation.md +13 -4
  369. package/docs/sdk.md +903 -0
  370. package/package.json +10 -6
  371. package/schemas/external-findings.schema.json +2 -1
  372. package/dist/hosted-scanner-v1.d.ts +0 -6
  373. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  374. package/dist/hosted-scanner-v1.js +0 -60
  375. package/dist/hosted-scanner-v1.js.map +0 -1
  376. package/dist/reader-selection.d.ts +0 -15
  377. package/dist/reader-selection.d.ts.map +0 -1
  378. package/dist/reader-selection.js +0 -89
  379. package/dist/reader-selection.js.map +0 -1
  380. package/dist/semgrep-platform-v1.d.ts +0 -6
  381. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  382. package/dist/semgrep-platform-v1.js +0 -83
  383. package/dist/semgrep-platform-v1.js.map +0 -1
  384. package/dist/snyk-rest-v1.d.ts +0 -28
  385. package/dist/snyk-rest-v1.d.ts.map +0 -1
  386. package/dist/snyk-rest-v1.js +0 -132
  387. package/dist/snyk-rest-v1.js.map +0 -1
@@ -1,36 +1,36 @@
1
+ import { readScannerJson } from "./scanner-import.js";
1
2
  import { hash, randomUUID } from "node:crypto";
2
3
  import { chmodSync } from "node:fs";
3
- import { lstat, mkdir, open, readFile, readdir, rename, rm, } from "node:fs/promises";
4
+ import { lstat, mkdir, open, readFile, rename, rm } from "node:fs/promises";
4
5
  import { join } from "node:path";
5
6
  import { nullIfMissingFile } from "./targets.js";
6
7
  import { setTimeout as delay } from "node:timers/promises";
7
- import { isBoxedPrimitive, isNativeError, isProxy, isStringObject, } from "node:util/types";
8
+ import { isProxy } from "node:util/types";
8
9
  import { privateImportClient, privateJobVersions, selectPrivateReport, readPrivateCheckpoint, parsePrivateCheckpoint, unsuccessfulJob, } from "./private-finding-import.js";
9
10
  import { readCloudCredentials } from "./cloud-publish.js";
11
+ import { armorCodeRepositoryUrl } from "./armorcode-findings.js";
10
12
  import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
11
13
  import { tenableReportFormat } from "./tenable-findings.js";
12
14
  import { guardianFindingId, guardianFindingRepository, guardianSelectionFormat, } from "./semgrep-guardian-findings.js";
13
- import { cloudBaseUrl, cloudFindingsUrl, DEFAULT_CLOUD_BASE_URL, } from "./cloud-endpoint.js";
15
+ import { cloudBaseUrl, cloudFindingsUrl } from "./cloud-endpoint.js";
14
16
  import { CodexSecurityError, errorMessage } from "./errors.js";
15
17
  import { codexSecurityStateDirectory, createWindowsOutputDirectory, validatePreparedOutputDir, sqliteDatabaseOpener, } from "./runtime.js";
16
18
  import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, requireCloudReader, semgrepSarifRepositories, snykFileRepositories, } from "./external-findings-read.js";
17
- import { canSnapshotWithoutGetters, canonicalJson, isRecord, } from "./record.js";
19
+ import { canonicalJson, isRecord } from "./record.js";
18
20
  import { notify } from "./value.js";
19
21
  import { wizCsvRepositoryUrl } from "./wiz-csv.js";
20
22
  import { isWizPackageFinding, wizFindingRepository } from "./wiz-findings.js";
21
23
  import { getOpenGrepSourcePositions } from "./opengrep-findings.js";
22
- import { previousReaderSelection, hasPreviousCloudProjection, } from "./reader-selection.js";
23
24
  import { dependabotRepository } from "./github-dependabot-findings.js";
24
25
  import { retainedGitHubRepository } from "./github-findings.js";
25
- import { normalizePreviousSemgrepFindings, normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
26
- import { normalizeSnykFile, readSnykReport, snykRepositoryUrls, } from "./snyk-findings.js";
27
- import { isSnykRestFinding, isSnykRestFormat, snykRestCheckpointFindingId, snykRestImportRepository, snykRestRepositoryMatches, } from "./snyk-rest-findings.js";
28
- import { hasRetainedSemgrepScope, isSemgrepPlatformEvidence, isSemgrepPlatformFormat, semgrepPlatformFormat, parseSemgrepResponse, semgrepLegacyRepositoryWitnesses, semgrepNativeProjectUrl, semgrepPlatformFindingBinding, semgrepPlatformRepositoryReference, semgrepPlatformReportScope, } from "./semgrep-platform-findings.js";
29
- import { semgrepV1Id } from "./semgrep-platform-v1.js";
26
+ import { normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
27
+ import { normalizeSnykFile, snykRepositoryUrls } from "./snyk-findings.js";
28
+ import { isSnykRestFinding, isSnykRestFormat, snykRestImportRepository, snykRestRepositoryMatches, } from "./snyk-rest-findings.js";
29
+ import { hasRetainedSemgrepScope, isSemgrepPlatformEvidence, isSemgrepPlatformFormat, semgrepPlatformFormat, semgrepPlatformFindingBinding, semgrepPlatformRepositoryReference, semgrepPlatformReportScope, } from "./semgrep-platform-findings.js";
30
30
  import { hostedRepositoryUrlKey, normalizeHostedGitRepositoryUrl, } from "./hosted-git-repository.js";
31
31
  import { trivyRemoteKey, trivyRepositoryUrl } from "./trivy-findings.js";
32
32
  import { hostedRepositoryUrl } from "./hosted-scanner-http.js";
33
- import { endorRepositoryUrls, requiresStructuredEndorReport, } from "./endor-findings.js";
33
+ import { endorRepositoryUrls } from "./endor-findings.js";
34
34
  import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
35
35
  import { checkmarxSelection } from "./checkmarx-repository.js";
36
36
  import { continuumReportRepositories } from "./continuum-findings.js";
@@ -38,8 +38,8 @@ import { veracodeReportRepositories } from "./veracode-findings.js";
38
38
  import { inspectorReportRepository } from "./inspector-findings.js";
39
39
  import { sonarRepositoryUrls } from "./sonar-findings.js";
40
40
  import { checkRetainedTrivyProvider, checkTrivyReportProvider, isTrivyReportHeader, retainedTrivyReport, trivyBatchSourceUrls, validateTrivyRepositoryUrl, } from "./trivy-import.js";
41
- import { NoPublishableFindingsError, reportForJson, snapshotSourceRepositories, snapshotImportOptions, cloneImportPreview, nativeErrorStackGetter, snapshotNormalizedFindings, } from "./external-findings.js";
42
- import { canonicalNumber, cloudRepositoryUrlKey, CloudEvidenceDepthError, validateImportRequest, validateExternalEvidence, validatePreviousCloudEvidence, validateExternalReport, validateImportReceipt, validateRepositories, validateSourceReports, validateSourceReport, } from "./external-import-contract.js";
41
+ import { NoPublishableFindingsError, reportForJson, snapshotSourceRepositories, snapshotImportOptions, cloneImportPreview, snapshotNormalizedFindings, } from "./external-findings.js";
42
+ import { canonicalNumber, cloudRepositoryUrlKey, validateImportRequest, validateExternalEvidence, validateExternalReport, validateImportReceipt, validateRepositories, validateSourceReports, validateSourceReport, } from "./external-import-contract.js";
43
43
  const MAX_REQUEST_BYTES = 5 * 1024 * 1024;
44
44
  /** Preserve accepted work in CLI JSON output when publication cannot finish. */
45
45
  export class ExternalPublicationError extends CodexSecurityError {
@@ -49,6 +49,27 @@ export class ExternalPublicationError extends CodexSecurityError {
49
49
  this.result = result;
50
50
  }
51
51
  }
52
+ /** Bind reviewed evidence to its account, repository, connector and destination version. */
53
+ export function cloudReviewDigest(preview, checkout, findings) {
54
+ return hash("sha256", canonicalJson({
55
+ checkout,
56
+ api: preview.cloudApiUrl,
57
+ account: preview.accountId,
58
+ repository: preview.destination.id,
59
+ connector: preview.destination.repo_connector_id,
60
+ url: preview.destination.url,
61
+ reset: preview.destination.reset_marker,
62
+ source: preview.source,
63
+ privateImport: preview.privateImport,
64
+ ...(findings && { findings, excluded: preview.excluded }),
65
+ items: preview.requests.flatMap((request) => request.items.map((item) => [
66
+ item.source_finding_id,
67
+ item.expected_version,
68
+ request.repository.environment_id,
69
+ item.evidence,
70
+ ])),
71
+ }));
72
+ }
52
73
  // Limit read concurrency to avoid one network round trip per finding in series.
53
74
  // Wait for the entire batch on failure so callers never outlive their read tasks.
54
75
  async function readInBatches(items, read) {
@@ -63,17 +84,9 @@ async function readInBatches(items, read) {
63
84
  }
64
85
  return output;
65
86
  }
66
- // JSON.stringify serializes boxed primitives after the replacer. Let it
67
- // produce their actual wire values, including false and strings.
68
- function wireJson(value) {
69
- return canonicalJson(value, undefined, isBoxedPrimitive);
70
- }
71
- function jsonDigest(value, serialize = wireJson) {
72
- return hash("sha256", serialize(value));
73
- }
74
87
  function matchesRepositoryEvidence(expected, stored) {
75
- const storedWire = wireJson(stored);
76
- if (wireJson(expected) === storedWire)
88
+ const storedWire = canonicalJson(stored);
89
+ if (canonicalJson(expected) === storedWire)
77
90
  return true;
78
91
  // A repository can store a literal first-component colon with an explicit
79
92
  // relative prefix. Match only that spelling in typed locations and their manifests.
@@ -92,7 +105,7 @@ function matchesRepositoryEvidence(expected, stored) {
92
105
  const path = item.manifest_path && qualified.get(item.manifest_path);
93
106
  return path ? { ...item, manifest_path: path } : item;
94
107
  });
95
- return wireJson({ ...expected, locations, packages }) === storedWire;
108
+ return canonicalJson({ ...expected, locations, packages }) === storedWire;
96
109
  }
97
110
  function isCompleteUnscoredOpenGrepReport(report) {
98
111
  let rows = report.excluded.length;
@@ -159,7 +172,7 @@ function sameSubmission(left, right) {
159
172
  return (left.accountId === right.accountId &&
160
173
  left.trivyRepositoryUrl === right.trivyRepositoryUrl &&
161
174
  left.inspectorProjectMapRequired === right.inspectorProjectMapRequired &&
162
- wireJson(left.requests) === wireJson(right.requests));
175
+ canonicalJson(left.requests) === canonicalJson(right.requests));
163
176
  }
164
177
  function wireFinding({ source_finding_id, evidence, }) {
165
178
  return { source_finding_id, evidence };
@@ -167,36 +180,6 @@ function wireFinding({ source_finding_id, evidence, }) {
167
180
  function submissionFindings(requests) {
168
181
  return requests.flatMap((batch) => batch.items.map(wireFinding));
169
182
  }
170
- function sameLegacyJson(saved, current, equivalent) {
171
- if (saved === current || equivalent(saved, current))
172
- return true;
173
- if (Array.isArray(saved) && Array.isArray(current))
174
- return (saved.length === current.length &&
175
- saved.every((child, i) => sameLegacyJson(child, current[i], equivalent)));
176
- if (!isRecord(saved) || !isRecord(current))
177
- return false;
178
- return (Object.keys(current).every((key) => Object.hasOwn(saved, key)) &&
179
- Object.keys(saved).every((key) => sameLegacyJson(saved[key], current[key], equivalent)));
180
- }
181
- // A copied reader result can retain the JSON from Buffer.toJSON but lose
182
- // the native Buffer that the previous reader cloned into a Uint8Array.
183
- function previousBufferJson(saved, current) {
184
- if (!isRecord(current) ||
185
- current["type"] !== "Buffer" ||
186
- !Array.isArray(current["data"]))
187
- return false;
188
- return (isRecord(saved) &&
189
- Object.keys(current).length === 2 &&
190
- Object.keys(saved).length === current["data"].length &&
191
- current["data"].every((byte, index) => Number.isInteger(byte) &&
192
- byte >= 0 &&
193
- byte <= 255 &&
194
- saved[index] === byte));
195
- }
196
- function sameFindingSelection(left, right) {
197
- return (left.length === right.length &&
198
- left.every((finding, index) => finding.source_finding_id === right[index].source_finding_id));
199
- }
200
183
  async function readOptionalFile(path) {
201
184
  return (await readFile(path, "utf8").catch(nullIfMissingFile)) ?? undefined;
202
185
  }
@@ -234,8 +217,8 @@ function validatePublicationReceipt(value, batch) {
234
217
  const receipt = validateImportReceipt(value);
235
218
  const remaining = new Set(batch.items.map((item) => item.client_id));
236
219
  if (receipt.id !== batch.request_id ||
237
- wireJson(receipt.repository) !== wireJson(batch.repository) ||
238
- wireJson(receipt.source) !== wireJson(batch.source) ||
220
+ canonicalJson(receipt.repository) !== canonicalJson(batch.repository) ||
221
+ canonicalJson(receipt.source) !== canonicalJson(batch.source) ||
239
222
  receipt.item_count !== batch.items.length ||
240
223
  receipt.results.length !== batch.items.length ||
241
224
  receipt.results.some((item) => !remaining.delete(item.client_id)))
@@ -258,56 +241,47 @@ function validatePublicationReceipt(value, batch) {
258
241
  result.version === null)
259
242
  throw new CodexSecurityError("Cloud returned an incomplete saved finding.");
260
243
  }
261
- if (wireJson(receipt.counts) !== wireJson(actual))
244
+ if (canonicalJson(receipt.counts) !== canonicalJson(actual))
262
245
  throw new CodexSecurityError("Cloud returned inconsistent publication counts.");
263
246
  return receipt;
264
247
  }
265
- async function withImportLocks(state, keys, signal, operation) {
248
+ function acknowledgedReceipts({ receipts = [], requests }) {
249
+ if (receipts.length > requests.length)
250
+ throw new CodexSecurityError("Saved publication has more receipts than requests.");
251
+ return receipts.map((receipt, index) => validatePublicationReceipt(receipt, requests[index]));
252
+ }
253
+ async function withImportLock(state, key, signal, operation) {
266
254
  if (process.platform === "win32")
267
255
  await createWindowsOutputDirectory(state, true);
268
256
  else
269
257
  await mkdir(state, { recursive: true, mode: 0o700 });
270
258
  await validatePreparedOutputDir(state, undefined, true);
271
- const openDatabase = sqliteDatabaseOpener();
272
- const guards = [];
259
+ const path = join(state, key + ".lock.sqlite");
260
+ const metadata = await lstat(path).catch(nullIfMissingFile);
261
+ if (metadata && !metadata.isFile())
262
+ throw new CodexSecurityError("The publication lock is not a regular file.");
263
+ const guard = sqliteDatabaseOpener()(path);
273
264
  try {
274
- for (const key of [...new Set(keys)].sort()) {
275
- const path = join(state, `${key}.lock.sqlite`);
276
- const metadata = await lstat(path).catch(nullIfMissingFile);
277
- if (metadata && !metadata.isFile())
278
- throw new CodexSecurityError("The publication lock is not a regular file.");
279
- const guard = openDatabase(path);
280
- guards.push(guard);
281
- if (process.platform !== "win32")
282
- chmodSync(path, 0o600);
283
- guard.exec("PRAGMA busy_timeout = 0");
284
- }
265
+ if (process.platform !== "win32")
266
+ chmodSync(path, 0o600);
267
+ guard.exec("PRAGMA busy_timeout = 0");
285
268
  for (;;) {
286
269
  signal?.throwIfAborted();
287
- let acquired = 0;
288
270
  try {
289
- // SQLite releases these transactions on process exit.
290
- for (const guard of guards) {
291
- guard.exec("BEGIN EXCLUSIVE");
292
- acquired++;
293
- }
271
+ guard.exec("BEGIN EXCLUSIVE");
294
272
  break;
295
273
  }
296
274
  catch (error) {
297
275
  const sqliteError = error;
298
276
  if (sqliteError.errcode !== 5 && sqliteError.code !== "SQLITE_BUSY")
299
277
  throw error;
300
- // Older SDKs can acquire historical keys in a different order.
301
- for (const guard of guards.slice(0, acquired))
302
- guard.exec("ROLLBACK");
303
278
  await delay(50, undefined, { signal });
304
279
  }
305
280
  }
306
281
  return await operation();
307
282
  }
308
283
  finally {
309
- for (const guard of guards)
310
- guard.close();
284
+ guard.close();
311
285
  }
312
286
  }
313
287
  function hostedSourceReferences(readerSources, url, sourcePlatform) {
@@ -319,20 +293,6 @@ function hostedSourceReferences(readerSources, url, sourcePlatform) {
319
293
  ? sources.filter(({ platform }) => platform !== "github")
320
294
  : sources;
321
295
  }
322
- function storedFindingId(finding) {
323
- const seen = new Set();
324
- for (let owner = finding; owner && !seen.has(owner); owner = Object.getPrototypeOf(owner)) {
325
- const property = Object.getOwnPropertyDescriptor(owner, "source_finding_id");
326
- if (property) {
327
- const id = property.value;
328
- return typeof id === "string" || isStringObject(id)
329
- ? String.prototype.valueOf.call(id)
330
- : "";
331
- }
332
- seen.add(owner);
333
- }
334
- return "";
335
- }
336
296
  function checkFindingProvider(input, provider) {
337
297
  function checkFormat(format) {
338
298
  if (format === tenableReportFormat)
@@ -340,15 +300,11 @@ function checkFindingProvider(input, provider) {
340
300
  if (format === guardianSelectionFormat && provider !== "semgrep")
341
301
  throw new CodexSecurityError("Use the semgrep provider for Guardian findings.");
342
302
  }
343
- checkFormat(ownData(ownData(input, "report"), "format"));
344
- if (!Array.isArray(input?.findings))
345
- return;
346
- for (const row of input.findings) {
347
- if (!row)
348
- continue;
349
- if (guardianFindingId.test(storedFindingId(row)))
303
+ checkFormat(input.report?.["format"]);
304
+ for (const { source_finding_id, evidence } of input.findings) {
305
+ if (guardianFindingId.test(source_finding_id))
350
306
  checkFormat(guardianSelectionFormat);
351
- checkFormat(ownData(ownData(row.evidence, "source_data"), "format"));
307
+ checkFormat(evidence.source_data?.["format"]);
352
308
  }
353
309
  }
354
310
  export async function prepareExternalPublication(path, options, dependencies = {}) {
@@ -362,7 +318,7 @@ export async function prepareExternalPublication(path, options, dependencies = {
362
318
  const semgrep = settings.provider === "semgrep";
363
319
  const report = await (semgrep
364
320
  ? readSemgrepReport(path)
365
- : readSnykReport(path));
321
+ : readScannerJson(path));
366
322
  const normalize = async (url, platform) => {
367
323
  const references = hostedSourceReferences(readerSources, url, semgrep ? platform : undefined);
368
324
  const semgrepOptions = {
@@ -372,10 +328,7 @@ export async function prepareExternalPublication(path, options, dependencies = {
372
328
  const findings = semgrep
373
329
  ? normalizeSemgrepFindings(report, semgrepOptions, "cloud")
374
330
  : await normalizeSnykFile(report, "cloud", references);
375
- const selection = normalizedPublicationInput(findings, provider);
376
- if (semgrep && hasPreviousCloudProjection(findings))
377
- selection.readPreviousFindings = () => normalizePreviousSemgrepFindings(report, semgrepOptions);
378
- return selection;
331
+ return normalizedPublicationInput(findings, provider);
379
332
  };
380
333
  const hosted = isRecord(report) &&
381
334
  (semgrep
@@ -422,29 +375,27 @@ export async function prepareExternalPublication(path, options, dependencies = {
422
375
  }
423
376
  else {
424
377
  const parsed = await readExternalFindings(path, settings);
425
- checkFindingProvider(parsed.findings, provider);
426
- input =
427
- parsed.publication ??
428
- normalizedPublicationInput(parsed.findings, provider);
429
- input.readPreviousFindings = parsed.previousFindings;
430
- if (provider === "endor") {
378
+ input = normalizedPublicationInput(parsed.findings, provider);
379
+ if (provider === "endor")
431
380
  fileRepositories = () => parsed.sourceRepositories ?? [];
432
- input.requiresStructuredReport = requiresStructuredEndorReport(parsed.findings);
433
- }
434
381
  }
435
- return preparePublicationInput(input, { ...settings, provider }, dependencies, readerSources, settings.sourceRepositoryUrl, path, fileRepositories);
382
+ return preparePublicationInput(input, { ...settings, provider }, dependencies, readerSources, undefined, settings.sourceRepositoryUrl, fileRepositories);
436
383
  }
437
384
  /** Prepare normalized provider evidence without reading a vendor export. */
438
385
  export async function prepareNormalizedExternalPublication(input, options, dependencies = {}) {
386
+ return prepareNormalizedPublication(input, options, dependencies);
387
+ }
388
+ /** @internal The workbench persists acknowledgements before a repository checkpoint is retired. */
389
+ export async function prepareNormalizedPublication(input, options, dependencies, workbench) {
439
390
  const settings = snapshotImportOptions(options);
440
391
  requireCloudReader(settings);
441
- return preparePublicationInput(normalizedPublicationInput(input, settings.provider), settings, dependencies, snapshotSourceRepositories(dependencies.sourceRepositories));
392
+ return preparePublicationInput(normalizedPublicationInput(input, settings.provider), settings, dependencies, snapshotSourceRepositories(dependencies.sourceRepositories), workbench);
442
393
  }
443
394
  function cloudSourceKey(url, platform) {
444
395
  return hostedRepositoryUrlKey(url, platform === "github", platform === "gitlab", "cloud");
445
396
  }
446
397
  /** Verify every source in a hosted selection, including SDK inputs containing typed-only rows. */
447
- function hostedRepositoryMatcher(input, provider, declaredUrl, destination, readerSources, allowOpaqueLegacyRows = false) {
398
+ function hostedRepositoryMatcher(input, provider, declaredUrl, destination, readerSources) {
448
399
  const references = hostedSourceReferences(readerSources, destination.url, input.sourceRepositoryPlatform);
449
400
  if (provider === "snyk") {
450
401
  const declaredSource = input.sourceRepositoryUrl !== undefined ||
@@ -454,7 +405,7 @@ function hostedRepositoryMatcher(input, provider, declaredUrl, destination, read
454
405
  const binding = snykRestImportRepository(input, provider, [
455
406
  ...readerSources.map(({ url }) => url),
456
407
  ...(declaredUrl === undefined ? [] : [declaredUrl]),
457
- ], references, undefined, allowOpaqueLegacyRows, declaredSource ? destination.url : undefined);
408
+ ], references, undefined, declaredSource ? destination.url : undefined);
458
409
  if (binding)
459
410
  return {
460
411
  github: binding.platform === "github",
@@ -484,71 +435,13 @@ function hostedRepositoryMatcher(input, provider, declaredUrl, destination, read
484
435
  claims.add(guardian);
485
436
  continue;
486
437
  }
487
- const data = finding.evidence.source_data;
488
438
  const sarif = semgrepSarifRepositories(finding, hasNativeSource);
489
439
  for (const { url } of sarif)
490
440
  claims.add(hostedRepositoryUrl(url, "Semgrep source repository"));
491
- const project = data?.["project"];
492
- if (!allowOpaqueLegacyRows ||
493
- !isSemgrepPlatformEvidence(finding, provider) ||
494
- (isRecord(project) &&
495
- project["id"] != null &&
496
- project["name"] != null &&
497
- data?.["deployment"] != null &&
498
- data["ref"] != null &&
499
- data["product"] != null &&
500
- ((isRecord(data["finding"]) && data["finding"]["id"] != null) ||
501
- typeof data["semgrepPlatformFindingJson"] === "string"))) {
502
- nativeRows.push({ finding, sarif });
503
- continue;
504
- }
505
- // Released SDKs could save partial native records. Retain any source still
506
- // identifiable on that row while validating complete siblings under the new mapping.
507
- if (!data)
508
- continue;
509
- if (reportScope?.projectId !== undefined) {
510
- const id = isRecord(project) ? project["id"] : undefined;
511
- if ((id != null &&
512
- id !== reportScope.projectId &&
513
- semgrepV1Id(id) !== reportScope.projectId) ||
514
- ["deployment", "ref", "product"].some((field) => data[field] != null && data[field] !== reportScope[field]))
515
- throw new CodexSecurityError("The retained Semgrep finding does not match the supplied report scope.");
516
- }
517
- const rows = [data["finding"]];
518
- const raw = data["semgrepPlatformFindingJson"];
519
- if (typeof raw === "string") {
520
- try {
521
- rows.push(parseSemgrepResponse(raw));
522
- }
523
- catch {
524
- // An unreadable historical row contributes no URL. Check the remaining claims.
525
- }
526
- }
527
- const nativeUrls = [isRecord(project) ? project["url"] : undefined];
528
- if (data["format"] === semgrepPlatformFormat)
529
- nativeUrls.push(data["nativeProjectUrl"]);
530
- for (const row of rows) {
531
- if (!isRecord(row))
532
- continue;
533
- if (reportScope?.ref !== undefined &&
534
- row["ref"] !== undefined &&
535
- row["ref"] !== reportScope.ref)
536
- throw new CodexSecurityError("The retained Semgrep finding does not match the supplied report scope.");
537
- const repository = row["repository"];
538
- if (isRecord(repository))
539
- nativeUrls.push(repository["url"]);
540
- }
541
- const urls = nativeUrls.map((url) => semgrepNativeProjectUrl(url, references));
542
- for (const url of [...urls, data["sourceRepositoryUrl"]]) {
543
- if (typeof url !== "string")
544
- continue;
545
- original ??= url;
546
- claims.add(url);
547
- }
441
+ nativeRows.push({ finding, sarif });
548
442
  }
549
- const witnesses = semgrepLegacyRepositoryWitnesses(nativeRows.map(({ finding }) => finding), provider, references, "cloud");
550
443
  for (const { finding, sarif } of nativeRows) {
551
- const native = semgrepPlatformFindingBinding(finding, provider, references, witnesses, reportScope, [{ url: projectedBlackDuckRepositoryUrl(finding, "cloud") }, ...sarif], "cloud", allowOpaqueLegacyRows)?.url;
444
+ const native = semgrepPlatformFindingBinding(finding, provider, references, reportScope, [{ url: projectedBlackDuckRepositoryUrl(finding, "cloud") }, ...sarif], "cloud")?.url;
552
445
  if (native) {
553
446
  original ??= native;
554
447
  claims.add(native);
@@ -581,93 +474,6 @@ function ownData(value, key) {
581
474
  ? Object.getOwnPropertyDescriptor(value, key)?.value
582
475
  : undefined;
583
476
  }
584
- // When native capture would invoke caller code, only the original data
585
- // properties can identify the earlier selection. Unknown IDs cannot rule it out.
586
- function previousFindingIds(input) {
587
- const rows = ownData(input, "findings");
588
- if (!Array.isArray(rows) || isProxy(rows))
589
- return null;
590
- return Array.from({ length: rows.length }, (_, index) => {
591
- const row = Object.getOwnPropertyDescriptor(rows, index)?.value;
592
- const id = ownData(row, "source_finding_id");
593
- return typeof id === "string" ? id : undefined;
594
- });
595
- }
596
- function withDataProperty(record, key, value) {
597
- const fields = Object.getOwnPropertyDescriptors(record);
598
- return Object.create(Object.getPrototypeOf(record), {
599
- ...fields,
600
- [key]: { ...fields[key], value },
601
- });
602
- }
603
- // Native cloning discarded enumerable diagnostic fields. Recover its message
604
- // without reading the caller's stack getter or changing their report.
605
- const nativeDiagnosticPrototypes = new Set([
606
- Error.prototype,
607
- EvalError.prototype,
608
- RangeError.prototype,
609
- ReferenceError.prototype,
610
- SyntaxError.prototype,
611
- TypeError.prototype,
612
- URIError.prototype,
613
- ]);
614
- function previousDiagnosticMessage(diagnostic) {
615
- const stack = Object.getOwnPropertyDescriptor(diagnostic, "stack");
616
- const message = ownData(diagnostic, "message");
617
- const cause = Object.getOwnPropertyDescriptor(diagnostic, "cause");
618
- const name = Object.getOwnPropertyDescriptor(diagnostic, "name");
619
- if (!nativeDiagnosticPrototypes.has(Object.getPrototypeOf(diagnostic)) ||
620
- typeof message !== "string" ||
621
- (stack?.get && stack.get !== nativeErrorStackGetter) ||
622
- (name && typeof name.value !== "string") ||
623
- (cause &&
624
- (!Object.hasOwn(cause, "value") ||
625
- !canSnapshotWithoutGetters(cause.value))))
626
- return;
627
- return message;
628
- }
629
- function previousDiagnosticInput(input, nativeDiagnostics) {
630
- const report = ownData(input, "report");
631
- const errors = ownData(report, "errors");
632
- if (!isRecord(report) || !Array.isArray(errors) || isProxy(errors))
633
- return input;
634
- let entries;
635
- for (let index = 0; index < errors.length; index++) {
636
- const descriptor = Object.getOwnPropertyDescriptor(errors, index);
637
- const diagnostic = descriptor?.value;
638
- if (!descriptor || !isNativeError(diagnostic))
639
- continue;
640
- const message = previousDiagnosticMessage(diagnostic);
641
- if (message === undefined)
642
- return input;
643
- nativeDiagnostics.set(index, diagnostic);
644
- (entries ??= Object.getOwnPropertyDescriptors(errors))[index] = {
645
- ...descriptor,
646
- value: { message },
647
- };
648
- }
649
- if (!entries)
650
- return input;
651
- const capturedErrors = Object.defineProperties([], entries);
652
- const capturedReport = withDataProperty(report, "errors", capturedErrors);
653
- return withDataProperty(input, "report", capturedReport);
654
- }
655
- // Capture before JSON hooks can change their source. If native capture would
656
- // invoke caller code too, the original bytes cannot be observed independently.
657
- function previousNormalizedFindings(input, nativeDiagnostics, observe) {
658
- input = previousDiagnosticInput(input, nativeDiagnostics);
659
- if (!canSnapshotWithoutGetters(input, observe))
660
- return;
661
- // Object spread skips a hidden report, but explicitly reading it could run a getter.
662
- const reportField = Object.getOwnPropertyDescriptor(input, "report");
663
- if (reportField && !Object.hasOwn(reportField, "value"))
664
- return;
665
- const { report, ...parsed } = input;
666
- const snapshot = structuredClone(parsed);
667
- if (report !== undefined)
668
- snapshot.report = structuredClone(report);
669
- return snapshot;
670
- }
671
477
  function publicationIdentity(parsed, provider) {
672
478
  // For Trivy, the independently checked header binds the repository. Files
673
479
  // and normalized rows use the same checkpoint when their findings agree.
@@ -676,7 +482,7 @@ function publicationIdentity(parsed, provider) {
676
482
  return parsed.findings;
677
483
  return { findings: parsed.findings, report: reportForJson(parsed.report) };
678
484
  }
679
- function validatePublicationFindings(parsed, validateEvidence) {
485
+ function validatePublicationFindings(parsed) {
680
486
  validateExternalReport(parsed.report);
681
487
  const ids = new Set();
682
488
  for (const finding of parsed.findings) {
@@ -686,293 +492,121 @@ function validatePublicationFindings(parsed, validateEvidence) {
686
492
  if (ids.has(id))
687
493
  throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(id)}.`);
688
494
  ids.add(id);
689
- finding.evidence = validateEvidence(finding.evidence);
690
- }
691
- }
692
- function historicalPublication(native) {
693
- if (!native)
694
- return;
695
- try {
696
- // Older SDKs detached all raw records before Cloud validation added defaults.
697
- for (const finding of native.findings)
698
- if (finding.evidence.source_data !== undefined)
699
- finding.evidence.source_data = structuredClone(finding.evidence.source_data);
700
- validatePublicationFindings(native, validatePreviousCloudEvidence);
701
- const identity = publicationIdentity(native);
702
- let hasBoxedScalars = false;
703
- const wire = canonicalJson(identity, undefined, (value) => {
704
- if (!isBoxedPrimitive(value))
705
- return false;
706
- hasBoxedScalars = true;
707
- return true;
708
- });
709
- return { parsed: native, identity, wire, hasBoxedScalars };
710
- }
711
- catch {
712
- // The caller may export valid JSON even if the native candidate cannot be
713
- // validated or hashed, for example when an unused row property holds a BigInt.
714
- return;
495
+ finding.evidence = validateExternalEvidence(finding.evidence);
715
496
  }
716
497
  }
717
498
  function normalizedPublicationInput(input, provider) {
718
- const nativeDiagnostics = new Map();
719
- let native;
720
- let plainJson = true;
721
- try {
722
- native = previousNormalizedFindings(input, nativeDiagnostics, (value) => {
723
- if (!plainJson)
724
- return;
725
- const prototype = Object.getPrototypeOf(value);
726
- plainJson =
727
- (prototype === null ||
728
- prototype === Object.prototype ||
729
- prototype === Array.prototype) &&
730
- !("toJSON" in value);
731
- });
732
- }
733
- catch {
734
- /* A valid JSON export can contain an uncloneable value. */
735
- }
736
- let priorIds = native ? undefined : previousFindingIds(input);
737
- let current;
738
- let freshError;
739
- try {
740
- current = snapshotNormalizedFindings(input, undefined, "cloud");
741
- }
742
- catch (error) {
743
- if ((!isNativeError(error) && !(error instanceof Error)) ||
744
- !native?.findings.length)
745
- throw error;
746
- freshError = error;
747
- current = { read: native.read, findings: [], excluded: [] };
748
- }
749
- // Repository and format declarations can be non-enumerable SDK getters.
750
- for (const key of [
751
- "sourceFormat",
752
- "semgrepPlatformScope",
753
- "snykRestContext",
754
- ...(provider === "semgrep" || provider === "snyk"
755
- ? ["sourceRepositoryUrl", "sourceRepositoryPlatform"]
756
- : []),
757
- ]) {
758
- if (!(key in current) &&
759
- !Object.prototype.propertyIsEnumerable.call(input, key) &&
760
- key in input)
761
- Object.assign(current, {
762
- [key]: structuredClone(Reflect.get(input, key)),
763
- });
764
- }
765
- const parsed = current;
766
- if (parsed.snykRestContext !== undefined) {
499
+ const current = snapshotNormalizedFindings(input, undefined, "cloud", provider);
500
+ if (current.snykRestContext !== undefined) {
767
501
  if (provider !== "snyk")
768
502
  throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
769
- if (!isSnykRestFormat(parsed.snykRestContext?.["format"]))
503
+ if (!isSnykRestFormat(current.snykRestContext?.["format"]))
770
504
  throw new CodexSecurityError("Expected a versioned Snyk REST report context.");
771
505
  }
772
- const markedSemgrep = "sourceFormat" in parsed && isSemgrepPlatformFormat(parsed.sourceFormat);
506
+ const markedSemgrep = "sourceFormat" in current && isSemgrepPlatformFormat(current.sourceFormat);
773
507
  if (markedSemgrep && provider !== "semgrep")
774
508
  throw new CodexSecurityError("Semgrep Platform evidence requires the semgrep provider.");
775
- if (markedSemgrep || "semgrepPlatformScope" in parsed)
776
- semgrepPlatformReportScope(parsed, provider);
777
- if (native && nativeDiagnostics.size) {
778
- const historical = native.report["errors"];
779
- const exported = current.report?.["errors"];
780
- for (const [index, source] of nativeDiagnostics) {
781
- const message = historical[index].message;
782
- let diagnostic = Array.isArray(exported) && exported[index];
783
- // A failed export may never reach the report. Its hooks have already run,
784
- // so check the original descriptors again before native cloning reads a stack.
785
- if (freshError && previousDiagnosticMessage(source) === message)
786
- diagnostic = source;
787
- if (isNativeError(diagnostic) &&
788
- Object.getPrototypeOf(diagnostic) === Object.getPrototypeOf(source)) {
789
- try {
790
- const copy = structuredClone(diagnostic);
791
- if (copy.message === message) {
792
- historical[index] = copy;
793
- continue;
794
- }
795
- }
796
- catch {
797
- // A failed native clone cannot establish a historical report.
798
- }
799
- }
800
- if (freshError)
801
- throw freshError;
802
- priorIds = previousFindingIds(native);
803
- native = undefined;
804
- break;
805
- }
806
- }
807
- // A Cloud depth error can interrupt a local reader's JSON export. Its plain,
808
- // independently captured output can still verify the original reader selection.
809
- const readerOutput = freshError
810
- ? freshError instanceof CloudEvidenceDepthError &&
811
- plainJson &&
812
- !nativeDiagnostics.size &&
813
- native
814
- : current;
815
- const reader = readerOutput
816
- ? previousReaderSelection(input, readerOutput, native ?? null)
817
- : undefined;
818
- if (reader)
819
- native = reader.snapshot;
820
- const original = historicalPublication(native);
821
- if (original)
822
- checkFindingProvider(original.parsed, provider);
823
- try {
824
- validatePublicationFindings(current, validateExternalEvidence);
825
- }
826
- catch (error) {
827
- if (!(error instanceof Error) || !original?.parsed.findings.length)
828
- throw error;
829
- freshError = error;
830
- }
831
- if (freshError) {
832
- if (!original)
833
- throw freshError;
834
- // Only the old selection can be reviewed when fresh validation failed.
835
- current = { read: original.parsed.read, findings: [], excluded: [] };
836
- }
509
+ if (markedSemgrep || "semgrepPlatformScope" in current)
510
+ semgrepPlatformReportScope(current, provider);
511
+ validatePublicationFindings(current);
837
512
  checkFindingProvider(current, provider);
838
- const identity = publicationIdentity(current, provider);
839
513
  return {
840
514
  current,
841
- legacy: current,
842
- currentIdentity: identity,
843
- legacyIdentity: identity,
844
515
  sourcePositions: getOpenGrepSourcePositions(ownData(input, "findings")),
845
- original,
846
- freshError,
847
- unprovenIdPrefixes: reader?.unprovenIdPrefixes,
848
- uncertainFindingIds: reader?.uncertainFindingIds,
849
- unprovenOccurrenceCount: reader?.unprovenOccurrenceCount,
850
- knownFindings: reader?.knownFindings,
851
- potentialIds: reader?.sourceFindingIds ??
852
- (original
853
- ? undefined
854
- : (native?.findings.map((row) => row.source_finding_id) ?? priorIds)),
855
516
  };
856
517
  }
857
- // The old hash represented Number objects as {}. Unpublished row properties
858
- // and report metadata cannot be recovered from the immutable saved request.
859
- function verifiableLegacyMetadata({ report, findings }, wireIdentity) {
860
- let verifiable = true;
861
- // Only values in these records can be old scalar projections. Their record
862
- // containers are required by the normalized selection, including an empty report.
863
- const { errors, ...metadata } = report ?? {};
864
- JSON.stringify([
865
- Object.values(metadata),
866
- // The original hash used the serialized form of report.errors arrays.
867
- Array.isArray(errors) ? undefined : errors,
868
- findings.map(({ evidence: _, ...fields }) => Object.values(fields)),
869
- ], (_key, value) => {
870
- if (isRecord(value) && !(wireIdentity && isBoxedPrimitive(value))) {
871
- // {} and string-index records can both be the old form of a scalar.
872
- let index = 0;
873
- if (Object.keys(value).every((key) => {
874
- const item = value[key];
875
- return (item === undefined ||
876
- (key === String(index++) &&
877
- typeof item === "string" &&
878
- item.length === 1));
879
- }))
880
- verifiable = false;
881
- }
882
- return value;
883
- });
884
- return verifiable;
885
- }
886
- // Prefer the current native evidence for new publications. The original SDK input
887
- // remains a candidate so an approved request can resume under its exact digest.
888
- function* hostedPublicationProjections(input, provider, destination, readerSources) {
889
- const current = input.current;
518
+ // A normalized hosted input can omit native fields that the authenticated
519
+ // repository and the retained source response establish for each occurrence.
520
+ function hostedPublicationFindings(current, provider, destination, readerSources) {
890
521
  if (provider === "snyk") {
891
522
  const first = current.findings.find(isSnykRestFinding);
892
523
  if (!first && current.snykRestContext === undefined)
893
- return;
894
- // A previous publisher may have approved the exact raw selection.
895
- yield input;
896
- const originalUrl = current.snykRestContext?.["sourceRepositoryUrl"] ??
524
+ return current;
525
+ const url = current.snykRestContext?.["sourceRepositoryUrl"] ??
897
526
  current.sourceRepositoryUrl ??
898
527
  first?.evidence.source_data?.["sourceRepositoryUrl"];
899
- // The original spelling reconstructs a lookup key after a catalog rename.
900
- // Admission validates the input against the saved approval or live destination.
901
- const retained = structuredClone(current);
902
- try {
903
- snykRestImportRepository(retained, provider, [], hostedSourceReferences(readerSources, typeof originalUrl === "string" ? originalUrl : destination.url, current.sourceRepositoryPlatform), (finding, source) => {
904
- finding.evidence.source_data = source;
905
- });
906
- }
907
- catch (error) {
908
- // A headerless input can still identify an already-approved opaque request.
909
- if (current.snykRestContext !== undefined)
910
- throw error;
911
- return;
912
- }
913
- yield {
914
- ...input,
915
- current: retained,
916
- // The raw input above owns its historical native checkpoint.
917
- original: undefined,
918
- currentIdentity: publicationIdentity(retained),
919
- };
920
- return;
528
+ snykRestImportRepository(current, provider, [], hostedSourceReferences(readerSources, typeof url === "string" ? url : destination.url, current.sourceRepositoryPlatform), (finding, source) => {
529
+ finding.evidence.source_data = source;
530
+ });
531
+ return current;
921
532
  }
922
- const originalRow = (finding) => isRecord(finding.evidence.source_data?.["finding"]) &&
923
- isSemgrepPlatformEvidence(finding, "semgrep");
924
- const currentBulkRow = (finding) => finding.evidence.source_data?.["format"] === semgrepPlatformFormat;
925
- const first = current.findings.find(originalRow) ?? current.findings.find(currentBulkRow);
533
+ if (provider !== "semgrep")
534
+ return current;
535
+ const first = current.findings.find((finding) => isSemgrepPlatformEvidence(finding, provider));
926
536
  if (!first)
927
- return;
928
- const reportScope = semgrepPlatformReportScope(current, "semgrep");
537
+ return current;
929
538
  const retained = first.evidence.source_data;
930
539
  const project = retained?.["project"];
931
- const retainedUrl = current.sourceRepositoryUrl ??
540
+ const url = current.sourceRepositoryUrl ??
932
541
  retained?.["sourceRepositoryUrl"] ??
933
542
  (isRecord(project) ? project["url"] : undefined);
934
- // A renamed repository may need the original spelling to identify its checkpoint.
935
- // Preparation validates the unmodified report against the authenticated approval.
936
- for (const url of new Set([destination.url, retainedUrl])) {
937
- if (typeof url !== "string")
938
- continue;
939
- const references = hostedSourceReferences(readerSources, url, current.sourceRepositoryPlatform);
940
- try {
941
- const witnesses = semgrepLegacyRepositoryWitnesses(current.findings, "semgrep", references, "cloud");
942
- const findings = current.findings.map((finding) => {
943
- const original = originalRow(finding);
944
- if (!original && !currentBulkRow(finding))
945
- return finding;
946
- const binding = semgrepPlatformFindingBinding(finding, "semgrep", references, witnesses, reportScope, undefined, "cloud");
947
- // The authenticated repository can make an offline backlog row selectable.
948
- return binding?.sourceData &&
949
- (original || binding.sourceData["format"] !== semgrepPlatformFormat)
950
- ? {
951
- ...finding,
952
- evidence: {
953
- ...finding.evidence,
954
- ...binding.migration,
955
- source_data: binding.sourceData,
956
- },
543
+ const references = hostedSourceReferences(readerSources, typeof url === "string"
544
+ ? normalizeHostedGitRepositoryUrl(url, destination.url, true)
545
+ : destination.url, current.sourceRepositoryPlatform);
546
+ const scope = semgrepPlatformReportScope(current, provider, references);
547
+ const findings = current.findings.map((finding) => {
548
+ const data = finding.evidence.source_data;
549
+ const original = isRecord(data?.["finding"]) &&
550
+ isSemgrepPlatformEvidence(finding, provider);
551
+ if (!original && data?.["format"] !== semgrepPlatformFormat)
552
+ return finding;
553
+ const binding = semgrepPlatformFindingBinding(finding, provider, references, scope, undefined, "cloud");
554
+ return binding?.sourceData &&
555
+ (original || binding.sourceData["format"] !== semgrepPlatformFormat)
556
+ ? {
557
+ ...finding,
558
+ evidence: {
559
+ ...finding.evidence,
560
+ ...binding.migration,
561
+ source_data: binding.sourceData,
562
+ },
563
+ }
564
+ : finding;
565
+ });
566
+ return { ...current, findings };
567
+ }
568
+ async function preparePublicationInput(supplied, options, dependencies, readerSources, workbench, declaredUrl, fileRepositories) {
569
+ const record = workbench !== "preview" && workbench?.record;
570
+ function withReceipts(scope, prepared) {
571
+ return {
572
+ preview: prepared.preview,
573
+ async publish() {
574
+ if (!record)
575
+ return prepared.publish();
576
+ let recorded = false;
577
+ const persist = async (result) => {
578
+ if (recorded)
579
+ return;
580
+ recorded = true;
581
+ const job = result.privateJob;
582
+ const privateJobId = job?.status === "completed" &&
583
+ !result.counts.error &&
584
+ !result.unacknowledged
585
+ ? job.id
586
+ : undefined;
587
+ if (!privateJobId && !result.receipts.length)
588
+ return;
589
+ try {
590
+ await record(scope, result.receipts, privateJobId);
957
591
  }
958
- : finding;
959
- });
960
- const upgraded = { ...current, findings };
961
- yield {
962
- ...input,
963
- current: upgraded,
964
- original: undefined,
965
- currentIdentity: publicationIdentity(upgraded),
966
- };
967
- }
968
- catch {
969
- // The released SDK also accepted partial original records; keep the raw
970
- // identity as a fallback so its exact saved request remains recoverable.
971
- }
592
+ catch (error) {
593
+ throw new ExternalPublicationError(`Cloud returned receipts, but the workbench could not record them: ${errorMessage(error)}`, result, error);
594
+ }
595
+ };
596
+ let result;
597
+ try {
598
+ result = await prepared.publish(persist);
599
+ }
600
+ catch (error) {
601
+ if (error instanceof ExternalPublicationError)
602
+ await persist(error.result);
603
+ throw error;
604
+ }
605
+ await persist(result);
606
+ return result;
607
+ },
608
+ };
972
609
  }
973
- yield input;
974
- }
975
- async function preparePublicationInput(supplied, options, dependencies, readerSources, declaredUrl, nativePath, fileRepositories) {
976
610
  const { inspectorProjectMap } = options;
977
611
  const progress = (event) => notify(() => dependencies.onProgress?.(event));
978
612
  if (!options.sourceKey.trim() ||
@@ -992,44 +626,23 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
992
626
  ? (url) => cloudSourceKey(url, "github")
993
627
  : cloudRepositoryUrlKey;
994
628
  const state = externalPublicationStateDirectory(environment);
995
- function pendingFile(key) {
996
- return join(state, `${key}.pending.json`);
997
- }
998
- let previousFindings;
999
- async function previousFindingsIfSaved(input, currentKey) {
1000
- if (!input.readPreviousFindings || previousFindings)
1001
- return previousFindings;
1002
- // An empty state directory (or just this current receipt) needs only the
1003
- // current reader for its preview.
1004
- const entries = (await readdir(state).catch(nullIfMissingFile)) ?? [];
1005
- if (entries.some((name) => /^[a-f0-9]{64}\.(?:pending|private-import)\.json$/u.test(name) &&
1006
- name.split(".", 1)[0] !== currentKey))
1007
- previousFindings = input.readPreviousFindings();
1008
- return previousFindings;
1009
- }
1010
- async function checkSelection(input) {
629
+ function checkSelection(input) {
1011
630
  const parsed = input.current;
1012
631
  checkTrivyReportProvider(options.provider, parsed.report);
1013
632
  for (const finding of parsed.findings)
1014
633
  checkRetainedTrivyProvider(options.provider, finding);
1015
- if (!parsed.findings.length &&
1016
- !input.original?.parsed.findings.length &&
1017
- input.potentialIds !== null &&
1018
- !input.potentialIds?.length &&
1019
- !input.uncertainFindingIds?.length &&
1020
- !input.unprovenOccurrenceCount &&
1021
- !input.unprovenIdPrefixes?.length &&
1022
- !(await previousFindingsIfSaved(input))?.findings.length)
634
+ if (!parsed.findings.length)
1023
635
  throw new NoPublishableFindingsError(parsed);
1024
636
  }
1025
637
  if (typeof supplied !== "function")
1026
- await checkSelection(supplied);
638
+ checkSelection(supplied);
1027
639
  progress({ phase: "discovering", completed: 0 });
1028
640
  const apiBaseUrl = cloudBaseUrl(environment);
1029
641
  const cloudApiUrl = `${apiBaseUrl}/external`;
1030
642
  // Validate the configured return destination before authentication or uploads.
1031
643
  cloudFindingsUrl(environment, options.repository);
1032
- const credentials = await (dependencies.credentials ?? (() => readCloudCredentials(environment)))();
644
+ const credentials = await (dependencies.credentials ??
645
+ (() => readCloudCredentials(environment, dependencies.signal)))();
1033
646
  let canStartJob = false;
1034
647
  let repositorySeverities;
1035
648
  const jobVersionHeader = "Codex-Security-Private-Import-Job-Version";
@@ -1063,7 +676,19 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
1063
676
  if (!response.ok) {
1064
677
  const payload = (await response.json().catch(() => null));
1065
678
  const retryAfter = response.headers.get("Retry-After");
1066
- throw new CloudImportError(response.status, `Cloud import failed (HTTP ${response.status}). ${payload?.error?.message ?? response.statusText}${retryAfter ? ` Retry-After: ${retryAfter}.` : ""}`);
679
+ const detail = payload?.error?.message ?? response.statusText;
680
+ let message = `Cloud import failed (HTTP ${response.status}).`;
681
+ if (detail)
682
+ message += ` ${detail}`;
683
+ if (repositoryCatalog && response.status === 404) {
684
+ if (!/[.!?]$/u.test(message))
685
+ message += ".";
686
+ message +=
687
+ " Cloud import is not available for this account or deployment.";
688
+ }
689
+ if (retryAfter)
690
+ message += ` Retry-After: ${retryAfter}.`;
691
+ throw new CloudImportError(response.status, message);
1067
692
  }
1068
693
  if (repositoryCatalog) {
1069
694
  const advertised = (header) => response.headers
@@ -1108,303 +733,34 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
1108
733
  const deferred = typeof supplied === "function";
1109
734
  const resolved = deferred ? await supplied(destination) : supplied;
1110
735
  if (deferred)
1111
- await checkSelection(resolved);
736
+ checkSelection(resolved);
1112
737
  const report = resolved.current;
1113
738
  const source = { provider: options.provider, source_key: options.sourceKey };
1114
739
  const importPrefix = source.provider === "sonar" ? "/v2" : "";
1115
740
  const sourceReportsPath = importPrefix + sourcePath(destination);
1116
- const checkpointIdentity = [
1117
- // Keep existing production checkpoints readable; other deployments must
1118
- // never share a saved request or receipt with the production default.
1119
- ...(apiBaseUrl === DEFAULT_CLOUD_BASE_URL ? [] : [apiBaseUrl]),
741
+ const hosted = options.provider === "snyk" || options.provider === "semgrep";
742
+ const parsed = hostedPublicationFindings(report, options.provider, destination, readerSources);
743
+ const key = hash("sha256", canonicalJson([
744
+ "external-findings/2",
745
+ apiBaseUrl,
1120
746
  credentials.account_id,
1121
747
  destination.id,
1122
748
  destination.repo_connector_id,
1123
749
  source,
1124
- ];
1125
- function scopeKey(identity, serialize = wireJson) {
1126
- return jsonDigest([...checkpointIdentity, identity], serialize);
1127
- }
1128
- function localeKey(rows) {
1129
- return hash("sha256", canonicalJson([...checkpointIdentity, rows], (left, right) => left.localeCompare(right)));
1130
- }
1131
- const hosted = options.provider === "snyk" || options.provider === "semgrep";
1132
- // Different selections can share native occurrences. Serialize their checkpoint
1133
- // creation under the authenticated source and release before calling Cloud.
1134
- const sourceLock = "source-" + hash("sha256", canonicalJson(checkpointIdentity));
1135
- const withSourceAdmission = (operation) => hosted ? underLocks([sourceLock], operation) : operation();
1136
- let projection = resolved;
1137
- let capturedPending;
1138
- const projectionKeys = new Set();
1139
- if (options.provider === "semgrep" || options.provider === "snyk") {
1140
- for (const candidate of hostedPublicationProjections(resolved, options.provider, destination, readerSources)) {
1141
- const candidateKey = scopeKey(candidate.currentIdentity);
1142
- if (projectionKeys.has(candidateKey))
1143
- continue;
1144
- // New imports use the first reconstructed projection; an exact pending key
1145
- // takes precedence, including an earlier SDK's unmodified original input.
1146
- capturedPending = await readOptionalFile(pendingFile(candidateKey));
1147
- if (projection === resolved || capturedPending !== undefined)
1148
- projection = candidate;
1149
- projectionKeys.add(candidateKey);
1150
- if (capturedPending !== undefined)
1151
- break;
1152
- }
1153
- }
1154
- // Changed reader projections get new keys, but both transports must replay the
1155
- // exact bytes already approved by the earlier reader when a checkpoint exists.
750
+ publicationIdentity(parsed, options.provider),
751
+ ...(workbench === "preview"
752
+ ? ["preview"]
753
+ : workbench
754
+ ? [workbench.checkout, workbench.findings]
755
+ : []),
756
+ ]));
757
+ const pendingPath = join(state, key + ".pending.json");
758
+ const underPublishLock = (operation) => withImportLock(state, key, dependencies.signal, operation);
759
+ const removePending = () => rm(pendingPath, { force: true });
1156
760
  const privateClient = privateImportClient(apiBaseUrl, credentials, dependencies.fetch ?? globalThis.fetch, dependencies.signal);
1157
- let previewContext;
1158
- const currentReaderKey = resolved.readPreviousFindings
1159
- ? scopeKey(resolved.currentIdentity)
1160
- : undefined;
1161
- let alternateKey;
1162
- let resumingPreviousReader = false;
1163
- function previousCandidateKey(previous) {
1164
- if (!previous?.findings.length)
1165
- return;
1166
- // The file reader already validated plain JSON evidence for Cloud. Only a
1167
- // matching checkpoint needs the full normalized publication snapshot.
1168
- const previousKey = scopeKey(publicationIdentity(previous, options.provider));
1169
- return previousKey !== currentReaderKey ? previousKey : undefined;
1170
- }
1171
- async function alternateCheckpoint(key, context) {
1172
- const pending = await readOptionalFile(pendingFile(key));
1173
- if (pending !== undefined)
1174
- return { pending };
1175
- const saved = await readOptionalFile(join(state, key + ".private-import.json"));
1176
- if (saved === undefined)
1177
- return;
1178
- const checkpoint = parsePrivateCheckpoint(saved);
1179
- // A completed import cannot acknowledge findings newly admitted by the
1180
- // current reader. Pending uploads and jobs always retain their original bytes.
1181
- if (!resumingPreviousReader &&
1182
- previousFindings &&
1183
- checkpoint.receipt?.status === "completed" &&
1184
- !sameFindingSelection(previousFindings.findings, resolved.current.findings))
1185
- return;
1186
- if (checkpoint.contextVersion === (await context()).context_version)
1187
- return { pending };
1188
- }
1189
- async function assertNoAlternateCheckpoint(context = () => privateClient.context()) {
1190
- if (alternateKey && (await alternateCheckpoint(alternateKey, context)))
1191
- throw new CodexSecurityError(resumingPreviousReader
1192
- ? "Both reader versions have saved publications for this report. Resume either one using its original normalized findings."
1193
- : "Another publication prepared this input. Run the command again to review and resume the saved request.");
1194
- }
1195
- if (currentReaderKey)
1196
- alternateKey = previousCandidateKey(await previousFindingsIfSaved(resolved, currentReaderKey));
1197
- if (alternateKey && previousFindings) {
1198
- const context = async () => (previewContext ??= await privateClient.context());
1199
- const checkpoint = await alternateCheckpoint(alternateKey, context);
1200
- capturedPending = checkpoint?.pending;
1201
- if (checkpoint) {
1202
- projection = normalizedPublicationInput(previousFindings, options.provider);
1203
- resumingPreviousReader = true;
1204
- alternateKey = currentReaderKey;
1205
- await assertNoAlternateCheckpoint(context);
1206
- }
1207
- }
1208
- const input = projection;
1209
- let { current: parsed, legacy: legacyParsed, currentIdentity, legacyIdentity, recheckFileRepository, } = input;
1210
761
  const scopedSemgrepReport = options.provider === "semgrep" &&
1211
762
  "sourceFormat" in parsed &&
1212
763
  isSemgrepPlatformFormat(parsed.sourceFormat);
1213
- const original = input.original;
1214
- const originalParsed = original?.parsed ?? parsed;
1215
- const originalIdentity = original?.identity ?? currentIdentity;
1216
- const hasBoxedScalars = original?.hasBoxedScalars === true;
1217
- const changedCapture = original && original.wire !== wireJson(currentIdentity);
1218
- const originalKey = changedCapture || hasBoxedScalars
1219
- ? scopeKey(originalIdentity, canonicalJson)
1220
- : undefined;
1221
- let historicalOnly = false;
1222
- const originalWireKey = changedCapture
1223
- ? scopeKey(originalIdentity)
1224
- : undefined;
1225
- if (changedCapture && originalKey && originalWireKey) {
1226
- // A released SDK could stage either spelling. A modern approval for the
1227
- // fresh JSON can occupy the very same historical filename.
1228
- for (const pathKey of new Set([
1229
- originalKey,
1230
- originalWireKey,
1231
- localeKey(original.parsed.findings),
1232
- ])) {
1233
- const bytes = await readOptionalFile(pendingFile(pathKey));
1234
- if (bytes === undefined)
1235
- continue;
1236
- const record = JSON.parse(bytes);
1237
- if ((record?.legacyApproval &&
1238
- (record.wireKey ?? pathKey) === originalWireKey) ||
1239
- (record?.wireKey === undefined &&
1240
- record?.inputProjection?.identityFormat !== 2 &&
1241
- (pathKey === originalKey ||
1242
- pathKey === originalWireKey ||
1243
- original.parsed.report === undefined ||
1244
- record?.inputProjection?.inputDigest ===
1245
- jsonDigest(originalIdentity, canonicalJson)))) {
1246
- parsed = legacyParsed = original.parsed;
1247
- currentIdentity = legacyIdentity = original.identity;
1248
- historicalOnly = true;
1249
- break;
1250
- }
1251
- }
1252
- }
1253
- if (input.freshError && !historicalOnly)
1254
- throw input.freshError;
1255
- const inputDigest = jsonDigest(currentIdentity);
1256
- const legacyInputDigest = currentIdentity === legacyIdentity
1257
- ? inputDigest
1258
- : jsonDigest(legacyIdentity);
1259
- function matchesSavedDestination(requests) {
1260
- return (requests.length > 0 &&
1261
- requests.every((batch) => batch.repository.id === destination.id &&
1262
- batch.repository.repo_connector_id ===
1263
- destination.repo_connector_id &&
1264
- wireJson(batch.source) === wireJson(source)));
1265
- }
1266
- const originalHostedRetry = "This source has a pending hosted Cloud request. Resume it with the SDK build that created it and the original input before publishing another selection.";
1267
- const unknownHostedRetry = "A pending hosted request matches this provider and repository, but its deployment could not be established. Resume it with the SDK build that created it, on the original deployment, using the full original input and metadata.";
1268
- function originalHostedPending(content, filenameKey) {
1269
- const projection = content.inputProjection;
1270
- if ((options.provider !== "semgrep" && options.provider !== "snyk") ||
1271
- content.accountId !== credentials.account_id ||
1272
- !projection ||
1273
- !content.requests?.length ||
1274
- !content.requests.every(({ repository, source: savedSource }) => repository.id === destination.id &&
1275
- repository.repo_connector_id === destination.repo_connector_id &&
1276
- canonicalJson(savedSource) === canonicalJson(source)))
1277
- return false;
1278
- const findings = submissionFindings(content.requests);
1279
- if (projection.savedEvidenceDigest !== hash("sha256", canonicalJson(findings)))
1280
- return false;
1281
- const projections = [findings];
1282
- // Historical filenames include caller fields discarded by request validation.
1283
- // Reuse them by stable ID with the evidence and order of the approved request.
1284
- const metadata = new Map(legacyParsed.findings
1285
- .filter((row) => Object.keys(row).some((key) => key !== "evidence" && key !== "source_finding_id"))
1286
- .map((row) => [row.source_finding_id, row]));
1287
- if (findings.some((row) => metadata.has(row.source_finding_id)))
1288
- projections.push(findings.map((row) => ({
1289
- ...metadata.get(row.source_finding_id),
1290
- ...row,
1291
- })));
1292
- const identities = [...projections];
1293
- if (parsed.report !== undefined) {
1294
- const report = reportForJson(parsed.report);
1295
- identities.push(...projections.map((rows) => ({ findings: rows, report })));
1296
- }
1297
- // Caller metadata on a normalized finding is part of the filename but not the
1298
- // request body. An exact retry still supplies that original identity.
1299
- if (filenameKey === scopeKey(legacyIdentity))
1300
- identities.unshift(legacyIdentity);
1301
- const identity = identities.find((value) => filenameKey === scopeKey(value));
1302
- const digest = (value) => hash("sha256", canonicalJson(value));
1303
- const semgrep = options.provider === "semgrep";
1304
- const isHosted = (row) => semgrep
1305
- ? isSemgrepPlatformEvidence(row, "semgrep")
1306
- : isSnykRestFinding(row);
1307
- const scannerId = (row) => isHosted({
1308
- ...row,
1309
- evidence: { ...row.evidence, source_data: undefined },
1310
- });
1311
- const hasNativeEvidence = (row) => {
1312
- const data = row.evidence.source_data;
1313
- // A discriminator alone cannot identify a native occurrence.
1314
- return (data &&
1315
- isHosted({
1316
- source_finding_id: "",
1317
- evidence: {
1318
- ...row.evidence,
1319
- source_data: { ...data, format: undefined },
1320
- },
1321
- }));
1322
- };
1323
- const references = hostedSourceReferences(readerSources, content.approvedRepositoryUrl ?? destination.url, content.approvedRepositoryPlatform);
1324
- const occurrenceIds = (rows) => {
1325
- const ids = new Set(rows.map((row) => row.source_finding_id));
1326
- let native = false;
1327
- let unresolved = false;
1328
- for (const row of rows) {
1329
- if (!hasNativeEvidence(row))
1330
- continue;
1331
- native = true;
1332
- try {
1333
- const id = semgrep
1334
- ? semgrepPlatformFindingBinding({ ...row, source_finding_id: "" }, "semgrep", references, undefined, undefined, undefined, "cloud")?.nativeId
1335
- : snykRestCheckpointFindingId(row, references);
1336
- if (id) {
1337
- ids.add(id);
1338
- continue;
1339
- }
1340
- }
1341
- catch {
1342
- // An earlier SDK may have accepted a partial native projection.
1343
- }
1344
- if (!scannerId(row))
1345
- unresolved = true;
1346
- }
1347
- return { ids, native, unresolved };
1348
- };
1349
- const previous = occurrenceIds(findings);
1350
- const requested = occurrenceIds(parsed.findings);
1351
- const hostedSelection = projection.retainedHostedSelection ||
1352
- scopedSemgrepReport ||
1353
- previous.native ||
1354
- requested.native;
1355
- // Submitted and native IDs share one namespace even when one side drops its raw evidence.
1356
- const couldOverlap = (hostedSelection &&
1357
- Array.from(requested.ids).some((id) => previous.ids.has(id))) ||
1358
- (previous.native &&
1359
- requested.native &&
1360
- (previous.unresolved || requested.unresolved));
1361
- if (content.approvedRepositoryUrl && !projection.retainedHostedSelection) {
1362
- if (!couldOverlap)
1363
- return false;
1364
- if (identity)
1365
- return projection.inputDigest === digest(identity) && "verified";
1366
- // The filename includes metadata omitted from the saved request. A reproducible
1367
- // original digest under another filename proves this is another deployment.
1368
- return (!identities.some((value) => digest(value) === projection.inputDigest) &&
1369
- "unidentified");
1370
- }
1371
- if (identity && projection.inputDigest !== digest(identity))
1372
- return ((couldOverlap || !previous.native || !requested.native) && "verified");
1373
- if (!couldOverlap)
1374
- return false;
1375
- if (!identity) {
1376
- // If the saved selections reconstruct an old input digest but not its scoped
1377
- // filename, the pending request belongs to another deployment. The older
1378
- // publisher included its repository comparison flags in the digest.
1379
- const repositories = new Set([destination.url]);
1380
- for (const { evidence } of findings) {
1381
- const data = evidence.source_data;
1382
- const project = data?.["project"];
1383
- const retained = (semgrep && isRecord(project) ? project["url"] : undefined) ??
1384
- data?.["sourceRepositoryUrl"];
1385
- if (typeof retained === "string")
1386
- repositories.add(retained);
1387
- }
1388
- const paths = semgrep ? [null, true] : [false, true];
1389
- const suffixes = semgrep ? [false] : [false, true];
1390
- for (const candidate of identities) {
1391
- if (digest(candidate) === projection.inputDigest)
1392
- return false;
1393
- for (const strict of paths) {
1394
- for (const suffix of suffixes) {
1395
- for (const repository of repositories) {
1396
- const url = hostedRepositoryUrlKey(repository, !strict, suffix);
1397
- if (digest([candidate, [url, strict, suffix]]) ===
1398
- projection.inputDigest)
1399
- return false;
1400
- }
1401
- }
1402
- }
1403
- }
1404
- return "unidentified";
1405
- }
1406
- return "verified";
1407
- }
1408
764
  function wasReset(content) {
1409
765
  return content.requests.some(({ repository }) => repository.reset_marker !== destination.reset_marker);
1410
766
  }
@@ -1428,21 +784,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
1428
784
  ]
1429
785
  : null));
1430
786
  }
1431
- async function retireIfReset(content, retire) {
1432
- if (wasReset(content)) {
1433
- if (hosted)
1434
- await confirmReset();
1435
- await retire();
1436
- throw new CloudImportError(409, "The repository was reset after this submission. The saved request was retired without uploading. Review the destination and run the command again to approve a fresh publication.");
1437
- }
1438
- }
1439
- function retirePendingIfReset(content, keys, path, remove = () => rm(path)) {
1440
- return retireIfReset(content, () => underLocks(keys, async () => {
1441
- const bytes = await readOptionalFile(path);
1442
- if (bytes !== undefined && sameSubmission(JSON.parse(bytes), content))
1443
- await remove();
1444
- }));
1445
- }
1446
787
  function readSaved(content) {
1447
788
  if (!content ||
1448
789
  content.accountId !== credentials.account_id ||
@@ -1450,592 +791,77 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
1450
791
  content.requests.length === 0)
1451
792
  throw new Error("Saved import account or requests do not match.");
1452
793
  content.requests = content.requests.map(validateImportRequest);
1453
- for (const finding of submissionFindings(content.requests))
794
+ const actual = submissionFindings(content.requests);
795
+ for (const finding of actual)
1454
796
  checkRetainedTrivyProvider(options.provider, finding);
1455
- if (!matchesSavedDestination(content.requests))
797
+ if (content.requests.some((batch) => batch.repository.id !== destination.id ||
798
+ batch.repository.repo_connector_id !==
799
+ destination.repo_connector_id ||
800
+ canonicalJson(batch.source) !== canonicalJson(source)))
1456
801
  throw new Error("Saved import destination does not match.");
1457
- if (source.provider === "trivy" && !content.trivyRepositoryUrl)
1458
- throw new CodexSecurityError("This build cannot verify the original repository for this pending Trivy import. Check its destination before resuming with the build that created it.");
1459
- return content;
1460
- }
1461
- function validateSaved(record, legacy = false, filenameKey = key) {
1462
- const content = readSaved(record);
1463
- const saved = submissionFindings(content.requests);
1464
- const wire = wireJson(saved);
1465
- const projection = content.inputProjection;
1466
- const expected = repositoryFindings(legacy ? legacyParsed : parsed, projection?.repositorySeverities);
1467
- if (projection &&
1468
- (!sameFindingSelection(saved, expected) ||
1469
- projection.inputDigest !== (legacy ? legacyInputDigest : inputDigest) ||
1470
- projection.savedEvidenceDigest !== hash("sha256", wire))) {
1471
- const status = originalHostedPending(content, filenameKey);
1472
- if (status === "unidentified")
1473
- throw new CodexSecurityError(unknownHostedRetry);
1474
- if (status) {
1475
- if (wasReset(content))
1476
- return content;
1477
- throw new CodexSecurityError(originalHostedRetry);
1478
- }
1479
- throw new Error("Saved import evidence does not match the selected input.");
1480
- }
1481
- // Older file readers can have a different, explicitly bound projection.
1482
- // A corrected numeric checkpoint must carry the selected evidence verbatim.
1483
- const exactWire = historicalOnly || hasBoxedScalars || content.wireKey !== undefined;
1484
- if ((!projection || exactWire) &&
1485
- wire !== wireJson(exactWire ? expected.map(wireFinding) : expected))
1486
- throw new Error("Saved import evidence does not match the selected input.");
1487
- if (!legacy &&
1488
- hasBoxedScalars &&
1489
- projection?.identityFormat !== 2 &&
1490
- !verifiableLegacyMetadata(originalParsed, true))
1491
- throw unmatchedPreviousNumbers();
1492
- checkFindingProvider({ ...parsed, findings: saved }, options.provider);
1493
- const approvedScope = content.inputProjection?.semgrepPartialScopeDigest;
1494
- if (approvedScope !== undefined &&
802
+ checkFindingProvider({ ...parsed, findings: actual }, options.provider);
803
+ const expected = repositoryFindings(parsed, content.repositorySeverities);
804
+ if (canonicalJson(actual) !== canonicalJson(expected.map(wireFinding)))
805
+ throw new CodexSecurityError("Saved import evidence does not match the selected input.");
806
+ const scope = content.semgrepPartialScopeDigest;
807
+ if (scope !== undefined &&
1495
808
  !wasReset(content) &&
1496
- approvedScope !== suppliedSemgrepScopeDigest())
809
+ scope !== suppliedSemgrepScopeDigest())
1497
810
  throw new CodexSecurityError("The supplied Semgrep report scope does not match the approved request.");
1498
811
  return content;
1499
812
  }
1500
- // The original filename and digests identify the previous selection, but
1501
- // contained {} for every boxed number. Only its actual saved request can
1502
- // prove which numbers were approved.
1503
- function readPreviousNumbers(record) {
1504
- const content = readSaved(record);
1505
- const projection = content.inputProjection;
1506
- const saved = submissionFindings(content.requests);
1507
- const savedWire = wireJson(saved);
1508
- const wireDigest = hash("sha256", savedWire);
1509
- if (projection?.inputDigest !== jsonDigest(originalIdentity, canonicalJson))
1510
- throw unmatchedPreviousNumbers();
1511
- if (projection.identityFormat === 2) {
1512
- // A current writer may own the old filename for an ordinary object.
1513
- if (projection.savedEvidenceDigest === wireDigest)
1514
- return undefined;
1515
- throw unmatchedPreviousNumbers();
1516
- }
1517
- const selected = originalParsed.findings.map(wireFinding);
1518
- if (projection.savedEvidenceDigest !== jsonDigest(selected, canonicalJson))
1519
- throw unmatchedPreviousNumbers();
1520
- if (savedWire !== wireJson(selected)) {
1521
- // A genuinely empty object at this key is a separate ordinary selection.
1522
- if (wireDigest === projection.savedEvidenceDigest)
1523
- return undefined;
1524
- return "different-wire";
1525
- }
1526
- if ((changedCapture && !historicalOnly) ||
1527
- !verifiableLegacyMetadata(originalParsed, false))
1528
- throw unmatchedPreviousNumbers();
1529
- checkFindingProvider({ ...parsed, findings: saved }, options.provider);
1530
- content.legacyApproval = true;
1531
- content.inputProjection = {
1532
- ...content.inputProjection,
1533
- identityFormat: 2,
1534
- inputDigest,
1535
- savedEvidenceDigest: wireDigest,
1536
- };
1537
- return content;
1538
- }
1539
- function unmatchedPreviousNumbers() {
1540
- return new CodexSecurityError("The older saved import cannot be matched to the selected input. Its checkpoint was preserved without uploading.");
1541
- }
1542
- const key = scopeKey(currentIdentity);
1543
- const stagingKey = originalKey ?? key;
1544
- const canonicalPath = pendingFile(key);
1545
- const lookupPath = join(state, `${key}.lookup.json`);
1546
- // A lookup only suggests a regular file to validate. A missing or stale hint
1547
- // leaves the same on-disk discovery available as before.
1548
- async function readOptionalRegularFile(path) {
1549
- try {
1550
- if ((await lstat(path)).isFile())
1551
- return await readFile(path, "utf8");
1552
- }
1553
- catch {
1554
- // Optional discovery must not veto an independently verified checkpoint.
1555
- }
1556
- }
1557
- async function lookupFileKey() {
1558
- const serialized = await readOptionalRegularFile(lookupPath);
1559
- return serialized?.trim().match(/^"([a-f0-9]{64})"$/u)?.[1];
1560
- }
1561
- const historicalKey = localeKey(legacyParsed.findings);
1562
- const legacyIdentityKey = scopeKey(legacyIdentity);
1563
- const legacyKeys = new Set([legacyIdentityKey, historicalKey]);
1564
- function underLocks(keys, operation) {
1565
- return withImportLocks(state, keys, dependencies.signal, operation);
813
+ async function readPending() {
814
+ const bytes = await readOptionalFile(pendingPath);
815
+ return bytes === undefined ? undefined : readSaved(JSON.parse(bytes));
1566
816
  }
1567
- let recovered;
1568
- for (const legacyKey of legacyKeys) {
1569
- if (legacyKey === key || legacyKey === originalKey)
1570
- continue;
1571
- const legacyPath = pendingFile(legacyKey);
1572
- const captured = await readOptionalFile(legacyPath);
1573
- if (captured !== undefined) {
1574
- // Preserve requests staged by the earlier locale-based filename format.
1575
- // Hold both publication locks while moving the original checkpoint.
1576
- await underLocks([key, legacyKey], async () => {
1577
- const current = await readOptionalFile(canonicalPath);
1578
- const serialized = await readOptionalFile(legacyPath);
1579
- let prior;
1580
- if (serialized !== undefined) {
1581
- try {
1582
- prior = JSON.parse(serialized);
1583
- }
1584
- catch (error) {
1585
- if (current === undefined || !(error instanceof SyntaxError))
1586
- throw error;
1587
- }
1588
- }
1589
- if (prior?.wireKey !== undefined)
1590
- return;
1591
- if (current !== undefined) {
1592
- recovered = validateSaved(JSON.parse(current));
1593
- if (prior && sameSubmission(prior, recovered))
1594
- await rm(legacyPath);
1595
- return;
1596
- }
1597
- // A report-free approval at the locale-era filename can be a separate input.
1598
- if (legacyKey !== legacyIdentityKey &&
1599
- prior?.inputProjection &&
1600
- prior.inputProjection.inputDigest !== legacyInputDigest) {
1601
- const projection = prior.inputProjection;
1602
- const rows = legacyParsed.findings;
1603
- if (projection.identityFormat === 2 ||
1604
- (projection.inputDigest === jsonDigest(rows) &&
1605
- projection.savedEvidenceDigest ===
1606
- jsonDigest(submissionFindings(prior.requests))))
1607
- return;
1608
- // The released SDK hashed report-free rows as an array and boxed scores as {}.
1609
- const originalRows = original?.parsed.findings ?? rows;
1610
- if (hasBoxedScalars &&
1611
- legacyParsed.report !== undefined &&
1612
- legacyKey === scopeKey(originalRows, canonicalJson) &&
1613
- projection.inputDigest ===
1614
- jsonDigest(originalRows, canonicalJson) &&
1615
- projection.savedEvidenceDigest ===
1616
- jsonDigest(originalRows.map(wireFinding), canonicalJson) &&
1617
- sameFindingSelection(submissionFindings(readSaved(prior).requests), rows))
1618
- return;
1619
- }
1620
- const content = validateSaved(serialized === undefined ? JSON.parse(captured) : prior, true, legacyKey);
1621
- if (!sameFindingSelection(legacyParsed.findings, parsed.findings))
1622
- throw new CodexSecurityError("The saved import selects different findings from this input. Resume the original selection before publishing this selection.");
1623
- await retireIfReset(content, async () => {
1624
- if (serialized !== undefined)
1625
- await rm(legacyPath);
1626
- });
1627
- const savedEvidenceDigest = content.inputProjection?.savedEvidenceDigest ??
1628
- jsonDigest(legacyParsed.findings);
1629
- const rebindProjection = content.inputProjection !== undefined ||
1630
- savedEvidenceDigest !== inputDigest;
1631
- if (rebindProjection) {
1632
- if (content.inputProjection?.identityFormat !== 2)
1633
- content.legacyApproval = true;
1634
- content.inputProjection = {
1635
- ...content.inputProjection,
1636
- identityFormat: 2,
1637
- inputDigest,
1638
- savedEvidenceDigest,
1639
- };
1640
- }
1641
- recovered = content;
1642
- if (serialized === undefined)
1643
- return;
1644
- await withSourceAdmission(async () => {
1645
- if (!rebindProjection) {
1646
- await rename(legacyPath, canonicalPath);
1647
- }
1648
- else {
1649
- // Bind the new input projection to the original immutable evidence,
1650
- // so later inventory reordering still resumes these exact requests.
1651
- await writeAtomicJson(canonicalPath, content);
1652
- await rm(legacyPath);
1653
- }
1654
- });
1655
- });
1656
- }
1657
- }
1658
- // Some getter-backed batches cannot reproduce a released filename. Their IDs
1659
- // can stop a conflicting upload, but never authorize replay of a saved request.
1660
- const potentialIds = input.potentialIds === undefined && changedCapture
1661
- ? original.parsed.findings.map((row) => row.source_finding_id)
1662
- : input.potentialIds;
1663
- const unprovenPrefixes = new Set(input.unprovenIdPrefixes);
1664
- const uncertainIds = new Set(input.uncertainFindingIds);
1665
- const uncertainMembership = input.unprovenOccurrenceCount ||
1666
- uncertainIds.size > 0 ||
1667
- unprovenPrefixes.size > 0;
1668
- function uncertainId(id) {
1669
- return (uncertainIds.has(id) ||
1670
- unprovenPrefixes.has(id.replace(/\/[a-f0-9]{64}$/u, "/")));
1671
- }
1672
- const stableIds = uncertainMembership
1673
- ? (potentialIds ?? parsed.findings.map((row) => row.source_finding_id)).filter((id) => id === undefined || !uncertainId(id))
1674
- : undefined;
1675
- const knownMembership = input.unprovenOccurrenceCount
1676
- ? new Set(stableIds)
1677
- : undefined;
1678
- const knownRows = new Map(input.knownFindings?.map((row) => [
1679
- row.source_finding_id,
1680
- wireFinding(row),
1681
- ]));
1682
- let originalInputDigest;
1683
- const cannotCaptureOriginal = !input.original &&
1684
- (potentialIds === null || !!(potentialIds?.length || uncertainMembership));
1685
- const possibleBufferExport = options.provider === "github" && original && !changedCapture;
1686
- function potentialOriginal(record, fileKey) {
1687
- const projection = record.inputProjection;
1688
- if (record.accountId !== credentials.account_id)
1689
- return false;
1690
- if (!projection) {
1691
- // Locale-era requests had no projection. Their scoped occurrence IDs
1692
- // can stop an opaque retry but cannot authorize replay.
1693
- if (!cannotCaptureOriginal || record.wireKey !== undefined)
1694
- return false;
1695
- }
1696
- else if (!/^[a-f0-9]{64}$/u.test(projection.inputDigest) ||
1697
- !/^[a-f0-9]{64}$/u.test(projection.savedEvidenceDigest) ||
1698
- (projection.identityFormat === 2 && !record.legacyApproval))
1699
- return false;
1700
- try {
1701
- // Older evidence may fail today's limits. Scope and selection can still
1702
- // identify an outstanding approval and prevent a duplicate submission.
1703
- if (!matchesSavedDestination(record.requests))
1704
- return false;
1705
- const rows = submissionFindings(record.requests);
1706
- const savedWire = wireJson(rows);
1707
- const evidenceMatches = projection &&
1708
- projection.savedEvidenceDigest === hash("sha256", savedWire);
1709
- if (evidenceMatches) {
1710
- // Matching old digests reconstruct its scoped filename. A report from
1711
- // this caller is useful only when the saved digest independently binds it.
1712
- const reportFree = projection.inputDigest === projection.savedEvidenceDigest;
1713
- const identity = reportFree
1714
- ? rows
1715
- : parsed.report !== undefined
1716
- ? { findings: rows, report: reportForJson(parsed.report) }
1717
- : undefined;
1718
- if (identity &&
1719
- (reportFree || projection.inputDigest === jsonDigest(identity))) {
1720
- if (record.wireKey
1721
- ? record.wireKey !== scopeKey(identity)
1722
- : fileKey !== scopeKey(identity, canonicalJson) &&
1723
- fileKey !== localeKey(rows))
1724
- return false;
1725
- if (possibleBufferExport &&
1726
- projection.inputDigest !== inputDigest &&
1727
- sameLegacyJson(identity, currentIdentity, previousBufferJson)) {
1728
- return true;
1729
- }
1730
- }
1731
- if (!record.wireKey &&
1732
- reportFree &&
1733
- original &&
1734
- original.wire !== savedWire)
1735
- return false;
1736
- }
1737
- if (record.wireKey && !cannotCaptureOriginal)
1738
- return false;
1739
- if (projection &&
1740
- original &&
1741
- fileKey !== stagingKey &&
1742
- fileKey !== originalWireKey &&
1743
- projection.inputDigest ===
1744
- (originalInputDigest ??= jsonDigest(original.identity, canonicalJson)) &&
1745
- fileKey !== localeKey(original.parsed.findings) &&
1746
- projection.savedEvidenceDigest ===
1747
- jsonDigest(original.parsed.findings.map(wireFinding), canonicalJson) &&
1748
- savedWire === wireJson(original.parsed.findings.map(wireFinding)))
1749
- return false;
1750
- if (stableIds) {
1751
- // An opaque occurrence may have had a different old ID. Compare all
1752
- // definite members and count the remaining IDs without claiming them.
1753
- const certain = rows.filter((row) => !uncertainId(row.source_finding_id));
1754
- const stableSaved = knownMembership
1755
- ? certain.filter((row) => knownMembership.has(row.source_finding_id))
1756
- : certain;
1757
- if (certain.length - stableSaved.length >
1758
- (input.unprovenOccurrenceCount ?? 0))
1759
- return false;
1760
- return (rows.length > 0 &&
1761
- stableSaved.length === stableIds.length &&
1762
- stableSaved.every((row, i) => {
1763
- const known = knownRows.get(row.source_finding_id);
1764
- return (row.source_finding_id === stableIds[i] &&
1765
- (!known || wireJson(row) === wireJson(known)));
1766
- }));
1767
- }
1768
- const candidates = originalParsed.findings;
1769
- const ids = potentialIds === undefined
1770
- ? parsed.findings.map((row) => row.source_finding_id)
1771
- : potentialIds;
1772
- if (ids &&
1773
- (!ids.length ||
1774
- rows.length !== ids.length ||
1775
- !rows.every((row, i) => ids[i] === undefined || row.source_finding_id === ids[i])))
1776
- return false;
1777
- // An opaque serializer can add a report or replace every visible field.
1778
- // Only scoped, independently known occurrences can rule out its old request.
1779
- if (cannotCaptureOriginal || !projection)
1780
- return true;
1781
- if (projection.inputDigest === projection.savedEvidenceDigest &&
1782
- parsed.report !== undefined)
1783
- return false;
1784
- if (potentialIds === undefined && (hasBoxedScalars || evidenceMatches))
1785
- return false;
1786
- return (!sameFindingSelection(rows, candidates) ||
1787
- rows.every((row, i) => {
1788
- const { source_data: savedData, ...savedFields } = row.evidence;
1789
- const { source_data: selectedData, ...selectedFields } = candidates[i].evidence;
1790
- if (wireJson(savedFields) !== wireJson(selectedFields))
1791
- return false;
1792
- // Once the original SDK discarded boxed positions, a plain JSON export
1793
- // alone cannot attribute a new numeric spelling to that saved request.
1794
- return sameLegacyJson(savedData, selectedData, (value) => typeof value === "number");
1795
- }));
1796
- }
1797
- catch {
1798
- return false;
1799
- }
817
+ async function readCompletedPublication(requests) {
818
+ const bytes = await readOptionalFile(join(state, key + ".result.json"));
819
+ if (bytes === undefined)
820
+ return;
821
+ const result = JSON.parse(bytes);
822
+ if ((result.status === "complete" || result.status === "partial") &&
823
+ result.receipts.length === requests.length &&
824
+ result.receipts.every((r, i) => r.id === requests[i].request_id))
825
+ return {
826
+ receipts: result.receipts.map((r, i) => validatePublicationReceipt(r, requests[i])),
827
+ verified: result.verified,
828
+ };
1800
829
  }
1801
- async function selectedCheckpoint(knownFileKey, preparing = false) {
1802
- const directory = await validatePreparedOutputDir(state, undefined, true).catch(nullIfMissingFile);
1803
- if (!directory)
1804
- return undefined;
1805
- const known = new Set([key, originalKey, knownFileKey].filter((value) => value !== undefined));
1806
- let unidentified = false;
1807
- let unprovenOriginal = false;
1808
- let incomplete = false;
1809
- let stagingPathOccupied = false;
1810
- async function readCandidate(fileKey, selected, contents) {
1811
- const path = pendingFile(fileKey);
1812
- const serialized = contents ??
1813
- (selected?.fileKey === key && !known.has(fileKey)
1814
- ? await readOptionalRegularFile(path)
1815
- : await readOptionalFile(path)) ??
1816
- (preparing && fileKey === key ? capturedPending : undefined);
1817
- if (serialized === undefined) {
1818
- if (!known.has(fileKey))
1819
- incomplete = true;
1820
- return selected;
1821
- }
1822
- if (fileKey === stagingKey)
1823
- stagingPathOccupied = true;
1824
- let record;
1825
- try {
1826
- record = JSON.parse(serialized);
1827
- }
1828
- catch (error) {
1829
- if (known.has(fileKey))
1830
- throw error;
1831
- incomplete = true;
1832
- return selected;
1833
- }
1834
- // A migrated checkpoint records the wire identity it belongs to even
1835
- // when a separate input hashes to its historical filename.
1836
- const tag = record?.wireKey;
1837
- const tagged = tag !== undefined;
1838
- const ownerKey = tagged ? tag : fileKey;
1839
- const historical = !tagged && fileKey === originalKey && fileKey !== key;
1840
- if (ownerKey !== key && !historical) {
1841
- if (hosted && record?.inputProjection) {
1842
- let status;
1843
- try {
1844
- status = originalHostedPending(record, ownerKey);
1845
- }
1846
- catch {
1847
- // An unrelated or unreadable checkpoint cannot identify this source.
1848
- }
1849
- if (status === "unidentified")
1850
- throw new CodexSecurityError(unknownHostedRetry);
1851
- if (status) {
1852
- if (wasReset(record)) {
1853
- if (!preparing)
1854
- throw new CodexSecurityError("The pending request and this preview have different repository reset markers. Review the destination again.");
1855
- await retirePendingIfReset(record, [fileKey], path);
1856
- }
1857
- throw new CodexSecurityError(originalHostedRetry);
1858
- }
1859
- }
1860
- if (record &&
1861
- (!tagged || cannotCaptureOriginal || possibleBufferExport) &&
1862
- potentialOriginal(record, fileKey))
1863
- unprovenOriginal = true;
1864
- // Some early locale filenames carry no deployment identity. Never guess their target.
1865
- if (!tagged &&
1866
- record &&
1867
- !record.inputProjection &&
1868
- !legacyKeys.has(fileKey)) {
1869
- try {
1870
- // A different locale cannot authorize replay, even when the
1871
- // original native capture proves these rows were selected.
1872
- if (!original ||
1873
- wireJson(submissionFindings(readSaved(record).requests)) !==
1874
- wireJson(original.parsed.findings.map(wireFinding)))
1875
- validateSaved(record, true);
1876
- unidentified = true;
1877
- }
1878
- catch {
1879
- /* Unrelated input. */
1880
- }
830
+ await validatePreparedOutputDir(state, undefined, true).catch(nullIfMissingFile);
831
+ const saved = await readPending();
832
+ if (saved && wasReset(saved)) {
833
+ await underPublishLock(async () => {
834
+ const current = await readPending();
835
+ if (current && sameSubmission(current, saved)) {
836
+ await confirmReset();
837
+ if (record && current.receipts?.length) {
838
+ await record({
839
+ cloudApiUrl,
840
+ accountId: credentials.account_id,
841
+ destination,
842
+ requests: current.requests,
843
+ findings: [],
844
+ }, acknowledgedReceipts(current));
1881
845
  }
1882
- return selected;
1883
- }
1884
- const content = historical
1885
- ? readPreviousNumbers(record)
1886
- : validateSaved(record);
1887
- if (content === "different-wire") {
1888
- // Another spelling may already have a verified checkpoint for this wire value.
1889
- unprovenOriginal = true;
1890
- return selected;
1891
- }
1892
- if (!content)
1893
- return selected;
1894
- if (selected) {
1895
- const conflict = new CodexSecurityError("Two saved imports match this input. Their original requests and receipts were preserved without uploading.");
1896
- if (!preparing)
1897
- throw conflict;
1898
- // The two unlocked reads may have straddled completion of the first request.
1899
- return await underLocks([key, selected.fileKey, fileKey], async () => {
1900
- const first = await readCandidate(selected.fileKey);
1901
- if (first) {
1902
- if (await readCandidate(fileKey))
1903
- throw conflict;
1904
- if (sameSubmission(first.content, selected.content))
1905
- return first;
1906
- }
1907
- return completedCheckpoint(selected);
1908
- });
1909
- }
1910
- return { fileKey, content, historical };
1911
- }
1912
- let selected;
1913
- for (const fileKey of known)
1914
- selected = await readCandidate(fileKey, selected);
1915
- // A known file that disappeared can be checked against its completed receipt.
1916
- if (!selected && knownFileKey !== undefined && !hosted)
1917
- return undefined;
1918
- const hint = await lookupFileKey();
1919
- if (hint && !known.has(hint)) {
1920
- const contents = await readOptionalRegularFile(pendingFile(hint));
1921
- if (contents !== undefined) {
1922
- selected = await readCandidate(hint, selected, contents);
1923
- known.add(hint);
1924
- }
1925
- }
1926
- // A released publisher could stage the canonical request while another SDK
1927
- // tagged its old filename but had not yet written the optional lookup.
1928
- if (selected &&
1929
- !cannotCaptureOriginal &&
1930
- !selected.historical &&
1931
- (selected.fileKey !== key ||
1932
- selected.content.canonicalChecked ||
1933
- selected.content.inputProjection?.identityFormat === 2))
1934
- return selected;
1935
- const entries = (await readdir(state, { withFileTypes: true }).catch(nullIfMissingFile)) ?? [];
1936
- for (const entry of entries) {
1937
- if (!entry.isFile() || !/^[a-f0-9]{64}\.pending\.json$/u.test(entry.name))
1938
- continue;
1939
- const fileKey = entry.name.slice(0, -".pending.json".length);
1940
- if (!known.has(fileKey))
1941
- selected = await readCandidate(fileKey, selected);
1942
- }
1943
- if (unprovenOriginal && (!selected || cannotCaptureOriginal))
1944
- throw unmatchedPreviousNumbers();
1945
- if (!selected && stagingPathOccupied)
1946
- throw occupiedCheckpoint();
1947
- if (!selected && unidentified)
1948
- throw new CodexSecurityError("An older pending import matches this input, but its checkpoint identity could not be established. Resume it using the original deployment and locale before publishing this selection. The saved request was preserved without uploading.");
1949
- if (selected?.fileKey === key && !preparing && !incomplete)
1950
- selected.checkedCanonical = true;
1951
- return selected;
1952
- }
1953
- async function readCompletedPublication(requests, observedKey) {
1954
- for (const resultKey of new Set([key, observedKey])) {
1955
- const serialized = await readOptionalFile(join(state, `${resultKey}.result.json`));
1956
- if (serialized === undefined)
1957
- continue;
1958
- const completed = JSON.parse(serialized);
1959
- if ((completed?.status === "complete" || completed?.status === "partial") &&
1960
- Array.isArray(completed.receipts) &&
1961
- completed.receipts.length === requests.length &&
1962
- completed.receipts.every((receipt, i) => receipt?.id === requests[i].request_id))
1963
- return {
1964
- receipts: completed.receipts.map((receipt, i) => validatePublicationReceipt(receipt, requests[i])),
1965
- verified: completed.verified,
1966
- };
1967
- }
1968
- }
1969
- async function completedCheckpoint(observed) {
1970
- if (await readCompletedPublication(observed.content.requests, observed.fileKey))
1971
- return observed;
1972
- throw new CodexSecurityError("The saved publication changed while preparing this input. Review it again.");
1973
- }
1974
- function occupiedCheckpoint() {
1975
- return new CodexSecurityError("Finish the other pending import at this checkpoint first, then review this input again.");
1976
- }
1977
- let selected = await selectedCheckpoint(recovered ? key : undefined, true);
1978
- const fileKey = selected?.fileKey ?? (recovered ? key : stagingKey);
1979
- const pendingPath = pendingFile(fileKey);
1980
- async function rememberFile() {
1981
- if (fileKey !== key && (await lookupFileKey()) !== fileKey)
1982
- await writeAtomicJson(lookupPath, fileKey).catch(() => undefined);
1983
- }
1984
- async function removePending() {
1985
- await rm(pendingPath, { force: true });
1986
- if (fileKey !== key && (await lookupFileKey()) === fileKey)
1987
- await rm(lookupPath, { force: true }).catch(() => undefined);
1988
- }
1989
- const lockKeys = [key, fileKey, stagingKey];
1990
- if (alternateKey)
1991
- lockKeys.push(alternateKey);
1992
- async function underPublishLocks(operation) {
1993
- // An older publisher may already hold its lock before its checkpoint exists.
1994
- // Derive that key for actual writes, even after a checkpoint-free preview.
1995
- if (resolved.readPreviousFindings && !previousFindings) {
1996
- previousFindings = resolved.readPreviousFindings();
1997
- alternateKey = previousCandidateKey(previousFindings);
1998
- if (alternateKey)
1999
- lockKeys.push(alternateKey);
2000
- }
2001
- return underLocks(lockKeys, operation);
2002
- }
2003
- if (selected?.historical) {
2004
- const observed = selected;
2005
- selected = await underLocks(lockKeys, async () => {
2006
- const current = await selectedCheckpoint(fileKey);
2007
- if (!current ||
2008
- current.fileKey !== fileKey ||
2009
- !sameSubmission(current.content, observed.content))
2010
- return completedCheckpoint(observed);
2011
- if (current.historical) {
2012
- current.content.wireKey = key;
2013
- await writeAtomicJson(pendingPath, current.content);
2014
- await rememberFile();
846
+ await removePending();
2015
847
  }
2016
- return current;
2017
848
  });
849
+ throw new CloudImportError(409, "The repository was reset after this submission. The saved request was retired without uploading. Review the destination and run the command again to approve a fresh publication.");
2018
850
  }
2019
- const saved = selected?.content ?? recovered;
2020
- if (historicalOnly && !saved)
2021
- throw unmatchedPreviousNumbers();
2022
- if (!parsed.findings.length)
2023
- throw new NoPublishableFindingsError(parsed);
2024
- if (saved)
2025
- await retirePendingIfReset(saved, lockKeys, pendingPath, removePending);
2026
851
  if (saved?.inspectorProjectMapRequired && !inspectorProjectMap)
2027
852
  throw new CodexSecurityError("Supply the verified Inspector project binding again to resume.");
2028
853
  // Existing repository submissions keep their original request bodies and receipts.
2029
854
  const privatePath = join(state, `${key}.private-import.json`);
2030
- const privateSaved = await readOptionalFile(privatePath);
2031
- if (resumingPreviousReader && !saved && privateSaved === undefined)
2032
- throw new CodexSecurityError("The saved publication changed. Run the command again to preview this report.");
855
+ const readPrivate = async () => parsePrivateCheckpoint(await readOptionalFile(privatePath));
856
+ const privateSaved = await readPrivate();
2033
857
  const usePrivateImport = !saved && (canStartJob || privateSaved !== undefined);
2034
858
  async function preparePrivateAttempt() {
2035
- const context = previewContext ?? (await privateClient.context());
859
+ const context = await privateClient.context();
2036
860
  if (source.source_key.trim() !== source.source_key)
2037
861
  throw new CodexSecurityError("A private source key cannot have leading or trailing whitespace.");
2038
- const report = await selectPrivateReport(parsed, source.provider, nativePath, context, privateSaved, resolved.requiresStructuredReport);
862
+ const report = selectPrivateReport(parsed.findings, source.provider, context, privateSaved?.contextVersion === context.context_version
863
+ ? privateSaved.format
864
+ : undefined);
2039
865
  const binding = {
2040
866
  format: report.format,
2041
867
  apiBaseUrl,
@@ -2055,15 +881,15 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2055
881
  }
2056
882
  // Use an earlier catalog URL only after the account, connector, repository,
2057
883
  // inbox context and exact upload digest all match the immutable checkpoint.
2058
- const existingPrivate = usePrivateImport && privateSaved !== undefined
884
+ const privateAttempt = usePrivateImport
2059
885
  ? await preparePrivateAttempt()
2060
886
  : undefined;
2061
- const previous = existingPrivate &&
2062
- readPrivateCheckpoint(privateSaved, existingPrivate.binding);
887
+ const previous = privateAttempt &&
888
+ readPrivateCheckpoint(privateSaved, privateAttempt.binding);
2063
889
  const retryOfJobId = unsuccessfulJob(previous?.receipt) &&
2064
890
  canStartJob &&
2065
- existingPrivate?.context.can_upload &&
2066
- acceptsJob(existingPrivate.context, existingPrivate.report.format)
891
+ privateAttempt?.context.can_upload &&
892
+ acceptsJob(privateAttempt.context, privateAttempt.report.format)
2067
893
  ? previous?.jobId
2068
894
  : undefined;
2069
895
  const resumed = previous !== undefined && retryOfJobId === undefined;
@@ -2073,63 +899,19 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2073
899
  privateApproval?.approvedRepositoryPlatform;
2074
900
  // The findings-only checkpoint key lets projected and native callers resume one immutable
2075
901
  // request. Supplemental report claims are outside that digest and must still match its source.
2076
- const recheckOriginal = options.provider === "semgrep" &&
2077
- projection !== resolved &&
2078
- saved?.approvedRepositoryPlatform === "other";
2079
- // Native Semgrep and OpenGrep files include their required source URL in every
2080
- // saved finding. An exact replay by repository ID survives a catalog rename.
2081
- const recordedFileSource = saved &&
2082
- !saved.approvedRepositoryUrl &&
2083
- options.provider === "semgrep" &&
2084
- !deferred &&
2085
- declaredUrl !== undefined &&
2086
- saved.requests.every(({ items }) => items.every(({ evidence }) => evidence.details?.repository?.url === declaredUrl));
2087
- const declaredSource = recheckOriginal ||
2088
- readerSources.length > 0 ||
2089
- (declaredUrl !== undefined && !recordedFileSource) ||
2090
- report.sourceRepositoryUrl !== undefined ||
2091
- report.sourceRepositoryPlatform !== undefined ||
2092
- report.snykRestContext !== undefined;
2093
- let legacyTypedUrl;
2094
- let suppliedReport = report;
2095
- const sourceFor = (url, platform) => {
2096
- try {
2097
- return hostedRepositoryMatcher(platform
2098
- ? { ...suppliedReport, sourceRepositoryPlatform: platform }
2099
- : suppliedReport, options.provider, declaredUrl, { url }, readerSources, saved !== undefined);
2100
- }
2101
- catch (error) {
2102
- if (!recheckOriginal || readerSources.length)
2103
- throw error;
2104
- // An older strict approval did not distinguish GitLab from another case-sensitive SCM.
2105
- throw new CodexSecurityError(`${error instanceof Error ? error.message : String(error)} Resume with the original Semgrep input and SCM repository mapping, or the SDK build that created this request.`, { cause: error });
2106
- }
2107
- };
2108
- if (hosted && saved && declaredSource) {
2109
- // The released publisher checked typed repository URLs against its authenticated catalog.
2110
- // Opaque original records could name a different project and cannot establish a rename.
2111
- const findings = submissionFindings(saved.requests);
2112
- if (!saved.approvedRepositoryUrl)
2113
- legacyTypedUrl = findings.find(({ evidence }) => evidence.details?.repository?.url)?.evidence.details?.repository?.url;
2114
- // Supplemental claims must agree with each verifiable row from the immutable request.
2115
- suppliedReport = {
2116
- ...report,
2117
- // The v1 upgrade may drop a redundant mapping using the catalog's GitHub casing.
2118
- findings: recheckOriginal ? [...report.findings, ...findings] : findings,
2119
- };
2120
- }
2121
- // The released request retained its typed finding URL, but only the authenticated
2122
- // catalog or a previously recorded approval can bind a new source declaration.
2123
- const approvedUrl = saved?.approvedRepositoryUrl ?? privateUrl ?? destination.url;
2124
- if (hosted &&
2125
- readerSources.some(({ platform, url }) => {
2126
- const source = normalizeHostedGitRepositoryUrl(url, approvedUrl, platform !== undefined);
2127
- return (cloudSourceKey(source, platform) !==
2128
- cloudSourceKey(approvedUrl, platform));
2129
- }))
902
+ const approvedUrl = saved?.approvedRepositoryUrl ??
903
+ saved?.trivyRepositoryUrl ??
904
+ privateUrl ??
905
+ destination.url;
906
+ const sourceFor = (url, platform) => hostedRepositoryMatcher(platform ? { ...report, sourceRepositoryPlatform: platform } : report, options.provider, declaredUrl, { url }, readerSources);
907
+ if (readerSources.some(({ platform, url }) => {
908
+ const source = normalizeHostedGitRepositoryUrl(url, approvedUrl, platform !== undefined);
909
+ return (cloudSourceKey(source, platform) !==
910
+ cloudSourceKey(approvedUrl, platform));
911
+ }))
2130
912
  throw new CodexSecurityError("The reader's source repository does not match the selected Cloud repository.");
2131
- await recheckFileRepository?.(approvedUrl, approvedPlatform);
2132
- const hostedSource = hosted && (!saved || declaredSource)
913
+ await resolved.recheckFileRepository?.(approvedUrl, approvedPlatform);
914
+ const hostedSource = hosted
2133
915
  ? sourceFor(approvedUrl, approvedPlatform)
2134
916
  : undefined;
2135
917
  const matchesHostedRepository = hostedSource?.matches;
@@ -2141,8 +923,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2141
923
  throw new CodexSecurityError("The source project does not match the selected Cloud repository.");
2142
924
  }
2143
925
  requireApprovedSource(approvedUrl);
2144
- if (legacyTypedUrl)
2145
- requireApprovedSource(legacyTypedUrl);
2146
926
  const trivyTarget = saved?.trivyRepositoryUrl ?? privateUrl ?? destination.url;
2147
927
  function requireTrivyRemote(url, id) {
2148
928
  if (trivyRemoteKey(url, trivyTarget) !== catalogKey(trivyTarget)) {
@@ -2150,13 +930,8 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2150
930
  throw new CodexSecurityError(`${label} belongs to ${JSON.stringify(url)}, which does not match the selected Cloud repository ${JSON.stringify(trivyTarget)}. Verify the source repository mapping before publishing.`);
2151
931
  }
2152
932
  }
2153
- if (trivyReportUrls) {
2154
- for (const url of trivyReportUrls)
2155
- requireTrivyRemote(url);
2156
- if (parsed !== resolved.current)
2157
- for (const url of trivyBatchSourceUrls(parsed, true))
2158
- requireTrivyRemote(url);
2159
- }
933
+ for (const url of trivyReportUrls ?? [])
934
+ requireTrivyRemote(url);
2160
935
  function checkRepositories({ findings, report }, historical = Boolean(saved)) {
2161
936
  const { provider } = options;
2162
937
  checkTrivyReportProvider(provider, report);
@@ -2183,6 +958,8 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2183
958
  : key(url) !== key(comparisonUrl)))
2184
959
  throw new CodexSecurityError(`Finding ${JSON.stringify(id)} belongs to ${JSON.stringify(url)}, which does not match the selected Cloud repository ${JSON.stringify(destination.url)}. Verify the source repository mapping before publishing.`);
2185
960
  }
961
+ if (provider === "armorcode")
962
+ requireDestination("ArmorCode source", declaredUrl);
2186
963
  if (report?.["format"] === guardianSelectionFormat)
2187
964
  requireDestination("Guardian source", declaredScannerRepositoryUrl(report["repositoryUrl"], "Guardian"));
2188
965
  // An immutable retry may refer to an earlier repository name. Additional
@@ -2221,7 +998,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2221
998
  if (binding)
2222
999
  requireDestination(binding.findingId, binding.url);
2223
1000
  }
2224
- const checkOnlyProjected = !checkNative("blackduck", "inspector", "veracode", "checkmarx", "continuum", "sonar");
1001
+ const checkOnlyProjected = !checkNative("armorcode", "blackduck", "inspector", "veracode", "checkmarx", "continuum", "sonar");
2225
1002
  for (const finding of findings) {
2226
1003
  const { source_finding_id: id, evidence } = finding;
2227
1004
  const guardian = guardianFindingRepository(finding, "cloud");
@@ -2246,7 +1023,10 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2246
1023
  checkmarxRepository(finding)?.url,
2247
1024
  evidence.details?.repository?.url,
2248
1025
  ];
2249
- if (provider === "wiz") {
1026
+ if (provider === "armorcode") {
1027
+ urls.push(armorCodeRepositoryUrl(evidence.source_data, "cloud"));
1028
+ }
1029
+ else if (provider === "wiz") {
2250
1030
  const native = hasProjection ||
2251
1031
  (!historical && isWizPackageFinding(evidence.source_data));
2252
1032
  urls.push(native
@@ -2279,46 +1059,11 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2279
1059
  throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
2280
1060
  }
2281
1061
  }
2282
- if (!usePrivateImport)
1062
+ if (!privateAttempt)
2283
1063
  checkRepositories(parsed);
2284
- // A retry sends its saved projection, which may differ from today's reader.
2285
- if (saved) {
2286
- // Only use the report associated with the input digest in the saved checkpoint.
2287
- const report = saved.inputProjection?.inputDigest === inputDigest
2288
- ? parsed.report
2289
- : undefined;
2290
- checkRepositories({ findings: submissionFindings(saved.requests), report });
2291
- }
2292
- // An older, genuinely unbound checkpoint first acquires a URL on a matching preview.
2293
- // Retain it at the original path so its bare caller can still recover the same request.
2294
- if (saved && !saved.approvedRepositoryUrl && hostedSource) {
2295
- await underLocks(lockKeys, async () => {
2296
- const serialized = await readOptionalFile(pendingPath);
2297
- if (serialized === undefined)
2298
- return;
2299
- const current = validateSaved(JSON.parse(serialized));
2300
- if (!sameSubmission(current, saved))
2301
- throw new CodexSecurityError("Another publication prepared this input. Review the saved request again.");
2302
- if (current.approvedRepositoryUrl) {
2303
- requireApprovedSource(current.approvedRepositoryUrl, current.approvedRepositoryPlatform);
2304
- }
2305
- else {
2306
- // Adding the catalog URL cannot erase an older SDK's same-selection hold.
2307
- if (current.inputProjection &&
2308
- originalHostedPending(current, current.wireKey ?? fileKey) ===
2309
- "verified")
2310
- current.inputProjection.retainedHostedSelection = true;
2311
- current.approvedRepositoryUrl = approvedUrl;
2312
- await writeAtomicJson(pendingPath, current);
2313
- }
2314
- saved.inputProjection = current.inputProjection;
2315
- saved.approvedRepositoryUrl = current.approvedRepositoryUrl;
2316
- saved.approvedRepositoryPlatform = current.approvedRepositoryPlatform;
2317
- });
2318
- }
2319
- if (usePrivateImport) {
1064
+ if (privateAttempt) {
2320
1065
  const client = privateClient;
2321
- const { context, report, binding } = existingPrivate ?? (await preparePrivateAttempt());
1066
+ const { context, report, binding } = privateAttempt;
2322
1067
  function requireAccess(value, saved) {
2323
1068
  if (!value.can_read ||
2324
1069
  (!saved && !canStartJob) ||
@@ -2346,41 +1091,32 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2346
1091
  requests: [],
2347
1092
  privateImport,
2348
1093
  };
2349
- return {
1094
+ return withReceipts(preview, {
2350
1095
  preview: structuredClone(preview),
2351
- publish: () => underPublishLocks(async () => {
1096
+ publish: () => underPublishLock(async () => {
2352
1097
  const current = await client.context();
2353
1098
  if (current.context_version !== binding.contextVersion)
2354
1099
  throw new CodexSecurityError("The private inbox changed. Run the command again to review the new destination.");
2355
- await assertNoAlternateCheckpoint(async () => current);
2356
- const stored = readPrivateCheckpoint(await readOptionalFile(privatePath), binding);
2357
- if (!stored &&
2358
- (resumingPreviousReader ||
2359
- (privateUrl && privateUrl !== destination.url)))
1100
+ const stored = readPrivateCheckpoint(await readPrivate(), binding);
1101
+ if (previous && !stored)
2360
1102
  throw new CodexSecurityError("The saved private import changed. Run the command again to preview this report.");
2361
1103
  // Only a preview of this terminal job can start a new attempt.
2362
1104
  const retrying = retryOfJobId !== undefined && stored?.receipt?.id === retryOfJobId;
2363
1105
  const active = retrying ? undefined : stored;
2364
- if (resumed && !active)
2365
- checkRepositories(parsed);
2366
1106
  requireAccess(current, active);
2367
- if (await selectedCheckpoint())
1107
+ if (await readPending())
2368
1108
  throw new CodexSecurityError("A repository submission is pending. Review its saved request before continuing.");
2369
- // Both routes share request IDs. A server upgrade can promote an
2370
- // existing job, and its saved route also survives gate rollback.
2371
- const checkpoint = {
2372
- ...(active ?? {
2373
- ...binding,
2374
- approvedRepositoryUrl: destination.url,
2375
- approvedRepositoryPlatform: hostedSource?.github === false ? "other" : undefined,
2376
- uploadRequestId: randomUUID(),
2377
- jobRequestId: randomUUID(),
2378
- fileId: undefined,
2379
- jobId: undefined,
2380
- receipt: undefined,
2381
- previousReceipt: retrying ? stored?.receipt : undefined,
2382
- }),
2383
- jobApiVersion: stored?.jobApiVersion ?? jobApiVersion,
1109
+ const checkpoint = active ?? {
1110
+ ...binding,
1111
+ approvedRepositoryUrl: destination.url,
1112
+ approvedRepositoryPlatform: hostedSource?.github === false ? "other" : undefined,
1113
+ uploadRequestId: randomUUID(),
1114
+ jobRequestId: randomUUID(),
1115
+ jobApiVersion: retrying ? stored?.jobApiVersion : jobApiVersion,
1116
+ fileId: undefined,
1117
+ jobId: undefined,
1118
+ receipt: undefined,
1119
+ previousReceipt: retrying ? stored?.receipt : undefined,
2384
1120
  };
2385
1121
  const result = {
2386
1122
  cloudApiUrl: preview.cloudApiUrl,
@@ -2420,7 +1156,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2420
1156
  const savedReceipt = checkpoint.receipt ?? checkpoint.previousReceipt;
2421
1157
  if (savedReceipt)
2422
1158
  acknowledge(savedReceipt);
2423
- if (!active || active.jobApiVersion !== checkpoint.jobApiVersion)
1159
+ if (!active)
2424
1160
  await writeAtomicJson(privatePath, checkpoint);
2425
1161
  if (!checkpoint.fileId) {
2426
1162
  progress({ phase: "uploading", completed: 0 });
@@ -2460,13 +1196,11 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2460
1196
  throw new ExternalPublicationError(result.error, result, error);
2461
1197
  }
2462
1198
  }),
2463
- };
1199
+ });
2464
1200
  }
2465
1201
  // The original selection and request bytes govern a retry even if discovery changes.
2466
- const severities = saved
2467
- ? saved.inputProjection?.repositorySeverities
2468
- : repositorySeverities;
2469
- const direct = repositorySelection(parsed, severities, input.sourcePositions);
1202
+ const severities = saved ? saved.repositorySeverities : repositorySeverities;
1203
+ const direct = repositorySelection(parsed, severities, resolved.sourcePositions);
2470
1204
  if (!direct.findings.length)
2471
1205
  throw new NoPublishableFindingsError(direct);
2472
1206
  let requests = saved?.requests;
@@ -2557,23 +1291,12 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2557
1291
  ...(trivyReportUrls && { trivyRepositoryUrl: trivyTarget }),
2558
1292
  requests,
2559
1293
  receipts: saved?.receipts,
2560
- legacyApproval: saved?.legacyApproval,
2561
- wireKey: saved?.wireKey ?? (fileKey === key ? undefined : key),
2562
- inputProjection: saved?.inputProjection ?? {
2563
- ...(direct !== parsed && { repositorySeverities: severities }),
2564
- identityFormat: saved ? undefined : 2,
2565
- ...(scopedSemgrepReport && { retainedHostedSelection: true }),
2566
- ...(bindSemgrepScope && {
2567
- semgrepPartialScopeDigest: suppliedSemgrepScopeDigest(),
2568
- }),
2569
- inputDigest,
2570
- savedEvidenceDigest: jsonDigest(submissionFindings(requests)),
2571
- },
1294
+ repositorySeverities: severities,
1295
+ semgrepPartialScopeDigest: bindSemgrepScope
1296
+ ? suppliedSemgrepScopeDigest()
1297
+ : saved?.semgrepPartialScopeDigest,
1298
+ approvedRepositoryUrl: hosted ? approvedUrl : undefined,
2572
1299
  };
2573
- if (hosted &&
2574
- (!saved || saved.approvedRepositoryUrl || matchesHostedRepository))
2575
- submission.approvedRepositoryUrl =
2576
- saved?.approvedRepositoryUrl ?? approvedUrl;
2577
1300
  if (saved?.approvedRepositoryPlatform ||
2578
1301
  (hostedSource && !hostedSource.github))
2579
1302
  submission.approvedRepositoryPlatform = "other";
@@ -2590,9 +1313,9 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2590
1313
  resumed: saved !== undefined,
2591
1314
  requests,
2592
1315
  };
2593
- return {
1316
+ return withReceipts(preview, {
2594
1317
  preview: cloneImportPreview(preview),
2595
- async publish() {
1318
+ async publish(beforeRetire) {
2596
1319
  progress({ phase: "waiting", completed: 0 });
2597
1320
  const result = (acknowledged, verified) => {
2598
1321
  const counts = { created: 0, updated: 0, unchanged: 0, error: 0 };
@@ -2632,28 +1355,22 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2632
1355
  function interruptedPreview(message, cause, savedSubmission) {
2633
1356
  // The expected file is gone or another publisher owns the lock. Use only
2634
1357
  // the acknowledgements this caller saw when it prepared the request.
2635
- const known = submission.receipts ?? [];
2636
- if (known.length > submission.requests.length)
2637
- throw new CodexSecurityError("Saved publication has more receipts than requests.");
2638
- const acknowledged = known.map((receipt, index) => validatePublicationReceipt(receipt, submission.requests[index]));
2639
1358
  return new ExternalPublicationError(message, {
2640
- ...result(acknowledged, 0),
1359
+ ...result(acknowledgedReceipts(submission), 0),
2641
1360
  status: "interrupted",
2642
1361
  error: message,
2643
1362
  ...(savedSubmission === undefined ? {} : { savedSubmission }),
2644
1363
  }, cause);
2645
1364
  }
2646
1365
  let acquired = false;
2647
- return await underPublishLocks(async () => {
1366
+ return await underPublishLock(async () => {
2648
1367
  acquired = true;
2649
- await assertNoAlternateCheckpoint();
2650
1368
  // Re-read under the lock to keep checkpoints from another publisher.
2651
- const selected = await selectedCheckpoint(saved ? fileKey : undefined).catch((error) => {
1369
+ let pending = await readPending().catch((error) => {
2652
1370
  if (!submission.receipts?.length)
2653
1371
  throw error;
2654
1372
  throw interruptedPreview(errorMessage(error), error);
2655
1373
  });
2656
- let pending = selected?.content;
2657
1374
  const current = pending ?? submission;
2658
1375
  const adoptProjectMap = submission.inspectorProjectMapRequired &&
2659
1376
  current.inspectorProjectMapRequired === undefined;
@@ -2661,25 +1378,20 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2661
1378
  current.inspectorProjectMapRequired = true;
2662
1379
  if (current.approvedRepositoryUrl)
2663
1380
  requireApprovedSource(current.approvedRepositoryUrl, current.approvedRepositoryPlatform);
2664
- if (!selected ||
2665
- selected.fileKey !== fileKey ||
2666
- selected.historical ||
2667
- !sameSubmission(current, submission)) {
2668
- const message = selected
1381
+ if (!pending || !sameSubmission(current, submission)) {
1382
+ const message = pending
2669
1383
  ? "Another publication prepared this input. Run the command again to review and resume that saved request."
2670
1384
  : "The saved publication changed after preview. Review its result before publishing again.";
2671
1385
  if (saved) {
2672
- const completed = await readCompletedPublication(requests, fileKey);
1386
+ const completed = await readCompletedPublication(requests);
2673
1387
  if (completed)
2674
1388
  return result(completed.receipts, completed.verified);
2675
1389
  throw interruptedPreview(message);
2676
1390
  }
2677
- if (selected)
1391
+ if (pending)
2678
1392
  throw new CodexSecurityError(message);
2679
1393
  if ((await readOptionalFile(privatePath)) !== undefined)
2680
1394
  throw new CodexSecurityError("A private import already owns this selection. Review its saved job before continuing.");
2681
- if ((await readOptionalFile(pendingPath)) !== undefined)
2682
- throw occupiedCheckpoint();
2683
1395
  }
2684
1396
  // A preview can pin the catalog URL. Tighten its SCM comparison only
2685
1397
  // once the caller confirms publication, including when resuming a request.
@@ -2693,36 +1405,10 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2693
1405
  const acknowledged = [];
2694
1406
  let verified = 0;
2695
1407
  try {
2696
- if (selected?.checkedCanonical)
2697
- current.canonicalChecked = true;
2698
- if (pending === undefined) {
2699
- await withSourceAdmission(async () => {
2700
- if (hosted) {
2701
- for (const otherKey of new Set([
2702
- ...projectionKeys,
2703
- ...legacyKeys,
2704
- ])) {
2705
- if (otherKey !== key &&
2706
- otherKey !== fileKey &&
2707
- (await readOptionalFile(pendingFile(otherKey))) !==
2708
- undefined)
2709
- throw new CodexSecurityError("Another publication prepared this input. Run the command again to review and resume that saved request.");
2710
- }
2711
- if (await selectedCheckpoint())
2712
- throw new CodexSecurityError("Another publication prepared this input. Run the command again to review and resume that saved request.");
2713
- }
2714
- await writeAtomicJson(pendingPath, current);
2715
- });
2716
- pending = current;
2717
- }
2718
- else if (adoptProjectMap || adoptStrictRepository) {
1408
+ if (!pending || adoptProjectMap || adoptStrictRepository) {
2719
1409
  await writeAtomicJson(pendingPath, current);
1410
+ pending = current;
2720
1411
  }
2721
- else if (selected?.checkedCanonical) {
2722
- // The existing approval and receipts are usable if caching the scan fails.
2723
- await writeAtomicJson(pendingPath, current).catch(() => undefined);
2724
- }
2725
- await rememberFile();
2726
1412
  progress({
2727
1413
  phase: "uploading",
2728
1414
  completed: 0,
@@ -2743,8 +1429,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2743
1429
  // Acknowledged batches must not consume another POST quota on retry.
2744
1430
  // Readback can still resume after this checkpoint without replaying writes.
2745
1431
  await writeAtomicJson(pendingPath, {
2746
- ...submission,
2747
- canonicalChecked: current.canonicalChecked,
1432
+ ...current,
2748
1433
  receipts: acknowledged,
2749
1434
  });
2750
1435
  }
@@ -2779,7 +1464,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2779
1464
  report.repo_id !== destination.id ||
2780
1465
  report.repo_connector_id !== destination.repo_connector_id ||
2781
1466
  report.environment_id !== batch.repository.environment_id ||
2782
- wireJson(report.source) !== wireJson(source))
1467
+ canonicalJson(report.source) !== canonicalJson(source))
2783
1468
  throw new CodexSecurityError("Cloud readback did not match the saved finding identity.");
2784
1469
  progress({
2785
1470
  phase: "verifying",
@@ -2792,13 +1477,21 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2792
1477
  ...completed,
2793
1478
  report: reportForJson(completed.report),
2794
1479
  });
1480
+ await beforeRetire?.(completed);
2795
1481
  await removePending();
2796
1482
  return completed;
2797
1483
  }
2798
1484
  catch (error) {
2799
1485
  if (error instanceof CloudImportError && error.status === 409) {
2800
- await removePending();
2801
- pending = undefined;
1486
+ try {
1487
+ await beforeRetire?.(result(acknowledged, verified));
1488
+ await removePending();
1489
+ pending = undefined;
1490
+ }
1491
+ catch (recordError) {
1492
+ // Keep acknowledged batches resumable when their receipts are not durable.
1493
+ error = recordError;
1494
+ }
2802
1495
  }
2803
1496
  const message = `${error instanceof Error ? error.message : String(error)} ${error instanceof CloudImportError && error.status === 409 ? "The old submission was retired. Rediscover and approve a fresh publication." : pending ? `Repeat the same command to resume the saved request. Saved submission: ${pendingPath}` : "No resumable request was saved. Correct the error and review the input before retrying."}`;
2804
1497
  throw new ExternalPublicationError(message, {
@@ -2817,6 +1510,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
2817
1510
  throw interruptedPreview(message, error, saved ? pendingPath : undefined);
2818
1511
  });
2819
1512
  },
2820
- };
1513
+ });
2821
1514
  }
2822
1515
  //# sourceMappingURL=external-findings-publish.js.map