@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 +1 @@
1
- {"version":3,"file":"external-findings-import.d.ts","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,6BAA6B,EAEnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGL,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EAClC,MAAM,8BAA8B,CAAC;AAOtC,MAAM,WAAW,0BACf,SACE,IAAI,CAAC,4BAA4B,EAAE,UAAU,CAAC,EAC9C,6BAA6B;CAAG;AAEpC,8EAA8E;AAC9E,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,0BAA0B,EACnC,YAAY,GAAE,+BAAoC,+EAsDnD"}
1
+ {"version":3,"file":"external-findings-import.d.ts","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,6BAA6B,EAEnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGL,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EAClC,MAAM,8BAA8B,CAAC;AAQtC,MAAM,WAAW,0BACf,SACE,IAAI,CAAC,4BAA4B,EAAE,UAAU,CAAC,EAC9C,6BAA6B;CAAG;AAEpC,8EAA8E;AAC9E,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,0BAA0B,EACnC,YAAY,GAAE,+BAAoC,+EA4EnD"}
@@ -1,13 +1,18 @@
1
+ import { stat } from "node:fs/promises";
2
+ import { InvalidTargetError } from "./errors.js";
1
3
  import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
2
4
  import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, } from "./external-findings-read.js";
3
5
  import { distinctSourceRepositories, prepareLocalImport, } from "./external-findings-local.js";
4
6
  import { snapshotImportOptions, snapshotSourceRepositories, } from "./external-findings.js";
7
+ import { resolveInputPath } from "./runtime.js";
5
8
  import { abortable } from "./targets.js";
6
9
  /** Read an installed vendor format and prepare it for the local workbench. */
