@openai/codex-security 0.1.30 → 0.2.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 (320) hide show
  1. package/README.md +386 -37
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  15. package/_bundled_plugin/references/artifact-storage.md +4 -4
  16. package/_bundled_plugin/references/config-preflight.md +1 -1
  17. package/_bundled_plugin/references/core-scan.md +14 -2
  18. package/_bundled_plugin/references/final-report.md +4 -2
  19. package/_bundled_plugin/references/scan-artifacts.md +2 -2
  20. package/_bundled_plugin/references/scan-contract.md +2 -2
  21. package/_bundled_plugin/references/threat-model.md +2 -2
  22. package/_bundled_plugin/schemas/coverage.schema.json +22 -0
  23. package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
  24. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +19 -4
  25. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
  26. package/_bundled_plugin/scripts/config_preflight.py +4 -8
  27. package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
  28. package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
  29. package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
  30. package/_bundled_plugin/scripts/finding_preview.py +42 -82
  31. package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
  32. package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
  33. package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
  34. package/_bundled_plugin/scripts/rank_preview.py +86 -68
  35. package/_bundled_plugin/scripts/report_projection.py +37 -58
  36. package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
  37. package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
  38. package/_bundled_plugin/scripts/workbench/storage.py +11 -0
  39. package/_bundled_plugin/scripts/workbench_cli.py +11 -17
  40. package/_bundled_plugin/scripts/workbench_constants.py +6 -14
  41. package/_bundled_plugin/scripts/workbench_db.py +116 -228
  42. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
  43. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
  44. package/_bundled_plugin/scripts/workbench_progress.py +12 -34
  45. package/_bundled_plugin/scripts/workbench_publication.py +47 -62
  46. package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
  47. package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
  48. package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
  49. package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
  50. package/_bundled_plugin/scripts/workbench_schema.py +86 -271
  51. package/_bundled_plugin/scripts/workbench_severity.py +3 -0
  52. package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
  53. package/_bundled_plugin/scripts/workbench_target.py +98 -10
  54. package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
  55. package/_bundled_plugin/scripts/workbench_validation.py +6 -20
  56. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  57. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
  58. package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
  59. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  60. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  61. package/dist/api.d.ts +3 -5
  62. package/dist/api.d.ts.map +1 -1
  63. package/dist/api.js +201 -207
  64. package/dist/api.js.map +1 -1
  65. package/dist/artifact-export.d.ts +70 -0
  66. package/dist/artifact-export.d.ts.map +1 -0
  67. package/dist/artifact-export.js +277 -0
  68. package/dist/artifact-export.js.map +1 -0
  69. package/dist/auth.d.ts.map +1 -1
  70. package/dist/auth.js +9 -4
  71. package/dist/auth.js.map +1 -1
  72. package/dist/bulk-scan-discovery.d.ts +1 -0
  73. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  74. package/dist/bulk-scan-discovery.js +8 -9
  75. package/dist/bulk-scan-discovery.js.map +1 -1
  76. package/dist/classify-scan-severity.d.ts.map +1 -1
  77. package/dist/classify-scan-severity.js +2 -5
  78. package/dist/classify-scan-severity.js.map +1 -1
  79. package/dist/classify-severity.d.ts +2 -8
  80. package/dist/classify-severity.d.ts.map +1 -1
  81. package/dist/classify-severity.js +3 -5
  82. package/dist/classify-severity.js.map +1 -1
  83. package/dist/cli-help.d.ts +3 -0
  84. package/dist/cli-help.d.ts.map +1 -0
  85. package/dist/cli-help.js +281 -0
  86. package/dist/cli-help.js.map +1 -0
  87. package/dist/cli.d.ts +21 -22
  88. package/dist/cli.d.ts.map +1 -1
  89. package/dist/cli.js +673 -701
  90. package/dist/cli.js.map +1 -1
  91. package/dist/cloud-publish.d.ts.map +1 -1
  92. package/dist/cloud-publish.js +1 -8
  93. package/dist/cloud-publish.js.map +1 -1
  94. package/dist/codex-prompt.d.ts.map +1 -1
  95. package/dist/codex-prompt.js +1 -2
  96. package/dist/codex-prompt.js.map +1 -1
  97. package/dist/codex-sdk-environment.d.ts +2 -0
  98. package/dist/codex-sdk-environment.d.ts.map +1 -0
  99. package/dist/codex-sdk-environment.js +30 -0
  100. package/dist/codex-sdk-environment.js.map +1 -0
  101. package/dist/component-plan.d.ts.map +1 -1
  102. package/dist/component-plan.js +2 -6
  103. package/dist/component-plan.js.map +1 -1
  104. package/dist/component-scan.d.ts +1 -0
  105. package/dist/component-scan.d.ts.map +1 -1
  106. package/dist/component-scan.js +31 -9
  107. package/dist/component-scan.js.map +1 -1
  108. package/dist/config.d.ts.map +1 -1
  109. package/dist/config.js +32 -33
  110. package/dist/config.js.map +1 -1
  111. package/dist/contract.d.ts +2 -1
  112. package/dist/contract.d.ts.map +1 -1
  113. package/dist/contract.js +63 -122
  114. package/dist/contract.js.map +1 -1
  115. package/dist/cost-model.d.ts.map +1 -1
  116. package/dist/cost-model.js +65 -34
  117. package/dist/cost-model.js.map +1 -1
  118. package/dist/cost.d.ts.map +1 -1
  119. package/dist/cost.js +15 -31
  120. package/dist/cost.js.map +1 -1
  121. package/dist/custom-validation-prompt.js +4 -4
  122. package/dist/custom-validation-prompt.js.map +1 -1
  123. package/dist/custom-validation.d.ts.map +1 -1
  124. package/dist/custom-validation.js +17 -16
  125. package/dist/custom-validation.js.map +1 -1
  126. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  127. package/dist/deduplication/checkpointed-review.js +10 -11
  128. package/dist/deduplication/checkpointed-review.js.map +1 -1
  129. package/dist/deduplication/codex-review.d.ts +2 -0
  130. package/dist/deduplication/codex-review.d.ts.map +1 -1
  131. package/dist/deduplication/codex-review.js +3 -3
  132. package/dist/deduplication/codex-review.js.map +1 -1
  133. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  134. package/dist/deduplication/deduplication-reviewer.js +2 -0
  135. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  136. package/dist/deduplication/deduplication.js +40 -62
  137. package/dist/deduplication/deduplication.js.map +1 -1
  138. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  139. package/dist/deduplication/records-protocol.js +1 -4
  140. package/dist/deduplication/records-protocol.js.map +1 -1
  141. package/dist/deduplication/records.d.ts +2 -1
  142. package/dist/deduplication/records.d.ts.map +1 -1
  143. package/dist/deduplication/records.js +24 -6
  144. package/dist/deduplication/records.js.map +1 -1
  145. package/dist/deduplication/review.d.ts +7 -0
  146. package/dist/deduplication/review.d.ts.map +1 -1
  147. package/dist/deduplication/review.js.map +1 -1
  148. package/dist/deduplication/scan.js +3 -7
  149. package/dist/deduplication/scan.js.map +1 -1
  150. package/dist/deep-config.d.ts.map +1 -1
  151. package/dist/deep-config.js +3 -19
  152. package/dist/deep-config.js.map +1 -1
  153. package/dist/deep-progress.d.ts +0 -1
  154. package/dist/deep-progress.d.ts.map +1 -1
  155. package/dist/deep-progress.js +22 -40
  156. package/dist/deep-progress.js.map +1 -1
  157. package/dist/errors.d.ts +3 -2
  158. package/dist/errors.d.ts.map +1 -1
  159. package/dist/errors.js +5 -7
  160. package/dist/errors.js.map +1 -1
  161. package/dist/finding-catalogue.d.ts.map +1 -1
  162. package/dist/finding-catalogue.js +22 -22
  163. package/dist/finding-catalogue.js.map +1 -1
  164. package/dist/finding-workflow.d.ts.map +1 -1
  165. package/dist/finding-workflow.js +4 -7
  166. package/dist/finding-workflow.js.map +1 -1
  167. package/dist/findings-import.d.ts.map +1 -1
  168. package/dist/findings-import.js +7 -17
  169. package/dist/findings-import.js.map +1 -1
  170. package/dist/github.d.ts.map +1 -1
  171. package/dist/github.js +2 -3
  172. package/dist/github.js.map +1 -1
  173. package/dist/import-scan.js +2 -2
  174. package/dist/import-scan.js.map +1 -1
  175. package/dist/index.d.ts +6 -2
  176. package/dist/index.d.ts.map +1 -1
  177. package/dist/index.js +3 -1
  178. package/dist/index.js.map +1 -1
  179. package/dist/knowledge-base.js +7 -3
  180. package/dist/knowledge-base.js.map +1 -1
  181. package/dist/linear.d.ts.map +1 -1
  182. package/dist/linear.js +2 -3
  183. package/dist/linear.js.map +1 -1
  184. package/dist/models.d.ts +24 -0
  185. package/dist/models.d.ts.map +1 -1
  186. package/dist/models.js.map +1 -1
  187. package/dist/multiscan.d.ts.map +1 -1
  188. package/dist/multiscan.js +36 -31
  189. package/dist/multiscan.js.map +1 -1
  190. package/dist/owner-evidence.d.ts +29 -0
  191. package/dist/owner-evidence.d.ts.map +1 -0
  192. package/dist/owner-evidence.js +192 -0
  193. package/dist/owner-evidence.js.map +1 -0
  194. package/dist/patch-tui.d.ts.map +1 -1
  195. package/dist/patch-tui.js +2 -4
  196. package/dist/patch-tui.js.map +1 -1
  197. package/dist/project-config-schema.d.ts +10 -0
  198. package/dist/project-config-schema.d.ts.map +1 -1
  199. package/dist/project-config-schema.js +1 -0
  200. package/dist/project-config-schema.js.map +1 -1
  201. package/dist/project-config.d.ts +1 -0
  202. package/dist/project-config.d.ts.map +1 -1
  203. package/dist/project-config.js +2 -0
  204. package/dist/project-config.js.map +1 -1
  205. package/dist/prompt-files.d.ts +0 -1
  206. package/dist/prompt-files.d.ts.map +1 -1
  207. package/dist/prompt-files.js +2 -4
  208. package/dist/prompt-files.js.map +1 -1
  209. package/dist/publication-events.d.ts.map +1 -1
  210. package/dist/publication-events.js +15 -29
  211. package/dist/publication-events.js.map +1 -1
  212. package/dist/publication-store.d.ts.map +1 -1
  213. package/dist/publication-store.js +9 -13
  214. package/dist/publication-store.js.map +1 -1
  215. package/dist/publication.d.ts.map +1 -1
  216. package/dist/publication.js +11 -14
  217. package/dist/publication.js.map +1 -1
  218. package/dist/publish.d.ts.map +1 -1
  219. package/dist/publish.js +31 -41
  220. package/dist/publish.js.map +1 -1
  221. package/dist/record.d.ts +2 -0
  222. package/dist/record.d.ts.map +1 -0
  223. package/dist/record.js +4 -0
  224. package/dist/record.js.map +1 -0
  225. package/dist/result.d.ts +4 -1
  226. package/dist/result.d.ts.map +1 -1
  227. package/dist/result.js +7 -0
  228. package/dist/result.js.map +1 -1
  229. package/dist/runtime.d.ts +10 -13
  230. package/dist/runtime.d.ts.map +1 -1
  231. package/dist/runtime.js +230 -145
  232. package/dist/runtime.js.map +1 -1
  233. package/dist/saved-scan.d.ts.map +1 -1
  234. package/dist/saved-scan.js +10 -20
  235. package/dist/saved-scan.js.map +1 -1
  236. package/dist/scan-activity.d.ts.map +1 -1
  237. package/dist/scan-activity.js +8 -22
  238. package/dist/scan-activity.js.map +1 -1
  239. package/dist/scan-comparison.d.ts +4 -4
  240. package/dist/scan-comparison.d.ts.map +1 -1
  241. package/dist/scan-comparison.js +38 -73
  242. package/dist/scan-comparison.js.map +1 -1
  243. package/dist/scan-dashboard.d.ts +0 -1
  244. package/dist/scan-dashboard.d.ts.map +1 -1
  245. package/dist/scan-dashboard.js +10 -19
  246. package/dist/scan-dashboard.js.map +1 -1
  247. package/dist/scan-history-renderer.d.ts.map +1 -1
  248. package/dist/scan-history-renderer.js +1 -2
  249. package/dist/scan-history-renderer.js.map +1 -1
  250. package/dist/scan-logs.d.ts.map +1 -1
  251. package/dist/scan-logs.js +2 -6
  252. package/dist/scan-logs.js.map +1 -1
  253. package/dist/scan-sessions.d.ts.map +1 -1
  254. package/dist/scan-sessions.js +1 -3
  255. package/dist/scan-sessions.js.map +1 -1
  256. package/dist/scan-settings.d.ts +5 -0
  257. package/dist/scan-settings.d.ts.map +1 -1
  258. package/dist/scan-settings.js +4 -0
  259. package/dist/scan-settings.js.map +1 -1
  260. package/dist/security-policy-cli.d.ts.map +1 -1
  261. package/dist/security-policy-cli.js +8 -6
  262. package/dist/security-policy-cli.js.map +1 -1
  263. package/dist/security-policy.d.ts +8 -4
  264. package/dist/security-policy.d.ts.map +1 -1
  265. package/dist/security-policy.js +98 -84
  266. package/dist/security-policy.js.map +1 -1
  267. package/dist/server/dashboard/app.js +5 -5
  268. package/dist/server/embeddings.d.ts.map +1 -1
  269. package/dist/server/embeddings.js +1 -0
  270. package/dist/server/embeddings.js.map +1 -1
  271. package/dist/server/routes.d.ts +3 -2
  272. package/dist/server/routes.d.ts.map +1 -1
  273. package/dist/server/routes.js +19 -7
  274. package/dist/server/routes.js.map +1 -1
  275. package/dist/server/server.d.ts.map +1 -1
  276. package/dist/server/server.js +2 -3
  277. package/dist/server/server.js.map +1 -1
  278. package/dist/server/sqlite-store.d.ts.map +1 -1
  279. package/dist/server/sqlite-store.js +4 -14
  280. package/dist/server/sqlite-store.js.map +1 -1
  281. package/dist/severity-store.js +8 -15
  282. package/dist/severity-store.js.map +1 -1
  283. package/dist/suggest-owners.d.ts +37 -0
  284. package/dist/suggest-owners.d.ts.map +1 -0
  285. package/dist/suggest-owners.js +111 -0
  286. package/dist/suggest-owners.js.map +1 -0
  287. package/dist/targets.d.ts +7 -2
  288. package/dist/targets.d.ts.map +1 -1
  289. package/dist/targets.js +29 -25
  290. package/dist/targets.js.map +1 -1
  291. package/dist/thread-source.d.ts +1 -0
  292. package/dist/thread-source.d.ts.map +1 -1
  293. package/dist/thread-source.js +1 -0
  294. package/dist/thread-source.js.map +1 -1
  295. package/dist/trusted-executable.d.ts +5 -0
  296. package/dist/trusted-executable.d.ts.map +1 -1
  297. package/dist/trusted-executable.js +22 -5
  298. package/dist/trusted-executable.js.map +1 -1
  299. package/dist/value.d.ts +2 -0
  300. package/dist/value.d.ts.map +1 -0
  301. package/dist/value.js +20 -0
  302. package/dist/value.js.map +1 -0
  303. package/dist/version.d.ts.map +1 -1
  304. package/dist/version.js +3 -6
  305. package/dist/version.js.map +1 -1
  306. package/dist/windows-path.d.ts.map +1 -1
  307. package/dist/windows-path.js +1 -2
  308. package/dist/windows-path.js.map +1 -1
  309. package/dist/worker-progress.d.ts +1 -0
  310. package/dist/worker-progress.d.ts.map +1 -1
  311. package/dist/worker-progress.js +13 -34
  312. package/dist/worker-progress.js.map +1 -1
  313. package/docs/dedupe-records.md +24 -0
  314. package/package.json +15 -13
  315. package/schemas/project-config.schema.json +5 -0
  316. package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
  317. package/dist/server/findings-service.d.ts +0 -20
  318. package/dist/server/findings-service.d.ts.map +0 -1
  319. package/dist/server/findings-service.js +0 -31
  320. package/dist/server/findings-service.js.map +0 -1
