@openai/codex-security 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (484) hide show
  1. package/README.md +437 -2692
  2. package/_bundled_plugin/.app.json +5 -1
  3. package/_bundled_plugin/.codex-plugin/plugin.json +4 -0
  4. package/_bundled_plugin/.mcp.json +2 -0
  5. package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
  6. package/_bundled_plugin/examples/completed-scan/report.md +28 -26
  7. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
  8. package/_bundled_plugin/mcp/helpers.mjs +1 -0
  9. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +556 -0
  20. package/_bundled_plugin/mcp/server.mjs +1 -0
  21. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  22. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  23. package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
  24. package/_bundled_plugin/references/artifact-storage.md +2 -2
  25. package/_bundled_plugin/references/config-preflight.md +0 -4
  26. package/_bundled_plugin/references/core-scan.md +21 -9
  27. package/_bundled_plugin/references/final-report.md +11 -13
  28. package/_bundled_plugin/references/finding-detail-fields.md +90 -80
  29. package/_bundled_plugin/references/sarif-adapter.md +1 -1
  30. package/_bundled_plugin/references/scan-artifacts.md +1 -2
  31. package/_bundled_plugin/references/scan-contract.md +9 -4
  32. package/_bundled_plugin/references/scan-prologue.md +12 -0
  33. package/_bundled_plugin/references/security-guidance.md +2 -2
  34. package/_bundled_plugin/references/standalone-validation.md +11 -0
  35. package/_bundled_plugin/references/threat-model.md +1 -1
  36. package/_bundled_plugin/schemas/coverage.schema.json +43 -170
  37. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
  38. package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
  39. package/_bundled_plugin/schemas/findings.schema.json +159 -567
  40. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  41. package/_bundled_plugin/schemas/scan-manifest.schema.json +78 -220
  42. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
  43. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
  44. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
  45. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
  46. package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
  47. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
  48. package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
  49. package/_bundled_plugin/scripts/codex_session.mjs +53 -0
  50. package/_bundled_plugin/scripts/config_preflight.py +26 -62
  51. package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
  52. package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
  53. package/_bundled_plugin/scripts/finalize_scan_contract.py +321 -237
  54. package/_bundled_plugin/scripts/finding_preview.py +39 -9
  55. package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
  56. package/_bundled_plugin/scripts/generate_rank_input.py +115 -926
  57. package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
  58. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
  59. package/_bundled_plugin/scripts/rank_preview.py +42 -918
  60. package/_bundled_plugin/scripts/report_projection.py +150 -183
  61. package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
  62. package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
  63. package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
  64. package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
  65. package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
  66. package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
  67. package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
  68. package/_bundled_plugin/scripts/workbench/storage.py +10 -6
  69. package/_bundled_plugin/scripts/workbench_cli.py +102 -184
  70. package/_bundled_plugin/scripts/workbench_db.py +463 -464
  71. package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
  72. package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
  73. package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
  74. package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
  75. package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
  76. package/_bundled_plugin/scripts/workbench_progress.py +14 -58
  77. package/_bundled_plugin/scripts/workbench_publication.py +234 -289
  78. package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
  79. package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
  80. package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
  81. package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
  82. package/_bundled_plugin/scripts/workbench_scan_usage.py +194 -42
  83. package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
  84. package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
  85. package/_bundled_plugin/scripts/workbench_target.py +430 -142
  86. package/_bundled_plugin/scripts/workbench_validation.py +31 -28
  87. package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
  88. package/_bundled_plugin/shared/workbench-migrations.json +414 -0
  89. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
  90. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
  91. package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
  92. package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
  93. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  94. package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
  95. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
  96. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
  97. package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
  98. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  99. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +15 -1
  100. package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
  101. package/_bundled_plugin/skills/track-findings/SKILL.md +48 -176
  102. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
  103. package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
  104. package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
  105. package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
  106. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
  107. package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
  108. package/bin/codex-security.mjs +9 -2
  109. package/dist/api.d.ts +63 -10
  110. package/dist/api.d.ts.map +1 -1
  111. package/dist/api.js +1015 -383
  112. package/dist/api.js.map +1 -1
  113. package/dist/artifact-export.d.ts +1 -1
  114. package/dist/artifact-export.d.ts.map +1 -1
  115. package/dist/artifact-export.js +28 -13
  116. package/dist/artifact-export.js.map +1 -1
  117. package/dist/auth.d.ts +2 -6
  118. package/dist/auth.d.ts.map +1 -1
  119. package/dist/auth.js +19 -9
  120. package/dist/auth.js.map +1 -1
  121. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  122. package/dist/bulk-scan-discovery.js +1 -0
  123. package/dist/bulk-scan-discovery.js.map +1 -1
  124. package/dist/classify-severity.d.ts +26 -9
  125. package/dist/classify-severity.d.ts.map +1 -1
  126. package/dist/classify-severity.js +13 -30
  127. package/dist/classify-severity.js.map +1 -1
  128. package/dist/cli-help.d.ts.map +1 -1
  129. package/dist/cli-help.js +17 -13
  130. package/dist/cli-help.js.map +1 -1
  131. package/dist/cli-signals.d.ts +8 -0
  132. package/dist/cli-signals.d.ts.map +1 -0
  133. package/dist/cli-signals.js +28 -0
  134. package/dist/cli-signals.js.map +1 -0
  135. package/dist/cli.d.ts +4 -3
  136. package/dist/cli.d.ts.map +1 -1
  137. package/dist/cli.js +1102 -905
  138. package/dist/cli.js.map +1 -1
  139. package/dist/cloud-publish.d.ts.map +1 -1
  140. package/dist/cloud-publish.js +10 -9
  141. package/dist/cloud-publish.js.map +1 -1
  142. package/dist/codeowners.d.ts +19 -0
  143. package/dist/codeowners.d.ts.map +1 -0
  144. package/dist/codeowners.js +138 -0
  145. package/dist/codeowners.js.map +1 -0
  146. package/dist/codex-sdk-environment.d.ts +1 -0
  147. package/dist/codex-sdk-environment.d.ts.map +1 -1
  148. package/dist/codex-sdk-environment.js +40 -2
  149. package/dist/codex-sdk-environment.js.map +1 -1
  150. package/dist/component-plan.d.ts +2 -5
  151. package/dist/component-plan.d.ts.map +1 -1
  152. package/dist/component-plan.js +39 -31
  153. package/dist/component-plan.js.map +1 -1
  154. package/dist/component-scan.d.ts +6 -5
  155. package/dist/component-scan.d.ts.map +1 -1
  156. package/dist/component-scan.js +25 -36
  157. package/dist/component-scan.js.map +1 -1
  158. package/dist/config.d.ts.map +1 -1
  159. package/dist/config.js +64 -74
  160. package/dist/config.js.map +1 -1
  161. package/dist/contract.d.ts +16 -3
  162. package/dist/contract.d.ts.map +1 -1
  163. package/dist/contract.js +91 -255
  164. package/dist/contract.js.map +1 -1
  165. package/dist/cost-model.d.ts +13 -6
  166. package/dist/cost-model.d.ts.map +1 -1
  167. package/dist/cost-model.js +14 -4
  168. package/dist/cost-model.js.map +1 -1
  169. package/dist/cost.d.ts +10 -2
  170. package/dist/cost.d.ts.map +1 -1
  171. package/dist/cost.js +102 -104
  172. package/dist/cost.js.map +1 -1
  173. package/dist/custom-validation-prompt.d.ts.map +1 -1
  174. package/dist/custom-validation-prompt.js +6 -5
  175. package/dist/custom-validation-prompt.js.map +1 -1
  176. package/dist/custom-validation.d.ts +1 -2
  177. package/dist/custom-validation.d.ts.map +1 -1
  178. package/dist/custom-validation.js +9 -3
  179. package/dist/custom-validation.js.map +1 -1
  180. package/dist/deduplication/checkpointed-review.d.ts +4 -2
  181. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  182. package/dist/deduplication/checkpointed-review.js +23 -9
  183. package/dist/deduplication/checkpointed-review.js.map +1 -1
  184. package/dist/deduplication/codex-review.d.ts +8 -6
  185. package/dist/deduplication/codex-review.d.ts.map +1 -1
  186. package/dist/deduplication/codex-review.js +128 -19
  187. package/dist/deduplication/codex-review.js.map +1 -1
  188. package/dist/deduplication/deduplication-prompts.d.ts +5 -2
  189. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  190. package/dist/deduplication/deduplication-prompts.js +18 -4
  191. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  192. package/dist/deduplication/deduplication-reviewer.d.ts +27 -5
  193. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  194. package/dist/deduplication/deduplication-reviewer.js +58 -48
  195. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  196. package/dist/deduplication/deduplication.d.ts.map +1 -1
  197. package/dist/deduplication/deduplication.js +19 -51
  198. package/dist/deduplication/deduplication.js.map +1 -1
  199. package/dist/deduplication/diagnostics.d.ts +17 -0
  200. package/dist/deduplication/diagnostics.d.ts.map +1 -0
  201. package/dist/deduplication/diagnostics.js +5 -0
  202. package/dist/deduplication/diagnostics.js.map +1 -0
  203. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  204. package/dist/deduplication/finding-schema.js +7 -1
  205. package/dist/deduplication/finding-schema.js.map +1 -1
  206. package/dist/deduplication/local.d.ts +31 -0
  207. package/dist/deduplication/local.d.ts.map +1 -0
  208. package/dist/deduplication/local.js +166 -0
  209. package/dist/deduplication/local.js.map +1 -0
  210. package/dist/deduplication/records-protocol.d.ts +3 -8
  211. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  212. package/dist/deduplication/records-protocol.js +11 -184
  213. package/dist/deduplication/records-protocol.js.map +1 -1
  214. package/dist/deduplication/records.d.ts +186 -11
  215. package/dist/deduplication/records.d.ts.map +1 -1
  216. package/dist/deduplication/records.js +10 -18
  217. package/dist/deduplication/records.js.map +1 -1
  218. package/dist/deduplication/scan.d.ts +9 -3
  219. package/dist/deduplication/scan.d.ts.map +1 -1
  220. package/dist/deduplication/scan.js +158 -39
  221. package/dist/deduplication/scan.js.map +1 -1
  222. package/dist/deep-config.d.ts +2 -1
  223. package/dist/deep-config.d.ts.map +1 -1
  224. package/dist/deep-config.js +4 -4
  225. package/dist/deep-config.js.map +1 -1
  226. package/dist/deep-progress.d.ts +17 -1
  227. package/dist/deep-progress.d.ts.map +1 -1
  228. package/dist/deep-progress.js +19 -17
  229. package/dist/deep-progress.js.map +1 -1
  230. package/dist/deep-scan.d.ts +20 -0
  231. package/dist/deep-scan.d.ts.map +1 -0
  232. package/dist/deep-scan.js +113 -0
  233. package/dist/deep-scan.js.map +1 -0
  234. package/dist/errors.d.ts +2 -0
  235. package/dist/errors.d.ts.map +1 -1
  236. package/dist/errors.js +2 -0
  237. package/dist/errors.js.map +1 -1
  238. package/dist/executable-path.d.ts +2 -0
  239. package/dist/executable-path.d.ts.map +1 -0
  240. package/dist/executable-path.js +12 -0
  241. package/dist/executable-path.js.map +1 -0
  242. package/dist/feedback.d.ts +1 -4
  243. package/dist/feedback.d.ts.map +1 -1
  244. package/dist/feedback.js +54 -22
  245. package/dist/feedback.js.map +1 -1
  246. package/dist/finding-catalogue.d.ts.map +1 -1
  247. package/dist/finding-catalogue.js +4 -8
  248. package/dist/finding-catalogue.js.map +1 -1
  249. package/dist/finding-normalization.d.ts +5 -0
  250. package/dist/finding-normalization.d.ts.map +1 -0
  251. package/dist/finding-normalization.js +120 -0
  252. package/dist/finding-normalization.js.map +1 -0
  253. package/dist/finding-retrieval.d.ts +9 -0
  254. package/dist/finding-retrieval.d.ts.map +1 -1
  255. package/dist/finding-retrieval.js.map +1 -1
  256. package/dist/finding-workflow.d.ts +13 -8
  257. package/dist/finding-workflow.d.ts.map +1 -1
  258. package/dist/finding-workflow.js +14 -6
  259. package/dist/finding-workflow.js.map +1 -1
  260. package/dist/findings-client.d.ts +2 -1
  261. package/dist/findings-client.d.ts.map +1 -1
  262. package/dist/findings-client.js +36 -9
  263. package/dist/findings-client.js.map +1 -1
  264. package/dist/findings-errors.d.ts +16 -0
  265. package/dist/findings-errors.d.ts.map +1 -0
  266. package/dist/findings-errors.js +24 -0
  267. package/dist/findings-errors.js.map +1 -0
  268. package/dist/findings-import.d.ts +1 -1
  269. package/dist/findings-import.d.ts.map +1 -1
  270. package/dist/findings-import.js +12 -30
  271. package/dist/findings-import.js.map +1 -1
  272. package/dist/github.d.ts.map +1 -1
  273. package/dist/github.js +7 -1
  274. package/dist/github.js.map +1 -1
  275. package/dist/host-protocol.d.ts +19 -0
  276. package/dist/host-protocol.d.ts.map +1 -0
  277. package/dist/host-protocol.js +270 -0
  278. package/dist/host-protocol.js.map +1 -0
  279. package/dist/hosted-scan-protocol.d.ts +4 -0
  280. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  281. package/dist/hosted-scan-protocol.js +25 -0
  282. package/dist/hosted-scan-protocol.js.map +1 -0
  283. package/dist/hosted-scan.d.ts +117 -0
  284. package/dist/hosted-scan.d.ts.map +1 -0
  285. package/dist/hosted-scan.js +260 -0
  286. package/dist/hosted-scan.js.map +1 -0
  287. package/dist/import-scan.d.ts.map +1 -1
  288. package/dist/import-scan.js +48 -38
  289. package/dist/import-scan.js.map +1 -1
  290. package/dist/index.d.ts +11 -4
  291. package/dist/index.d.ts.map +1 -1
  292. package/dist/index.js +2 -1
  293. package/dist/index.js.map +1 -1
  294. package/dist/knowledge-base.d.ts +7 -1
  295. package/dist/knowledge-base.d.ts.map +1 -1
  296. package/dist/knowledge-base.js +114 -46
  297. package/dist/knowledge-base.js.map +1 -1
  298. package/dist/linear.d.ts.map +1 -1
  299. package/dist/linear.js +2 -7
  300. package/dist/linear.js.map +1 -1
  301. package/dist/mock-scan.d.ts.map +1 -1
  302. package/dist/mock-scan.js +0 -1
  303. package/dist/mock-scan.js.map +1 -1
  304. package/dist/models.d.ts +0 -2
  305. package/dist/models.d.ts.map +1 -1
  306. package/dist/models.js.map +1 -1
  307. package/dist/multiscan.d.ts +9 -3
  308. package/dist/multiscan.d.ts.map +1 -1
  309. package/dist/multiscan.js +240 -135
  310. package/dist/multiscan.js.map +1 -1
  311. package/dist/owner-evidence.d.ts +10 -2
  312. package/dist/owner-evidence.d.ts.map +1 -1
  313. package/dist/owner-evidence.js +67 -8
  314. package/dist/owner-evidence.js.map +1 -1
  315. package/dist/patch-tui.d.ts.map +1 -1
  316. package/dist/patch-tui.js +3 -2
  317. package/dist/patch-tui.js.map +1 -1
  318. package/dist/project-config.js +3 -3
  319. package/dist/project-config.js.map +1 -1
  320. package/dist/provider-profile.d.ts +21 -0
  321. package/dist/provider-profile.d.ts.map +1 -0
  322. package/dist/provider-profile.js +133 -0
  323. package/dist/provider-profile.js.map +1 -0
  324. package/dist/publication-events.d.ts +6 -8
  325. package/dist/publication-events.d.ts.map +1 -1
  326. package/dist/publication-events.js +25 -50
  327. package/dist/publication-events.js.map +1 -1
  328. package/dist/publication-store.d.ts.map +1 -1
  329. package/dist/publication-store.js +95 -109
  330. package/dist/publication-store.js.map +1 -1
  331. package/dist/publication.d.ts +1 -4
  332. package/dist/publication.d.ts.map +1 -1
  333. package/dist/publication.js +2 -13
  334. package/dist/publication.js.map +1 -1
  335. package/dist/publish.d.ts +1 -5
  336. package/dist/publish.d.ts.map +1 -1
  337. package/dist/publish.js +109 -160
  338. package/dist/publish.js.map +1 -1
  339. package/dist/request-metadata.d.ts +9 -0
  340. package/dist/request-metadata.d.ts.map +1 -0
  341. package/dist/request-metadata.js +13 -0
  342. package/dist/request-metadata.js.map +1 -0
  343. package/dist/runtime.d.ts +20 -6
  344. package/dist/runtime.d.ts.map +1 -1
  345. package/dist/runtime.js +407 -148
  346. package/dist/runtime.js.map +1 -1
  347. package/dist/saved-scan-bootstrap.d.ts +14 -0
  348. package/dist/saved-scan-bootstrap.d.ts.map +1 -0
  349. package/dist/saved-scan-bootstrap.js +261 -0
  350. package/dist/saved-scan-bootstrap.js.map +1 -0
  351. package/dist/saved-scan.d.ts +1 -1
  352. package/dist/saved-scan.d.ts.map +1 -1
  353. package/dist/saved-scan.js +6 -12
  354. package/dist/saved-scan.js.map +1 -1
  355. package/dist/scan-activity.js +11 -8
  356. package/dist/scan-activity.js.map +1 -1
  357. package/dist/scan-comparison.d.ts +28 -15
  358. package/dist/scan-comparison.d.ts.map +1 -1
  359. package/dist/scan-comparison.js +276 -281
  360. package/dist/scan-comparison.js.map +1 -1
  361. package/dist/scan-dashboard.d.ts +3 -0
  362. package/dist/scan-dashboard.d.ts.map +1 -1
  363. package/dist/scan-dashboard.js +345 -77
  364. package/dist/scan-dashboard.js.map +1 -1
  365. package/dist/scan-executor.d.ts +104 -0
  366. package/dist/scan-executor.d.ts.map +1 -0
  367. package/dist/scan-executor.js +62 -0
  368. package/dist/scan-executor.js.map +1 -0
  369. package/dist/scan-history-renderer.d.ts.map +1 -1
  370. package/dist/scan-history-renderer.js +54 -13
  371. package/dist/scan-history-renderer.js.map +1 -1
  372. package/dist/scan-inputs.d.ts +6 -0
  373. package/dist/scan-inputs.d.ts.map +1 -0
  374. package/dist/scan-inputs.js +71 -0
  375. package/dist/scan-inputs.js.map +1 -0
  376. package/dist/scan-logs.d.ts +2 -3
  377. package/dist/scan-logs.d.ts.map +1 -1
  378. package/dist/scan-logs.js +12 -6
  379. package/dist/scan-logs.js.map +1 -1
  380. package/dist/scan-sessions.d.ts +4 -0
  381. package/dist/scan-sessions.d.ts.map +1 -1
  382. package/dist/scan-sessions.js +17 -0
  383. package/dist/scan-sessions.js.map +1 -1
  384. package/dist/scan-skill-paths.d.ts +8 -0
  385. package/dist/scan-skill-paths.d.ts.map +1 -0
  386. package/dist/scan-skill-paths.js +47 -0
  387. package/dist/scan-skill-paths.js.map +1 -0
  388. package/dist/security-policy-cli.d.ts.map +1 -1
  389. package/dist/security-policy-cli.js +7 -27
  390. package/dist/security-policy-cli.js.map +1 -1
  391. package/dist/security-policy.d.ts +9 -5
  392. package/dist/security-policy.d.ts.map +1 -1
  393. package/dist/security-policy.js +33 -14
  394. package/dist/security-policy.js.map +1 -1
  395. package/dist/server/api.d.ts +0 -1
  396. package/dist/server/api.d.ts.map +1 -1
  397. package/dist/server/api.js +0 -1
  398. package/dist/server/api.js.map +1 -1
  399. package/dist/server/embeddings.d.ts +3 -1
  400. package/dist/server/embeddings.d.ts.map +1 -1
  401. package/dist/server/embeddings.js +10 -3
  402. package/dist/server/embeddings.js.map +1 -1
  403. package/dist/server/errors.d.ts +5 -2
  404. package/dist/server/errors.d.ts.map +1 -1
  405. package/dist/server/errors.js +7 -0
  406. package/dist/server/errors.js.map +1 -1
  407. package/dist/server/sqlite-store.d.ts +0 -2
  408. package/dist/server/sqlite-store.d.ts.map +1 -1
  409. package/dist/server/sqlite-store.js +54 -44
  410. package/dist/server/sqlite-store.js.map +1 -1
  411. package/dist/server/storage.d.ts +0 -2
  412. package/dist/server/storage.d.ts.map +1 -1
  413. package/dist/server/storage.js.map +1 -1
  414. package/dist/severity-store.js +19 -24
  415. package/dist/severity-store.js.map +1 -1
  416. package/dist/standalone-validation-prompt.d.ts +2 -0
  417. package/dist/standalone-validation-prompt.d.ts.map +1 -0
  418. package/dist/standalone-validation-prompt.js +10 -0
  419. package/dist/standalone-validation-prompt.js.map +1 -0
  420. package/dist/suggest-owners.d.ts +4 -2
  421. package/dist/suggest-owners.d.ts.map +1 -1
  422. package/dist/suggest-owners.js +11 -5
  423. package/dist/suggest-owners.js.map +1 -1
  424. package/dist/targets.d.ts +11 -0
  425. package/dist/targets.d.ts.map +1 -1
  426. package/dist/targets.js +123 -72
  427. package/dist/targets.js.map +1 -1
  428. package/dist/trusted-executable.d.ts +2 -2
  429. package/dist/trusted-executable.d.ts.map +1 -1
  430. package/dist/trusted-executable.js +8 -6
  431. package/dist/trusted-executable.js.map +1 -1
  432. package/dist/value.js +7 -0
  433. package/dist/value.js.map +1 -1
  434. package/dist/version.js.map +1 -1
  435. package/dist/workbench-arguments.d.ts +3 -0
  436. package/dist/workbench-arguments.d.ts.map +1 -0
  437. package/dist/workbench-arguments.js +15 -0
  438. package/dist/workbench-arguments.js.map +1 -0
  439. package/dist/worker-progress.d.ts +44 -11
  440. package/dist/worker-progress.d.ts.map +1 -1
  441. package/dist/worker-progress.js +48 -49
  442. package/dist/worker-progress.js.map +1 -1
  443. package/docs/cli.md +1788 -0
  444. package/docs/findings-service.md +402 -0
  445. package/docs/hosted-scans.md +242 -0
  446. package/package.json +23 -22
  447. package/schemas/hosted-scan-v2.fixture.json +145 -0
  448. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
  449. package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
  450. package/_bundled_plugin/scripts/workbench_findings.py +0 -221
  451. package/_bundled_plugin/scripts/workbench_severity.py +0 -122
  452. package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
  453. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
  454. package/dist/server/dashboard/app.css +0 -2
  455. package/dist/server/dashboard/app.js +0 -66
  456. package/dist/server/dashboard/index.html +0 -18
  457. package/dist/server/dashboard-types.d.ts +0 -48
  458. package/dist/server/dashboard-types.d.ts.map +0 -1
  459. package/dist/server/dashboard-types.js +0 -2
  460. package/dist/server/dashboard-types.js.map +0 -1
  461. package/dist/server/dashboard.d.ts +0 -6
  462. package/dist/server/dashboard.d.ts.map +0 -1
  463. package/dist/server/dashboard.js +0 -59
  464. package/dist/server/dashboard.js.map +0 -1
  465. package/dist/server/index.d.ts +0 -2
  466. package/dist/server/index.d.ts.map +0 -1
  467. package/dist/server/index.js +0 -6
  468. package/dist/server/index.js.map +0 -1
  469. package/dist/server/routes.d.ts +0 -7
  470. package/dist/server/routes.d.ts.map +0 -1
  471. package/dist/server/routes.js +0 -98
  472. package/dist/server/routes.js.map +0 -1
  473. package/dist/server/serve.d.ts +0 -2
  474. package/dist/server/serve.d.ts.map +0 -1
  475. package/dist/server/serve.js +0 -28
  476. package/dist/server/serve.js.map +0 -1
  477. package/dist/server/server.d.ts +0 -10
  478. package/dist/server/server.d.ts.map +0 -1
  479. package/dist/server/server.js +0 -16
  480. package/dist/server/server.js.map +0 -1
  481. package/dist/server/validation.d.ts +0 -17
  482. package/dist/server/validation.d.ts.map +0 -1
  483. package/dist/server/validation.js +0 -53
  484. package/dist/server/validation.js.map +0 -1