7
10
  export async function prepareLocalExternalImport(path, options, dependencies = {}) {
8
11
  dependencies.signal?.throwIfAborted();
9
12
  const settings = snapshotImportOptions(options);
10
13
  const readerSources = distinctSourceRepositories(snapshotSourceRepositories(dependencies.sourceRepositories));
14
+ const requested = resolveInputPath(settings.repository, process.cwd(), dependencies.environment);
15
+ const selected = await abortable(() => stat(requested, { bigint: true }).catch(() => null), dependencies.signal);
11
16
  const parsed = await abortable(() => readExternalFindings(path, settings, "local", readerSources), dependencies.signal);
12
17
  const normalizedOptions = {
13
18
  ...settings,
@@ -38,6 +43,12 @@ export async function prepareLocalExternalImport(path, options, dependencies = {
38
43
  ];
39
44
  }
40
45
  const { environment, runWorkbench, signal } = dependencies;
41
- return prepareLocalImport(parsed.findings, normalizedOptions, { environment, runWorkbench, signal }, readerSources, sourceRepositories);
46
+ const prepared = await prepareLocalImport(parsed.findings, normalizedOptions, { environment, runWorkbench, signal }, readerSources, sourceRepositories);
47
+ const destination = await abortable(() => stat(prepared.preview.repository, { bigint: true }), dependencies.signal);
48
+ if (!selected ||
49
+ selected.dev !== destination.dev ||
50
+ selected.ino !== destination.ino)
51
+ throw new InvalidTargetError(`Repository path changed while reading external findings: ${requested}`);
52
+ return prepared;
42
53
  }
43
54
  //# sourceMappingURL=external-findings-import.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-import.js","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,2BAA2B,EAE3B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GAGnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,IAAY,EACZ,OAAmC,EACnC,YAAY,GAAoC,EAAE;IAElD,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,0BAA0B,CAC9C,0BAA0B,CAAC,YAA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C,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;oBACxC,GAAG,SAAS;oBACZ,QAAQ,EAAE,QAAiB;iBAC5B,CAAC,CAAC;aACJ,CAAC;IACN,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IAC3D,OAAO,kBAAkB,CACvB,MAAM,CAAC,QAAQ,EACf,iBAAiB,EACjB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,EACrC,aAAa,EACb,kBAAkB,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import {\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport {\n EXTERNAL_FINDINGS_PROVIDERS,\n type ExternalFindingsReaderOptions,\n readExternalFindings,\n} from \"./external-findings-read.js\";\nimport {\n distinctSourceRepositories,\n prepareLocalImport,\n type LocalExternalImportDependencies,\n type NormalizedLocalImportOptions,\n} from \"./external-findings-local.js\";\nimport {\n snapshotImportOptions,\n snapshotSourceRepositories,\n} from \"./external-findings.js\";\nimport { abortable } from \"./targets.js\";\n\nexport interface LocalExternalImportOptions\n extends\n Omit<NormalizedLocalImportOptions, \"provider\">,\n ExternalFindingsReaderOptions {}\n\n/** Read an installed vendor format and prepare it for the local workbench. */\nexport async function prepareLocalExternalImport(\n path: string,\n options: LocalExternalImportOptions,\n dependencies: LocalExternalImportDependencies = {},\n) {\n dependencies.signal?.throwIfAborted();\n const settings = snapshotImportOptions(options);\n const readerSources = distinctSourceRepositories(\n snapshotSourceRepositories(dependencies.sourceRepositories),\n );\n const parsed = await abortable(\n () => readExternalFindings(path, settings, \"local\", readerSources),\n dependencies.signal,\n );\n const normalizedOptions = {\n ...settings,\n provider: EXTERNAL_FINDINGS_PROVIDERS[settings.provider],\n };\n let sourceRepositories = parsed.sourceRepositories ?? [];\n if (\n normalizedOptions.provider === \"semgrep\" &&\n parsed.sourceRepositories &&\n settings.sourceRepositoryUrl\n ) {\n // The Cloud reader allows custom GitHub casing. Local provenance must also\n // agree with the caller's source URL when the checkout has no remote.\n const source = settings.sourceRepositoryUrl;\n const knownGitHub = readerSources.some(\n ({ url, platform }) =>\n platform === \"github\" &&\n cloudRepositoryUrlKey(url) === cloudRepositoryUrlKey(source),\n );\n const key = knownGitHub ? cloudRepositoryUrlKey : repositoryUrlKey;\n sourceRepositories = distinctSourceRepositories(sourceRepositories);\n for (const reference of sourceRepositories) {\n if (key(reference.url) !== key(source))\n throw new Error(\n \"SARIF source repository does not match the declared source repository URL.\",\n );\n }\n if (knownGitHub)\n sourceRepositories = [\n { url: source, platform: \"github\" },\n ...sourceRepositories.map((reference) => ({\n ...reference,\n platform: \"github\" as const,\n })),\n ];\n }\n const { environment, runWorkbench, signal } = dependencies;\n return prepareLocalImport(\n parsed.findings,\n normalizedOptions,\n { environment, runWorkbench, signal },\n readerSources,\n sourceRepositories,\n );\n}\n"]}
1
+ {"version":3,"file":"external-findings-import.js","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,2BAA2B,EAE3B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GAGnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,IAAY,EACZ,OAAmC,EACnC,YAAY,GAAoC,EAAE;IAEl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IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { InvalidTargetError } from \"./errors.js\";\nimport {\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport {\n EXTERNAL_FINDINGS_PROVIDERS,\n type ExternalFindingsReaderOptions,\n readExternalFindings,\n} from \"./external-findings-read.js\";\nimport {\n distinctSourceRepositories,\n prepareLocalImport,\n type LocalExternalImportDependencies,\n type NormalizedLocalImportOptions,\n} from \"./external-findings-local.js\";\nimport {\n snapshotImportOptions,\n snapshotSourceRepositories,\n} from \"./external-findings.js\";\nimport { resolveInputPath } from \"./runtime.js\";\nimport { abortable } from \"./targets.js\";\n\nexport interface LocalExternalImportOptions\n extends\n Omit<NormalizedLocalImportOptions, \"provider\">,\n ExternalFindingsReaderOptions {}\n\n/** Read an installed vendor format and prepare it for the local workbench. */\nexport async function prepareLocalExternalImport(\n path: string,\n options: LocalExternalImportOptions,\n dependencies: LocalExternalImportDependencies = {},\n) {\n dependencies.signal?.throwIfAborted();\n const settings = snapshotImportOptions(options);\n const readerSources = distinctSourceRepositories(\n snapshotSourceRepositories(dependencies.sourceRepositories),\n );\n const requested = resolveInputPath(\n settings.repository,\n process.cwd(),\n dependencies.environment,\n );\n const selected = await abortable(\n () => stat(requested, { bigint: true }).catch(() => null),\n dependencies.signal,\n );\n const parsed = await abortable(\n () => readExternalFindings(path, settings, \"local\", readerSources),\n dependencies.signal,\n );\n const normalizedOptions = {\n ...settings,\n provider: EXTERNAL_FINDINGS_PROVIDERS[settings.provider],\n };\n let sourceRepositories = parsed.sourceRepositories ?? [];\n if (\n normalizedOptions.provider === \"semgrep\" &&\n parsed.sourceRepositories &&\n settings.sourceRepositoryUrl\n ) {\n // The Cloud reader allows custom GitHub casing. Local provenance must also\n // agree with the caller's source URL when the checkout has no remote.\n const source = settings.sourceRepositoryUrl;\n const knownGitHub = readerSources.some(\n ({ url, platform }) =>\n platform === \"github\" &&\n cloudRepositoryUrlKey(url) === cloudRepositoryUrlKey(source),\n );\n const key = knownGitHub ? cloudRepositoryUrlKey : repositoryUrlKey;\n sourceRepositories = distinctSourceRepositories(sourceRepositories);\n for (const reference of sourceRepositories) {\n if (key(reference.url) !== key(source))\n throw new Error(\n \"SARIF source repository does not match the declared source repository URL.\",\n );\n }\n if (knownGitHub)\n sourceRepositories = [\n { url: source, platform: \"github\" },\n ...sourceRepositories.map((reference) => ({\n ...reference,\n platform: \"github\" as const,\n })),\n ];\n }\n const { environment, runWorkbench, signal } = dependencies;\n const prepared = await prepareLocalImport(\n parsed.findings,\n normalizedOptions,\n { environment, runWorkbench, signal },\n readerSources,\n sourceRepositories,\n );\n const destination = await abortable(\n () => stat(prepared.preview.repository, { bigint: true }),\n dependencies.signal,\n );\n if (\n !selected ||\n selected.dev !== destination.dev ||\n selected.ino !== destination.ino\n )\n throw new InvalidTargetError(\n `Repository path changed while reading external findings: ${requested}`,\n );\n return prepared;\n}\n"]}
@@ -1,12 +1,11 @@
1
1
  import { type ExternalFindings, type ExternalSourceRepository } from "./external-findings.js";
2
2
  import type { ExternalFindingEvidence } from "./external-import-models.js";
3
- import { type LocalFindingProvider } from "./external-findings-read.js";
4
3
  import { runWorkbench } from "./runtime.js";
5
4
  /** A scanner source record, independent of a Codex assessment or completed scan. */
