@openai/codex-security 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +2 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/artifact-storage.md +1 -1
  15. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  16. package/_bundled_plugin/references/core-scan.md +5 -42
  17. package/_bundled_plugin/references/final-report.md +1 -1
  18. package/_bundled_plugin/references/focused-investigator.md +13 -0
  19. package/_bundled_plugin/references/scan-prologue.md +2 -2
  20. package/_bundled_plugin/references/scan-runtime.md +4 -2
  21. package/_bundled_plugin/references/security-guidance.md +14 -1
  22. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  23. package/_bundled_plugin/scripts/deep_scan_workbench.py +29 -12
  24. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -3
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  30. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  31. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  32. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  33. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  34. package/_bundled_plugin/scripts/workbench_db.py +244 -217
  35. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  36. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  37. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  38. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  39. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +281 -119
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +143 -9
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  44. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  45. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_target.py +471 -84
  47. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  48. package/_bundled_plugin/shared/workbench-history-repairs.json +60 -14
  49. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  50. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  51. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -160
  52. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  53. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  54. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  55. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  56. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  57. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  58. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  60. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  61. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  62. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  63. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  64. package/bin/codex-security.mjs +2 -2
  65. package/dist/api.d.ts +6 -1
  66. package/dist/api.d.ts.map +1 -1
  67. package/dist/api.js +437 -154
  68. package/dist/api.js.map +1 -1
  69. package/dist/armorcode-findings.d.ts +9 -0
  70. package/dist/armorcode-findings.d.ts.map +1 -0
  71. package/dist/armorcode-findings.js +145 -0
  72. package/dist/armorcode-findings.js.map +1 -0
  73. package/dist/artifact-export.d.ts +2 -0
  74. package/dist/artifact-export.d.ts.map +1 -1
  75. package/dist/artifact-export.js +29 -13
  76. package/dist/artifact-export.js.map +1 -1
  77. package/dist/auth.d.ts +6 -2
  78. package/dist/auth.d.ts.map +1 -1
  79. package/dist/auth.js +33 -12
  80. package/dist/auth.js.map +1 -1
  81. package/dist/batch-cost.d.ts +18 -0
  82. package/dist/batch-cost.d.ts.map +1 -0
  83. package/dist/batch-cost.js +41 -0
  84. package/dist/batch-cost.js.map +1 -0
  85. package/dist/blackduck-findings.d.ts +1 -1
  86. package/dist/blackduck-findings.d.ts.map +1 -1
  87. package/dist/blackduck-findings.js +5 -18
  88. package/dist/blackduck-findings.js.map +1 -1
  89. package/dist/bundled-plugin.d.ts +4 -0
  90. package/dist/bundled-plugin.d.ts.map +1 -0
  91. package/dist/bundled-plugin.js +23 -0
  92. package/dist/bundled-plugin.js.map +1 -0
  93. package/dist/classify-scan-severity.d.ts +1 -1
  94. package/dist/classify-scan-severity.d.ts.map +1 -1
  95. package/dist/classify-scan-severity.js +11 -3
  96. package/dist/classify-scan-severity.js.map +1 -1
  97. package/dist/classify-severity.d.ts.map +1 -1
  98. package/dist/classify-severity.js +9 -6
  99. package/dist/classify-severity.js.map +1 -1
  100. package/dist/cli-argument.d.ts +4 -0
  101. package/dist/cli-argument.d.ts.map +1 -0
  102. package/dist/cli-argument.js +17 -0
  103. package/dist/cli-argument.js.map +1 -0
  104. package/dist/cli-help.d.ts +1 -1
  105. package/dist/cli-help.d.ts.map +1 -1
  106. package/dist/cli-help.js +71 -29
  107. package/dist/cli-help.js.map +1 -1
  108. package/dist/cli-hook.d.ts +3 -0
  109. package/dist/cli-hook.d.ts.map +1 -0
  110. package/dist/cli-hook.js +87 -0
  111. package/dist/cli-hook.js.map +1 -0
  112. package/dist/cli-integrations.d.ts +13 -0
  113. package/dist/cli-integrations.d.ts.map +1 -0
  114. package/dist/cli-integrations.js +333 -0
  115. package/dist/cli-integrations.js.map +1 -0
  116. package/dist/cli-mcp.d.ts +15 -0
  117. package/dist/cli-mcp.d.ts.map +1 -0
  118. package/dist/cli-mcp.js +178 -0
  119. package/dist/cli-mcp.js.map +1 -0
  120. package/dist/cli-token-view.d.ts +10 -0
  121. package/dist/cli-token-view.d.ts.map +1 -0
  122. package/dist/cli-token-view.js +41 -0
  123. package/dist/cli-token-view.js.map +1 -0
  124. package/dist/cli.d.ts +5 -3
  125. package/dist/cli.d.ts.map +1 -1
  126. package/dist/cli.js +1763 -894
  127. package/dist/cli.js.map +1 -1
  128. package/dist/cloud-publish.d.ts.map +1 -1
  129. package/dist/cloud-publish.js +33 -31
  130. package/dist/cloud-publish.js.map +1 -1
  131. package/dist/codex-sdk-environment.d.ts +6 -0
  132. package/dist/codex-sdk-environment.d.ts.map +1 -1
  133. package/dist/codex-sdk-environment.js +19 -0
  134. package/dist/codex-sdk-environment.js.map +1 -1
  135. package/dist/command-words.d.ts +3 -0
  136. package/dist/command-words.d.ts.map +1 -0
  137. package/dist/command-words.js +46 -0
  138. package/dist/command-words.js.map +1 -0
  139. package/dist/component-scan.d.ts +3 -1
  140. package/dist/component-scan.d.ts.map +1 -1
  141. package/dist/component-scan.js +40 -7
  142. package/dist/component-scan.js.map +1 -1
  143. package/dist/config.d.ts +1 -1
  144. package/dist/config.d.ts.map +1 -1
  145. package/dist/config.js +30 -1
  146. package/dist/config.js.map +1 -1
  147. package/dist/continuum-findings.d.ts +1 -1
  148. package/dist/continuum-findings.d.ts.map +1 -1
  149. package/dist/continuum-findings.js +93 -31
  150. package/dist/continuum-findings.js.map +1 -1
  151. package/dist/cost.d.ts.map +1 -1
  152. package/dist/cost.js +1 -45
  153. package/dist/cost.js.map +1 -1
  154. package/dist/custom-validation-prompt.d.ts +1 -1
  155. package/dist/custom-validation-prompt.d.ts.map +1 -1
  156. package/dist/custom-validation-prompt.js +29 -19
  157. package/dist/custom-validation-prompt.js.map +1 -1
  158. package/dist/deduplication/local.d.ts +3 -1
  159. package/dist/deduplication/local.d.ts.map +1 -1
  160. package/dist/deduplication/local.js +8 -1
  161. package/dist/deduplication/local.js.map +1 -1
  162. package/dist/deduplication/refusal.d.ts.map +1 -1
  163. package/dist/deduplication/refusal.js +2 -1
  164. package/dist/deduplication/refusal.js.map +1 -1
  165. package/dist/deduplication/scan.d.ts +2 -0
  166. package/dist/deduplication/scan.d.ts.map +1 -1
  167. package/dist/deduplication/scan.js +24 -7
  168. package/dist/deduplication/scan.js.map +1 -1
  169. package/dist/deep-scan.d.ts.map +1 -1
  170. package/dist/deep-scan.js +16 -15
  171. package/dist/deep-scan.js.map +1 -1
  172. package/dist/endor-findings.d.ts +2 -2
  173. package/dist/endor-findings.d.ts.map +1 -1
  174. package/dist/endor-findings.js +6 -23
  175. package/dist/endor-findings.js.map +1 -1
  176. package/dist/errors.d.ts +3 -1
  177. package/dist/errors.d.ts.map +1 -1
  178. package/dist/errors.js +7 -3
  179. package/dist/errors.js.map +1 -1
  180. package/dist/executable-path.d.ts +3 -0
  181. package/dist/executable-path.d.ts.map +1 -1
  182. package/dist/executable-path.js +26 -0
  183. package/dist/executable-path.js.map +1 -1
  184. package/dist/external-findings-import.d.ts.map +1 -1
  185. package/dist/external-findings-import.js +12 -1
  186. package/dist/external-findings-import.js.map +1 -1
  187. package/dist/external-findings-local.d.ts +66 -4
  188. package/dist/external-findings-local.d.ts.map +1 -1
  189. package/dist/external-findings-local.js +234 -53
  190. package/dist/external-findings-local.js.map +1 -1
  191. package/dist/external-findings-publish.d.ts +6 -1
  192. package/dist/external-findings-publish.d.ts.map +1 -1
  193. package/dist/external-findings-publish.js +326 -1633
  194. package/dist/external-findings-publish.js.map +1 -1
  195. package/dist/external-findings-read.d.ts +1 -0
  196. package/dist/external-findings-read.d.ts.map +1 -1
  197. package/dist/external-findings-read.js +31 -51
  198. package/dist/external-findings-read.js.map +1 -1
  199. package/dist/external-findings.d.ts +1 -1
  200. package/dist/external-findings.d.ts.map +1 -1
  201. package/dist/external-findings.js +12 -1
  202. package/dist/external-findings.js.map +1 -1
  203. package/dist/external-import-contract.d.ts +3 -11
  204. package/dist/external-import-contract.d.ts.map +1 -1
  205. package/dist/external-import-contract.js +29 -176
  206. package/dist/external-import-contract.js.map +1 -1
  207. package/dist/external-import-models.d.ts +1 -1
  208. package/dist/external-import-models.d.ts.map +1 -1
  209. package/dist/external-import-models.js.map +1 -1
  210. package/dist/finding-prompt.d.ts.map +1 -1
  211. package/dist/finding-prompt.js +2 -2
  212. package/dist/finding-prompt.js.map +1 -1
  213. package/dist/github-dependabot-findings.d.ts.map +1 -1
  214. package/dist/github-dependabot-findings.js +3 -4
  215. package/dist/github-dependabot-findings.js.map +1 -1
  216. package/dist/github-findings.d.ts.map +1 -1
  217. package/dist/github-findings.js +19 -287
  218. package/dist/github-findings.js.map +1 -1
  219. package/dist/hosted-remediation.d.ts +1 -0
  220. package/dist/hosted-remediation.d.ts.map +1 -1
  221. package/dist/hosted-remediation.js +23 -3
  222. package/dist/hosted-remediation.js.map +1 -1
  223. package/dist/index.d.ts +3 -2
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js +2 -1
  226. package/dist/index.js.map +1 -1
  227. package/dist/inspector-findings.d.ts.map +1 -1
  228. package/dist/inspector-findings.js +19 -35
  229. package/dist/inspector-findings.js.map +1 -1
  230. package/dist/knowledge-base.d.ts +1 -1
  231. package/dist/knowledge-base.d.ts.map +1 -1
  232. package/dist/knowledge-base.js +34 -27
  233. package/dist/knowledge-base.js.map +1 -1
  234. package/dist/linear.d.ts +11 -0
  235. package/dist/linear.d.ts.map +1 -1
  236. package/dist/linear.js.map +1 -1
  237. package/dist/local-git-metadata.d.ts +5 -2
  238. package/dist/local-git-metadata.d.ts.map +1 -1
  239. package/dist/local-git-metadata.js +8 -4
  240. package/dist/local-git-metadata.js.map +1 -1
  241. package/dist/multiscan.d.ts +4 -0
  242. package/dist/multiscan.d.ts.map +1 -1
  243. package/dist/multiscan.js +79 -37
  244. package/dist/multiscan.js.map +1 -1
  245. package/dist/opengrep-findings.d.ts +4 -2
  246. package/dist/opengrep-findings.d.ts.map +1 -1
  247. package/dist/opengrep-findings.js +39 -22
  248. package/dist/opengrep-findings.js.map +1 -1
  249. package/dist/private-finding-import.d.ts +8 -13
  250. package/dist/private-finding-import.d.ts.map +1 -1
  251. package/dist/private-finding-import.js +69 -129
  252. package/dist/private-finding-import.js.map +1 -1
  253. package/dist/project-config.d.ts.map +1 -1
  254. package/dist/project-config.js +53 -13
  255. package/dist/project-config.js.map +1 -1
  256. package/dist/prompt-files.d.ts +7 -2
  257. package/dist/prompt-files.d.ts.map +1 -1
  258. package/dist/prompt-files.js +42 -20
  259. package/dist/prompt-files.js.map +1 -1
  260. package/dist/provider-profile.d.ts.map +1 -1
  261. package/dist/provider-profile.js +4 -9
  262. package/dist/provider-profile.js.map +1 -1
  263. package/dist/publication.d.ts +1 -1
  264. package/dist/publication.d.ts.map +1 -1
  265. package/dist/publication.js.map +1 -1
  266. package/dist/record.d.ts +1 -5
  267. package/dist/record.d.ts.map +1 -1
  268. package/dist/record.js +3 -51
  269. package/dist/record.js.map +1 -1
  270. package/dist/remediation.d.ts.map +1 -1
  271. package/dist/remediation.js +3 -1
  272. package/dist/remediation.js.map +1 -1
  273. package/dist/runtime.d.ts +35 -7
  274. package/dist/runtime.d.ts.map +1 -1
  275. package/dist/runtime.js +778 -153
  276. package/dist/runtime.js.map +1 -1
  277. package/dist/saved-scan-bootstrap.d.ts +6 -1
  278. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  279. package/dist/saved-scan-bootstrap.js +267 -115
  280. package/dist/saved-scan-bootstrap.js.map +1 -1
  281. package/dist/scan-archive-path.d.ts +2 -0
  282. package/dist/scan-archive-path.d.ts.map +1 -0
  283. package/dist/scan-archive-path.js +5 -0
  284. package/dist/scan-archive-path.js.map +1 -0
  285. package/dist/scan-comparison.d.ts.map +1 -1
  286. package/dist/scan-comparison.js +6 -2
  287. package/dist/scan-comparison.js.map +1 -1
  288. package/dist/scan-dashboard.d.ts +1 -0
  289. package/dist/scan-dashboard.d.ts.map +1 -1
  290. package/dist/scan-dashboard.js +18 -2
  291. package/dist/scan-dashboard.js.map +1 -1
  292. package/dist/scan-executor.d.ts.map +1 -1
  293. package/dist/scan-executor.js +4 -2
  294. package/dist/scan-executor.js.map +1 -1
  295. package/dist/scan-history-renderer.d.ts +1 -0
  296. package/dist/scan-history-renderer.d.ts.map +1 -1
  297. package/dist/scan-history-renderer.js +25 -9
  298. package/dist/scan-history-renderer.js.map +1 -1
  299. package/dist/scan-logs.d.ts.map +1 -1
  300. package/dist/scan-logs.js +28 -4
  301. package/dist/scan-logs.js.map +1 -1
  302. package/dist/scanner-import.d.ts +5 -11
  303. package/dist/scanner-import.d.ts.map +1 -1
  304. package/dist/scanner-import.js +16 -89
  305. package/dist/scanner-import.js.map +1 -1
  306. package/dist/security-policy.d.ts.map +1 -1
  307. package/dist/security-policy.js +26 -6
  308. package/dist/security-policy.js.map +1 -1
  309. package/dist/semgrep-findings.d.ts.map +1 -1
  310. package/dist/semgrep-findings.js +14 -48
  311. package/dist/semgrep-findings.js.map +1 -1
  312. package/dist/semgrep-platform-findings.d.ts +20 -70
  313. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  314. package/dist/semgrep-platform-findings.js +116 -333
  315. package/dist/semgrep-platform-findings.js.map +1 -1
  316. package/dist/snyk-findings.d.ts +2 -0
  317. package/dist/snyk-findings.d.ts.map +1 -1
  318. package/dist/snyk-findings.js +5 -8
  319. package/dist/snyk-findings.js.map +1 -1
  320. package/dist/snyk-rest-findings.d.ts +3 -20
  321. package/dist/snyk-rest-findings.d.ts.map +1 -1
  322. package/dist/snyk-rest-findings.js +45 -217
  323. package/dist/snyk-rest-findings.js.map +1 -1
  324. package/dist/sonar-findings.d.ts +1 -1
  325. package/dist/sonar-findings.d.ts.map +1 -1
  326. package/dist/sonar-findings.js +2 -4
  327. package/dist/sonar-findings.js.map +1 -1
  328. package/dist/sonar-import.d.ts +3 -0
  329. package/dist/sonar-import.d.ts.map +1 -1
  330. package/dist/sonar-import.js +28 -30
  331. package/dist/sonar-import.js.map +1 -1
  332. package/dist/stored-finding-projection.d.ts +6 -0
  333. package/dist/stored-finding-projection.d.ts.map +1 -0
  334. package/dist/stored-finding-projection.js +104 -0
  335. package/dist/stored-finding-projection.js.map +1 -0
  336. package/dist/stored-findings-publication.d.ts +23 -0
  337. package/dist/stored-findings-publication.d.ts.map +1 -0
  338. package/dist/stored-findings-publication.js +169 -0
  339. package/dist/stored-findings-publication.js.map +1 -0
  340. package/dist/targets.d.ts +6 -1
  341. package/dist/targets.d.ts.map +1 -1
  342. package/dist/targets.js +76 -23
  343. package/dist/targets.js.map +1 -1
  344. package/dist/tenable-findings.d.ts +1 -4
  345. package/dist/tenable-findings.d.ts.map +1 -1
  346. package/dist/tenable-findings.js.map +1 -1
  347. package/dist/trivy-findings.d.ts.map +1 -1
  348. package/dist/trivy-findings.js +0 -11
  349. package/dist/trivy-findings.js.map +1 -1
  350. package/dist/trusted-executable.d.ts +6 -0
  351. package/dist/trusted-executable.d.ts.map +1 -1
  352. package/dist/trusted-executable.js +140 -37
  353. package/dist/trusted-executable.js.map +1 -1
  354. package/dist/veracode-findings.d.ts +1 -3
  355. package/dist/veracode-findings.d.ts.map +1 -1
  356. package/dist/veracode-findings.js +13 -38
  357. package/dist/veracode-findings.js.map +1 -1
  358. package/dist/version.d.ts +3 -1
  359. package/dist/version.d.ts.map +1 -1
  360. package/dist/version.js +184 -32
  361. package/dist/version.js.map +1 -1
  362. package/dist/wiz-findings.d.ts +2 -2
  363. package/dist/wiz-findings.d.ts.map +1 -1
  364. package/dist/wiz-findings.js +14 -92
  365. package/dist/wiz-findings.js.map +1 -1
  366. package/docs/cli.md +373 -106
  367. package/docs/findings-service.md +22 -9
  368. package/docs/hosted-remediation.md +13 -4
  369. package/docs/sdk.md +903 -0
  370. package/package.json +10 -6
  371. package/schemas/external-findings.schema.json +2 -1
  372. package/dist/hosted-scanner-v1.d.ts +0 -6
  373. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  374. package/dist/hosted-scanner-v1.js +0 -60
  375. package/dist/hosted-scanner-v1.js.map +0 -1
  376. package/dist/reader-selection.d.ts +0 -15
  377. package/dist/reader-selection.d.ts.map +0 -1
  378. package/dist/reader-selection.js +0 -89
  379. package/dist/reader-selection.js.map +0 -1
  380. package/dist/semgrep-platform-v1.d.ts +0 -6
  381. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  382. package/dist/semgrep-platform-v1.js +0 -83
  383. package/dist/semgrep-platform-v1.js.map +0 -1
  384. package/dist/snyk-rest-v1.d.ts +0 -28
  385. package/dist/snyk-rest-v1.d.ts.map +0 -1
  386. package/dist/snyk-rest-v1.js +0 -132
  387. package/dist/snyk-rest-v1.js.map +0 -1
