@openai/codex-security 0.1.8 → 0.1.10

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 (77) hide show
  1. package/README.md +30 -14
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/preflight/capability-profiles.toml +1 -1
  6. package/_bundled_plugin/references/scan-contract.md +1 -1
  7. package/_bundled_plugin/scripts/deep_scan_workbench.py +22 -0
  8. package/_bundled_plugin/scripts/generate_in_scope_files.py +102 -1
  9. package/_bundled_plugin/scripts/generate_rank_input.py +28 -2
  10. package/_bundled_plugin/scripts/normalize_candidates.py +20 -2
  11. package/_bundled_plugin/scripts/workbench_cli.py +4 -0
  12. package/_bundled_plugin/scripts/workbench_constants.py +0 -1
  13. package/_bundled_plugin/scripts/workbench_db.py +12 -8
  14. package/_bundled_plugin/scripts/workbench_native_indexes.py +100 -43
  15. package/_bundled_plugin/scripts/workbench_scan_history.py +8 -10
  16. package/_bundled_plugin/skills/finding-discovery/SKILL.md +8 -4
  17. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +21 -140
  18. package/dist/api.d.ts +43 -4
  19. package/dist/api.d.ts.map +1 -1
  20. package/dist/api.js +164 -117
  21. package/dist/api.js.map +1 -1
  22. package/dist/auth.d.ts.map +1 -1
  23. package/dist/auth.js +18 -71
  24. package/dist/auth.js.map +1 -1
  25. package/dist/cli.d.ts +2 -2
  26. package/dist/cli.d.ts.map +1 -1
  27. package/dist/cli.js +112 -178
  28. package/dist/cli.js.map +1 -1
  29. package/dist/contract.d.ts.map +1 -1
  30. package/dist/contract.js +7 -228
  31. package/dist/contract.js.map +1 -1
  32. package/dist/cost.d.ts +1 -0
  33. package/dist/cost.d.ts.map +1 -1
  34. package/dist/cost.js +1 -5
  35. package/dist/cost.js.map +1 -1
  36. package/dist/errors.d.ts +4 -2
  37. package/dist/errors.d.ts.map +1 -1
  38. package/dist/errors.js +10 -46
  39. package/dist/errors.js.map +1 -1
  40. package/dist/index.d.ts +2 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/knowledge-base.js +4 -4
  45. package/dist/knowledge-base.js.map +1 -1
  46. package/dist/multiscan.d.ts.map +1 -1
  47. package/dist/multiscan.js +33 -7
  48. package/dist/multiscan.js.map +1 -1
  49. package/dist/result.d.ts +13 -1
  50. package/dist/result.d.ts.map +1 -1
  51. package/dist/result.js +3 -0
  52. package/dist/result.js.map +1 -1
  53. package/dist/runtime.d.ts.map +1 -1
  54. package/dist/runtime.js +17 -153
  55. package/dist/runtime.js.map +1 -1
  56. package/dist/scan-comparison.d.ts +14 -0
  57. package/dist/scan-comparison.d.ts.map +1 -1
  58. package/dist/scan-comparison.js +89 -0
  59. package/dist/scan-comparison.js.map +1 -1
  60. package/dist/scan-dashboard.d.ts.map +1 -1
  61. package/dist/scan-dashboard.js +1 -0
  62. package/dist/scan-dashboard.js.map +1 -1
  63. package/dist/scan-history-renderer.d.ts +1 -1
  64. package/dist/scan-history-renderer.d.ts.map +1 -1
  65. package/dist/scan-history-renderer.js +10 -0
  66. package/dist/scan-history-renderer.js.map +1 -1
  67. package/dist/scan-logs.d.ts +17 -0
  68. package/dist/scan-logs.d.ts.map +1 -0
  69. package/dist/scan-logs.js +90 -0
  70. package/dist/scan-logs.js.map +1 -0
  71. package/dist/version.d.ts +1 -1
  72. package/dist/version.js +1 -1
  73. package/dist/version.js.map +1 -1
  74. package/dist/worker-progress.d.ts.map +1 -1
  75. package/dist/worker-progress.js +8 -29
  76. package/dist/worker-progress.js.map +1 -1
  77. package/package.json +3 -3
