@openai/codex-security 0.8.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (658) hide show
  1. package/README.md +36 -746
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +7 -1
  4. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  5. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  6. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  7. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  8. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  9. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/package.json +1 -0
  20. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
  21. package/_bundled_plugin/mcp/server.mjs +2 -11
  22. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  23. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  24. package/_bundled_plugin/references/artifact-storage.md +1 -1
  25. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  26. package/_bundled_plugin/references/core-scan.md +5 -42
  27. package/_bundled_plugin/references/default-severity-rubric.md +9 -4
  28. package/_bundled_plugin/references/final-report.md +5 -3
  29. package/_bundled_plugin/references/finding-detail-fields.md +18 -18
  30. package/_bundled_plugin/references/focused-investigator.md +13 -0
  31. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  32. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  33. package/_bundled_plugin/references/scan-contract.md +27 -33
  34. package/_bundled_plugin/references/scan-prologue.md +2 -2
  35. package/_bundled_plugin/references/scan-runtime.md +4 -2
  36. package/_bundled_plugin/references/security-guidance.md +14 -1
  37. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  38. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  39. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  40. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  41. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  42. package/_bundled_plugin/scripts/deep_scan_workbench.py +192 -352
  43. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  44. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  45. package/_bundled_plugin/scripts/finalize_scan_contract.py +182 -230
  46. package/_bundled_plugin/scripts/finding_preview.py +20 -0
  47. package/_bundled_plugin/scripts/launch_codex_security_mcp +55 -16
  48. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  49. package/_bundled_plugin/scripts/posix_scan_local_files.py +37 -1
  50. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  51. package/_bundled_plugin/scripts/report_projection.py +81 -43
  52. package/_bundled_plugin/scripts/review_state.py +8 -2
  53. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  54. package/_bundled_plugin/scripts/snapshot_sqlite.py +9 -2
  55. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  56. package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
  57. package/_bundled_plugin/scripts/windows_scan_local_files.py +582 -20
  58. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  59. package/_bundled_plugin/scripts/workbench/handoff.py +100 -23
  60. package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
  61. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  62. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  63. package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
  64. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  65. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  66. package/_bundled_plugin/scripts/workbench/storage.py +91 -7
  67. package/_bundled_plugin/scripts/workbench_cli.py +54 -14
  68. package/_bundled_plugin/scripts/workbench_constants.py +12 -0
  69. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  70. package/_bundled_plugin/scripts/workbench_db.py +562 -303
  71. package/_bundled_plugin/scripts/workbench_feedback.py +57 -11
  72. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  73. package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
  74. package/_bundled_plugin/scripts/workbench_native_indexes.py +238 -41
  75. package/_bundled_plugin/scripts/workbench_progress.py +169 -4
  76. package/_bundled_plugin/scripts/workbench_publication.py +16 -13
  77. package/_bundled_plugin/scripts/workbench_remediation.py +155 -2
  78. package/_bundled_plugin/scripts/workbench_saved_results.py +176 -81
  79. package/_bundled_plugin/scripts/workbench_scan_history.py +398 -174
  80. package/_bundled_plugin/scripts/workbench_scan_start.py +224 -31
  81. package/_bundled_plugin/scripts/workbench_scan_usage.py +675 -73
  82. package/_bundled_plugin/scripts/workbench_schema.py +258 -63
  83. package/_bundled_plugin/scripts/workbench_setup.py +14 -2
  84. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  85. package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
  86. package/_bundled_plugin/scripts/workbench_target.py +594 -136
  87. package/_bundled_plugin/scripts/workbench_target_state.py +1110 -21
  88. package/_bundled_plugin/scripts/workbench_validation.py +43 -3
  89. package/_bundled_plugin/shared/workbench-history-repairs.json +77 -35
  90. package/_bundled_plugin/shared/workbench-migrations.json +100 -0
  91. package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
  92. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  93. package/_bundled_plugin/skills/fix-finding/SKILL.md +2 -1
  94. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -153
  95. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  96. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  97. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
  98. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +409 -0
  99. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  100. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  101. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  102. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  103. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  104. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  105. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  106. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  107. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  108. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
  109. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
  110. package/bin/codex-security.mjs +2 -2
  111. package/dist/api.d.ts +45 -5
  112. package/dist/api.d.ts.map +1 -1
  113. package/dist/api.js +1192 -427
  114. package/dist/api.js.map +1 -1
  115. package/dist/armorcode-findings.d.ts +9 -0
  116. package/dist/armorcode-findings.d.ts.map +1 -0
  117. package/dist/armorcode-findings.js +145 -0
  118. package/dist/armorcode-findings.js.map +1 -0
  119. package/dist/artifact-export.d.ts +2 -0
  120. package/dist/artifact-export.d.ts.map +1 -1
  121. package/dist/artifact-export.js +29 -13
  122. package/dist/artifact-export.js.map +1 -1
  123. package/dist/auth.d.ts +6 -2
  124. package/dist/auth.d.ts.map +1 -1
  125. package/dist/auth.js +37 -18
  126. package/dist/auth.js.map +1 -1
  127. package/dist/batch-cost.d.ts +18 -0
  128. package/dist/batch-cost.d.ts.map +1 -0
  129. package/dist/batch-cost.js +41 -0
  130. package/dist/batch-cost.js.map +1 -0
  131. package/dist/bedrock-oss-pricing.d.ts +6 -0
  132. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  133. package/dist/bedrock-oss-pricing.js +58 -0
  134. package/dist/bedrock-oss-pricing.js.map +1 -0
  135. package/dist/bedrock-pricing.d.ts +15 -0
  136. package/dist/bedrock-pricing.d.ts.map +1 -0
  137. package/dist/bedrock-pricing.js +117 -0
  138. package/dist/bedrock-pricing.js.map +1 -0
  139. package/dist/blackduck-findings.d.ts +1 -1
  140. package/dist/blackduck-findings.d.ts.map +1 -1
  141. package/dist/blackduck-findings.js +24 -22
  142. package/dist/blackduck-findings.js.map +1 -1
  143. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  144. package/dist/bulk-scan-discovery.js +4 -4
  145. package/dist/bulk-scan-discovery.js.map +1 -1
  146. package/dist/bundled-plugin.d.ts +4 -0
  147. package/dist/bundled-plugin.d.ts.map +1 -0
  148. package/dist/bundled-plugin.js +23 -0
  149. package/dist/bundled-plugin.js.map +1 -0
  150. package/dist/checkmarx-evidence.d.ts +19 -0
  151. package/dist/checkmarx-evidence.d.ts.map +1 -0
  152. package/dist/checkmarx-evidence.js +36 -0
  153. package/dist/checkmarx-evidence.js.map +1 -0
  154. package/dist/checkmarx-findings.d.ts +4 -0
  155. package/dist/checkmarx-findings.d.ts.map +1 -0
  156. package/dist/checkmarx-findings.js +27 -0
  157. package/dist/checkmarx-findings.js.map +1 -0
  158. package/dist/checkmarx-one.d.ts +4 -0
  159. package/dist/checkmarx-one.d.ts.map +1 -0
  160. package/dist/checkmarx-one.js +53 -0
  161. package/dist/checkmarx-one.js.map +1 -0
  162. package/dist/checkmarx-repository.d.ts +12 -0
  163. package/dist/checkmarx-repository.d.ts.map +1 -0
  164. package/dist/checkmarx-repository.js +181 -0
  165. package/dist/checkmarx-repository.js.map +1 -0
  166. package/dist/checkmarx-xml.d.ts +12 -0
  167. package/dist/checkmarx-xml.d.ts.map +1 -0
  168. package/dist/checkmarx-xml.js +196 -0
  169. package/dist/checkmarx-xml.js.map +1 -0
  170. package/dist/classify-scan-severity.d.ts +1 -1
  171. package/dist/classify-scan-severity.d.ts.map +1 -1
  172. package/dist/classify-scan-severity.js +11 -3
  173. package/dist/classify-scan-severity.js.map +1 -1
  174. package/dist/classify-severity-records.d.ts +1 -9
  175. package/dist/classify-severity-records.d.ts.map +1 -1
  176. package/dist/classify-severity-records.js +3 -13
  177. package/dist/classify-severity-records.js.map +1 -1
  178. package/dist/classify-severity.d.ts.map +1 -1
  179. package/dist/classify-severity.js +11 -10
  180. package/dist/classify-severity.js.map +1 -1
  181. package/dist/cli-argument.d.ts +4 -0
  182. package/dist/cli-argument.d.ts.map +1 -0
  183. package/dist/cli-argument.js +17 -0
  184. package/dist/cli-argument.js.map +1 -0
  185. package/dist/cli-help.d.ts +1 -1
  186. package/dist/cli-help.d.ts.map +1 -1
  187. package/dist/cli-help.js +71 -29
  188. package/dist/cli-help.js.map +1 -1
  189. package/dist/cli-hook.d.ts +3 -0
  190. package/dist/cli-hook.d.ts.map +1 -0
  191. package/dist/cli-hook.js +87 -0
  192. package/dist/cli-hook.js.map +1 -0
  193. package/dist/cli-integrations.d.ts +13 -0
  194. package/dist/cli-integrations.d.ts.map +1 -0
  195. package/dist/cli-integrations.js +333 -0
  196. package/dist/cli-integrations.js.map +1 -0
  197. package/dist/cli-mcp.d.ts +15 -0
  198. package/dist/cli-mcp.d.ts.map +1 -0
  199. package/dist/cli-mcp.js +178 -0
  200. package/dist/cli-mcp.js.map +1 -0
  201. package/dist/cli-token-view.d.ts +10 -0
  202. package/dist/cli-token-view.d.ts.map +1 -0
  203. package/dist/cli-token-view.js +41 -0
  204. package/dist/cli-token-view.js.map +1 -0
  205. package/dist/cli.d.ts +16 -8
  206. package/dist/cli.d.ts.map +1 -1
  207. package/dist/cli.js +3382 -2017
  208. package/dist/cli.js.map +1 -1
  209. package/dist/cloud-publish.d.ts.map +1 -1
  210. package/dist/cloud-publish.js +35 -33
  211. package/dist/cloud-publish.js.map +1 -1
  212. package/dist/codex-sdk-environment.d.ts +6 -0
  213. package/dist/codex-sdk-environment.d.ts.map +1 -1
  214. package/dist/codex-sdk-environment.js +19 -0
  215. package/dist/codex-sdk-environment.js.map +1 -1
  216. package/dist/command-words.d.ts +3 -0
  217. package/dist/command-words.d.ts.map +1 -0
  218. package/dist/command-words.js +46 -0
  219. package/dist/command-words.js.map +1 -0
  220. package/dist/component-scan.d.ts +19 -4
  221. package/dist/component-scan.d.ts.map +1 -1
  222. package/dist/component-scan.js +67 -9
  223. package/dist/component-scan.js.map +1 -1
  224. package/dist/config.d.ts +1 -1
  225. package/dist/config.d.ts.map +1 -1
  226. package/dist/config.js +130 -67
  227. package/dist/config.js.map +1 -1
  228. package/dist/continuum-findings.d.ts +1 -1
  229. package/dist/continuum-findings.d.ts.map +1 -1
  230. package/dist/continuum-findings.js +149 -19
  231. package/dist/continuum-findings.js.map +1 -1
  232. package/dist/contract-values.d.ts +2 -0
  233. package/dist/contract-values.d.ts.map +1 -1
  234. package/dist/contract-values.js +12 -9
  235. package/dist/contract-values.js.map +1 -1
  236. package/dist/cost-model.d.ts +13 -1
  237. package/dist/cost-model.d.ts.map +1 -1
  238. package/dist/cost-model.js +66 -112
  239. package/dist/cost-model.js.map +1 -1
  240. package/dist/cost.d.ts +42 -3
  241. package/dist/cost.d.ts.map +1 -1
  242. package/dist/cost.js +484 -149
  243. package/dist/cost.js.map +1 -1
  244. package/dist/custom-publish.d.ts +4 -0
  245. package/dist/custom-publish.d.ts.map +1 -1
  246. package/dist/custom-publish.js +40 -3
  247. package/dist/custom-publish.js.map +1 -1
  248. package/dist/custom-validation-prompt.d.ts +1 -1
  249. package/dist/custom-validation-prompt.d.ts.map +1 -1
  250. package/dist/custom-validation-prompt.js +29 -19
  251. package/dist/custom-validation-prompt.js.map +1 -1
  252. package/dist/deduplication/local.d.ts +4 -2
  253. package/dist/deduplication/local.d.ts.map +1 -1
  254. package/dist/deduplication/local.js +9 -2
  255. package/dist/deduplication/local.js.map +1 -1
  256. package/dist/deduplication/refusal.d.ts.map +1 -1
  257. package/dist/deduplication/refusal.js +26 -5
  258. package/dist/deduplication/refusal.js.map +1 -1
  259. package/dist/deduplication/scan.d.ts +5 -0
  260. package/dist/deduplication/scan.d.ts.map +1 -1
  261. package/dist/deduplication/scan.js +24 -7
  262. package/dist/deduplication/scan.js.map +1 -1
  263. package/dist/deep-config.d.ts +0 -1
  264. package/dist/deep-config.d.ts.map +1 -1
  265. package/dist/deep-config.js +22 -33
  266. package/dist/deep-config.js.map +1 -1
  267. package/dist/deep-scan-defaults.d.ts +2 -0
  268. package/dist/deep-scan-defaults.d.ts.map +1 -1
  269. package/dist/deep-scan-defaults.js +28 -1
  270. package/dist/deep-scan-defaults.js.map +1 -1
  271. package/dist/deep-scan.d.ts +2 -0
  272. package/dist/deep-scan.d.ts.map +1 -1
  273. package/dist/deep-scan.js +44 -19
  274. package/dist/deep-scan.js.map +1 -1
  275. package/dist/default-severity-rubric.d.ts +1 -1
  276. package/dist/default-severity-rubric.d.ts.map +1 -1
  277. package/dist/default-severity-rubric.js +1 -1
  278. package/dist/default-severity-rubric.js.map +1 -1
  279. package/dist/endor-findings.d.ts +3 -1
  280. package/dist/endor-findings.d.ts.map +1 -1
  281. package/dist/endor-findings.js +86 -45
  282. package/dist/endor-findings.js.map +1 -1
  283. package/dist/errors.d.ts +4 -2
  284. package/dist/errors.d.ts.map +1 -1
  285. package/dist/errors.js +15 -4
  286. package/dist/errors.js.map +1 -1
  287. package/dist/executable-path.d.ts +3 -0
  288. package/dist/executable-path.d.ts.map +1 -1
  289. package/dist/executable-path.js +26 -0
  290. package/dist/executable-path.js.map +1 -1
  291. package/dist/external-findings-import.d.ts +5 -3
  292. package/dist/external-findings-import.d.ts.map +1 -1
  293. package/dist/external-findings-import.js +19 -7
  294. package/dist/external-findings-import.js.map +1 -1
  295. package/dist/external-findings-local.d.ts +69 -5
  296. package/dist/external-findings-local.d.ts.map +1 -1
  297. package/dist/external-findings-local.js +537 -108
  298. package/dist/external-findings-local.js.map +1 -1
  299. package/dist/external-findings-publish.d.ts +13 -6
  300. package/dist/external-findings-publish.d.ts.map +1 -1
  301. package/dist/external-findings-publish.js +895 -1142
  302. package/dist/external-findings-publish.js.map +1 -1
  303. package/dist/external-findings-read.d.ts +21 -2
  304. package/dist/external-findings-read.d.ts.map +1 -1
  305. package/dist/external-findings-read.js +130 -68
  306. package/dist/external-findings-read.js.map +1 -1
  307. package/dist/external-findings.d.ts +15 -3
  308. package/dist/external-findings.d.ts.map +1 -1
  309. package/dist/external-findings.js +54 -2
  310. package/dist/external-findings.js.map +1 -1
  311. package/dist/external-import-contract.d.ts +8 -12
  312. package/dist/external-import-contract.d.ts.map +1 -1
  313. package/dist/external-import-contract.js +51 -184
  314. package/dist/external-import-contract.js.map +1 -1
  315. package/dist/external-import-models.d.ts +1 -1
  316. package/dist/external-import-models.d.ts.map +1 -1
  317. package/dist/external-import-models.js.map +1 -1
  318. package/dist/feedback.d.ts.map +1 -1
  319. package/dist/feedback.js +5 -4
  320. package/dist/feedback.js.map +1 -1
  321. package/dist/finding-prompt.d.ts +5 -0
  322. package/dist/finding-prompt.d.ts.map +1 -0
  323. package/dist/finding-prompt.js +32 -0
  324. package/dist/finding-prompt.js.map +1 -0
  325. package/dist/findings-client.d.ts +1 -0
  326. package/dist/findings-client.d.ts.map +1 -1
  327. package/dist/findings-client.js +27 -3
  328. package/dist/findings-client.js.map +1 -1
  329. package/dist/github-advisories.d.ts.map +1 -1
  330. package/dist/github-advisories.js +0 -2
  331. package/dist/github-advisories.js.map +1 -1
  332. package/dist/github-dependabot-findings.d.ts.map +1 -1
  333. package/dist/github-dependabot-findings.js +18 -8
  334. package/dist/github-dependabot-findings.js.map +1 -1
  335. package/dist/github-findings.d.ts +4 -1
  336. package/dist/github-findings.d.ts.map +1 -1
  337. package/dist/github-findings.js +73 -316
  338. package/dist/github-findings.js.map +1 -1
  339. package/dist/hosted-git-remotes.d.ts +5 -0
  340. package/dist/hosted-git-remotes.d.ts.map +1 -0
  341. package/dist/hosted-git-remotes.js +285 -0
  342. package/dist/hosted-git-remotes.js.map +1 -0
  343. package/dist/hosted-git-repository.d.ts +28 -0
  344. package/dist/hosted-git-repository.d.ts.map +1 -0
  345. package/dist/hosted-git-repository.js +222 -0
  346. package/dist/hosted-git-repository.js.map +1 -0
  347. package/dist/hosted-remediation.d.ts +1 -0
  348. package/dist/hosted-remediation.d.ts.map +1 -1
  349. package/dist/hosted-remediation.js +23 -3
  350. package/dist/hosted-remediation.js.map +1 -1
  351. package/dist/hosted-scan-protocol.js +2 -2
  352. package/dist/hosted-scan-protocol.js.map +1 -1
  353. package/dist/hosted-scan.d.ts.map +1 -1
  354. package/dist/hosted-scan.js +16 -11
  355. package/dist/hosted-scan.js.map +1 -1
  356. package/dist/hosted-scanner-http.d.ts +21 -0
  357. package/dist/hosted-scanner-http.d.ts.map +1 -0
  358. package/dist/hosted-scanner-http.js +204 -0
  359. package/dist/hosted-scanner-http.js.map +1 -0
  360. package/dist/import-scan.d.ts.map +1 -1
  361. package/dist/import-scan.js +3 -0
  362. package/dist/import-scan.js.map +1 -1
  363. package/dist/index.d.ts +21 -9
  364. package/dist/index.d.ts.map +1 -1
  365. package/dist/index.js +12 -3
  366. package/dist/index.js.map +1 -1
  367. package/dist/inspector-findings.d.ts.map +1 -1
  368. package/dist/inspector-findings.js +52 -86
  369. package/dist/inspector-findings.js.map +1 -1
  370. package/dist/knowledge-base.d.ts +1 -1
  371. package/dist/knowledge-base.d.ts.map +1 -1
  372. package/dist/knowledge-base.js +102 -32
  373. package/dist/knowledge-base.js.map +1 -1
  374. package/dist/linear.d.ts +11 -0
  375. package/dist/linear.d.ts.map +1 -1
  376. package/dist/linear.js.map +1 -1
  377. package/dist/local-git-metadata.d.ts +5 -2
  378. package/dist/local-git-metadata.d.ts.map +1 -1
  379. package/dist/local-git-metadata.js +8 -5
  380. package/dist/local-git-metadata.js.map +1 -1
  381. package/dist/multiscan.d.ts +10 -4
  382. package/dist/multiscan.d.ts.map +1 -1
  383. package/dist/multiscan.js +217 -102
  384. package/dist/multiscan.js.map +1 -1
  385. package/dist/native-json-findings.d.ts +2 -1
  386. package/dist/native-json-findings.d.ts.map +1 -1
  387. package/dist/native-json-findings.js +12 -2
  388. package/dist/native-json-findings.js.map +1 -1
  389. package/dist/opengrep-findings.d.ts +5 -2
  390. package/dist/opengrep-findings.d.ts.map +1 -1
  391. package/dist/opengrep-findings.js +54 -33
  392. package/dist/opengrep-findings.js.map +1 -1
  393. package/dist/operation-telemetry.d.ts +104 -0
  394. package/dist/operation-telemetry.d.ts.map +1 -0
  395. package/dist/operation-telemetry.js +293 -0
  396. package/dist/operation-telemetry.js.map +1 -0
  397. package/dist/plugin-python-probe.d.ts +4 -0
  398. package/dist/plugin-python-probe.d.ts.map +1 -0
  399. package/dist/plugin-python-probe.js +10 -0
  400. package/dist/plugin-python-probe.js.map +1 -0
  401. package/dist/private-finding-import.d.ts +99 -9
  402. package/dist/private-finding-import.d.ts.map +1 -1
  403. package/dist/private-finding-import.js +116 -152
  404. package/dist/private-finding-import.js.map +1 -1
  405. package/dist/project-config.d.ts.map +1 -1
  406. package/dist/project-config.js +53 -13
  407. package/dist/project-config.js.map +1 -1
  408. package/dist/prompt-files.d.ts +7 -2
  409. package/dist/prompt-files.d.ts.map +1 -1
  410. package/dist/prompt-files.js +42 -20
  411. package/dist/prompt-files.js.map +1 -1
  412. package/dist/provider-profile.d.ts +1 -1
  413. package/dist/provider-profile.d.ts.map +1 -1
  414. package/dist/provider-profile.js +12 -10
  415. package/dist/provider-profile.js.map +1 -1
  416. package/dist/publication-telemetry.d.ts +45 -0
  417. package/dist/publication-telemetry.d.ts.map +1 -0
  418. package/dist/publication-telemetry.js +50 -0
  419. package/dist/publication-telemetry.js.map +1 -0
  420. package/dist/publication.d.ts +1 -1
  421. package/dist/publication.d.ts.map +1 -1
  422. package/dist/publication.js.map +1 -1
  423. package/dist/publish.d.ts +4 -0
  424. package/dist/publish.d.ts.map +1 -1
  425. package/dist/publish.js +42 -2
  426. package/dist/publish.js.map +1 -1
  427. package/dist/record.d.ts +1 -5
  428. package/dist/record.d.ts.map +1 -1
  429. package/dist/record.js +3 -51
  430. package/dist/record.js.map +1 -1
  431. package/dist/remediation.d.ts +1 -4
  432. package/dist/remediation.d.ts.map +1 -1
  433. package/dist/remediation.js +6 -8
  434. package/dist/remediation.js.map +1 -1
  435. package/dist/request-metadata.d.ts +3 -0
  436. package/dist/request-metadata.d.ts.map +1 -1
  437. package/dist/request-metadata.js +9 -0
  438. package/dist/request-metadata.js.map +1 -1
  439. package/dist/result.d.ts +4 -0
  440. package/dist/result.d.ts.map +1 -1
  441. package/dist/result.js +1 -1
  442. package/dist/result.js.map +1 -1
  443. package/dist/retry-windows-rename.d.ts +8 -0
  444. package/dist/retry-windows-rename.d.ts.map +1 -0
  445. package/dist/retry-windows-rename.js +24 -0
  446. package/dist/retry-windows-rename.js.map +1 -0
  447. package/dist/runtime.d.ts +54 -6
  448. package/dist/runtime.d.ts.map +1 -1
  449. package/dist/runtime.js +1084 -256
  450. package/dist/runtime.js.map +1 -1
  451. package/dist/saved-scan-bootstrap.d.ts +7 -1
  452. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  453. package/dist/saved-scan-bootstrap.js +269 -114
  454. package/dist/saved-scan-bootstrap.js.map +1 -1
  455. package/dist/scan-activity.d.ts.map +1 -1
  456. package/dist/scan-activity.js +141 -56
  457. package/dist/scan-activity.js.map +1 -1
  458. package/dist/scan-archive-path.d.ts +2 -0
  459. package/dist/scan-archive-path.d.ts.map +1 -0
  460. package/dist/scan-archive-path.js +5 -0
  461. package/dist/scan-archive-path.js.map +1 -0
  462. package/dist/scan-comparison.d.ts +10 -5
  463. package/dist/scan-comparison.d.ts.map +1 -1
  464. package/dist/scan-comparison.js +66 -17
  465. package/dist/scan-comparison.js.map +1 -1
  466. package/dist/scan-dashboard.d.ts +7 -6
  467. package/dist/scan-dashboard.d.ts.map +1 -1
  468. package/dist/scan-dashboard.js +92 -43
  469. package/dist/scan-dashboard.js.map +1 -1
  470. package/dist/scan-executor.d.ts +10 -1
  471. package/dist/scan-executor.d.ts.map +1 -1
  472. package/dist/scan-executor.js +24 -2
  473. package/dist/scan-executor.js.map +1 -1
  474. package/dist/scan-history-renderer.d.ts +1 -0
  475. package/dist/scan-history-renderer.d.ts.map +1 -1
  476. package/dist/scan-history-renderer.js +34 -28
  477. package/dist/scan-history-renderer.js.map +1 -1
  478. package/dist/scan-logs.d.ts +12 -0
  479. package/dist/scan-logs.d.ts.map +1 -1
  480. package/dist/scan-logs.js +131 -78
  481. package/dist/scan-logs.js.map +1 -1
  482. package/dist/scan-measurement.d.ts +26 -0
  483. package/dist/scan-measurement.d.ts.map +1 -0
  484. package/dist/scan-measurement.js +77 -0
  485. package/dist/scan-measurement.js.map +1 -0
  486. package/dist/scan-progress.d.ts +1 -0
  487. package/dist/scan-progress.d.ts.map +1 -1
  488. package/dist/scan-progress.js +3 -0
  489. package/dist/scan-progress.js.map +1 -1
  490. package/dist/scan-sessions.d.ts.map +1 -1
  491. package/dist/scan-sessions.js +4 -1
  492. package/dist/scan-sessions.js.map +1 -1
  493. package/dist/scan-settings.d.ts +1 -1
  494. package/dist/scan-settings.d.ts.map +1 -1
  495. package/dist/scan-settings.js +1 -24
  496. package/dist/scan-settings.js.map +1 -1
  497. package/dist/scanner-import.d.ts +25 -13
  498. package/dist/scanner-import.d.ts.map +1 -1
  499. package/dist/scanner-import.js +216 -97
  500. package/dist/scanner-import.js.map +1 -1
  501. package/dist/scanner-repository-url.d.ts +4 -1
  502. package/dist/scanner-repository-url.d.ts.map +1 -1
  503. package/dist/scanner-repository-url.js +10 -6
  504. package/dist/scanner-repository-url.js.map +1 -1
  505. package/dist/security-policy.d.ts +1 -1
  506. package/dist/security-policy.d.ts.map +1 -1
  507. package/dist/security-policy.js +26 -6
  508. package/dist/security-policy.js.map +1 -1
  509. package/dist/semgrep-findings.d.ts +6 -3
  510. package/dist/semgrep-findings.d.ts.map +1 -1
  511. package/dist/semgrep-findings.js +72 -42
  512. package/dist/semgrep-findings.js.map +1 -1
  513. package/dist/semgrep-guardian-findings.d.ts +38 -0
  514. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  515. package/dist/semgrep-guardian-findings.js +165 -0
  516. package/dist/semgrep-guardian-findings.js.map +1 -0
  517. package/dist/semgrep-platform-collector.d.ts +26 -0
  518. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  519. package/dist/semgrep-platform-collector.js +108 -0
  520. package/dist/semgrep-platform-collector.js.map +1 -0
  521. package/dist/semgrep-platform-findings.d.ts +157 -6
  522. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  523. package/dist/semgrep-platform-findings.js +766 -103
  524. package/dist/semgrep-platform-findings.js.map +1 -1
  525. package/dist/server/api.d.ts +1 -1
  526. package/dist/server/api.d.ts.map +1 -1
  527. package/dist/server/api.js.map +1 -1
  528. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  529. package/dist/server/embedding-tokenizer.d.ts +2 -0
  530. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  531. package/dist/server/embedding-tokenizer.js +322 -0
  532. package/dist/server/embedding-tokenizer.js.map +6 -0
  533. package/dist/server/embeddings.d.ts +16 -2
  534. package/dist/server/embeddings.d.ts.map +1 -1
  535. package/dist/server/embeddings.js +35 -5
  536. package/dist/server/embeddings.js.map +1 -1
  537. package/dist/session-lines.d.ts +5 -0
  538. package/dist/session-lines.d.ts.map +1 -0
  539. package/dist/session-lines.js +60 -0
  540. package/dist/session-lines.js.map +1 -0
  541. package/dist/severity-review.d.ts +3 -1
  542. package/dist/severity-review.d.ts.map +1 -1
  543. package/dist/severity-review.js +3 -2
  544. package/dist/severity-review.js.map +1 -1
  545. package/dist/skill-authentication.d.ts +1 -0
  546. package/dist/skill-authentication.d.ts.map +1 -1
  547. package/dist/skill-authentication.js +1 -0
  548. package/dist/skill-authentication.js.map +1 -1
  549. package/dist/snyk-findings.d.ts +9 -2
  550. package/dist/snyk-findings.d.ts.map +1 -1
  551. package/dist/snyk-findings.js +90 -70
  552. package/dist/snyk-findings.js.map +1 -1
  553. package/dist/snyk-rest-findings.d.ts +59 -0
  554. package/dist/snyk-rest-findings.d.ts.map +1 -0
  555. package/dist/snyk-rest-findings.js +879 -0
  556. package/dist/snyk-rest-findings.js.map +1 -0
  557. package/dist/snyk-token-origin.d.ts +4 -0
  558. package/dist/snyk-token-origin.d.ts.map +1 -0
  559. package/dist/snyk-token-origin.js +82 -0
  560. package/dist/snyk-token-origin.js.map +1 -0
  561. package/dist/sonar-collector.d.ts.map +1 -1
  562. package/dist/sonar-collector.js +0 -3
  563. package/dist/sonar-collector.js.map +1 -1
  564. package/dist/sonar-findings.d.ts +1 -1
  565. package/dist/sonar-findings.d.ts.map +1 -1
  566. package/dist/sonar-findings.js +2 -4
  567. package/dist/sonar-findings.js.map +1 -1
  568. package/dist/sonar-import.d.ts +3 -0
  569. package/dist/sonar-import.d.ts.map +1 -1
  570. package/dist/sonar-import.js +30 -34
  571. package/dist/sonar-import.js.map +1 -1
  572. package/dist/stored-finding-projection.d.ts +6 -0
  573. package/dist/stored-finding-projection.d.ts.map +1 -0
  574. package/dist/stored-finding-projection.js +104 -0
  575. package/dist/stored-finding-projection.js.map +1 -0
  576. package/dist/stored-findings-publication.d.ts +23 -0
  577. package/dist/stored-findings-publication.d.ts.map +1 -0
  578. package/dist/stored-findings-publication.js +169 -0
  579. package/dist/stored-findings-publication.js.map +1 -0
  580. package/dist/target-drift.d.ts +9 -0
  581. package/dist/target-drift.d.ts.map +1 -0
  582. package/dist/target-drift.js +27 -0
  583. package/dist/target-drift.js.map +1 -0
  584. package/dist/targets.d.ts +8 -1
  585. package/dist/targets.d.ts.map +1 -1
  586. package/dist/targets.js +131 -42
  587. package/dist/targets.js.map +1 -1
  588. package/dist/tenable-findings.d.ts +6 -0
  589. package/dist/tenable-findings.d.ts.map +1 -0
  590. package/dist/tenable-findings.js +122 -0
  591. package/dist/tenable-findings.js.map +1 -0
  592. package/dist/terminal-stream.d.ts +13 -0
  593. package/dist/terminal-stream.d.ts.map +1 -0
  594. package/dist/terminal-stream.js +35 -0
  595. package/dist/terminal-stream.js.map +1 -0
  596. package/dist/trivy-findings.d.ts +19 -0
  597. package/dist/trivy-findings.d.ts.map +1 -0
  598. package/dist/trivy-findings.js +424 -0
  599. package/dist/trivy-findings.js.map +1 -0
  600. package/dist/trivy-import.d.ts +19 -0
  601. package/dist/trivy-import.d.ts.map +1 -0
  602. package/dist/trivy-import.js +151 -0
  603. package/dist/trivy-import.js.map +1 -0
  604. package/dist/trusted-executable.d.ts +6 -0
  605. package/dist/trusted-executable.d.ts.map +1 -1
  606. package/dist/trusted-executable.js +140 -37
  607. package/dist/trusted-executable.js.map +1 -1
  608. package/dist/validation-records.js +1 -1
  609. package/dist/validation-records.js.map +1 -1
  610. package/dist/veracode-findings.d.ts +1 -1
  611. package/dist/veracode-findings.d.ts.map +1 -1
  612. package/dist/veracode-findings.js +19 -6
  613. package/dist/veracode-findings.js.map +1 -1
  614. package/dist/version.d.ts +3 -1
  615. package/dist/version.d.ts.map +1 -1
  616. package/dist/version.js +184 -32
  617. package/dist/version.js.map +1 -1
  618. package/dist/vertex-pricing.d.ts +8 -0
  619. package/dist/vertex-pricing.d.ts.map +1 -0
  620. package/dist/vertex-pricing.js +20 -0
  621. package/dist/vertex-pricing.js.map +1 -0
  622. package/dist/windows-path.d.ts +1 -0
  623. package/dist/windows-path.d.ts.map +1 -1
  624. package/dist/windows-path.js +26 -1
  625. package/dist/windows-path.js.map +1 -1
  626. package/dist/wiz-findings.d.ts +6 -2
  627. package/dist/wiz-findings.d.ts.map +1 -1
  628. package/dist/wiz-findings.js +65 -89
  629. package/dist/wiz-findings.js.map +1 -1
  630. package/docs/classify-severity-records.md +27 -12
  631. package/docs/cli.md +853 -639
  632. package/docs/dedupe-records.md +44 -24
  633. package/docs/findings-service.md +84 -44
  634. package/docs/hosted-remediation.md +27 -11
  635. package/docs/hosted-scans.md +50 -42
  636. package/docs/sdk.md +903 -0
  637. package/docs/telemetry.md +236 -0
  638. package/docs/validate-records.md +78 -44
  639. package/package.json +23 -16
  640. package/schemas/external-findings.schema.json +4 -1
  641. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  642. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  643. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  644. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  645. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  646. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  647. package/dist/external-imports-feature.d.ts +0 -6
  648. package/dist/external-imports-feature.d.ts.map +0 -1
  649. package/dist/external-imports-feature.js +0 -51
  650. package/dist/external-imports-feature.js.map +0 -1
  651. package/dist/finding-normalization.d.ts +0 -5
  652. package/dist/finding-normalization.d.ts.map +0 -1
  653. package/dist/finding-normalization.js +0 -155
  654. package/dist/finding-normalization.js.map +0 -1
  655. package/dist/reader-selection.d.ts +0 -13
  656. package/dist/reader-selection.d.ts.map +0 -1
  657. package/dist/reader-selection.js +0 -81
  658. package/dist/reader-selection.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ import { isIPv4 } from "node:net";