@@ -0,0 +1,169 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import cloudSchema from "../schemas/external-findings.schema.json" with { type: "json" };
3
+ import { CodexSecurityError } from "./errors.js";
4
+ import { distinctSourceRepositories, recordExternalFindingPublications, selectLocalExternalFindings, } from "./external-findings-local.js";
5
+ import { cloudReviewDigest, prepareNormalizedPublication, } from "./external-findings-publish.js";
6
+ import { NoPublishableFindingsError, externalImportDisposition, } from "./external-findings.js";
7
+ import { projectStoredFinding } from "./stored-finding-projection.js";
8
+ function reference({ id, version, provider, sourceKey, sourceFindingId, }) {
9
+ return { id, version, provider, sourceKey, sourceFindingId };
10
+ }
11
+ function cloudProvider(provider) {
12
+ return cloudSchema.$defs.ImportSource.properties.provider.enum.includes(provider);
13
+ }
14
+ function cloudSelection(rows, sourceRepositories, inspectorMap, metadata) {
15
+ const selected = {
16
+ read: metadata?.excluded.length ?? 0,
17
+ findings: [],
18
+ excluded: [...(metadata?.excluded ?? [])],
19
+ report: metadata?.report,
20
+ };
21
+ const skipped = new Set(selected.excluded.map((item) => item.position));
22
+ let position = 0;
23
+ for (const row of rows) {
24
+ const projection = projectStoredFinding(row, sourceRepositories, inspectorMap);
25
+ selected.findings.push(...projection.findings);
26
+ selected.read += projection.read;
27
+ const positions = Array.from({ length: projection.read }, () => {
28
+ do {
29
+ position++;
30
+ } while (skipped.has(position));
31
+ return position;
32
+ });
33
+ for (const item of projection.excluded)
34
+ selected.excluded.push({
35
+ ...item,
36
+ position: positions[item.position - 1],
37
+ source_finding_id: row.sourceFindingId,
38
+ ...(projection.read > 1 && {
39
+ reason: `Retained trace ${item.position} in ${JSON.stringify(row.sourceFindingId)} (position in stored selection order): ${item.reason}`,
40
+ }),
41
+ });
42
+ }
43
+ // A native source may account for additional input observations, and an agent
44
+ // report may count a grouped occurrence once before its traces are expanded.
45
+ selected.read = Math.max(selected.read, metadata?.read ?? 0);
46
+ selected.excluded.sort((a, b) => a.position - b.position);
47
+ return selected;
48
+ }
49
+ function receiptRecorder(rows, dependencies) {
50
+ const repository = rows[0].repository;
51
+ const pins = new Map(rows.map(({ id, version, sourceFindingId }) => [
52
+ sourceFindingId,
53
+ { id, version },
54
+ ]));
55
+ return async ({ accountId, cloudApiUrl, destination, requests, findings }, receipts, privateJobId) => {
56
+ const entries = [];
57
+ if (privateJobId) {
58
+ for (const finding of findings)
59
+ entries.push({
60
+ ...pins.get(finding.source_finding_id),
61
+ receiptId: privateJobId,
62
+ outcome: "private_job",
63
+ });
64
+ }
65
+ for (const [index, receipt] of receipts.entries()) {
66
+ const batch = new Map(requests[index].items.map((item) => [
67
+ item.client_id,
68
+ pins.get(item.source_finding_id),
69
+ ]));
70
+ for (const item of receipt.results)
71
+ if (item.outcome !== "error")
72
+ entries.push({
73
+ ...batch.get(item.client_id),
74
+ receiptId: receipt.id,
75
+ outcome: item.outcome,
76
+ cloudFindingId: item.canonical_finding_id ?? undefined,
77
+ });
78
+ }
79
+ if (entries.length)
80
+ await recordExternalFindingPublications({
81
+ repository,
82
+ accountId,
83
+ cloudApiUrl,
84
+ destinationId: destination.id,
85
+ entries,
86
+ }, dependencies);
87
+ };
88
+ }
89
+ function prepareSource(rows, options, dependencies, workbench, metadata) {
90
+ const references = [...(dependencies.sourceRepositories ?? [])];
91
+ const inspectorProjectMap = new Map();
92
+ for (const row of rows) {
93
+ references.push(...(row.provenance?.sourceRepositories ?? []));
94
+ for (const [arn, url] of row.provenance?.inspectorProjectMap ?? []) {
95
+ if (inspectorProjectMap.has(arn) && inspectorProjectMap.get(arn) !== url)
96
+ throw new CodexSecurityError("The selected findings disagree on the Inspector project repository.");
97
+ inspectorProjectMap.set(arn, url);
98
+ }
99
+ }
100
+ const sourceRepositories = distinctSourceRepositories(references);
101
+ return prepareNormalizedPublication(cloudSelection(rows, sourceRepositories, inspectorProjectMap.size ? inspectorProjectMap : undefined, metadata), { ...options, ...(inspectorProjectMap.size && { inspectorProjectMap }) }, { ...dependencies, sourceRepositories }, workbench);
102
+ }
103
+ /** Preview each source once. Each group's approval can be resumed independently. */
104
+ export async function prepareStoredFindingsPublication(selection, options, dependencies = {}) {
105
+ const { importId } = selection;
106
+ const stored = await selectLocalExternalFindings(selection, dependencies);
107
+ const groups = [];
108
+ const excluded = [];
109
+ const bySource = Map.groupBy(stored.findings, ({ provider, sourceKey }) => JSON.stringify([provider, sourceKey]));
110
+ for (const rows of bySource.values()) {
111
+ const { provider, sourceKey, repository } = rows[0];
112
+ if (!cloudProvider(provider)) {
113
+ const reason = `The Cloud import contract does not support provider ${JSON.stringify(provider)}.`;
114
+ for (const row of rows)
115
+ excluded.push({ ...reference(row), reason });
116
+ continue;
117
+ }
118
+ const findings = rows.map(({ id, version }) => ({ id, version }));
119
+ let prepared;
120
+ try {
121
+ prepared = await prepareSource(rows, { ...options, provider, sourceKey }, dependencies, {
122
+ checkout: repository,
123
+ findings,
124
+ record: receiptRecorder(rows, dependencies),
125
+ }, importId === undefined ? undefined : stored);
126
+ }
127
+ catch (error) {
128
+ if (!(error instanceof NoPublishableFindingsError) ||
129
+ externalImportDisposition(error.selection) === "failed")
130
+ throw error;
131
+ appendExclusions(rows, error.selection);
132
+ continue;
133
+ }
134
+ const { preview } = prepared;
135
+ appendExclusions(rows, preview);
136
+ const first = groups[0]?.preview;
137
+ if (first &&
138
+ (first.accountId !== preview.accountId ||
139
+ !isDeepStrictEqual(first.destination, preview.destination)))
140
+ throw new CodexSecurityError("The Cloud account or repository changed during publication preparation.");
141
+ const reviewId = cloudReviewDigest(preview, repository, findings);
142
+ groups.push({
143
+ selection: importId === undefined
144
+ ? { repository, findings }
145
+ : { repository, importId },
146
+ preview,
147
+ reviewId,
148
+ async publish(approvedReviewId) {
149
+ if (approvedReviewId !== reviewId)
150
+ throw new CodexSecurityError("The stored findings publication has changed. Review the new preview before publishing.");
151
+ return prepared.publish();
152
+ },
153
+ });
154
+ }
155
+ return { groups, excluded };
156
+ function appendExclusions(rows, projected) {
157
+ const accepted = new Set(projected.findings.map((f) => f.source_finding_id));
158
+ const reasons = new Map(projected.excluded.map((f) => [f.source_finding_id, f.reason]));
159
+ for (const row of rows) {
160
+ if (!accepted.has(row.sourceFindingId))
161
+ excluded.push({
162
+ ...reference(row),
163
+ reason: reasons.get(row.sourceFindingId) ??
164
+ "Excluded by the Cloud publisher.",
165
+ });
166
+ }
167
+ }
168
+ }
169
+ //# sourceMappingURL=stored-findings-publication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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ACJ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC;wBAChC,kCAAkC;iBACrC,CAAC,CAAC;QACP,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport cloudSchema from \"../schemas/external-findings.schema.json\" with { type: \"json\" };\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport {\n distinctSourceRepositories,\n recordExternalFindingPublications,\n selectLocalExternalFindings,\n type LocalExternalFindingSelection,\n type LocalFindingReceipt,\n type LocalExternalImportDependencies,\n type StoredExternalFinding,\n} from \"./external-findings-local.js\";\nimport {\n cloudReviewDigest,\n prepareNormalizedPublication,\n type WorkbenchPublication,\n type ExternalPublicationDependencies,\n type ExternalPublicationPreview,\n type ExternalPublicationResult,\n type PreparedExternalPublication,\n} from \"./external-findings-publish.js\";\nimport {\n NoPublishableFindingsError,\n externalImportDisposition,\n type ExternalFindings,\n type ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { projectStoredFinding } from \"./stored-finding-projection.js\";\n\ntype Dependencies = ExternalPublicationDependencies &\n LocalExternalImportDependencies;\ntype Reference = Pick<\n StoredExternalFinding,\n \"id\" | \"version\" | \"provider\" | \"sourceKey\" | \"sourceFindingId\"\n>;\ntype Metadata = Pick<ExternalFindings, \"read\" | \"excluded\" | \"report\">;\n\nexport interface StoredFindingsPublicationGroup {\n /** Prepare this selection again to resume the same reviewed source in another process. */\n selection: LocalExternalFindingSelection;\n preview: ExternalPublicationPreview;\n reviewId: string;\n publish(reviewId: string): Promise<ExternalPublicationResult>;\n}\n\nexport interface StoredFindingsPublication {\n groups: StoredFindingsPublicationGroup[];\n excluded: (Reference & { reason: string })[];\n}\n\nfunction reference({\n id,\n version,\n provider,\n sourceKey,\n sourceFindingId,\n}: StoredExternalFinding): Reference {\n return { id, version, provider, sourceKey, sourceFindingId };\n}\n\nfunction cloudProvider(provider: string): provider is Provider {\n return cloudSchema.$defs.ImportSource.properties.provider.enum.includes(\n provider,\n );\n}\n\nfunction cloudSelection(\n rows: StoredExternalFinding[],\n sourceRepositories: readonly ExternalSourceRepository[],\n inspectorMap: ReadonlyMap<string, string> | undefined,\n metadata?: Metadata,\n): ExternalFindings {\n const selected: ExternalFindings = {\n read: metadata?.excluded.length ?? 0,\n findings: [],\n excluded: [...(metadata?.excluded ?? [])],\n report: metadata?.report,\n };\n const skipped = new Set(selected.excluded.map((item) => item.position));\n let position = 0;\n for (const row of rows) {\n const projection = projectStoredFinding(\n row,\n sourceRepositories,\n inspectorMap,\n );\n selected.findings.push(...projection.findings);\n selected.read += projection.read;\n const positions = Array.from({ length: projection.read }, () => {\n do {\n position++;\n } while (skipped.has(position));\n return position;\n });\n for (const item of projection.excluded)\n selected.excluded.push({\n ...item,\n position: positions[item.position - 1]!,\n source_finding_id: row.sourceFindingId,\n ...(projection.read > 1 && {\n reason: `Retained trace ${item.position} in ${JSON.stringify(row.sourceFindingId)} (position in stored selection order): ${item.reason}`,\n }),\n });\n }\n // A native source may account for additional input observations, and an agent\n // report may count a grouped occurrence once before its traces are expanded.\n selected.read = Math.max(selected.read, metadata?.read ?? 0);\n selected.excluded.sort((a, b) => a.position - b.position);\n return selected;\n}\n\nfunction receiptRecorder(\n rows: StoredExternalFinding[],\n dependencies: Dependencies,\n): WorkbenchPublication[\"record\"] {\n const repository = rows[0]!.repository;\n const pins = new Map(\n rows.map(({ id, version, sourceFindingId }) => [\n sourceFindingId,\n { id, version },\n ]),\n );\n return async (\n { accountId, cloudApiUrl, destination, requests, findings },\n receipts,\n privateJobId,\n ) => {\n const entries: LocalFindingReceipt[] = [];\n if (privateJobId) {\n for (const finding of findings)\n entries.push({\n ...pins.get(finding.source_finding_id)!,\n receiptId: privateJobId,\n outcome: \"private_job\",\n });\n }\n for (const [index, receipt] of receipts.entries()) {\n const batch = new Map(\n requests[index]!.items.map((item) => [\n item.client_id,\n pins.get(item.source_finding_id)!,\n ]),\n );\n for (const item of receipt.results)\n if (item.outcome !== \"error\")\n entries.push({\n ...batch.get(item.client_id)!,\n receiptId: receipt.id,\n outcome: item.outcome,\n cloudFindingId: item.canonical_finding_id ?? undefined,\n });\n }\n if (entries.length)\n await recordExternalFindingPublications(\n {\n repository,\n accountId,\n cloudApiUrl,\n destinationId: destination.id,\n entries,\n },\n dependencies,\n );\n };\n}\n\nfunction prepareSource(\n rows: StoredExternalFinding[],\n options: { repository: string; provider: Provider; sourceKey: string },\n dependencies: Dependencies,\n workbench: WorkbenchPublication,\n metadata?: Metadata,\n) {\n const references = [...(dependencies.sourceRepositories ?? [])];\n const inspectorProjectMap = new Map<string, string>();\n for (const row of rows) {\n references.push(...(row.provenance?.sourceRepositories ?? []));\n for (const [arn, url] of row.provenance?.inspectorProjectMap ?? []) {\n if (inspectorProjectMap.has(arn) && inspectorProjectMap.get(arn) !== url)\n throw new CodexSecurityError(\n \"The selected findings disagree on the Inspector project repository.\",\n );\n inspectorProjectMap.set(arn, url);\n }\n }\n const sourceRepositories = distinctSourceRepositories(references);\n return prepareNormalizedPublication(\n cloudSelection(\n rows,\n sourceRepositories,\n inspectorProjectMap.size ? inspectorProjectMap : undefined,\n metadata,\n ),\n { ...options, ...(inspectorProjectMap.size && { inspectorProjectMap }) },\n { ...dependencies, sourceRepositories },\n workbench,\n );\n}\n\n/** Preview each source once. Each group's approval can be resumed independently. */\nexport async function prepareStoredFindingsPublication(\n selection: LocalExternalFindingSelection,\n options: { repository: string },\n dependencies: Dependencies = {},\n): Promise<StoredFindingsPublication> {\n const { importId } = selection;\n const stored = await selectLocalExternalFindings(selection, dependencies);\n const groups: StoredFindingsPublicationGroup[] = [];\n const excluded: StoredFindingsPublication[\"excluded\"] = [];\n const bySource = Map.groupBy(stored.findings, ({ provider, sourceKey }) =>\n JSON.stringify([provider, sourceKey]),\n );\n for (const rows of bySource.values()) {\n const { provider, sourceKey, repository } = rows[0]!;\n if (!cloudProvider(provider)) {\n const reason = `The Cloud import contract does not support provider ${JSON.stringify(provider)}.`;\n for (const row of rows) excluded.push({ ...reference(row), reason });\n continue;\n }\n const findings = rows.map(({ id, version }) => ({ id, version }));\n let prepared: PreparedExternalPublication;\n try {\n prepared = await prepareSource(\n rows,\n { ...options, provider, sourceKey },\n dependencies,\n {\n checkout: repository,\n findings,\n record: receiptRecorder(rows, dependencies),\n },\n importId === undefined ? undefined : stored,\n );\n } catch (error) {\n if (\n !(error instanceof NoPublishableFindingsError) ||\n externalImportDisposition(error.selection) === \"failed\"\n )\n throw error;\n appendExclusions(rows, error.selection);\n continue;\n }\n const { preview } = prepared;\n appendExclusions(rows, preview);\n const first = groups[0]?.preview;\n if (\n first &&\n (first.accountId !== preview.accountId ||\n !isDeepStrictEqual(first.destination, preview.destination))\n )\n throw new CodexSecurityError(\n \"The Cloud account or repository changed during publication preparation.\",\n );\n const reviewId = cloudReviewDigest(preview, repository, findings);\n groups.push({\n selection:\n importId === undefined\n ? { repository, findings }\n : { repository, importId },\n preview,\n reviewId,\n async publish(approvedReviewId) {\n if (approvedReviewId !== reviewId)\n throw new CodexSecurityError(\n \"The stored findings publication has changed. Review the new preview before publishing.\",\n );\n return prepared.publish();\n },\n });\n }\n return { groups, excluded };\n\n function appendExclusions(\n rows: StoredExternalFinding[],\n projected: ExternalFindings,\n ) {\n const accepted = new Set(\n projected.findings.map((f) => f.source_finding_id),\n );\n const reasons = new Map(\n projected.excluded.map((f) => [f.source_finding_id, f.reason]),\n );\n for (const row of rows) {\n if (!accepted.has(row.sourceFindingId))\n excluded.push({\n ...reference(row),\n reason:\n reasons.get(row.sourceFindingId) ??\n \"Excluded by the Cloud publisher.\",\n });\n }\n }\n}\n"]}
package/dist/targets.d.ts CHANGED
@@ -33,7 +33,9 @@ export interface NormalizedTarget {
33
33
  headRef?: string;
34
34
  }