package/README.md CHANGED
@@ -53,6 +53,10 @@ Use `security.preflight()` to validate local inputs, `onWorkerStatus` and
53
53
  `onReconnect` to observe long-running scans, and an `AbortSignal` to cancel a
54
54
  scan.
55
55
 
56
+ Successful results include open repository findings in `repositoryFindings`,
57
+ when available; `findings` remains the current scan. Matching earlier findings
58
+ can make one additional model call, including with a scan cost limit.
59
+
56
60
  Results can contain source excerpts, vulnerability details, and reproduction
57
61
  steps. Keep result directories and saved reports outside the repository and
58
62
  limit access to authorized reviewers.
@@ -212,15 +216,18 @@ npx @openai/codex-security scan /path/to/repository --mode deep --workers 2 --su
212
216
  npx @openai/codex-security install-hook
213
217
  npx @openai/codex-security bulk-scan
214
218
  npx @openai/codex-security bulk-scan --model gpt-5.6-terra --effort high
219
+ npx @openai/codex-security bulk-scan --workers 4 --mode deep --max-attempts 3
215
220
  npx @openai/codex-security bulk-scan repositories.csv --output-dir /path/outside/repositories/security-scans --workers 4 --knowledge-base /path/to/threat-models --knowledge-base /path/to/architecture.pdf
216
221
  npx @openai/codex-security bulk-scan repositories.csv --output-dir /path/outside/repositories/security-scans --scan-prompt-file scan.md --post-scan-prompt-file follow-up.md
217
222
  npx @openai/codex-security scans list /path/to/repository
218
223
  npx @openai/codex-security scans list --scan-root /path/outside/repository/results
219
224
  npx @openai/codex-security scans show SCAN_ID
225
+ npx @openai/codex-security scans logs SCAN_ID
220
226
  npx @openai/codex-security scans rerun SCAN_ID
221
227
  npx @openai/codex-security scans match PREVIOUS_SCAN_ID CURRENT_SCAN_ID
222
228
  npx @openai/codex-security scans match --all
223
229
  npx @openai/codex-security scans compare PREVIOUS_SCAN_ID CURRENT_SCAN_ID
230
+ npx @openai/codex-security findings list /path/to/repository
224
231
  npx @openai/codex-security findings false-positive OCCURRENCE_ID --reason "The route already checks permissions"
225
232
  npx @openai/codex-security export /path/outside/repository/results --export-format sarif --output /path/outside/repository/results.sarif
226
233
  npx @openai/codex-security export /path/outside/repository/results --export-format csv --output /path/outside/repository/findings.csv
@@ -399,7 +406,7 @@ The CLI and SDK recognize the following user-configurable environment:
399
406
  | Variable | Effect |
400
407
  | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
401
408
  | `OPENAI_API_KEY`, `CODEX_API_KEY` | Scan authentication; `OPENAI_API_KEY` wins when both are present. |
402
- | `CODEX_SECURITY_LOG_LEVEL` | CLI-only; set to `debug` for redacted diagnostics. |
409
+ | `CODEX_SECURITY_LOG_LEVEL` | CLI-only; set to `debug` for verbose diagnostics. |
403
410
  | `LOG_LEVEL` | CLI-only fallback when `CODEX_SECURITY_LOG_LEVEL` is unset. |
404
411
  | `CODEX_SECURITY_STATE_DIR` | Override the private scan-history, workbench, and default artifact directory. |
405
412
  | `CODEX_HOME` | Set the ambient Codex home for file-backed sign-in and default state; defaults to `~/.codex`. |
@@ -450,11 +457,12 @@ token and worker counts, estimated cost, the results directory, and the next
450
457
  useful command.
451
458
  Progress and summaries use stderr; structured scan results remain on stdout.
452
459
 
