@openai/codex-security 0.8.2 → 0.8.3

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 (375) hide show
  1. package/README.md +43 -61
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  15. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  16. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  18. package/_bundled_plugin/references/artifact-storage.md +1 -1
  19. package/_bundled_plugin/references/core-scan.md +14 -5
  20. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  21. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  22. package/_bundled_plugin/references/threat-model.md +1 -0
  23. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  24. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  25. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  26. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  27. package/_bundled_plugin/scripts/report_projection.py +87 -136
  28. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  30. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  31. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  32. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  33. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  34. package/_bundled_plugin/scripts/workbench_db.py +186 -360
  35. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  36. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  37. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  38. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  39. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  40. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  41. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  42. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  43. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  44. package/_bundled_plugin/scripts/workbench_target.py +213 -20
  45. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  46. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  47. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  48. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  49. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  50. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  51. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  52. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  53. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  54. package/_bundled_plugin/skills/publish-findings/SKILL.md +64 -35
  55. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  56. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +14 -8
  57. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  58. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  59. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  60. package/dist/api.d.ts +6 -1
  61. package/dist/api.d.ts.map +1 -1
  62. package/dist/api.js +411 -160
  63. package/dist/api.js.map +1 -1
  64. package/dist/auth.js +6 -1
  65. package/dist/auth.js.map +1 -1
  66. package/dist/blackduck-findings.d.ts +8 -0
  67. package/dist/blackduck-findings.d.ts.map +1 -0
  68. package/dist/blackduck-findings.js +305 -0
  69. package/dist/blackduck-findings.js.map +1 -0
  70. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  71. package/dist/bulk-scan-discovery.js +51 -36
  72. package/dist/bulk-scan-discovery.js.map +1 -1
  73. package/dist/classify-severity-records.d.ts +5 -0
  74. package/dist/classify-severity-records.d.ts.map +1 -1
  75. package/dist/classify-severity-records.js +6 -8
  76. package/dist/classify-severity-records.js.map +1 -1
  77. package/dist/classify-severity.d.ts +4 -1
  78. package/dist/classify-severity.d.ts.map +1 -1
  79. package/dist/classify-severity.js +28 -9
  80. package/dist/classify-severity.js.map +1 -1
  81. package/dist/cli.d.ts +3 -0
  82. package/dist/cli.d.ts.map +1 -1
  83. package/dist/cli.js +608 -258
  84. package/dist/cli.js.map +1 -1
  85. package/dist/codex-prompt.d.ts +2 -0
  86. package/dist/codex-prompt.d.ts.map +1 -1
  87. package/dist/codex-prompt.js +6 -0
  88. package/dist/codex-prompt.js.map +1 -1
  89. package/dist/component-scan.d.ts.map +1 -1
  90. package/dist/component-scan.js +6 -5
  91. package/dist/component-scan.js.map +1 -1
  92. package/dist/config.d.ts +2 -1
  93. package/dist/config.d.ts.map +1 -1
  94. package/dist/config.js +162 -40
  95. package/dist/config.js.map +1 -1
  96. package/dist/continuum-findings.d.ts +7 -0
  97. package/dist/continuum-findings.d.ts.map +1 -0
  98. package/dist/continuum-findings.js +157 -0
  99. package/dist/continuum-findings.js.map +1 -0
  100. package/dist/contract-values.d.ts +28 -0
  101. package/dist/contract-values.d.ts.map +1 -0
  102. package/dist/contract-values.js +75 -0
  103. package/dist/contract-values.js.map +1 -0
  104. package/dist/contract.d.ts +2 -20
  105. package/dist/contract.d.ts.map +1 -1
  106. package/dist/contract.js +58 -669
  107. package/dist/contract.js.map +1 -1
  108. package/dist/cost-model.d.ts.map +1 -1
  109. package/dist/cost-model.js +1 -4
  110. package/dist/cost-model.js.map +1 -1
  111. package/dist/cost.d.ts +19 -1
  112. package/dist/cost.d.ts.map +1 -1
  113. package/dist/cost.js +2120 -39
  114. package/dist/cost.js.map +1 -1
  115. package/dist/custom-validation-prompt.d.ts +1 -1
  116. package/dist/custom-validation-prompt.d.ts.map +1 -1
  117. package/dist/custom-validation-prompt.js +5 -0
  118. package/dist/custom-validation-prompt.js.map +1 -1
  119. package/dist/custom-validation.d.ts +2 -0
  120. package/dist/custom-validation.d.ts.map +1 -1
  121. package/dist/custom-validation.js +4 -0
  122. package/dist/custom-validation.js.map +1 -1
  123. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  124. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  125. package/dist/deduplication/deduplication-prompts.js +2 -2
  126. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  127. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  128. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  129. package/dist/deduplication/deduplication-reviewer.js +11 -4
  130. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  131. package/dist/deduplication/deduplication.js.map +1 -1
  132. package/dist/deduplication/finding-schema.d.ts +19 -1
  133. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  134. package/dist/deduplication/finding-schema.js +25 -0
  135. package/dist/deduplication/finding-schema.js.map +1 -1
  136. package/dist/deduplication/local.d.ts.map +1 -1
  137. package/dist/deduplication/local.js +3 -8
  138. package/dist/deduplication/local.js.map +1 -1
  139. package/dist/deduplication/records.d.ts +8 -2
  140. package/dist/deduplication/records.d.ts.map +1 -1
  141. package/dist/deduplication/records.js +36 -8
  142. package/dist/deduplication/records.js.map +1 -1
  143. package/dist/deep-scan.d.ts +11 -0
  144. package/dist/deep-scan.d.ts.map +1 -1
  145. package/dist/deep-scan.js +235 -4
  146. package/dist/deep-scan.js.map +1 -1
  147. package/dist/default-severity-rubric.d.ts +1 -2
  148. package/dist/default-severity-rubric.d.ts.map +1 -1
  149. package/dist/default-severity-rubric.js +2 -66
  150. package/dist/default-severity-rubric.js.map +1 -1
  151. package/dist/endor-findings.d.ts.map +1 -1
  152. package/dist/endor-findings.js +7 -37
  153. package/dist/endor-findings.js.map +1 -1
  154. package/dist/errors.js +1 -1
  155. package/dist/errors.js.map +1 -1
  156. package/dist/external-findings-import.d.ts.map +1 -1
  157. package/dist/external-findings-import.js +5 -11
  158. package/dist/external-findings-import.js.map +1 -1
  159. package/dist/external-findings-local.d.ts +9 -0
  160. package/dist/external-findings-local.d.ts.map +1 -1
  161. package/dist/external-findings-local.js +325 -179
  162. package/dist/external-findings-local.js.map +1 -1
  163. package/dist/external-findings-publish.d.ts +12 -0
  164. package/dist/external-findings-publish.d.ts.map +1 -1
  165. package/dist/external-findings-publish.js +1202 -214
  166. package/dist/external-findings-publish.js.map +1 -1
  167. package/dist/external-findings-read.d.ts +8 -0
  168. package/dist/external-findings-read.d.ts.map +1 -1
  169. package/dist/external-findings-read.js +65 -54
  170. package/dist/external-findings-read.js.map +1 -1
  171. package/dist/external-findings.d.ts +2 -0
  172. package/dist/external-findings.d.ts.map +1 -1
  173. package/dist/external-findings.js +111 -0
  174. package/dist/external-findings.js.map +1 -1
  175. package/dist/external-import-contract.d.ts +29 -1
  176. package/dist/external-import-contract.d.ts.map +1 -1
  177. package/dist/external-import-contract.js +314 -44
  178. package/dist/external-import-contract.js.map +1 -1
  179. package/dist/external-import-models.d.ts +1 -1
  180. package/dist/external-import-models.d.ts.map +1 -1
  181. package/dist/external-import-models.js.map +1 -1
  182. package/dist/finding-normalization.d.ts +1 -1
  183. package/dist/finding-normalization.d.ts.map +1 -1
  184. package/dist/finding-normalization.js +46 -11
  185. package/dist/finding-normalization.js.map +1 -1
  186. package/dist/finding-retrieval.d.ts +3 -3
  187. package/dist/finding-retrieval.d.ts.map +1 -1
  188. package/dist/finding-retrieval.js.map +1 -1
  189. package/dist/finding-workflow.d.ts +6 -1
  190. package/dist/finding-workflow.d.ts.map +1 -1
  191. package/dist/finding-workflow.js +2 -2
  192. package/dist/finding-workflow.js.map +1 -1
  193. package/dist/git-remote.d.ts +4 -0
  194. package/dist/git-remote.d.ts.map +1 -1
  195. package/dist/git-remote.js +20 -0
  196. package/dist/git-remote.js.map +1 -1
  197. package/dist/github-advisories.d.ts +3 -12
  198. package/dist/github-advisories.d.ts.map +1 -1
  199. package/dist/github-advisories.js +9 -29
  200. package/dist/github-advisories.js.map +1 -1
  201. package/dist/github-dependabot-findings.d.ts.map +1 -1
  202. package/dist/github-dependabot-findings.js +7 -16
  203. package/dist/github-dependabot-findings.js.map +1 -1
  204. package/dist/github-findings.d.ts.map +1 -1
  205. package/dist/github-findings.js +344 -56
  206. package/dist/github-findings.js.map +1 -1
  207. package/dist/github.d.ts +17 -7
  208. package/dist/github.d.ts.map +1 -1
  209. package/dist/github.js +43 -30
  210. package/dist/github.js.map +1 -1
  211. package/dist/host-protocol.d.ts +2 -2
  212. package/dist/host-protocol.d.ts.map +1 -1
  213. package/dist/host-protocol.js.map +1 -1
  214. package/dist/host-records-protocol.d.ts +10 -11
  215. package/dist/host-records-protocol.d.ts.map +1 -1
  216. package/dist/host-records-protocol.js +69 -9
  217. package/dist/host-records-protocol.js.map +1 -1
  218. package/dist/hosted-scan.d.ts +15 -0
  219. package/dist/hosted-scan.d.ts.map +1 -1
  220. package/dist/hosted-scan.js +55 -33
  221. package/dist/hosted-scan.js.map +1 -1
  222. package/dist/index.d.ts +7 -0
  223. package/dist/index.d.ts.map +1 -1
  224. package/dist/index.js +6 -0
  225. package/dist/index.js.map +1 -1
  226. package/dist/inspector-findings.d.ts.map +1 -1
  227. package/dist/inspector-findings.js +13 -18
  228. package/dist/inspector-findings.js.map +1 -1
  229. package/dist/knowledge-base.js +18 -5
  230. package/dist/knowledge-base.js.map +1 -1
  231. package/dist/local-git-metadata.d.ts +5 -0
  232. package/dist/local-git-metadata.d.ts.map +1 -0
  233. package/dist/local-git-metadata.js +131 -0
  234. package/dist/local-git-metadata.js.map +1 -0
  235. package/dist/multiscan.d.ts.map +1 -1
  236. package/dist/multiscan.js +22 -12
  237. package/dist/multiscan.js.map +1 -1
  238. package/dist/opengrep-findings.d.ts.map +1 -1
  239. package/dist/opengrep-findings.js +34 -20
  240. package/dist/opengrep-findings.js.map +1 -1
  241. package/dist/patch-tui.d.ts.map +1 -1
  242. package/dist/patch-tui.js +90 -35
  243. package/dist/patch-tui.js.map +1 -1
  244. package/dist/private-finding-import.d.ts +246 -0
  245. package/dist/private-finding-import.d.ts.map +1 -0
  246. package/dist/private-finding-import.js +387 -0
  247. package/dist/private-finding-import.js.map +1 -0
  248. package/dist/project-config.d.ts.map +1 -1
  249. package/dist/project-config.js +2 -2
  250. package/dist/project-config.js.map +1 -1
  251. package/dist/provider-profile.d.ts +10 -2
  252. package/dist/provider-profile.d.ts.map +1 -1
  253. package/dist/provider-profile.js +72 -10
  254. package/dist/provider-profile.js.map +1 -1
  255. package/dist/publication.js +7 -1
  256. package/dist/publication.js.map +1 -1
  257. package/dist/reader-selection.d.ts +13 -0
  258. package/dist/reader-selection.d.ts.map +1 -0
  259. package/dist/reader-selection.js +81 -0
  260. package/dist/reader-selection.js.map +1 -0
  261. package/dist/record.d.ts +6 -1
  262. package/dist/record.d.ts.map +1 -1
  263. package/dist/record.js +53 -2
  264. package/dist/record.js.map +1 -1
  265. package/dist/remediation.d.ts +5 -0
  266. package/dist/remediation.d.ts.map +1 -1
  267. package/dist/remediation.js +30 -0
  268. package/dist/remediation.js.map +1 -1
  269. package/dist/result.d.ts +2 -0
  270. package/dist/result.d.ts.map +1 -1
  271. package/dist/result.js +3 -1
  272. package/dist/result.js.map +1 -1
  273. package/dist/runtime.d.ts +2 -1
  274. package/dist/runtime.d.ts.map +1 -1
  275. package/dist/runtime.js +95 -52
  276. package/dist/runtime.js.map +1 -1
  277. package/dist/scan-activity.js +40 -17
  278. package/dist/scan-activity.js.map +1 -1
  279. package/dist/scan-comparison.d.ts +1 -1
  280. package/dist/scan-comparison.d.ts.map +1 -1
  281. package/dist/scan-comparison.js +11 -13
  282. package/dist/scan-comparison.js.map +1 -1
  283. package/dist/scan-dashboard.d.ts +1 -0
  284. package/dist/scan-dashboard.d.ts.map +1 -1
  285. package/dist/scan-dashboard.js +16 -37
  286. package/dist/scan-dashboard.js.map +1 -1
  287. package/dist/scan-executor.d.ts +2 -0
  288. package/dist/scan-executor.d.ts.map +1 -1
  289. package/dist/scan-executor.js.map +1 -1
  290. package/dist/scan-history-renderer.d.ts.map +1 -1
  291. package/dist/scan-history-renderer.js +22 -9
  292. package/dist/scan-history-renderer.js.map +1 -1
  293. package/dist/scan-logs.d.ts.map +1 -1
  294. package/dist/scan-logs.js +5 -5
  295. package/dist/scan-logs.js.map +1 -1
  296. package/dist/scanner-import.d.ts +46 -6
  297. package/dist/scanner-import.d.ts.map +1 -1
  298. package/dist/scanner-import.js +208 -42
  299. package/dist/scanner-import.js.map +1 -1
  300. package/dist/scanner-repository-url.d.ts +14 -0
  301. package/dist/scanner-repository-url.d.ts.map +1 -0
  302. package/dist/scanner-repository-url.js +67 -0
  303. package/dist/scanner-repository-url.js.map +1 -0
  304. package/dist/semgrep-findings.d.ts.map +1 -1
  305. package/dist/semgrep-findings.js +20 -48
  306. package/dist/semgrep-findings.js.map +1 -1
  307. package/dist/semgrep-platform-findings.d.ts +12 -0
  308. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  309. package/dist/semgrep-platform-findings.js +198 -0
  310. package/dist/semgrep-platform-findings.js.map +1 -0
  311. package/dist/severity-rubric.d.ts +20 -0
  312. package/dist/severity-rubric.d.ts.map +1 -0
  313. package/dist/severity-rubric.js +73 -0
  314. package/dist/severity-rubric.js.map +1 -0
  315. package/dist/severity-store.js +15 -5
  316. package/dist/severity-store.js.map +1 -1
  317. package/dist/snyk-findings.d.ts.map +1 -1
  318. package/dist/snyk-findings.js +21 -20
  319. package/dist/snyk-findings.js.map +1 -1
  320. package/dist/sonar-collector.d.ts +16 -0
  321. package/dist/sonar-collector.d.ts.map +1 -0
  322. package/dist/sonar-collector.js +383 -0
  323. package/dist/sonar-collector.js.map +1 -0
  324. package/dist/sonar-findings.d.ts +49 -0
  325. package/dist/sonar-findings.d.ts.map +1 -0
  326. package/dist/sonar-findings.js +288 -0
  327. package/dist/sonar-findings.js.map +1 -0
  328. package/dist/sonar-import.d.ts +111 -0
  329. package/dist/sonar-import.d.ts.map +1 -0
  330. package/dist/sonar-import.js +279 -0
  331. package/dist/sonar-import.js.map +1 -0
  332. package/dist/suggest-owners.d.ts.map +1 -1
  333. package/dist/suggest-owners.js +2 -1
  334. package/dist/suggest-owners.js.map +1 -1
  335. package/dist/targets.d.ts +3 -0
  336. package/dist/targets.d.ts.map +1 -1
  337. package/dist/targets.js +18 -12
  338. package/dist/targets.js.map +1 -1
  339. package/dist/terminal-columns.d.ts +4 -0
  340. package/dist/terminal-columns.d.ts.map +1 -0
  341. package/dist/terminal-columns.js +19 -0
  342. package/dist/terminal-columns.js.map +1 -0
  343. package/dist/validation-records.d.ts +0 -3
  344. package/dist/validation-records.d.ts.map +1 -1
  345. package/dist/validation-records.js +0 -16
  346. package/dist/validation-records.js.map +1 -1
  347. package/dist/veracode-findings.d.ts +7 -0
  348. package/dist/veracode-findings.d.ts.map +1 -0
  349. package/dist/veracode-findings.js +371 -0
  350. package/dist/veracode-findings.js.map +1 -0
  351. package/dist/windows-path.d.ts.map +1 -1
  352. package/dist/windows-path.js +1 -0
  353. package/dist/windows-path.js.map +1 -1
  354. package/dist/wiz-csv.d.ts +2 -2
  355. package/dist/wiz-csv.d.ts.map +1 -1
  356. package/dist/wiz-csv.js +1 -3
  357. package/dist/wiz-csv.js.map +1 -1
  358. package/dist/wiz-findings.d.ts +10 -2
  359. package/dist/wiz-findings.d.ts.map +1 -1
  360. package/dist/wiz-findings.js +88 -49
  361. package/dist/wiz-findings.js.map +1 -1
  362. package/docs/classify-severity-records.md +1 -1
  363. package/docs/cli.md +310 -477
  364. package/docs/dedupe-records.md +10 -0
  365. package/docs/findings-service.md +21 -8
  366. package/docs/hosted-scans.md +16 -1
  367. package/package.json +8 -9
  368. package/schemas/external-findings.schema.json +12 -1
  369. package/schemas/hosted-scan-v2.fixture.json +16 -1
  370. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  371. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  372. package/dist/deduplication/records-protocol.d.ts +0 -4
  373. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  374. package/dist/deduplication/records-protocol.js +0 -49
  375. package/dist/deduplication/records-protocol.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-finding-import.js","sourceRoot":"","sources":["../src/private-finding-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC;IAC3B,gBAAgB;IAChB,wBAAwB;IACxB,2BAA2B;CAC5B,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,CAAC,M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C;oBACZ,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACrB,CAAC;gBACD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAClD,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnD,MAAM,KAAK,CACT,IAAI,CAAC,GAAG,CACN,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACtC,GAAG,CAAC,kBAAkB,IAAI,CAAC,CAC5B,GAAG,IAAI,EACR,SAAS,EACT,EAAE,MAAM,EAAE,CACX,CAAC;gBACF,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { hash } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { open } from \"node:fs/promises\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { z } from \"zod\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport type { ImportSource } from \"./external-import-models.js\";\nimport { canonicalJson, isRecord } from \"./record.js\";\n\nconst structuredFormat = \"security.findings.v1\";\nconst privateFormat = z.enum([\n structuredFormat,\n \"endor.findings_json.v1\",\n \"wiz.vulnerability_json.v1\",\n]);\nexport type PrivateImportFormat = z.infer<typeof privateFormat>;\nconst fileId = z.string().regex(/^aifile_[0-9a-f]{32}$/u);\nconst contextSchema = z.object({\n object: z.literal(\"security.finding_import_context\"),\n context_version: z.string().min(1),\n can_upload: z.boolean(),\n can_create_import_jobs: z.boolean(),\n can_read: z.boolean(),\n formats: z.array(z.string()),\n limits: z.object({\n max_direct_file_bytes: z.int().positive(),\n max_record_bytes: z.int().positive(),\n }),\n});\nconst fileSchema = z.object({\n id: fileId,\n object: z.literal(\"security.finding_import_file\"),\n purpose: z.literal(\"report\"),\n sha256: z.string(),\n bytes: z.int().positive(),\n});\nconst jobSchema = z.object({\n object: z.literal(\"security.finding_import_job\"),\n id: z.string().regex(/^import_[0-9a-f]{32}$/u),\n request_id: z.uuid(),\n source: z.object({ provider: z.string(), source_key: z.string() }),\n input: z.object({\n type: z.literal(\"file\"),\n file_id: fileId,\n format: privateFormat,\n }),\n default_targets: z.array(\n z.object({\n type: z.literal(\"repository\"),\n repo_id: z.string(),\n repo_connector_id: z.string(),\n }),\n ),\n status: z.enum([\n \"queued\",\n \"in_progress\",\n \"cancelling\",\n \"completed\",\n \"failed\",\n \"cancelled\",\n ]),\n counts: z.object({\n total: z.int().nonnegative().nullable(),\n discovered: z.int().nonnegative(),\n created: z.int().nonnegative(),\n updated: z.int().nonnegative(),\n unchanged: z.int().nonnegative(),\n error: z.int().nonnegative(),\n unprocessed: z.int().nonnegative(),\n }),\n poll_after_seconds: z.int().positive().nullable(),\n error: z.object({ message: z.string() }).nullable(),\n});\n\nexport type PrivateImportContext = z.infer<typeof contextSchema>;\nexport type PrivateImportJob = z.infer<typeof jobSchema>;\n\nexport function privateReport(\n findings: ExternalFinding[],\n limits: PrivateImportContext[\"limits\"],\n) {\n if (findings.length > 10_000)\n throw new CodexSecurityError(\n \"A structured report accepts up to 10,000 findings. Split this selection.\",\n );\n const records = findings.map(({ source_finding_id, evidence }) => {\n if (source_finding_id !== source_finding_id.trim())\n throw new CodexSecurityError(\n \"A private source finding ID cannot have leading or trailing whitespace.\",\n );\n const record = {\n source_finding_id,\n evidence: {\n ...evidence,\n severity: evidence.severity === \"unknown\" ? null : evidence.severity,\n locations: evidence.locations?.map(({ path, line }, index) => ({\n path,\n start_line: line,\n ...(index === 0 && evidence.details?.code?.end_line != null\n ? { end_line: evidence.details.code.end_line }\n : {}),\n })),\n },\n };\n if (Buffer.byteLength(canonicalJson(record)) > limits.max_record_bytes)\n throw new CodexSecurityError(\n `Finding ${JSON.stringify(source_finding_id)} exceeds the private import record limit.`,\n );\n return record;\n });\n const bytes = canonicalJson({ format: structuredFormat, findings: records });\n if (Buffer.byteLength(bytes) > limits.max_direct_file_bytes)\n throw new CodexSecurityError(\n \"The selected report exceeds the Cloud direct-upload limit. Split this selection.\",\n );\n return {\n format: structuredFormat as PrivateImportFormat,\n bytes,\n digest: hash(\"sha256\", bytes),\n };\n}\n\nconst endorExport = z.strictObject({\n list: z.strictObject({\n objects: z.array(z.unknown()),\n response: z\n .strictObject({\n next_page_id: z.literal([\"\", null]).optional(),\n next_page_token: z.literal([\"\", \"0\", 0, null]).optional(),\n total_size: z.union([z.string(), z.number()]).optional(),\n })\n .optional(),\n }),\n});\nconst wizExport = z.strictObject({\n vulnerabilityFindings: z.strictObject({\n nodes: z.array(z.unknown()),\n pageInfo: z\n .strictObject({\n hasNextPage: z.literal(false).optional(),\n hasPreviousPage: z.literal(false).optional(),\n startCursor: z.string().nullable().optional(),\n endCursor: z.string().nullable().optional(),\n })\n .optional(),\n }),\n});\n\n// Only complete, known envelopes can be sent byte for byte. Unreviewed sibling\n// collections, metadata or partial pages keep the normalized projection.\nfunction nativeRecords(\n payload: unknown,\n provider: string,\n): unknown[] | undefined {\n if (provider === \"wiz\" && Array.isArray(payload)) return payload;\n if (!isRecord(payload)) return;\n if (provider === \"endor\") {\n if (isRecord(payload[\"spec\"])) return [payload];\n return endorExport.safeParse(payload).data?.list.objects;\n }\n if (typeof payload[\"id\"] === \"string\") return [payload];\n const data =\n Object.keys(payload).length === 1 && \"data\" in payload\n ? payload[\"data\"]\n : payload;\n return wizExport.safeParse(data).data?.vulnerabilityFindings.nodes;\n}\n\nexport async function selectPrivateReport(\n selection: ExternalFindings,\n provider: string,\n path: string | undefined,\n context: PrivateImportContext,\n saved: string | undefined,\n): Promise<ReturnType<typeof privateReport>> {\n const checkpoint =\n saved === undefined ? undefined : checkpointSchema.parse(JSON.parse(saved));\n const originalFormat =\n checkpoint?.contextVersion === context.context_version\n ? checkpoint.format\n : undefined;\n const format =\n provider === \"endor\"\n ? \"endor.findings_json.v1\"\n : provider === \"wiz\"\n ? \"wiz.vulnerability_json.v1\"\n : undefined;\n if (\n format &&\n path &&\n selection.excluded.length === 0 &&\n selection.read <= 10_000 &&\n selection.findings.length === selection.read &&\n (originalFormat\n ? originalFormat === format\n : context.formats.includes(format))\n ) {\n const handle = await open(\n path,\n constants.O_RDONLY | (constants.O_NONBLOCK ?? 0),\n );\n let bytes: string | undefined;\n try {\n const info = await handle.stat();\n if (\n info.isFile() &&\n info.size > 0 &&\n info.size <= context.limits.max_direct_file_bytes\n ) {\n const buffer = Buffer.alloc(info.size + 1);\n let count = 0;\n while (count < buffer.length) {\n const { bytesRead } = await handle.read(\n buffer,\n count,\n buffer.length - count,\n );\n if (bytesRead === 0) break;\n count += bytesRead;\n }\n if (count === info.size) {\n try {\n bytes = new TextDecoder(\"utf-8\", {\n fatal: true,\n ignoreBOM: true,\n }).decode(buffer.subarray(0, count));\n } catch {\n /* Binary exports use the normalized selection. */\n }\n }\n }\n } finally {\n await handle.close();\n }\n if (bytes !== undefined) {\n let payload: unknown;\n try {\n payload = JSON.parse(bytes.replace(/^\\uFEFF/u, \"\"));\n } catch {\n /* JSONL and other exports use the normalized selection. */\n }\n const records = nativeRecords(payload, provider);\n if (\n records &&\n records.length === selection.findings.length &&\n records.every((raw, index) => {\n const reviewed = selection.findings[index]!;\n if (!isRecord(raw)) return false;\n const record = canonicalJson(raw);\n return (\n raw[provider === \"endor\" ? \"uuid\" : \"id\"] ===\n reviewed.source_finding_id &&\n reviewed.source_finding_id === reviewed.source_finding_id.trim() &&\n reviewed.evidence.source_data != null &&\n record === canonicalJson(reviewed.evidence.source_data) &&\n Buffer.byteLength(record) <= context.limits.max_record_bytes\n );\n })\n )\n return { format, bytes, digest: hash(\"sha256\", bytes) };\n }\n }\n if (originalFormat && originalFormat !== structuredFormat)\n throw new CodexSecurityError(\n \"The original native report is required to resume this private import.\",\n );\n return privateReport(selection.findings, context.limits);\n}\n\nconst checkpointSchema = z.object({\n format: privateFormat.default(structuredFormat),\n apiBaseUrl: z.string(),\n accountId: z.string(),\n contextVersion: z.string(),\n sha256: z.string(),\n source: z.object({ provider: z.string(), source_key: z.string() }),\n repository: z.object({ id: z.string(), repo_connector_id: z.string() }),\n uploadRequestId: z.uuid(),\n jobRequestId: z.uuid(),\n fileId: fileId.optional(),\n jobId: jobSchema.shape.id.optional(),\n receipt: jobSchema\n .refine((job) => job.status === \"completed\" || unsuccessfulJob(job))\n .optional(),\n previousReceipt: jobSchema.refine(unsuccessfulJob).optional(),\n});\n\nexport function unsuccessfulJob(job: PrivateImportJob | undefined) {\n return job?.status === \"failed\" || job?.status === \"cancelled\";\n}\n\nexport function readPrivateCheckpoint(\n serialized: string,\n expected: {\n format: PrivateImportFormat;\n apiBaseUrl: string;\n accountId: string;\n contextVersion: string;\n sha256: string;\n source: ImportSource;\n repository: { id: string; repo_connector_id: string };\n },\n) {\n const checkpoint = checkpointSchema.parse(JSON.parse(serialized));\n const {\n uploadRequestId,\n jobRequestId,\n fileId,\n jobId,\n receipt,\n previousReceipt,\n contextVersion,\n format,\n sha256,\n ...scope\n } = checkpoint;\n const {\n contextVersion: currentContext,\n format: selectedFormat,\n sha256: selectedDigest,\n ...selectedScope\n } = expected;\n const sameContext = contextVersion === currentContext;\n if (\n canonicalJson(scope) !== canonicalJson(selectedScope) ||\n (sameContext && (format !== selectedFormat || sha256 !== selectedDigest)) ||\n (jobId && !fileId) ||\n [receipt, previousReceipt].some(\n (job) =>\n job &&\n (job.input.format !== format ||\n canonicalJson(job.source) !== canonicalJson(scope.source) ||\n job.default_targets.length !== 1 ||\n job.default_targets[0]?.repo_id !== scope.repository.id ||\n job.default_targets[0]?.repo_connector_id !==\n scope.repository.repo_connector_id),\n ) ||\n (receipt &&\n (receipt.id !== jobId ||\n receipt.request_id !== jobRequestId ||\n receipt.input.file_id !== fileId)) ||\n uploadRequestId === jobRequestId\n )\n throw new CodexSecurityError(\n \"Saved private import does not match this account, repository or report.\",\n );\n return sameContext ? checkpoint : undefined;\n}\n\nexport class PrivateImportRequestError extends CodexSecurityError {\n constructor(\n readonly status: number,\n readonly code: string | undefined,\n message: string,\n ) {\n super(message);\n }\n}\n\nexport function privateImportClient(\n base: string,\n credentials: { access_token: string; account_id: string },\n fetch: (url: string, options: RequestInit) => Promise<Response>,\n signal?: AbortSignal,\n) {\n async function request(path: string, body?: FormData | string) {\n const timeout = AbortSignal.timeout(body === undefined ? 30_000 : 60_000);\n const response = await fetch(`${base}/finding-imports/${path}`, {\n method: body === undefined ? \"GET\" : \"POST\",\n body,\n redirect: \"error\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n Accept: \"application/json\",\n ...(typeof body === \"string\"\n ? { \"Content-Type\": \"application/json\" }\n : {}),\n },\n signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n });\n if (!response.ok) {\n const payload = await response.json().catch(() => undefined);\n const error = z\n .object({\n error: z.object({ code: z.string(), message: z.string().optional() }),\n })\n .safeParse(payload);\n const detail = error.data?.error;\n throw new PrivateImportRequestError(\n response.status,\n detail?.code,\n `Private import failed (HTTP ${response.status}): ${detail?.message ?? detail?.code ?? response.statusText}`,\n );\n }\n return response;\n }\n return {\n async context() {\n return contextSchema.parse(await (await request(\"context\")).json());\n },\n async upload(input: {\n requestId: string;\n contextVersion: string;\n bytes: string;\n digest: string;\n recovering: boolean;\n }) {\n let response: Response | undefined;\n if (input.recovering) {\n try {\n response = await request(`file-requests/${input.requestId}`);\n } catch (error) {\n if (\n !(error instanceof PrivateImportRequestError) ||\n (error.status !== 404 &&\n !(error.status === 409 && error.code === \"upload_retryable\"))\n )\n throw error;\n }\n }\n if (!response) {\n const form = new FormData();\n form.set(\"request_id\", input.requestId);\n form.set(\"context_version\", input.contextVersion);\n form.set(\"purpose\", \"report\");\n form.set(\n \"file\",\n new Blob([input.bytes], { type: \"application/json\" }),\n \"findings.json\",\n );\n response = await request(\"files\", form);\n }\n const file = fileSchema.parse(await response.json());\n if (\n file.sha256 !== input.digest ||\n file.bytes !== Buffer.byteLength(input.bytes)\n )\n throw new CodexSecurityError(\n \"The uploaded file does not match the reviewed report.\",\n );\n return file.id;\n },\n async job(\n input: {\n requestId: string;\n contextVersion: string;\n fileId: string;\n format: PrivateImportFormat;\n source: ImportSource;\n repository: { id: string; repo_connector_id: string };\n jobId?: string;\n },\n accepted: (id: string) => Promise<void>,\n ) {\n let id = input.jobId;\n let response = id\n ? await request(`jobs/${id}`)\n : await request(\n \"jobs\",\n JSON.stringify({\n request_id: input.requestId,\n context_version: input.contextVersion,\n source: input.source,\n input: {\n type: \"file\",\n file_id: input.fileId,\n format: input.format,\n },\n default_targets: [\n {\n type: \"repository\",\n repo_id: input.repository.id,\n repo_connector_id: input.repository.repo_connector_id,\n },\n ],\n }),\n );\n for (;;) {\n const job = jobSchema.parse(await response.json());\n if (\n (id !== undefined && job.id !== id) ||\n job.request_id !== input.requestId ||\n job.input.file_id !== input.fileId ||\n job.input.format !== input.format ||\n job.source.provider !== input.source.provider ||\n job.source.source_key !== input.source.source_key ||\n job.default_targets.length !== 1 ||\n job.default_targets[0]?.repo_id !== input.repository.id ||\n job.default_targets[0]?.repo_connector_id !==\n input.repository.repo_connector_id\n )\n throw new CodexSecurityError(\n \"Cloud returned a job for a different private import.\",\n );\n if (\n job.status === \"completed\" ||\n job.status === \"failed\" ||\n job.status === \"cancelled\"\n )\n return job;\n if (!id) {\n id = job.id;\n await accepted(id);\n }\n const retry = response.headers.get(\"Retry-After\");\n const seconds = retry === null ? 0 : Number(retry);\n await delay(\n Math.max(\n Number.isFinite(seconds) ? seconds : 0,\n job.poll_after_seconds ?? 1,\n ) * 1000,\n undefined,\n { signal },\n );\n response = await request(`jobs/${id}`);\n }\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"project-config.d.ts","sourceRoot":"","sources":["../src/project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AqB,CAwKvB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,GAAG,SAAS,GAC9B,UAAU,GAAG,SAAS,CAKxB"}
