@openai/codex-security 0.6.0 → 0.7.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 (243) hide show
  1. package/README.md +68 -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/helpers.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
  6. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/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/mcp/server.mjs.br.part-002 +0 -0
  16. package/_bundled_plugin/references/access-advisory.md +11 -0
  17. package/_bundled_plugin/references/core-scan.md +30 -77
  18. package/_bundled_plugin/references/final-report.md +45 -189
  19. package/_bundled_plugin/references/scan-contract.md +2 -0
  20. package/_bundled_plugin/references/scan-prologue.md +1 -1
  21. package/_bundled_plugin/references/scan-runtime.md +1 -5
  22. package/_bundled_plugin/references/threat-model.md +33 -41
  23. package/_bundled_plugin/schemas/coverage.schema.json +12 -1
  24. package/_bundled_plugin/schemas/scan-manifest.schema.json +1 -0
  25. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
  26. package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
  27. package/_bundled_plugin/scripts/deep_scan_workbench.py +145 -85
  28. package/_bundled_plugin/scripts/finalize_scan_contract.py +189 -57
  29. package/_bundled_plugin/scripts/report_projection.py +44 -15
  30. package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
  31. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
  32. package/_bundled_plugin/scripts/workbench/retained_coverage.py +3218 -0
  33. package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
  34. package/_bundled_plugin/scripts/workbench/saved_coverage.py +644 -1
  35. package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
  36. package/_bundled_plugin/scripts/workbench/saved_sources.py +712 -0
  37. package/_bundled_plugin/scripts/workbench_cli.py +3 -0
  38. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
  39. package/_bundled_plugin/scripts/workbench_db.py +51 -22
  40. package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
  41. package/_bundled_plugin/scripts/workbench_finding_workflows.py +51 -9
  42. package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +641 -2387
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +72 -7
  45. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
  47. package/_bundled_plugin/scripts/workbench_target.py +142 -17
  48. package/_bundled_plugin/scripts/workbench_validation.py +9 -2
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +28 -0
  51. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
  52. package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
  53. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
  54. package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
  56. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
  57. package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
  58. package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
  59. package/_bundled_plugin/skills/fix-finding/SKILL.md +9 -28
  60. package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
  61. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
  62. package/_bundled_plugin/skills/publish-findings/SKILL.md +28 -24
  63. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
  64. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
  65. package/_bundled_plugin/skills/security-scan/SKILL.md +28 -16
  66. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
  67. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
  68. package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
  69. package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
  70. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
  71. package/_bundled_plugin/skills/validation/SKILL.md +42 -104
  72. package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
  73. package/_bundled_plugin/skills/verify-fix/SKILL.md +4 -2
  74. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
  75. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
  76. package/dist/api.d.ts +5 -3
  77. package/dist/api.d.ts.map +1 -1
  78. package/dist/api.js +341 -37
  79. package/dist/api.js.map +1 -1
  80. package/dist/auth.d.ts.map +1 -1
  81. package/dist/auth.js +4 -1
  82. package/dist/auth.js.map +1 -1
  83. package/dist/cli.d.ts +2 -2
  84. package/dist/cli.d.ts.map +1 -1
  85. package/dist/cli.js +674 -419
  86. package/dist/cli.js.map +1 -1
  87. package/dist/component-scan.d.ts +8 -2
  88. package/dist/component-scan.d.ts.map +1 -1
  89. package/dist/component-scan.js +2 -0
  90. package/dist/component-scan.js.map +1 -1
  91. package/dist/contract.d.ts +2 -0
  92. package/dist/contract.d.ts.map +1 -1
  93. package/dist/contract.js +67 -33
  94. package/dist/contract.js.map +1 -1
  95. package/dist/cost.d.ts +18 -0
  96. package/dist/cost.d.ts.map +1 -1
  97. package/dist/cost.js +107 -12
  98. package/dist/cost.js.map +1 -1
  99. package/dist/coverage-presentation.d.ts +6 -0
  100. package/dist/coverage-presentation.d.ts.map +1 -0
  101. package/dist/coverage-presentation.js +34 -0
  102. package/dist/coverage-presentation.js.map +1 -0
  103. package/dist/custom-validation-prompt.js +3 -3
  104. package/dist/custom-validation-prompt.js.map +1 -1
  105. package/dist/custom-validation.d.ts.map +1 -1
  106. package/dist/custom-validation.js +30 -4
  107. package/dist/custom-validation.js.map +1 -1
  108. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  109. package/dist/deduplication/checkpointed-review.js +3 -1
  110. package/dist/deduplication/checkpointed-review.js.map +1 -1
  111. package/dist/deduplication/scan.d.ts.map +1 -1
  112. package/dist/deduplication/scan.js +7 -5
  113. package/dist/deduplication/scan.js.map +1 -1
  114. package/dist/endor-findings.d.ts +4 -3
  115. package/dist/endor-findings.d.ts.map +1 -1
  116. package/dist/endor-findings.js +16 -11
  117. package/dist/endor-findings.js.map +1 -1
  118. package/dist/external-findings-import.d.ts.map +1 -1
  119. package/dist/external-findings-import.js +13 -5
  120. package/dist/external-findings-import.js.map +1 -1
  121. package/dist/external-findings-local.d.ts.map +1 -1
  122. package/dist/external-findings-local.js +8 -1
  123. package/dist/external-findings-local.js.map +1 -1
  124. package/dist/external-findings-publish.d.ts +1 -1
  125. package/dist/external-findings-publish.d.ts.map +1 -1
  126. package/dist/external-findings-publish.js +11 -3
  127. package/dist/external-findings-publish.js.map +1 -1
  128. package/dist/external-findings-read.d.ts +11 -1
  129. package/dist/external-findings-read.d.ts.map +1 -1
  130. package/dist/external-findings-read.js +15 -6
  131. package/dist/external-findings-read.js.map +1 -1
  132. package/dist/external-import-contract.d.ts +3 -1
  133. package/dist/external-import-contract.d.ts.map +1 -1
  134. package/dist/external-import-contract.js +33 -25
  135. package/dist/external-import-contract.js.map +1 -1
  136. package/dist/external-imports-feature.d.ts +6 -0
  137. package/dist/external-imports-feature.d.ts.map +1 -0
  138. package/dist/external-imports-feature.js +51 -0
  139. package/dist/external-imports-feature.js.map +1 -0
  140. package/dist/finding-workflow.d.ts +22 -5
  141. package/dist/finding-workflow.d.ts.map +1 -1
  142. package/dist/finding-workflow.js +21 -9
  143. package/dist/finding-workflow.js.map +1 -1
  144. package/dist/github-advisories.d.ts.map +1 -1
  145. package/dist/github-advisories.js +3 -1
  146. package/dist/github-advisories.js.map +1 -1
  147. package/dist/github-findings.d.ts +4 -3
  148. package/dist/github-findings.d.ts.map +1 -1
  149. package/dist/github-findings.js +16 -14
  150. package/dist/github-findings.js.map +1 -1
  151. package/dist/hosted-remediation.d.ts.map +1 -1
  152. package/dist/hosted-remediation.js +19 -2
  153. package/dist/hosted-remediation.js.map +1 -1
  154. package/dist/hosted-scan.d.ts +1 -1
  155. package/dist/hosted-scan.d.ts.map +1 -1
  156. package/dist/hosted-scan.js +0 -5
  157. package/dist/hosted-scan.js.map +1 -1
  158. package/dist/import-scan.js +1 -1
  159. package/dist/import-scan.js.map +1 -1
  160. package/dist/index.d.ts +3 -3
  161. package/dist/index.d.ts.map +1 -1
  162. package/dist/index.js +1 -1
  163. package/dist/index.js.map +1 -1
  164. package/dist/knowledge-base.d.ts +1 -0
  165. package/dist/knowledge-base.d.ts.map +1 -1
  166. package/dist/knowledge-base.js +17 -8
  167. package/dist/knowledge-base.js.map +1 -1
  168. package/dist/models.d.ts +1 -0
  169. package/dist/models.d.ts.map +1 -1
  170. package/dist/models.js.map +1 -1
  171. package/dist/owner-evidence.d.ts +2 -0
  172. package/dist/owner-evidence.d.ts.map +1 -1
  173. package/dist/owner-evidence.js +2 -1
  174. package/dist/owner-evidence.js.map +1 -1
  175. package/dist/publish.d.ts +2 -0
  176. package/dist/publish.d.ts.map +1 -1
  177. package/dist/publish.js +1 -1
  178. package/dist/publish.js.map +1 -1
  179. package/dist/remediation.d.ts +1 -25
  180. package/dist/remediation.d.ts.map +1 -1
  181. package/dist/remediation.js +3 -24
  182. package/dist/remediation.js.map +1 -1
  183. package/dist/runtime.d.ts.map +1 -1
  184. package/dist/runtime.js +7 -7
  185. package/dist/runtime.js.map +1 -1
  186. package/dist/scan-dashboard.d.ts +5 -3
  187. package/dist/scan-dashboard.d.ts.map +1 -1
  188. package/dist/scan-dashboard.js +79 -26
  189. package/dist/scan-dashboard.js.map +1 -1
  190. package/dist/scan-history-renderer.d.ts.map +1 -1
  191. package/dist/scan-history-renderer.js +8 -2
  192. package/dist/scan-history-renderer.js.map +1 -1
  193. package/dist/scan-owner-suggestions.d.ts +1 -1
  194. package/dist/scan-owner-suggestions.d.ts.map +1 -1
  195. package/dist/scan-owner-suggestions.js +4 -4
  196. package/dist/scan-owner-suggestions.js.map +1 -1
  197. package/dist/scan-usage-display.d.ts +8 -0
  198. package/dist/scan-usage-display.d.ts.map +1 -0
  199. package/dist/scan-usage-display.js +46 -0
  200. package/dist/scan-usage-display.js.map +1 -0
  201. package/dist/scanner-import.d.ts +1 -1
  202. package/dist/scanner-import.d.ts.map +1 -1
  203. package/dist/scanner-import.js +7 -3
  204. package/dist/scanner-import.js.map +1 -1
  205. package/dist/security-policy.d.ts.map +1 -1
  206. package/dist/security-policy.js +1 -20
  207. package/dist/security-policy.js.map +1 -1
  208. package/dist/semgrep-findings.d.ts +4 -3
  209. package/dist/semgrep-findings.d.ts.map +1 -1
  210. package/dist/semgrep-findings.js +9 -9
  211. package/dist/semgrep-findings.js.map +1 -1
  212. package/dist/skill-authentication.d.ts +18 -0
  213. package/dist/skill-authentication.d.ts.map +1 -0
  214. package/dist/skill-authentication.js +82 -0
  215. package/dist/skill-authentication.js.map +1 -0
  216. package/dist/snyk-findings.d.ts +5 -4
  217. package/dist/snyk-findings.d.ts.map +1 -1
  218. package/dist/snyk-findings.js +18 -17
  219. package/dist/snyk-findings.js.map +1 -1
  220. package/dist/suggest-owners.d.ts +4 -1
  221. package/dist/suggest-owners.d.ts.map +1 -1
  222. package/dist/suggest-owners.js +53 -21
  223. package/dist/suggest-owners.js.map +1 -1
  224. package/dist/targets.d.ts.map +1 -1
  225. package/dist/targets.js +4 -1
  226. package/dist/targets.js.map +1 -1
  227. package/dist/wiz-csv.d.ts +2 -1
  228. package/dist/wiz-csv.d.ts.map +1 -1
  229. package/dist/wiz-csv.js +3 -3
  230. package/dist/wiz-csv.js.map +1 -1
  231. package/dist/wiz-findings.d.ts +2 -1
  232. package/dist/wiz-findings.d.ts.map +1 -1
  233. package/dist/wiz-findings.js +27 -23
  234. package/dist/wiz-findings.js.map +1 -1
  235. package/docs/classify-severity-records.md +3 -4
  236. package/docs/cli.md +155 -38
  237. package/docs/findings-service.md +119 -118
  238. package/docs/hosted-remediation.md +19 -17
  239. package/docs/hosted-scans.md +37 -11
  240. package/package.json +8 -8
  241. package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
  242. package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
  243. package/_bundled_plugin/scripts/rank_preview.py +0 -129