453
- Add `--verbose` or set `CODEX_SECURITY_LOG_LEVEL=debug` to print redacted
460
+ Add `--verbose` or set `CODEX_SECURITY_LOG_LEVEL=debug` to print
454
461
  lifecycle, authentication, progress, and cost diagnostics to stderr.
455
462
  `LOG_LEVEL=debug` is used only when `CODEX_SECURITY_LOG_LEVEL` is unset.
456
- Credentials and provider identifiers remain redacted, and structured JSON
457
- results remain on stdout.
463
+ Structured JSON results remain on stdout. Verbose diagnostics may contain
464
+ sensitive data; review local logs before sharing them. The interactive
465
+ dashboard omits activity containing recognizable credentials.
458
466
 
459
467
  Each scan records its model, tokens, and estimated cost in its JSON result,
460
468
  scan history, and bulk-scan receipt. Estimates use
@@ -463,9 +471,7 @@ including cached input and cache writes; fees and surcharges are not included.
463
471
 
464
472
  Use `--max-cost USD` to stop a scan, including its delegated workers, when its
465
473
  running cost exceeds the limit. Partial results are preserved. Requests
466
- already in progress can finish above the limit. Cost tracking accepts Codex
467
- session events up to 1 MiB; an oversized event stops the scan because its
468
- running cost can no longer be verified safely.
474
+ already in progress can finish above the limit.
469
475
 
470
476
  Run `npx @openai/codex-security scan --help` or `npx @openai/codex-security bulk-scan --help`
471
477
  for the complete CLI references.
@@ -478,6 +484,11 @@ Private checkouts reuse your GitHub CLI sign-in without changing your global Git
478
484
  configuration. The selected repositories are saved to
479
485
  `<output-dir>/repositories.csv` for review or resumption.
480
486
 
487
+ Interactive discovery accepts the same `--workers`, `--mode`, `--max-attempts`,
488
+ `--model`, `--effort`, `--plugin-path`, `--python`, and `--codex` settings as
489
+ CSV-driven scans. It prompts for the output directory; `--output-dir` is only
490
+ valid when a repository CSV is supplied.
491
+
481
492
  To use an existing repository list or run in CI, pass a CSV with required `id`,
482
493
  `repository`, and `revision` columns. Revisions must be full commit hashes;
483
494
  optional `scope`, `mode`, and `prompt` columns customize individual scans:
@@ -490,7 +501,8 @@ service,https://github.com/acme/service.git,0123456789abcdef0123456789abcdef0123
490
501
  Use `--scan-prompt-file PATH` to add instructions to a scan or every bulk scan.
491
502
  Bulk scans append each repository's CSV `prompt` after the shared instructions.
492
503
  Use `--post-scan-prompt-file PATH` to run a follow-up in the same authenticated
493
- session after each completed scan has been validated.
504
+ session after each scan, including incomplete or failed scans. Canceled scans
505
+ and scans stopped at their configured cost limit do not start another turn.
494
506
 
495
507
  `--workers` limits concurrent scans and `--max-attempts` retries failures.
496
508
  Results remain under `--output-dir`; rerun the same command to resume.
@@ -503,13 +515,17 @@ whose artifacts are under a particular root. `scans show SCAN_ID` includes the
503
515
  scan configuration, results, coverage, and artifact locations. Add
504
516
  `--show-linked-findings` to include finding links from previous scans.
505
517
 
518
+ `scans logs SCAN_ID` shows complete session events from the scan and its
519
+ workers, which can include source code and credentials.
520
+
506
521
  Every scan history command accepts a full scan ID or a unique prefix of at
507
522
  least eight characters.
508
523
 
509
524
  Scan history uses the existing Codex Security workbench database at
510
525
  `$CODEX_HOME/state/plugins/codex-security/workbench.sqlite3`. Set
511
526
  `CODEX_SECURITY_STATE_DIR` to place the database elsewhere. Scan credentials
