@openai/codex-security 0.4.0 → 0.5.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.
- package/README.md +45 -9
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- 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/references/core-scan.md +2 -0
- package/_bundled_plugin/references/final-report.md +5 -1
- package/_bundled_plugin/references/investigation-time-budget.md +11 -0
- package/_bundled_plugin/references/sarif-adapter.md +1 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -6
- package/_bundled_plugin/references/scan-runtime.md +15 -0
- package/_bundled_plugin/references/threat-model.md +2 -0
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +80 -43
- package/_bundled_plugin/scripts/finding_preview.py +5 -3
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
- package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
- package/_bundled_plugin/scripts/workbench_cli.py +0 -3
- package/_bundled_plugin/scripts/workbench_constants.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +56 -33
- package/_bundled_plugin/scripts/workbench_progress.py +0 -50
- package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
- package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
- package/_bundled_plugin/scripts/workbench_scan_usage.py +190 -30
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
- package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
- package/_bundled_plugin/scripts/workbench_target.py +7 -5
- package/_bundled_plugin/scripts/workbench_validation.py +37 -1
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
- package/_bundled_plugin/shared/workbench-migrations.json +5 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/dist/api.d.ts +3 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +54 -36
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +2 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +38 -23
- package/dist/artifact-export.js.map +1 -1
- package/dist/classify-severity-records.d.ts +76 -0
- package/dist/classify-severity-records.d.ts.map +1 -0
- package/dist/classify-severity-records.js +141 -0
- package/dist/classify-severity-records.js.map +1 -0
- package/dist/classify-severity.d.ts +1 -23
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -24
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +2 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +4 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +136 -147
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +1 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.js +1 -1
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -4
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +65 -17
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +7 -2
- package/dist/cost-model.js.map +1 -1
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/records.js +1 -1
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +10 -9
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +4 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +21 -1
- package/dist/deep-config.js.map +1 -1
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +3 -3
- package/dist/findings-import.js.map +1 -1
- package/dist/git-remote.d.ts +10 -0
- package/dist/git-remote.d.ts.map +1 -0
- package/dist/git-remote.js +24 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +5 -7
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.js +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +15 -0
- package/dist/host-records-protocol.d.ts.map +1 -0
- package/dist/host-records-protocol.js +15 -0
- package/dist/host-records-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +1 -6
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +2 -2
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +87 -7
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +62 -28
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-publication.d.ts +26 -0
- package/dist/patch-publication.d.ts.map +1 -0
- package/dist/patch-publication.js +105 -0
- package/dist/patch-publication.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +16 -6
- package/dist/project-config.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +135 -19
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +39 -25
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +83 -22
- package/dist/runtime.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +7 -1
- package/dist/scan-settings.js.map +1 -1
- package/dist/scan-time-budget.d.ts +9 -0
- package/dist/scan-time-budget.d.ts.map +1 -0
- package/dist/scan-time-budget.js +16 -0
- package/dist/scan-time-budget.js.map +1 -0
- package/dist/severity-review.d.ts +29 -0
- package/dist/severity-review.d.ts.map +1 -0
- package/dist/severity-review.js +47 -0
- package/dist/severity-review.js.map +1 -0
- package/dist/validation-records.d.ts +38 -0
- package/dist/validation-records.d.ts.map +1 -0
- package/dist/validation-records.js +76 -0
- package/dist/validation-records.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +4 -2
- package/dist/version.js.map +1 -1
- package/dist/worker-progress.d.ts +2 -6
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +1 -43
- package/dist/worker-progress.js.map +1 -1
- package/docs/classify-severity-records.md +89 -0
- package/docs/cli.md +269 -33
- package/docs/validate-records.md +69 -0
- package/package.json +12 -10
- package/schemas/project-config.schema.json +7 -1
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
- package/_bundled_plugin/references/config-preflight.md +0 -93
- package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
- package/_bundled_plugin/scripts/config_preflight.py +0 -911
|
@@ -1,911 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Evaluate Codex Security capability profiles against the current Codex setup."""
|
|
3
|
-
|
|
4
|
-
from __future__ import annotations
|
|
5
|
-
|
|
6
|
-
import argparse
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
import re
|
|
10
|
-
import sys
|
|
11
|
-
from collections.abc import Iterator
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
from typing import Any
|
|
14
|
-
|
|
15
|
-
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
16
|
-
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
|
-
from workbench.runtime_toml import tomllib
|
|
18
|
-
from workbench_constants import positive_int
|
|
19
|
-
|
|
20
|
-
PLUGIN_ROOT = Path(__file__).resolve().parents[1]
|
|
21
|
-
DEFAULT_REGISTRY = PLUGIN_ROOT / "preflight" / "capability-profiles.toml"
|
|
22
|
-
DEFAULT_CODEX_HOME = Path(
|
|
23
|
-
os.environ["CODEX_HOME"] if os.environ.get("CODEX_HOME", "").strip() else "~/.codex"
|
|
24
|
-
).expanduser()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def default_system_config() -> Path:
|
|
28
|
-
if os.name == "nt":
|
|
29
|
-
program_data = os.environ.get("ProgramData", r"C:\ProgramData")
|
|
30
|
-
return Path(program_data) / "OpenAI" / "Codex" / "config.toml"
|
|
31
|
-
return Path("/etc/codex/config.toml")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
SYSTEM_CONFIG = default_system_config()
|
|
35
|
-
DEFAULT_CONFIG = DEFAULT_CODEX_HOME / "config.toml"
|
|
36
|
-
VALID_SEVERITIES = {"block", "warn", "suggest"}
|
|
37
|
-
VALID_MULTI_AGENT_OWNERS = {"native", "codex-bridge"}
|
|
38
|
-
VALID_MULTI_AGENT_VERSIONS = {"v1", "v2"}
|
|
39
|
-
VALID_MULTI_AGENT_PROVENANCE = {
|
|
40
|
-
"app-server",
|
|
41
|
-
"thread-context",
|
|
42
|
-
"tool-surface",
|
|
43
|
-
"verified-bridge",
|
|
44
|
-
}
|
|
45
|
-
NATIVE_V2_DEFAULT_SESSION_CAP = 4
|
|
46
|
-
CONFIG_PROFILE_NAME = re.compile(r"^[A-Za-z0-9_-]+$")
|
|
47
|
-
# Of the config roots evaluated here, only features is valid in legacy ConfigProfile.
|
|
48
|
-
LEGACY_CONFIG_PROFILE_CAPABILITY_FIELDS = {"features"}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def parse_args() -> argparse.Namespace:
|
|
52
|
-
parser = argparse.ArgumentParser(description=__doc__)
|
|
53
|
-
selector = parser.add_mutually_exclusive_group(required=True)
|
|
54
|
-
selector.add_argument("--profile", help="Capability profile id to evaluate.")
|
|
55
|
-
selector.add_argument(
|
|
56
|
-
"--skill", help="Top-level skill id to resolve through the registry routes."
|
|
57
|
-
)
|
|
58
|
-
parser.add_argument(
|
|
59
|
-
"--registry",
|
|
60
|
-
type=Path,
|
|
61
|
-
default=DEFAULT_REGISTRY,
|
|
62
|
-
help="Capability registry path. Defaults to the bundled registry.",
|
|
63
|
-
)
|
|
64
|
-
config_input = parser.add_mutually_exclusive_group()
|
|
65
|
-
config_input.add_argument(
|
|
66
|
-
"--config",
|
|
67
|
-
type=Path,
|
|
68
|
-
action="append",
|
|
69
|
-
help=(
|
|
70
|
-
"Codex config.toml layer, from lower to higher precedence. "
|
|
71
|
-
"Repeat to override automatic cwd-based discovery."
|
|
72
|
-
),
|
|
73
|
-
)
|
|
74
|
-
parser.add_argument(
|
|
75
|
-
"--cwd",
|
|
76
|
-
type=Path,
|
|
77
|
-
default=Path.cwd(),
|
|
78
|
-
help="Working directory used to discover trusted project config layers.",
|
|
79
|
-
)
|
|
80
|
-
parser.add_argument(
|
|
81
|
-
"--codex-config-profile",
|
|
82
|
-
help="Selected Codex config profile name, when the session uses one.",
|
|
83
|
-
)
|
|
84
|
-
parser.add_argument(
|
|
85
|
-
"--multi-agent-runtime-owner",
|
|
86
|
-
choices=sorted(VALID_MULTI_AGENT_OWNERS),
|
|
87
|
-
help=(
|
|
88
|
-
"Verified owner of the active multi-agent runtime. Do not infer bridge "
|
|
89
|
-
"ownership from a backend_config value alone."
|
|
90
|
-
),
|
|
91
|
-
)
|
|
92
|
-
parser.add_argument(
|
|
93
|
-
"--multi-agent-runtime-version",
|
|
94
|
-
choices=sorted(VALID_MULTI_AGENT_VERSIONS),
|
|
95
|
-
help="Version exposed by the active multi-agent tool surface.",
|
|
96
|
-
)
|
|
97
|
-
parser.add_argument(
|
|
98
|
-
"--multi-agent-session-cap",
|
|
99
|
-
type=positive_int,
|
|
100
|
-
help="Resolved V2 session cap from the active runtime; includes the root thread.",
|
|
101
|
-
)
|
|
102
|
-
parser.add_argument(
|
|
103
|
-
"--multi-agent-runtime-provenance",
|
|
104
|
-
choices=sorted(VALID_MULTI_AGENT_PROVENANCE),
|
|
105
|
-
help="Evidence source for explicitly supplied multi-agent runtime facts.",
|
|
106
|
-
)
|
|
107
|
-
parser.add_argument(
|
|
108
|
-
"--runtime-check",
|
|
109
|
-
action="append",
|
|
110
|
-
default=[],
|
|
111
|
-
metavar="NAME=BOOL",
|
|
112
|
-
help="Known runtime capability, such as delegation_available=true.",
|
|
113
|
-
)
|
|
114
|
-
parser.add_argument(
|
|
115
|
-
"--available-plugin-skill",
|
|
116
|
-
action="append",
|
|
117
|
-
metavar="SKILL_NAME",
|
|
118
|
-
help=(
|
|
119
|
-
"Plugin-local skill name exposed by the current runtime, such as "
|
|
120
|
-
"security-scan. Repeat only for skills from the capability's plugin."
|
|
121
|
-
),
|
|
122
|
-
)
|
|
123
|
-
parser.add_argument(
|
|
124
|
-
"--effective-config",
|
|
125
|
-
action="append",
|
|
126
|
-
default=[],
|
|
127
|
-
metavar="PATH=JSON",
|
|
128
|
-
help="Known effective config value, such as agents.max_threads=8.",
|
|
129
|
-
)
|
|
130
|
-
return parser.parse_args()
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def read_toml(path: Path, *, required: bool) -> dict[str, Any]:
|
|
134
|
-
try:
|
|
135
|
-
with path.open("rb") as file:
|
|
136
|
-
return tomllib.load(file)
|
|
137
|
-
except FileNotFoundError:
|
|
138
|
-
if required:
|
|
139
|
-
raise
|
|
140
|
-
return {}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def parse_bool(value: str) -> bool:
|
|
144
|
-
normalized = value.lower()
|
|
145
|
-
if normalized == "true":
|
|
146
|
-
return True
|
|
147
|
-
if normalized == "false":
|
|
148
|
-
return False
|
|
149
|
-
raise ValueError(f"expected true or false, got {value!r}")
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def parse_assignment(raw: str) -> tuple[str, str]:
|
|
153
|
-
key, separator, value = raw.partition("=")
|
|
154
|
-
if not separator or not key or not value:
|
|
155
|
-
raise ValueError(f"expected NAME=VALUE, got {raw!r}")
|
|
156
|
-
return key, value
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def parse_runtime_checks(values: list[str]) -> dict[str, bool]:
|
|
160
|
-
checks: dict[str, bool] = {}
|
|
161
|
-
for raw in values:
|
|
162
|
-
key, value = parse_assignment(raw)
|
|
163
|
-
checks[key] = parse_bool(value)
|
|
164
|
-
return checks
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
def parse_available_plugin_skills(values: list[str] | None) -> set[str] | None:
|
|
168
|
-
if values is None:
|
|
169
|
-
return None
|
|
170
|
-
for value in values:
|
|
171
|
-
if ":" in value:
|
|
172
|
-
raise ValueError(
|
|
173
|
-
f"expected plugin-local skill name, got {value!r}; omit the plugin prefix"
|
|
174
|
-
)
|
|
175
|
-
return set(values)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def parse_effective_config(values: list[str]) -> dict[str, Any]:
|
|
179
|
-
config: dict[str, Any] = {}
|
|
180
|
-
for raw in values:
|
|
181
|
-
key, value = parse_assignment(raw)
|
|
182
|
-
try:
|
|
183
|
-
config[key] = json.loads(value)
|
|
184
|
-
except json.JSONDecodeError as error:
|
|
185
|
-
raise ValueError(f"expected JSON value for {key!r}, got {value!r}") from error
|
|
186
|
-
return config
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def lookup_dotted(config: dict[str, Any], path: str) -> tuple[bool, Any]:
|
|
190
|
-
current: Any = config
|
|
191
|
-
for part in path.split("."):
|
|
192
|
-
if not isinstance(current, dict) or part not in current:
|
|
193
|
-
return False, None
|
|
194
|
-
current = current[part]
|
|
195
|
-
return True, current
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def lookup_layered_value(
|
|
199
|
-
path: str, config_layers: list[tuple[Path, dict[str, Any]]]
|
|
200
|
-
) -> tuple[bool, Any]:
|
|
201
|
-
for _config_path, config in reversed(config_layers):
|
|
202
|
-
found, actual = lookup_dotted(config, path)
|
|
203
|
-
if found:
|
|
204
|
-
return True, actual
|
|
205
|
-
return False, None
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def iter_config_views(
|
|
209
|
-
config_layers: list[tuple[Path, dict[str, Any]]], config_profile: str | None
|
|
210
|
-
) -> Iterator[tuple[str, dict[str, Any]]]:
|
|
211
|
-
for config_path, config in reversed(config_layers):
|
|
212
|
-
if config_profile is not None:
|
|
213
|
-
profiles = config.get("profiles")
|
|
214
|
-
if isinstance(profiles, dict):
|
|
215
|
-
profile_config = profiles.get(config_profile)
|
|
216
|
-
if isinstance(profile_config, dict):
|
|
217
|
-
supported_profile_config = {
|
|
218
|
-
key: value
|
|
219
|
-
for key, value in profile_config.items()
|
|
220
|
-
if key in LEGACY_CONFIG_PROFILE_CAPABILITY_FIELDS
|
|
221
|
-
}
|
|
222
|
-
if supported_profile_config:
|
|
223
|
-
yield (
|
|
224
|
-
f"{config_path} [profiles.{config_profile}]",
|
|
225
|
-
supported_profile_config,
|
|
226
|
-
)
|
|
227
|
-
yield str(config_path), config
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def resolve_project_root(cwd: Path, config_layers: list[tuple[Path, dict[str, Any]]]) -> Path:
|
|
231
|
-
found, configured_markers = lookup_layered_value("project_root_markers", config_layers)
|
|
232
|
-
markers = configured_markers if found else [".git"]
|
|
233
|
-
if not isinstance(markers, list) or not all(isinstance(marker, str) for marker in markers):
|
|
234
|
-
raise ValueError("project_root_markers must be an array of strings")
|
|
235
|
-
if not markers:
|
|
236
|
-
return cwd
|
|
237
|
-
for candidate in (cwd, *cwd.parents):
|
|
238
|
-
if any((candidate / marker).exists() for marker in markers):
|
|
239
|
-
return candidate
|
|
240
|
-
return cwd
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
def project_trust_level(
|
|
244
|
-
config_layers: list[tuple[Path, dict[str, Any]]], project_root: Path
|
|
245
|
-
) -> str | None:
|
|
246
|
-
for _path, config in reversed(config_layers):
|
|
247
|
-
projects = config.get("projects")
|
|
248
|
-
if not isinstance(projects, dict):
|
|
249
|
-
continue
|
|
250
|
-
project = projects.get(str(project_root))
|
|
251
|
-
if not isinstance(project, dict) and os.name == "nt":
|
|
252
|
-
project_key = os.path.normcase(os.path.realpath(project_root))
|
|
253
|
-
project = next(
|
|
254
|
-
(
|
|
255
|
-
value
|
|
256
|
-
for path, value in projects.items()
|
|
257
|
-
if os.path.normcase(os.path.realpath(path)) == project_key
|
|
258
|
-
),
|
|
259
|
-
None,
|
|
260
|
-
)
|
|
261
|
-
if not isinstance(project, dict):
|
|
262
|
-
continue
|
|
263
|
-
trust_level = project.get("trust_level")
|
|
264
|
-
if isinstance(trust_level, str):
|
|
265
|
-
return trust_level
|
|
266
|
-
return None
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
def project_config_paths(project_root: Path, cwd: Path) -> list[Path]:
|
|
270
|
-
relative = cwd.relative_to(project_root)
|
|
271
|
-
return [
|
|
272
|
-
project_root / directory / ".codex" / "config.toml"
|
|
273
|
-
for directory in reversed((relative, *relative.parents))
|
|
274
|
-
]
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
def discover_config_paths(
|
|
278
|
-
*, cwd: Path, profile_layer_path: Path | None
|
|
279
|
-
) -> tuple[list[Path], dict[str, Any]]:
|
|
280
|
-
resolved_cwd = cwd.expanduser().resolve()
|
|
281
|
-
if not resolved_cwd.is_dir():
|
|
282
|
-
raise ValueError(f"cwd must be a directory, got {str(resolved_cwd)!r}")
|
|
283
|
-
|
|
284
|
-
base_paths = [SYSTEM_CONFIG, DEFAULT_CONFIG]
|
|
285
|
-
if profile_layer_path is not None:
|
|
286
|
-
base_paths.append(profile_layer_path)
|
|
287
|
-
base_layers = [(path, read_toml(path, required=False)) for path in base_paths]
|
|
288
|
-
project_root = resolve_project_root(resolved_cwd, base_layers)
|
|
289
|
-
trust_level = project_trust_level(base_layers, project_root)
|
|
290
|
-
paths = [*base_paths]
|
|
291
|
-
if trust_level == "trusted":
|
|
292
|
-
paths.extend(project_config_paths(project_root, resolved_cwd))
|
|
293
|
-
return paths, {
|
|
294
|
-
"cwd": str(resolved_cwd),
|
|
295
|
-
"project_root": str(project_root),
|
|
296
|
-
"project_trust_level": trust_level,
|
|
297
|
-
"project_layers_loaded": trust_level == "trusted",
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def compare(actual: Any, op: str, expected: Any) -> bool:
|
|
302
|
-
if op == "==":
|
|
303
|
-
return actual == expected
|
|
304
|
-
if op == ">=":
|
|
305
|
-
return isinstance(actual, int) and not isinstance(actual, bool) and actual >= expected
|
|
306
|
-
raise ValueError(f"unsupported comparison operator: {op!r}")
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
def lookup_config_value(
|
|
310
|
-
path: str,
|
|
311
|
-
*,
|
|
312
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
313
|
-
effective_config: dict[str, Any],
|
|
314
|
-
config_profile: str | None,
|
|
315
|
-
default: Any = None,
|
|
316
|
-
has_default: bool = False,
|
|
317
|
-
) -> tuple[bool, Any, str | None]:
|
|
318
|
-
if path in effective_config:
|
|
319
|
-
return True, effective_config[path], "effective-config"
|
|
320
|
-
for source, config in iter_config_views(config_layers, config_profile):
|
|
321
|
-
found, actual = lookup_dotted(config, path)
|
|
322
|
-
if found:
|
|
323
|
-
return True, actual, source
|
|
324
|
-
if has_default:
|
|
325
|
-
return True, default, "documented-default"
|
|
326
|
-
return False, None, None
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
def resolve_active_config_profile(
|
|
330
|
-
*,
|
|
331
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
332
|
-
override: str | None,
|
|
333
|
-
cli_profile_selected: bool,
|
|
334
|
-
) -> tuple[str | None, str | None]:
|
|
335
|
-
if cli_profile_selected:
|
|
336
|
-
if override is None:
|
|
337
|
-
raise ValueError("CLI profile selection requires an explicit config profile name")
|
|
338
|
-
return override, None
|
|
339
|
-
|
|
340
|
-
if override is None:
|
|
341
|
-
found, configured = lookup_layered_value("profile", config_layers)
|
|
342
|
-
if not found:
|
|
343
|
-
return None, None
|
|
344
|
-
if not isinstance(configured, str):
|
|
345
|
-
raise ValueError("profile must be a string")
|
|
346
|
-
profile = configured
|
|
347
|
-
else:
|
|
348
|
-
profile = override
|
|
349
|
-
|
|
350
|
-
profile_values = [
|
|
351
|
-
config.get("profiles", {}).get(profile)
|
|
352
|
-
for _path, config in config_layers
|
|
353
|
-
if isinstance(config.get("profiles"), dict) and profile in config["profiles"]
|
|
354
|
-
]
|
|
355
|
-
if not profile_values:
|
|
356
|
-
raise ValueError(f"config profile {profile!r} not found")
|
|
357
|
-
if any(not isinstance(value, dict) for value in profile_values):
|
|
358
|
-
raise ValueError(f"config profile {profile!r} must be a table")
|
|
359
|
-
return profile, profile
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
def config_profile_layer_path(profile: str | None) -> Path | None:
|
|
363
|
-
if profile is None:
|
|
364
|
-
return None
|
|
365
|
-
if not CONFIG_PROFILE_NAME.fullmatch(profile):
|
|
366
|
-
raise ValueError(
|
|
367
|
-
f"invalid config profile name {profile!r}; pass a plain name such as 'work'"
|
|
368
|
-
)
|
|
369
|
-
path = DEFAULT_CODEX_HOME / f"{profile}.config.toml"
|
|
370
|
-
return path if path.is_file() else None
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
def lookup_multi_agent_v2_enabled(
|
|
374
|
-
*,
|
|
375
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
376
|
-
effective_config: dict[str, Any],
|
|
377
|
-
config_profile: str | None,
|
|
378
|
-
) -> tuple[bool, bool | None, str | None]:
|
|
379
|
-
if "features.multi_agent_v2.enabled" in effective_config:
|
|
380
|
-
enabled = effective_config["features.multi_agent_v2.enabled"]
|
|
381
|
-
if not isinstance(enabled, bool):
|
|
382
|
-
raise ValueError("features.multi_agent_v2.enabled must be a boolean")
|
|
383
|
-
return True, enabled, "effective-config"
|
|
384
|
-
|
|
385
|
-
v2_configs = []
|
|
386
|
-
if "features.multi_agent_v2" in effective_config:
|
|
387
|
-
v2_configs.append(("effective-config", effective_config["features.multi_agent_v2"]))
|
|
388
|
-
for source, config in iter_config_views(config_layers, config_profile):
|
|
389
|
-
found, feature_config = lookup_dotted(config, "features.multi_agent_v2")
|
|
390
|
-
if found:
|
|
391
|
-
v2_configs.append((source, feature_config))
|
|
392
|
-
|
|
393
|
-
table_override = False
|
|
394
|
-
for source, feature_config in v2_configs:
|
|
395
|
-
if table_override and not isinstance(feature_config, (dict, bool)):
|
|
396
|
-
break
|
|
397
|
-
if isinstance(feature_config, bool):
|
|
398
|
-
return True, feature_config, source
|
|
399
|
-
if not isinstance(feature_config, dict):
|
|
400
|
-
raise ValueError("features.multi_agent_v2 must be a boolean or table")
|
|
401
|
-
if "enabled" in feature_config:
|
|
402
|
-
enabled = feature_config["enabled"]
|
|
403
|
-
if not isinstance(enabled, bool):
|
|
404
|
-
raise ValueError("features.multi_agent_v2.enabled must be a boolean")
|
|
405
|
-
return True, enabled, source
|
|
406
|
-
table_override = True
|
|
407
|
-
return (True, False, "documented-default") if table_override else (False, None, None)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
def resolve_multi_agent_context(
|
|
411
|
-
*,
|
|
412
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
413
|
-
effective_config: dict[str, Any],
|
|
414
|
-
config_profile: str | None,
|
|
415
|
-
runtime_owner: str | None,
|
|
416
|
-
runtime_version: str | None,
|
|
417
|
-
runtime_session_cap: int | None,
|
|
418
|
-
runtime_provenance: str | None,
|
|
419
|
-
validate_multi_agent_config: bool,
|
|
420
|
-
) -> dict[str, Any]:
|
|
421
|
-
runtime_facts_supplied = any(
|
|
422
|
-
value is not None for value in (runtime_owner, runtime_version, runtime_session_cap)
|
|
423
|
-
)
|
|
424
|
-
if runtime_facts_supplied and runtime_provenance is None:
|
|
425
|
-
raise ValueError(
|
|
426
|
-
"explicit multi-agent runtime facts require --multi-agent-runtime-provenance"
|
|
427
|
-
)
|
|
428
|
-
if runtime_provenance is not None and not runtime_facts_supplied:
|
|
429
|
-
raise ValueError(
|
|
430
|
-
"--multi-agent-runtime-provenance requires an explicit runtime owner, version, or cap"
|
|
431
|
-
)
|
|
432
|
-
if runtime_owner == "codex-bridge" and runtime_provenance != "verified-bridge":
|
|
433
|
-
raise ValueError(
|
|
434
|
-
"codex-bridge ownership requires --multi-agent-runtime-provenance verified-bridge"
|
|
435
|
-
)
|
|
436
|
-
if runtime_owner == "native" and runtime_provenance == "verified-bridge":
|
|
437
|
-
raise ValueError("native ownership cannot use verified-bridge provenance")
|
|
438
|
-
|
|
439
|
-
feature_found, enabled, feature_source = lookup_multi_agent_v2_enabled(
|
|
440
|
-
config_layers=config_layers,
|
|
441
|
-
effective_config=effective_config,
|
|
442
|
-
config_profile=config_profile,
|
|
443
|
-
)
|
|
444
|
-
|
|
445
|
-
if runtime_version is not None:
|
|
446
|
-
version = runtime_version
|
|
447
|
-
version_source = "runtime-fact"
|
|
448
|
-
elif feature_found:
|
|
449
|
-
version = "v2" if enabled else "v1"
|
|
450
|
-
version_source = feature_source
|
|
451
|
-
elif runtime_owner == "codex-bridge":
|
|
452
|
-
version = "v2"
|
|
453
|
-
version_source = "runtime-owner"
|
|
454
|
-
else:
|
|
455
|
-
version = "unknown"
|
|
456
|
-
version_source = None
|
|
457
|
-
|
|
458
|
-
if runtime_owner is not None:
|
|
459
|
-
owner = runtime_owner
|
|
460
|
-
owner_source = "runtime-fact"
|
|
461
|
-
elif feature_found:
|
|
462
|
-
owner = "native"
|
|
463
|
-
owner_source = feature_source
|
|
464
|
-
else:
|
|
465
|
-
owner = "unknown"
|
|
466
|
-
owner_source = None
|
|
467
|
-
|
|
468
|
-
if owner == "codex-bridge" and version != "v2":
|
|
469
|
-
raise ValueError("codex-bridge ownership requires multi-agent runtime version v2")
|
|
470
|
-
if runtime_session_cap is not None and version != "v2":
|
|
471
|
-
raise ValueError("--multi-agent-session-cap is valid only for a V2 runtime")
|
|
472
|
-
|
|
473
|
-
bridge_cap_found, bridge_cap, bridge_cap_source = lookup_config_value(
|
|
474
|
-
"multiagent_config.max_concurrency",
|
|
475
|
-
config_layers=config_layers,
|
|
476
|
-
effective_config=effective_config,
|
|
477
|
-
config_profile=config_profile,
|
|
478
|
-
)
|
|
479
|
-
if (
|
|
480
|
-
bridge_cap_found
|
|
481
|
-
and owner != "codex-bridge"
|
|
482
|
-
and (validate_multi_agent_config or runtime_facts_supplied)
|
|
483
|
-
):
|
|
484
|
-
raise ValueError(
|
|
485
|
-
"multiagent_config.max_concurrency does not prove bridge ownership; "
|
|
486
|
-
"pass --multi-agent-runtime-owner codex-bridge only when the active runtime "
|
|
487
|
-
"is verified as bridge-managed"
|
|
488
|
-
)
|
|
489
|
-
if bridge_cap_found and runtime_session_cap is not None and bridge_cap != runtime_session_cap:
|
|
490
|
-
raise ValueError(
|
|
491
|
-
"conflicting bridge concurrency facts: multiagent_config.max_concurrency "
|
|
492
|
-
f"from {bridge_cap_source} is {bridge_cap!r}, but --multi-agent-session-cap is "
|
|
493
|
-
f"{runtime_session_cap!r}"
|
|
494
|
-
)
|
|
495
|
-
|
|
496
|
-
agent_threads_found, agent_threads, agent_threads_source = lookup_config_value(
|
|
497
|
-
"agents.max_threads",
|
|
498
|
-
config_layers=config_layers,
|
|
499
|
-
effective_config=effective_config,
|
|
500
|
-
config_profile=config_profile,
|
|
501
|
-
)
|
|
502
|
-
if owner != "codex-bridge" and feature_found and enabled and agent_threads_found:
|
|
503
|
-
raise ValueError("agents.max_threads cannot be set when multi_agent_v2 is enabled")
|
|
504
|
-
|
|
505
|
-
if version == "v1":
|
|
506
|
-
mode = "v1"
|
|
507
|
-
elif version == "v2" and owner == "codex-bridge":
|
|
508
|
-
mode = "bridge-v2"
|
|
509
|
-
elif version == "v2" and owner == "native":
|
|
510
|
-
mode = "v2"
|
|
511
|
-
else:
|
|
512
|
-
mode = "unknown"
|
|
513
|
-
return {
|
|
514
|
-
"mode": mode,
|
|
515
|
-
"owner": owner,
|
|
516
|
-
"owner_source": owner_source,
|
|
517
|
-
"version": version,
|
|
518
|
-
"version_source": version_source,
|
|
519
|
-
"runtime_provenance": runtime_provenance,
|
|
520
|
-
"config_v2_enabled": feature_found and bool(enabled),
|
|
521
|
-
"agent_max_threads_configured": agent_threads_found,
|
|
522
|
-
"agent_max_threads": agent_threads if agent_threads_found else None,
|
|
523
|
-
"agent_max_threads_source": agent_threads_source if agent_threads_found else None,
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
def evaluate_multi_agent_capacity(
|
|
528
|
-
result: dict[str, Any],
|
|
529
|
-
capability: dict[str, Any],
|
|
530
|
-
*,
|
|
531
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
532
|
-
effective_config: dict[str, Any],
|
|
533
|
-
config_profile: str | None,
|
|
534
|
-
multi_agent_context: dict[str, Any],
|
|
535
|
-
runtime_session_cap: int | None,
|
|
536
|
-
) -> dict[str, Any]:
|
|
537
|
-
multi_agent_mode = str(multi_agent_context["mode"])
|
|
538
|
-
if multi_agent_mode == "unknown":
|
|
539
|
-
return {**result, "status": "unknown", "check": "active_multi_agent_mode"}
|
|
540
|
-
|
|
541
|
-
if multi_agent_mode == "v1":
|
|
542
|
-
path = "agents.max_threads"
|
|
543
|
-
found, actual, source = lookup_config_value(
|
|
544
|
-
path,
|
|
545
|
-
config_layers=config_layers,
|
|
546
|
-
effective_config=effective_config,
|
|
547
|
-
config_profile=config_profile,
|
|
548
|
-
default=capability.get("v1_default"),
|
|
549
|
-
has_default="v1_default" in capability,
|
|
550
|
-
)
|
|
551
|
-
worker_slots = actual
|
|
552
|
-
else:
|
|
553
|
-
if runtime_session_cap is not None:
|
|
554
|
-
path = "runtime.multi_agent.session_cap"
|
|
555
|
-
found, actual, source = True, runtime_session_cap, "runtime-fact"
|
|
556
|
-
elif multi_agent_context["owner"] == "codex-bridge":
|
|
557
|
-
path = "multiagent_config.max_concurrency"
|
|
558
|
-
found, actual, source = lookup_config_value(
|
|
559
|
-
path,
|
|
560
|
-
config_layers=config_layers,
|
|
561
|
-
effective_config=effective_config,
|
|
562
|
-
config_profile=config_profile,
|
|
563
|
-
)
|
|
564
|
-
elif multi_agent_context["owner"] == "native" and multi_agent_context["config_v2_enabled"]:
|
|
565
|
-
path = "features.multi_agent_v2.max_concurrent_threads_per_session"
|
|
566
|
-
found, actual, source = lookup_config_value(
|
|
567
|
-
path,
|
|
568
|
-
config_layers=config_layers,
|
|
569
|
-
effective_config=effective_config,
|
|
570
|
-
config_profile=config_profile,
|
|
571
|
-
default=NATIVE_V2_DEFAULT_SESSION_CAP,
|
|
572
|
-
has_default=True,
|
|
573
|
-
)
|
|
574
|
-
else:
|
|
575
|
-
path = "runtime.multi_agent.session_cap"
|
|
576
|
-
found, actual, source = False, None, None
|
|
577
|
-
worker_slots = (
|
|
578
|
-
actual - 1 if isinstance(actual, int) and not isinstance(actual, bool) else actual
|
|
579
|
-
)
|
|
580
|
-
|
|
581
|
-
if not found:
|
|
582
|
-
return {**result, "status": "unknown", "path": path, "multi_agent_mode": multi_agent_mode}
|
|
583
|
-
return {
|
|
584
|
-
**result,
|
|
585
|
-
"status": "pass"
|
|
586
|
-
if compare(worker_slots, capability["op"], capability["value"])
|
|
587
|
-
else "fail",
|
|
588
|
-
"path": path,
|
|
589
|
-
"actual": worker_slots,
|
|
590
|
-
"configured_value": actual,
|
|
591
|
-
"expected": {"op": capability["op"], "value": capability["value"]},
|
|
592
|
-
"source": source,
|
|
593
|
-
"multi_agent_mode": multi_agent_mode,
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
def resolve_profile(registry: dict[str, Any], *, profile: str | None, skill: str | None) -> str:
|
|
598
|
-
if profile:
|
|
599
|
-
return profile
|
|
600
|
-
routes = {route["skill"]: route["profile"] for route in registry["routes"]}
|
|
601
|
-
try:
|
|
602
|
-
return routes[str(skill)]
|
|
603
|
-
except KeyError as error:
|
|
604
|
-
raise ValueError(f"no capability profile route for skill {skill!r}") from error
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
def evaluate_requirement(
|
|
608
|
-
requirement: dict[str, Any],
|
|
609
|
-
*,
|
|
610
|
-
capabilities: dict[str, dict[str, Any]],
|
|
611
|
-
config_layers: list[tuple[Path, dict[str, Any]]],
|
|
612
|
-
effective_config: dict[str, Any],
|
|
613
|
-
config_profile: str | None,
|
|
614
|
-
runtime_checks: dict[str, bool],
|
|
615
|
-
available_plugin_skills: set[str] | None,
|
|
616
|
-
multi_agent_context: dict[str, Any],
|
|
617
|
-
runtime_session_cap: int | None,
|
|
618
|
-
) -> dict[str, Any]:
|
|
619
|
-
capability_id = requirement["capability"]
|
|
620
|
-
capability = capabilities[capability_id]
|
|
621
|
-
result = {
|
|
622
|
-
"capability": capability_id,
|
|
623
|
-
"severity": requirement["severity"],
|
|
624
|
-
"reason": requirement["reason"],
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if capability["kind"] == "runtime":
|
|
628
|
-
check = capability["check"]
|
|
629
|
-
if check not in runtime_checks:
|
|
630
|
-
return {**result, "status": "unknown", "check": check}
|
|
631
|
-
actual = runtime_checks[check]
|
|
632
|
-
return {**result, "status": "pass" if actual else "fail", "actual": actual, "check": check}
|
|
633
|
-
|
|
634
|
-
if capability["kind"] == "multi_agent_mode":
|
|
635
|
-
actual = {
|
|
636
|
-
"owner": multi_agent_context["owner"],
|
|
637
|
-
"version": multi_agent_context["version"],
|
|
638
|
-
}
|
|
639
|
-
expected = {
|
|
640
|
-
"owner": capability["owner"],
|
|
641
|
-
"version": capability["version"],
|
|
642
|
-
}
|
|
643
|
-
if "unknown" in actual.values():
|
|
644
|
-
return {
|
|
645
|
-
**result,
|
|
646
|
-
"status": "unknown",
|
|
647
|
-
"check": "active_multi_agent_mode",
|
|
648
|
-
"actual": actual,
|
|
649
|
-
"expected": expected,
|
|
650
|
-
}
|
|
651
|
-
return {
|
|
652
|
-
**result,
|
|
653
|
-
"status": "pass" if actual == expected else "fail",
|
|
654
|
-
"actual": actual,
|
|
655
|
-
"expected": expected,
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
if capability["kind"] == "plugin_skills":
|
|
659
|
-
required = capability["required"]
|
|
660
|
-
required_skill_ids = [f"{capability['plugin']}:{skill}" for skill in required]
|
|
661
|
-
if available_plugin_skills is None:
|
|
662
|
-
return {
|
|
663
|
-
**result,
|
|
664
|
-
"status": "unknown",
|
|
665
|
-
"check": "available_plugin_skills",
|
|
666
|
-
"required": required_skill_ids,
|
|
667
|
-
}
|
|
668
|
-
unavailable = [
|
|
669
|
-
f"{capability['plugin']}:{skill}"
|
|
670
|
-
for skill in required
|
|
671
|
-
if skill not in available_plugin_skills
|
|
672
|
-
]
|
|
673
|
-
return {
|
|
674
|
-
**result,
|
|
675
|
-
"status": "fail" if unavailable else "pass",
|
|
676
|
-
"unavailable": unavailable,
|
|
677
|
-
"required": required_skill_ids,
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
if capability["kind"] == "multi_agent_capacity":
|
|
681
|
-
return evaluate_multi_agent_capacity(
|
|
682
|
-
result,
|
|
683
|
-
capability,
|
|
684
|
-
config_layers=config_layers,
|
|
685
|
-
effective_config=effective_config,
|
|
686
|
-
config_profile=config_profile,
|
|
687
|
-
multi_agent_context=multi_agent_context,
|
|
688
|
-
runtime_session_cap=runtime_session_cap,
|
|
689
|
-
)
|
|
690
|
-
|
|
691
|
-
if capability["kind"] == "config_absent":
|
|
692
|
-
path = capability["path"]
|
|
693
|
-
found, actual, source = lookup_config_value(
|
|
694
|
-
path,
|
|
695
|
-
config_layers=config_layers,
|
|
696
|
-
effective_config=effective_config,
|
|
697
|
-
config_profile=config_profile,
|
|
698
|
-
)
|
|
699
|
-
if not found:
|
|
700
|
-
return {**result, "status": "pass", "path": path, "expected": "unset"}
|
|
701
|
-
return {
|
|
702
|
-
**result,
|
|
703
|
-
"status": "fail",
|
|
704
|
-
"path": path,
|
|
705
|
-
"actual": actual,
|
|
706
|
-
"expected": "unset",
|
|
707
|
-
"source": source,
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
path = capability["path"]
|
|
711
|
-
found, actual, source = lookup_config_value(
|
|
712
|
-
path,
|
|
713
|
-
config_layers=config_layers,
|
|
714
|
-
effective_config=effective_config,
|
|
715
|
-
config_profile=config_profile,
|
|
716
|
-
default=capability.get("default"),
|
|
717
|
-
has_default="default" in capability,
|
|
718
|
-
)
|
|
719
|
-
if not found:
|
|
720
|
-
return {**result, "status": "unknown", "path": path}
|
|
721
|
-
return {
|
|
722
|
-
**result,
|
|
723
|
-
"status": "pass" if compare(actual, capability["op"], capability["value"]) else "fail",
|
|
724
|
-
"path": path,
|
|
725
|
-
"actual": actual,
|
|
726
|
-
"expected": {"op": capability["op"], "value": capability["value"]},
|
|
727
|
-
"source": source,
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
def validate_registry(registry: dict[str, Any]) -> None:
|
|
732
|
-
capabilities = registry["capabilities"]
|
|
733
|
-
profiles = registry["profiles"]
|
|
734
|
-
for profile_id, profile in profiles.items():
|
|
735
|
-
for requirement in profile["requirements"]:
|
|
736
|
-
if requirement["capability"] not in capabilities:
|
|
737
|
-
raise ValueError(
|
|
738
|
-
f"profile {profile_id!r} references unknown capability {requirement['capability']!r}"
|
|
739
|
-
)
|
|
740
|
-
if requirement["severity"] not in VALID_SEVERITIES:
|
|
741
|
-
raise ValueError(
|
|
742
|
-
f"profile {profile_id!r} has unsupported severity {requirement['severity']!r}"
|
|
743
|
-
)
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
def profile_requires_multi_agent_config(
|
|
747
|
-
profile: dict[str, Any], capabilities: dict[str, dict[str, Any]]
|
|
748
|
-
) -> bool:
|
|
749
|
-
def is_runtime_path(path: Any) -> bool:
|
|
750
|
-
return isinstance(path, str) and (
|
|
751
|
-
path in {"agents", "features", "features.multi_agent_v2", "multiagent_config"}
|
|
752
|
-
or path.startswith(("agents.", "multiagent_config.", "features.multi_agent_v2."))
|
|
753
|
-
)
|
|
754
|
-
|
|
755
|
-
for requirement in profile["requirements"]:
|
|
756
|
-
capability = capabilities[requirement["capability"]]
|
|
757
|
-
if (
|
|
758
|
-
capability["kind"] in {"multi_agent_capacity", "multi_agent_mode"}
|
|
759
|
-
or requirement.get("modes")
|
|
760
|
-
or is_runtime_path(capability.get("path"))
|
|
761
|
-
):
|
|
762
|
-
return True
|
|
763
|
-
remediation = profile.get("remediation", {})
|
|
764
|
-
return bool(remediation.get("variants")) or any(
|
|
765
|
-
is_runtime_path(patch.get("path")) for patch in remediation.get("patches", [])
|
|
766
|
-
)
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
def resolve_remediation(
|
|
770
|
-
profile: dict[str, Any], *, multi_agent_context: dict[str, Any]
|
|
771
|
-
) -> dict[str, Any]:
|
|
772
|
-
multi_agent_mode = str(multi_agent_context["mode"])
|
|
773
|
-
remediation = dict(profile.get("remediation", {}))
|
|
774
|
-
variants = remediation.pop("variants", [])
|
|
775
|
-
remediation["multi_agent_mode"] = multi_agent_mode
|
|
776
|
-
for variant in variants:
|
|
777
|
-
if variant["mode"] == multi_agent_mode:
|
|
778
|
-
if multi_agent_mode == "v2" and multi_agent_context["owner"] != "native":
|
|
779
|
-
break
|
|
780
|
-
variant_patches = variant.get("patches", [])
|
|
781
|
-
if multi_agent_mode == "v2" and not multi_agent_context["agent_max_threads_configured"]:
|
|
782
|
-
variant_patches = [
|
|
783
|
-
patch
|
|
784
|
-
for patch in variant_patches
|
|
785
|
-
if not (
|
|
786
|
-
patch.get("kind") == "remove" and patch.get("path") == "agents.max_threads"
|
|
787
|
-
)
|
|
788
|
-
]
|
|
789
|
-
remediation["patches"] = remediation.get("patches", []) + variant_patches
|
|
790
|
-
return remediation
|
|
791
|
-
if variants:
|
|
792
|
-
remediation["note"] = (
|
|
793
|
-
"Do not apply a concurrency patch until the active runtime version and config "
|
|
794
|
-
"ownership are known."
|
|
795
|
-
)
|
|
796
|
-
return remediation
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
def evaluate(args: argparse.Namespace) -> dict[str, Any]:
|
|
800
|
-
registry = read_toml(args.registry, required=True)
|
|
801
|
-
validate_registry(registry)
|
|
802
|
-
profile_id = resolve_profile(registry, profile=args.profile, skill=args.skill)
|
|
803
|
-
try:
|
|
804
|
-
profile = registry["profiles"][profile_id]
|
|
805
|
-
except KeyError as error:
|
|
806
|
-
raise ValueError(f"unknown capability profile: {profile_id!r}") from error
|
|
807
|
-
|
|
808
|
-
cli_profile_selected = args.codex_config_profile is not None
|
|
809
|
-
if args.config:
|
|
810
|
-
config_paths = args.config
|
|
811
|
-
config_discovery = None
|
|
812
|
-
config_resolution = "manual-layers"
|
|
813
|
-
project_config_paths_set: set[Path] = set()
|
|
814
|
-
profile_layer_path = None
|
|
815
|
-
else:
|
|
816
|
-
profile_layer_path = config_profile_layer_path(args.codex_config_profile)
|
|
817
|
-
config_paths, config_discovery = discover_config_paths(
|
|
818
|
-
cwd=args.cwd,
|
|
819
|
-
profile_layer_path=profile_layer_path,
|
|
820
|
-
)
|
|
821
|
-
config_resolution = "cwd-discovery"
|
|
822
|
-
project_config_paths_set = set(config_paths[3 if profile_layer_path else 2 :])
|
|
823
|
-
config_layers = []
|
|
824
|
-
for path in config_paths:
|
|
825
|
-
config = read_toml(path, required=False)
|
|
826
|
-
if path in project_config_paths_set:
|
|
827
|
-
# Codex strips project-local profile selection and definitions before
|
|
828
|
-
# resolving the merged config. Mirror that denylist here.
|
|
829
|
-
config.pop("profile", None)
|
|
830
|
-
config.pop("profiles", None)
|
|
831
|
-
config_layers.append((path, config))
|
|
832
|
-
config_profile, embedded_config_profile = resolve_active_config_profile(
|
|
833
|
-
config_layers=config_layers,
|
|
834
|
-
override=args.codex_config_profile,
|
|
835
|
-
cli_profile_selected=cli_profile_selected,
|
|
836
|
-
)
|
|
837
|
-
runtime_checks = parse_runtime_checks(args.runtime_check)
|
|
838
|
-
available_plugin_skills = parse_available_plugin_skills(args.available_plugin_skill)
|
|
839
|
-
effective_config = parse_effective_config(args.effective_config)
|
|
840
|
-
multi_agent_context = resolve_multi_agent_context(
|
|
841
|
-
config_layers=config_layers,
|
|
842
|
-
effective_config=effective_config,
|
|
843
|
-
config_profile=embedded_config_profile,
|
|
844
|
-
runtime_owner=args.multi_agent_runtime_owner,
|
|
845
|
-
runtime_version=args.multi_agent_runtime_version,
|
|
846
|
-
runtime_session_cap=args.multi_agent_session_cap,
|
|
847
|
-
runtime_provenance=args.multi_agent_runtime_provenance,
|
|
848
|
-
validate_multi_agent_config=profile_requires_multi_agent_config(
|
|
849
|
-
profile, registry["capabilities"]
|
|
850
|
-
),
|
|
851
|
-
)
|
|
852
|
-
results = [
|
|
853
|
-
evaluate_requirement(
|
|
854
|
-
requirement,
|
|
855
|
-
capabilities=registry["capabilities"],
|
|
856
|
-
config_layers=config_layers,
|
|
857
|
-
effective_config=effective_config,
|
|
858
|
-
runtime_checks=runtime_checks,
|
|
859
|
-
available_plugin_skills=available_plugin_skills,
|
|
860
|
-
config_profile=embedded_config_profile,
|
|
861
|
-
multi_agent_context=multi_agent_context,
|
|
862
|
-
runtime_session_cap=args.multi_agent_session_cap,
|
|
863
|
-
)
|
|
864
|
-
for requirement in profile["requirements"]
|
|
865
|
-
if not requirement.get("modes") or multi_agent_context["mode"] in requirement["modes"]
|
|
866
|
-
]
|
|
867
|
-
failed = [result for result in results if result["status"] == "fail"]
|
|
868
|
-
unknown = [result for result in results if result["status"] == "unknown"]
|
|
869
|
-
if any(result["severity"] == "block" for result in failed):
|
|
870
|
-
status = "blocked"
|
|
871
|
-
elif any(result["severity"] == "block" for result in unknown):
|
|
872
|
-
status = "incomplete"
|
|
873
|
-
else:
|
|
874
|
-
status = "ready"
|
|
875
|
-
return {
|
|
876
|
-
"version": registry["version"],
|
|
877
|
-
"profile": profile_id,
|
|
878
|
-
"description": profile["description"],
|
|
879
|
-
"config_resolution": config_resolution,
|
|
880
|
-
"user_config_path": None if args.config else str(profile_layer_path or DEFAULT_CONFIG),
|
|
881
|
-
"config_paths": [str(path) for path in config_paths],
|
|
882
|
-
"config_discovery": config_discovery,
|
|
883
|
-
"config_profile": config_profile,
|
|
884
|
-
"config_profile_path": str(profile_layer_path) if profile_layer_path else None,
|
|
885
|
-
"multi_agent_mode": multi_agent_context["mode"],
|
|
886
|
-
"multi_agent_context": multi_agent_context,
|
|
887
|
-
"status": status,
|
|
888
|
-
"results": results,
|
|
889
|
-
"failed": failed,
|
|
890
|
-
"unknown": unknown,
|
|
891
|
-
"remediation": resolve_remediation(
|
|
892
|
-
profile,
|
|
893
|
-
multi_agent_context=multi_agent_context,
|
|
894
|
-
),
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
def main() -> int:
|
|
899
|
-
try:
|
|
900
|
-
payload = evaluate(parse_args())
|
|
901
|
-
except (KeyError, OSError, TypeError, ValueError, tomllib.TOMLDecodeError) as error:
|
|
902
|
-
print(json.dumps({"status": "error", "error": str(error)}, indent=2, sort_keys=True))
|
|
903
|
-
return 2
|
|
904
|
-
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
905
|
-
if payload["status"] == "blocked":
|
|
906
|
-
return 1
|
|
907
|
-
return 2 if payload["status"] == "incomplete" else 0
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
if __name__ == "__main__":
|
|
911
|
-
sys.exit(main())
|