@@ -2,7 +2,6 @@ import { readFile } from "node:fs/promises";
2
2
  import { dirname, extname, isAbsolute, relative, resolve, sep, } from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import Ajv from "ajv";
5
- import { parseDocument } from "yaml";
6
5
  import { DEFAULT_CODEX_CONFIG, mergeCodexOverrides, } from "./config.js";
7
6
  import { ConfigurationError, errorMessage } from "./errors.js";
8
7
  import { DEFAULT_DEEP_SCAN_SETTINGS } from "./deep-scan-defaults.js";
@@ -62,9 +61,10 @@ export async function readProjectConfig(file, directory = process.cwd()) {
62
61
  let value;
63
62
  try {
64
63
  if (extension === ".json") {
65
- value = JSON.parse(text);
64
+ value = JSON.parse(text.replace(/^\uFEFF/u, ""));
66
65
  }
67
66
  else {
67
+ const { parseDocument } = await import("yaml");
68
68
  const document = parseDocument(text, { prettyErrors: false });
69
69
  if (document.errors.length > 0)
70
70
  throw document.errors[0];
@@ -1 +1 @@
1
- {"version":3,"file":"project-config.js","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,E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;QAC1B,OAAO,EAAE,QAAQ;QACjB,OAAO,EAAE,eAAe;QACxB,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS;YAC7B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,KAA+B;IAE/B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,IAAI,KAAK;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,MAAM,IAAI,KAAK;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport {\n dirname,\n extname,\n isAbsolute,\n relative,\n resolve,\n sep,\n} from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport Ajv from \"ajv\";\nimport { parseDocument } from \"yaml\";\nimport {\n DEFAULT_CODEX_CONFIG,\n mergeCodexOverrides,\n type JsonObject,\n} from \"./config.js\";\nimport { ConfigurationError, errorMessage } from \"./errors.js\";\nimport { DEFAULT_DEEP_SCAN_SETTINGS } from \"./deep-scan-defaults.js\";\nimport { resolveConfigPath, type AbsolutePath } from \"./config-path.js\";\nimport { deepScanOptions, type DeepScanSources } from \"./deep-config.js\";\nimport {\n projectConfigJsonSchema,\n type ProjectConfigInput,\n type ProjectScope,\n} from \"./project-config-schema.js\";\nimport { expandHome } from \"./runtime.js\";\nimport {\n DEFAULT_SCAN_AUTH,\n DEFAULT_SCAN_MODE,\n DEEP_SCAN_SETTINGS,\n pickScanSettings,\n type DeepScanOptions,\n type ResolvedScanSettings,\n type ScanSettings,\n} from \"./scan-settings.js\";\nimport { DiffTarget, type ScanTarget } from \"./targets.js\";\n\nconst validateProjectConfig = new Ajv({\n allErrors: true,\n}).compile<ProjectConfigInput>(projectConfigJsonSchema());\n\nexport interface ProjectConfigSource {\n path?: string;\n directory: string;\n input: ProjectConfigInput;\n}\n\nexport interface ResolvedProjectConfig {\n config: { codexOverrides: JsonObject };\n options: ResolvedScanSettings;\n sources: ConfigurationSources;\n projectConfig?: ProjectConfigProvenance;\n}\n\nexport type ConfigurationSource = \"default\" | \"legacy\" | \"project\" | \"cli\";\nconst PROJECT_SETTING_KEYS = {\n auth: \"auth\",\n mode: \"scan.mode\",\n maxTimeMinutes: \"scan.max_time_minutes\",\n cyberAccessProgram: \"scan.cyber_access_program\",\n ownerSuggestions: \"scan.owner_suggestions\",\n target: \"scan.scope\",\n knowledgeBasePaths: \"scan.knowledge_base\",\n scanPromptFile: \"scan.instructions_file\",\n validationPromptFile: \"scan.validation_file\",\n outputDir: \"output.directory\",\n failureSeverity: \"policy.fail_on_severity\",\n maxCostUsd: \"limits.max_cost_usd_per_scan\",\n} as const satisfies Partial<Record<keyof ScanSettings, string>>;\ntype SettingProvenanceKey =\n (typeof PROJECT_SETTING_KEYS)[keyof typeof PROJECT_SETTING_KEYS];\nexport type ScopeProvenanceKey =\n \"scan.scope\" | \"scan.scope.diff.head\" | \"scan.scope.working_tree.base\";\nexport type ProvenanceKey =\n | SettingProvenanceKey\n | ScopeProvenanceKey\n | `scan.deep.${(typeof DEEP_SCAN_SETTINGS)[number][2]}`\n | `codex.${string}`;\nexport type ConfigurationSources = Readonly<\n Record<SettingProvenanceKey, ConfigurationSource> &\n Partial<Record<ProvenanceKey, ConfigurationSource>>\n>;\nexport interface ProjectConfigProvenance {\n path: string;\n sources: ConfigurationSources;\n}\n\n/** Build a complete, immutable source map after layer and preflight resolution. */\nexport function configurationSources(\n values: Partial<Record<ProvenanceKey, ConfigurationSource>> = {},\n deepSources?: DeepScanSources,\n): ConfigurationSources {\n const sources = {\n ...Object.fromEntries(\n Object.values(PROJECT_SETTING_KEYS).map((key) => [key, \"default\"]),\n ),\n ...values,\n } as Record<SettingProvenanceKey, ConfigurationSource> &\n Partial<Record<ProvenanceKey, ConfigurationSource>>;\n for (const [name, , key] of DEEP_SCAN_SETTINGS) {\n const source = deepSources?.[name];\n if (source !== undefined && source !== \"override\")\n sources[`scan.deep.${key}`] = source;\n }\n return Object.freeze(sources);\n}\n\nexport async function loadProjectConfig(\n file: string,\n directory = process.cwd(),\n): Promise<ResolvedProjectConfig> {\n return resolveScanSettings(\n await readProjectConfig(file, directory),\n {},\n directory,\n );\n}\n\nexport function resolveProjectConfig(\n input: ProjectConfigInput,\n directory = process.cwd(),\n): ResolvedProjectConfig {\n requireProjectConfig(input);\n return resolveScanSettings(\n { input, directory: resolve(directory) },\n {},\n directory,\n );\n}\n\nexport async function readProjectConfig(\n file: string,\n directory = process.cwd(),\n): Promise<ProjectConfigSource> {\n const path = resolve(directory, expandHome(file));\n const extension = projectConfigExtension(path);\n let text: string;\n try {\n text = await readFile(path, \"utf8\");\n } catch (error) {\n throw new ConfigurationError(\n `Cannot read project configuration at ${path}: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n let value: unknown;\n try {\n if (extension === \".json\") {\n value = JSON.parse(text);\n } else {\n const document = parseDocument(text, { prettyErrors: false });\n if (document.errors.length > 0) throw document.errors[0];\n // Keep YAML's expansion guard while allowing repeated native profiles.\n value = document.toJS({ maxAliasCount: 10_000 });\n }\n } catch (error) {\n throw new ConfigurationError(\n `Cannot parse project configuration at ${path}: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n requireProjectConfig(value, path);\n return { path, directory: dirname(path), input: value };\n}\n\nfunction projectConfigExtension(path: string): string {\n const extension = extname(path).toLowerCase();\n if (![\".yaml\", \".yml\", \".json\"].includes(extension)) {\n throw new ConfigurationError(\n \"Project configuration must be a .yaml, .yml, or .json file.\",\n );\n }\n return extension;\n}\n\nexport function projectConfigStarter(\n path: string,\n directory = process.cwd(),\n): string {\n const schemaPath = resolve(\n directory,\n \"node_modules/@openai/codex-security/schemas/project-config.schema.json\",\n );\n const relativeSchema = relative(\n dirname(resolve(directory, path)),\n schemaPath,\n );\n const schema = isAbsolute(relativeSchema)\n ? pathToFileURL(schemaPath).href\n : `${relativeSchema.startsWith(\".\") ? \"\" : \"./\"}${encodeURI(\n relativeSchema.split(sep).join(\"/\"),\n ).replace(/[#?]/gu, encodeURIComponent)}`;\n if (projectConfigExtension(path) === \".json\")\n return `${JSON.stringify({ $schema: schema }, null, 2)}\\n`;\n return [\n \"# This file is trusted like CLI options. Keep it outside untrusted inputs.\",\n `$schema: ${schema}`,\n \"\",\n \"# Uncomment the settings you want to override. Defaults remain unpinned.\",\n `# auth: ${DEFAULT_SCAN_AUTH}`,\n \"# scan:\",\n `# mode: ${DEFAULT_SCAN_MODE}`,\n \"# scope:\",\n \"# paths: [src] # Relative to each selected repository.\",\n \"# knowledge_base: [] # Paths relative to this file.\",\n \"# instructions_file: instructions.md\",\n \"# validation_file: validation.md # Standard mode only.\",\n \"# max_time_minutes: 15 # Advisory in Standard; enforced discovery limit in Deep.\",\n \"# deep: # Used when mode is deep.\",\n ...DEEP_SCAN_SETTINGS.filter(([name]) => name !== \"maxTimeHours\").map(\n ([name, , key]) => `# ${key}: ${DEFAULT_DEEP_SCAN_SETTINGS[name]}`,\n ),\n \"# codex:\",\n `# model: ${DEFAULT_CODEX_CONFIG[\"model\"]}`,\n `# model_reasoning_effort: ${DEFAULT_CODEX_CONFIG[\"model_reasoning_effort\"]}`,\n \"# limits:\",\n \"# max_cost_usd_per_scan: 10 # Optional limit per scan attempt.\",\n \"# policy:\",\n \"# fail_on_severity: high # Omitted by default (report only).\",\n \"# output:\",\n \"# directory: ../scan-results # Outside the selected repositories.\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction requireProjectConfig(\n value: unknown,\n path?: string,\n): asserts value is ProjectConfigInput {\n if (!validateProjectConfig(value)) {\n const issues = validateProjectConfig\n .errors!.map((issue) => {\n const message =\n issue.keyword === \"additionalProperties\"\n ? `Unknown key ${issue.params[\"additionalProperty\"]}.`\n : issue.message;\n return `${issue.instancePath || \"configuration\"}: ${message}`;\n })\n .join(\"; \");\n throw new ConfigurationError(\n `Invalid project configuration${path === undefined ? \"\" : ` at ${path}`}: ${issues}`,\n );\n }\n}\n\nexport function resolveScanSettings(\n project: ProjectConfigSource | undefined,\n overrides: Partial<ScanSettings> & { codexOverrides?: JsonObject },\n directory: string,\n scopeSources: Partial<Record<ScopeProvenanceKey, ConfigurationSource>> = {},\n): ResolvedProjectConfig {\n const file = project?.input;\n const sources: Partial<Record<ProvenanceKey, ConfigurationSource>> = {};\n const choose = <T>(\n key: ProvenanceKey,\n configured: T | undefined,\n explicit: T | undefined,\n ): T | undefined => {\n if (explicit !== undefined) {\n sources[key] = \"cli\";\n return explicit;\n }\n if (configured !== undefined) {\n sources[key] = \"project\";\n return configured;\n }\n return undefined;\n };\n const projectDirectory = project?.directory ?? directory;\n const filePath = (value: string | undefined): AbsolutePath | undefined =>\n value === undefined\n ? undefined\n : resolveConfigPath(projectDirectory, value);\n const cliPath = (value: string | undefined): AbsolutePath | undefined =>\n value === undefined ? undefined : resolveConfigPath(directory, value);\n\n const mode =\n choose(\"scan.mode\", file?.scan?.mode, overrides.mode) ?? DEFAULT_SCAN_MODE;\n const explicitDeep = deepScanOptions({\n ...overrides,\n maxTimeMinutes: undefined,\n mode,\n });\n const target =\n choose(\n \"scan.scope\",\n projectScopeTarget(file?.scan?.scope),\n overrides.target,\n ) ?? \"repository\";\n const configuredDeep = file?.scan?.deep;\n const explicitTime =\n overrides.maxTimeMinutes !== undefined ||\n overrides.maxTimeHours !== undefined;\n const maxTimeMinutes = choose(\n \"scan.max_time_minutes\",\n explicitTime ? undefined : file?.scan?.max_time_minutes,\n overrides.maxTimeMinutes,\n );\n const deep: DeepScanOptions = {};\n if (mode === \"deep\") {\n for (const [name, , field] of DEEP_SCAN_SETTINGS) {\n const value = choose(\n `scan.deep.${field}`,\n name === \"maxTimeHours\" && explicitTime\n ? undefined\n : configuredDeep?.[field],\n explicitDeep[name],\n );\n if (value !== undefined) deep[name] = value;\n }\n }\n\n const codexOverrides = mergeCodexOverrides(\n file?.codex ?? {},\n overrides.codexOverrides ?? {},\n );\n const nativeSourceTree = (\n value: JsonObject,\n source: ConfigurationSource,\n ): JsonObject =>\n Object.fromEntries(\n Object.entries(value).map(([key, item]) => [\n key,\n item !== null && typeof item === \"object\" && !Array.isArray(item)\n ? nativeSourceTree(item, source)\n : source,\n ]),\n );\n const recordNativeSources = (\n value: JsonObject,\n source: ConfigurationSource,\n prefix: \"codex\" | `codex.${string}` = \"codex\",\n ) => {\n for (const [key, item] of Object.entries(value)) {\n const path: `codex.${string}` = `${prefix}.${key}`;\n if (item !== null && typeof item === \"object\" && !Array.isArray(item)) {\n recordNativeSources(item, source, path);\n } else if (item === source) {\n sources[path] = source;\n }\n }\n };\n // Match the value merge: defaults beneath the combined project/CLI overrides.\n const nativeSources = mergeCodexOverrides(\n nativeSourceTree(DEFAULT_CODEX_CONFIG, \"default\"),\n mergeCodexOverrides(\n nativeSourceTree(file?.codex ?? {}, \"project\"),\n nativeSourceTree(overrides.codexOverrides ?? {}, \"cli\"),\n ),\n );\n // Literal dotted keys can share a flattened name; retain layer precedence.\n for (const source of [\"default\", \"project\", \"cli\"] as const) {\n recordNativeSources(nativeSources, source);\n }\n const knowledgeBasePaths =\n choose(\n \"scan.knowledge_base\",\n file?.scan?.knowledge_base?.map((value) =>\n resolveConfigPath(projectDirectory, value),\n ),\n overrides.knowledgeBasePaths?.map((value) =>\n resolveConfigPath(directory, value),\n ),\n ) ?? [];\n const settings: ResolvedScanSettings = {\n ...pickScanSettings(overrides),\n auth: choose(\"auth\", file?.auth, overrides.auth) ?? DEFAULT_SCAN_AUTH,\n cyberAccessProgram: choose(\n \"scan.cyber_access_program\",\n file?.scan?.cyber_access_program,\n overrides.cyberAccessProgram,\n ),\n mode,\n maxTimeMinutes,\n target,\n ownerSuggestions: choose(\n \"scan.owner_suggestions\",\n file?.scan?.owner_suggestions,\n overrides.ownerSuggestions,\n ),\n knowledgeBasePaths,\n scanPromptFile: choose(\n \"scan.instructions_file\",\n filePath(file?.scan?.instructions_file),\n cliPath(overrides.scanPromptFile),\n ),\n validationPromptFile: choose(\n \"scan.validation_file\",\n filePath(file?.scan?.validation_file),\n cliPath(overrides.validationPromptFile),\n ),\n postScanPromptFile: cliPath(overrides.postScanPromptFile),\n outputDir: choose(\n \"output.directory\",\n filePath(file?.output?.directory),\n cliPath(overrides.outputDir),\n ),\n failureSeverity: choose(\n \"policy.fail_on_severity\",\n file?.policy?.fail_on_severity,\n overrides.failureSeverity,\n ),\n maxCostUsd: choose(\n \"limits.max_cost_usd_per_scan\",\n file?.limits?.max_cost_usd_per_scan,\n overrides.maxCostUsd,\n ),\n ...deep,\n };\n const resolvedSources = configurationSources({ ...sources, ...scopeSources });\n return {\n config: { codexOverrides },\n options: settings,\n sources: resolvedSources,\n ...(project?.path === undefined\n ? {}\n : { projectConfig: { path: project.path, sources: resolvedSources } }),\n };\n}\n\nexport function projectScopeTarget(\n scope: ProjectScope | undefined,\n): ScanTarget | undefined {\n if (scope === undefined) return undefined;\n if (\"paths\" in scope) return [...scope.paths];\n if (\"diff\" in scope) return DiffTarget.refs(scope.diff);\n return DiffTarget.workingTree(scope.working_tree);\n}\n"]}
1
+ {"version":3,"file":"project-config.js","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GAEpB,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EAAE,MAAM,CAChB,8BAA8B,EAC9B,IAAI,EAAE,MAAM,EAAE,qBAAqB,EACnC,SAAS,CAAC,UAAU,CACrB;QACD,GAAG,IAAI;KACR,CAAC;IACF,MAAM,eAAe,GAAG,oBAAoB,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;IAC9E,OAAO;QACL,MAAM,EAAE,EAAE,cAAc,EAAE;QAC1B,OAAO,EAAE,QAAQ;QACjB,OAAO,EAAE,eAAe;QACxB,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS;YAC7B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,KAA+B;IAE/B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,IAAI,KAAK;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,MAAM,IAAI,KAAK;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport {\n dirname,\n extname,\n isAbsolute,\n relative,\n resolve,\n sep,\n} from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport Ajv from \"ajv\";\nimport {\n DEFAULT_CODEX_CONFIG,\n mergeCodexOverrides,\n type JsonObject,\n} from \"./config.js\";\nimport { ConfigurationError, errorMessage } from \"./errors.js\";\nimport { DEFAULT_DEEP_SCAN_SETTINGS } from \"./deep-scan-defaults.js\";\nimport { resolveConfigPath, type AbsolutePath } from \"./config-path.js\";\nimport { deepScanOptions, type DeepScanSources } from \"./deep-config.js\";\nimport {\n projectConfigJsonSchema,\n type ProjectConfigInput,\n type ProjectScope,\n} from \"./project-config-schema.js\";\nimport { expandHome } from \"./runtime.js\";\nimport {\n DEFAULT_SCAN_AUTH,\n DEFAULT_SCAN_MODE,\n DEEP_SCAN_SETTINGS,\n pickScanSettings,\n type DeepScanOptions,\n type ResolvedScanSettings,\n type ScanSettings,\n} from \"./scan-settings.js\";\nimport { DiffTarget, type ScanTarget } from \"./targets.js\";\n\nconst validateProjectConfig = new Ajv({\n allErrors: true,\n}).compile<ProjectConfigInput>(projectConfigJsonSchema());\n\nexport interface ProjectConfigSource {\n path?: string;\n directory: string;\n input: ProjectConfigInput;\n}\n\nexport interface ResolvedProjectConfig {\n config: { codexOverrides: JsonObject };\n options: ResolvedScanSettings;\n sources: ConfigurationSources;\n projectConfig?: ProjectConfigProvenance;\n}\n\nexport type ConfigurationSource = \"default\" | \"legacy\" | \"project\" | \"cli\";\nconst PROJECT_SETTING_KEYS = {\n auth: \"auth\",\n mode: \"scan.mode\",\n maxTimeMinutes: \"scan.max_time_minutes\",\n cyberAccessProgram: \"scan.cyber_access_program\",\n ownerSuggestions: \"scan.owner_suggestions\",\n target: \"scan.scope\",\n knowledgeBasePaths: \"scan.knowledge_base\",\n scanPromptFile: \"scan.instructions_file\",\n validationPromptFile: \"scan.validation_file\",\n outputDir: \"output.directory\",\n failureSeverity: \"policy.fail_on_severity\",\n maxCostUsd: \"limits.max_cost_usd_per_scan\",\n} as const satisfies Partial<Record<keyof ScanSettings, string>>;\ntype SettingProvenanceKey =\n (typeof PROJECT_SETTING_KEYS)[keyof typeof PROJECT_SETTING_KEYS];\nexport type ScopeProvenanceKey =\n \"scan.scope\" | \"scan.scope.diff.head\" | \"scan.scope.working_tree.base\";\nexport type ProvenanceKey =\n | SettingProvenanceKey\n | ScopeProvenanceKey\n | `scan.deep.${(typeof DEEP_SCAN_SETTINGS)[number][2]}`\n | `codex.${string}`;\nexport type ConfigurationSources = Readonly<\n Record<SettingProvenanceKey, ConfigurationSource> &\n Partial<Record<ProvenanceKey, ConfigurationSource>>\n>;\nexport interface ProjectConfigProvenance {\n path: string;\n sources: ConfigurationSources;\n}\n\n/** Build a complete, immutable source map after layer and preflight resolution. */\nexport function configurationSources(\n values: Partial<Record<ProvenanceKey, ConfigurationSource>> = {},\n deepSources?: DeepScanSources,\n): ConfigurationSources {\n const sources = {\n ...Object.fromEntries(\n Object.values(PROJECT_SETTING_KEYS).map((key) => [key, \"default\"]),\n ),\n ...values,\n } as Record<SettingProvenanceKey, ConfigurationSource> &\n Partial<Record<ProvenanceKey, ConfigurationSource>>;\n for (const [name, , key] of DEEP_SCAN_SETTINGS) {\n const source = deepSources?.[name];\n if (source !== undefined && source !== \"override\")\n sources[`scan.deep.${key}`] = source;\n }\n return Object.freeze(sources);\n}\n\nexport async function loadProjectConfig(\n file: string,\n directory = process.cwd(),\n): Promise<ResolvedProjectConfig> {\n return resolveScanSettings(\n await readProjectConfig(file, directory),\n {},\n directory,\n );\n}\n\nexport function resolveProjectConfig(\n input: ProjectConfigInput,\n directory = process.cwd(),\n): ResolvedProjectConfig {\n requireProjectConfig(input);\n return resolveScanSettings(\n { input, directory: resolve(directory) },\n {},\n directory,\n );\n}\n\nexport async function readProjectConfig(\n file: string,\n directory = process.cwd(),\n): Promise<ProjectConfigSource> {\n const path = resolve(directory, expandHome(file));\n const extension = projectConfigExtension(path);\n let text: string;\n try {\n text = await readFile(path, \"utf8\");\n } catch (error) {\n throw new ConfigurationError(\n `Cannot read project configuration at ${path}: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n let value: unknown;\n try {\n if (extension === \".json\") {\n value = JSON.parse(text.replace(/^\\uFEFF/u, \"\"));\n } else {\n const { parseDocument } = await import(\"yaml\");\n const document = parseDocument(text, { prettyErrors: false });\n if (document.errors.length > 0) throw document.errors[0];\n // Keep YAML's expansion guard while allowing repeated native profiles.\n value = document.toJS({ maxAliasCount: 10_000 });\n }\n } catch (error) {\n throw new ConfigurationError(\n `Cannot parse project configuration at ${path}: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n requireProjectConfig(value, path);\n return { path, directory: dirname(path), input: value };\n}\n\nfunction projectConfigExtension(path: string): string {\n const extension = extname(path).toLowerCase();\n if (![\".yaml\", \".yml\", \".json\"].includes(extension)) {\n throw new ConfigurationError(\n \"Project configuration must be a .yaml, .yml, or .json file.\",\n );\n }\n return extension;\n}\n\nexport function projectConfigStarter(\n path: string,\n directory = process.cwd(),\n): string {\n const schemaPath = resolve(\n directory,\n \"node_modules/@openai/codex-security/schemas/project-config.schema.json\",\n );\n const relativeSchema = relative(\n dirname(resolve(directory, path)),\n schemaPath,\n );\n const schema = isAbsolute(relativeSchema)\n ? pathToFileURL(schemaPath).href\n : `${relativeSchema.startsWith(\".\") ? \"\" : \"./\"}${encodeURI(\n relativeSchema.split(sep).join(\"/\"),\n ).replace(/[#?]/gu, encodeURIComponent)}`;\n if (projectConfigExtension(path) === \".json\")\n return `${JSON.stringify({ $schema: schema }, null, 2)}\\n`;\n return [\n \"# This file is trusted like CLI options. Keep it outside untrusted inputs.\",\n `$schema: ${schema}`,\n \"\",\n \"# Uncomment the settings you want to override. Defaults remain unpinned.\",\n `# auth: ${DEFAULT_SCAN_AUTH}`,\n \"# scan:\",\n `# mode: ${DEFAULT_SCAN_MODE}`,\n \"# scope:\",\n \"# paths: [src] # Relative to each selected repository.\",\n \"# knowledge_base: [] # Paths relative to this file.\",\n \"# instructions_file: instructions.md\",\n \"# validation_file: validation.md # Standard mode only.\",\n \"# max_time_minutes: 15 # Advisory in Standard; enforced discovery limit in Deep.\",\n \"# deep: # Used when mode is deep.\",\n ...DEEP_SCAN_SETTINGS.filter(([name]) => name !== \"maxTimeHours\").map(\n ([name, , key]) => `# ${key}: ${DEFAULT_DEEP_SCAN_SETTINGS[name]}`,\n ),\n \"# codex:\",\n `# model: ${DEFAULT_CODEX_CONFIG[\"model\"]}`,\n `# model_reasoning_effort: ${DEFAULT_CODEX_CONFIG[\"model_reasoning_effort\"]}`,\n \"# limits:\",\n \"# max_cost_usd_per_scan: 10 # Optional limit per scan attempt.\",\n \"# policy:\",\n \"# fail_on_severity: high # Omitted by default (report only).\",\n \"# output:\",\n \"# directory: ../scan-results # Outside the selected repositories.\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction requireProjectConfig(\n value: unknown,\n path?: string,\n): asserts value is ProjectConfigInput {\n if (!validateProjectConfig(value)) {\n const issues = validateProjectConfig\n .errors!.map((issue) => {\n const message =\n issue.keyword === \"additionalProperties\"\n ? `Unknown key ${issue.params[\"additionalProperty\"]}.`\n : issue.message;\n return `${issue.instancePath || \"configuration\"}: ${message}`;\n })\n .join(\"; \");\n throw new ConfigurationError(\n `Invalid project configuration${path === undefined ? \"\" : ` at ${path}`}: ${issues}`,\n );\n }\n}\n\nexport function resolveScanSettings(\n project: ProjectConfigSource | undefined,\n overrides: Partial<ScanSettings> & { codexOverrides?: JsonObject },\n directory: string,\n scopeSources: Partial<Record<ScopeProvenanceKey, ConfigurationSource>> = {},\n): ResolvedProjectConfig {\n const file = project?.input;\n const sources: Partial<Record<ProvenanceKey, ConfigurationSource>> = {};\n const choose = <T>(\n key: ProvenanceKey,\n configured: T | undefined,\n explicit: T | undefined,\n ): T | undefined => {\n if (explicit !== undefined) {\n sources[key] = \"cli\";\n return explicit;\n }\n if (configured !== undefined) {\n sources[key] = \"project\";\n return configured;\n }\n return undefined;\n };\n const projectDirectory = project?.directory ?? directory;\n const filePath = (value: string | undefined): AbsolutePath | undefined =>\n value === undefined\n ? undefined\n : resolveConfigPath(projectDirectory, value);\n const cliPath = (value: string | undefined): AbsolutePath | undefined =>\n value === undefined ? undefined : resolveConfigPath(directory, value);\n\n const mode =\n choose(\"scan.mode\", file?.scan?.mode, overrides.mode) ?? DEFAULT_SCAN_MODE;\n const explicitDeep = deepScanOptions({\n ...overrides,\n maxTimeMinutes: undefined,\n mode,\n });\n const target =\n choose(\n \"scan.scope\",\n projectScopeTarget(file?.scan?.scope),\n overrides.target,\n ) ?? \"repository\";\n const configuredDeep = file?.scan?.deep;\n const explicitTime =\n overrides.maxTimeMinutes !== undefined ||\n overrides.maxTimeHours !== undefined;\n const maxTimeMinutes = choose(\n \"scan.max_time_minutes\",\n explicitTime ? undefined : file?.scan?.max_time_minutes,\n overrides.maxTimeMinutes,\n );\n const deep: DeepScanOptions = {};\n if (mode === \"deep\") {\n for (const [name, , field] of DEEP_SCAN_SETTINGS) {\n const value = choose(\n `scan.deep.${field}`,\n name === \"maxTimeHours\" && explicitTime\n ? undefined\n : configuredDeep?.[field],\n explicitDeep[name],\n );\n if (value !== undefined) deep[name] = value;\n }\n }\n\n const codexOverrides = mergeCodexOverrides(\n file?.codex ?? {},\n overrides.codexOverrides ?? {},\n );\n const nativeSourceTree = (\n value: JsonObject,\n source: ConfigurationSource,\n ): JsonObject =>\n Object.fromEntries(\n Object.entries(value).map(([key, item]) => [\n key,\n item !== null && typeof item === \"object\" && !Array.isArray(item)\n ? nativeSourceTree(item, source)\n : source,\n ]),\n );\n const recordNativeSources = (\n value: JsonObject,\n source: ConfigurationSource,\n prefix: \"codex\" | `codex.${string}` = \"codex\",\n ) => {\n for (const [key, item] of Object.entries(value)) {\n const path: `codex.${string}` = `${prefix}.${key}`;\n if (item !== null && typeof item === \"object\" && !Array.isArray(item)) {\n recordNativeSources(item, source, path);\n } else if (item === source) {\n sources[path] = source;\n }\n }\n };\n // Match the value merge: defaults beneath the combined project/CLI overrides.\n const nativeSources = mergeCodexOverrides(\n nativeSourceTree(DEFAULT_CODEX_CONFIG, \"default\"),\n mergeCodexOverrides(\n nativeSourceTree(file?.codex ?? {}, \"project\"),\n nativeSourceTree(overrides.codexOverrides ?? {}, \"cli\"),\n ),\n );\n // Literal dotted keys can share a flattened name; retain layer precedence.\n for (const source of [\"default\", \"project\", \"cli\"] as const) {\n recordNativeSources(nativeSources, source);\n }\n const knowledgeBasePaths =\n choose(\n \"scan.knowledge_base\",\n file?.scan?.knowledge_base?.map((value) =>\n resolveConfigPath(projectDirectory, value),\n ),\n overrides.knowledgeBasePaths?.map((value) =>\n resolveConfigPath(directory, value),\n ),\n ) ?? [];\n const settings: ResolvedScanSettings = {\n ...pickScanSettings(overrides),\n auth: choose(\"auth\", file?.auth, overrides.auth) ?? DEFAULT_SCAN_AUTH,\n cyberAccessProgram: choose(\n \"scan.cyber_access_program\",\n file?.scan?.cyber_access_program,\n overrides.cyberAccessProgram,\n ),\n mode,\n maxTimeMinutes,\n target,\n ownerSuggestions: choose(\n \"scan.owner_suggestions\",\n file?.scan?.owner_suggestions,\n overrides.ownerSuggestions,\n ),\n knowledgeBasePaths,\n scanPromptFile: choose(\n \"scan.instructions_file\",\n filePath(file?.scan?.instructions_file),\n cliPath(overrides.scanPromptFile),\n ),\n validationPromptFile: choose(\n \"scan.validation_file\",\n filePath(file?.scan?.validation_file),\n cliPath(overrides.validationPromptFile),\n ),\n postScanPromptFile: cliPath(overrides.postScanPromptFile),\n outputDir: choose(\n \"output.directory\",\n filePath(file?.output?.directory),\n cliPath(overrides.outputDir),\n ),\n failureSeverity: choose(\n \"policy.fail_on_severity\",\n file?.policy?.fail_on_severity,\n overrides.failureSeverity,\n ),\n maxCostUsd: choose(\n \"limits.max_cost_usd_per_scan\",\n file?.limits?.max_cost_usd_per_scan,\n overrides.maxCostUsd,\n ),\n ...deep,\n };\n const resolvedSources = configurationSources({ ...sources, ...scopeSources });\n return {\n config: { codexOverrides },\n options: settings,\n sources: resolvedSources,\n ...(project?.path === undefined\n ? {}\n : { projectConfig: { path: project.path, sources: resolvedSources } }),\n };\n}\n\nexport function projectScopeTarget(\n scope: ProjectScope | undefined,\n): ScanTarget | undefined {\n if (scope === undefined) return undefined;\n if (\"paths\" in scope) return [...scope.paths];\n if (\"diff\" in scope) return DiffTarget.refs(scope.diff);\n return DiffTarget.workingTree(scope.working_tree);\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { Codex, CodexOptions } from "@openai/codex-sdk";
2
2
  import { type JsonObject } from "./config.js";
3
- import { requirePrivateCredentialHome, type CodexCommand } from "./runtime.js";
3
+ import { requirePrivateCredentialHome, type CodexCommand, type ProcessEnvironment } from "./runtime.js";
4
4
  export interface ProviderProfile {
5
5
  name: string;
6
6
  path: string;
@@ -8,8 +8,14 @@ export interface ProviderProfile {
8
8
  }
9
9
  /** Native no-turn commands need provider metadata when managed policy selects it. */
10
10
  export declare function providerPreflightCommand(command: CodexCommand, config: JsonObject): Promise<CodexCommand>;
11
+ /** Retain explicit settings omitted from the readable recipe when its file reloads. */
12
+ export declare function privateReplayOverrides(config: JsonObject, recipe: JsonObject): JsonObject;
11
13
  /** Provider definitions use a native file layer, never process arguments. */
12
- export declare function createProviderProfile(codexHome: string, config: JsonObject, options?: Parameters<typeof requirePrivateCredentialHome>[2]): Promise<ProviderProfile>;
14
+ export declare function createProviderProfile(codexHome: string, config: JsonObject, options?: Parameters<typeof requirePrivateCredentialHome>[2] & {
15
+ replay?: boolean;
16
+ }): Promise<ProviderProfile>;
17
+ /** Restore private replay settings from the credential home, never scan artifacts. */
18
+ export declare function restoreProviderProfile(config: JsonObject, profile: unknown, environment: ProcessEnvironment): Promise<JsonObject>;
13
19
  /** The pinned SDK lacks the native CLI's private profile-file option. */
14
20
  export declare function createProfileCodex(options: CodexOptions, profileName: string, requestedPermissionProfile?: string): Promise<Codex>;
15
21
  /** Verify the effective helper policy before starting exec with a private profile. */
@@ -18,4 +24,6 @@ export declare function preflightReadOnlyProfileCodex(options: CodexOptions, exp
18
24
  configOverrides: string[];
19
25
  }>;
20
26
  export declare function withCodexPreflightLock<T>(env: Record<string, string> | undefined, signal: AbortSignal | undefined, operation: () => Promise<T>): Promise<T>;
27
+ export declare function nativePermissionPreflight(): Promise<any>;
28
+ export declare function nativeProfileClient(): Promise<any>;
21
29
  //# sourceMappingURL=provider-profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-profile.d.ts","sourceRoot":"","sources":["../src/provider-profile.ts"],"names":[],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EAAE,MAAM,GAClC,OAAO,CAAC,KAAK,CAAC,CAahB;AAED,sFAAsF;AACtF,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,YAAY,EACrB,eAAe,EAAE,UAAU,EAC3B,cAAc,EAAE,UAAU,EAC1B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA+CrE;AAED,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACvC,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED,wBAAsB,yBAAyB,iBAU9C;AAED,wBAAsB,mBAAmB,iBAMxC"}
@@ -7,14 +7,16 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  return path;
8
8
  };
9
9
  import { randomUUID } from "node:crypto";
10
- import { lstat, mkdir, rm } from "node:fs/promises";
10
+ import { lstat, mkdir, readFile, rm } from "node:fs/promises";
11
11
  import { join } from "node:path";
12
12
  import { pathToFileURL } from "node:url";
13
+ import { parse } from "smol-toml";
13
14
  import { configuredCodexHome } from "./auth.js";
14
- import { resolveCodexProfile, modelProviderConfigOverride, inlineToml, writeCodexConfig, } from "./config.js";
15
+ import { CodexSecurityError } from "./errors.js";
16
+ import { resolveCodexProfile, deepMerge, modelProviderConfigOverride, inlineToml, writeCodexConfig, writePrivateConfig, } from "./config.js";
15
17
  import { isRecord } from "./record.js";
16
18
  import { bundledCodexSdkEnvironment } from "./codex-sdk-environment.js";
17
- import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, executablePathForSpawn, requirePrivateCredentialHome, resolveCodexCommand, } from "./runtime.js";
19
+ import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, codexSecurityCredentialHome, executablePathForSpawn, requirePrivateCredentialHome, requireSecureCredentialHome, resolveCodexCommand, } from "./runtime.js";
18
20
  /** Native no-turn commands need provider metadata when managed policy selects it. */
19
21
  export async function providerPreflightCommand(command, config) {
20
22
  const resolved = resolveCodexProfile(config);
@@ -37,20 +39,80 @@ export async function providerPreflightCommand(command, config) {
37
39
  ],
38
40
  };
39
41
  }