2
+ import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
3
+ import { isGitHubCloudHost } from "./git-remote.js";
4
+ // Git treats a colon followed by "//" as the start of a URL transport.
5
+ const scpRemote = /^(?:([^@/:\s?#]+)@)?(\[[^\]]+\]|[^@/:\s?#]+):(?!\/\/)(.+)$/u;
6
+ const sshRemote = /^(?:ssh|git\+ssh|ssh\+git):\/\/([^/]+?)(?:\/|%2[fF])/u;
7
+ /** A native file URL or an unambiguous local path. */
8
+ export function isLocalGitRemote(remote) {
9
+ if (remote.includes("://"))
10
+ return remote.startsWith("file://");
11
+ const colon = remote.indexOf(":");
12
+ return colon < 0 || remote.slice(0, colon).includes("/");
13
+ }
14
+ export function isWindowsGitDrive(remote) {
15
+ // Git for Windows accepts one character or up to four consecutive non-ASCII bytes before a drive colon.
16
+ return (process.platform === "win32" &&
17
+ !remote.includes("://") &&
18
+ /^(?:.|[\u0080-\u07ff]{2}):(?!:)/su.test(remote));
19
+ }
20
+ function parseScpRemote(remote) {
21
+ return !isLocalGitRemote(remote) &&
22
+ !remote.includes("://") &&
23
+ !/^[a-z\d][a-z\d+.-]*::/iu.test(remote)
24
+ ? scpRemote.exec(remote)
25
+ : null;
26
+ }
27
+ function sshAuthority(host) {
28
+ if (/[\/\\?#@\s\x00-\x1f\x7f]/u.test(host))
29
+ return null;
30
+ // Git passes a leading plus on decimal ports through to OpenSSH.
31
+ const parse = (authority) => URL.parse("ssh://" + authority.replace(/:\+(\d+)$/u, ":$1"));
32
+ const parsed = parse(host);
33
+ if (parsed)
34
+ return parsed;
35
+ // Git accepts brackets around DNS names, with an SSH port inside or after the brackets.
36
+ const bracketed = /^\[([^\]]+)\](?::(\+?\d*))?$/u.exec(host);
37
+ // An empty port outside the brackets is ignored, but an inner trailing colon is a hostname byte.
38
+ if (!bracketed || bracketed[1].endsWith(":"))
39
+ return null;
40
+ const [, name, port] = bracketed;
41
+ return parse(name + (port ? `:${port}` : ""));
42
+ }
43
+ /** Git decodes URI escapes once except for NUL, and sends SCP bytes literally. */
44
+ export function gitTransportBytes(raw, scpStyle) {
45
+ const bytes = Buffer.from(raw).toString("latin1");
46
+ return scpStyle
47
+ ? bytes
48
+ : bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
49
+ }
50
+ /** Decode only URI escapes whose ASCII bytes cannot introduce a delimiter. */
51
+ export function decodeUnreserved(value) {
52
+ return value.replace(/%([0-9a-f]{2})/giu, (escape, hex) => {
53
+ const byte = String.fromCharCode(parseInt(hex, 16));
54
+ return /^[a-z0-9._~-]$/iu.test(byte) ? byte : escape.toUpperCase();
55
+ });
56
+ }
57
+ /** Represent upload-pack path bytes relative to an HTTP repository origin. */
58
+ export function gitPathToHttpPath(bytes) {
59
+ return bytes
60
+ .replace(/^\//u, "")
61
+ .replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
62
+ }
63
+ /** Ignore the optional DNS root dot for provider classification only. */
64
+ export function gitServiceHostname(hostname) {
65
+ return hostname.replace(/\.$/u, "");
66
+ }
67
+ export function isPublicGitHost(host) {
68
+ return (isGitHubCloudHost(host) || host === "gitlab.com" || host === "bitbucket.org");
69
+ }
70
+ /** Public SSH-over-443 hosts share the HTTPS hostname after the first DNS label. */
71
+ function publicGitSsh443Host(hostname) {
72
+ switch (gitServiceHostname(hostname)) {
73
+ case "ssh.github.com":
74
+ case "altssh.gitlab.com":
75
+ case "altssh.bitbucket.org":
76
+ return hostname.slice(hostname.indexOf(".") + 1);
77
+ }
78
+ }
79
+ function matchesHttpsHost(url, hostname) {
80
+ const source = url && URL.parse(url);
81
+ return (!!source &&
82
+ source.protocol === "https:" &&
83
+ source.hostname.toLowerCase() === hostname);
84
+ }
85
+ /** Standard public SSH aliases, plus a hosted SCM established by the caller. */
86
+ export function normalizeHostedGitRepositoryUrl(remote, source, trustedScm) {
87
+ // A projected single-project report may retain only its SSH spelling.
88
+ return normalizeGitSshAlias(remote, (host) => (trustedScm || isPublicGitHost(gitServiceHostname(host))) &&
89
+ matchesHttpsHost(source ?? `https://${host}`, host));
90
+ }
91
+ function normalizeGitSshAlias(repository, isAliasHost) {
92
+ const isGitSshUser = (username, hostname) => (username === "git" && hostname === "github.com") ||
93
+ (isAliasHost(hostname) &&
94
+ (username === "git" ||
95
+ username ===
96
+ /^([^.]+)\.ghe\.com$/u.exec(gitServiceHostname(hostname))?.[1]));
97
+ const hostedAlias = (url, user, path, scpStyle) => {
98
+ const hostname = url.hostname.toLowerCase();
99
+ const standard = isGitSshUser(user, hostname) && (url.port === "" || url.port === "22");
100
+ const alternate = user === "git" && url.port === "443" && publicGitSsh443Host(hostname);
101
+ if (!standard && !alternate)
102
+ return repository;
103
+ const bytes = gitTransportBytes(path, scpStyle);
104
+ if (/[?#\\]/u.test(bytes) || /(?:^|\/)\.{1,2}(?:\/|$)/u.test(bytes))
105
+ return repository;
106
+ return `https://${alternate || hostname}/${gitPathToHttpPath(bytes)}`;
107
+ };
108
+ const scp = parseScpRemote(repository);
109
+ if (scp) {
110
+ if (!scp[1])
111
+ return repository;
112
+ const authority = sshAuthority(scp[2]);
113
+ return authority
114
+ ? hostedAlias(authority, scp[1], scp[3], true)
115
+ : repository;
116
+ }
117
+ // Git separates the decoded authority from the path at the first slash.
118
+ const ssh = sshRemote.exec(repository);
119
+ if (ssh && !/[\t\r\n]/u.test(repository)) {
120
+ const authority = gitTransportBytes(ssh[1], false);
121
+ const login = /^([^@:]+)@([^@]+)$/u.exec(authority);
122
+ if (!login || /[/\\%?#\s]/u.test(authority))
123
+ return repository;
124
+ const url = sshAuthority(login[2]);
125
+ if (url)
126
+ return hostedAlias(url, login[1], "/" + repository.slice(ssh[0].length), false);
127
+ }
128
+ return repository;
129
+ }
130
+ function hostedHttpAuthority(authority) {
131
+ if (/[%@\\\s]/u.test(authority))
132
+ return authority;
133
+ const hostname = URL.parse(`https://${authority}/`)?.hostname;
134
+ // Hostname serialization handles IP literals and IDNA. The connector distinguishes explicit ports.
135
+ const port = /:\d*$/u.exec(authority)?.[0] ?? "";
136
+ return hostname ? hostname + port : authority;
137
+ }
138
+ function hostedHttpPath(path) {
139
+ const segments = [];
140
+ for (const segment of path.split("/")) {
141
+ // Git's HTTP transport resolves literal dot segments before sending the path.
142
+ if (segment === "..") {
143
+ segments.pop();
144
+ }
145
+ else if (segment !== ".") {
146
+ const spelling = segment.replace(/\P{ASCII}+/gu, (text) => encodeURIComponent(text.toWellFormed()));
147
+ const decoded = decodeUnreserved(spelling);
148
+ segments.push(decoded === "." || decoded === ".." ? segment.toUpperCase() : decoded);
149
+ }
150
+ }
151
+ if (/(?:^|\/)\.{1,2}$/u.test(path))
152
+ segments.push("");
153
+ return segments.join("/");
154
+ }
155
+ /** Compare the HTTP request path a browser and Git would send for the same link. */
156
+ export function ambiguousHostedHttpPath(value) {
157
+ const path = /^https?:\/\/[^/?#]+\/([^?#]*)/iu.exec(value)?.[1];
158
+ if (path === undefined)
159
+ return false;
160
+ const web = URL.parse(value)?.pathname.slice(1);
161
+ return (web !== undefined &&
162
+ path !== web &&
163
+ hostedHttpPath(path) !== hostedHttpPath(web));
164
+ }
165
+ /** Compare hosted HTTP repository spellings without changing the retained evidence. */
166
+ export function hostedRepositoryUrlKey(value, github = false, knownGitSuffix = false, target = "local") {
167
+ const url = value.replace(/^(https?:\/\/)([^/?#]+)\/([^?#]*)/iu, (_, scheme, authority, path) => scheme +
168
+ (target === "cloud" && ambiguousGitIpHost(value)
169
+ ? authority.toLowerCase()
170
+ : hostedHttpAuthority(authority)) +
171
+ "/" +
172
+ hostedHttpPath(path));
173
+ if (github)
174
+ return cloudRepositoryUrlKey(url);
175
+ const host = URL.parse(url)?.hostname ?? "";
176
+ const service = /^https?:\/\//iu.test(url) ? gitServiceHostname(host) : host;
177
+ if (service !== host && isGitHubCloudHost(service))
178
+ return cloudRepositoryUrlKey(url);
179
+ // An arbitrary Git server can serve different repositories at /repo and /repo.git.
180
+ const key = repositoryUrlKey(url);
181
+ return !knownGitSuffix && !isPublicGitHost(service) && /\.git\/?$/u.test(url)
182
+ ? key + ".git"
183
+ : key;
184
+ }
185
+ /** The Git HTTP Host and TLS server name can differ from the web URL's parsed IP literal. */
186
+ export function ambiguousGitIpHost(url) {
187
+ const host = URL.parse(url)?.hostname;
188
+ if (!host || (!isIPv4(host) && !host.startsWith("[")))
189
+ return false;
190
+ const authority = /^https?:\/\/([^/?#]*)/iu.exec(url)?.[1] ?? "";
191
+ const rawHost = authority
192
+ .slice(authority.lastIndexOf("@") + 1)
193
+ .replace(/:\d*$/u, "");
194
+ return rawHost.toLowerCase() !== host;
195
+ }
196
+ /** Match a Git checkout to an independently selected hosted repository. */
197
+ export function hostedRepositoryMatches(source, remote) {
198
+ if (!/^https?:\/\//iu.test(source.url))
199
+ return remote === source.url;
200
+ const github = source.platform === "github";
201
+ const url = normalizeHostedGitRepositoryUrl(remote, source.url, github || source.platform === "gitlab");
202
+ const userinfo = /^https?:\/\/([^/?#]*)@/iu.exec(url)?.[1] ?? "";
203
+ // Git passes raw URL paths to its HTTP transport. Do not turn backslashes,
204
+ // controls or an encoded traversal into a match via web URL serialization.
205
+ if (!/^https?:\/\//iu.test(url) ||
206
+ /[\\\x00-\x20\x7f?#]/u.test(url) ||
207
+ // libcurl accepts encoded userinfo but rejects multiple literal authority delimiters.
208
+ userinfo.includes("@") ||
209
+ // Git rejects a decoded line feed in credentials and libcurl rejects a NUL in usernames.
210
+ /%0a/iu.test(userinfo) ||
211
+ /^[^:]*%00/u.test(userinfo) ||
212
+ ambiguousGitIpHost(url) ||
213
+ ambiguousHostedHttpPath(url))
214
+ return false;
215
+ // The local checkout's credentials and default HTTP port don't change the server path.
216
+ const key = (value) => hostedRepositoryUrlKey(value.replace(/^(https?:\/\/)([^/?#\\]+)\//iu, (match, scheme, authority) => {
217
+ const parsed = URL.parse(scheme + authority);
218
+ return parsed ? scheme + parsed.host + "/" : match;
219
+ }), github, source.gitlab || source.platform === "gitlab");
220
+ return key(url) === key(source.url);
221
+ }
222
+ //# sourceMappingURL=hosted-git-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-git-repository.js","sourceRoot":"","sources":["../src/hosted-git-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAA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AAM,EACN,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAC9C,CAAC;IACJ,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { isIPv4 } from \"node:net\";\nimport {\n type ExternalImportTarget,\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport { isGitHubCloudHost } from \"./git-remote.js\";\n\n// Git treats a colon followed by \"//\" as the start of a URL transport.\nconst scpRemote = /^(?:([^@/:\\s?#]+)@)?(\\[[^\\]]+\\]|[^@/:\\s?#]+):(?!\\/\\/)(.+)$/u;\n\nconst sshRemote = /^(?:ssh|git\\+ssh|ssh\\+git):\\/\\/([^/]+?)(?:\\/|%2[fF])/u;\n\n/** A native file URL or an unambiguous local path. */\nexport function isLocalGitRemote(remote: string): boolean {\n if (remote.includes(\"://\")) return remote.startsWith(\"file://\");\n const colon = remote.indexOf(\":\");\n return colon < 0 || remote.slice(0, colon).includes(\"/\");\n}\n\nexport function isWindowsGitDrive(remote: string): boolean {\n // Git for Windows accepts one character or up to four consecutive non-ASCII bytes before a drive colon.\n return (\n process.platform === \"win32\" &&\n !remote.includes(\"://\") &&\n /^(?:.|[\\u0080-\\u07ff]{2}):(?!:)/su.test(remote)\n );\n}\n\nfunction parseScpRemote(remote: string): RegExpExecArray | null {\n return !isLocalGitRemote(remote) &&\n !remote.includes(\"://\") &&\n !/^[a-z\\d][a-z\\d+.-]*::/iu.test(remote)\n ? scpRemote.exec(remote)\n : null;\n}\n\nfunction sshAuthority(host: string): URL | null {\n if (/[\\/\\\\?#@\\s\\x00-\\x1f\\x7f]/u.test(host)) return null;\n // Git passes a leading plus on decimal ports through to OpenSSH.\n const parse = (authority: string) =>\n URL.parse(\"ssh://\" + authority.replace(/:\\+(\\d+)$/u, \":$1\"));\n const parsed = parse(host);\n if (parsed) return parsed;\n // Git accepts brackets around DNS names, with an SSH port inside or after the brackets.\n const bracketed = /^\\[([^\\]]+)\\](?::(\\+?\\d*))?$/u.exec(host);\n // An empty port outside the brackets is ignored, but an inner trailing colon is a hostname byte.\n if (!bracketed || bracketed[1]!.endsWith(\":\")) return null;\n const [, name, port] = bracketed;\n return parse(name + (port ? `:${port}` : \"\"));\n}\n\n/** Git decodes URI escapes once except for NUL, and sends SCP bytes literally. */\nexport function gitTransportBytes(raw: string, scpStyle: boolean): string {\n const bytes = Buffer.from(raw).toString(\"latin1\");\n return scpStyle\n ? bytes\n : bytes.replace(/%(?!00)([\\da-f]{2})/giu, (_, hex: string) =>\n String.fromCharCode(parseInt(hex, 16)),\n );\n}\n\n/** Decode only URI escapes whose ASCII bytes cannot introduce a delimiter. */\nexport function decodeUnreserved(value: string): string {\n return value.replace(/%([0-9a-f]{2})/giu, (escape, hex: string) => {\n const byte = String.fromCharCode(parseInt(hex, 16));\n return /^[a-z0-9._~-]$/iu.test(byte) ? byte : escape.toUpperCase();\n });\n}\n\n/** Represent upload-pack path bytes relative to an HTTP repository origin. */\nexport function gitPathToHttpPath(bytes: string): string {\n return bytes\n .replace(/^\\//u, \"\")\n .replace(\n /[%\\x00-\\x20\\x7f-\\xff]/gu,\n (byte) =>\n \"%\" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\"),\n );\n}\n\n/** Ignore the optional DNS root dot for provider classification only. */\nexport function gitServiceHostname(hostname: string): string {\n return hostname.replace(/\\.$/u, \"\");\n}\n\nexport function isPublicGitHost(host: string): boolean {\n return (\n isGitHubCloudHost(host) || host === \"gitlab.com\" || host === \"bitbucket.org\"\n );\n}\n\n/** Public SSH-over-443 hosts share the HTTPS hostname after the first DNS label. */\nfunction publicGitSsh443Host(hostname: string): string | undefined {\n switch (gitServiceHostname(hostname)) {\n case \"ssh.github.com\":\n case \"altssh.gitlab.com\":\n case \"altssh.bitbucket.org\":\n return hostname.slice(hostname.indexOf(\".\") + 1);\n }\n}\n\nfunction matchesHttpsHost(url: string | undefined, hostname: string): boolean {\n const source = url && URL.parse(url);\n return (\n !!source &&\n source.protocol === \"https:\" &&\n source.hostname.toLowerCase() === hostname\n );\n}\n\n/** Standard public SSH aliases, plus a hosted SCM established by the caller. */\nexport function normalizeHostedGitRepositoryUrl(\n remote: string,\n source: string | undefined,\n trustedScm: boolean,\n): string {\n // A projected single-project report may retain only its SSH spelling.\n return normalizeGitSshAlias(\n remote,\n (host) =>\n (trustedScm || isPublicGitHost(gitServiceHostname(host))) &&\n matchesHttpsHost(source ?? `https://${host}`, host),\n );\n}\n\nfunction normalizeGitSshAlias(\n repository: string,\n isAliasHost: (host: string) => boolean,\n): string {\n const isGitSshUser = (username: string, hostname: string) =>\n (username === \"git\" && hostname === \"github.com\") ||\n (isAliasHost(hostname) &&\n (username === \"git\" ||\n username ===\n /^([^.]+)\\.ghe\\.com$/u.exec(gitServiceHostname(hostname))?.[1]));\n const hostedAlias = (\n url: URL,\n user: string,\n path: string,\n scpStyle: boolean,\n ) => {\n const hostname = url.hostname.toLowerCase();\n const standard =\n isGitSshUser(user, hostname) && (url.port === \"\" || url.port === \"22\");\n const alternate =\n user === \"git\" && url.port === \"443\" && publicGitSsh443Host(hostname);\n if (!standard && !alternate) return repository;\n const bytes = gitTransportBytes(path, scpStyle);\n if (/[?#\\\\]/u.test(bytes) || /(?:^|\\/)\\.{1,2}(?:\\/|$)/u.test(bytes))\n return repository;\n return `https://${alternate || hostname}/${gitPathToHttpPath(bytes)}`;\n };\n const scp = parseScpRemote(repository);\n if (scp) {\n if (!scp[1]) return repository;\n const authority = sshAuthority(scp[2]!);\n return authority\n ? hostedAlias(authority, scp[1], scp[3]!, true)\n : repository;\n }\n // Git separates the decoded authority from the path at the first slash.\n const ssh = sshRemote.exec(repository);\n if (ssh && !/[\\t\\r\\n]/u.test(repository)) {\n const authority = gitTransportBytes(ssh[1]!, false);\n const login = /^([^@:]+)@([^@]+)$/u.exec(authority);\n if (!login || /[/\\\\%?#\\s]/u.test(authority)) return repository;\n const url = sshAuthority(login[2]!);\n if (url)\n return hostedAlias(\n url,\n login[1]!,\n \"/\" + repository.slice(ssh[0].length),\n false,\n );\n }\n return repository;\n}\n\nfunction hostedHttpAuthority(authority: string): string {\n if (/[%@\\\\\\s]/u.test(authority)) return authority;\n const hostname = URL.parse(`https://${authority}/`)?.hostname;\n // Hostname serialization handles IP literals and IDNA. The connector distinguishes explicit ports.\n const port = /:\\d*$/u.exec(authority)?.[0] ?? \"\";\n return hostname ? hostname + port : authority;\n}\n\nfunction hostedHttpPath(path: string): string {\n const segments: string[] = [];\n for (const segment of path.split(\"/\")) {\n // Git's HTTP transport resolves literal dot segments before sending the path.\n if (segment === \"..\") {\n segments.pop();\n } else if (segment !== \".\") {\n const spelling = segment.replace(/\\P{ASCII}+/gu, (text) =>\n encodeURIComponent(text.toWellFormed()),\n );\n const decoded = decodeUnreserved(spelling);\n segments.push(\n decoded === \".\" || decoded === \"..\" ? segment.toUpperCase() : decoded,\n );\n }\n }\n if (/(?:^|\\/)\\.{1,2}$/u.test(path)) segments.push(\"\");\n return segments.join(\"/\");\n}\n\n/** Compare the HTTP request path a browser and Git would send for the same link. */\nexport function ambiguousHostedHttpPath(value: string): boolean {\n const path = /^https?:\\/\\/[^/?#]+\\/([^?#]*)/iu.exec(value)?.[1];\n if (path === undefined) return false;\n const web = URL.parse(value)?.pathname.slice(1);\n return (\n web !== undefined &&\n path !== web &&\n hostedHttpPath(path) !== hostedHttpPath(web)\n );\n}\n\n/** Compare hosted HTTP repository spellings without changing the retained evidence. */\nexport function hostedRepositoryUrlKey(\n value: string,\n github = false,\n knownGitSuffix = false,\n target: ExternalImportTarget = \"local\",\n): string {\n const url = value.replace(\n /^(https?:\\/\\/)([^/?#]+)\\/([^?#]*)/iu,\n (_, scheme: string, authority: string, path: string) =>\n scheme +\n (target === \"cloud\" && ambiguousGitIpHost(value)\n ? authority.toLowerCase()\n : hostedHttpAuthority(authority)) +\n \"/\" +\n hostedHttpPath(path),\n );\n if (github) return cloudRepositoryUrlKey(url);\n const host = URL.parse(url)?.hostname ?? \"\";\n const service = /^https?:\\/\\//iu.test(url) ? gitServiceHostname(host) : host;\n if (service !== host && isGitHubCloudHost(service))\n return cloudRepositoryUrlKey(url);\n // An arbitrary Git server can serve different repositories at /repo and /repo.git.\n const key = repositoryUrlKey(url);\n return !knownGitSuffix && !isPublicGitHost(service) && /\\.git\\/?$/u.test(url)\n ? key + \".git\"\n : key;\n}\n\n/** The Git HTTP Host and TLS server name can differ from the web URL's parsed IP literal. */\nexport function ambiguousGitIpHost(url: string): boolean {\n const host = URL.parse(url)?.hostname;\n if (!host || (!isIPv4(host) && !host.startsWith(\"[\"))) return false;\n const authority = /^https?:\\/\\/([^/?#]*)/iu.exec(url)?.[1] ?? \"\";\n const rawHost = authority\n .slice(authority.lastIndexOf(\"@\") + 1)\n .replace(/:\\d*$/u, \"\");\n return rawHost.toLowerCase() !== host;\n}\n\n/** Match a Git checkout to an independently selected hosted repository. */\nexport function hostedRepositoryMatches(\n source: { url: string; platform?: string; gitlab?: boolean },\n remote: string,\n): boolean {\n if (!/^https?:\\/\\//iu.test(source.url)) return remote === source.url;\n const github = source.platform === \"github\";\n const url = normalizeHostedGitRepositoryUrl(\n remote,\n source.url,\n github || source.platform === \"gitlab\",\n );\n const userinfo = /^https?:\\/\\/([^/?#]*)@/iu.exec(url)?.[1] ?? \"\";\n // Git passes raw URL paths to its HTTP transport. Do not turn backslashes,\n // controls or an encoded traversal into a match via web URL serialization.\n if (\n !/^https?:\\/\\//iu.test(url) ||\n /[\\\\\\x00-\\x20\\x7f?#]/u.test(url) ||\n // libcurl accepts encoded userinfo but rejects multiple literal authority delimiters.\n userinfo.includes(\"@\") ||\n // Git rejects a decoded line feed in credentials and libcurl rejects a NUL in usernames.\n /%0a/iu.test(userinfo) ||\n /^[^:]*%00/u.test(userinfo) ||\n ambiguousGitIpHost(url) ||\n ambiguousHostedHttpPath(url)\n )\n return false;\n // The local checkout's credentials and default HTTP port don't change the server path.\n const key = (value: string) =>\n hostedRepositoryUrlKey(\n value.replace(\n /^(https?:\\/\\/)([^/?#\\\\]+)\\//iu,\n (match, scheme: string, authority: string) => {\n const parsed = URL.parse(scheme + authority);\n return parsed ? scheme + parsed.host + \"/\" : match;\n },\n ),\n github,\n source.gitlab || source.platform === \"gitlab\",\n );\n return key(url) === key(source.url);\n}\n"]}
@@ -78,6 +78,7 @@ export interface HostedRemediationResult {
78
78
  error?: {
79
79
  code: string;
80
80
  message: string;
81
+ reason?: "revision_changed";
81
82
  };
82
83
  }
83
84
  export declare class HostedRemediationPreparationError extends Error {
@@ -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,EAKL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;kBAmBvC,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;IACd,eAAe,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IAC3D,OAAO,EAAE,iBAAiB,GAAG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AAA;KAAE,CAAC;CACxE;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,CAwGlC"}
@@ -47,7 +47,7 @@ export async function runHostedRemediation(value, options) {
47
47
  throw new HostedRemediationPreparationError();
48
48
  const pluginRoot = await bundledPluginRoot();
49
49
  const { version: pluginVersion } = await pluginMetadata(pluginRoot);
50
- const prompt = await remediationPrompt({
50
+ let prompt = await remediationPrompt({
51
51
  operation: input.operation,
52
52
  pluginRoot,
53
53
  contents: [
@@ -59,6 +59,13 @@ export async function runHostedRemediation(value, options) {
59
59
  validationInstructions: input.validationInstructions,
60
60
  verificationMode: input.verificationMode,
61
61
  });
62
+ if (input.operation === "patch") {
63
+ prompt = [
64
+ "Work in the supplied checkout and leave all patch edits uncommitted for the host to capture, even if repository or validation instructions ask you to commit or use a separate worktree.",
65
+ `Keep HEAD at the pinned revision ${input.revision}. Before returning, check git rev-parse HEAD and git status --short to confirm the revision and the files you report.`,
66
+ prompt,
67
+ ].join("\n");
68
+ }
62
69
  const target = {
63
70
  version: 1,
64
71
  operation: input.operation,
@@ -98,8 +105,21 @@ export async function runHostedRemediation(value, options) {
98
105
  throw new Error("Execution receipt does not match the remediation request.");
99
106
  if (execution.status !== "completed")
100
107
  return { ...base, status: execution.status, execution };
101
- if ((await repositoryRevision(repository)) !== input.revision)
102
- throw new Error("Checkout changed from the frozen revision during execution.");
108
+ const revision = await repositoryRevision(repository);
109
+ if (revision === null)
110
+ throw new Error("Could not resolve HEAD after remediation execution.");
111
+ if (revision !== input.revision) {
112
+ return {
113
+ ...base,
114
+ status: "failed",
115
+ execution,
116
+ error: {
117
+ code: "INVALID_RESULT",
118
+ reason: "revision_changed",
119
+ message: "Checkout changed from the frozen revision during execution.",
120
+ },
121
+ };
122
+ }
103
123
  const response = execution.finalResponse ?? "";
104
124
  const outcome = input.operation === "patch"
105
125
  ? { patch: parseFindingPatch(response, input.finding.id) }
@@ -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,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,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC;IAC7D,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC;QACtB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;KAClC,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AE,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"]}
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,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC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KAAK,CAAC;aAC7B;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB,CAAC,QAAgB,EAAE,SAAiB;IAClE,MAAM,YAAY,GAAG,yBAAyB,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;IAC1E,IAAI,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; reason?: \"revision_changed\" };\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 let 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 if (input.operation === \"patch\") {\n prompt = [\n \"Work in the supplied checkout and leave all patch edits uncommitted for the host to capture, even if repository or validation instructions ask you to commit or use a separate worktree.\",\n `Keep HEAD at the pinned revision ${input.revision}. Before returning, check git rev-parse HEAD and git status --short to confirm the revision and the files you report.`,\n prompt,\n ].join(\"\\n\");\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 const revision = await repositoryRevision(repository);\n if (revision === null)\n throw new Error(\"Could not resolve HEAD after remediation execution.\");\n if (revision !== input.revision) {\n return {\n ...base,\n status: \"failed\",\n execution,\n error: {\n code: \"INVALID_RESULT\",\n reason: \"revision_changed\",\n message:\n \"Checkout changed from the frozen revision during execution.\",\n },\n };\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"]}
@@ -1,5 +1,5 @@
1
1
  import { runHostProtocol } from "./host-protocol.js";
2
- import { HostedScanPreparationError, runHostedScan, } from "./hosted-scan.js";
2
+ import { HostedScanPreparationError, runHostedScanInternal, } from "./hosted-scan.js";
3
3
  import { ScanExecutionEventSchema, ScanExecutionResultSchema, } from "./scan-executor.js";
4
4
  export async function runHostedScanProtocol(input, output, signal) {
5
5
  return await runHostProtocol(input, output, {
@@ -9,7 +9,7 @@ export async function runHostedScanProtocol(input, output, signal) {
9
9
  errorData: (error) => error instanceof HostedScanPreparationError
10
10
  ? { reason: error.reason }
11
11
  : undefined,
12
- run: async (params, execute, signal, onEvent) => await runHostedScan(params, {
12
+ run: async (params, execute, signal, onEvent) => await runHostedScanInternal("cli", params, {
13
13
  signal,
14
14
  onEvent,
15
15
  executor: {
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-scan-protocol.js","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,0BAA0B,EAC1B,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAe,EACf,MAA6C,EAC7C,MAAoB;IAEpB,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,eAAe;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,0BAA0B;YACzC,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,aAAa,CAAC,MAAyB,EAAE;YAC7C,MAAM;YACN,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,yBAAyB,CAAC,KAAK,CAC7B,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClD,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBACzD,IAAI,MAAM,CAAC,OAAO;wBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC,CACH;aACJ;SACF,CAAC;KACL,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n type HostedScanInput,\n HostedScanPreparationError,\n runHostedScan,\n} from \"./hosted-scan.js\";\nimport {\n ScanExecutionEventSchema,\n ScanExecutionResultSchema,\n} from \"./scan-executor.js\";\n\nexport async function runHostedScanProtocol(\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: \"Scan\",\n requestMethod: \"execution.run\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedScanPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) =>\n await runHostedScan(params as HostedScanInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n ScanExecutionResultSchema.parse(\n await execute(request.requestId, request, (event) => {\n const parsed = ScanExecutionEventSchema.safeParse(event);\n if (parsed.success) options.onEvent?.(parsed.data);\n }),\n ),\n },\n }),\n },\n signal,\n );\n}\n"]}
1
+ {"version":3,"file":"hosted-scan-protocol.js","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAe,EACf,MAA6C,EAC7C,MAAoB;IAEpB,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,eAAe;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,0BAA0B;YACzC,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,qBAAqB,CAAC,KAAK,EAAE,MAAyB,EAAE;YAC5D,MAAM;YACN,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,yBAAyB,CAAC,KAAK,CAC7B,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClD,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBACzD,IAAI,MAAM,CAAC,OAAO;wBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC,CACH;aACJ;SACF,CAAC;KACL,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n type HostedScanInput,\n HostedScanPreparationError,\n runHostedScanInternal,\n} from \"./hosted-scan.js\";\nimport {\n ScanExecutionEventSchema,\n ScanExecutionResultSchema,\n} from \"./scan-executor.js\";\n\nexport async function runHostedScanProtocol(\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: \"Scan\",\n requestMethod: \"execution.run\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedScanPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) =>\n await runHostedScanInternal(\"cli\", params as HostedScanInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n ScanExecutionResultSchema.parse(\n await execute(request.requestId, request, (event) => {\n const parsed = ScanExecutionEventSchema.safeParse(event);\n if (parsed.success) options.onEvent?.(parsed.data);\n }),\n ),\n },\n }),\n },\n signal,\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-scan.d.ts","sourceRoot":"","sources":["../src/hosted-scan.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,kBAAkB,EAExB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,qFAAqF;AACrF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;kBAuBhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,QAAQ,CAAC,MAAM,EAC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C;IACF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC/C;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,iBAAiB;;;;QAef,KAAK;;;;;;;;;;;;aAYL,CAAC;;;;;;;;;;;;;;;;;;;;;;YA6IA,WAAW;;;;;;;;;;;QAzJZ,KAAK;;;;;;;;;;;;aAYL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;GAxBb;AAwMD,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC"}
@@ -3,13 +3,13 @@ import { isDeepStrictEqual } from "node:util";
3
3
  import { readScanFile, safeScopePath, validatedFileDigests, } from "./contract.js";
4
4
  import { isRecord } from "./record.js";
5
5
  import { VERSION } from "./version.js";
6
- import { ScanExecutionError, } from "./scan-executor.js";
6
+ import { hostedScanFailureStatus, ScanExecutionError, } from "./scan-executor.js";
7
7
  import { realpath } from "node:fs/promises";
8
8
  import { isAbsolute, relative, resolve, sep } from "node:path";
9
9
  import { z } from "zod";
10
10
  import { CodexSecurity } from "./api.js";
11
11
  import { severityRubricSnapshotSchema } from "./classify-severity-records.js";
12
- import { ScanInterruptedError, errorMessage } from "./errors.js";
12
+ import { errorMessage } from "./errors.js";
13
13
  import { abortable, normalizeRepository, repositoryRevision, } from "./targets.js";
14
14
  import { isWithin } from "./trusted-executable.js";
15
15
  /** Hosted v2 mirrors repository/paths targets; only Standard scans are supported. */
@@ -118,7 +118,11 @@ function hostedScanEnvironment(stateDirectory) {
118
118
  return environment;
119
119
  }
120
120
  /** One invocation, with only scan-domain state. The host decides retry/reconciliation. */
121
- export async function runHostedScan(value, options) {
121
+ export function runHostedScan(value, options) {
122
+ return runHostedScanInternal("sdk", value, options);
123
+ }
124
+ /** @internal */
125
+ export async function runHostedScanInternal(surface, value, options) {
122
126
  const input = HostedScanInputSchema.parse(value);
123
127
  const context = {
124
128
  repository: input.repository,
@@ -132,6 +136,7 @@ export async function runHostedScan(value, options) {
132
136
  let execution;
133
137
  let request;
134
138
  let scanId;
139
+ let stoppedStatus;
135
140
  let outputDirectory = resolve(input.outputDirectory);
136
141
  const base = () => ({
137
142
  version: 2,
@@ -193,7 +198,7 @@ export async function runHostedScan(value, options) {
193
198
  createCodex() {
194
199
  throw new Error("Local inference is unavailable in hosted mode.");
195
200
  },
196
- }, { surface: "sdk" });
201
+ }, { surface });
197
202
  try {
198
203
  const result = await client.run(context.repository, {
199
204
  target: context.scope.paths[0] === "."
@@ -210,6 +215,10 @@ export async function runHostedScan(value, options) {
210
215
  scanId = scan.scanId;
211
216
  outputDirectory = scan.scanDir;
212
217
  },
218
+ onLifecycle(scan) {
219
+ if (scan.status === "canceled" || scan.status === "failed")
220
+ stoppedStatus = scan.status;
221
+ },
213
222
  onProgress(progress) {
214
223
  onEvent({ type: "progress", progress });
215
224
  },
@@ -262,15 +271,11 @@ export async function runHostedScan(value, options) {
262
271
  catch (error) {
263
272
  if (error instanceof ScanExecutionError)
264
273
  execution = error.result;
274
+ const status = hostedScanFailureStatus(error, options.signal, execution);
265
275
  return {
266
276
  ...base(),
267
- status: execution?.status === "acceptance_unknown"
268
- ? "acceptance_unknown"
269
- : options.signal?.aborted ||
270
- execution?.status === "canceled" ||
271
- error instanceof ScanInterruptedError
272
- ? "canceled"
273
- : "failed",
277
+ // A late abort during cleanup cannot change an already committed failure.
278
+ status: status === "acceptance_unknown" ? status : (stoppedStatus ?? status),
274
279
  error: errorMessage(error),
275
280
  artifacts: [],
276
281
  };