35
35
  export declare function normalizeRepository(repository: string, signal?: AbortSignal): Promise<string>;
36
- export declare function resolveRepositoryPath(repository: string): string;
36
+ export declare function resolveRepositoryPath(repository: string, directory?: string): string;
37
+ /** Preserve filesystem resolution of symlink/.. paths on POSIX. */
38
+ export declare function resolveTargetPath(value: string, directory?: string): string;
37
39
  type ReadWorktreeGit = (repository: string, args: readonly string[], signal?: AbortSignal) => Promise<string>;
38
40
  export declare function enclosingGitWorktreeRoot(repository: string, signal?: AbortSignal, options?: {
39
41
  requireIfPresent?: boolean;
@@ -58,11 +60,14 @@ export declare function repositoryRevision(repository: string, signal?: AbortSig
58
60
  export declare function gitHistoryIdentity(repository: string, git: TrustedExecutable, signal?: AbortSignal): Promise<{
59
61
  commonDirectory: string | null;
60
62
  origin: string | null;
63
+ relativePath: string | null;
61
64
  }>;
62
65
  /** Resolve Git and its sanitized executable search path for a single selected checkout. */
63
66
  export declare function trustedGitCommand(repository: string, preserveConfiguration: boolean, sourceEnvironment: NodeJS.ProcessEnv, protectedRoots: string | readonly string[], signal?: AbortSignal): Promise<TrustedExecutable>;
64
67
  export declare function gitOutput(repository: string, args: readonly string[], signal?: AbortSignal, environment?: NodeJS.ProcessEnv, workingDirectory?: string, encoding?: "utf8", protectedRoots?: string | readonly string[], sourceEnvironment?: NodeJS.ProcessEnv): Promise<string>;
65
68
  export declare function gitOutput(repository: string, args: readonly string[], signal: AbortSignal | undefined, environment: NodeJS.ProcessEnv | undefined, workingDirectory: string | undefined, encoding: "buffer", protectedRoots?: string | readonly string[], sourceEnvironment?: NodeJS.ProcessEnv): Promise<Buffer>;
69
+ /** Bound repository-supplied document links to the selected checkout or directory. */
70
+ export declare function documentSourceRoot(repository: string, signal?: AbortSignal): Promise<string>;
66
71
  export declare function gitMarkerRoot(repository: string, signal: AbortSignal | undefined, search: "nearest" | "outermost"): Promise<string | null>;
67
72
  /** Protect both the stored path's checkout and its resolved destination. */
68
73
  export declare function gitProtectionRoots(repository: string, signal?: AbortSignal): Promise<string[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAiBA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,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CD,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
package/dist/targets.js CHANGED
@@ -2,8 +2,8 @@ import { isNonEmptyString } from "./value.js";
2
2
  import { isUtf8 } from "node:buffer";
3
3
  import { execFile as execFileCallback } from "node:child_process";
4
4
  import { realpathSync } from "node:fs";
5
- import { lstat, readFile, realpath, stat } from "node:fs/promises";
6
- import { homedir } from "node:os";
5
+ import { copyFile, lstat, mkdtemp, readFile, realpath, rm, stat, } from "node:fs/promises";
6
+ import { homedir, tmpdir } from "node:os";
7
7
  import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
8
8
  import { promisify } from "node:util";
9
9
  import { InvalidTargetError, abortReason, errorMessage } from "./errors.js";
@@ -86,9 +86,22 @@ export async function normalizeRepository(repository, signal) {
86
86
  requirePortableWindowsRepositoryPath(canonical);
87
87
  return canonical;
88
88
  }
89
- export function resolveRepositoryPath(repository) {
89
+ export function resolveRepositoryPath(repository, directory = process.cwd()) {
90
90
  requireUtf8Path("Repository path", repository);
91
- return resolve(expandHome(repository));
91
+ return resolveTargetPath(expandHome(repository), directory);
92
+ }
93
+ /** Preserve filesystem resolution of symlink/.. paths on POSIX. */
94
+ export function resolveTargetPath(value, directory = process.cwd()) {
95
+ if (sep === "\\")
96
+ return resolve(directory, value);
97
+ const base = isAbsolute(directory)
98
+ ? directory
99
+ : `${process.cwd()}/${directory}`;
100
+ const absolute = isAbsolute(value) ? value : `${base}/${value}`;
101
+ const parts = absolute
102
+ .split("/")
103
+ .filter((part) => part !== "" && part !== ".");
104
+ return `/${parts.join("/")}`;
92
105
  }
93
106
  function requireUtf8Path(label, value, resolved) {
94
107
  if (resolved === undefined ? !value.isWellFormed() : !isUtf8(resolved)) {
@@ -392,9 +405,7 @@ export async function normalizeTarget(repository, target, signal) {
392
405
  throw new InvalidTargetError("Path scan targets must not contain an empty path.");
393
406
  }
394
407
  requireUtf8Path("Path target", value);
395
- const candidate = isAbsolute(expandHome(value))
396
- ? resolve(expandHome(value))
397
- : resolve(root, expandHome(value));
408
+ const candidate = resolveTargetPath(expandHome(value), root);
398
409
  let canonical;
399
410
  try {
400
411
  // Some runtimes cannot canonicalize special files to filesystem paths.
@@ -444,10 +455,40 @@ export async function validateCommittedDiffCheckout(repository, target, signal)
444
455
  if (status.length !== 0) {
445
456
  throw new InvalidTargetError("Committed-diff scans require a clean repository checkout. Commit, stash, or remove local changes and retry. Use `git stash --include-untracked` to stash untracked files.");
446
457
  }
447
- const tracked = await gitOutput(repository, ["ls-files", "-t", "-z"], signal);
448
- if (tracked.split("\0").some((entry) => entry.startsWith("S "))) {
458
+ const tracked = (await gitOutput(repository, ["ls-files", "-v", "-z"], signal)).split("\0");
459
+ if (tracked.some((entry) => /^[Ss] /u.test(entry))) {
449
460
  throw new InvalidTargetError("Committed-diff scans require a full repository checkout. Sparse checkouts are not supported; materialize skipped tracked files and retry.");
450
461
  }
462
+ if (tracked.some((entry) => entry.startsWith("h "))) {
463
+ await verifyAssumedUnchangedFiles(repository, signal);
464
+ }
465
+ }
466
+ async function verifyAssumedUnchangedFiles(repository, signal) {
467
+ const index = await gitOutput(repository, ["rev-parse", "--path-format=absolute", "--git-path", "index"], signal);
468
+ // Git changes to the repository before resolving GIT_INDEX_FILE, even when TMPDIR is relative.
469
+ const directory = await mkdtemp(join(await realpath(tmpdir()), "codex-security-git-index-"));
470
+ const copy = join(directory, "index");
471
+ try {
472
+ // Git refreshes stat data and flags. Keep that write and any hooks out of the checkout.
473
+ await copyFile(index, copy);
474
+ await gitOutput(repository, [
475
+ "-c",
476
+ `core.hooksPath=${directory}`,
477
+ "-c",
478
+ "core.splitIndex=false",
479
+ "update-index",
480
+ "--really-refresh",
481
+ ], signal, { GIT_INDEX_FILE: copy });
482
+ }
483
+ catch (error) {
484
+ if (error instanceof Error && "code" in error && error.code === 1) {
485
+ throw new InvalidTargetError("Committed-diff scans require a clean repository checkout. A tracked file marked assume-unchanged has changed on disk.", { cause: error });
486
+ }
487
+ throw error;
488
+ }
489
+ finally {
490
+ await rm(directory, { recursive: true, force: true });
491
+ }
451
492
  }
452
493
  export function validateMode(target, mode) {
453
494
  if (mode !== "standard" && mode !== "deep") {
@@ -494,7 +535,7 @@ async function resolveGitRef(repository, ref, signal) {
494
535
  }
495
536
  /** Read-only identity for matching saved history with an already selected host Git. */
496
537
  export async function gitHistoryIdentity(repository, git, signal) {
497
- const read = async (args) => {
538
+ const read = async (args, allowEmpty = false) => {
498
539
  try {
499
540
  const { stdout } = await execFile(git.executable, ["-c", "core.fsmonitor=false", "-C", repository, ...args], {
500
541
  encoding: "utf8",
@@ -502,19 +543,20 @@ export async function gitHistoryIdentity(repository, git, signal) {
502
543
  env: isolatedGitEnvironment(true, git.environment),
503
544
  maxBuffer: Infinity,
504
545
  });
505
- return (stdout.replace(process.platform === "win32" ? /\r?\n$/u : /\n$/u, "") ||
506
- null);
546
+ const value = stdout.replace(process.platform === "win32" ? /\r?\n$/u : /\n$/u, "");
547
+ return value || (allowEmpty ? "" : null);
507
548
  }
508
549
  catch {
509
550
  throwIfAborted(signal);
510
551
  return null;
511
552
  }
512
553
  };
513
- const [commonDirectory, origin] = await Promise.all([
554
+ const [commonDirectory, origin, relativePath] = await Promise.all([
514
555
  read(["rev-parse", "--path-format=absolute", "--git-common-dir"]),
515
556
  read(["remote", "get-url", "origin"]),
557
+ read(["rev-parse", "--show-prefix"], true),
516
558
  ]);
517
- return { commonDirectory, origin };
559
+ return { commonDirectory, origin, relativePath };
518
560
  }
519
561
  /** Resolve Git and its sanitized executable search path for a single selected checkout. */
520
562
  export async function trustedGitCommand(repository, preserveConfiguration, sourceEnvironment, protectedRoots, signal) {
@@ -562,8 +604,20 @@ export async function gitOutput(repository, args, signal, environment = {}, work
562
604
  const remoteUrl = args[0] === "remote" && args[1] === "get-url";
563
605
  return stdout.replace(process.platform === "win32" && !remoteUrl ? /\r?\n$/u : /\n$/u, "");
564
606
  }
607
+ function unavailableGitMarkerPath(error, search) {
608
+ const { code } = error;
609
+ return (code === "ENOENT" ||
610
+ code === "ENOTDIR" ||
611
+ (search === "outermost" &&
612
+ ["EACCES", "EPERM", "ELOOP", "ENAMETOOLONG"].includes(code ?? "")));
613
+ }
614
+ /** Bound repository-supplied document links to the selected checkout or directory. */
615
+ export async function documentSourceRoot(repository, signal) {
616
+ return ((await gitMarkerRoot(repository, signal, "nearest")) ??
617
+ (await realpath(repository)));
618
+ }
565
619
  export async function gitMarkerRoot(repository, signal, search) {
566
- let candidate = resolve(repository);
620
+ let candidate = resolveTargetPath(repository);
567
621
  let current;
568
622
  while (true) {
569
623
  try {
@@ -576,9 +630,7 @@ export async function gitMarkerRoot(repository, signal, search) {
576
630
  catch (error) {
577
631
  // Stale or inaccessible descendants still belong to their accessible checkout ancestors.
578
632
  throwIfAborted(signal);
579
- const code = error.code;
580
- if (search !== "outermost" ||
581
- !["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(code ?? ""))
633
+ if (search !== "outermost" || !unavailableGitMarkerPath(error, search))
582
634
  throw error;
583
635
  const parent = dirname(candidate);
584
636
  if (parent === candidate)
@@ -608,10 +660,7 @@ async function walkGitMarkers(current, signal, search) {
608
660
  }
609
661
  catch (error) {
610
662
  throwIfAborted(signal);
611
- const code = error.code;
612
- if (code !== "ENOENT" &&
613
- code !== "ENOTDIR" &&
614
- (search !== "outermost" || (code !== "EACCES" && code !== "EPERM")))
663
+ if (!unavailableGitMarkerPath(error, search))
615
664
  throw error;
616
665
  }
617
666
  const parent = dirname(current);
@@ -662,7 +711,11 @@ function expandHome(value) {
662
711
  }
663
712
  if (value.startsWith("~/") || value.startsWith("~\\")) {
664
713
  const separators = sep === "/" && value.startsWith("~/") ? /^\/+/ : /^[/\\]+/;
665
- return resolve(homedir(), value.slice(2).replace(separators, ""));
714
+ const suffix = value.slice(2).replace(separators, "");
715
+ const home = homedir();
716
+ if (process.platform === "win32")
717
+ return resolve(home, suffix);
718
+ return home === "" ? resolveTargetPath(suffix) : `${home}${sep}${suffix}`;
666
719
  }
667
720
  return value;
668
721
  }