42
+ /** Retain explicit settings omitted from the readable recipe when its file reloads. */
43
+ export function privateReplayOverrides(config, recipe) {
44
+ const result = {};
45
+ for (const [key, value] of Object.entries(config)) {
46
+ const saved = recipe[key];
47
+ if (value === null || saved === undefined) {
48
+ result[key] = structuredClone(value);
49
+ }
50
+ else if (isRecord(value) && isRecord(saved)) {
51
+ const nested = privateReplayOverrides(value, saved);
52
+ if (Object.keys(nested).length > 0)
53
+ result[key] = nested;
54
+ }
55
+ }
56
+ return result;
57
+ }
40
58
  /** Provider definitions use a native file layer, never process arguments. */
41
59
  export async function createProviderProfile(codexHome, config, options = {}) {
42
- const providers = resolveCodexProfile(config)["model_providers"];
43
60
  const name = `codex_security_${randomUUID()}`;
44
- const path = join(codexHome, `${name}.config.toml`);
61
+ const path = join(codexHome, `${name}.config.${options.replay ? "json" : "toml"}`);
45
62
  if ((options.platform ?? process.platform) === "win32") {
46
63
  await mkdir(codexHome, { recursive: true, mode: 0o700 });
47
64
  await requirePrivateCredentialHome(await lstat(codexHome), codexHome, options);
48
65
  }
49
- await writeCodexConfig(path, {
50
- model_providers: isRecord(providers) ? providers : {},
51
- });
66
+ if (options.replay) {
67
+ await writePrivateConfig(path, JSON.stringify(config));
68
+ }
69
+ else {
70
+ const providers = resolveCodexProfile(config)["model_providers"];
71
+ await writeCodexConfig(path, {
72
+ model_providers: isRecord(providers) ? providers : {},
73
+ });
74
+ }
52
75
  return { name, path, cleanup: () => rm(path, { force: true }) };
53
76
  }
