@openai/codex-security 0.5.1 → 0.7.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 (313) hide show
  1. package/README.md +151 -36
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
  6. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-gnu/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.part-000 +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  15. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  16. package/_bundled_plugin/references/access-advisory.md +11 -0
  17. package/_bundled_plugin/references/core-scan.md +30 -77
  18. package/_bundled_plugin/references/final-report.md +45 -189
  19. package/_bundled_plugin/references/scan-contract.md +2 -0
  20. package/_bundled_plugin/references/scan-prologue.md +1 -1
  21. package/_bundled_plugin/references/scan-runtime.md +1 -5
  22. package/_bundled_plugin/references/threat-model.md +33 -41
  23. package/_bundled_plugin/schemas/coverage.schema.json +12 -1
  24. package/_bundled_plugin/schemas/scan-manifest.schema.json +1 -0
  25. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
  26. package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
  27. package/_bundled_plugin/scripts/deep_scan_workbench.py +145 -85
  28. package/_bundled_plugin/scripts/finalize_scan_contract.py +189 -57
  29. package/_bundled_plugin/scripts/report_projection.py +44 -15
  30. package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
  31. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
  32. package/_bundled_plugin/scripts/workbench/retained_coverage.py +3218 -0
  33. package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
  34. package/_bundled_plugin/scripts/workbench/saved_coverage.py +644 -1
  35. package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
  36. package/_bundled_plugin/scripts/workbench/saved_sources.py +712 -0
  37. package/_bundled_plugin/scripts/workbench_cli.py +3 -0
  38. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
  39. package/_bundled_plugin/scripts/workbench_db.py +51 -22
  40. package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
  41. package/_bundled_plugin/scripts/workbench_finding_workflows.py +53 -9
  42. package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +641 -2387
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +72 -7
  45. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
  47. package/_bundled_plugin/scripts/workbench_target.py +142 -17
  48. package/_bundled_plugin/scripts/workbench_validation.py +9 -2
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +44 -0
  51. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
  52. package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
  53. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
  54. package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
  56. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
  57. package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
  58. package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
  59. package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -30
  60. package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
  61. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
  62. package/_bundled_plugin/skills/publish-findings/SKILL.md +134 -0
  63. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +6 -0
  64. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
  65. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
  66. package/_bundled_plugin/skills/security-scan/SKILL.md +28 -16
  67. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
  68. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
  69. package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
  70. package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
  71. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
  72. package/_bundled_plugin/skills/validation/SKILL.md +42 -104
  73. package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
  74. package/_bundled_plugin/skills/verify-fix/SKILL.md +8 -4
  75. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
  76. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
  77. package/dist/api.d.ts +8 -3
  78. package/dist/api.d.ts.map +1 -1
  79. package/dist/api.js +414 -72
  80. package/dist/api.js.map +1 -1
  81. package/dist/auth.d.ts.map +1 -1
  82. package/dist/auth.js +4 -1
  83. package/dist/auth.js.map +1 -1
  84. package/dist/classify-severity-records.d.ts +5 -2
  85. package/dist/classify-severity-records.d.ts.map +1 -1
  86. package/dist/classify-severity-records.js +40 -34
  87. package/dist/classify-severity-records.js.map +1 -1
  88. package/dist/classify-severity.d.ts +5 -1
  89. package/dist/classify-severity.d.ts.map +1 -1
  90. package/dist/classify-severity.js +20 -30
  91. package/dist/classify-severity.js.map +1 -1
  92. package/dist/cli-help.d.ts.map +1 -1
  93. package/dist/cli-help.js +1 -0
  94. package/dist/cli-help.js.map +1 -1
  95. package/dist/cli.d.ts +9 -2
  96. package/dist/cli.d.ts.map +1 -1
  97. package/dist/cli.js +802 -149
  98. package/dist/cli.js.map +1 -1
  99. package/dist/cloud-endpoint.d.ts +6 -0
  100. package/dist/cloud-endpoint.d.ts.map +1 -0
  101. package/dist/cloud-endpoint.js +51 -0
  102. package/dist/cloud-endpoint.js.map +1 -0
  103. package/dist/cloud-publish.d.ts.map +1 -1
  104. package/dist/cloud-publish.js +7 -5
  105. package/dist/cloud-publish.js.map +1 -1
  106. package/dist/component-scan.d.ts +8 -2
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +2 -0
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/contract.d.ts +2 -0
  111. package/dist/contract.d.ts.map +1 -1
  112. package/dist/contract.js +67 -33
  113. package/dist/contract.js.map +1 -1
  114. package/dist/cost.d.ts +18 -0
  115. package/dist/cost.d.ts.map +1 -1
  116. package/dist/cost.js +107 -12
  117. package/dist/cost.js.map +1 -1
  118. package/dist/coverage-presentation.d.ts +6 -0
  119. package/dist/coverage-presentation.d.ts.map +1 -0
  120. package/dist/coverage-presentation.js +34 -0
  121. package/dist/coverage-presentation.js.map +1 -0
  122. package/dist/custom-validation-prompt.js +3 -3
  123. package/dist/custom-validation-prompt.js.map +1 -1
  124. package/dist/custom-validation.d.ts.map +1 -1
  125. package/dist/custom-validation.js +30 -4
  126. package/dist/custom-validation.js.map +1 -1
  127. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  128. package/dist/deduplication/checkpointed-review.js +3 -1
  129. package/dist/deduplication/checkpointed-review.js.map +1 -1
  130. package/dist/deduplication/scan.d.ts.map +1 -1
  131. package/dist/deduplication/scan.js +7 -5
  132. package/dist/deduplication/scan.js.map +1 -1
  133. package/dist/default-severity-rubric.d.ts +3 -0
  134. package/dist/default-severity-rubric.d.ts.map +1 -0
  135. package/dist/default-severity-rubric.js +67 -0
  136. package/dist/default-severity-rubric.js.map +1 -0
  137. package/dist/endor-findings.d.ts +8 -0
  138. package/dist/endor-findings.d.ts.map +1 -0
  139. package/dist/endor-findings.js +238 -0
  140. package/dist/endor-findings.js.map +1 -0
  141. package/dist/external-findings-import.d.ts +5 -0
  142. package/dist/external-findings-import.d.ts.map +1 -0
  143. package/dist/external-findings-import.js +46 -0
  144. package/dist/external-findings-import.js.map +1 -0
  145. package/dist/external-findings-local.d.ts +63 -0
  146. package/dist/external-findings-local.d.ts.map +1 -0
  147. package/dist/external-findings-local.js +344 -0
  148. package/dist/external-findings-local.js.map +1 -0
  149. package/dist/external-findings-publish.d.ts +73 -0
  150. package/dist/external-findings-publish.d.ts.map +1 -0
  151. package/dist/external-findings-publish.js +721 -0
  152. package/dist/external-findings-publish.js.map +1 -0
  153. package/dist/external-findings-read.d.ts +16 -0
  154. package/dist/external-findings-read.d.ts.map +1 -0
  155. package/dist/external-findings-read.js +97 -0
  156. package/dist/external-findings-read.js.map +1 -0
  157. package/dist/external-findings.d.ts +21 -0
  158. package/dist/external-findings.d.ts.map +1 -0
  159. package/dist/external-findings.js +2 -0
  160. package/dist/external-findings.js.map +1 -0
  161. package/dist/external-import-contract.d.ts +15 -0
  162. package/dist/external-import-contract.d.ts.map +1 -0
  163. package/dist/external-import-contract.js +262 -0
  164. package/dist/external-import-contract.js.map +1 -0
  165. package/dist/external-import-models.d.ts +362 -0
  166. package/dist/external-import-models.d.ts.map +1 -0
  167. package/dist/external-import-models.js +3 -0
  168. package/dist/external-import-models.js.map +1 -0
  169. package/dist/external-imports-feature.d.ts +6 -0
  170. package/dist/external-imports-feature.d.ts.map +1 -0
  171. package/dist/external-imports-feature.js +51 -0
  172. package/dist/external-imports-feature.js.map +1 -0
  173. package/dist/finding-workflow.d.ts +23 -6
  174. package/dist/finding-workflow.d.ts.map +1 -1
  175. package/dist/finding-workflow.js +23 -10
  176. package/dist/finding-workflow.js.map +1 -1
  177. package/dist/github-advisories.d.ts +386 -0
  178. package/dist/github-advisories.d.ts.map +1 -0
  179. package/dist/github-advisories.js +133 -0
  180. package/dist/github-advisories.js.map +1 -0
  181. package/dist/github-findings.d.ts +11 -0
  182. package/dist/github-findings.d.ts.map +1 -0
  183. package/dist/github-findings.js +258 -0
  184. package/dist/github-findings.js.map +1 -0
  185. package/dist/hosted-remediation-protocol.d.ts +2 -1
  186. package/dist/hosted-remediation-protocol.d.ts.map +1 -1
  187. package/dist/hosted-remediation-protocol.js +17 -11
  188. package/dist/hosted-remediation-protocol.js.map +1 -1
  189. package/dist/hosted-remediation.d.ts +4 -0
  190. package/dist/hosted-remediation.d.ts.map +1 -1
  191. package/dist/hosted-remediation.js +22 -3
  192. package/dist/hosted-remediation.js.map +1 -1
  193. package/dist/hosted-scan.d.ts +16 -0
  194. package/dist/hosted-scan.d.ts.map +1 -1
  195. package/dist/hosted-scan.js +9 -2
  196. package/dist/hosted-scan.js.map +1 -1
  197. package/dist/import-scan.js +1 -1
  198. package/dist/import-scan.js.map +1 -1
  199. package/dist/index.d.ts +16 -3
  200. package/dist/index.d.ts.map +1 -1
  201. package/dist/index.js +9 -1
  202. package/dist/index.js.map +1 -1
  203. package/dist/knowledge-base.d.ts +1 -0
  204. package/dist/knowledge-base.d.ts.map +1 -1
  205. package/dist/knowledge-base.js +17 -8
  206. package/dist/knowledge-base.js.map +1 -1
  207. package/dist/models.d.ts +1 -0
  208. package/dist/models.d.ts.map +1 -1
  209. package/dist/models.js.map +1 -1
  210. package/dist/owner-evidence.d.ts +2 -0
  211. package/dist/owner-evidence.d.ts.map +1 -1
  212. package/dist/owner-evidence.js +2 -1
  213. package/dist/owner-evidence.js.map +1 -1
  214. package/dist/project-config-schema.d.ts +2 -0
  215. package/dist/project-config-schema.d.ts.map +1 -1
  216. package/dist/project-config-schema.js +1 -0
  217. package/dist/project-config-schema.js.map +1 -1
  218. package/dist/project-config.d.ts +1 -0
  219. package/dist/project-config.d.ts.map +1 -1
  220. package/dist/project-config.js +2 -0
  221. package/dist/project-config.js.map +1 -1
  222. package/dist/publish.d.ts +2 -0
  223. package/dist/publish.d.ts.map +1 -1
  224. package/dist/publish.js +1 -1
  225. package/dist/publish.js.map +1 -1
  226. package/dist/remediation.d.ts +7 -25
  227. package/dist/remediation.d.ts.map +1 -1
  228. package/dist/remediation.js +18 -28
  229. package/dist/remediation.js.map +1 -1
  230. package/dist/result.d.ts +4 -0
  231. package/dist/result.d.ts.map +1 -1
  232. package/dist/result.js +10 -0
  233. package/dist/result.js.map +1 -1
  234. package/dist/runtime.d.ts +1 -0
  235. package/dist/runtime.d.ts.map +1 -1
  236. package/dist/runtime.js +10 -8
  237. package/dist/runtime.js.map +1 -1
  238. package/dist/scan-dashboard.d.ts +5 -3
  239. package/dist/scan-dashboard.d.ts.map +1 -1
  240. package/dist/scan-dashboard.js +79 -26
  241. package/dist/scan-dashboard.js.map +1 -1
  242. package/dist/scan-history-renderer.d.ts.map +1 -1
  243. package/dist/scan-history-renderer.js +8 -2
  244. package/dist/scan-history-renderer.js.map +1 -1
  245. package/dist/scan-owner-suggestions.d.ts +8 -0
  246. package/dist/scan-owner-suggestions.d.ts.map +1 -0
  247. package/dist/scan-owner-suggestions.js +33 -0
  248. package/dist/scan-owner-suggestions.js.map +1 -0
  249. package/dist/scan-settings.d.ts +1 -0
  250. package/dist/scan-settings.d.ts.map +1 -1
  251. package/dist/scan-settings.js +4 -0
  252. package/dist/scan-settings.js.map +1 -1
  253. package/dist/scan-usage-display.d.ts +8 -0
  254. package/dist/scan-usage-display.d.ts.map +1 -0
  255. package/dist/scan-usage-display.js +46 -0
  256. package/dist/scan-usage-display.js.map +1 -0
  257. package/dist/scanner-import.d.ts +20 -0
  258. package/dist/scanner-import.d.ts.map +1 -0
  259. package/dist/scanner-import.js +208 -0
  260. package/dist/scanner-import.js.map +1 -0
  261. package/dist/security-policy-diff.d.ts +2 -0
  262. package/dist/security-policy-diff.d.ts.map +1 -0
  263. package/dist/security-policy-diff.js +197 -0
  264. package/dist/security-policy-diff.js.map +1 -0
  265. package/dist/security-policy.d.ts +7 -3
  266. package/dist/security-policy.d.ts.map +1 -1
  267. package/dist/security-policy.js +11 -76
  268. package/dist/security-policy.js.map +1 -1
  269. package/dist/semgrep-findings.d.ts +10 -0
  270. package/dist/semgrep-findings.d.ts.map +1 -0
  271. package/dist/semgrep-findings.js +293 -0
  272. package/dist/semgrep-findings.js.map +1 -0
  273. package/dist/severity-review.d.ts +3 -0
  274. package/dist/severity-review.d.ts.map +1 -1
  275. package/dist/severity-review.js +19 -0
  276. package/dist/severity-review.js.map +1 -1
  277. package/dist/severity-store.js +7 -2
  278. package/dist/severity-store.js.map +1 -1
  279. package/dist/skill-authentication.d.ts +18 -0
  280. package/dist/skill-authentication.d.ts.map +1 -0
  281. package/dist/skill-authentication.js +82 -0
  282. package/dist/skill-authentication.js.map +1 -0
  283. package/dist/snyk-findings.d.ts +10 -0
  284. package/dist/snyk-findings.d.ts.map +1 -0
  285. package/dist/snyk-findings.js +350 -0
  286. package/dist/snyk-findings.js.map +1 -0
  287. package/dist/suggest-owners.d.ts +4 -1
  288. package/dist/suggest-owners.d.ts.map +1 -1
  289. package/dist/suggest-owners.js +53 -21
  290. package/dist/suggest-owners.js.map +1 -1
  291. package/dist/targets.d.ts +2 -2
  292. package/dist/targets.d.ts.map +1 -1
  293. package/dist/targets.js +16 -3
  294. package/dist/targets.js.map +1 -1
  295. package/dist/wiz-csv.d.ts +9 -0
  296. package/dist/wiz-csv.d.ts.map +1 -0
  297. package/dist/wiz-csv.js +116 -0
  298. package/dist/wiz-csv.js.map +1 -0
  299. package/dist/wiz-findings.d.ts +5 -0
  300. package/dist/wiz-findings.d.ts.map +1 -0
  301. package/dist/wiz-findings.js +464 -0
  302. package/dist/wiz-findings.js.map +1 -0
  303. package/docs/classify-severity-records.md +30 -13
  304. package/docs/cli.md +835 -47
  305. package/docs/findings-service.md +119 -118
  306. package/docs/hosted-remediation.md +43 -24
  307. package/docs/hosted-scans.md +38 -0
  308. package/package.json +11 -9
  309. package/schemas/external-findings.schema.json +1421 -0
  310. package/schemas/project-config.schema.json +4 -0
  311. package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
  312. package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
  313. package/_bundled_plugin/scripts/rank_preview.py +0 -129
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-advisories.js","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,OAAO;IACP,QAAQ;IACR,QAAQ;CACA,CAAC;AAsCX,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAoC,EACpC,YAAY,GAAqC,EAAE;IAEnD,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAC5D,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,oCAAoC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,K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,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Octokit } from \"@octokit/core\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\nimport { createAuthenticatedGitHub } from \"./github.js\";\n\nexport const GITHUB_ADVISORY_STATES = [\n \"published\",\n \"draft\",\n \"triage\",\n \"closed\",\n] as const;\n\nexport interface GitHubAdvisoryImportOptions {\n /** Source repository, or the selected target for explicit global advisory IDs. */\n repository: string;\n /** Exact GHSA IDs. Required for the global advisory API. */\n advisoryIds?: readonly string[];\n /** Repository advisories by default; global never enumerates the database. */\n source?: \"repository\" | \"global\";\n /** Repository list state (default: published). Exact IDs ignore state. */\n state?: (typeof GITHUB_ADVISORY_STATES)[number];\n /** Defaults to GH_HOST or github.com. */\n githubHost?: string;\n /** Omit to use the authenticated GitHub CLI. */\n githubToken?: string;\n signal?: AbortSignal;\n}\n\ntype RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;\ntype GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;\n\nexport interface ImportedGitHubAdvisory {\n source: \"github-security-advisory\";\n selection: \"repository\" | \"global\";\n repository: string;\n githubHost: string;\n ghsaId: string;\n url: string;\n /** Upstream disclosure, not proof that the selected repository is affected. */\n advisory: RepositoryAdvisory | GlobalAdvisory;\n}\n\ninterface GitHubAdvisoryImportDependencies {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;\n}\n\n/** Read repository disclosures or explicitly selected public GHSA records. */\nexport async function importGitHubAdvisories(\n options: GitHubAdvisoryImportOptions,\n dependencies: GitHubAdvisoryImportDependencies = {},\n): Promise<ImportedGitHubAdvisory[]> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n requireExternalImports(environment);\n const repository = options.repository.trim();\n const parts = /^([a-z0-9_.-]+)\\/([a-z0-9_.-]+)$/iu.exec(repository);\n if (!parts || parts.slice(1).some((part) => /^\\.{1,2}$/u.test(part)))\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n const owner = parts[1]!;\n const repo = parts[2]!;\n const ids = [\n ...new Set(\n (options.advisoryIds ?? []).map((id) =>\n id\n .trim()\n .toLowerCase()\n .replace(/^ghsa-/u, \"GHSA-\"),\n ),\n ),\n ];\n if (ids.some((id) => !/^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/u.test(id)))\n throw new CodexSecurityError(\n \"GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.\",\n );\n const source = options.source ?? \"repository\";\n const state = options.state ?? \"published\";\n if (source !== \"repository\" && source !== \"global\")\n throw new CodexSecurityError(\n \"GitHub advisory source must be repository or global.\",\n );\n if (!GITHUB_ADVISORY_STATES.includes(state))\n throw new CodexSecurityError(\"GitHub advisory state is invalid.\");\n if (source === \"global\" && ids.length === 0)\n throw new CodexSecurityError(\n \"Select explicit GHSA IDs for global advisories; database-wide import is not supported.\",\n );\n if (ids.length > 0 && state !== \"published\")\n throw new CodexSecurityError(\n \"--github-state only filters repository lists; omit it when selecting exact GHSA IDs.\",\n );\n const host =\n options.githubHost?.trim() ??\n (environment[\"GH_HOST\"]?.trim() || \"github.com\");\n if (!host) throw new CodexSecurityError(\"GitHub host must not be empty.\");\n\n try {\n const github = dependencies.createGitHub\n ? await dependencies.createGitHub(host, options.signal)\n : await createAuthenticatedGitHub(host, {\n token: options.githubToken,\n environment,\n currentDirectory: dependencies.currentDirectory,\n signal: options.signal,\n });\n const advisories: (RepositoryAdvisory | GlobalAdvisory)[] = [];\n if (ids.length > 0) {\n for (const id of ids) {\n options.signal?.throwIfAborted();\n advisories.push(\n source === \"global\"\n ? await fetchGlobalAdvisory(github, id, options.signal)\n : await fetchRepositoryAdvisory(\n github,\n owner,\n repo,\n id,\n options.signal,\n ),\n );\n }\n } else {\n let after: string | undefined;\n const cursors = new Set<string>();\n do {\n options.signal?.throwIfAborted();\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories\",\n {\n owner,\n repo,\n state,\n per_page: 100,\n after,\n request: { signal: options.signal, redirect: \"error\" },\n },\n );\n advisories.push(...response.data);\n const next = response.headers.link\n ?.split(\",\")\n .find((link) => /;\\s*rel=\"next\"/u.test(link));\n const nextUrl = next?.match(/<([^>]+)>/u)?.[1];\n // Keep requests on the authenticated route; only carry over the cursor.\n after = nextUrl\n ? (new URL(nextUrl).searchParams.get(\"after\") ?? undefined)\n : undefined;\n if (next && (!after || cursors.has(after)))\n throw new CodexSecurityError(\n \"GitHub returned invalid advisory pagination.\",\n );\n if (after) cursors.add(after);\n } while (after !== undefined);\n }\n return advisories.map((advisory) => ({\n source: \"github-security-advisory\",\n selection: source,\n repository,\n githubHost: host,\n ghsaId: advisory.ghsa_id,\n url: advisory.html_url,\n advisory,\n }));\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error instanceof CodexSecurityError) throw error;\n const status =\n typeof error === \"object\" && error !== null && \"status\" in error\n ? error.status\n : undefined;\n if (status === 401)\n throw new CodexSecurityError(\"GitHub authentication failed.\");\n if (status === 403)\n throw new CodexSecurityError(\n \"GitHub denied security advisory access. Check repository advisory permissions and API rate limits.\",\n );\n if (status === 404)\n throw new CodexSecurityError(\n \"GitHub repository or security advisory was not found or is not accessible.\",\n );\n if (status === 429)\n throw new CodexSecurityError(\n \"GitHub request was rate limited. Wait and retry.\",\n );\n throw new CodexSecurityError(\n `GitHub security advisory request failed${typeof status === \"number\" ? ` (HTTP ${status})` : \"\"}: ${errorMessage(error)}`,\n );\n }\n}\n\nasync function fetchRepositoryAdvisory(\n github: Octokit,\n owner: string,\n repo: string,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}\",\n {\n owner,\n repo,\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n\nasync function fetchGlobalAdvisory(\n github: Octokit,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\"GET /advisories/{ghsa_id}\", {\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n });\n return response.data;\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { ExternalImportTarget } from "./external-import-contract.js";
2
+ import type { ExternalFindings } from "./external-findings.js";
3
+ import type { ImportedGitHubCodeScanningAlert } from "./github.js";
4
+ import type { ImportedGitHubAdvisory } from "./github-advisories.js";
5
+ /** Map selected code-scanning instances while retaining complete upstream evidence. */
6
+ export declare function normalizeGitHubCodeScanningAlerts(alerts: readonly ImportedGitHubCodeScanningAlert[], target?: ExternalImportTarget): ExternalFindings;
7
+ /** Map advisory disclosures without asserting an installed vulnerable dependency. */
8
+ export declare function normalizeGitHubAdvisories(advisories: readonly ImportedGitHubAdvisory[], target?: ExternalImportTarget): ExternalFindings;
9
+ /** Read unfiltered JSON/JSONL output saved by the read-only GitHub import commands. */
10
+ export declare function readGitHubFindings(path: string, target?: ExternalImportTarget): Promise<ExternalFindings>;
11
+ //# sourceMappingURL=github-findings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-findings.d.ts","sourceRoot":"","sources":["../src/github-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAI1E,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAySrE,uFAAuF;AACvF,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,SAAS,+BAA+B,EAAE,EAClD,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAElB;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,SAAS,sBAAsB,EAAE,EAC7C,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAElB;AAED,uFAAuF;AACvF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CAa3B"}
@@ -0,0 +1,258 @@
1
+ import { hash } from "node:crypto";
2
+ import { CodexSecurityError, errorMessage } from "./errors.js";
3
+ import { validateExternalEvidence } from "./external-import-contract.js";
4
+ import { parseJsonOrJsonl, readScannerText, text } from "./scanner-import.js";
5
+ function object(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value)
7
+ ? value
8
+ : undefined;
9
+ }
10
+ function repositoryName(value) {
11
+ const repository = text(value);
12
+ const parts = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)$/iu.exec(repository ?? "");
13
+ if (!parts || parts.slice(1).some((part) => /^\.{1,2}$/u.test(part)))
14
+ throw new Error("GitHub repository must be OWNER/REPO.");
15
+ return repository;
16
+ }
17
+ function sourceUrl(value) {
18
+ const parsed = new URL(value);
19
+ const origin = /^(https?:\/\/([^/?#]+))/iu.exec(value);
20
+ if (!origin)
21
+ throw new Error("GitHub evidence URL must be an HTTP(S) link.");
22
+ // URL.origin/host remove explicit default ports; Cloud keeps those distinct.
23
+ return { parsed, host: origin[2].toLowerCase(), origin: origin[1] };
24
+ }
25
+ function sourceTimestamp(value) {
26
+ if (value === undefined || value === null)
27
+ return null;
28
+ const seconds = typeof value === "string" ? Date.parse(value) / 1000 : NaN;
29
+ if (!Number.isFinite(seconds) || seconds < 0)
30
+ throw new Error("GitHub updated_at is not a valid timestamp.");
31
+ return Math.floor(seconds);
32
+ }
33
+ function severity(value) {
34
+ // SARIF error/warning/note are not vulnerability severity ratings.
35
+ return typeof value === "string" &&
36
+ ["critical", "high", "medium", "low", "informational"].includes(value)
37
+ ? value
38
+ : "unknown";
39
+ }
40
+ function codeScanningFinding(record, target = "cloud") {
41
+ const repository = repositoryName(record["repository"]);
42
+ const alert = object(record["alert"]);
43
+ const number = record["number"];
44
+ if (!alert ||
45
+ typeof number !== "number" ||
46
+ !Number.isSafeInteger(number) ||
47
+ number < 1 ||
48
+ alert["number"] !== number)
49
+ throw new Error("Expected a GitHub code-scanning import with matching alert numbers.");
50
+ const url = text(record["url"]);
51
+ if (!url || url !== alert["html_url"])
52
+ throw new Error("GitHub alert URL must match the original alert.");
53
+ const { parsed: parsedUrl, host, origin } = sourceUrl(url);
54
+ if (!["security/code-scanning", "code-scanning"].some((route) => parsedUrl.pathname.toLowerCase() ===
55
+ `/${repository}/${route}/${number}`.toLowerCase()))
56
+ throw new Error("GitHub alert URL does not match the selected repository and alert.");
57
+ const rule = object(alert["rule"]);
58
+ const instance = object(alert["most_recent_instance"]);
59
+ const ref = text(instance?.["ref"]);
60
+ if (!ref)
61
+ throw new Error("GitHub code-scanning evidence requires the selected instance ref.");
62
+ const location = object(instance?.["location"]);
63
+ const tool = object(alert["tool"]);
64
+ const message = text(object(instance?.["message"])?.["text"]);
65
+ const description = text(rule?.["full_description"]) ?? text(rule?.["description"]);
66
+ const tags = Array.isArray(rule?.["tags"]) ? rule["tags"] : [];
67
+ const weaknessIds = [
68
+ ...new Set(tags.flatMap((tag) => {
69
+ const match = typeof tag === "string"
70
+ ? /^external\/cwe\/cwe-(\d+)$/iu.exec(tag)
71
+ : null;
72
+ return match ? [`CWE-${Number(match[1])}`] : [];
73
+ })),
74
+ ];
75
+ const path = text(location?.["path"]);
76
+ const sourceId = `${host}/${repository.toLowerCase()}/code-scanning/${number}/${hash("sha256", ref)}`;
77
+ return {
78
+ source_finding_id: sourceId,
79
+ evidence: validateExternalEvidence({
80
+ title: text(rule?.["name"]) ??
81
+ text(rule?.["description"]) ??
82
+ `GitHub code-scanning alert #${number}`,
83
+ severity: severity(rule?.["security_severity_level"]),
84
+ description: [...new Set([message, description].filter(Boolean))].join("\n\n") ||
85
+ null,
86
+ url,
87
+ locations: path
88
+ ? [{ path, line: location?.["start_line"] ?? null }]
89
+ : [],
90
+ branch: ref,
91
+ code_revision: text(instance?.["commit_sha"]),
92
+ source_updated_at: sourceTimestamp(alert["updated_at"]),
93
+ source_data: record,
94
+ details: {
95
+ kind: "sast",
96
+ repository: {
97
+ url: `${origin}/${repository}`,
98
+ name: repository,
99
+ },
100
+ // Dismissal covers every branch; detection state belongs to the selected ref.
101
+ source_status: alert["state"] === "dismissed"
102
+ ? "dismissed"
103
+ : (text(instance?.["state"]) ?? text(alert["state"])),
104
+ scanner_origin: text(tool?.["name"]),
105
+ rule: { id: text(rule?.["id"]), name: text(rule?.["name"]) },
106
+ weakness_ids: weaknessIds,
107
+ remediation_instructions: text(rule?.["help"]),
108
+ code: path ? { end_line: location?.["end_line"] ?? null } : null,
109
+ },
110
+ }, target),
111
+ };
112
+ }
113
+ function advisoryFinding(record, target = "cloud") {
114
+ const repository = repositoryName(record["repository"]);
115
+ const advisory = object(record["advisory"]);
116
+ const id = text(record["ghsaId"]);
117
+ const selection = record["selection"];
118
+ if (!advisory ||
119
+ !id ||
120
+ !/^GHSA-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/iu.test(id) ||
121
+ text(advisory["ghsa_id"])?.toUpperCase() !== id.toUpperCase())
122
+ throw new Error("Expected a GitHub advisory import with matching GHSA IDs.");
123
+ if (selection !== "repository" && selection !== "global")
124
+ throw new Error("GitHub advisory selection must be repository or global.");
125
+ const url = text(record["url"]);
126
+ if (!url || url !== advisory["html_url"])
127
+ throw new Error("GitHub advisory URL must match the original advisory.");
128
+ const { parsed: parsedUrl, host: linkHost, origin } = sourceUrl(url);
129
+ const host = text(record["githubHost"])?.toLowerCase();
130
+ // Enterprise APIs may return the public advisory database's canonical link.
131
+ const canonicalGlobalLink = selection === "global" && parsedUrl.host === "github.com";
132
+ const expectedPath = selection === "repository"
133
+ ? `/${repository}/security/advisories/${id}`
134
+ : `/advisories/${id}`;
135
+ if (!host ||
136
+ (linkHost !== host && !canonicalGlobalLink) ||
137
+ parsedUrl.pathname.toLowerCase() !== expectedPath.toLowerCase())
138
+ throw new Error("GitHub advisory URL does not match the selected source and GHSA ID.");
139
+ const vulnerabilities = advisory["vulnerabilities"] === null ? [] : advisory["vulnerabilities"];
140
+ if (!Array.isArray(vulnerabilities))
141
+ throw new Error("GitHub advisory vulnerabilities must be an array.");
142
+ const identifiers = Array.isArray(advisory["identifiers"])
143
+ ? advisory["identifiers"]
144
+ : [];
145
+ const advisoryIds = [
146
+ id,
147
+ text(advisory["cve_id"]),
148
+ ...identifiers.map((identifier) => text(object(identifier)?.["value"])),
149
+ ].filter((value) => value !== null);
150
+ const packages = vulnerabilities.flatMap((value) => {
151
+ const vulnerability = object(value);
152
+ const pkg = object(vulnerability?.["package"]);
153
+ const name = text(pkg?.["name"]);
154
+ // GitHub permits incomplete package metadata in advisory disclosures.
155
+ // Preserve it in source_data without inventing a typed package identity.
156
+ if (!name)
157
+ return [];
158
+ const fixedVersion = text(vulnerability?.["first_patched_version"]) ??
159
+ text(vulnerability?.["patched_versions"]);
160
+ return [
161
+ {
162
+ name,
163
+ ecosystem: text(pkg?.["ecosystem"]),
164
+ vulnerable_version_range: text(vulnerability?.["vulnerable_version_range"]),
165
+ fixed_versions: fixedVersion ? [fixedVersion] : [],
166
+ },
167
+ ];
168
+ });
169
+ const cwes = Array.isArray(advisory["cwes"]) ? advisory["cwes"] : [];
170
+ return {
171
+ source_finding_id: `${host}/${selection === "repository" ? repository.toLowerCase() : "global"}/security-advisory/${id.toUpperCase()}`,
172
+ evidence: validateExternalEvidence({
173
+ title: text(advisory["summary"]) ?? id,
174
+ severity: severity(advisory["severity"]),
175
+ description: text(advisory["description"]),
176
+ url,
177
+ advisory_ids: [...new Set(advisoryIds)],
178
+ packages,
179
+ source_updated_at: sourceTimestamp(advisory["updated_at"]),
180
+ source_data: record,
181
+ details: {
182
+ kind: "advisory",
183
+ advisory: { source: selection },
184
+ ...(selection === "repository"
185
+ ? {
186
+ repository: {
187
+ url: `${origin}/${repository}`,
188
+ name: repository,
189
+ },
190
+ }
191
+ : {}),
192
+ source_status: text(advisory["withdrawn_at"])
193
+ ? "withdrawn"
194
+ : (text(advisory["state"]) ??
195
+ (selection === "global" ? "published" : null)),
196
+ scanner_origin: "GitHub Security Advisories",
197
+ weakness_ids: cwes
198
+ .map((value) => text(object(value)?.["cwe_id"]))
199
+ .filter((value) => value !== null),
200
+ },
201
+ }, target),
202
+ };
203
+ }
204
+ function normalizeRecords(records, target = "cloud") {
205
+ const result = {
206
+ read: records.length,
207
+ findings: [],
208
+ excluded: [],
209
+ };
210
+ const identities = new Set();
211
+ for (const [index, value] of records.entries()) {
212
+ const record = object(value);
213
+ try {
214
+ if (!record)
215
+ throw new Error("GitHub finding must be an object.");
216
+ let finding;
217
+ if (record["source"] === "github-code-scanning")
218
+ finding = codeScanningFinding(record, target);
219
+ else if (record["source"] === "github-security-advisory")
220
+ finding = advisoryFinding(record, target);
221
+ else
222
+ throw new Error("Expected saved output from import github or import github-advisories; raw or incomplete API responses need an explicit mapping.");
223
+ if (identities.has(finding.source_finding_id))
224
+ throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}. Select each GitHub occurrence once.`);
225
+ identities.add(finding.source_finding_id);
226
+ result.findings.push(finding);
227
+ }
228
+ catch (error) {
229
+ if (error instanceof CodexSecurityError)
230
+ throw error;
231
+ result.excluded.push({
232
+ position: index + 1,
233
+ source_finding_id: text(record?.["url"]),
234
+ reason: errorMessage(error),
235
+ });
236
+ }
237
+ }
238
+ return result;
239
+ }
240
+ /** Map selected code-scanning instances while retaining complete upstream evidence. */
241
+ export function normalizeGitHubCodeScanningAlerts(alerts, target = "cloud") {
242
+ return normalizeRecords(alerts, target);
243
+ }
244
+ /** Map advisory disclosures without asserting an installed vulnerable dependency. */
245
+ export function normalizeGitHubAdvisories(advisories, target = "cloud") {
246
+ return normalizeRecords(advisories, target);
247
+ }
248
+ /** Read unfiltered JSON/JSONL output saved by the read-only GitHub import commands. */
249
+ export async function readGitHubFindings(path, target = "cloud") {
250
+ try {
251
+ const payload = parseJsonOrJsonl(await readScannerText(path));
252
+ return normalizeRecords(Array.isArray(payload) ? payload : [payload], target);
253
+ }
254
+ catch (cause) {
255
+ throw new CodexSecurityError(`Could not read GitHub findings as UTF-8 JSON or JSONL: ${errorMessage(cause)}`, { cause });
256
+ }
257
+ }
258
+ //# sourceMappingURL=github-findings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-findings.js","sourceRoot":"","sources":["../src/github-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAIzE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE9E,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,oCAAoC,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IAC1E,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,OAAO,UAAW,CAAC;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AC;YACrD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACnB,QAAQ,EAAE,KAAK,GAAG,CAAC;gBACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;gBACxC,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,iCAAiC,CAC/C,MAAkD,EAClD,MAAM,GAAyB,OAAO;IAEtC,OAAO,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,yBAAyB,CACvC,UAA6C,EAC7C,MAAM,GAAyB,OAAO;IAEtC,OAAO,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAY,EACZ,MAAM,GAAyB,OAAO;IAEtC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,OAAO,gBAAgB,CACrB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAC5C,MAAM,CACP,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAC1B,0DAA0D,YAAY,CAAC,KAAK,CAAC,EAAE,EAC/E,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { hash } from \"node:crypto\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport type { ImportedGitHubCodeScanningAlert } from \"./github.js\";\nimport type { ImportedGitHubAdvisory } from \"./github-advisories.js\";\nimport { parseJsonOrJsonl, readScannerText, text } from \"./scanner-import.js\";\n\nfunction object(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nfunction repositoryName(value: unknown): string {\n const repository = text(value);\n const parts = /^([a-z0-9_.-]+)\\/([a-z0-9_.-]+)$/iu.exec(repository ?? \"\");\n if (!parts || parts.slice(1).some((part) => /^\\.{1,2}$/u.test(part)))\n throw new Error(\"GitHub repository must be OWNER/REPO.\");\n return repository!;\n}\n\nfunction sourceUrl(value: string): {\n parsed: URL;\n host: string;\n origin: string;\n} {\n const parsed = new URL(value);\n const origin = /^(https?:\\/\\/([^/?#]+))/iu.exec(value);\n if (!origin) throw new Error(\"GitHub evidence URL must be an HTTP(S) link.\");\n // URL.origin/host remove explicit default ports; Cloud keeps those distinct.\n return { parsed, host: origin[2]!.toLowerCase(), origin: origin[1]! };\n}\n\nfunction sourceTimestamp(value: unknown): number | null {\n if (value === undefined || value === null) return null;\n const seconds = typeof value === \"string\" ? Date.parse(value) / 1000 : NaN;\n if (!Number.isFinite(seconds) || seconds < 0)\n throw new Error(\"GitHub updated_at is not a valid timestamp.\");\n return Math.floor(seconds);\n}\n\nfunction severity(value: unknown): string {\n // SARIF error/warning/note are not vulnerability severity ratings.\n return typeof value === \"string\" &&\n [\"critical\", \"high\", \"medium\", \"low\", \"informational\"].includes(value)\n ? value\n : \"unknown\";\n}\n\nfunction codeScanningFinding(\n record: Record<string, unknown>,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFinding {\n const repository = repositoryName(record[\"repository\"]);\n const alert = object(record[\"alert\"]);\n const number = record[\"number\"];\n if (\n !alert ||\n typeof number !== \"number\" ||\n !Number.isSafeInteger(number) ||\n number < 1 ||\n alert[\"number\"] !== number\n )\n throw new Error(\n \"Expected a GitHub code-scanning import with matching alert numbers.\",\n );\n const url = text(record[\"url\"]);\n if (!url || url !== alert[\"html_url\"])\n throw new Error(\"GitHub alert URL must match the original alert.\");\n const { parsed: parsedUrl, host, origin } = sourceUrl(url);\n if (\n ![\"security/code-scanning\", \"code-scanning\"].some(\n (route) =>\n parsedUrl.pathname.toLowerCase() ===\n `/${repository}/${route}/${number}`.toLowerCase(),\n )\n )\n throw new Error(\n \"GitHub alert URL does not match the selected repository and alert.\",\n );\n const rule = object(alert[\"rule\"]);\n const instance = object(alert[\"most_recent_instance\"]);\n const ref = text(instance?.[\"ref\"]);\n if (!ref)\n throw new Error(\n \"GitHub code-scanning evidence requires the selected instance ref.\",\n );\n const location = object(instance?.[\"location\"]);\n const tool = object(alert[\"tool\"]);\n const message = text(object(instance?.[\"message\"])?.[\"text\"]);\n const description =\n text(rule?.[\"full_description\"]) ?? text(rule?.[\"description\"]);\n const tags = Array.isArray(rule?.[\"tags\"]) ? rule[\"tags\"] : [];\n const weaknessIds = [\n ...new Set(\n tags.flatMap((tag: unknown) => {\n const match =\n typeof tag === \"string\"\n ? /^external\\/cwe\\/cwe-(\\d+)$/iu.exec(tag)\n : null;\n return match ? [`CWE-${Number(match[1])}`] : [];\n }),\n ),\n ];\n const path = text(location?.[\"path\"]);\n const sourceId = `${host}/${repository.toLowerCase()}/code-scanning/${number}/${hash(\"sha256\", ref)}`;\n return {\n source_finding_id: sourceId,\n evidence: validateExternalEvidence(\n {\n title:\n text(rule?.[\"name\"]) ??\n text(rule?.[\"description\"]) ??\n `GitHub code-scanning alert #${number}`,\n severity: severity(rule?.[\"security_severity_level\"]),\n description:\n [...new Set([message, description].filter(Boolean))].join(\"\\n\\n\") ||\n null,\n url,\n locations: path\n ? [{ path, line: location?.[\"start_line\"] ?? null }]\n : [],\n branch: ref,\n code_revision: text(instance?.[\"commit_sha\"]),\n source_updated_at: sourceTimestamp(alert[\"updated_at\"]),\n source_data: record,\n details: {\n kind: \"sast\",\n repository: {\n url: `${origin}/${repository}`,\n name: repository,\n },\n // Dismissal covers every branch; detection state belongs to the selected ref.\n source_status:\n alert[\"state\"] === \"dismissed\"\n ? \"dismissed\"\n : (text(instance?.[\"state\"]) ?? text(alert[\"state\"])),\n scanner_origin: text(tool?.[\"name\"]),\n rule: { id: text(rule?.[\"id\"]), name: text(rule?.[\"name\"]) },\n weakness_ids: weaknessIds,\n remediation_instructions: text(rule?.[\"help\"]),\n code: path ? { end_line: location?.[\"end_line\"] ?? null } : null,\n },\n },\n target,\n ),\n };\n}\n\nfunction advisoryFinding(\n record: Record<string, unknown>,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFinding {\n const repository = repositoryName(record[\"repository\"]);\n const advisory = object(record[\"advisory\"]);\n const id = text(record[\"ghsaId\"]);\n const selection = record[\"selection\"];\n if (\n !advisory ||\n !id ||\n !/^GHSA-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/iu.test(id) ||\n text(advisory[\"ghsa_id\"])?.toUpperCase() !== id.toUpperCase()\n )\n throw new Error(\n \"Expected a GitHub advisory import with matching GHSA IDs.\",\n );\n if (selection !== \"repository\" && selection !== \"global\")\n throw new Error(\"GitHub advisory selection must be repository or global.\");\n const url = text(record[\"url\"]);\n if (!url || url !== advisory[\"html_url\"])\n throw new Error(\"GitHub advisory URL must match the original advisory.\");\n const { parsed: parsedUrl, host: linkHost, origin } = sourceUrl(url);\n const host = text(record[\"githubHost\"])?.toLowerCase();\n // Enterprise APIs may return the public advisory database's canonical link.\n const canonicalGlobalLink =\n selection === \"global\" && parsedUrl.host === \"github.com\";\n const expectedPath =\n selection === \"repository\"\n ? `/${repository}/security/advisories/${id}`\n : `/advisories/${id}`;\n if (\n !host ||\n (linkHost !== host && !canonicalGlobalLink) ||\n parsedUrl.pathname.toLowerCase() !== expectedPath.toLowerCase()\n )\n throw new Error(\n \"GitHub advisory URL does not match the selected source and GHSA ID.\",\n );\n const vulnerabilities =\n advisory[\"vulnerabilities\"] === null ? [] : advisory[\"vulnerabilities\"];\n if (!Array.isArray(vulnerabilities))\n throw new Error(\"GitHub advisory vulnerabilities must be an array.\");\n const identifiers = Array.isArray(advisory[\"identifiers\"])\n ? advisory[\"identifiers\"]\n : [];\n const advisoryIds = [\n id,\n text(advisory[\"cve_id\"]),\n ...identifiers.map((identifier) => text(object(identifier)?.[\"value\"])),\n ].filter((value): value is string => value !== null);\n const packages = vulnerabilities.flatMap((value) => {\n const vulnerability = object(value);\n const pkg = object(vulnerability?.[\"package\"]);\n const name = text(pkg?.[\"name\"]);\n // GitHub permits incomplete package metadata in advisory disclosures.\n // Preserve it in source_data without inventing a typed package identity.\n if (!name) return [];\n const fixedVersion =\n text(vulnerability?.[\"first_patched_version\"]) ??\n text(vulnerability?.[\"patched_versions\"]);\n return [\n {\n name,\n ecosystem: text(pkg?.[\"ecosystem\"]),\n vulnerable_version_range: text(\n vulnerability?.[\"vulnerable_version_range\"],\n ),\n fixed_versions: fixedVersion ? [fixedVersion] : [],\n },\n ];\n });\n const cwes = Array.isArray(advisory[\"cwes\"]) ? advisory[\"cwes\"] : [];\n return {\n source_finding_id: `${host}/${selection === \"repository\" ? repository.toLowerCase() : \"global\"}/security-advisory/${id.toUpperCase()}`,\n evidence: validateExternalEvidence(\n {\n title: text(advisory[\"summary\"]) ?? id,\n severity: severity(advisory[\"severity\"]),\n description: text(advisory[\"description\"]),\n url,\n advisory_ids: [...new Set(advisoryIds)],\n packages,\n source_updated_at: sourceTimestamp(advisory[\"updated_at\"]),\n source_data: record,\n details: {\n kind: \"advisory\",\n advisory: { source: selection },\n ...(selection === \"repository\"\n ? {\n repository: {\n url: `${origin}/${repository}`,\n name: repository,\n },\n }\n : {}),\n source_status: text(advisory[\"withdrawn_at\"])\n ? \"withdrawn\"\n : (text(advisory[\"state\"]) ??\n (selection === \"global\" ? \"published\" : null)),\n scanner_origin: \"GitHub Security Advisories\",\n weakness_ids: cwes\n .map((value) => text(object(value)?.[\"cwe_id\"]))\n .filter((value): value is string => value !== null),\n },\n },\n target,\n ),\n };\n}\n\nfunction normalizeRecords(\n records: readonly unknown[],\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const result: ExternalFindings = {\n read: records.length,\n findings: [],\n excluded: [],\n };\n const identities = new Set<string>();\n for (const [index, value] of records.entries()) {\n const record = object(value);\n try {\n if (!record) throw new Error(\"GitHub finding must be an object.\");\n let finding: ExternalFinding;\n if (record[\"source\"] === \"github-code-scanning\")\n finding = codeScanningFinding(record, target);\n else if (record[\"source\"] === \"github-security-advisory\")\n finding = advisoryFinding(record, target);\n else\n throw new Error(\n \"Expected saved output from import github or import github-advisories; raw or incomplete API responses need an explicit mapping.\",\n );\n if (identities.has(finding.source_finding_id))\n throw new CodexSecurityError(\n `Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}. Select each GitHub occurrence once.`,\n );\n identities.add(finding.source_finding_id);\n result.findings.push(finding);\n } catch (error) {\n if (error instanceof CodexSecurityError) throw error;\n result.excluded.push({\n position: index + 1,\n source_finding_id: text(record?.[\"url\"]),\n reason: errorMessage(error),\n });\n }\n }\n return result;\n}\n\n/** Map selected code-scanning instances while retaining complete upstream evidence. */\nexport function normalizeGitHubCodeScanningAlerts(\n alerts: readonly ImportedGitHubCodeScanningAlert[],\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n return normalizeRecords(alerts, target);\n}\n\n/** Map advisory disclosures without asserting an installed vulnerable dependency. */\nexport function normalizeGitHubAdvisories(\n advisories: readonly ImportedGitHubAdvisory[],\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n return normalizeRecords(advisories, target);\n}\n\n/** Read unfiltered JSON/JSONL output saved by the read-only GitHub import commands. */\nexport async function readGitHubFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n try {\n const payload = parseJsonOrJsonl(await readScannerText(path));\n return normalizeRecords(\n Array.isArray(payload) ? payload : [payload],\n target,\n );\n } catch (cause) {\n throw new CodexSecurityError(\n `Could not read GitHub findings as UTF-8 JSON or JSONL: ${errorMessage(cause)}`,\n { cause },\n );\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { Readable } from "node:stream";
2
2
  import { runHostProtocol } from "./host-protocol.js";
3
+ import { type HostedRemediationInput } from "./hosted-remediation.js";
3
4
  /** SDK launcher for prepared hosted checkouts; no local inference fallback. */
4
- export declare function runHostedRemediationProtocol(input: Readable, output: Parameters<typeof runHostProtocol>[1], signal?: AbortSignal): Promise<number>;
5
+ export declare function runHostedRemediationProtocol(input: Readable, output: Parameters<typeof runHostProtocol>[1], signal?: AbortSignal, operation?: HostedRemediationInput["operation"]): Promise<number>;
5
6
  //# sourceMappingURL=hosted-remediation-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-remediation-protocol.d.ts","sourceRoot":"","sources":["../src/hosted-remediation-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AASrD,+EAA+E;AAC/E,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
1
+ {"version":3,"file":"hosted-remediation-protocol.d.ts","sourceRoot":"","sources":["../src/hosted-remediation-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AAGjC,+EAA+E;AAC/E,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,CAAC,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE,sBAAsB,CAAC,WAAW,CAAC,GAC9C,OAAO,CAAC,MAAM,CAAC,CAoCjB"}
@@ -2,7 +2,7 @@ import { runHostProtocol } from "./host-protocol.js";
2
2
  import { HostedRemediationPreparationError, runHostedRemediation, } from "./hosted-remediation.js";
3
3
  import { isRecord } from "./record.js";
4
4
  /** SDK launcher for prepared hosted checkouts; no local inference fallback. */
5
- export async function runHostedRemediationProtocol(input, output, signal) {
5
+ export async function runHostedRemediationProtocol(input, output, signal, operation) {
6
6
  return await runHostProtocol(input, output, {
7
7
  label: "Remediation",
8
8
  requestMethod: "execution.run",
@@ -11,16 +11,22 @@ export async function runHostedRemediationProtocol(input, output, signal) {
11
11
  errorData: (error) => error instanceof HostedRemediationPreparationError
12
12
  ? { reason: error.reason }
13
13
  : undefined,
14
- run: async (params, execute, signal, onEvent) => await runHostedRemediation(params, {
15
- signal,
16
- onEvent,
17
- executor: {
18
- run: async (request, options) => (await execute(request.requestId, request, (event) => {
19
- if (isRecord(event))
20
- options.onEvent?.(event);
21
- })),
22
- },
23
- }),
14
+ run: async (params, execute, signal, onEvent) => {
15
+ if (operation !== undefined &&
16
+ (!isRecord(params) || params["operation"] !== operation)) {
17
+ throw new Error(`Hosted ${operation} requires operation "${operation}".`);
18
+ }
19
+ return await runHostedRemediation(params, {
20
+ signal,
21
+ onEvent,
22
+ executor: {
23
+ run: async (request, options) => (await execute(request.requestId, request, (event) => {
24
+ if (isRecord(event))
25
+ options.onEvent?.(event);
26
+ })),
27
+ },
28
+ });
29
+ },
24
30
  }, signal);
25
31
  }
26
32
  //# sourceMappingURL=hosted-remediation-protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-remediation-protocol.js","sourceRoot":"","sources":["../src/hosted-remediation-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,iCAAiC,EACjC,oBAAoB,GAGrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,KAAe,EACf,MAA6C,EAC7C,MAAoB;IAEpB,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,aAAa;QACpB,aAAa,EAAE,eAAe;QAC9B,cAAc,EAAE,sBAAsB;QACtC,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,iCAAiC;YAChD,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;YAC1B,CAAC,CAAC,SAAS;QACf,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAC9C,MAAM,oBAAoB,CAAC,MAAgC,EAAE;YAC3D,MAAM;YACN,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBACnD,IAAI,QAAQ,CAAC,KAAK,CAAC;wBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;gBAChD,CAAC,CAAC,CAA+B;aACpC;SACF,CAAC;KACL,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n HostedRemediationPreparationError,\n runHostedRemediation,\n type HostedRemediationInput,\n type RemediationExecutionResult,\n} from \"./hosted-remediation.js\";\nimport { isRecord } from \"./record.js\";\n\n/** SDK launcher for prepared hosted checkouts; no local inference fallback. */\nexport async function runHostedRemediationProtocol(\n input: Readable,\n output: Parameters<typeof runHostProtocol>[1],\n signal?: AbortSignal,\n): Promise<number> {\n return await runHostProtocol(\n input,\n output,\n {\n label: \"Remediation\",\n requestMethod: \"execution.run\",\n progressMethod: \"remediation.progress\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedRemediationPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) =>\n await runHostedRemediation(params as HostedRemediationInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n (await execute(request.requestId, request, (event) => {\n if (isRecord(event)) options.onEvent?.(event);\n })) as RemediationExecutionResult,\n },\n }),\n },\n signal,\n );\n}\n"]}
1
+ {"version":3,"file":"hosted-remediation-protocol.js","sourceRoot":"","sources":["../src/hosted-remediation-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,iCAAiC,EACjC,oBAAoB,GAGrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,KAAe,EACf,MAA6C,EAC7C,MAAoB,EACpB,SAA+C;IAE/C,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,aAAa;QACpB,aAAa,EAAE,eAAe;QAC9B,cAAc,EAAE,sBAAsB;QACtC,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,iCAAiC;YAChD,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;YAC1B,CAAC,CAAC,SAAS;QACf,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YAC9C,IACE,SAAS,KAAK,SAAS;gBACvB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,SAAS,CAAC,EACxD,CAAC;gBACD,MAAM,IAAI,KAAK,CACb,UAAU,SAAS,wBAAwB,SAAS,IAAI,CACzD,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,oBAAoB,CAAC,MAAgC,EAAE;gBAClE,MAAM;gBACN,OAAO;gBACP,QAAQ,EAAE;oBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;wBACnD,IAAI,QAAQ,CAAC,KAAK,CAAC;4BAAE,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;oBAChD,CAAC,CAAC,CAA+B;iBACpC;aACF,CAAC,CAAC;QACL,CAAC;KACF,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n HostedRemediationPreparationError,\n runHostedRemediation,\n type HostedRemediationInput,\n type RemediationExecutionResult,\n} from \"./hosted-remediation.js\";\nimport { isRecord } from \"./record.js\";\n\n/** SDK launcher for prepared hosted checkouts; no local inference fallback. */\nexport async function runHostedRemediationProtocol(\n input: Readable,\n output: Parameters<typeof runHostProtocol>[1],\n signal?: AbortSignal,\n operation?: HostedRemediationInput[\"operation\"],\n): Promise<number> {\n return await runHostProtocol(\n input,\n output,\n {\n label: \"Remediation\",\n requestMethod: \"execution.run\",\n progressMethod: \"remediation.progress\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedRemediationPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) => {\n if (\n operation !== undefined &&\n (!isRecord(params) || params[\"operation\"] !== operation)\n ) {\n throw new Error(\n `Hosted ${operation} requires operation \"${operation}\".`,\n );\n }\n return await runHostedRemediation(params as HostedRemediationInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n (await execute(request.requestId, request, (event) => {\n if (isRecord(event)) options.onEvent?.(event);\n })) as RemediationExecutionResult,\n },\n });\n },\n },\n signal,\n );\n}\n"]}
@@ -15,6 +15,10 @@ export declare const HostedRemediationInputSchema: z.ZodObject<{
15
15
  }, z.core.$strict>;
16
16
  instructions: z.ZodOptional<z.ZodString>;
17
17
  validationInstructions: z.ZodOptional<z.ZodString>;
18
+ verificationMode: z.ZodOptional<z.ZodEnum<{
19
+ standard: "standard";
20
+ static: "static";
21
+ }>>;
18
22
  model: z.ZodString;
19
23
  reasoningEffort: z.ZodString;
20
24
  identity: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-remediation.d.ts","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;kBAkBvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAC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EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,qBAAa,iCAAkC,SAAQ,KAAK;IAC1D,QAAQ,CAAC,MAAM,uBAAuB;IACtC,cAGC;CACF;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAqFlC"}
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { errorMessage } from "./errors.js";
4
4
  import { bundledPluginRoot, pluginMetadata } from "./runtime.js";
5
5
  import { normalizeRepository, repositoryRevision } from "./targets.js";
6
- import { parseFindingPatch, parseFindingVerifications, remediationPrompt, } from "./remediation.js";
6
+ import { parseFindingPatch, parseFindingVerifications, remediationPrompt, VerificationModeSchema, } from "./remediation.js";
7
7
  import { ScanExecutionResultSchema, } from "./scan-executor.js";
8
8
  import { VERSION } from "./version.js";
9
9
  export const HostedRemediationInputSchema = z.strictObject({
@@ -17,6 +17,7 @@ export const HostedRemediationInputSchema = z.strictObject({
17
17
  }),
18
18
  instructions: z.string().optional(),
19
19
  validationInstructions: z.string().optional(),
20
+ verificationMode: VerificationModeSchema.optional(),
20
21
  model: z.string().min(1),
21
22
  reasoningEffort: z.string(),
22
23
  identity: z.strictObject({
@@ -53,10 +54,10 @@ export async function runHostedRemediation(value, options) {
53
54
  { occurrenceId: input.finding.id, context: input.finding.context },
54
55
  ],
55
56
  structuredPatch: true,
56
- structuredVerification: true,
57
57
  verificationIds: [input.finding.id],
58
58
  instructions: input.instructions,
59
59
  validationInstructions: input.validationInstructions,
60
+ verificationMode: input.verificationMode,
60
61
  });
61
62
  const target = {
62
63
  version: 1,
@@ -103,7 +104,7 @@ export async function runHostedRemediation(value, options) {
103
104
  const outcome = input.operation === "patch"
104
105
  ? { patch: parseFindingPatch(response, input.finding.id) }
105
106
  : {
106
- verification: parseFindingVerifications(response, [input.finding.id], { requireChecks: true })[0],
107
+ verification: parseHostedVerification(response, input.finding.id),
107
108
  };
108
109
  return { ...base, status: "completed", execution, ...outcome };
109
110
  }
@@ -119,4 +120,22 @@ export async function runHostedRemediation(value, options) {
119
120
  };
120
121
  }
121
122
  }
123
+ function parseHostedVerification(response, findingId) {
124
+ const verification = parseFindingVerifications(response, [findingId])[0];
125
+ if (verification.status !== "fixed")
126
+ return verification;
127
+ // Recognize SDK 0.6.0 checks in the original report without requiring them.
128
+ const checks = z
129
+ .array(z.object({
130
+ name: z.string().trim().min(1),
131
+ status: z.enum(["passed", "failed", "not_run"]),
132
+ evidence: z.string().trim().min(1),
133
+ command: z.string().trim().min(1).optional(),
134
+ }))
135
+ .safeParse(JSON.parse(response).results[0].checks);
136
+ if (checks.success && checks.data.some(({ status }) => status !== "passed")) {
137
+ throw new Error("A fixed verification result contradicts a failed or unrun required check.");
138
+ }
139
+ return verification;
140
+ }
122
141
  //# sourceMappingURL=hosted-remediation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-remediation.js","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,GAGlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,YAAY,CAAC;IACzD,OAAO,EAAE,CAAC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kBAAkB,CAAC,UAAU,CAAC,CAAC,KAAK,KAAK,CAAC,QAAQ;YAC3D,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;QACJ,MAAM,QAAQ,GAAG,SAAS,CAAC,aAAa,IAAI,EAAE,CAAC;QAC/C,MAAM,OAAO,GACX,KAAK,CAAC,SAAS,KAAK,OAAO;YACzB,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YAC1D,CAAC,CAAC;gBACE,YAAY,EAAE,yBAAyB,CACrC,QAAQ,EACR,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAClB,EAAE,aAAa,EAAE,IAAI,EAAE,CACxB,CAAC,CAAC,CAAE;aACN,CAAC;QACR,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,MAAM,CAAC,OAAO,IAAI,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ;YACzE,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;YACjD,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB;gBACrE,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC;aAC7B;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\nimport { errorMessage } from \"./errors.js\";\nimport { bundledPluginRoot, pluginMetadata } from \"./runtime.js\";\nimport { normalizeRepository, repositoryRevision } from \"./targets.js\";\nimport {\n parseFindingPatch,\n parseFindingVerifications,\n remediationPrompt,\n type FindingPatch,\n type FindingVerification,\n} from \"./remediation.js\";\nimport {\n ScanExecutionResultSchema,\n type ScanExecutionResult,\n} from \"./scan-executor.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const HostedRemediationInputSchema = z.strictObject({\n version: z.literal(1),\n operation: z.enum([\"patch\", \"verify\"]),\n repository: z.string().min(1),\n revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),\n finding: z.strictObject({\n id: z.string().min(1),\n context: z.string().trim().min(1),\n }),\n instructions: z.string().optional(),\n validationInstructions: z.string().optional(),\n model: z.string().min(1),\n reasoningEffort: z.string(),\n identity: z.strictObject({\n runId: z.string().min(1),\n attemptId: z.string().min(1),\n buildId: z.string().min(1),\n }),\n});\n\nexport type HostedRemediationInput = z.infer<\n typeof HostedRemediationInputSchema\n>;\n\nexport interface RemediationExecutionRequest {\n version: 1;\n requestId: string;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n prompt: string;\n model: string;\n reasoningEffort: HostedRemediationInput[\"reasoningEffort\"];\n sandbox: \"workspace-write\" | \"read-only\";\n runtime: { pluginRoot: string; pluginVersion: string };\n}\n\nexport type RemediationExecutionResult = ScanExecutionResult;\nexport type RemediationExecutionEvent = Readonly<Record<string, unknown>>;\n\nexport interface RemediationExecutor {\n /** Submit once and settle cancellation with the host's recorded receipt. */\n run(\n request: RemediationExecutionRequest,\n options: {\n signal: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n },\n ): Promise<RemediationExecutionResult>;\n}\n\nexport interface HostedRemediationOptions {\n executor: RemediationExecutor;\n signal?: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n}\n\nexport interface HostedRemediationResult {\n version: 1;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n status: RemediationExecutionResult[\"status\"];\n provenance: { cliVersion: string; pluginVersion: string; buildId: string };\n execution?: RemediationExecutionResult;\n patch?: FindingPatch;\n verification?: FindingVerification;\n error?: { code: string; message: string };\n}\n\nexport class HostedRemediationPreparationError extends Error {\n readonly reason = \"revision_mismatch\";\n constructor() {\n super(\"Checkout does not match the frozen revision.\");\n this.name = \"HostedRemediationPreparationError\";\n }\n}\n\n/**\n * Run one patch or verification through the supplied host executor.\n * The host prepares the candidate checkout, enforces the requested sandbox,\n * and owns patch artifacts, durable attempts, usage, and reconciliation.\n */\nexport async function runHostedRemediation(\n value: HostedRemediationInput,\n options: HostedRemediationOptions,\n): Promise<HostedRemediationResult> {\n const input = HostedRemediationInputSchema.parse(value);\n const signal = options.signal ?? new AbortController().signal;\n signal.throwIfAborted();\n const repository = await normalizeRepository(input.repository, signal);\n if ((await repositoryRevision(repository, signal)) !== input.revision)\n throw new HostedRemediationPreparationError();\n const pluginRoot = await bundledPluginRoot();\n const { version: pluginVersion } = await pluginMetadata(pluginRoot);\n const prompt = await remediationPrompt({\n operation: input.operation,\n pluginRoot,\n contents: [\n { occurrenceId: input.finding.id, context: input.finding.context },\n ],\n structuredPatch: true,\n structuredVerification: true,\n verificationIds: [input.finding.id],\n instructions: input.instructions,\n validationInstructions: input.validationInstructions,\n });\n const target = {\n version: 1 as const,\n operation: input.operation,\n repository,\n revision: input.revision,\n identity: input.identity,\n findingId: input.finding.id,\n };\n const request: RemediationExecutionRequest = {\n ...target,\n requestId: randomUUID(),\n prompt,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n sandbox: input.operation === \"verify\" ? \"read-only\" : \"workspace-write\",\n runtime: { pluginRoot, pluginVersion },\n };\n const base = {\n ...target,\n provenance: {\n cliVersion: VERSION,\n pluginVersion,\n buildId: input.identity.buildId,\n },\n };\n let execution: RemediationExecutionResult | undefined;\n const onEvent = (event: RemediationExecutionEvent) => {\n void Promise.resolve()\n .then(() => options.onEvent?.(event))\n .catch(() => {});\n };\n try {\n signal.throwIfAborted();\n execution = await options.executor.run(request, { signal, onEvent });\n ScanExecutionResultSchema.parse(execution);\n if (execution.requestId !== request.requestId)\n throw new Error(\n \"Execution receipt does not match the remediation request.\",\n );\n if (execution.status !== \"completed\")\n return { ...base, status: execution.status, execution };\n if ((await repositoryRevision(repository)) !== input.revision)\n throw new Error(\n \"Checkout changed from the frozen revision during execution.\",\n );\n const response = execution.finalResponse ?? \"\";\n const outcome =\n input.operation === \"patch\"\n ? { patch: parseFindingPatch(response, input.finding.id) }\n : {\n verification: parseFindingVerifications(\n response,\n [input.finding.id],\n { requireChecks: true },\n )[0]!,\n };\n return { ...base, status: \"completed\", execution, ...outcome };\n } catch (error) {\n return {\n ...base,\n status: signal.aborted && execution === undefined ? \"canceled\" : \"failed\",\n ...(execution === undefined ? {} : { execution }),\n error: {\n code: execution === undefined ? \"EXECUTION_FAILED\" : \"INVALID_RESULT\",\n message: errorMessage(error),\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"hosted-remediation.js","sourceRoot":"","sources":["../src/hosted-remediation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,GAGvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,YAAY,CAAC;IACzD,OAAO,EAAE,CAA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YAAY,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO,YAAY,CAAC;IACzD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,CAAC;SACb,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC/C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;KAC7C,CAAC,CACH;SACA,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\nimport { errorMessage } from \"./errors.js\";\nimport { bundledPluginRoot, pluginMetadata } from \"./runtime.js\";\nimport { normalizeRepository, repositoryRevision } from \"./targets.js\";\nimport {\n parseFindingPatch,\n parseFindingVerifications,\n remediationPrompt,\n VerificationModeSchema,\n type FindingPatch,\n type FindingVerification,\n} from \"./remediation.js\";\nimport {\n ScanExecutionResultSchema,\n type ScanExecutionResult,\n} from \"./scan-executor.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const HostedRemediationInputSchema = z.strictObject({\n version: z.literal(1),\n operation: z.enum([\"patch\", \"verify\"]),\n repository: z.string().min(1),\n revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),\n finding: z.strictObject({\n id: z.string().min(1),\n context: z.string().trim().min(1),\n }),\n instructions: z.string().optional(),\n validationInstructions: z.string().optional(),\n verificationMode: VerificationModeSchema.optional(),\n model: z.string().min(1),\n reasoningEffort: z.string(),\n identity: z.strictObject({\n runId: z.string().min(1),\n attemptId: z.string().min(1),\n buildId: z.string().min(1),\n }),\n});\n\nexport type HostedRemediationInput = z.infer<\n typeof HostedRemediationInputSchema\n>;\n\nexport interface RemediationExecutionRequest {\n version: 1;\n requestId: string;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n prompt: string;\n model: string;\n reasoningEffort: HostedRemediationInput[\"reasoningEffort\"];\n sandbox: \"workspace-write\" | \"read-only\";\n runtime: { pluginRoot: string; pluginVersion: string };\n}\n\nexport type RemediationExecutionResult = ScanExecutionResult;\nexport type RemediationExecutionEvent = Readonly<Record<string, unknown>>;\n\nexport interface RemediationExecutor {\n /** Submit once and settle cancellation with the host's recorded receipt. */\n run(\n request: RemediationExecutionRequest,\n options: {\n signal: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n },\n ): Promise<RemediationExecutionResult>;\n}\n\nexport interface HostedRemediationOptions {\n executor: RemediationExecutor;\n signal?: AbortSignal;\n onEvent?: (event: RemediationExecutionEvent) => void;\n}\n\nexport interface HostedRemediationResult {\n version: 1;\n operation: HostedRemediationInput[\"operation\"];\n repository: string;\n revision: string;\n identity: HostedRemediationInput[\"identity\"];\n findingId: string;\n status: RemediationExecutionResult[\"status\"];\n provenance: { cliVersion: string; pluginVersion: string; buildId: string };\n execution?: RemediationExecutionResult;\n patch?: FindingPatch;\n verification?: FindingVerification;\n error?: { code: string; message: string };\n}\n\nexport class HostedRemediationPreparationError extends Error {\n readonly reason = \"revision_mismatch\";\n constructor() {\n super(\"Checkout does not match the frozen revision.\");\n this.name = \"HostedRemediationPreparationError\";\n }\n}\n\n/**\n * Run one patch or verification through the supplied host executor.\n * The host prepares the candidate checkout, enforces the requested sandbox,\n * and owns patch artifacts, durable attempts, usage, and reconciliation.\n */\nexport async function runHostedRemediation(\n value: HostedRemediationInput,\n options: HostedRemediationOptions,\n): Promise<HostedRemediationResult> {\n const input = HostedRemediationInputSchema.parse(value);\n const signal = options.signal ?? new AbortController().signal;\n signal.throwIfAborted();\n const repository = await normalizeRepository(input.repository, signal);\n if ((await repositoryRevision(repository, signal)) !== input.revision)\n throw new HostedRemediationPreparationError();\n const pluginRoot = await bundledPluginRoot();\n const { version: pluginVersion } = await pluginMetadata(pluginRoot);\n const prompt = await remediationPrompt({\n operation: input.operation,\n pluginRoot,\n contents: [\n { occurrenceId: input.finding.id, context: input.finding.context },\n ],\n structuredPatch: true,\n verificationIds: [input.finding.id],\n instructions: input.instructions,\n validationInstructions: input.validationInstructions,\n verificationMode: input.verificationMode,\n });\n const target = {\n version: 1 as const,\n operation: input.operation,\n repository,\n revision: input.revision,\n identity: input.identity,\n findingId: input.finding.id,\n };\n const request: RemediationExecutionRequest = {\n ...target,\n requestId: randomUUID(),\n prompt,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n sandbox: input.operation === \"verify\" ? \"read-only\" : \"workspace-write\",\n runtime: { pluginRoot, pluginVersion },\n };\n const base = {\n ...target,\n provenance: {\n cliVersion: VERSION,\n pluginVersion,\n buildId: input.identity.buildId,\n },\n };\n let execution: RemediationExecutionResult | undefined;\n const onEvent = (event: RemediationExecutionEvent) => {\n void Promise.resolve()\n .then(() => options.onEvent?.(event))\n .catch(() => {});\n };\n try {\n signal.throwIfAborted();\n execution = await options.executor.run(request, { signal, onEvent });\n ScanExecutionResultSchema.parse(execution);\n if (execution.requestId !== request.requestId)\n throw new Error(\n \"Execution receipt does not match the remediation request.\",\n );\n if (execution.status !== \"completed\")\n return { ...base, status: execution.status, execution };\n if ((await repositoryRevision(repository)) !== input.revision)\n throw new Error(\n \"Checkout changed from the frozen revision during execution.\",\n );\n const response = execution.finalResponse ?? \"\";\n const outcome =\n input.operation === \"patch\"\n ? { patch: parseFindingPatch(response, input.finding.id) }\n : {\n verification: parseHostedVerification(response, input.finding.id),\n };\n return { ...base, status: \"completed\", execution, ...outcome };\n } catch (error) {\n return {\n ...base,\n status: signal.aborted && execution === undefined ? \"canceled\" : \"failed\",\n ...(execution === undefined ? {} : { execution }),\n error: {\n code: execution === undefined ? \"EXECUTION_FAILED\" : \"INVALID_RESULT\",\n message: errorMessage(error),\n },\n };\n }\n}\n\nfunction parseHostedVerification(response: string, findingId: string) {\n const verification = parseFindingVerifications(response, [findingId])[0]!;\n if (verification.status !== \"fixed\") return verification;\n // Recognize SDK 0.6.0 checks in the original report without requiring them.\n const checks = z\n .array(\n z.object({\n name: z.string().trim().min(1),\n status: z.enum([\"passed\", \"failed\", \"not_run\"]),\n evidence: z.string().trim().min(1),\n command: z.string().trim().min(1).optional(),\n }),\n )\n .safeParse(JSON.parse(response).results[0].checks);\n if (checks.success && checks.data.some(({ status }) => status !== \"passed\")) {\n throw new Error(\n \"A fixed verification result contradicts a failed or unrun required check.\",\n );\n }\n return verification;\n}\n"]}
@@ -13,6 +13,7 @@ export declare const HostedScanInputSchema: z.ZodObject<{
13
13
  stateDirectory: z.ZodString;
14
14
  model: z.ZodString;
15
15
  reasoningEffort: z.ZodString;
16
+ ownerSuggestions: z.ZodOptional<z.ZodBoolean>;
16
17
  identity: z.ZodObject<{
17
18
  runId: z.ZodString;
18
19
  attemptId: z.ZodString;
@@ -28,6 +29,20 @@ export declare function normalizeHostedScope(path: string): string;
28
29
  export declare function normalizeHostedPaths(paths?: readonly string[]): string[];
29
30
  export interface HostedScanOptions {
30
31
  executor: ScanExecutor;
32
+ /** @deprecated Automatic owner reports validate scan hints without additional inference. */
33
+ ownerCodex?: {
34
+ startThread(options: {
35
+ model?: string;
36
+ modelReasoningEffort?: string;
37
+ }): {
38
+ run(input: string, options: {
39
+ outputSchema?: unknown;
40
+ signal?: AbortSignal;
41
+ }): Promise<{
42
+ finalResponse: string;
43
+ }>;
44
+ };
45
+ };
31
46
  signal?: AbortSignal;
32
47
  onEvent?: (event: ScanExecutionEvent) => void;
33
48
  }
@@ -66,6 +81,7 @@ export declare function runHostedScan(value: HostedScanInput, options: HostedSca
66
81
  } | undefined;
67
82
  } | undefined;
68
83
  status: "completed";
84
+ ownerSuggestionsError?: string | undefined;
69
85
  artifacts: {
70
86
  path: string;
71
87
  sha256: string;