@openai/codex-security 0.1.6 → 0.1.8
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.
- package/README.md +20 -3
- package/_bundled_plugin/.mcp.json +16 -0
- package/_bundled_plugin/mcp/server.mjs +1 -1
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/preflight/capability-profiles.toml +2 -2
- package/_bundled_plugin/references/config-preflight.md +6 -6
- package/_bundled_plugin/references/desktop-config-preflight.md +11 -0
- package/_bundled_plugin/references/final-report.md +10 -14
- package/_bundled_plugin/references/scan-artifacts.md +17 -17
- package/_bundled_plugin/references/shared-hard-rules.md +2 -2
- package/_bundled_plugin/scripts/deep_scan_workbench.py +422 -48
- package/_bundled_plugin/scripts/generate_rank_input.py +91 -0
- package/_bundled_plugin/scripts/workbench_cli.py +1 -50
- package/_bundled_plugin/scripts/workbench_constants.py +0 -2
- package/_bundled_plugin/scripts/workbench_db.py +7 -289
- package/_bundled_plugin/scripts/workbench_progress.py +11 -0
- package/_bundled_plugin/scripts/workbench_scan_history.py +0 -54
- package/_bundled_plugin/scripts/workbench_target.py +2 -6
- package/_bundled_plugin/scripts/workbench_validation.py +0 -211
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +10 -10
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +25 -43
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +2 -4
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +11 -23
- package/_bundled_plugin/skills/security-scan/SKILL.md +89 -26
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +25 -0
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +11 -38
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +5 -6
- package/_bundled_plugin/skills/triage-finding/SKILL.md +6 -14
- package/_bundled_plugin/skills/validation/SKILL.md +9 -9
- package/dist/api.d.ts +6 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +111 -31
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +77 -17
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +18 -10
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +4 -1
- package/dist/cost.js.map +1 -1
- package/dist/multiscan.d.ts +5 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +206 -26
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts +13 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +122 -92
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -2
- package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
|
@@ -27,6 +27,7 @@ from __future__ import annotations
|
|
|
27
27
|
import argparse
|
|
28
28
|
import hashlib
|
|
29
29
|
import json
|
|
30
|
+
import os
|
|
30
31
|
import re
|
|
31
32
|
import subprocess
|
|
32
33
|
import sys
|
|
@@ -37,6 +38,7 @@ from pathlib import Path
|
|
|
37
38
|
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
38
39
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
39
40
|
from rank_preview import DEFAULT_PREVIEW_BYTES, TEXT_CODE_EXTENSIONS, preview_for
|
|
41
|
+
from workbench_target import git_directory_snapshot_paths
|
|
40
42
|
|
|
41
43
|
EXCLUDED_DIRS = {
|
|
42
44
|
".cache",
|
|
@@ -153,6 +155,18 @@ def parse_args() -> argparse.Namespace:
|
|
|
153
155
|
help=f"Maximum UTF-8 bytes in each preview. Defaults to {DEFAULT_PREVIEW_BYTES}.",
|
|
154
156
|
)
|
|
155
157
|
|
|
158
|
+
scoped = subparsers.add_parser(
|
|
159
|
+
"make-repo-scope-input",
|
|
160
|
+
help="List every explicitly scoped file without ranking or reading its contents.",
|
|
161
|
+
)
|
|
162
|
+
scoped.add_argument("--repo", required=True, help="Repository root.")
|
|
163
|
+
scoped.add_argument(
|
|
164
|
+
"--scopes-file",
|
|
165
|
+
required=True,
|
|
166
|
+
help="JSON array of repository-relative files and directories to scan together.",
|
|
167
|
+
)
|
|
168
|
+
scoped.add_argument("--out", required=True, help="Output scoped-source-input.jsonl path.")
|
|
169
|
+
|
|
156
170
|
bind = subparsers.add_parser(
|
|
157
171
|
"bind-repo-scopes",
|
|
158
172
|
help="Copy SDK scoped-path targets into the unsealed manifest and coverage documents.",
|
|
@@ -459,6 +473,81 @@ def make_repo_rank_input(args: argparse.Namespace) -> None:
|
|
|
459
473
|
print(f"Wrote {len(rows)} rows to {output}")
|
|
460
474
|
|
|
461
475
|
|
|
476
|
+
def make_repo_scope_input(args: argparse.Namespace) -> None:
|
|
477
|
+
repo = Path(args.repo).expanduser().resolve()
|
|
478
|
+
if not repo.is_dir():
|
|
479
|
+
raise SystemExit(f"Repo path not found: {repo}")
|
|
480
|
+
|
|
481
|
+
scopes = load_scopes_file(Path(args.scopes_file).expanduser())
|
|
482
|
+
rows_by_path: dict[str, JsonRow] = {}
|
|
483
|
+
for scope in scopes:
|
|
484
|
+
scope_path = resolve_scope(repo, scope, expand_user=False)
|
|
485
|
+
if scope_path.is_file():
|
|
486
|
+
candidates = (scope_path,)
|
|
487
|
+
else:
|
|
488
|
+
git_candidates = git_directory_snapshot_paths(scope_path)
|
|
489
|
+
if git_candidates is not None:
|
|
490
|
+
candidates = git_candidates
|
|
491
|
+
else:
|
|
492
|
+
command = [
|
|
493
|
+
"rg",
|
|
494
|
+
"--files",
|
|
495
|
+
"--hidden",
|
|
496
|
+
"--no-require-git",
|
|
497
|
+
"--null",
|
|
498
|
+
"--glob",
|
|
499
|
+
"!.git/**",
|
|
500
|
+
"--",
|
|
501
|
+
str(scope_path.relative_to(repo)),
|
|
502
|
+
]
|
|
503
|
+
try:
|
|
504
|
+
result = subprocess.run(command, cwd=repo, capture_output=True, check=False)
|
|
505
|
+
except OSError as exc:
|
|
506
|
+
ignore_names = (".gitignore", ".ignore", ".rgignore")
|
|
507
|
+
ancestors = (scope_path, *scope_path.parents)
|
|
508
|
+
has_ignore_rules = (
|
|
509
|
+
any((ancestor / ".git").exists() for ancestor in (repo, *repo.parents))
|
|
510
|
+
or any(
|
|
511
|
+
(ancestor / name).is_file()
|
|
512
|
+
for ancestor in ancestors
|
|
513
|
+
if ancestor == repo or repo in ancestor.parents
|
|
514
|
+
for name in ignore_names
|
|
515
|
+
)
|
|
516
|
+
or any(
|
|
517
|
+
path.name in ignore_names
|
|
518
|
+
for path in scope_path.rglob("*")
|
|
519
|
+
if path.is_file()
|
|
520
|
+
)
|
|
521
|
+
)
|
|
522
|
+
if has_ignore_rules:
|
|
523
|
+
raise SystemExit(
|
|
524
|
+
"Could not safely enumerate ignored scoped files without Git or ripgrep."
|
|
525
|
+
) from exc
|
|
526
|
+
candidates = scope_path.rglob("*")
|
|
527
|
+
else:
|
|
528
|
+
if result.returncode not in (0, 1):
|
|
529
|
+
detail = result.stderr.decode("utf-8", errors="replace").strip()
|
|
530
|
+
raise SystemExit(f"Could not enumerate scoped repository files: {detail}")
|
|
531
|
+
candidates = (
|
|
532
|
+
repo / os.fsdecode(path) for path in result.stdout.split(b"\0") if path
|
|
533
|
+
)
|
|
534
|
+
for path in candidates:
|
|
535
|
+
try:
|
|
536
|
+
if path.is_symlink() or not path.is_file():
|
|
537
|
+
continue
|
|
538
|
+
relative = path.resolve(strict=True).relative_to(repo)
|
|
539
|
+
except (OSError, ValueError):
|
|
540
|
+
continue
|
|
541
|
+
if ".git" in relative.parts:
|
|
542
|
+
continue
|
|
543
|
+
rows_by_path.setdefault(relative.as_posix(), {"path": relative.as_posix()})
|
|
544
|
+
|
|
545
|
+
rows = sorted(rows_by_path.values(), key=lambda row: str(row["path"]))
|
|
546
|
+
output = Path(args.out).expanduser()
|
|
547
|
+
write_jsonl(output, rows)
|
|
548
|
+
print(f"Wrote {len(rows)} scoped paths to {output}")
|
|
549
|
+
|
|
550
|
+
|
|
462
551
|
def bind_repo_scopes(args: argparse.Namespace) -> None:
|
|
463
552
|
scopes = load_scopes_file(Path(args.scopes_file).expanduser())
|
|
464
553
|
manifest_path = Path(args.manifest).expanduser()
|
|
@@ -985,6 +1074,8 @@ def main() -> None:
|
|
|
985
1074
|
args = parse_args()
|
|
986
1075
|
if args.command == "make-repo-rank-input":
|
|
987
1076
|
make_repo_rank_input(args)
|
|
1077
|
+
elif args.command == "make-repo-scope-input":
|
|
1078
|
+
make_repo_scope_input(args)
|
|
988
1079
|
elif args.command == "bind-repo-scopes":
|
|
989
1080
|
bind_repo_scopes(args)
|
|
990
1081
|
elif args.command == "make-diff-rank-input":
|
|
@@ -28,8 +28,6 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
28
28
|
parser = argparse.ArgumentParser(description=description)
|
|
29
29
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
30
30
|
|
|
31
|
-
subparsers.add_parser("get-setup-preference")
|
|
32
|
-
|
|
33
31
|
create_workspace = subparsers.add_parser("create-workspace")
|
|
34
32
|
create_workspace.add_argument("--workspace-id", required=True)
|
|
35
33
|
create_workspace.add_argument("--thread-id")
|
|
@@ -37,9 +35,6 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
37
35
|
create_workspace.add_argument("--target-title")
|
|
38
36
|
create_workspace.add_argument("--target-summary")
|
|
39
37
|
create_workspace.add_argument("--user-context")
|
|
40
|
-
create_preflight = create_workspace.add_mutually_exclusive_group()
|
|
41
|
-
create_preflight.add_argument("--capability-preflight-json")
|
|
42
|
-
create_preflight.add_argument("--capability-preflight-json-file", type=Path)
|
|
43
38
|
create_workspace.add_argument("--scope")
|
|
44
39
|
create_workspace.add_argument("--mode", choices=MODES, default="standard")
|
|
45
40
|
create_workspace.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
@@ -51,14 +46,6 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
51
46
|
get_workspace.add_argument("--workspace-id", required=True)
|
|
52
47
|
get_workspace.add_argument("--thread-id")
|
|
53
48
|
|
|
54
|
-
get_latest_workspace = subparsers.add_parser("get-latest-workspace")
|
|
55
|
-
get_latest_workspace.add_argument("--thread-id", required=True)
|
|
56
|
-
|
|
57
|
-
list_workspace_scans = subparsers.add_parser("list-workspace-scans")
|
|
58
|
-
list_workspace_scans.add_argument("--workspace-id", required=True)
|
|
59
|
-
list_workspace_scans.add_argument("--offset", type=non_negative_int, default=0)
|
|
60
|
-
list_workspace_scans.add_argument("--limit", type=workspace_scan_limit, default=20)
|
|
61
|
-
|
|
62
49
|
inspect_target = subparsers.add_parser("inspect-target")
|
|
63
50
|
inspect_target.add_argument("--target-path", required=True)
|
|
64
51
|
|
|
@@ -71,25 +58,6 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
71
58
|
inspect_setup.add_argument("--diff-head-revision")
|
|
72
59
|
inspect_setup.add_argument("--diff-content-digest")
|
|
73
60
|
|
|
74
|
-
begin_diff_resolution = subparsers.add_parser("begin-diff-resolution")
|
|
75
|
-
begin_diff_resolution.add_argument("--workspace-id", required=True)
|
|
76
|
-
begin_diff_resolution.add_argument("--request-id", required=True)
|
|
77
|
-
begin_diff_resolution.add_argument("--target-path", required=True)
|
|
78
|
-
begin_diff_resolution.add_argument("--user-context")
|
|
79
|
-
|
|
80
|
-
cancel_diff_resolution = subparsers.add_parser("cancel-diff-resolution")
|
|
81
|
-
cancel_diff_resolution.add_argument("--workspace-id", required=True)
|
|
82
|
-
cancel_diff_resolution.add_argument("--request-id", required=True)
|
|
83
|
-
|
|
84
|
-
set_diff_target = subparsers.add_parser("set-diff-target")
|
|
85
|
-
set_diff_target.add_argument("--workspace-id", required=True)
|
|
86
|
-
set_diff_target.add_argument("--request-id", required=True)
|
|
87
|
-
set_diff_target.add_argument("--target-summary", required=True)
|
|
88
|
-
set_diff_target.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS, required=True)
|
|
89
|
-
set_diff_target.add_argument("--diff-base-revision")
|
|
90
|
-
set_diff_target.add_argument("--diff-head-revision")
|
|
91
|
-
set_diff_target.add_argument("--diff-content-digest")
|
|
92
|
-
|
|
93
61
|
save_workspace = subparsers.add_parser("save-workspace")
|
|
94
62
|
save_workspace.add_argument("--workspace-id", required=True)
|
|
95
63
|
save_workspace.add_argument("--target-path", required=True)
|
|
@@ -102,23 +70,12 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
102
70
|
save_workspace.add_argument("--diff-head-revision")
|
|
103
71
|
save_workspace.add_argument("--diff-content-digest")
|
|
104
72
|
|
|
105
|
-
set_capability_preflight = subparsers.add_parser("set-capability-preflight")
|
|
106
|
-
set_capability_preflight.add_argument("--workspace-id", required=True)
|
|
107
|
-
set_capability_preflight.add_argument("--checked-target-path", required=True)
|
|
108
|
-
set_capability_preflight.add_argument("--checked-mode", choices=MODES, required=True)
|
|
109
|
-
set_preflight = set_capability_preflight.add_mutually_exclusive_group(required=True)
|
|
110
|
-
set_preflight.add_argument("--capability-preflight-json")
|
|
111
|
-
set_preflight.add_argument("--capability-preflight-json-file", type=Path)
|
|
112
|
-
|
|
113
73
|
start_scan = subparsers.add_parser("start-scan")
|
|
114
74
|
start_scan.add_argument("--workspace-id", required=True)
|
|
115
75
|
start_scan.add_argument("--scan-root")
|
|
116
76
|
start_scan.add_argument("--model")
|
|
117
77
|
start_scan.add_argument("--reasoning-effort")
|
|
118
78
|
|
|
119
|
-
disable_setup_ui = subparsers.add_parser("disable-setup-ui")
|
|
120
|
-
disable_setup_ui.add_argument("--workspace-id", required=True)
|
|
121
|
-
|
|
122
79
|
start_prompt_only_scan = subparsers.add_parser("start-prompt-only-scan")
|
|
123
80
|
start_prompt_only_scan.add_argument("--thread-id", required=True)
|
|
124
81
|
start_prompt_only_scan.add_argument("--target-path", required=True)
|
|
@@ -238,6 +195,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
238
195
|
update_progress.add_argument("--reportable-findings-count", type=non_negative_int)
|
|
239
196
|
update_progress.add_argument("--deep-review-pass", type=positive_int)
|
|
240
197
|
update_progress.add_argument("--claim-token")
|
|
198
|
+
update_progress.add_argument("--coordinator-generation", type=positive_int)
|
|
241
199
|
update_progress.add_argument("--model")
|
|
242
200
|
update_progress.add_argument("--reasoning-effort")
|
|
243
201
|
|
|
@@ -355,12 +313,5 @@ def positive_int(value: str) -> int:
|
|
|
355
313
|
return parsed
|
|
356
314
|
|
|
357
315
|
|
|
358
|
-
def workspace_scan_limit(value: str) -> int:
|
|
359
|
-
parsed = positive_int(value)
|
|
360
|
-
if parsed > 100:
|
|
361
|
-
raise argparse.ArgumentTypeError("expected an integer between 1 and 100")
|
|
362
|
-
return parsed
|
|
363
|
-
|
|
364
|
-
|
|
365
316
|
if __name__ == "__main__":
|
|
366
317
|
parse_args(__doc__)
|
|
@@ -57,8 +57,6 @@ FINDING_LOCATION_PATH_BYTES = 2_048
|
|
|
57
57
|
FINDING_LOCATION_ROLE_BYTES = 128
|
|
58
58
|
FINDING_ABSOLUTE_PATH_BYTES = 4_096
|
|
59
59
|
FINDING_LEVEL_BYTES = 128
|
|
60
|
-
MAX_CAPABILITY_PREFLIGHT_INPUT_JSON_BYTES = 160_000
|
|
61
|
-
MAX_CAPABILITY_PREFLIGHT_PERSISTED_JSON_BYTES = 180_000
|
|
62
60
|
GIT_REPOSITORY_ENVIRONMENT = (
|
|
63
61
|
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
64
62
|
"GIT_CEILING_DIRECTORIES",
|
|
@@ -121,8 +121,6 @@ from workbench_target import (
|
|
|
121
121
|
from workbench_target_state import backfill_security_targets, ensure_security_target
|
|
122
122
|
from workbench_validation import (
|
|
123
123
|
bounded_output_text,
|
|
124
|
-
capability_preflight_input,
|
|
125
|
-
capability_preflight_json,
|
|
126
124
|
optional_text,
|
|
127
125
|
parse_scan_cost,
|
|
128
126
|
path_within_scope,
|
|
@@ -246,39 +244,6 @@ def connect() -> sqlite3.Connection:
|
|
|
246
244
|
raise AssertionError("SQLite retry loop exhausted unexpectedly.")
|
|
247
245
|
|
|
248
246
|
|
|
249
|
-
def setup_preference(connection: sqlite3.Connection) -> dict[str, bool]:
|
|
250
|
-
row = connection.execute(
|
|
251
|
-
"SELECT skip_setup_ui FROM setup_preferences WHERE singleton = 1"
|
|
252
|
-
).fetchone()
|
|
253
|
-
return {"skipSetupUi": bool(row["skip_setup_ui"]) if row is not None else False}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
def record_setup_ui_disabled(connection: sqlite3.Connection, timestamp: str) -> None:
|
|
257
|
-
connection.execute(
|
|
258
|
-
"""
|
|
259
|
-
INSERT INTO setup_preferences (singleton, skip_setup_ui, updated_at)
|
|
260
|
-
VALUES (1, ?, ?)
|
|
261
|
-
ON CONFLICT(singleton) DO UPDATE SET
|
|
262
|
-
skip_setup_ui = excluded.skip_setup_ui,
|
|
263
|
-
updated_at = excluded.updated_at
|
|
264
|
-
""",
|
|
265
|
-
(1, timestamp),
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
def disable_setup_ui(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
270
|
-
workspace_id = require_uuid(args.workspace_id, "workspace-id")
|
|
271
|
-
try:
|
|
272
|
-
connection.execute("BEGIN IMMEDIATE")
|
|
273
|
-
require_workspace(connection, workspace_id)
|
|
274
|
-
record_setup_ui_disabled(connection, now())
|
|
275
|
-
connection.commit()
|
|
276
|
-
except BaseException:
|
|
277
|
-
connection.rollback()
|
|
278
|
-
raise
|
|
279
|
-
return workspace_state(connection, workspace_id)
|
|
280
|
-
|
|
281
|
-
|
|
282
247
|
def apply_migrations(connection: sqlite3.Connection) -> None:
|
|
283
248
|
apply_schema_migrations(connection, MIGRATIONS, now, backfill_security_targets)
|
|
284
249
|
|
|
@@ -730,13 +695,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
730
695
|
diff_content_digest = inspected["diffTarget"].get("contentDigest")
|
|
731
696
|
except SystemExit:
|
|
732
697
|
pass
|
|
733
|
-
preflight_json = capability_preflight_json(
|
|
734
|
-
capability_preflight_input(
|
|
735
|
-
args.capability_preflight_json, args.capability_preflight_json_file
|
|
736
|
-
),
|
|
737
|
-
checked_target_path=target_path,
|
|
738
|
-
checked_mode=args.mode,
|
|
739
|
-
)
|
|
740
698
|
with connection:
|
|
741
699
|
target_id = (
|
|
742
700
|
ensure_security_target(connection, target_path) if target_path is not None else None
|
|
@@ -747,8 +705,8 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
747
705
|
id, thread_id, target_id, target_path, target_title, target_summary,
|
|
748
706
|
default_scope, default_mode,
|
|
749
707
|
user_context, diff_target_kind, diff_base_revision, diff_head_revision,
|
|
750
|
-
diff_content_digest,
|
|
751
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
708
|
+
diff_content_digest, created_at, updated_at
|
|
709
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
752
710
|
""",
|
|
753
711
|
(
|
|
754
712
|
workspace_id,
|
|
@@ -764,7 +722,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
764
722
|
diff_base_revision,
|
|
765
723
|
diff_head_revision,
|
|
766
724
|
diff_content_digest,
|
|
767
|
-
preflight_json,
|
|
768
725
|
timestamp,
|
|
769
726
|
timestamp,
|
|
770
727
|
),
|
|
@@ -772,55 +729,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
772
729
|
return workspace_state(connection, workspace_id)
|
|
773
730
|
|
|
774
731
|
|
|
775
|
-
def latest_workspace(connection: sqlite3.Connection, thread_id: str) -> dict[str, Any]:
|
|
776
|
-
thread_id = optional_text(thread_id, maximum=512)
|
|
777
|
-
if thread_id is None:
|
|
778
|
-
raise SystemExit("thread-id is required.")
|
|
779
|
-
row = connection.execute(
|
|
780
|
-
"""
|
|
781
|
-
SELECT workspaces.id
|
|
782
|
-
FROM workspaces
|
|
783
|
-
LEFT JOIN scans ON scans.id = workspaces.active_scan_id
|
|
784
|
-
WHERE workspaces.thread_id = ?
|
|
785
|
-
ORDER BY
|
|
786
|
-
CASE WHEN scans.status = 'running' THEN 0 ELSE 1 END,
|
|
787
|
-
CASE WHEN scans.status = 'running' THEN
|
|
788
|
-
MAX(
|
|
789
|
-
workspaces.updated_at,
|
|
790
|
-
scans.updated_at,
|
|
791
|
-
COALESCE((
|
|
792
|
-
SELECT MAX(progress.updated_at)
|
|
793
|
-
FROM scan_progress AS progress
|
|
794
|
-
WHERE progress.scan_id = scans.id
|
|
795
|
-
), '')
|
|
796
|
-
)
|
|
797
|
-
ELSE
|
|
798
|
-
MAX(
|
|
799
|
-
workspaces.updated_at,
|
|
800
|
-
COALESCE((
|
|
801
|
-
SELECT MAX(triage.updated_at)
|
|
802
|
-
FROM finding_triage AS triage
|
|
803
|
-
JOIN finding_occurrences AS occurrences
|
|
804
|
-
ON occurrences.id = triage.occurrence_id
|
|
805
|
-
WHERE occurrences.scan_id = scans.id
|
|
806
|
-
), ''),
|
|
807
|
-
COALESCE((
|
|
808
|
-
SELECT MAX(remediation.updated_at)
|
|
809
|
-
FROM finding_remediation_attempts AS remediation
|
|
810
|
-
JOIN finding_occurrences AS occurrences
|
|
811
|
-
ON occurrences.id = remediation.occurrence_id
|
|
812
|
-
WHERE occurrences.scan_id = scans.id
|
|
813
|
-
), '')
|
|
814
|
-
)
|
|
815
|
-
END DESC,
|
|
816
|
-
workspaces.created_at DESC
|
|
817
|
-
LIMIT 1
|
|
818
|
-
""",
|
|
819
|
-
(thread_id,),
|
|
820
|
-
).fetchone()
|
|
821
|
-
return {"workspace": workspace_state(connection, row["id"]) if row is not None else None}
|
|
822
|
-
|
|
823
|
-
|
|
824
732
|
def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
825
733
|
workspace = require_workspace(connection, args.workspace_id)
|
|
826
734
|
if workspace["active_scan_id"]:
|
|
@@ -858,7 +766,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
858
766
|
SET target_id = ?, target_path = ?, target_title = ?, target_summary = ?, default_scope = ?,
|
|
859
767
|
default_mode = ?, user_context = ?, diff_target_kind = ?,
|
|
860
768
|
diff_base_revision = ?, diff_head_revision = ?, diff_content_digest = ?,
|
|
861
|
-
|
|
769
|
+
submitted = 1, updated_at = ?
|
|
862
770
|
WHERE id = ? AND active_scan_id IS NULL
|
|
863
771
|
""",
|
|
864
772
|
(
|
|
@@ -884,136 +792,6 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
884
792
|
return workspace_state(connection, workspace["id"])
|
|
885
793
|
|
|
886
794
|
|
|
887
|
-
def set_capability_preflight(
|
|
888
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
889
|
-
) -> dict[str, Any]:
|
|
890
|
-
workspace = require_workspace(connection, args.workspace_id)
|
|
891
|
-
if workspace["active_scan_id"]:
|
|
892
|
-
raise SystemExit("Cannot update capability preflight after a scan has started.")
|
|
893
|
-
checked_target_path = str(require_target(args.checked_target_path))
|
|
894
|
-
preflight_json = capability_preflight_json(
|
|
895
|
-
capability_preflight_input(
|
|
896
|
-
args.capability_preflight_json, args.capability_preflight_json_file
|
|
897
|
-
),
|
|
898
|
-
checked_target_path=checked_target_path,
|
|
899
|
-
checked_mode=args.checked_mode,
|
|
900
|
-
)
|
|
901
|
-
timestamp = now()
|
|
902
|
-
with connection:
|
|
903
|
-
updated = connection.execute(
|
|
904
|
-
"""
|
|
905
|
-
UPDATE workspaces
|
|
906
|
-
SET capability_preflight_json = ?, updated_at = ?
|
|
907
|
-
WHERE id = ? AND active_scan_id IS NULL
|
|
908
|
-
""",
|
|
909
|
-
(preflight_json, timestamp, workspace["id"]),
|
|
910
|
-
)
|
|
911
|
-
if updated.rowcount != 1:
|
|
912
|
-
raise SystemExit("Cannot update capability preflight after a scan has started.")
|
|
913
|
-
return workspace_state(connection, workspace["id"])
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
def begin_diff_resolution(
|
|
917
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
918
|
-
) -> dict[str, Any]:
|
|
919
|
-
workspace = require_workspace(connection, args.workspace_id)
|
|
920
|
-
request_id = require_uuid(args.request_id, "request-id")
|
|
921
|
-
if workspace["active_scan_id"]:
|
|
922
|
-
raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
|
|
923
|
-
target = require_target(args.target_path)
|
|
924
|
-
require_review_changes_target(target)
|
|
925
|
-
target_title = (
|
|
926
|
-
workspace["target_title"] if workspace["target_path"] == str(target) else target.name
|
|
927
|
-
)
|
|
928
|
-
timestamp = now()
|
|
929
|
-
with connection:
|
|
930
|
-
target_id = ensure_security_target(connection, str(target))
|
|
931
|
-
updated = connection.execute(
|
|
932
|
-
"""
|
|
933
|
-
UPDATE workspaces
|
|
934
|
-
SET target_id = ?, target_path = ?, target_title = ?, target_summary = NULL,
|
|
935
|
-
default_scope = '.', default_mode = 'diff',
|
|
936
|
-
user_context = ?, diff_target_kind = NULL, diff_base_revision = NULL,
|
|
937
|
-
diff_head_revision = NULL, diff_content_digest = NULL,
|
|
938
|
-
diff_resolution_id = ?, submitted = 0, updated_at = ?
|
|
939
|
-
WHERE id = ? AND active_scan_id IS NULL
|
|
940
|
-
""",
|
|
941
|
-
(
|
|
942
|
-
target_id,
|
|
943
|
-
str(target),
|
|
944
|
-
target_title,
|
|
945
|
-
user_text(args.user_context),
|
|
946
|
-
request_id,
|
|
947
|
-
timestamp,
|
|
948
|
-
workspace["id"],
|
|
949
|
-
),
|
|
950
|
-
)
|
|
951
|
-
if updated.rowcount != 1:
|
|
952
|
-
raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
|
|
953
|
-
return workspace_state(connection, workspace["id"])
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
def cancel_diff_resolution(
|
|
957
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
958
|
-
) -> dict[str, Any]:
|
|
959
|
-
workspace = require_workspace(connection, args.workspace_id)
|
|
960
|
-
request_id = require_uuid(args.request_id, "request-id")
|
|
961
|
-
timestamp = now()
|
|
962
|
-
with connection:
|
|
963
|
-
connection.execute(
|
|
964
|
-
"""
|
|
965
|
-
UPDATE workspaces
|
|
966
|
-
SET diff_resolution_id = NULL, updated_at = ?
|
|
967
|
-
WHERE id = ? AND diff_resolution_id = ?
|
|
968
|
-
""",
|
|
969
|
-
(timestamp, workspace["id"], request_id),
|
|
970
|
-
)
|
|
971
|
-
return workspace_state(connection, workspace["id"])
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
def set_diff_target(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
975
|
-
workspace = require_workspace(connection, args.workspace_id)
|
|
976
|
-
request_id = require_uuid(args.request_id, "request-id")
|
|
977
|
-
if workspace["active_scan_id"]:
|
|
978
|
-
raise SystemExit("Cannot resolve a new change set while this workspace has a scan.")
|
|
979
|
-
if workspace["diff_resolution_id"] != request_id:
|
|
980
|
-
raise SystemExit("This change-resolution request is no longer active.")
|
|
981
|
-
target = require_target(workspace["target_path"])
|
|
982
|
-
require_scannable_target(target)
|
|
983
|
-
diff_target = require_diff_target(
|
|
984
|
-
target,
|
|
985
|
-
args.diff_target_kind,
|
|
986
|
-
args.diff_base_revision,
|
|
987
|
-
args.diff_head_revision,
|
|
988
|
-
args.diff_content_digest,
|
|
989
|
-
)
|
|
990
|
-
timestamp = now()
|
|
991
|
-
with connection:
|
|
992
|
-
updated = connection.execute(
|
|
993
|
-
"""
|
|
994
|
-
UPDATE workspaces
|
|
995
|
-
SET target_summary = ?, default_scope = '.', default_mode = 'diff',
|
|
996
|
-
diff_target_kind = ?, diff_base_revision = ?, diff_head_revision = ?,
|
|
997
|
-
diff_content_digest = ?, diff_resolution_id = NULL,
|
|
998
|
-
submitted = 0, updated_at = ?
|
|
999
|
-
WHERE id = ? AND diff_resolution_id = ? AND active_scan_id IS NULL
|
|
1000
|
-
""",
|
|
1001
|
-
(
|
|
1002
|
-
optional_text(args.target_summary, maximum=2400),
|
|
1003
|
-
diff_target["kind"],
|
|
1004
|
-
diff_target["baseRevision"],
|
|
1005
|
-
diff_target["headRevision"],
|
|
1006
|
-
diff_target.get("contentDigest"),
|
|
1007
|
-
timestamp,
|
|
1008
|
-
workspace["id"],
|
|
1009
|
-
request_id,
|
|
1010
|
-
),
|
|
1011
|
-
)
|
|
1012
|
-
if updated.rowcount != 1:
|
|
1013
|
-
raise SystemExit("This change-resolution request is no longer active.")
|
|
1014
|
-
return workspace_state(connection, workspace["id"])
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
795
|
def scan_target_root(scan_root: str | None, target: Path) -> Path:
|
|
1018
796
|
root = Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"
|
|
1019
797
|
target_root = (root / safe_segment(target.name)).resolve()
|
|
@@ -1176,10 +954,6 @@ def _start_prompt_driven_scan(
|
|
|
1176
954
|
|
|
1177
955
|
connection.execute("BEGIN IMMEDIATE")
|
|
1178
956
|
try:
|
|
1179
|
-
if not headless_standard and not setup_preference(connection)["skipSetupUi"]:
|
|
1180
|
-
raise SystemExit(
|
|
1181
|
-
"Prompt-only scanning requires the persisted setup UI opt-out preference."
|
|
1182
|
-
)
|
|
1183
957
|
current_target = require_remediation_target(target_path)
|
|
1184
958
|
current_diff_target = (
|
|
1185
959
|
require_diff_target(
|
|
@@ -1238,20 +1012,6 @@ def _start_prompt_driven_scan(
|
|
|
1238
1012
|
if existing is not None:
|
|
1239
1013
|
connection.commit()
|
|
1240
1014
|
return {**scan_context(connection, existing["id"]), "startDisposition": "joined"}
|
|
1241
|
-
if headless_standard and not setup_preference(connection)["skipSetupUi"]:
|
|
1242
|
-
pending = connection.execute(
|
|
1243
|
-
"""
|
|
1244
|
-
SELECT 1 FROM workspaces
|
|
1245
|
-
WHERE thread_id = ? AND target_path = ? AND default_scope = ?
|
|
1246
|
-
AND default_mode = 'standard' AND active_scan_id IS NULL LIMIT 1
|
|
1247
|
-
""",
|
|
1248
|
-
(thread_id, target_path, scope),
|
|
1249
|
-
).fetchone()
|
|
1250
|
-
if pending is not None:
|
|
1251
|
-
raise SystemExit(
|
|
1252
|
-
"A matching Codex Security setup workspace is waiting for Start scan. "
|
|
1253
|
-
"Finish that setup and retry with its scanId."
|
|
1254
|
-
)
|
|
1255
1015
|
target_root.mkdir(parents=True, exist_ok=True)
|
|
1256
1016
|
workspace_id = str(uuid.uuid4())
|
|
1257
1017
|
scan_id = str(uuid.uuid4())
|
|
@@ -2809,9 +2569,7 @@ def workspace_state(
|
|
|
2809
2569
|
result: dict[str, Any] = {
|
|
2810
2570
|
"id": workspace["id"],
|
|
2811
2571
|
"diffTarget": persisted_diff_target,
|
|
2812
|
-
"diffResolutionId": workspace["diff_resolution_id"],
|
|
2813
2572
|
"mode": workspace["default_mode"],
|
|
2814
|
-
"recentTargets": [],
|
|
2815
2573
|
"scope": workspace["default_scope"],
|
|
2816
2574
|
"setup": {"submitted": bool(workspace["submitted"])},
|
|
2817
2575
|
"setupValidation": {"error": None, "valid": bool(workspace["submitted"])},
|
|
@@ -2821,8 +2579,6 @@ def workspace_state(
|
|
|
2821
2579
|
"updatedAt": workspace["updated_at"],
|
|
2822
2580
|
"userContext": workspace["user_context"],
|
|
2823
2581
|
}
|
|
2824
|
-
if workspace["capability_preflight_json"]:
|
|
2825
|
-
result["capabilityPreflight"] = json.loads(workspace["capability_preflight_json"])
|
|
2826
2582
|
selected_scan_id = result_scan_id or workspace["active_scan_id"]
|
|
2827
2583
|
if selected_scan_id:
|
|
2828
2584
|
selected_scan = require_scan(connection, selected_scan_id)
|
|
@@ -2854,7 +2610,6 @@ def workspace_state(
|
|
|
2854
2610
|
except SystemExit:
|
|
2855
2611
|
pass
|
|
2856
2612
|
result["diffTarget"] = validated_diff_target or persisted_diff_target
|
|
2857
|
-
result["recentTargets"] = recent_targets(connection)
|
|
2858
2613
|
result["setupValidation"] = {
|
|
2859
2614
|
"error": setup_error,
|
|
2860
2615
|
"valid": setup_error is None and bool(target_metadata),
|
|
@@ -2864,28 +2619,6 @@ def workspace_state(
|
|
|
2864
2619
|
return result
|
|
2865
2620
|
|
|
2866
2621
|
|
|
2867
|
-
def recent_targets(connection: sqlite3.Connection) -> list[dict[str, Any]]:
|
|
2868
|
-
targets: list[dict[str, Any]] = []
|
|
2869
|
-
rows = connection.execute(
|
|
2870
|
-
"""
|
|
2871
|
-
SELECT target_path, MAX(updated_at) AS last_used_at
|
|
2872
|
-
FROM workspaces
|
|
2873
|
-
WHERE submitted = 1 AND target_path IS NOT NULL
|
|
2874
|
-
GROUP BY target_path
|
|
2875
|
-
ORDER BY last_used_at DESC
|
|
2876
|
-
"""
|
|
2877
|
-
)
|
|
2878
|
-
for row in rows:
|
|
2879
|
-
try:
|
|
2880
|
-
inspected = inspect_target(row["target_path"])
|
|
2881
|
-
except SystemExit:
|
|
2882
|
-
continue
|
|
2883
|
-
targets.append(inspected)
|
|
2884
|
-
if len(targets) == 5:
|
|
2885
|
-
break
|
|
2886
|
-
return targets
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
2622
|
def scan_context(
|
|
2890
2623
|
connection: sqlite3.Connection,
|
|
2891
2624
|
scan_id: str,
|
|
@@ -3574,6 +3307,7 @@ def main() -> None:
|
|
|
3574
3307
|
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3575
3308
|
safe_segment=safe_segment,
|
|
3576
3309
|
compact_timestamp=compact_timestamp,
|
|
3310
|
+
scan_completion_lock=scan_completion_lock,
|
|
3577
3311
|
)
|
|
3578
3312
|
)
|
|
3579
3313
|
if args.command == "inspect-target":
|
|
@@ -3585,30 +3319,12 @@ def main() -> None:
|
|
|
3585
3319
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3586
3320
|
return
|
|
3587
3321
|
with closing(connect()) as connection:
|
|
3588
|
-
if args.command == "
|
|
3589
|
-
result = setup_preference(connection)
|
|
3590
|
-
elif args.command == "disable-setup-ui":
|
|
3591
|
-
result = disable_setup_ui(connection, args)
|
|
3592
|
-
elif args.command == "create-workspace":
|
|
3322
|
+
if args.command == "create-workspace":
|
|
3593
3323
|
result = create_workspace(connection, args)
|
|
3594
3324
|
elif args.command == "get-workspace":
|
|
3595
3325
|
result = workspace_state(connection, args.workspace_id, thread_id=args.thread_id)
|
|
3596
|
-
elif args.command == "get-latest-workspace":
|
|
3597
|
-
result = latest_workspace(connection, args.thread_id)
|
|
3598
|
-
elif args.command == "list-workspace-scans":
|
|
3599
|
-
result = scan_history.list_workspace_scans(
|
|
3600
|
-
connection, args, require_workspace=require_workspace
|
|
3601
|
-
)
|
|
3602
|
-
elif args.command == "begin-diff-resolution":
|
|
3603
|
-
result = begin_diff_resolution(connection, args)
|
|
3604
|
-
elif args.command == "cancel-diff-resolution":
|
|
3605
|
-
result = cancel_diff_resolution(connection, args)
|
|
3606
|
-
elif args.command == "set-diff-target":
|
|
3607
|
-
result = set_diff_target(connection, args)
|
|
3608
3326
|
elif args.command == "save-workspace":
|
|
3609
3327
|
result = save_workspace(connection, args)
|
|
3610
|
-
elif args.command == "set-capability-preflight":
|
|
3611
|
-
result = set_capability_preflight(connection, args)
|
|
3612
3328
|
elif args.command == "start-scan":
|
|
3613
3329
|
result = start_scan(connection, args)
|
|
3614
3330
|
elif args.command == "start-prompt-only-scan":
|
|
@@ -3619,6 +3335,8 @@ def main() -> None:
|
|
|
3619
3335
|
result = deep_scan.begin_deep_scan(connection, args)
|
|
3620
3336
|
elif args.command == "get-deep-scan":
|
|
3621
3337
|
result = deep_scan.get_deep_scan(connection, args)
|
|
3338
|
+
elif args.command == "claim-deep-scan-coordinator":
|
|
3339
|
+
result = deep_scan.claim_deep_scan_coordinator(connection, args)
|
|
3622
3340
|
elif args.command == "upsert-deep-scan-worker":
|
|
3623
3341
|
result = deep_scan.upsert_deep_scan_worker(connection, args)
|
|
3624
3342
|
elif args.command == "claim-deep-scan-dedup":
|
|
@@ -8,6 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
from typing import Any, Callable
|
|
9
9
|
|
|
10
10
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
11
|
+
from deep_scan_workbench import require_current_coordinator
|
|
11
12
|
from workbench.handoff import require_current_continuation
|
|
12
13
|
from workbench_constants import PHASES
|
|
13
14
|
from workbench_validation import optional_text, require_uuid, user_text
|
|
@@ -175,6 +176,16 @@ def update_progress(
|
|
|
175
176
|
scan = require_scan(connection, scan_id)
|
|
176
177
|
if scan["status"] != "running":
|
|
177
178
|
raise SystemExit("Only a running scan can update progress.")
|
|
179
|
+
if scan["mode"] == "deep":
|
|
180
|
+
coordinator = connection.execute(
|
|
181
|
+
"SELECT * FROM deep_scan_runs WHERE scan_id = ?", (scan_id,)
|
|
182
|
+
).fetchone()
|
|
183
|
+
if coordinator is not None and (
|
|
184
|
+
coordinator["status"] == "running" or args.coordinator_generation is not None
|
|
185
|
+
):
|
|
186
|
+
require_current_coordinator(coordinator, args)
|
|
187
|
+
elif args.coordinator_generation is not None:
|
|
188
|
+
raise SystemExit("Coordinator leases apply only to Deep Scan progress.")
|
|
178
189
|
require_current_continuation(
|
|
179
190
|
scan,
|
|
180
191
|
args.claim_token,
|