77
+ /** Restore private replay settings from the credential home, never scan artifacts. */
78
+ export async function restoreProviderProfile(config, profile, environment) {
79
+ if (profile === undefined)
80
+ return config;
81
+ if (!isRecord(profile) ||
82
+ typeof profile["name"] !== "string" ||
83
+ (profile["home"] !== "ambient" && profile["home"] !== "managed") ||
84
+ !/^codex_security_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u.test(profile["name"])) {
85
+ throw new CodexSecurityError("The saved scan contains an invalid provider profile.");
86
+ }
87
+ const codexHome = profile["home"] === "ambient"
88
+ ? configuredCodexHome(environment)
89
+ : codexSecurityCredentialHome(environment);
90
+ if (profile["home"] === "managed")
91
+ await requireSecureCredentialHome(codexHome);
92
+ let saved;
93
+ try {
94
+ saved = JSON.parse(await readFile(join(codexHome, `${profile["name"]}.config.json`), "utf8"));
95
+ }
96
+ catch (error) {
97
+ if (error.code !== "ENOENT")
98
+ throw error;
99
+ saved = parse(await readFile(join(codexHome, `${profile["name"]}.config.toml`), "utf8"));
100
+ }
101
+ if (!isRecord(saved) ||
102
+ (saved["model_providers"] !== undefined &&
103
+ saved["model_providers"] !== null &&
104
+ !isRecord(saved["model_providers"]))) {
105
+ throw new CodexSecurityError("The saved provider profile contains no provider configuration.");
106
+ }
107
+ const { model_providers: providers, ...overrides } = saved;
108
+ return {
109
+ ...deepMerge({ ...config }, overrides),
110
+ ...(providers === null ||
111
+ (isRecord(providers) && Object.keys(providers).length > 0)
112
+ ? { model_providers: providers }
113
+ : {}),
114
+ };
115
+ }
54
116
  /** The pinned SDK lacks the native CLI's private profile-file option. */