@@ -1,9 +1,12 @@
1
1
  import { basename, isAbsolute } from "node:path";
2
+ import { emitKeypressEvents } from "node:readline";
3
+ import { PassThrough } from "node:stream";
2
4
  import { pathToFileURL } from "node:url";
3
- import { stripVTControlCharacters } from "node:util";
5
+ import stripAnsi from "strip-ansi";
6
+ import stringWidth from "string-width";
4
7
  import { isRecord } from "./record.js";
5
8
  import { formatUsd } from "./cost.js";
6
- import { estimateScanCost, formatScanCost, formatScanCosts, formatScanCostTokens, } from "./cost-model.js";
9
+ import { estimateScanCost, formatScanCost, formatScanCosts, formatScanCostTokens, formatTokenUsage, } from "./cost-model.js";
7
10
  import { scanPhaseLabel } from "./worker-progress.js";
8
11
  const HIDE_CURSOR = "\u001B[?25l";
9
12
  const SHOW_CURSOR = "\u001B[?25h";
@@ -44,14 +47,17 @@ export class ScanDashboard {
44
47
  #showComponent = false;
45
48
  #componentResult = null;
46
49
  #activities = [];
50
+ #activityCache = new WeakMap();
47
51
  #details = [];
48
52
  #detailsCache = null;
49
53
  #stage = "Preparing scan";
50
54
  #files = null;
51
55
  #publicationProgress = null;
52
56
  #cost = null;
57
+ #tokens = null;
53
58
  #budget = null;
54
59
  #timer = null;
60
+ #refreshPending = false;
55
61
  #scrollOffset = 0;
56
62
  #view = "activity";
57
63
  #source = "all";
@@ -59,11 +65,119 @@ export class ScanDashboard {
59
65
  #noteCount = 0;
60
66
  #observingStreamErrors = false;
61
67
  #onStreamError = () => { };
68
+ #keyInput = null;
69
+ #ss3Parameters = false;
70
+ #inputKeys = null;
62
71
  #onInput = (chunk) => {
63
- const input = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
72
+ const batch = {
73
+ keys: [],
74
+ continued: false,
75
+ replay: false,
76
+ text: "",
77
+ };
78
+ let current = chunk;
79
+ do {
80
+ batch.replay = false;
81
+ this.#inputKeys = batch;
82
+ try {
83
+ this.#keyInput?.write(current);
84
+ }
85
+ finally {
86
+ this.#inputKeys = null;
87
+ }
88
+ if (typeof batch.replay === "string")
89
+ current = batch.replay;
90
+ } while (batch.replay);
91
+ this.#handleKeys(batch.keys);
92
+ };
93
+ #setKeyInput(input) {
94
+ const previous = this.#keyInput;
95
+ if (previous !== null) {
96
+ previous.removeAllListeners("keypress");
97
+ previous.on("keypress", () => { });
98
+ // Readline clears its Escape timer on input, after the active keypress returns.
99
+ queueMicrotask(() => {
100
+ previous.write(" ");
101
+ previous.removeAllListeners();
102
+ previous.destroy();
103
+ });
104
+ }
105
+ this.#keyInput = input;
106
+ if (input === null)
107
+ return;
108
+ let pending = 0;
109
+ this.#ss3Parameters = false;
110
+ input.setEncoding("utf8");
111
+ input.on("data", (text) => {
112
+ if (this.#inputKeys !== null) {
113
+ this.#inputKeys.continued = pending > 0;
114
+ this.#inputKeys.text = text;
115
+ }
116
+ pending += text.length;
117
+ });
118
+ emitKeypressEvents(input);
119
+ input.on("keypress", (_text, key) => {
120
+ pending -= key.sequence.length;
121
+ if (this.#ss3Parameters) {
122
+ if (/^[ -?]+$/u.test(key.sequence))
123
+ return;
124
+ this.#ss3Parameters = false;
125
+ if (/^[@-~]$/u.test(key.sequence))
126
+ return;
127
+ }
128
+ const escapes = key.code === undefined
129
+ ? undefined
130
+ : key.sequence.match(/^\u001B+(?=\u001B)/u)?.[0];
131
+ // Readline ends modified SS3 keys at the parameter separator.
132
+ const modifiedSs3 = key.code !== undefined &&
133
+ /^\u001BO[0-?]+$/u.test(key.sequence.slice(escapes?.length ?? 0));
134
+ if (modifiedSs3)
135
+ this.#ss3Parameters = true;
136
+ const keys = modifiedSs3
137
+ ? [...(escapes ?? ""), key.sequence.slice(escapes?.length ?? 0)]
138
+ : key.code !== undefined && key.sequence.endsWith("\u001B")
139
+ ? ["\u001B"]
140
+ : (key.meta && key.code === undefined) ||
141
+ key.sequence.includes("\u0003")
142
+ ? Array.from(key.sequence)
143
+ : escapes !== undefined
144
+ ? [...escapes, key.sequence.slice(escapes.length)]
145
+ : [key.sequence];
146
+ const batch = this.#inputKeys;
147
+ const continued = batch?.continued === true;
148
+ if (batch !== null)
149
+ batch.continued = false;
150
+ if (batch === null)
151
+ this.#handleKeys(keys);
152
+ else if (this.#budget !== null &&
153
+ batch.keys.length === 0 &&
154
+ keys.length > 1 &&
155
+ keys[0] === "\u001B" &&
156
+ continued) {
157
+ // The buffered Escape belongs to the prior chunk's budget dismissal.
158
+ // Replay the complete remaining key, including a prefix from prior chunks.
159
+ this.#handleKeys(["\u001B"]);
160
+ this.#setKeyInput(new PassThrough());
161
+ batch.replay =
162
+ key.sequence.slice(1) + (pending ? batch.text.slice(-pending) : "");
163
+ }
164
+ else if (keys.length > 1 && keys.every((key) => key === "\u001B")) {
165
+ // Readline can consume a following key's Escape as a repeated Escape.
166
+ // Keep that introducer with the remaining decoded text for replay.
167
+ const remaining = key.sequence + (pending ? batch.text.slice(-pending) : "");
168
+ const prefix = remaining.match(/^\u001B+/u)[0];
169
+ for (const escape of prefix.slice(0, -1))
170
+ batch.keys.push(escape);
171
+ this.#setKeyInput(new PassThrough());
172
+ batch.replay = remaining.slice(prefix.length - 1);
173
+ }
174
+ else
175
+ batch.keys.push(...keys);
176
+ });
177
+ }
178
+ #handleKeys(keys) {
64
179
  if (this.#budget !== null) {
65
- for (const key of input.match(/\u001B\[[0-?]*[ -/]*[@-~]|[\s\S]/gu) ??
66
- []) {
180
+ for (const key of keys) {
67
181
  const budget = this.#budget;
68
182
  if (budget === null)
69
183
  break;
@@ -72,7 +186,7 @@ export class ScanDashboard {
72
186
  this.#options.onInterrupt?.();
73
187
  }
74
188
  else if (key === "\u001B") {
75
- budget.finish();
189
+ budget.finish(undefined, true);
76
190
  }
77
191
  else if (key === "\r" || key === "\n") {
78
192
  const value = budget.input.trim();
@@ -99,11 +213,11 @@ export class ScanDashboard {
99
213
  return;
100
214
  }
101
215
  if (this.#options.presentation === "components") {
102
- this.#componentInput(input);
216
+ this.#componentInput(keys);
103
217
  return;
104
218
  }
105
219
  let lines = 0;
106
- for (const key of input.match(/[\u0003\u0004\u0015dam1-9]|\u001B\[(?:[ABHF]|[1456]~)/gu) ?? []) {
220
+ for (const key of keys) {
107
221
  if (key === "\u0003") {
108
222
  if (lines !== 0)
109
223
  this.scroll(lines);
@@ -147,7 +261,7 @@ export class ScanDashboard {
147
261
  else if (key === "\u001B[6~") {
148
262
  lines -= this.#activityRows();
149
263
  }
150
- else {
264
+ else if (["\u001B[H", "\u001B[F", "\u001B[1~", "\u001B[4~"].includes(key)) {
151
265
  if (lines !== 0)
152
266
  this.scroll(lines);
153
267
  this.scroll(key === "\u001B[H" || key === "\u001B[1~"
@@ -158,7 +272,7 @@ export class ScanDashboard {
158
272
  }
159
273
  if (lines !== 0)
160
274
  this.scroll(lines);
161
- };
275
+ }
162
276
  constructor(stream, options) {
163
277
  this.#stream = stream;
164
278
  this.#options = options;
@@ -179,12 +293,13 @@ export class ScanDashboard {
179
293
  }
180
294
  this.#stream.write(`${ENTER_ALTERNATE_SCREEN}${HIDE_CURSOR}`);
181
295
  if (input?.isTTY === true) {
296
+ this.#setKeyInput(new PassThrough());
182
297
  input.setRawMode?.(true);
183
298
  input.resume?.();
184
299
  input.on("data", this.#onInput);
185
300
  this.#stream.write(ENABLE_ALTERNATE_SCROLL);
186
301
  }
187
- this.#render();
302
+ this.#stream.write(this.#frame());
188
303
  }
189
304
  catch (error) {
190
305
  try {
@@ -202,6 +317,8 @@ export class ScanDashboard {
202
317
  stop() {
203
318
  if (this.#timer === null)
204
319
  return;
320
+ if (this.#refreshPending)
321
+ this.#refresh();
205
322
  this.#options.clock.clearInterval(this.#timer);
206
323
  this.#timer = null;
207
324
  this.#budget?.finish();
@@ -209,6 +326,7 @@ export class ScanDashboard {
209
326
  try {
210
327
  if (input?.isTTY === true) {
211
328
  input.off("data", this.#onInput);
329
+ this.#setKeyInput(null);
212
330
  input.setRawMode?.(this.#inputWasRaw);
213
331
  input.pause?.();
214
332
  }
@@ -291,6 +409,9 @@ export class ScanDashboard {
291
409
  case "cost":
292
410
  dashboard.setCost(event.value);
293
411
  break;
412
+ case "usage":
413
+ dashboard.setUsage(event.value);
414
+ break;
294
415
  case "workers":
295
416
  if (event.value.kind === "dispatch")
296
417
  dashboard.setStage(scanPhaseLabel(event.value.phase));
@@ -299,7 +420,7 @@ export class ScanDashboard {
299
420
  dashboard.note(event.value);
300
421
  break;
301
422
  }
302
- this.#refresh();
423
+ this.#scheduleRefresh();
303
424
  }
304
425
  showComponents(stage) {
305
426
  this.#showComponent = false;
@@ -307,10 +428,8 @@ export class ScanDashboard {
307
428
  }
308
429
  finishComponents(result) {
309
430
  this.#componentResult = result;
310
- this.showComponents(result.failed ||
311
- result.incomplete ||
312
- result.deduplication?.status === "incomplete"
313
- ? "Finished with partial results"
431
+ this.showComponents(result.failed || result.deduplication?.status === "failed"
432
+ ? "Finished with errors"
314
433
  : "Complete");
315
434
  }
316
435
  setFiles(files) {
@@ -323,9 +442,14 @@ export class ScanDashboard {
323
442
  }
324
443
  setCost(cost, maxCostUsd = this.#options.maxCostUsd) {
325
444
  this.#cost = cost;
445
+ this.#tokens = formatScanCostTokens(cost);
326
446
  this.#options.maxCostUsd = maxCostUsd;
327
447
  this.#refresh();
328
448
  }
449
+ setUsage(usage) {
450
+ this.#tokens = formatTokenUsage(usage);
451
+ this.#refresh();
452
+ }
329
453
  requestBudgetIncrease(request) {
330
454
  if (request.signal.aborted ||
331
455
  this.#timer === null ||
@@ -333,11 +457,14 @@ export class ScanDashboard {
333
457
  this.#budget !== null) {
334
458
  return Promise.resolve(undefined);
335
459
  }
460
+ this.#setKeyInput(new PassThrough());
336
461
  return new Promise((resolve) => {
337
462
  const abort = () => finish();
338
- const finish = (limit) => {
463
+ const finish = (limit, preserveInput = false) => {
339
464
  request.signal.removeEventListener("abort", abort);
340
465
  this.#budget = null;
466
+ if (this.#timer !== null && !preserveInput)
467
+ this.#setKeyInput(new PassThrough());
341
468
  this.#refresh();
342
469
  resolve(limit);
343
470
  };
@@ -377,7 +504,7 @@ export class ScanDashboard {
377
504
  if (this.#scrollOffset !== 0) {
378
505
  this.#scrollOffset += Math.max(0, this.#activityLines(this.#width()).length - previousRows);
379
506
  }
380
- this.#refresh();
507
+ this.#scheduleRefresh();
381
508
  }
382
509
  recordDetails(session) {
383
510
  const previousRows = this.#view === "details" && this.#scrollOffset !== 0
@@ -400,7 +527,7 @@ export class ScanDashboard {
400
527
  if (this.#scrollOffset !== 0) {
401
528
  this.#scrollOffset += Math.max(0, this.#activityLines(this.#width()).length - previousRows);
402
529
  }
403
- this.#refresh();
530
+ this.#scheduleRefresh();
404
531
  }
405
532
  }
406
533
  scroll(lines) {
@@ -412,12 +539,18 @@ export class ScanDashboard {
412
539
  if (this.#timer === null)
413
540
  return;
414
541
  try {
415
- this.#render();
542
+ this.#stream.write(this.#frame());
416
543
  }
417
544
  catch { }
418
545
  }
419
- #render() {
420
- this.#stream.write(this.#frame());
546
+ #scheduleRefresh() {
547
+ if (this.#timer === null || this.#refreshPending)
548
+ return;
549
+ this.#refreshPending = true;
550
+ (this.#options.clock.queueMicrotask ?? queueMicrotask)(() => {
551
+ this.#refreshPending = false;
552
+ this.#refresh();
553
+ });
421
554
  }
422
555
  #frame() {
423
556
  if (this.#options.presentation === "components") {
@@ -436,7 +569,9 @@ export class ScanDashboard {
436
569
  const time = formatElapsed(elapsed);
437
570
  const files = this.#files === null
438
571
  ? "waiting for inventory"
439
- : `${formatCount(this.#files.filesCompleted)} / ${formatCount(this.#files.filesTotal)} reviewed`;
572
+ : this.#files.filesCompleted > 0
573
+ ? `${formatCount(this.#files.filesCompleted)} / ${formatCount(this.#files.filesTotal)} reviewed`
574
+ : `${formatCount(this.#files.filesTotal)} in scope`;
440
575
  const history = this.#activityLines(width);
441
576
  const maximumOffset = Math.max(0, history.length - activityRows);
442
577
  this.#scrollOffset = Math.min(this.#scrollOffset, maximumOffset);
@@ -507,13 +642,13 @@ export class ScanDashboard {
507
642
  ? colored
508
643
  : linkActivity(this.#options.color === true
509
644
  ? styleInlineCode(colored, line)
510
- : colored, line.links);
645
+ : colored, line.links, line.contentStart);
511
646
  return `${ERASE_LINE}${formatted}`;
512
647
  })
513
648
  .join("\n"));
514
649
  }
515
- #componentInput(input) {
516
- for (const key of input.match(/\u001B\[(?:[ABHF]|[1456]~)|[\u0003\u0004\u0015\r\n\u001Bbdam1-9]/gu) ?? []) {
650
+ #componentInput(keys) {
651
+ for (const key of keys) {
517
652
  if (key === "\u0003") {
518
653
  this.#options.onInterrupt?.();
519
654
  }
@@ -521,7 +656,9 @@ export class ScanDashboard {
521
656
  if (key === "\u001B" || key === "b")
522
657
  this.#showComponent = false;
523
658
  else
524
- this.#components[this.#selectedComponent].dashboard.#onInput(key);
659
+ this.#components[this.#selectedComponent].dashboard.#handleKeys([
660
+ key,
661
+ ]);
525
662
  }
526
663
  else if ((key === "\r" || key === "\n") &&
527
664
  this.#components.length > 0) {
@@ -555,7 +692,11 @@ export class ScanDashboard {
555
692
  const first = Math.max(0, Math.min(this.#selectedComponent - Math.floor(rows / 2), this.#components.length - rows));
556
693
  const costWidth = Math.max(8, ...this.#components.map(({ dashboard }) => dashboard.#cost === null ? 1 : formatScanCost(dashboard.#cost).length));
557
694
  const nameWidth = Math.max(10, width - 52 - (this.#showCost ? costWidth + 1 : 0));
558
- const row = (marker, name, status, files, findings, cost) => ` ${marker} ${fitLine(name, nameWidth).padEnd(nameWidth)} ${fitLine(status, 24).padEnd(24)} ${files.padStart(11)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;
695
+ const cell = (value, width) => {
696
+ const text = fitLine(value, width);
697
+ return text + " ".repeat(width - stringWidth(text));
698
+ };
699
+ const row = (marker, name, status, files, findings, cost) => ` ${marker} ${cell(name, nameWidth)} ${cell(status, 24)} ${files.padStart(11)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;
559
700
  const table = this.#components
560
701
  .slice(first, first + rows)
561
702
  .map(({ receipt, dashboard }, index) => {
@@ -578,12 +719,12 @@ export class ScanDashboard {
578
719
  const rawFindings = this.#components.reduce((sum, { receipt }) => sum + (receipt.findingCount ?? 0), 0);
579
720
  const findings = this.#componentResult === null
580
721
  ? `${rawFindings} findings before deduplication`
581
- : `${this.#componentResult.sourceFindingCount} findings → ${this.#componentResult.findingCount} groups${this.#componentResult.deduplication?.status === "incomplete" ? " · matching incomplete" : ""}`;
722
+ : `${this.#componentResult.sourceFindingCount} findings → ${this.#componentResult.findingCount} groups${this.#componentResult.deduplication?.status === "failed" ? " · matching failed" : ""}`;
582
723
  const divider = ` ${"─".repeat(Math.max(0, width - 4))}`;
583
724
  return this.#formatFrame([
584
725
  ` CODEX SECURITY · COMPONENTS · ${basename(this.#options.repository)}`,
585
726
  divider,
586
- ` ${count("completed")} complete · ${count("started")} running · ${count("pending")} queued · ${count("incomplete")} incomplete · ${count("failed")} failed`,
727
+ ` ${count("completed")} complete · ${count("started")} running · ${count("pending")} queued · ${count("failed")} failed`,
587
728
  "",
588
729
  row(" ", "Component", "Status", "Files", "Findings", "Cost"),
589
730
  ...table,
@@ -615,29 +756,31 @@ export class ScanDashboard {
615
756
  this.#options.presentation === "verification"
616
757
  ? 0
617
758
  : this.#tokenLines().length - 1 + this.#costLines().length - 1) +
618
- (this.#options.presentation === "publication"
759
+ (this.#options.presentation === "publication" ||
760
+ this.#options.presentation === "verification"
619
761
  ? 2
620
762
  : this.#options.mode === "deep"
621
763
  ? 2
622
764
  : 0));
623
765
  }
624
766
  #tokenLines() {
625
- const tokens = this.#cost === null
626
- ? "waiting for usage"
627
- : formatScanCostTokens(this.#cost);
767
+ const tokens = this.#tokens ?? "waiting for usage";
628
768
  return wrapActivity(" TOKENS ", tokens, this.#width());
629
769
  }
630
770
  #costLines() {
631
771
  if (!this.#showCost)
632
772
  return [];
773
+ if (this.#cost === null &&
774
+ this.#options.maxCostUsd === undefined &&
775
+ estimateScanCost(this.#options.model?.model, {
776
+ input_tokens: 0,
777
+ output_tokens: 0,
778
+ }) === null) {
779
+ return [];
780
+ }
633
781
  const cost = this.#cost === null
634
782
  ? this.#options.maxCostUsd === undefined
635
- ? estimateScanCost(this.#options.model?.model, {
636
- input_tokens: 0,
637
- output_tokens: 0,
638
- }) === null
639
- ? "unavailable (model pricing missing)"
640
- : "waiting for usage"
783
+ ? "waiting for usage"
641
784
  : `— / ${formatUsd(this.#options.maxCostUsd)}`
642
785
  : `${formatScanCost(this.#cost)}${this.#options.maxCostUsd === undefined ? "" : `; short-context budget baseline: ${formatUsd(this.#cost.estimatedUsd)} / ${formatUsd(this.#options.maxCostUsd)} · ${budgetBar(this.#cost.estimatedUsd, this.#options.maxCostUsd)}`}`;
643
786
  return wrapActivity(" COST ", cost, this.#width());
@@ -699,7 +842,7 @@ export class ScanDashboard {
699
842
  cache.summaries.delete(threadId);
700
843
  }
701
844
  const source = worker === undefined ? "main" : `worker ${worker}`;
702
- const prefix = ` [${formatLocalTime(recordedAt)}] ${source} · `;
845
+ const prefix = fitActivityPrefix(` [${formatLocalTime(recordedAt)}] ${source} · `, width);
703
846
  const code = [];
704
847
  const bold = [];
705
848
  if (prose) {
@@ -714,7 +857,13 @@ export class ScanDashboard {
714
857
  ? wrapActivity(prefix, description, width)
715
858
  : paragraphs.flatMap((line, index) => wrapCode(index === 0 ? prefix : " ".repeat(prefix.length), line, width));
716
859
  for (const text of lines) {
717
- cache.lines.push({ text, kind: "path", code, bold });
860
+ cache.lines.push({
861
+ text,
862
+ kind: "path",
863
+ code,
864
+ bold,
865
+ contentStart: prefix.length,
866
+ });
718
867
  }
719
868
  }
720
869
  return cache.lines;
@@ -722,7 +871,8 @@ export class ScanDashboard {
722
871
  const elapsed = Math.max(0, Math.floor((this.#options.clock.now() - this.#startedAt) / 1_000));
723
872
  const runningIcon = ["◐", "◓", "◑", "◒"][elapsed % 4];
724
873
  const lines = [];
725
- const append = (prefix, value, kind) => {
874
+ const append = (prefix, value, kind, generatedPrefix = "") => {
875
+ prefix = fitActivityPrefix(prefix, width);
726
876
  if (kind !== "message" && kind !== "reasoning") {
727
877
  for (const text of wrapActivity(prefix, value, width)) {
728
878
  lines.push({ text, kind });
@@ -753,7 +903,16 @@ export class ScanDashboard {
753
903
  ? wrapCode(started ? continuation : prefix, description, width)
754
904
  : wrapActivity(started ? continuation : prefix, description, width);
755
905
  for (const text of wrapped) {
756
- lines.push({ text, kind: fenced ? "code" : kind, links, code });
906
+ lines.push({
907
+ text,
908
+ kind: fenced ? "code" : kind,
909
+ links,
910
+ code,
911
+ contentStart: prefix.length + generatedPrefix.length,
912
+ });
913
+ generatedPrefix = generatedPrefix
914
+ .slice(text.length - prefix.length)
915
+ .trimStart();
757
916
  started = true;
758
917
  }
759
918
  }
@@ -769,13 +928,25 @@ export class ScanDashboard {
769
928
  : entry.status === "running"
770
929
  ? runningIcon
771
930
  : ACTIVITY_MARKERS[kind];
931
+ const cached = this.#activityCache.get(entry);
932
+ if (cached?.width === width && cached.icon === icon) {
933
+ for (const line of cached.lines)
934
+ lines.push(line);
935
+ continue;
936
+ }
937
+ const first = lines.length;
772
938
  const timestamp = `[${formatLocalTime(entry.recordedAt)}]`;
773
939
  const worker = entry.worker === undefined ? "" : `worker ${entry.worker} · `;
774
940
  const prefix = ` ${timestamp} ${icon} `;
775
- append(prefix, `${worker}${entry.description}`, kind);
941
+ append(prefix, `${worker}${entry.description}`, kind, worker);
776
942
  for (const path of entry.paths) {
777
943
  append(" ".repeat(prefix.length), path, "path");
778
944
  }
945
+ this.#activityCache.set(entry, {
946
+ width,
947
+ icon,
948
+ lines: lines.slice(first),
949
+ });
779
950
  }
780
951
  return lines;
781
952
  }
@@ -837,20 +1008,40 @@ function detailsText(value) {
837
1008
  .flatMap((item) => isRecord(item) && typeof item["text"] === "string" ? [item["text"]] : [])
838
1009
  .join("\n");
839
1010
  }
1011
+ function replaceVisibleText(value, search, replacement, contentStart = 0) {
1012
+ let replaced = false;
1013
+ let offset = 0;
1014
+ return value
1015
+ .split(/(\u001B\[[0-?]*[ -/]*[@-~]|\u001B\][\s\S]*?(?:\u0007|\u001B\\))/gu)
1016
+ .map((part, index) => {
1017
+ if (index % 2 === 1)
1018
+ return part;
1019
+ const start = Math.max(0, contentStart - offset);
1020
+ offset += part.length;
1021
+ if (replaced || start >= part.length)
1022
+ return part;
1023
+ return (part.slice(0, start) +
1024
+ part.slice(start).replace(search, () => {
1025
+ replaced = true;
1026
+ return replacement;
1027
+ }));
1028
+ })
1029
+ .join("");
1030
+ }
840
1031
  function styleInlineCode(value, line) {
841
1032
  for (const text of line.bold ?? []) {
842
- value = value.replace(text, `\u001B[1m${text}\u001B[22m`);
1033
+ value = replaceVisibleText(value, text, `\u001B[1m${text}\u001B[22m`, line.contentStart);
843
1034
  }
844
1035
  for (const text of line.code ?? []) {
845
- value = value.replace(text, `\u001B[2m${text}\u001B[22m${line.kind === "message" ? "\u001B[1m" : ""}`);
1036
+ value = replaceVisibleText(value, text, `\u001B[2m${text}\u001B[22m${line.kind === "message" ? "\u001B[1m" : ""}`, line.contentStart);
846
1037
  }
847
1038
  return value;
848
1039
  }
849
- function linkActivity(value, links) {
1040
+ function linkActivity(value, links, contentStart) {
850
1041
  for (const { label, target } of links ?? []) {
851
1042
  const safe = safeHyperlinkTarget(target);
852
1043
  if (safe !== undefined) {
853
- value = value.replace(label, `\u001B]8;;${safe}\u0007${label}\u001B]8;;\u0007`);
1044
+ value = replaceVisibleText(value, label, `\u001B]8;;${safe}\u0007${label}\u001B]8;;\u0007`, contentStart);
854
1045
  }
855
1046
  }
856
1047
  return value;
@@ -880,7 +1071,6 @@ function componentStatus(receipt) {
880
1071
  pending: "Queued",
881
1072
  started: "Running",
882
1073
  completed: "Complete",
883
- incomplete: "Incomplete",
884
1074
  failed: "Failed",
885
1075
  }[receipt.status];
886
1076
  }
@@ -890,8 +1080,12 @@ function formatLocalTime(timestamp) {
890
1080
  .map((part) => String(part).padStart(2, "0"))
891
1081
  .join(":");
892
1082
  }
1083
+ function fitActivityPrefix(prefix, width) {
1084
+ return width <= 2 ? "" : fitLine(prefix, width - 2);
1085
+ }
893
1086
  function wrapActivity(prefix, value, width) {
894
- const available = Math.max(1, width - prefix.length);
1087
+ prefix = fitActivityPrefix(prefix, width);
1088
+ const available = Math.max(1, width - stringWidth(prefix));
895
1089
  const continuation = " ".repeat(prefix.length);
896
1090
  const lines = [];
897
1091
  const append = (text) => {
@@ -899,36 +1093,50 @@ function wrapActivity(prefix, value, width) {
899
1093
  };
900
1094
  let current = "";
901
1095
  let separator = "";
902
- for (const word of value.split(/(\s+)/u)) {
1096
+ let currentWidth = 0;
1097
+ const widths = new Map();
1098
+ const wrappedWords = new Map();
1099
+ const text = terminalText(value);
1100
+ const segments = graphemes.segment(text);
1101
+ let offset = 0;
1102
+ for (const word of text.split(/(\s+)/u)) {
1103
+ const start = offset;
1104
+ offset += word.length;
903
1105
  if (/^\s+$/u.test(word)) {
904
1106
  separator = word;
905
1107
  continue;
906
1108
  }
907
- const characters = Array.from(word);
908
- if (characters.length > available) {
1109
+ const ascii = /^[\u0020-\u007E]*$/u.test(word);
1110
+ let parts = ascii ? undefined : wrappedWords.get(word);
1111
+ if (!ascii && parts === undefined) {
1112
+ parts = columnChunks(word, available, widths, segments, start);
1113
+ wrappedWords.set(word, parts);
1114
+ }
1115
+ const wordWidth = ascii
1116
+ ? word.length
1117
+ : parts.length > 1
1118
+ ? available + 1
1119
+ : parts[0].columns;
1120
+ if (wordWidth > available) {
909
1121
  if (current !== "") {
910
1122
  append(current);
911
1123
  current = "";
912
1124
  }
913
- for (let start = 0; start < characters.length; start += available) {
914
- const part = characters.slice(start, start + available).join("");
915
- if (start + available < characters.length) {
916
- append(part);
917
- }
918
- else {
919
- current = part;
920
- }
921
- }
1125
+ const chunks = parts ?? columnChunks(word, available, widths, segments, start);
1126
+ const last = chunks.at(-1);
1127
+ current = last.text;
1128
+ currentWidth = last.columns;
1129
+ for (let index = 0; index < chunks.length - 1; index++)
1130
+ append(chunks[index].text);
922
1131
  }
923
1132
  else if (current !== "" &&
924
- Array.from(current).length +
925
- Array.from(separator).length +
926
- characters.length >
927
- available) {
1133
+ currentWidth + stringWidth(separator) + wordWidth > available) {
928
1134
  append(current);
929
1135
  current = word;
1136
+ currentWidth = wordWidth;
930
1137
  }
931
1138
  else {
1139
+ currentWidth += (current === "" ? 0 : stringWidth(separator)) + wordWidth;
932
1140
  current = current === "" ? word : `${current}${separator}${word}`;
933
1141
  }
934
1142
  separator = "";
@@ -937,12 +1145,62 @@ function wrapActivity(prefix, value, width) {
937
1145
  append(current);
938
1146
  return lines;
939
1147
  }
1148
+ const graphemes = new Intl.Segmenter();
1149
+ function columnChunks(value, width, widths = new Map(), segments = graphemes.segment(value), offset = 0) {
1150
+ const parts = [];
1151
+ let current = "";
1152
+ let columns = 0;
1153
+ const append = (text, size) => {
1154
+ if (current !== "" && columns + size > width) {
1155
+ parts.push({ text: current, columns });
1156
+ current = "";
1157
+ columns = 0;
1158
+ }
1159
+ current += text;
1160
+ columns += size;
1161
+ };
1162
+ const appendGraphemes = (start, end) => {
1163
+ while (start < end) {
1164
+ const next = segments.containing(offset + start);
1165
+ const boundary = Math.min(end, next.index + next.segment.length - offset);
1166
+ const segment = value.slice(start, boundary);
1167
+ let size = widths.get(segment);
1168
+ if (size === undefined) {
1169
+ size = stringWidth(segment);
1170
+ widths.set(segment, size);
1171
+ }
1172
+ append(segment, size);
1173
+ start = boundary;
1174
+ }
1175
+ };
1176
+ let cursor = 0;
1177
+ for (const match of value.matchAll(/[\u0020-\u007E]{2,}/gu)) {
1178
+ // Keep edge characters with Unicode that can attach to their grapheme.
1179
+ appendGraphemes(cursor, match.index + 1);
1180
+ let start = match.index + 1;
1181
+ const end = match.index + match[0].length - 1;
1182
+ while (start < end) {
1183
+ if (columns >= width) {
1184
+ parts.push({ text: current, columns });
1185
+ current = "";
1186
+ columns = 0;
1187
+ }
1188
+ const size = Math.min(width - columns, end - start);
1189
+ append(value.slice(start, start + size), size);
1190
+ start += size;
1191
+ }
1192
+ cursor = end;
1193
+ }
1194
+ appendGraphemes(cursor, value.length);
1195
+ if (current !== "" || parts.length === 0)
1196
+ parts.push({ text: current, columns });
1197
+ return parts;
1198
+ }
940
1199
  function wrapCode(prefix, value, width) {
941
- const characters = Array.from(value);
942
- const available = Math.max(1, width - prefix.length);
943
- return Array.from({ length: Math.max(1, Math.ceil(characters.length / available)) }, (_, index) => `${index === 0 ? prefix : " ".repeat(prefix.length)}${characters
944
- .slice(index * available, (index + 1) * available)
945
- .join("")}`);
1200
+ prefix = fitActivityPrefix(prefix, width);
1201
+ const prefixWidth = stringWidth(prefix);
1202
+ const continuation = " ".repeat(prefixWidth);
1203
+ return columnChunks(terminalText(value), Math.max(1, width - prefixWidth)).map((part, index) => `${index === 0 ? prefix : continuation}${part.text}`);
946
1204
  }
947
1205
  function styleLine(value, kind, details = false) {
948
1206
  if (details) {
@@ -990,11 +1248,21 @@ function budgetBar(cost, limit) {
990
1248
  const filled = Math.round(proportion * 12);
991
1249
  return `[${"█".repeat(filled)}${"░".repeat(12 - filled)}] ${Math.round(proportion * 100)}%`;
992
1250
  }
1251
+ function terminalText(value) {
1252
+ return stripAnsi(value).replaceAll(/[\u0000-\u001F\u007F]/gu, " ");
1253
+ }
993
1254
  function fitLine(value, width) {
994
- const clean = stripVTControlCharacters(value).replaceAll(/[\u0000-\u001F\u007F]/gu, " ");
995
- const characters = Array.from(clean);
996
- return characters.length <= width
997
- ? clean
998
- : `${characters.slice(0, Math.max(0, width - 1)).join("")}…`;
1255
+ const clean = terminalText(value);
1256
+ if (stringWidth(clean) <= width)
1257
+ return clean;
1258
+ let clipped = "";
1259
+ let columns = 0;
1260
+ for (const { segment } of graphemes.segment(clean)) {
1261
+ columns += stringWidth(segment);
1262
+ if (columns > width - 1)
1263
+ break;
1264
+ clipped += segment;
1265
+ }
1266
+ return `${clipped}…`;
999
1267
  }
1000
1268
  //# sourceMappingURL=scan-dashboard.js.map