@@ -27,14 +27,18 @@ TEXT_CODE_EXTENSIONS = {
27
27
  ".cue",
28
28
  ".cxx",
29
29
  ".dart",
30
+ ".ejs",
31
+ ".erb",
30
32
  ".ex",
31
33
  ".exs",
32
34
  ".go",
33
35
  ".graphql",
34
36
  ".h",
37
+ ".hh",
35
38
  ".hpp",
36
39
  ".hs",
37
40
  ".html",
41
+ ".hxx",
38
42
  ".java",
39
43
  ".js",
40
44
  ".json",
@@ -42,10 +46,12 @@ TEXT_CODE_EXTENSIONS = {
42
46
  ".kt",
43
47
  ".kts",
44
48
  ".lua",
49
+ ".m",
45
50
  ".mjs",
46
51
  ".mm",
47
52
  ".mts",
48
53
  ".php",
54
+ ".phtml",
49
55
  ".proto",
50
56
  ".ps1",
51
57
  ".psd1",
@@ -55,20 +61,35 @@ TEXT_CODE_EXTENSIONS = {
55
61
  ".rs",
56
62
  ".scala",
57
63
  ".sh",
64
+ ".sol",
58
65
  ".sql",
66
+ ".svelte",
59
67
  ".swift",
60
68
  ".tf",
61
69
  ".toml",
62
70
  ".ts",
63
71
  ".tsx",
64
72
  ".vue",
73
+ ".vy",
65
74
  ".xml",
66
75
  ".yaml",
67
76
  ".yml",
68
77
  }
69
78
 
70
79
  JAVASCRIPT_EXTENSIONS = {".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx", ".vue"}
71
- JAVA_LIKE_EXTENSIONS = {".c", ".cc", ".cpp", ".cs", ".cxx", ".h", ".hpp", ".java", ".mm"}
80
+ JAVA_LIKE_EXTENSIONS = {
81
+ ".c",
82
+ ".cc",
83
+ ".cpp",
84
+ ".cs",
85
+ ".cxx",
86
+ ".h",
87
+ ".hh",
88
+ ".hpp",
89
+ ".hxx",
90
+ ".java",
91
+ ".mm",
92
+ }
72
93
  BRACE_LANGUAGE_EXTENSIONS = {
73
94
  *JAVASCRIPT_EXTENSIONS,
74
95
  *JAVA_LIKE_EXTENSIONS,
@@ -82,6 +103,7 @@ BRACE_LANGUAGE_EXTENSIONS = {
82
103
  ".swift",
83
104
  }
84
105
  NESTED_BLOCK_COMMENT_EXTENSIONS = {".kt", ".kts", ".rs", ".scala", ".swift"}
106
+ CPP_RAW_STRING_RE = re.compile(r'(?<![\w\x80-\U0010ffff])(?:u8|u|U|L)?R"([^\s()\\]{0,16})\(')
85
107
  RUST_RAW_STRING_RE = re.compile(r'(?:br|r)(#{0,16})"')
86
108
  RUST_LIFETIME_RE = re.compile(r"'[A-Za-z_][A-Za-z0-9_]*")
87
109
  PHP_HEREDOC_RE = re.compile(r"<<<\s*['\"]?([A-Za-z_]\w*)['\"]?")
@@ -183,7 +205,7 @@ def python_arguments(node: ast.FunctionDef | ast.AsyncFunctionDef) -> str:
183
205
  def python_outline(text: str) -> list[str]:
184
206
  try:
185
207
  tree = ast.parse(text)
186
- except (SyntaxError, ValueError, TypeError, MemoryError):
208
+ except (SyntaxError, ValueError, TypeError, MemoryError, RecursionError):
187
209
  return []
188
210
 
189
211
  outline: list[str] = []
@@ -283,13 +305,13 @@ def mask_c_style_source(text: str, suffix: str) -> str:
283
305
  continue
284
306
  if heredoc_terminator:
285
307
  if index == 0 or text[index - 1] == "\n":
286
- line_end = text.find("\n", index)
287
- if line_end < 0:
288
- line_end = len(text)
289
- candidate = text[index:line_end].strip().removesuffix(";")
290
- if candidate == heredoc_terminator:
291
- masked.extend(" " * (line_end - index))
292
- index = line_end
308
+ # PHP identifiers allow every non-ASCII byte, including non-word characters.
309
+ terminator_match = re.compile(
310
+ rf"[ \t]*{heredoc_terminator}(?![A-Za-z0-9_\x80-\U0010ffff])"
311
+ ).match(text, index)
312
+ if terminator_match:
313
+ masked.extend(" " * (terminator_match.end() - index))
314
+ index = terminator_match.end()
293
315
  heredoc_terminator = ""
294
316
  continue
295
317
  masked.append(" ")
@@ -337,6 +359,14 @@ def mask_c_style_source(text: str, suffix: str) -> str:
337
359
  quote = ""
338
360
  index += 1
339
361
  continue
362
+ if suffix in {".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}:
363
+ raw_match = CPP_RAW_STRING_RE.match(text, index)
364
+ if raw_match:
365
+ token = raw_match.group(0)
366
+ masked.extend(" " * len(token))
367
+ raw_terminator = f'){raw_match.group(1)}"'
368
+ index += len(token)
369
+ continue
340
370
  if suffix == ".rs":
341
371
  raw_match = RUST_RAW_STRING_RE.match(text, index)
342
372
  if raw_match:
@@ -359,6 +389,11 @@ def mask_c_style_source(text: str, suffix: str) -> str:
359
389
  quote = '@"'
360
390
  index += 2
361
391
  continue
392
+ if suffix == ".go" and char == "`":
393
+ masked.append(" ")
394
+ raw_terminator = "`"
395
+ index += 1
396
+ continue
362
397
  triple_quote = text[index : index + 3]
363
398
  if triple_quote in {'"""', "'''"}:
364
399
  masked.extend((" ", " ", " "))
@@ -456,7 +491,7 @@ def match_type_declaration(line: str, suffix: str) -> tuple[str, str] | None:
456
491
  match = re.search(r"\b(class|struct|enum|protocol|actor|extension)\s+([A-Za-z_]\w*)", line)
457
492
  elif suffix == ".dart":
458
493
  match = re.search(r"\b(class|mixin|enum|extension)\s+([A-Za-z_]\w*)", line)
459
- elif suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"}:
494
+ elif suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}:
460
495
  match = re.search(
461
496
  r"\b(class|struct|union|enum(?:\s+class)?)\s+([A-Za-z_]\w*)",
462
497
  line,
@@ -508,12 +543,20 @@ def match_java_like_function(
508
543
  prefix = before[: name_match.start()].strip()
509
544
  if not prefix and name != (type_name or ""):
510
545
  return None
511
- if suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"} and prefix.startswith(
512
- ("typedef", "using")
513
- ):
546
+ if suffix in {
547
+ ".c",
548
+ ".cc",
549
+ ".cpp",
550
+ ".cxx",
551
+ ".h",
552
+ ".hh",
553
+ ".hpp",
554
+ ".hxx",
555
+ ".mm",
556
+ } and prefix.startswith(("typedef", "using")):
514
557
  return None
515
558
  if (
516
- suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"}
559
+ suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}
517
560
  and type_name is None
518
561
  and line.endswith(";")
519
562
  and not re.search(
@@ -651,8 +694,7 @@ def strip_leading_annotations(original: str, masked: str) -> tuple[str, str, lis
651
694
  def brace_language_outline(text: str, suffix: str) -> list[str]:
652
695
  original_lines = text.splitlines()
653
696
  masked_lines = mask_c_style_source(text, suffix).splitlines()
654
- outline: list[str] = []
655
- seen: set[str] = set()
697
+ outline: dict[str, None] = {}
656
698
  type_stack: list[tuple[str, int]] = []
657
699
  function_depths: list[int] = []
658
700
  blocked_depths: list[int] = []
@@ -663,9 +705,7 @@ def brace_language_outline(text: str, suffix: str) -> list[str]:
663
705
 
664
706
  def add(value: str) -> None:
665
707
  decorated = f"{' '.join(pending_annotations[-2:])} {value}".strip()
666
- if decorated not in seen:
667
- seen.add(decorated)
668
- outline.append(decorated)
708
+ outline[decorated] = None
669
709
 
670
710
  def next_lines_open_body(line_index: int) -> bool:
671
711
  inspected = 0
@@ -777,20 +817,14 @@ def brace_language_outline(text: str, suffix: str) -> list[str]:
777
817
  type_stack.pop()
778
818
  while blocked_depths and depth < blocked_depths[-1]:
779
819
  blocked_depths.pop()
780
- return outline
820
+ return list(outline)
781
821
 
782
822
 
783
823
  def ruby_outline(text: str) -> list[str]:
784
- outline: list[str] = []
785
- seen: set[str] = set()
824
+ outline: dict[str, None] = {}
786
825
  type_stack: list[tuple[int, str]] = []
787
826
  function_indents: list[int] = []
788
827
 
789
- def add(value: str) -> None:
790
- if value not in seen:
791
- seen.add(value)
792
- outline.append(value)
793
-
794
828
  for raw_line in text.splitlines():
795
829
  stripped = raw_line.strip()
796
830
  if not stripped or stripped.startswith("#"):
@@ -804,7 +838,7 @@ def ruby_outline(text: str) -> list[str]:
804
838
  type_match = re.match(r"^(class|module)\s+([A-Z]\w*(?:::[A-Z]\w*)*)", stripped)
805
839
  if type_match and not function_indents:
806
840
  kind, name = type_match.groups()
807
- add(f"{kind} {name}")
841
+ outline[f"{kind} {name}"] = None
808
842
  type_stack.append((indent, name))
809
843
  continue
810
844
 
@@ -812,21 +846,15 @@ def ruby_outline(text: str) -> list[str]:
812
846
  if function_match and not function_indents:
813
847
  name = function_match.group(1)
814
848
  if type_stack:
815
- add(f"method {type_stack[-1][1]}.{name}")
849
+ outline[f"method {type_stack[-1][1]}.{name}"] = None
816
850
  else:
817
- add(f"function {name}")
851
+ outline[f"function {name}"] = None
818
852
  function_indents.append(indent)
819
- return outline
853
+ return list(outline)
820
854
 
821
855
 
822
856
  def simple_language_outline(text: str, suffix: str) -> list[str]:
823
- outline: list[str] = []
824
- seen: set[str] = set()
825
-
826
- def add(value: str) -> None:
827
- if value not in seen:
828
- seen.add(value)
829
- outline.append(value)
857
+ outline: dict[str, None] = {}
830
858
 
831
859
  for raw_line in text.splitlines():
832
860
  line = compact_preview_line(raw_line)
@@ -836,69 +864,63 @@ def simple_language_outline(text: str, suffix: str) -> list[str]:
836
864
  if suffix == ".py":
837
865
  match = re.match(r"^(async\s+)?def\s+([A-Za-z_]\w*)\s*\(", line)
838
866
  if match:
839
- add(f"{'async function' if match.group(1) else 'function'} {match.group(2)}")
867
+ outline[
868
+ f"{'async function' if match.group(1) else 'function'} {match.group(2)}"
869
+ ] = None
840
870
  continue
841
871
  match = re.match(r"^class\s+([A-Za-z_]\w*)", line)
842
872
  if match:
843
- add(f"class {match.group(1)}")
844
- elif suffix == ".rb":
845
- match = re.match(r"^(class|module)\s+([A-Z]\w*(?:::[A-Z]\w*)*)", line)
846
- if match:
847
- add(f"{match.group(1)} {match.group(2)}")
848
- continue
849
- match = re.match(r"^def\s+(?:self\.)?([^\s(]+)", line)
850
- if match:
851
- add(f"function {match.group(1)}")
873
+ outline[f"class {match.group(1)}"] = None
852
874
  elif suffix in {".ex", ".exs"}:
853
875
  match = re.match(r"^defmodule\s+([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)", line)
854
876
  if match:
855
- add(f"module {match.group(1)}")
877
+ outline[f"module {match.group(1)}"] = None
856
878
  continue
857
879
  match = re.match(r"^(?:def|defp|defmacro)\s+([A-Za-z_]\w*[!?]?)", line)
858
880
  if match:
859
- add(f"function {match.group(1)}")
881
+ outline[f"function {match.group(1)}"] = None
860
882
  elif suffix == ".clj":
861
883
  match = re.match(
862
884
  r"^\((defn|defmacro|defprotocol|defrecord|deftype|defmulti|defmethod)\s+([^\s)]+)",
863
885
  line,
864
886
  )
865
887
  if match:
866
- add(f"{match.group(1)} {match.group(2)}")
888
+ outline[f"{match.group(1)} {match.group(2)}"] = None
867
889
  elif suffix == ".lua":
868
890
  match = re.match(r"^(?:local\s+)?function\s+([A-Za-z_]\w*(?:[.:][A-Za-z_]\w*)*)", line)
869
891
  if match:
870
- add(f"function {match.group(1)}")
892
+ outline[f"function {match.group(1)}"] = None
871
893
  elif suffix == ".sh":
872
894
  match = re.match(r"^(?:function\s+)?([A-Za-z_]\w*)\s*\(\s*\)\s*\{?", line)
873
895
  if match:
874
- add(f"function {match.group(1)}")
896
+ outline[f"function {match.group(1)}"] = None
875
897
  elif suffix == ".hs":
876
898
  match = re.match(r"^(data|newtype|type|class)\s+([A-Z]\w*)", line)
877
899
  if match:
878
- add(f"{match.group(1)} {match.group(2)}")
900
+ outline[f"{match.group(1)} {match.group(2)}"] = None
879
901
  continue
880
902
  match = re.match(r"^([a-z_]\w*)\s*::", line)
881
903
  if match:
882
- add(f"function {match.group(1)}")
904
+ outline[f"function {match.group(1)}"] = None
883
905
  elif suffix == ".proto":
884
906
  match = re.match(r"^(message|service|enum)\s+([A-Za-z_]\w*)", line)
885
907
  if match:
886
- add(f"{match.group(1)} {match.group(2)}")
908
+ outline[f"{match.group(1)} {match.group(2)}"] = None
887
909
  continue
888
910
  match = re.match(r"^rpc\s+([A-Za-z_]\w*)\s*\(", line)
889
911
  if match:
890
- add(f"rpc {match.group(1)}")
912
+ outline[f"rpc {match.group(1)}"] = None
891
913
  elif suffix == ".graphql":
892
914
  match = re.match(
893
915
  r"^(type|interface|input|enum|union|scalar|directive)\s+([A-Za-z_]\w*)",
894
916
  line,
895
917
  )
896
918
  if match:
897
- add(f"{match.group(1)} {match.group(2)}")
919
+ outline[f"{match.group(1)} {match.group(2)}"] = None
898
920
  continue
899
921
  match = re.match(r"^(query|mutation|subscription)\s+([A-Za-z_]\w*)", line)
900
922
  if match:
901
- add(f"{match.group(1)} {match.group(2)}")
923
+ outline[f"{match.group(1)} {match.group(2)}"] = None
902
924
  elif suffix == ".sql":
903
925
  match = re.match(
904
926
  r"^CREATE\s+(?:OR\s+REPLACE\s+)?(FUNCTION|PROCEDURE|TABLE|VIEW|TRIGGER)\s+"
@@ -907,16 +929,16 @@ def simple_language_outline(text: str, suffix: str) -> list[str]:
907
929
  flags=re.IGNORECASE,
908
930
  )
909
931
  if match:
910
- add(f"{match.group(1).lower()} {match.group(2)}")
932
+ outline[f"{match.group(1).lower()} {match.group(2)}"] = None
911
933
  elif suffix in {".yaml", ".yml"}:
912
934
  match = re.match(r"^([A-Za-z0-9_.-]+):(?:\s|$)", raw_line)
913
935
  if match:
914
- add(f"key {match.group(1)}")
936
+ outline[f"key {match.group(1)}"] = None
915
937
  elif suffix in {".toml", ".cfg"}:
916
938
  match = re.match(r"^\[([^]]+)]$", line)
917
939
  if match:
918
- add(f"section {match.group(1)}")
919
- return outline
940
+ outline[f"section {match.group(1)}"] = None
941
+ return list(outline)
920
942
 
921
943
 
922
944
  def json_outline(text: str) -> list[str]:
@@ -976,12 +998,8 @@ def preview_for_bytes(path: Path, data: bytes, preview_bytes: int) -> tuple[str,
976
998
  return fit_preview_lines(preview_lines, preview_bytes), False
977
999
 
978
1000
 
979
- def main() -> None:
1001
+ if __name__ == "__main__":
980
1002
  parser = argparse.ArgumentParser(
981
1003
  description="Build structural or sampled previews for Codex Security rank inputs."
982
1004
  )
983
1005
  parser.parse_args()
984
-
985
-
986
- if __name__ == "__main__":
987
- main()
@@ -32,18 +32,10 @@ def _text(value: Any, fallback: str) -> str:
32
32
  return ""
33
33
  if re.match(r"^(?:#{1,6}\s|[-*+]\s|>\s|```|\d+\.\s|\|)", normalized):
34
34
  normalized = f"Text: {normalized}"
35
- rendered: list[str] = []
36
- cursor = 0
37
- for match in re.finditer(r"(?<!`)`([^`\n]+)`(?!`)", normalized):
38
- rendered.append(_escape_markdown_text(normalized[cursor : match.start()]))
39
- rendered.append(f"`{match.group(1)}`")
40
- cursor = match.end()
41
- rendered.append(_escape_markdown_text(normalized[cursor:]))
42
- return "".join(rendered)
43
-
44
-
45
- def _escape_markdown_text(value: str) -> str:
46
- return re.sub(r"([\\`*\[\]<>])", r"\\\1", value)
35
+ return "".join(
36
+ part if index % 2 else re.sub(r"([\\`*\[\]<>])", r"\\\1", part)
37
+ for index, part in enumerate(re.split(r"((?<!`)`[^`\n]+`(?!`))", normalized))
38
+ )
47
39
 
48
40
 
49
41
  def _strings(value: Any) -> list[str]:
@@ -63,10 +55,6 @@ def _cell(value: Any) -> str:
63
55
  return _text(value, "none").replace("|", "\\|").replace("\n", "<br>")
64
56
 
65
57
 
66
- def _link_label(value: Any, fallback: str) -> str:
67
- return _cell(value) or _cell(fallback)
68
-
69
-
70
58
  def _deep_report_id(finding: dict[str, Any]) -> str:
71
59
  extensions = finding.get("extensions")
72
60
  if isinstance(extensions, dict):
@@ -141,10 +129,6 @@ def _deep_title_parts(finding: dict[str, Any]) -> tuple[str, str | None]:
141
129
  return normalized, None
142
130
 
143
131
 
144
- def _deep_finding_title(finding: dict[str, Any]) -> str:
145
- return _deep_title_parts(finding)[0]
146
-
147
-
148
132
  def _deep_finding_groups(
149
133
  findings: list[dict[str, Any]], writeup_paths: list[str | None]
150
134
  ) -> list[list[tuple[int, dict[str, Any], str | None]]]:
@@ -155,12 +139,9 @@ def _deep_finding_groups(
155
139
 
156
140
 
157
141
  def _deep_group_titles(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
158
- titles: list[str] = []
159
- for _, finding, _ in group:
160
- title = _cell(_deep_finding_title(finding))
161
- if title not in titles:
162
- titles.append(title)
163
- return "<br>".join(titles)
142
+ return "<br>".join(
143
+ dict.fromkeys(_cell(_deep_title_parts(finding)[0]) for _, finding, _ in group)
144
+ )
164
145
 
165
146
 
166
147
  def _deep_group_levels(
@@ -197,7 +178,7 @@ def _deep_group_report_labels(
197
178
  def _deep_group_report_links(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
198
179
  labels = _deep_group_report_labels(group)
199
180
  return "<br>".join(
200
- f"[{_link_label(label, 'Unidentified report')}](#finding-{number})"
181
+ f"[{_cell(label)}](#finding-{number})"
201
182
  for label, (number, _, _) in zip(labels, group, strict=True)
202
183
  )
203
184
 
@@ -206,7 +187,7 @@ def _deep_group_writeup_links(group: list[tuple[int, dict[str, Any], str | None]
206
187
  labels = _deep_group_report_labels(group)
207
188
  links: list[str] = []
208
189
  for label, (_, _, report_path) in zip(labels, group, strict=True):
209
- report_id = _link_label(label, "Unidentified report")
190
+ report_id = _cell(label)
210
191
  links.append(
211
192
  f"[Open {report_id}]({report_path})" if report_path else f"{report_id}: inline below"
212
193
  )
@@ -282,15 +263,11 @@ def _section_code_evidence(
282
263
  and isinstance(item.get("code"), str)
283
264
  and item["code"].strip()
284
265
  )
285
- unique: list[dict[str, Any]] = []
286
- seen: set[tuple[str, str]] = set()
266
+ unique: dict[tuple[str, str], dict[str, Any]] = {}
287
267
  for item in resolved:
288
268
  key = (str(item.get("id", "")), item["code"])
289
- if key in seen:
290
- continue
291
- seen.add(key)
292
- unique.append(item)
293
- return unique
269
+ unique.setdefault(key, item)
270
+ return list(unique.values())
294
271
 
295
272
 
296
273
  def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
@@ -867,26 +844,32 @@ def build_report_markdown(
867
844
  "",
868
845
  "## Threat Model",
869
846
  "",
847
+ ]
848
+ )
849
+ content = threat_model.get("content")
850
+ if threat_model.get("format") == "markdown" and isinstance(content, str) and content.strip():
851
+ lines.append(content)
852
+ else:
853
+ lines.append(
870
854
  _text(
871
855
  threat_model.get("summary"),
872
856
  "No explicit canonical threat-model summary was recorded.",
857
+ )
858
+ )
859
+ for heading, key, fallback in (
860
+ ("Assets", "assets", "No assets were recorded."),
861
+ ("Trust Boundaries", "trustBoundaries", "No trust boundaries were recorded."),
862
+ (
863
+ "Attacker Capabilities",
864
+ "attackerCapabilities",
865
+ "No attacker capabilities were recorded.",
873
866
  ),
874
- ]
875
- )
876
- for heading, key, fallback in (
877
- ("Assets", "assets", "No assets were recorded."),
878
- ("Trust Boundaries", "trustBoundaries", "No trust boundaries were recorded."),
879
- (
880
- "Attacker Capabilities",
881
- "attackerCapabilities",
882
- "No attacker capabilities were recorded.",
883
- ),
884
- ("Security Objectives", "securityObjectives", "No security objectives were recorded."),
885
- ("Assumptions", "assumptions", "No assumptions were recorded."),
886
- ):
887
- values = _strings(threat_model.get(key))
888
- if values:
889
- lines.extend(["", f"### {heading}", "", *_bullets(values, fallback)])
867
+ ("Security Objectives", "securityObjectives", "No security objectives were recorded."),
868
+ ("Assumptions", "assumptions", "No assumptions were recorded."),
869
+ ):
870
+ values = _strings(threat_model.get(key))
871
+ if values:
872
+ lines.extend(["", f"### {heading}", "", *_bullets(values, fallback)])
890
873
  lines.extend(["", "## Findings", ""])
891
874
  if findings:
892
875
  if deep_presentation:
@@ -913,7 +896,7 @@ def build_report_markdown(
913
896
  for number, (finding, report_path) in enumerate(
914
897
  zip(findings, writeup_paths, strict=True), 1
915
898
  ):
916
- title = _link_label(finding["title"], "Untitled finding")
899
+ title = _cell(finding["title"])
917
900
  finding_link = f"[{title}](#finding-{number})"
918
901
  writeup_link = f"[Open report]({report_path})" if report_path else "inline below"
919
902
  lines.append(
@@ -1078,11 +1061,7 @@ def generate_report_markdown(
1078
1061
  return build_report_markdown(manifest, findings, coverage).encode("utf-8")
1079
1062
 
1080
1063
 
1081
- def main() -> int:
1064
+ if __name__ == "__main__":
1082
1065
  parser = argparse.ArgumentParser(description=__doc__)
1083
1066
  parser.parse_args()
1084
- return 0
1085
-
1086
-
1087
- if __name__ == "__main__":
1088
- raise SystemExit(main())
1067
+ raise SystemExit(0)