6
5
  export interface StoredExternalFinding {
7
6
  id: string;
8
7
  repository: string;
9
- provider: LocalFindingProvider;
8
+ provider: string;
10
9
  sourceKey: string;
11
10
  sourceFindingId: string;
12
11
  evidence: ExternalFindingEvidence;
@@ -16,11 +15,53 @@ export interface StoredExternalFinding {
16
15
  version: number;
17
16
  createdAt: string;
18
17
  updatedAt: string;
18
+ /** Reader context required to publish this version without the original file. */
19
+ provenance?: ExternalFindingProvenance;
20
+ }
21
+ export interface ExternalFindingProvenance {
22
+ sourceRepositories?: ExternalSourceRepository[];
23
+ inspectorProjectMap?: [string, string][];
24
+ }
25
+ export type LocalExternalFindingSelection = {
26
+ repository: string;
27
+ } & ({
28
+ importId: string;
29
+ findings?: never;
30
+ /** Return an empty selection if the import is missing or any pinned version has changed. */
31
+ ifCurrent?: boolean;
32
+ } | {
33
+ findings: readonly Pick<StoredExternalFinding, "id" | "version">[];
34
+ importId?: never;
35
+ });
36
+ export interface SelectedLocalExternalFindings extends Omit<ExternalFindings, "findings"> {
37
+ findings: StoredExternalFinding[];
38
+ }
39
+ export interface StoredExternalImport {
40
+ importId: string;
41
+ createdAt: string;
42
+ provider: string;
43
+ sourceKey: string;
44
+ count: number;
45
+ }
46
+ export interface LocalFindingReceipt {
47
+ id: string;
48
+ version: number;
49
+ receiptId: string;
50
+ outcome: "created" | "updated" | "unchanged" | "private_job";
51
+ cloudFindingId?: string;
52
+ }
53
+ interface CloudFindingDestination {
54
+ cloudApiUrl: string;
55
+ accountId: string;
56
+ destinationId: string;
57
+ }
58
+ export interface StoredFindingPublication extends LocalFindingReceipt, CloudFindingDestination {
59
+ createdAt: string;
19
60
  }
20
61
  export interface NormalizedLocalImportOptions {
21
62
  /** Local checkout or source directory to associate with these records. */
22
63
  repository: string;
23
- provider: LocalFindingProvider;
64
+ provider: string;
24
65
  /** Stable scanner organization/project/branch namespace across imports. */
25
66
  sourceKey: string;
26
67
  /** Verified Git repository URL for readers that bind a finding to a checkout. */
@@ -38,11 +79,13 @@ export interface LocalExternalImportDependencies {
38
79
  export interface LocalExternalImportPreview extends ExternalFindings {
39
80
  repository: string;
40
81
  source: {
41
- provider: LocalFindingProvider;
82
+ provider: string;
42
83
  source_key: string;
43
84
  };
44
85
  }
45
86
  export interface LocalExternalImportResult {
87
+ /** Present when the import saved a nonempty selection, including unchanged rows. */
88
+ importId?: string;
46
89
  repository: string;
47
90
  read: number;
48
91
  report?: ExternalFindings["report"];
@@ -74,4 +117,23 @@ export declare function listLocalExternalFindings(selection: {
74
117
  repository: string;
75
118
  id?: string;
76
119
  }, dependencies?: LocalExternalImportDependencies): Promise<StoredExternalFinding[]>;
120
+ export declare function readLocalExternalFindings(selection: {
121
+ repository: string;
122
+ id?: string;
123
+ }, dependencies: LocalExternalImportDependencies): Promise<{
124
+ repository: string;
125
+ findings: StoredExternalFinding[];
126
+ }>;
127
+ /** Read the precise versions selected by the caller or captured by an earlier import. */
128
+ export declare function selectLocalExternalFindings(selection: LocalExternalFindingSelection, dependencies?: LocalExternalImportDependencies): Promise<SelectedLocalExternalFindings>;
129
+ /** List this checkout's nonempty imports, most recent first. */
130
+ export declare function listLocalExternalImports({ repository }: {
131
+ repository: string;
132
+ }, dependencies?: LocalExternalImportDependencies): Promise<StoredExternalImport[]>;
133
+ /** Read the destination and receipt for each acknowledged finding version. */
134
+ export declare function listLocalFindingPublications({ repository, id }: {
135
+ repository: string;
136
+ id?: string;
137
+ }, dependencies?: LocalExternalImportDependencies): Promise<StoredFindingPublication[]>;
138
+ export {};
77
139
  //# sourceMappingURL=external-findings-local.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-local.d.ts","sourceRoot":"","sources":["../src/external-findings-local.ts"],"names":[],"mappings":"AAyBA,OAAO,EAOL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAOhC,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,6BAA6B,CAAC;AAuCrC,OAAO,EAML,YAAY,EAGb,MAAM,cAAc,CAAC;AAQtB,oFAAoF;AACpF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE;QAAE,KAAK,EAAE,cAAc,CAAA;KAAE,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,M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BAAsB,yBAAyB,CAC7C,SAAS,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9C,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAElC;AAED,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9C,YAAY,EAAE,+BAA+B;;cAYA,qBAAqB,EAAE;GAErE;AAED,yFAAyF;AACzF,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,6BAA6B,EACxC,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,6BAA6B,CAAC,CAexC;AAED,gEAAgE;AAChE,wBAAsB,wBAAwB,CAC5C,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EACtC,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAQjC;AAmBD,8EAA8E;AAC9E,wBAAsB,4BAA4B,CAChD,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EACvD,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAQrC"}
@@ -1,11 +1,13 @@
1
- import { semgrepLegacyRepositoryWitnesses, semgrepPlatformFindingBinding, semgrepPlatformReportScope, semgrepPlatformRepositoryReference, isSemgrepPlatformEvidence, semgrepReferenceMatches, } from "./semgrep-platform-findings.js";
2
- import { gitPathToHttpPath, gitServiceHostname, isPublicGitHost, gitTransportBytes, hostedRepositoryMatches, } from "./hosted-git-repository.js";
1
+ import { resolve } from "node:path";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ import { semgrepPlatformFindingBinding, semgrepPlatformReportScope, semgrepPlatformRepositoryReference, isSemgrepPlatformEvidence, semgrepReferenceMatches, } from "./semgrep-platform-findings.js";
4
+ import { gitPathToHttpPath, gitServiceHostname, isPublicGitHost, gitTransportBytes, hostedRepositoryMatches, normalizeHostedGitRepositoryUrl, } from "./hosted-git-repository.js";
3
5
  import { checkRetainedTrivyProvider, checkTrivyReportProvider, matchTrivyCheckout, } from "./trivy-import.js";
4
6
  import { readGitRemoteNames, readHostedGitRemotes, } from "./hosted-git-remotes.js";
5
7
  import { CodexSecurityError } from "./errors.js";
6
- import { externalImportDisposition, NoPublishableFindingsError, cloneImportPreview, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
8
+ import { externalImportDisposition, NoPublishableFindingsError, cloneImportPreview, reportForJson, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
7
9
  import { cloudRepositoryUrlKey, requireSafeJsonInteger, repositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
8
- import { localFindingRepositories, semgrepSarifRepositories, } from "./external-findings-read.js";
10
+ import { EXTERNAL_FINDINGS_PROVIDERS, EXTERNAL_FINDINGS_READERS, localFindingRepositories, semgrepSarifRepositories, } from "./external-findings-read.js";
9
11
  import { tenableReportFormat, tenableSourceRepository, } from "./tenable-findings.js";
10
12
  import { guardianFindingRepository, guardianSelectionFormat, } from "./semgrep-guardian-findings.js";
11
13
  import { hasGitMetadata, localGitProtectionRoots, commandGitProtectionRoots, } from "./local-git-metadata.js";
@@ -16,16 +18,33 @@ import { continuumReportRepositories } from "./continuum-findings.js";
16
18
  import { veracodeReportRepositories } from "./veracode-findings.js";
17
19
  import { inspectorReportRepository } from "./inspector-findings.js";
18
20
  import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
21
+ import { armorCodeRepositoryUrl } from "./armorcode-findings.js";
19
22
  import { sonarRepositoryUrls } from "./sonar-findings.js";
20
23
  import { isRecord } from "./record.js";
21
24
  import { dependabotRepository } from "./github-dependabot-findings.js";
22
25
  import { retainedGitHubRepository } from "./github-findings.js";
23
26
  import { snykRestImportRepository, snykRestCheckoutMatches, } from "./snyk-rest-findings.js";
24
- import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
27
+ import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, resolveInputPath, resolveParentTraversal, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
25
28
  import { abortable, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, } from "./targets.js";
26
29
  function requireIdentity(value, field) {
27
30
  if (typeof value !== "string" || !value.trim() || value.includes("\0"))
28
31
  throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
32
+ if (!value.isWellFormed())
33
+ throw new CodexSecurityError(`${field} must contain valid Unicode.`);
34
+ }
35
+ function validateFindingIds(current) {
36
+ const identities = new Set();
37
+ for (const finding of current.findings) {
38
+ requireIdentity(finding.source_finding_id, "Source finding id");
39
+ if (identities.has(finding.source_finding_id))
40
+ throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}.`);
41
+ identities.add(finding.source_finding_id);
42
+ if (!isRecord(finding.evidence))
43
+ throw new CodexSecurityError("Imported evidence must be an object.");
44
+ if (typeof finding.evidence.title !== "string" ||
45
+ typeof finding.evidence.severity !== "string")
46
+ throw new CodexSecurityError("Imported evidence requires a title and severity.");
47
+ }
29
48
  }
30
49
  function checkStoredNumber(value) {
31
50
  if (!Number.isFinite(value))
@@ -289,17 +308,17 @@ export async function configuredFetchRemotes(repository, provider, protectedRoot
289
308
  }
290
309
  return remotes;
291
310
  }
311
+ async function hostedCheckoutRemotes(repository, protectedRoots, environment, signal) {
312
+ if (!(await hasGitMetadata(repository, signal)))
313
+ return undefined;
314
+ return readHostedGitRemotes(repository, [...protectedRoots, await canonicalConfigPath(process.cwd())], environment, signal);
315
+ }
292
316
  async function requireMatchingRepository(repository, provider, sources, strictSources, hostedSources, platformFor, snyk, protectedRoots, environment, signal, possibleSshHost, fetchRemotes, isCheckmarxSource) {
293
317
  if (!snyk && sources.length === 0 && hostedSources.length === 0)
294
318
  return false;
295
319
  let allSourcesMatched = true;
296
320
  if (snyk || hostedSources.length) {
297
- if (!(await hasGitMetadata(repository, signal)))
298
- return false;
299
- const remotes = await readHostedGitRemotes(repository, [
300
- ...protectedRoots,
301
- await abortable(() => canonicalConfigPath(process.cwd()), signal),
302
- ], environment, signal);
321
+ const remotes = await hostedCheckoutRemotes(repository, protectedRoots, environment, signal);
303
322
  if (snyk) {
304
323
  if (remotes &&
305
324
  !remotes.some((remote) => snykRestCheckoutMatches(snyk, remote)))
@@ -356,22 +375,32 @@ async function requireMatchingRepository(repository, provider, sources, strictSo
356
375
  export function sonarCheckoutMatchesSource(repository, url, protectedRoots, environment, signal) {
357
376
  return requireMatchingRepository(repository, "sonar", [{ url }], new Map(), [], () => "sonar", undefined, [...protectedRoots], environment, signal);
358
377
  }
378
+ /** @internal Resolve and protect the local checkout and workbench state directory. */
359
379
  async function localContext(selectedRepository, dependencies, mode = "import") {
360
380
  dependencies.signal?.throwIfAborted();
361
381
  const environment = workbenchEnvironment(dependencies.environment ?? process.env);
362
- const path = expandHome(selectedRepository, environment);
382
+ const requested = resolveInputPath(selectedRepository, process.cwd(), environment);
383
+ const path = await abortable(() => resolveParentTraversal(requested), dependencies.signal);
363
384
  const repository = mode === "read"
364
385
  ? await abortable(() => canonicalConfigPath(path), dependencies.signal)
365
386
  : await normalizeRepository(path, dependencies.signal);
387
+ const lexicalPath = resolve(requested);
388
+ const lexicalRepository = lexicalPath === resolve(path)
389
+ ? repository
390
+ : await abortable(() => canonicalConfigPath(lexicalPath), dependencies.signal);
366
391
  const protectedRoot = [
367
392
  ...new Set([
368
393
  repository,
369
- ...(await abortable(() => commandGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
394
+ ...(mode === "read" ? [lexicalRepository] : []),
395
+ ...(await abortable(() => commandGitProtectionRoots(path, environment, dependencies.signal, {
396
+ requestedPaths: [lexicalPath, lexicalRepository],
397
+ }), dependencies.signal)),
370
398
  ]),
371
399
  ];
372
400
  requireOutputOutsideRepositories(protectedRoot, await abortable(() => canonicalizeModelSafePath(environment.CODEX_SECURITY_STATE_DIR), dependencies.signal), "runtime");
373
401
  return {
374
402
  repository,
403
+ selectedPath: path,
375
404
  options: {
376
405
  pluginRoot: await abortable(() => bundledPluginRoot(), dependencies.signal),
377
406
  environment,
@@ -383,8 +412,63 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
383
412
  }
384
413
  /** Prepare scanner evidence without writing state or performing a security assessment. */
385
414
  export async function prepareNormalizedLocalImport(input, options, dependencies = {}) {
386
- dependencies.signal?.throwIfAborted();
387
- return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
415
+ const { signal } = dependencies;
416
+ signal?.throwIfAborted();
417
+ const settings = snapshotImportOptions(options);
418
+ const reader = EXTERNAL_FINDINGS_READERS.find((name) => name === settings.provider);
419
+ if (reader)
420
+ return prepareLocalImport(input, { ...settings, provider: EXTERNAL_FINDINGS_PROVIDERS[reader] }, dependencies);
421
+ const references = snapshotSourceRepositories(dependencies.sourceRepositories);
422
+ requireIdentity(settings.provider, "Provider");
423
+ requireIdentity(settings.sourceKey, "Source key");
424
+ const current = snapshotNormalizedFindings(input, checkStoredNumber);
425
+ validateFindingIds(current);
426
+ if (current.report !== undefined && !isRecord(current.report))
427
+ throw new CodexSecurityError("Report metadata must be an object.");
428
+ if (current.read !== current.findings.length + current.excluded.length)
429
+ throw new CodexSecurityError("Every source record must be accounted for by a finding or exclusion.");
430
+ const positions = new Set();
431
+ for (const { position, source_finding_id, reason } of current.excluded) {
432
+ if (!Number.isSafeInteger(position) ||
433
+ position < 1 ||
434
+ position > current.read ||
435
+ positions.has(position))
436
+ throw new CodexSecurityError("An excluded position must be unique and within the reported record count.");
437
+ positions.add(position);
438
+ requireIdentity(reason, "Exclusion reason");
439
+ if (source_finding_id !== null)
440
+ requireIdentity(source_finding_id, "Excluded source finding id");
441
+ }
442
+ const platform = references.find((ref) => ref.platform)?.platform;
443
+ const urls = new Set(references.map(({ url }) => url));
444
+ if (settings.sourceRepositoryUrl !== undefined)
445
+ urls.add(settings.sourceRepositoryUrl);
446
+ for (const finding of current.findings) {
447
+ finding.evidence = validateExternalEvidence(finding.evidence, "local");
448
+ const repository = finding.evidence.details?.repository;
449
+ if (repository)
450
+ urls.add(repository.url);
451
+ }
452
+ const sources = Array.from(urls, (url) => ({
453
+ url: declaredScannerRepositoryUrl(url, settings.provider, "local"),
454
+ platform,
455
+ }));
456
+ const [source] = sources;
457
+ const context = await localContext(settings.repository, dependencies);
458
+ let matched = false;
459
+ if (source) {
460
+ if (references.some((ref) => ref.platform && ref.platform !== platform) ||
461
+ sources.some(({ url }) => !hostedRepositoryMatches(source, url)))
462
+ throw new CodexSecurityError("The findings declare conflicting source repositories.");
463
+ const remotes = await hostedCheckoutRemotes(context.repository, context.options.protectedRoot, context.options.environment, signal);
464
+ matched =
465
+ remotes?.some((remote) => hostedRepositoryMatches(source, remote)) ??
466
+ false;
467
+ if (!matched &&
468
+ remotes?.some((remote) => /^https?:\/\//iu.test(normalizeHostedGitRepositoryUrl(remote, undefined, platform !== undefined))))
469
+ throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured fetch remote of ${context.repository}.`);
470
+ }
471
+ return preparedLocalStorage(current, settings, context, dependencies, matched, { sourceRepositories: sources });
388
472
  }
389
473
  // A scanner can repeat the same repository reference for every finding in a run.
390
474
  export function distinctSourceRepositories(sources) {
@@ -399,35 +483,23 @@ export function distinctSourceRepositories(sources) {
399
483
  });
400
484
  }
401
485
  /** @internal Prepare evidence using settings captured by either local import entrypoint. */
402
- export async function prepareLocalImport(input, options, dependencies, readerSources = distinctSourceRepositories(snapshotSourceRepositories(dependencies.sourceRepositories)), parsedInput = [], fetchRemotes) {
486
+ export async function prepareLocalImport(input, options, dependencies, readerSources = distinctSourceRepositories(snapshotSourceRepositories(dependencies.sourceRepositories)), parsedInput, fetchRemotes) {
403
487
  requireIdentity(options.sourceKey, "Source key");
404
- const parsedSources = distinctSourceRepositories(parsedInput);
405
- const current = snapshotNormalizedFindings(input, checkStoredNumber);
488
+ const parsedSources = distinctSourceRepositories(parsedInput ?? []);
489
+ // File readers interpret their source option while parsing. For normalized
490
+ // input the caller declares one repository for the whole selection.
491
+ const normalizedSource = parsedInput === undefined && options.sourceRepositoryUrl !== undefined
492
+ ? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, options.provider, "local")
493
+ : undefined;
494
+ const current = snapshotNormalizedFindings(input, checkStoredNumber, "local", options.provider);
406
495
  if (options.provider !== "tenable" &&
407
496
  (current.report?.["format"] === tenableReportFormat ||
408
497
  current.findings.some((row) => row.evidence?.source_data?.["format"] === tenableReportFormat)))
409
498
  throw new CodexSecurityError("Retained Tenable evidence requires the tenable provider.");
410
499
  checkTrivyReportProvider(options.provider, current.report);
411
- // The JSON snapshot omits inherited or non-enumerable SDK reader properties.
412
- if (!("snykRestContext" in current) && "snykRestContext" in input)
413
- current.snykRestContext = structuredClone(input.snykRestContext);
414
- if (options.provider === "snyk" || current.snykRestContext !== undefined) {
415
- for (const key of [
416
- "sourceRepositoryUrl",
417
- "sourceRepositoryPlatform",
418
- ])
419
- if (key in input && !(key in current))
420
- Object.assign(current, { [key]: structuredClone(input[key]) });
421
- }
422
500
  let dependabotSource;
423
- const identities = new Set();
501
+ validateFindingIds(current);
424
502
  for (const finding of current.findings) {
425
- requireIdentity(finding.source_finding_id, "Source finding id");
426
- if (identities.has(finding.source_finding_id))
427
- throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}.`);
428
- identities.add(finding.source_finding_id);
429
- if (!isRecord(finding.evidence))
430
- throw new CodexSecurityError("Imported evidence must be an object.");
431
503
  checkRetainedTrivyProvider(options.provider, finding, "local");
432
504
  if (options.provider !== "github")
433
505
  continue;
@@ -445,13 +517,12 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
445
517
  const context = await localContext(options.repository, dependencies);
446
518
  if (options.provider === "tenable") {
447
519
  const source = tenableSourceRepository(current, options.sourceRepositoryUrl, [...readerSources, ...parsedSources]);
448
- const remotes = await readHostedGitRemotes(context.repository, [
449
- ...context.options.protectedRoot,
450
- await abortable(() => canonicalConfigPath(process.cwd()), dependencies.signal),
451
- ], context.options.environment, dependencies.signal);
520
+ const remotes = await hostedCheckoutRemotes(context.repository, context.options.protectedRoot, context.options.environment, dependencies.signal);
452
521
  if (!remotes?.some((remote) => hostedRepositoryMatches(source, remote)))
453
522
  throw new CodexSecurityError("Tenable's source repository must match a configured Git fetch remote of the selected checkout.");
454
- return preparedLocalStorage(current, options, context, dependencies, true);
523
+ return preparedLocalStorage(current, options, context, dependencies, true, {
524
+ sourceRepositories: [source],
525
+ });
455
526
  }
456
527
  const { repository, options: workbenchOptions } = context;
457
528
  const sources = new Map();
@@ -462,7 +533,7 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
462
533
  projectedBlackDuckRepositoryUrl(finding, "local")) ||
463
534
  checkmarx.projections.has(finding));
464
535
  const mixed = projected.length > 0 && readerSources.length > 0;
465
- const nativeSources = new Map((mixed ? current.findings : projected)
536
+ const nativeSources = new Map((mixed || normalizedSource ? current.findings : projected)
466
537
  .filter(({ evidence }) => options.provider !== "endor" ||
467
538
  isRecord(evidence.source_data?.["runContext"]))
468
539
  .map((finding) => [
@@ -523,7 +594,6 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
523
594
  if (semgrepPlatformRepositoryUrl)
524
595
  addSemgrepSource(semgrepPlatformRepositoryUrl);
525
596
  const known = new Set(parsedSources.map(({ url }) => url));
526
- const legacyWitnesses = semgrepLegacyRepositoryWitnesses(current.findings, options.provider, readerSources);
527
597
  const hasPlatformEvidence = options.provider === "semgrep" &&
528
598
  (semgrepReportScope !== undefined ||
529
599
  current.findings.some((row) => isSemgrepPlatformEvidence(row, options.provider)));
@@ -532,8 +602,14 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
532
602
  for (const finding of current.findings) {
533
603
  const retained = bound.get(finding.source_finding_id) ?? checkmarxRepository(finding);
534
604
  const native = nativeSources.get(finding) ?? [];
535
- const sarif = hasPlatformEvidence ? semgrepSarifRepositories(finding) : [];
536
- const semgrep = semgrepPlatformFindingBinding(finding, options.provider, readerSources, legacyWitnesses, semgrepReportScope, [retained, ...native, ...sarif]);
605
+ const sarif = hasPlatformEvidence ||
606
+ (normalizedSource && options.provider === "semgrep")
607
+ ? semgrepSarifRepositories(finding)
608
+ : [];
609
+ if (normalizedSource)
610
+ for (const source of sarif)
611
+ known.add(source.url);
612
+ const semgrep = semgrepPlatformFindingBinding(finding, options.provider, readerSources, semgrepReportScope, [retained, ...native, ...sarif]);
537
613
  if (semgrep) {
538
614
  addSemgrepSource(semgrep.url);
539
615
  if (semgrep.sourceData)
@@ -542,6 +618,11 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
542
618
  Object.assign(finding.evidence, semgrep.migration);
543
619
  }
544
620
  const { evidence } = finding;
621
+ if (options.provider === "armorcode") {
622
+ const nativeUrl = armorCodeRepositoryUrl(evidence.source_data, "local");
623
+ if (nativeUrl)
624
+ sources.set(nativeUrl, { url: nativeUrl });
625
+ }
545
626
  if (options.provider === "github") {
546
627
  const source = retainedGitHubRepository(finding, (url) => identify(url).key);
547
628
  if (source)
@@ -712,6 +793,14 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
712
793
  (reportUrl &&
713
794
  hosted.some((source) => !semgrepReferenceMatches(source, reportUrl))))
714
795
  throw new Error("The retained Checkmarx report repository does not match the finding repository.");
796
+ if (options.provider === "armorcode") {
797
+ if (options.sourceRepositoryUrl !== undefined) {
798
+ const url = declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "ArmorCode", "local");
799
+ sources.set(url, { url });
800
+ }
801
+ if (!sameRepositories(sources.keys()))
802
+ throw new CodexSecurityError("ArmorCode findings must belong to a single source repository.");
803
+ }
715
804
  const sonarSources = sonarRepositoryUrls(options.provider, current.findings, current.report, "local");
716
805
  const manualSource = options.provider === "sonar" && options.sourceRepositoryUrl
717
806
  ? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Sonar", "local")
@@ -757,6 +846,13 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
757
846
  if (!sameRepositories(sources.keys()))
758
847
  throw new CodexSecurityError("The normalized repository does not match the Snyk reader's repository.");
759
848
  }
849
+ if (normalizedSource && !snyk) {
850
+ if (!sameRepositories([normalizedSource, ...sources.keys(), ...known]) ||
851
+ hosted.some((source) => !semgrepReferenceMatches(source, normalizedSource)))
852
+ throw new CodexSecurityError("The declared repository does not match the normalized finding source.");
853
+ if (!hosted.length && !sources.size)
854
+ sources.set(normalizedSource, { url: normalizedSource });
855
+ }
760
856
  const ordinarySources = [...sources.values()];
761
857
  // A reader can identify the VCS for both a hosted project and an ordinary row.
762
858
  const loosePlatformFor = localRepositoryPlatform(options.provider, [...ordinarySources, ...hostedReferences], false);
@@ -766,19 +862,67 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
766
862
  : await requireMatchingRepository(repository, options.provider, ordinarySources, strictSources, hosted, (source, bound) => bound ? platformFor(source) : loosePlatformFor(source), snyk, workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal, selected?.protocol === "https:" ? selected.hostname : undefined, fetchRemotes, checkmarx.projections.size
767
863
  ? (url) => checkmarxKeys.has(identify(url).key)
768
864
  : undefined);
769
- return preparedLocalStorage(current, options, context, dependencies, matchesRepositoryRemote);
865
+ let storedSources = [...references, ...ordinarySources, ...hosted];
866
+ const [project] = hosted;
867
+ if (options.provider === "semgrep" &&
868
+ !hasOrdinaryRows &&
869
+ !ordinarySources.length &&
870
+ hosted.length === 1 &&
871
+ project &&
872
+ references.every(({ url }) => url === project.url)) {
873
+ // A typed hint and a bare URL can be two witnesses for the same native
874
+ // project. Keep the hint if any stored occurrence needs it to verify its scope.
875
+ storedSources = [project];
876
+ const native = semgrepPlatformRepositoryReference(project.url, []);
877
+ if (native.platform !== project.platform) {
878
+ try {
879
+ if (current.findings.every((finding) => {
880
+ const binding = semgrepPlatformFindingBinding(finding, "semgrep", [
881
+ native,
882
+ ]);
883
+ return (binding?.url === native.url &&
884
+ !binding.migration &&
885
+ isDeepStrictEqual(binding.sourceData, finding.evidence.source_data));
886
+ }))
887
+ storedSources = [native];
888
+ }
889
+ catch {
890
+ // A private SCM alias or SSH mapping can require the reader's platform.
891
+ }
892
+ }
893
+ }
894
+ if (snyk)
895
+ storedSources.push({
896
+ url: snyk.url,
897
+ platform: snyk.platform === "github"
898
+ ? "github"
899
+ : snyk.gitlab
900
+ ? "gitlab"
901
+ : undefined,
902
+ });
903
+ return preparedLocalStorage(current, options, context, dependencies, matchesRepositoryRemote, {
904
+ sourceRepositories: distinctSourceRepositories(storedSources),
905
+ inspectorProjectMap: options.inspectorProjectMap
906
+ ? [...options.inspectorProjectMap]
907
+ : undefined,
908
+ });
770
909
  }
771
- function preparedLocalStorage(current, options, { repository, options: workbenchOptions, }, dependencies, matchesRepositoryRemote) {
910
+ /** @internal Prepare the transactional write after validating the report and repository. */
911
+ function preparedLocalStorage(current, { provider, sourceKey }, { repository, options: workbenchOptions, }, dependencies, matchesRepositoryRemote, provenance) {
772
912
  dependencies.signal?.throwIfAborted();
773
913
  const preview = {
774
914
  ...cloneImportPreview(current),
775
915
  repository,
776
- source: { provider: options.provider, source_key: options.sourceKey },
916
+ source: { provider, source_key: sourceKey },
777
917
  };
778
918
  const payload = JSON.stringify({
779
919
  repository,
780
- provider: options.provider,
781
- sourceKey: options.sourceKey,
920
+ provider,
921
+ sourceKey,
922
+ read: current.read,
923
+ excluded: current.excluded,
924
+ report: reportForJson(current.report),
925
+ provenance,
782
926
  findings: current.findings.map(({ source_finding_id, evidence }) => ({
783
927
  source_finding_id,
784
928
  evidence,
@@ -821,6 +965,7 @@ function preparedLocalStorage(current, options, { repository, options: workbench
821
965
  }, dependencies.signal);
822
966
  return {
823
967
  ...summary,
968
+ importId: result["importId"],
824
969
  findings: result["findings"],
825
970
  counts: result["counts"],
826
971
  };
@@ -829,14 +974,50 @@ function preparedLocalStorage(current, options, { repository, options: workbench
829
974
  }
830
975
  /** Read imported source records, including evidence that has not been assessed by Codex. */
831
976
  export async function listLocalExternalFindings(selection, dependencies = {}) {
977
+ return (await readLocalExternalFindings(selection, dependencies)).findings;
978
+ }
979
+ export async function readLocalExternalFindings(selection, dependencies) {
832
980
  dependencies.signal?.throwIfAborted();
833
981
  if (selection.id !== undefined)
834
982
  requireIdentity(selection.id, "Finding id");
835
- const { repository, options } = await localContext(selection.repository, dependencies, "read");
983
+ const { selectedPath, result } = await runLocalFindingWorkbench(selection.repository, "read-external-findings", { id: selection.id }, dependencies);
984
+ return {
985
+ repository: selectedPath,
986
+ findings: result["findings"],
987
+ };
988
+ }
989
+ /** Read the precise versions selected by the caller or captured by an earlier import. */
990
+ export async function selectLocalExternalFindings(selection, dependencies = {}) {
991
+ const { repository, importId, findings } = selection;
992
+ if ((importId === undefined) === (findings === undefined))
993
+ throw new CodexSecurityError("Select one import ID or a list of versioned findings.");
994
+ const { result } = await runLocalFindingWorkbench(repository, "read-external-findings", importId !== undefined
995
+ ? { importId, ifCurrent: selection.ifCurrent }
996
+ : { findings: findings.map(({ id, version }) => ({ id, version })) }, dependencies);
997
+ return result;
998
+ }
999
+ /** List this checkout's nonempty imports, most recent first. */
1000
+ export async function listLocalExternalImports({ repository }, dependencies = {}) {
1001
+ const { result } = await runLocalFindingWorkbench(repository, "list-external-imports", {}, dependencies);
1002
+ return result["imports"];
1003
+ }
1004
+ /** @internal Attach Cloud acknowledgements to the versions that were submitted. */
1005
+ export async function recordExternalFindingPublications(input, dependencies = {}) {
1006
+ const { repository, ...receipt } = input;
1007
+ await runLocalFindingWorkbench(repository, "record-external-finding-publications", receipt, dependencies);
1008
+ }
1009
+ /** Read the destination and receipt for each acknowledged finding version. */
1010
+ export async function listLocalFindingPublications({ repository, id }, dependencies = {}) {
1011
+ const { result } = await runLocalFindingWorkbench(repository, "list-external-finding-publications", { id }, dependencies);
1012
+ return result["publications"];
1013
+ }
1014
+ /** @internal Run a command against the workbench for the selected checkout. */
1015
+ async function runLocalFindingWorkbench(path, command, selection, dependencies) {
1016
+ const { repository, selectedPath, options } = await localContext(path, dependencies, "read");
836
1017
  const result = await abortable(() => {
837
1018
  dependencies.signal?.throwIfAborted();
838
- return (dependencies.runWorkbench ?? runWorkbench)(options, ["list-external-findings"], JSON.stringify({ repository, id: selection.id }));
1019
+ return (dependencies.runWorkbench ?? runWorkbench)(options, [command], JSON.stringify({ repository, ...selection }));
839
1020
  }, dependencies.signal);
840
- return result["findings"];
1021
+ return { selectedPath, result };
841
1022
  }
842
1023
  //# sourceMappingURL=external-findings-local.js.map