55
117
  export async function createProfileCodex(options, profileName, requestedPermissionProfile) {
56
118
  const command = options.codexPathOverride ?? resolveCodexCommand(options.env).command;
@@ -124,10 +186,10 @@ export async function withCodexPreflightLock(env, signal, operation) {
124
186
  await release();
125
187
  }
126
188
  }
127
- async function nativePermissionPreflight() {
189
+ export async function nativePermissionPreflight() {
128
190
  return await import(__rewriteRelativeImportExtension(pathToFileURL(join(await bundledPluginRoot(), "mcp", "permission-profile-preflight.mjs")).href));
129
191
  }
130
- async function nativeProfileClient() {
192
+ export async function nativeProfileClient() {
131
193
  return await import(__rewriteRelativeImportExtension(pathToFileURL(join(await bundledPluginRoot(), "scripts", "codex_profile.mjs")).href));
132
194
  }
133
195
  //# sourceMappingURL=provider-profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-profile.js","sourceRoot":"","sources":["../src/provider-profile.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,UAAU,EACV,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,sCAAsC,EACtC,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,GAEpB,MAAM,cAAc,CAAC;AAQtB,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAqB,EACrB,MAAkB;IAElB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,SAAS,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAC9C,IAAI,QAAQ,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,MAAM,GAAG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AAO,CAAC,MAAM,EAAE,CAAC;qBACvC;iBACF,CAAC;YACN,eAAe;YACf,MAAM,EAAE,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC,MAAM;YAC9C,OAAO,EAAE,QAAQ;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,GAAuC,EACvC,MAA+B,EAC/B,SAA2B;IAE3B,yEAAyE;IACzE,6EAA6E;IAC7E,MAAM,aAAa,GAAG,IAAI,CACxB,mBAAmB,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,EACvC,2BAA2B,CAC5B,CAAC;IACF,MAAM,KAAK,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,MAAM,sCAAsC,CAC1D,aAAa,EACb,MAAM,CACP,CAAC;IACF,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,EAAE,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,yBAAyB;IACtC,OAAO,MAAM,MAAM,kCACjB,aAAa,CACX,IAAI,CACF,MAAM,iBAAiB,EAAE,EACzB,KAAK,EACL,kCAAkC,CACnC,CACF,CAAC,IAAI,EACP,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,mBAAmB;IAChC,OAAO,MAAM,MAAM,kCACjB,aAAa,CACX,IAAI,CAAC,MAAM,iBAAiB,EAAE,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAChE,CAAC,IAAI,EACP,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { lstat, mkdir, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { Codex, CodexOptions } from \"@openai/codex-sdk\";\nimport { configuredCodexHome } from \"./auth.js\";\nimport {\n resolveCodexProfile,\n modelProviderConfigOverride,\n inlineToml,\n writeCodexConfig,\n type JsonObject,\n} from \"./config.js\";\nimport { isRecord } from \"./record.js\";\nimport { bundledCodexSdkEnvironment } from \"./codex-sdk-environment.js\";\nimport {\n bundledPluginRoot,\n acquireCodexSecurityCredentialHomeLock,\n executablePathForSpawn,\n requirePrivateCredentialHome,\n resolveCodexCommand,\n type CodexCommand,\n} from \"./runtime.js\";\n\nexport interface ProviderProfile {\n name: string;\n path: string;\n cleanup(): Promise<void>;\n}\n\n/** Native no-turn commands need provider metadata when managed policy selects it. */\nexport async function providerPreflightCommand(\n command: CodexCommand,\n config: JsonObject,\n): Promise<CodexCommand> {\n const resolved = resolveCodexProfile(config);\n const overrides: string[] = [];\n const providers = resolved[\"model_providers\"];\n if (isRecord(providers) && Object.keys(providers).length > 0) {\n const client = await nativeProfileClient();\n const definitions = client.preflightProviderDefinitions(\n providers,\n ) as JsonObject;\n overrides.push(\n ...modelProviderConfigOverride({ model_providers: definitions }),\n );\n }\n if (resolved[\"model_provider\"] !== undefined)\n overrides.push(`model_provider=${inlineToml(resolved[\"model_provider\"])}`);\n if (overrides.length === 0) return command;\n return {\n ...command,\n args: [\n ...(command.args ?? []),\n ...overrides.flatMap((value) => [\"-c\", value]),\n ],\n };\n}\n\n/** Provider definitions use a native file layer, never process arguments. */\nexport async function createProviderProfile(\n codexHome: string,\n config: JsonObject,\n options: Parameters<typeof requirePrivateCredentialHome>[2] = {},\n): Promise<ProviderProfile> {\n const providers = resolveCodexProfile(config)[\"model_providers\"];\n const name = `codex_security_${randomUUID()}`;\n const path = join(codexHome, `${name}.config.toml`);\n if ((options.platform ?? process.platform) === \"win32\") {\n await mkdir(codexHome, { recursive: true, mode: 0o700 });\n await requirePrivateCredentialHome(\n await lstat(codexHome),\n codexHome,\n options,\n );\n }\n await writeCodexConfig(path, {\n model_providers: isRecord(providers) ? providers : {},\n });\n return { name, path, cleanup: () => rm(path, { force: true }) };\n}\n\n/** The pinned SDK lacks the native CLI's private profile-file option. */\nexport async function createProfileCodex(\n options: CodexOptions,\n profileName: string,\n requestedPermissionProfile?: string,\n): Promise<Codex> {\n const command =\n options.codexPathOverride ?? resolveCodexCommand(options.env).command;\n const client = await nativeProfileClient();\n return client.createCodexProfileClient({\n ...options,\n codexPathOverride: executablePathForSpawn(command),\n profileName,\n requestedPermissionProfile,\n ...(options.env === undefined\n ? {}\n : { env: bundledCodexSdkEnvironment(command, options.env) }),\n }) as Codex;\n}\n\n/** Verify the effective helper policy before starting exec with a private profile. */\nexport async function preflightReadOnlyProfileCodex(\n options: CodexOptions,\n expectedProfile: JsonObject,\n providerConfig: JsonObject,\n cwd: string,\n signal?: AbortSignal,\n): Promise<{ permissionProfileId: string; configOverrides: string[] }> {\n const preflight = await nativePermissionPreflight();\n const permissionProfileId =\n preflight.DEEP_SCAN_WORKER_PERMISSION_PROFILE_ID as string;\n const configOverrides = [\n ...(options.configOverrides ?? []),\n `default_permissions=${JSON.stringify(permissionProfileId)}`,\n `permissions.${permissionProfileId}=${inlineToml(expectedProfile)}`,\n ];\n const command =\n options.codexPathOverride ?? resolveCodexCommand(options.env).command;\n const client = await nativeProfileClient();\n const providers = resolveCodexProfile(providerConfig)[\"model_providers\"];\n const definitions = isRecord(providers)\n ? (client.preflightProviderDefinitions(providers) as JsonObject)\n : {};\n const env =\n options.env === undefined\n ? undefined\n : bundledCodexSdkEnvironment(command, options.env);\n await withCodexPreflightLock(env, signal, async () => {\n await preflight.preflightDeepScanWorkerPermissionProfile({\n codexPath: executablePathForSpawn(command),\n cwd,\n configOverrides: [\n ...client.profileConfigOverrides(options.config ?? {}),\n ...configOverrides,\n ],\n providerConfigOverrides: modelProviderConfigOverride({\n model_providers: definitions,\n }),\n ...(env === undefined\n ? {}\n : {\n env: {\n ...env,\n ...(options.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: options.apiKey }),\n },\n }),\n expectedProfile,\n signal: signal ?? new AbortController().signal,\n context: \"helper\",\n });\n });\n return { permissionProfileId, configOverrides };\n}\n\nexport async function withCodexPreflightLock<T>(\n env: Record<string, string> | undefined,\n signal: AbortSignal | undefined,\n operation: () => Promise<T>,\n): Promise<T> {\n // App-server treats concurrent cold-home SQLite initialization as fatal.\n // Keep the lock in a private child so a readable native home stays readable.\n const lockDirectory = join(\n configuredCodexHome(env ?? process.env),\n \".codex-security-preflight\",\n );\n await mkdir(lockDirectory, { recursive: true, mode: 0o700 });\n const release = await acquireCodexSecurityCredentialHomeLock(\n lockDirectory,\n signal,\n );\n try {\n return await operation();\n } finally {\n await release();\n }\n}\n\nasync function nativePermissionPreflight() {\n return await import(\n pathToFileURL(\n join(\n await bundledPluginRoot(),\n \"mcp\",\n \"permission-profile-preflight.mjs\",\n ),\n ).href\n );\n}\n\nasync function nativeProfileClient() {\n return await import(\n pathToFileURL(\n join(await bundledPluginRoot(), \"scripts\", \"codex_profile.mjs\"),\n ).href\n );\n}\n"]}
1
+ {"version":3,"file":"provider-profile.js","sourceRoot":"","sources":["../src/provider-profile.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,2BAA2B,EAC3B,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,aAAa,CAAC;AACrB,O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D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,GAAuC,EACvC,MAA+B,EAC/B,SAA2B;IAE3B,yEAAyE;IACzE,6EAA6E;IAC7E,MAAM,aAAa,GAAG,IAAI,CACxB,mBAAmB,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,EACvC,2BAA2B,CAC5B,CAAC;IACF,MAAM,KAAK,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,MAAM,sCAAsC,CAC1D,aAAa,EACb,MAAM,CACP,CAAC;IACF,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,EAAE,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,OAAO,MAAM,MAAM,kCACjB,aAAa,CACX,IAAI,CACF,MAAM,iBAAiB,EAAE,EACzB,KAAK,EACL,kCAAkC,CACnC,CACF,CAAC,IAAI,EACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,OAAO,MAAM,MAAM,kCACjB,aAAa,CACX,IAAI,CAAC,MAAM,iBAAiB,EAAE,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAChE,CAAC,IAAI,EACP,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { lstat, mkdir, readFile, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { Codex, CodexOptions } from \"@openai/codex-sdk\";\nimport { parse } from \"smol-toml\";\nimport { configuredCodexHome } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n resolveCodexProfile,\n deepMerge,\n modelProviderConfigOverride,\n inlineToml,\n writeCodexConfig,\n writePrivateConfig,\n type JsonObject,\n} from \"./config.js\";\nimport { isRecord } from \"./record.js\";\nimport { bundledCodexSdkEnvironment } from \"./codex-sdk-environment.js\";\nimport {\n bundledPluginRoot,\n acquireCodexSecurityCredentialHomeLock,\n codexSecurityCredentialHome,\n executablePathForSpawn,\n requirePrivateCredentialHome,\n requireSecureCredentialHome,\n resolveCodexCommand,\n type CodexCommand,\n type ProcessEnvironment,\n} from \"./runtime.js\";\n\nexport interface ProviderProfile {\n name: string;\n path: string;\n cleanup(): Promise<void>;\n}\n\n/** Native no-turn commands need provider metadata when managed policy selects it. */\nexport async function providerPreflightCommand(\n command: CodexCommand,\n config: JsonObject,\n): Promise<CodexCommand> {\n const resolved = resolveCodexProfile(config);\n const overrides: string[] = [];\n const providers = resolved[\"model_providers\"];\n if (isRecord(providers) && Object.keys(providers).length > 0) {\n const client = await nativeProfileClient();\n const definitions = client.preflightProviderDefinitions(\n providers,\n ) as JsonObject;\n overrides.push(\n ...modelProviderConfigOverride({ model_providers: definitions }),\n );\n }\n if (resolved[\"model_provider\"] !== undefined)\n overrides.push(`model_provider=${inlineToml(resolved[\"model_provider\"])}`);\n if (overrides.length === 0) return command;\n return {\n ...command,\n args: [\n ...(command.args ?? []),\n ...overrides.flatMap((value) => [\"-c\", value]),\n ],\n };\n}\n\n/** Retain explicit settings omitted from the readable recipe when its file reloads. */\nexport function privateReplayOverrides(\n config: JsonObject,\n recipe: JsonObject,\n): JsonObject {\n const result: JsonObject = {};\n for (const [key, value] of Object.entries(config)) {\n const saved = recipe[key];\n if (value === null || saved === undefined) {\n result[key] = structuredClone(value);\n } else if (isRecord(value) && isRecord(saved)) {\n const nested = privateReplayOverrides(\n value as JsonObject,\n saved as JsonObject,\n );\n if (Object.keys(nested).length > 0) result[key] = nested;\n }\n }\n return result;\n}\n\n/** Provider definitions use a native file layer, never process arguments. */\nexport async function createProviderProfile(\n codexHome: string,\n config: JsonObject,\n options: Parameters<typeof requirePrivateCredentialHome>[2] & {\n replay?: boolean;\n } = {},\n): Promise<ProviderProfile> {\n const name = `codex_security_${randomUUID()}`;\n const path = join(\n codexHome,\n `${name}.config.${options.replay ? \"json\" : \"toml\"}`,\n );\n if ((options.platform ?? process.platform) === \"win32\") {\n await mkdir(codexHome, { recursive: true, mode: 0o700 });\n await requirePrivateCredentialHome(\n await lstat(codexHome),\n codexHome,\n options,\n );\n }\n if (options.replay) {\n await writePrivateConfig(path, JSON.stringify(config));\n } else {\n const providers = resolveCodexProfile(config)[\"model_providers\"];\n await writeCodexConfig(path, {\n model_providers: isRecord(providers) ? providers : {},\n });\n }\n return { name, path, cleanup: () => rm(path, { force: true }) };\n}\n\n/** Restore private replay settings from the credential home, never scan artifacts. */\nexport async function restoreProviderProfile(\n config: JsonObject,\n profile: unknown,\n environment: ProcessEnvironment,\n): Promise<JsonObject> {\n if (profile === undefined) return config;\n if (\n !isRecord(profile) ||\n typeof profile[\"name\"] !== \"string\" ||\n (profile[\"home\"] !== \"ambient\" && profile[\"home\"] !== \"managed\") ||\n !/^codex_security_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u.test(\n profile[\"name\"],\n )\n ) {\n throw new CodexSecurityError(\n \"The saved scan contains an invalid provider profile.\",\n );\n }\n const codexHome =\n profile[\"home\"] === \"ambient\"\n ? configuredCodexHome(environment)\n : codexSecurityCredentialHome(environment);\n if (profile[\"home\"] === \"managed\")\n await requireSecureCredentialHome(codexHome);\n let saved: unknown;\n try {\n saved = JSON.parse(\n await readFile(join(codexHome, `${profile[\"name\"]}.config.json`), \"utf8\"),\n );\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n saved = parse(\n await readFile(join(codexHome, `${profile[\"name\"]}.config.toml`), \"utf8\"),\n );\n }\n if (\n !isRecord(saved) ||\n (saved[\"model_providers\"] !== undefined &&\n saved[\"model_providers\"] !== null &&\n !isRecord(saved[\"model_providers\"]))\n ) {\n throw new CodexSecurityError(\n \"The saved provider profile contains no provider configuration.\",\n );\n }\n const { model_providers: providers, ...overrides } = saved;\n return {\n ...deepMerge({ ...config }, overrides as JsonObject),\n ...(providers === null ||\n (isRecord(providers) && Object.keys(providers).length > 0)\n ? { model_providers: providers as JsonObject | null }\n : {}),\n };\n}\n\n/** The pinned SDK lacks the native CLI's private profile-file option. */\nexport async function createProfileCodex(\n options: CodexOptions,\n profileName: string,\n requestedPermissionProfile?: string,\n): Promise<Codex> {\n const command =\n options.codexPathOverride ?? resolveCodexCommand(options.env).command;\n const client = await nativeProfileClient();\n return client.createCodexProfileClient({\n ...options,\n codexPathOverride: executablePathForSpawn(command),\n profileName,\n requestedPermissionProfile,\n ...(options.env === undefined\n ? {}\n : { env: bundledCodexSdkEnvironment(command, options.env) }),\n }) as Codex;\n}\n\n/** Verify the effective helper policy before starting exec with a private profile. */\nexport async function preflightReadOnlyProfileCodex(\n options: CodexOptions,\n expectedProfile: JsonObject,\n providerConfig: JsonObject,\n cwd: string,\n signal?: AbortSignal,\n): Promise<{ permissionProfileId: string; configOverrides: string[] }> {\n const preflight = await nativePermissionPreflight();\n const permissionProfileId =\n preflight.DEEP_SCAN_WORKER_PERMISSION_PROFILE_ID as string;\n const configOverrides = [\n ...(options.configOverrides ?? []),\n `default_permissions=${JSON.stringify(permissionProfileId)}`,\n `permissions.${permissionProfileId}=${inlineToml(expectedProfile)}`,\n ];\n const command =\n options.codexPathOverride ?? resolveCodexCommand(options.env).command;\n const client = await nativeProfileClient();\n const providers = resolveCodexProfile(providerConfig)[\"model_providers\"];\n const definitions = isRecord(providers)\n ? (client.preflightProviderDefinitions(providers) as JsonObject)\n : {};\n const env =\n options.env === undefined\n ? undefined\n : bundledCodexSdkEnvironment(command, options.env);\n await withCodexPreflightLock(env, signal, async () => {\n await preflight.preflightDeepScanWorkerPermissionProfile({\n codexPath: executablePathForSpawn(command),\n cwd,\n configOverrides: [\n ...client.profileConfigOverrides(options.config ?? {}),\n ...configOverrides,\n ],\n providerConfigOverrides: modelProviderConfigOverride({\n model_providers: definitions,\n }),\n ...(env === undefined\n ? {}\n : {\n env: {\n ...env,\n ...(options.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: options.apiKey }),\n },\n }),\n expectedProfile,\n signal: signal ?? new AbortController().signal,\n context: \"helper\",\n });\n });\n return { permissionProfileId, configOverrides };\n}\n\nexport async function withCodexPreflightLock<T>(\n env: Record<string, string> | undefined,\n signal: AbortSignal | undefined,\n operation: () => Promise<T>,\n): Promise<T> {\n // App-server treats concurrent cold-home SQLite initialization as fatal.\n // Keep the lock in a private child so a readable native home stays readable.\n const lockDirectory = join(\n configuredCodexHome(env ?? process.env),\n \".codex-security-preflight\",\n );\n await mkdir(lockDirectory, { recursive: true, mode: 0o700 });\n const release = await acquireCodexSecurityCredentialHomeLock(\n lockDirectory,\n signal,\n );\n try {\n return await operation();\n } finally {\n await release();\n }\n}\n\nexport async function nativePermissionPreflight() {\n return await import(\n pathToFileURL(\n join(\n await bundledPluginRoot(),\n \"mcp\",\n \"permission-profile-preflight.mjs\",\n ),\n ).href\n );\n}\n\nexport async function nativeProfileClient() {\n return await import(\n pathToFileURL(\n join(await bundledPluginRoot(), \"scripts\", \"codex_profile.mjs\"),\n ).href\n );\n}\n"]}
@@ -325,8 +325,14 @@ function immutableSourceUrl(target, location) {
325
325
  const repository = remote.pathname
326
326
  .replace(/\.git\/?$/, "")
327
327
  .replace(/\/$/, "");
328
- const path = location.path.split("/").map(encodeURIComponent).join("/");
328
+ const segments = location.path.split("/");
329
+ const path = segments.map(encodeURIComponent).join("/");
329
330
  remote.pathname = `${repository}/blob/${target.revision}/${path}`;
331
+ // GitHub renders Markdown previews without source line anchors.
332
+ const markdownPath = /\.(?:md|markdown|mdown|mdwn|mkd|mkdn|mkdown|mdx|litcoffee|livemd|ronn|scd|workbook)$/i;
333
+ if (markdownPath.test(location.path) || segments.at(-1) === "contents.lr") {
334
+ remote.search = "plain=1";
335
+ }
330
336
  remote.hash = `L${location.startLine}${location.endLine === undefined || location.endLine === location.startLine
331
337
  ? ""
332
338
  : `-L${location.endLine}`}`;