@@ -64,7 +64,6 @@ def get_scan_feedback(connection: sqlite3.Connection, scan: sqlite3.Row) -> dict
64
64
  ORDER BY julianday(upper(updated_at)) DESC,
65
65
  julianday(upper(source_completed_at)) DESC,
66
66
  source_scan_id DESC, finding_id DESC
67
- LIMIT 50
68
67
  """,
69
68
  (scan["target_id"], scan["id"]),
70
69
  )
@@ -6,12 +6,19 @@ import argparse
6
6
  import hashlib
7
7
  import json
8
8
  import sqlite3
9
+ import stat
9
10
  import sys
10
11
  from pathlib import Path
11
12
  from typing import Any
12
13
 
13
14
  sys.path.insert(0, str(Path(__file__).resolve().parent))
14
- from workbench_target import directory_content_digest, git_bytes, git_revision
15
+ from workbench_target import (
16
+ UnreadableLocalFile,
17
+ UnsupportedLocalFileType,
18
+ directory_content_digest,
19
+ git_bytes,
20
+ git_revision,
21
+ )
15
22
 
16
23
  WORKFLOW_BINDINGS = {
17
24
  "repositoryPath": "repository_path",
@@ -123,7 +130,24 @@ def finding_workflow(
123
130
  if payload["action"] == "get":
124
131
  return {"workflow": read_workflow(connection, workflow_id)}
125
132
  if payload["action"] == "source":
126
- target = Path(payload["repository"]).resolve(strict=True)
133
+ evidence = payload.get("evidence") is True
134
+ if evidence:
135
+ try:
136
+ target = Path(payload["repository"])
137
+ metadata = target.lstat()
138
+ if (
139
+ not target.is_absolute()
140
+ or not stat.S_ISDIR(metadata.st_mode)
141
+ or getattr(metadata, "st_reparse_tag", 0) & 0x20000000
142
+ or target.resolve(strict=True) != target
143
+ ):
144
+ raise UnreadableLocalFile("The validation evidence directory was replaced.")
145
+ except (OSError, RuntimeError, UnreadableLocalFile):
146
+ if payload.get("optional") is True:
147
+ return {"source": None}
148
+ raise
149
+ else:
150
+ target = Path(payload["repository"]).resolve(strict=True)
127
151
  private_paths = payload.get("privateStatePaths", [])
128
152
  if not isinstance(private_paths, list) or any(
129
153
  not isinstance(path, str) or not Path(path).is_absolute() for path in private_paths
@@ -133,18 +157,31 @@ def finding_workflow(
133
157
  excluded = tuple(path for path in excluded if path.is_relative_to(target))
134
158
  if target in excluded:
135
159
  raise SystemExit("Private runtime storage must not exclude the repository root.")
160
+ try:
161
+ content = directory_content_digest(
162
+ target,
163
+ excluded=excluded,
164
+ include_ignored=True,
165
+ include_git_metadata=evidence,
166
+ )
167
+ except (UnsupportedLocalFileType, UnreadableLocalFile, OSError):
168
+ if payload.get("optional") is True:
169
+ return {"source": None}
170
+ raise
136
171
  return {
137
172
  "source": {
138
173
  "repository": str(target),
139
- "revision": "unversioned" if payload.get("gitDisabled") else git_revision(target),
174
+ "revision": (
175
+ "unversioned"
176
+ if evidence or payload.get("gitDisabled")
177
+ else git_revision(target)
178
+ ),
140
179
  "refsDigest": hashlib.sha256(
141
180
  b""
142
- if payload.get("gitDisabled")
181
+ if evidence or payload.get("gitDisabled")
143
182
  else (git_bytes(target, "show-ref") or b"").strip()
144
183
  ).hexdigest(),
145
- "content": directory_content_digest(
146
- target, excluded=excluded, include_ignored=True
147
- ),
184
+ "content": content,
148
185
  **({"privateStatePaths": [str(path) for path in excluded]} if excluded else {}),
149
186
  }
150
187
  }
@@ -158,15 +195,20 @@ def finding_workflow(
158
195
  binding = payload["binding"]
159
196
  source = binding["source"]
160
197
  scope = binding["scope"]
198
+ on_conflict = (
199
+ "DO UPDATE SET result_json = excluded.result_json, created_at = excluded.created_at"
200
+ if payload.get("replace") is True and binding.get("stage") == "scan-validation"
201
+ else "DO NOTHING"
202
+ )
161
203
  with connection:
162
204
  connection.execute(
163
- """INSERT INTO finding_workflow_reviews
205
+ f"""INSERT INTO finding_workflow_reviews
164
206
  (workflow_id, review_key, review_contract_version, codex_version,
165
207
  source_repository_path, source_revision, source_refs_digest, source_content_digest,
166
208
  scope_repository_id, scope_all_repositories, model, effort, settings_digest,
167
209
  prompt_digest, contract_digest, result_json, created_at)
168
210
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
169
- ON CONFLICT(workflow_id, review_key) DO NOTHING""",
211
+ ON CONFLICT(workflow_id, review_key) {on_conflict}""",
170
212
  (
171
213
  workflow_id,
172
214
  payload["key"],
@@ -1,6 +1,7 @@
1
1
  """Read-only native findings and repository indexes for the Security workbench."""
2
2
 
3
3
  import argparse
4
+ import os
4
5
  import sqlite3
5
6
  import sys
6
7
  from collections import Counter
@@ -204,63 +205,74 @@ def list_repositories(
204
205
  args: argparse.Namespace | None = None,
205
206
  ) -> dict[str, Any]:
206
207
  scan_count_by_target = Counter()
207
- latest_scan_by_target: dict[str, dict[str, Any]] = {}
208
- for scan in (
209
- scan_history.scan_summary(row)
210
- for row in connection.execute(
211
- f"""{scan_history.SCAN_SUMMARY_QUERY}
212
- ORDER BY julianday(upper(scans.started_at)) DESC, scans.id DESC
213
- """
214
- ).fetchall()
215
- ):
216
- scan_count_by_target[scan["targetId"]] += 1
217
- latest_scan_by_target.setdefault(scan["targetId"], scan)
208
+ latest_by_target: dict[str, tuple[sqlite3.Row, dict[str, Any] | None]] = {}
209
+ for row in connection.execute(
210
+ f"""
211
+ SELECT targets.id AS repository_id, targets.display_name, targets.current_path,
212
+ {scan_history.SCAN_SUMMARY_COLUMNS}
213
+ FROM security_targets AS targets
214
+ LEFT JOIN scans ON scans.target_id = targets.id
215
+ AND scans.id IN (SELECT scan_id FROM scan_progress)
216
+ LEFT JOIN scan_progress AS progress ON progress.scan_id = scans.id
217
+ ORDER BY julianday(upper(scans.started_at)) DESC, scans.id DESC, targets.id
218
+ """
219
+ ).fetchall():
220
+ scan = scan_history.scan_summary(row) if row["id"] is not None else None
221
+ target_id = row["repository_id"]
222
+ if scan is not None:
223
+ scan_count_by_target[target_id] += 1
224
+ latest_by_target.setdefault(target_id, (row, scan))
218
225
 
219
226
  open_findings_by_target = Counter(
220
227
  row["target_id"] for row in _indexed_findings(connection) if row["status"] == "open"
221
228
  )
222
- targets = {row["id"]: row for row in connection.execute("SELECT * FROM security_targets")}
223
229
  repositories = [
224
230
  {
225
- "checkoutAvailable": Path(target["current_path"]).is_dir(),
226
231
  "displayName": target["display_name"],
227
232
  "latestScan": latest_scan,
228
- "openFindingsCount": open_findings_by_target.get(target_id, 0),
233
+ "openFindingsCount": open_findings_by_target[target_id]
234
+ if latest_scan is not None
235
+ else 0,
229
236
  "scanCount": scan_count_by_target[target_id],
230
237
  "targetId": target_id,
231
238
  "targetPath": target["current_path"],
232
239
  }
233
- for target_id, latest_scan in latest_scan_by_target.items()
234
- if (target := targets.get(target_id)) is not None
235
- ]
236
- if args is None:
237
- return {"repositories": repositories}
238
-
239
- query = args.query.strip().casefold() if args.query else ""
240
- repositories = [
241
- repository
242
- for repository in repositories
243
- if (args.target_id is None or repository["targetId"] == args.target_id)
244
- and args.status != "not_scanned"
245
- and (args.status != "open_findings" or repository["openFindingsCount"] > 0)
246
- and (
247
- not query
248
- or query in repository["displayName"].casefold()
249
- or query in repository["targetPath"].casefold()
250
- )
240
+ for target_id, (target, latest_scan) in latest_by_target.items()
251
241
  ]
252
- if args.limit is None and args.offset == 0:
253
- return {"repositories": repositories}
254
-
255
- limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX)
256
- page = repositories[args.offset : args.offset + limit]
257
- next_offset = args.offset + len(page)
258
- return {
259
- "repositories": page,
260
- "limit": limit,
261
- "nextOffset": next_offset if next_offset < len(repositories) else None,
262
- "offset": args.offset,
263
- }
242
+ pagination = {}
243
+ if args is not None:
244
+ query = args.query.strip().casefold() if args.query else ""
245
+ repositories = [
246
+ repository
247
+ for repository in repositories
248
+ if (args.target_id is None or repository["targetId"] == args.target_id)
249
+ and (args.status != "scanned" or repository["scanCount"] > 0)
250
+ and (args.status != "not_scanned" or repository["scanCount"] == 0)
251
+ and (args.status != "open_findings" or repository["openFindingsCount"] > 0)
252
+ and (
253
+ not query
254
+ or query in repository["displayName"].casefold()
255
+ or query in repository["targetPath"].casefold()
256
+ )
257
+ ]
258
+ if args.limit is not None or args.offset:
259
+ limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX)
260
+ end = args.offset + limit
261
+ pagination = {
262
+ "limit": limit,
263
+ "nextOffset": end if end < len(repositories) else None,
264
+ "offset": args.offset,
265
+ }
266
+ repositories = repositories[args.offset : end]
267
+ for repository in repositories:
268
+ path = os.path.expanduser(repository["targetPath"])
269
+ try:
270
+ repository["checkoutAvailable"] = Path(path).is_absolute() and os.path.isdir(
271
+ os.path.realpath(path)
272
+ )
273
+ except (OSError, RecursionError):
274
+ repository["checkoutAvailable"] = False
275
+ return {"repositories": repositories, **pagination}
264
276
 
265
277
 
266
278
  if __name__ == "__main__":