512
- are never stored in the scan configuration.
527
+ are never stored in the scan configuration. Recorded failure summaries and
528
+ bulk-scan receipts omit messages that contain recognizable credentials.
513
529
 
514
530
  The scan sandbox permits writes to the selected state directory so SQLite can
515
531
  maintain its database and journal files. If the host itself cannot write to the
@@ -580,11 +596,7 @@ text. Both commands operate on the current directory, use the scan model
580
596
  and reasoning defaults, ignore unrelated user configuration and plugins, and
581
597
  print the final response without the underlying Codex event stream. Override
582
598
  the model with `--codex 'model="gpt-5.6-sol"'` and the reasoning effort with
583
- `--effort high` or `--codex 'model_reasoning_effort="high"'`. Inputs are
584
- limited to 64 items and 1 MiB total.
585
-
586
- Canonical scan documents are limited to 16 MiB for the manifest, 128 MiB for
587
- findings, and 32 MiB for coverage. Oversized scans are rejected before sealing.
599
+ `--effort high` or `--codex 'model_reasoning_effort="high"'`.
588
600
 
589
601
  Exit codes are `0` for a completed report-only scan or a passing policy, `1`
590
602
  for a completed policy violation, `2` for invalid input, incomplete coverage, or
@@ -632,6 +644,10 @@ device login remains in `state/`. For unattended scans, set `OPENAI_API_KEY`
632
644
  or `CODEX_API_KEY` instead. Set `GH_TOKEN` or `GITHUB_TOKEN` for private
633
645
  GitHub repositories.
634
646
 
647
+ The container accepts the repository CSV before or after bulk-scan options.
648
+ Interactive repository discovery remains disabled, including when global CLI
649
+ options appear before `bulk-scan`.
650
+
635
651
  On Ubuntu hosts that restrict unprivileged user namespaces, an administrator
636
652
  can install the optional, narrowly scoped AppArmor profile once:
637
653
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-security",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Codex Security workflows for security scans, analysis, and investigation.",
5
5
  "author": {
6
6
  "name": "OpenAI"
@@ -40,7 +40,7 @@ description = "Capabilities for Git-backed Codex Security diff scans."
40
40
  [[profiles.security_diff_scan.requirements]]
41
41
  capability = "delegated_workers"
42
42
  severity = "warn"
43
- reason = "Large exhaustive diff scans use delegated workers when available; without them, the scan may need a narrower or parent-agent-only path."
43
+ reason = "Large diff scans may use discovery workers when available; otherwise the parent reviews every changed file."
44
44
 
45
45
  [[profiles.security_diff_scan.requirements]]
46
46
  capability = "goal_tools"
@@ -44,7 +44,7 @@ A dirty checkout has `allowedKinds: ["git_worktree"]`: copy `requiredSnapshotDig
44
44
 
45
45
  `targetId` identifies the stable repository or workspace. Prefer a digest of a sanitized canonical absolute remote URL when one exists. Otherwise use a digest of a stable local workspace identity. Never persist remote URL credentials, query parameters, fragments, or tokens.
46
46
 
47
- For dirty worktrees and diffs, calculate `snapshotDigest` from a deterministic representation of the reviewed content, including staged changes and reviewed untracked files where applicable. For directory snapshots, hash a sorted relative-path and file-hash inventory of the reviewed scope. Encode the result as `codex-security-snapshot/v1:sha256:<64 lowercase hex characters>`.
47
+ For dirty worktrees and working-tree diffs, calculate `snapshotDigest` from a deterministic representation of the reviewed content, including staged changes and reviewed untracked files where applicable. For committed or revision-range diffs, derive it from the exact authoritative diff kind and immutable base/head revisions. For directory snapshots, hash a sorted relative-path and file-hash inventory of the reviewed scope. Encode the result as `codex-security-snapshot/v1:sha256:<64 lowercase hex characters>`.
48
48
 
49
49
  ## Finding Identity
50
50
 
@@ -1274,6 +1274,28 @@ def upsert_deep_scan_worker(
1274
1274
  """,
1275
1275
  (timestamp, scan_id),
1276
1276
  )
1277
+ elif args.kind == "dedup" and args.status == "failed" and existing["status"] == "running":
1278
+ connection.execute(
1279
+ """
1280
+ UPDATE deep_scan_workers
1281
+ SET merge_state = 'buffered', updated_at = ?
1282
+ WHERE scan_id = ? AND kind = 'discovery' AND status = 'succeeded'
1283
+ AND merge_state = 'merging'
1284
+ AND id IN (
1285
+ SELECT discovery_worker_id FROM deep_scan_dedup_inputs
1286
+ WHERE scan_id = ? AND dedup_worker_id = ?
1287
+ )
1288
+ """,
1289
+ (timestamp, scan_id, scan_id, worker_id),
1290
+ )
1291
+ connection.execute(
1292
+ """
1293
+ UPDATE deep_scan_runs
1294
+ SET phase = 'discovery', updated_at = ?
1295
+ WHERE scan_id = ?
1296
+ """,
1297
+ (timestamp, scan_id),
1298
+ )
1277
1299
  completed_at = (
1278
1300
  timestamp
1279
1301
  if args.status in {"succeeded", "failed", "canceled"}
@@ -91,6 +91,88 @@ def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:
91
91
  inventory.seek(0)
92
92
  rows = sorted(inventory)
93
93
 
94
+ return write_inventory(output, rows)
95
+
96
+
97
+ def generate_diff_in_scope_files(
98
+ repository: Path,
99
+ base: str,
100
+ head: str,
101
+ mode: str,
102
+ output: Path,
103
+ ) -> int:
104
+ """Reuse the existing diff selection without generating previews or duplicate worklists."""
105
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
106
+ from generate_rank_input import git_changed_paths, path_is_excluded, run_git_changed_paths
107
+ from rank_preview import (
108
+ DEFAULT_PREVIEW_BYTES,
109
+ TEXT_CODE_EXTENSIONS,
110
+ is_binary_sample,
111
+ preview_for,
112
+ )
113
+
114
+ rows: list[bytes] = []
115
+ try:
116
+ if mode == "local-patch":
117
+ changed = run_git_changed_paths(repository, [base])
118
+ untracked = subprocess.run(
119
+ ["git", "-C", str(repository), "ls-files", "--others", "--exclude-standard", "-z"],
120
+ capture_output=True,
121
+ text=True,
122
+ check=True,
123
+ )
124
+ changed.extend(
125
+ (repository / relative, "A")
126
+ for relative in untracked.stdout.split("\0")
127
+ if relative
128
+ )
129
+ else:
130
+ changed = git_changed_paths(repository, base, head, mode)
131
+
132
+ for path, status in changed:
133
+ relative = path.relative_to(repository)
134
+ if path_is_excluded(relative) or path.suffix.lower() not in TEXT_CODE_EXTENSIONS:
135
+ continue
136
+ if status != "D":
137
+ if mode == "revisions":
138
+ contents = subprocess.run(
139
+ [
140
+ "git",
141
+ "-C",
142
+ str(repository),
143
+ "cat-file",
144
+ "blob",
145
+ f"{head}:{relative.as_posix()}",
146
+ ],
147
+ capture_output=True,
148
+ check=True,
149
+ ).stdout
150
+ if is_binary_sample(contents):
151
+ continue
152
+ elif (
153
+ path.is_symlink()
154
+ or not path.is_file()
155
+ or preview_for(path, DEFAULT_PREVIEW_BYTES)[1]
156
+ ):
157
+ continue
158
+ relative_path = relative.as_posix()
159
+ if "\n" in relative_path or "\r" in relative_path:
160
+ raise InventoryError(
161
+ "Git changes contain a path that cannot fit in the file inventory"
162
+ )
163
+ rows.append(f"{relative_path}\n".encode())
164
+ except (OSError, subprocess.CalledProcessError) as error:
165
+ detail = getattr(error, "stderr", None)
166
+ if isinstance(detail, bytes):
167
+ detail = detail.decode("utf-8", errors="replace")
168
+ message = detail.strip() if isinstance(detail, str) and detail.strip() else str(error)
169
+ raise InventoryError(f"could not resolve the selected Git changes: {message}") from error
170
+
171
+ return write_inventory(output, sorted(set(rows)))
172
+
173
+
174
+ def write_inventory(output: Path, rows: list[bytes]) -> int:
175
+ """Replace a complete inventory atomically, keeping failures from corrupting the old one."""
94
176
  output.parent.mkdir(parents=True, exist_ok=True)
95
177
  temporary: Path | None = None
96
178
  try:
@@ -116,13 +198,32 @@ def main() -> None:
116
198
  parser.add_argument("--repo", required=True, help="Repository root.")
117
199
  parser.add_argument("--scope", required=True, help="File or directory within the repository.")
118
200
  parser.add_argument("--out", required=True, help="Destination for the file inventory.")
201
+ parser.add_argument("--diff-base", help="Authoritative Git base for a changed-file inventory.")
202
+ parser.add_argument("--diff-head", default="HEAD", help="Authoritative Git head revision.")
203
+ parser.add_argument(
204
+ "--diff-mode",
205
+ choices=("revisions", "local-patch"),
206
+ default="revisions",
207
+ help="Use committed revisions or the current staged and unstaged patch.",
208
+ )
119
209
  args = parser.parse_args()
120
210
 
121
211
  try:
122
212
  repository = resolve_repository(args.repo)
123
213
  scope = resolve_scope(repository, args.scope)
124
214
  output = resolve_output(args.out)
125
- count = generate_in_scope_files(repository, scope, output)
215
+ if args.diff_base is None:
216
+ count = generate_in_scope_files(repository, scope, output)
217
+ elif scope not in (".", "./"):
218
+ raise InventoryError("--scope: diff scans must use the repository root")
219
+ else:
220
+ count = generate_diff_in_scope_files(
221
+ repository,
222
+ args.diff_base,
223
+ args.diff_head,
224
+ args.diff_mode,
225
+ output,
226
+ )
126
227
  except (OSError, ValueError) as error:
127
228
  print(f"generate_in_scope_files: {error}", file=sys.stderr)
128
229
  raise SystemExit(2) from error
@@ -288,10 +288,36 @@ def path_is_excluded(path: Path) -> bool:
288
288
  return path.name.endswith((".min.js", ".map"))
289
289
 
290
290
 
291
- def resolve_scope(repo: Path, scope: str, *, expand_user: bool = True) -> Path:
291
+ def resolve_scope(
292
+ repo: Path,
293
+ scope: str,
294
+ *,
295
+ expand_user: bool = True,
296
+ reject_symlinks: bool = False,
297
+ ) -> Path:
292
298
  scope_path = Path(scope).expanduser() if expand_user else Path(scope)
293
299
  if not scope_path.is_absolute():
294
300
  scope_path = repo / scope_path
301
+ if reject_symlinks:
302
+ repository = repo.resolve()
303
+ try:
304
+ relative = scope_path.relative_to(repository)
305
+ except ValueError as exc:
306
+ raise SystemExit(f"Scope must be inside repo: {scope_path}") from exc
307
+ ancestor = repository
308
+ for part in relative.parts:
309
+ if part == "..":
310
+ if ancestor == repository:
311
+ raise SystemExit(f"Scope must be inside repo: {scope_path}")
312
+ ancestor = ancestor.parent
313
+ continue
314
+ ancestor /= part
315
+ try:
316
+ metadata = ancestor.stat(follow_symlinks=False)
317
+ except OSError as exc:
318
+ raise SystemExit(f"Scope path not found: {ancestor}") from exc
319
+ if ancestor.is_symlink() or getattr(metadata, "st_reparse_tag", 0) & 0x20000000:
320
+ raise SystemExit(f"Requested scope must not contain symbolic links: {ancestor}")
295
321
  scope_path = scope_path.resolve()
296
322
  repo_resolved = repo.resolve()
297
323
  try:
@@ -481,7 +507,7 @@ def make_repo_scope_input(args: argparse.Namespace) -> None:
481
507
  scopes = load_scopes_file(Path(args.scopes_file).expanduser())
482
508
  rows_by_path: dict[str, JsonRow] = {}
483
509
  for scope in scopes:
484
- scope_path = resolve_scope(repo, scope, expand_user=False)
510
+ scope_path = resolve_scope(repo, scope, expand_user=False, reject_symlinks=True)
485
511
  if scope_path.is_file():
486
512
  candidates = (scope_path,)
487
513
  else:
@@ -135,7 +135,7 @@ def normalize_locations(
135
135
  )
136
136
 
137
137
 
138
- def read_scope(path: Path, repo_root: Path) -> set[str]:
138
+ def read_scope(path: Path, repo_root: Path, *, allow_missing: bool = False) -> set[str]:
139
139
  contents = path.read_bytes().decode("utf-8")
140
140
  lines = contents.split("\n")
141
141
  listed_rows = set(lines)
@@ -183,6 +183,19 @@ def read_scope(path: Path, repo_root: Path) -> set[str]:
183
183
  try:
184
184
  relative, _ = relative_file(line, repo_root)
185
185
  except (OSError, ValueError) as error:
186
+ if allow_missing and isinstance(error, FileNotFoundError):
187
+ candidate = PurePosixPath(line)
188
+ if candidate.is_absolute() or ".." in candidate.parts or "\0" in line:
189
+ raise ValueError(f"in-scope file row {number}: unsafe deleted path") from error
190
+ resolved = (repo_root / line).resolve(strict=False)
191
+ try:
192
+ relative = resolved.relative_to(repo_root).as_posix()
193
+ except ValueError as escaped:
194
+ raise ValueError(
195
+ f"in-scope file row {number}: path escapes repository"
196
+ ) from escaped
197
+ scope.add(relative)
198
+ continue
186
199
  raise ValueError(f"in-scope file row {number}: {error}") from error
187
200
  scope.add(relative)
188
201
  return scope
@@ -261,6 +274,11 @@ def main() -> None:
261
274
  parser.add_argument("--out", required=True, help="Combined candidate JSONL output.")
262
275
  parser.add_argument("--repo-root", required=True, help="Repository root for candidate paths.")
263
276
  parser.add_argument("--in-scope-files", required=True, help="Repository-relative file list.")
277
+ parser.add_argument(
278
+ "--allow-missing-in-scope",
279
+ action="store_true",
280
+ help="Keep deleted Git paths in a diff inventory while validating existing candidate files.",
281
+ )
264
282
  args = parser.parse_args()
265
283
  try:
266
284
  repo_root = Path(args.repo_root).expanduser().resolve(strict=True)
@@ -273,7 +291,7 @@ def main() -> None:
273
291
  raise ValueError("--out: must not also be an input")
274
292
  if output == scope_path:
275
293
  raise ValueError("--out: must not replace --in-scope-files")
276
- scope = read_scope(scope_path, repo_root)
294
+ scope = read_scope(scope_path, repo_root, allow_missing=args.allow_missing_in_scope)
277
295
  line_counts: dict[Path, int] = {}
278
296
  rows: list[dict[str, Any]] = []
279
297
  for source in inputs:
@@ -147,6 +147,10 @@ def parse_args(description: str) -> argparse.Namespace:
147
147
  register_cli_scan.add_argument("--archive-existing", action="store_true")
148
148
  register_cli_scan.add_argument("--archived-scan-dir")
149
149
 
150
+ set_scan_thread = subparsers.add_parser("set-scan-thread")
151
+ set_scan_thread.add_argument("--scan-id", required=True)
152
+ set_scan_thread.add_argument("--thread-id", required=True)
153
+
150
154
  get_scan_recipe = subparsers.add_parser("get-scan-recipe")
151
155
  get_scan_recipe.add_argument("--scan-id", required=True)
152
156
 
@@ -39,7 +39,6 @@ SQLITE_RETRY_ATTEMPTS = 5
39
39
  CLAIM_LEASE_SECONDS = 120
40
40
  DELIVERED_ACTION_LEASE_SECONDS = 900
41
41
  PATCH_PREVIEW_BYTES = 16_000
42
- PATCH_ARTIFACT_MAX_BYTES = 2 * 1024 * 1024
43
42
  FINDINGS_RESULT_LIMIT = 20
44
43
  FINDINGS_PAGE_MAX = 20
45
44
  FINDING_DETAILS_PREVIEW_BYTES = 16_000
@@ -74,7 +74,6 @@ from workbench_constants import (
74
74
  FINDING_TITLE_BYTES,
75
75
  FINDINGS_PAGE_MAX,
76
76
  FINDINGS_RESULT_LIMIT,
77
- PATCH_ARTIFACT_MAX_BYTES,
78
77
  PATCH_PREVIEW_BYTES,
79
78
  SQLITE_RETRY_ATTEMPTS,
80
79
  )
@@ -1433,6 +1432,16 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
1433
1432
  }
1434
1433
 
1435
1434
 
1435
+ def set_scan_thread(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1436
+ scan = require_scan(connection, args.scan_id)
1437
+ with connection:
1438
+ connection.execute(
1439
+ "UPDATE scans SET continuation_thread_id = ?, updated_at = ? WHERE id = ?",
1440
+ (args.thread_id, now(), scan["id"]),
1441
+ )
1442
+ return {"scanId": scan["id"], "threadId": args.thread_id}
1443
+
1444
+
1436
1445
  def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
1437
1446
  if len(value.encode("utf-8")) > SCAN_RECIPE_MAX_BYTES:
1438
1447
  raise SystemExit("Scan launch recipe must be no larger than 256 KiB.")
@@ -2442,18 +2451,12 @@ def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2442
2451
  def require_matching_patch_digest(scan: sqlite3.Row, patch_path: str, patch_digest: str) -> None:
2443
2452
  digest = hashlib.sha256()
2444
2453
  with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as patch:
2445
- require_bounded_patch_artifact(patch)
2446
2454
  while chunk := patch.read(1024 * 1024):
2447
2455
  digest.update(chunk)
2448
2456
  if f"sha256:{digest.hexdigest()}" != patch_digest:
2449
2457
  raise SystemExit("Patch digest does not match the scan-local patch file.")
2450
2458
 
2451
2459
 
2452
- def require_bounded_patch_artifact(patch: Any) -> None:
2453
- if os.fstat(patch.fileno()).st_size > PATCH_ARTIFACT_MAX_BYTES:
2454
- raise SystemExit("Patch artifact must be no larger than 2 MiB.")
2455
-
2456
-
2457
2460
  def open_scan_local_file(scan_dir: Path, relative_path: str) -> Any:
2458
2461
  parsed = PurePosixPath(relative_path)
2459
2462
  if parsed.is_absolute() or not parsed.parts or ".." in parsed.parts:
@@ -3150,7 +3153,6 @@ def patch_artifact_preview(
3150
3153
  at_line_start = True
3151
3154
  try:
3152
3155
  with open_scan_local_file(scan_dir, relative_path) as patch:
3153
- require_bounded_patch_artifact(patch)
3154
3156
  while chunk := patch.readline(1024 * 1024):
3155
3157
  digest.update(chunk)
3156
3158
  if len(preview) <= PATCH_PREVIEW_BYTES:
@@ -3362,6 +3364,8 @@ def main() -> None:
3362
3364
  )
3363
3365
  elif args.command == "register-cli-scan":
3364
3366
  result = register_cli_scan(connection, args)
3367
+ elif args.command == "set-scan-thread":
3368
+ result = set_scan_thread(connection, args)
3365
3369
  elif args.command == "get-scan-recipe":
3366
3370
  result = get_scan_recipe(connection, args)
3367
3371
  elif args.command == "compare-scans":