claude-dev-env 2.10.0 → 2.12.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/CLAUDE.md +1 -1
- package/_shared/advisor/CLAUDE.md +3 -2
- package/_shared/advisor/advisor-protocol.md +74 -108
- package/_shared/advisor/reference/advisor-block.md +37 -0
- package/_shared/advisor/reference/cli-chain.md +45 -0
- package/_shared/advisor/reference/consult-format.md +41 -0
- package/_shared/advisor/reference/lifecycle.md +21 -0
- package/_shared/advisor/reference/sol-rung.md +34 -0
- package/_shared/advisor/reference/spawn-walk-log.md +31 -0
- package/_shared/advisor/reference/third-party-bind.md +30 -0
- package/_shared/advisor/reference/warm-up.md +34 -0
- package/_shared/advisor/scripts/codex_sol_advisor.py +514 -0
- package/_shared/advisor/scripts/config/advisor_scripts_constants/advisor_route_constants.py +21 -0
- package/_shared/advisor/scripts/config/advisor_scripts_constants/model_tier_run_validator_constants.py +19 -17
- package/_shared/advisor/scripts/config/advisor_scripts_constants/sol_advisor_constants.py +33 -0
- package/_shared/advisor/scripts/model_tier_run_validator.py +32 -9
- package/_shared/advisor/scripts/tests/test_codex_sol_advisor.py +636 -0
- package/_shared/advisor/scripts/tests/test_model_tier_run_validator.py +79 -0
- package/_shared/advisor/scripts/tests/test_tier_model_ids.py +39 -17
- package/_shared/advisor/scripts/tier_model_ids.py +24 -0
- package/commands/CLAUDE.md +1 -0
- package/commands/sr-loop.md +48 -0
- package/docs/references/CLAUDE.md +2 -1
- package/docs/references/advisor-tool.md +26 -8
- package/docs/references/team-advisor-skill.md +3 -3
- package/docs/references/weak-executor-advisor.md +91 -0
- package/hooks/blocking/test_fable_spawn_gate.py +18 -11
- package/package.json +1 -1
- package/skills/_shared/advisor/CLAUDE.md +1 -1
- package/skills/_shared/advisor/scripts/README.md +2 -0
- package/skills/grokify/SKILL.md +1 -1
- package/skills/grokify/templates/handoff-template.md +2 -2
- package/skills/orchestrator/SKILL.md +5 -4
- package/skills/team-advisor/SKILL.md +7 -4
- package/skills/team-advisor/reference/advisor-docs-review.md +207 -0
- package/skills/usage-pause/SKILL.md +1 -1
- package/skills/usage-pause/scripts/resolve_usage_window.py +32 -4
- package/skills/usage-pause/scripts/test_resolve_usage_window.py +26 -0
- package/skills/usage-pause/scripts/usage_pause_constants/resolve_usage_window_constants.py +3 -1
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
"""Bind and consult a read-only Codex CLI session at Sol xhigh."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import importlib
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
14
|
+
from dataclasses import asdict, dataclass
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
_scripts_directory = Path(__file__).resolve().parent
|
|
18
|
+
_config_directory = _scripts_directory / "config"
|
|
19
|
+
_config_directory_text = str(_config_directory)
|
|
20
|
+
if _config_directory_text not in sys.path:
|
|
21
|
+
sys.path.insert(0, _config_directory_text)
|
|
22
|
+
|
|
23
|
+
from advisor_scripts_constants.sol_advisor_constants import ( # noqa: E402
|
|
24
|
+
ADVISOR_CODEX_EXECUTABLE_ENV_VAR,
|
|
25
|
+
CODEX_CONFIG_FLAG,
|
|
26
|
+
CODEX_EXECUTABLE,
|
|
27
|
+
CODEX_EXEC_SUBCOMMAND,
|
|
28
|
+
CODEX_JSON_FLAG,
|
|
29
|
+
CODEX_MODEL_FLAG,
|
|
30
|
+
CODEX_PROMPT_FROM_STDIN,
|
|
31
|
+
CODEX_READ_ONLY_SANDBOX,
|
|
32
|
+
CODEX_REASONING_CONFIG,
|
|
33
|
+
CODEX_RESUME_SUBCOMMAND,
|
|
34
|
+
CODEX_SANDBOX_FLAG,
|
|
35
|
+
CLAUDE_CONFIG_DIRECTORY_NAME,
|
|
36
|
+
SOL_BIND_FAILURE_REASON,
|
|
37
|
+
SOL_CODEX_TIMEOUT_REASON,
|
|
38
|
+
SOL_CODEX_TIMEOUT_SECONDS,
|
|
39
|
+
SOL_ENV_VAR,
|
|
40
|
+
SOL_ENABLE_FLAG,
|
|
41
|
+
SOL_EXECUTABLE_NOT_FOUND_REASON,
|
|
42
|
+
SOL_FALLBACK_KIND_BROKEN,
|
|
43
|
+
SOL_FALLBACK_KIND_DECLINED,
|
|
44
|
+
SOL_INVALID_SIGNAL_REASON,
|
|
45
|
+
SOL_MALFORMED_JSONL_REASON,
|
|
46
|
+
SOL_MISSING_SESSION_REASON,
|
|
47
|
+
SOL_PREFLIGHT_FAILURE_REASON,
|
|
48
|
+
SOL_PROBE_TIMEOUT_REASON,
|
|
49
|
+
SOL_REPLY_FAILURE_REASON,
|
|
50
|
+
SOL_SESSION_ID_METAVAR,
|
|
51
|
+
ALL_SOL_TRUTHY_VALUES,
|
|
52
|
+
SOL_USAGE_PROBE_TIMEOUT_SECONDS,
|
|
53
|
+
)
|
|
54
|
+
from advisor_scripts_constants.advisor_route_constants import ( # noqa: E402
|
|
55
|
+
ADVISOR_CODEX_MODEL_ID,
|
|
56
|
+
ADVISOR_FALLBACK_RESULT,
|
|
57
|
+
ADVISOR_FALLBACK_TIER,
|
|
58
|
+
ADVISOR_MODEL_TIER,
|
|
59
|
+
ALL_ADVISOR_GUIDANCE_SIGNALS,
|
|
60
|
+
CODEX_BIND_SUCCESS_TOKEN,
|
|
61
|
+
SPAWN_OUTCOME_KEY,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass(frozen=True)
|
|
66
|
+
class SolPreflight:
|
|
67
|
+
"""Record the weekly-meter decision made before a Sol attempt."""
|
|
68
|
+
|
|
69
|
+
eligible: bool
|
|
70
|
+
percent_left: float | None
|
|
71
|
+
reason: str
|
|
72
|
+
fallback_kind: str | None = None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass(frozen=True)
|
|
76
|
+
class CodexSolAdvisorReply:
|
|
77
|
+
"""Record a parsed Codex advisor response or an explicit fallback."""
|
|
78
|
+
|
|
79
|
+
session_id: str | None
|
|
80
|
+
guidance: str | None
|
|
81
|
+
successful: bool
|
|
82
|
+
reason: str | None
|
|
83
|
+
is_fallback: bool
|
|
84
|
+
signal: str | None
|
|
85
|
+
sol_enabled: bool
|
|
86
|
+
selected_tier: str
|
|
87
|
+
outcome: str
|
|
88
|
+
fallback_kind: str | None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _preflight_fallback(
|
|
92
|
+
reason: str,
|
|
93
|
+
percent_left: float | None,
|
|
94
|
+
fallback_kind: str = SOL_FALLBACK_KIND_BROKEN,
|
|
95
|
+
) -> SolPreflight:
|
|
96
|
+
return SolPreflight(False, percent_left, reason, fallback_kind)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _reply_fallback(
|
|
100
|
+
reason: str,
|
|
101
|
+
is_sol_enabled: bool,
|
|
102
|
+
fallback_kind: str | None = SOL_FALLBACK_KIND_BROKEN,
|
|
103
|
+
) -> CodexSolAdvisorReply:
|
|
104
|
+
return CodexSolAdvisorReply(
|
|
105
|
+
session_id=None,
|
|
106
|
+
guidance=None,
|
|
107
|
+
successful=False,
|
|
108
|
+
reason=reason,
|
|
109
|
+
is_fallback=True,
|
|
110
|
+
signal=None,
|
|
111
|
+
sol_enabled=is_sol_enabled,
|
|
112
|
+
selected_tier=ADVISOR_FALLBACK_TIER,
|
|
113
|
+
outcome=ADVISOR_FALLBACK_RESULT,
|
|
114
|
+
fallback_kind=fallback_kind,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _reply_success(
|
|
119
|
+
session_id: str,
|
|
120
|
+
guidance: str,
|
|
121
|
+
signal: str,
|
|
122
|
+
) -> CodexSolAdvisorReply:
|
|
123
|
+
return CodexSolAdvisorReply(
|
|
124
|
+
session_id=session_id,
|
|
125
|
+
guidance=guidance,
|
|
126
|
+
successful=True,
|
|
127
|
+
reason=None,
|
|
128
|
+
is_fallback=False,
|
|
129
|
+
signal=signal,
|
|
130
|
+
sol_enabled=True,
|
|
131
|
+
selected_tier=ADVISOR_MODEL_TIER,
|
|
132
|
+
outcome=CODEX_BIND_SUCCESS_TOKEN,
|
|
133
|
+
fallback_kind=None,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _resolved_setting_by_name(
|
|
138
|
+
setting_by_name: Mapping[str, str] | None,
|
|
139
|
+
) -> Mapping[str, str]:
|
|
140
|
+
return os.environ if setting_by_name is None else setting_by_name
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def is_sol_advisor_enabled(
|
|
144
|
+
setting_by_name: Mapping[str, str] | None,
|
|
145
|
+
) -> bool:
|
|
146
|
+
"""Return whether the optional Sol xhigh rung is enabled.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
setting_by_name: Optional environment-like settings mapping.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Whether the Sol feature flag contains a recognized truthy value.
|
|
153
|
+
"""
|
|
154
|
+
resolved_setting_by_name = _resolved_setting_by_name(setting_by_name)
|
|
155
|
+
return (
|
|
156
|
+
resolved_setting_by_name.get(SOL_ENV_VAR, "").strip().lower()
|
|
157
|
+
in ALL_SOL_TRUTHY_VALUES
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def resolve_usage_probe_path(home_directory: Path) -> Path:
|
|
162
|
+
"""Return the installed Codex weekly usage probe path.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
home_directory: Home directory used to construct the path.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
The path to the installed weekly usage probe.
|
|
169
|
+
"""
|
|
170
|
+
return (
|
|
171
|
+
home_directory
|
|
172
|
+
/ CLAUDE_CONFIG_DIRECTORY_NAME
|
|
173
|
+
/ "skills"
|
|
174
|
+
/ "codex-review"
|
|
175
|
+
/ "scripts"
|
|
176
|
+
/ "codex_usage_probe.py"
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _load_usage_gate(probe_path: Path) -> Callable[[float], bool]:
|
|
181
|
+
probe_directory = str(probe_path.parent)
|
|
182
|
+
if probe_directory not in sys.path:
|
|
183
|
+
sys.path.insert(0, probe_directory)
|
|
184
|
+
usage_probe_module = importlib.import_module("codex_usage_probe")
|
|
185
|
+
return usage_probe_module.is_codex_review_required
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _parse_probe_percent(stdout_text: str) -> tuple[float | None, str | None]:
|
|
189
|
+
try:
|
|
190
|
+
usage_report = json.loads(stdout_text)
|
|
191
|
+
except (TypeError, json.JSONDecodeError):
|
|
192
|
+
return None, "usage report is malformed"
|
|
193
|
+
if not isinstance(usage_report, dict):
|
|
194
|
+
return None, "usage report is malformed"
|
|
195
|
+
raw_percent_left = usage_report.get("percent_left")
|
|
196
|
+
if raw_percent_left is None:
|
|
197
|
+
return None, "usage meter is unknown"
|
|
198
|
+
if isinstance(raw_percent_left, bool) or not isinstance(
|
|
199
|
+
raw_percent_left, (int, float)
|
|
200
|
+
):
|
|
201
|
+
return None, "usage meter is malformed"
|
|
202
|
+
percent_left = float(raw_percent_left)
|
|
203
|
+
if not math.isfinite(percent_left):
|
|
204
|
+
return None, "usage meter is malformed"
|
|
205
|
+
return percent_left, None
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def run_sol_preflight(
|
|
209
|
+
probe_path: Path,
|
|
210
|
+
process_runner: Callable[..., subprocess.CompletedProcess[str]],
|
|
211
|
+
) -> SolPreflight:
|
|
212
|
+
"""Run the existing usage probe and require a finite meter above its gate.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
probe_path: Path to the installed usage probe.
|
|
216
|
+
process_runner: Callable used to execute the probe.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
The usage-meter eligibility decision and any fallback reason.
|
|
220
|
+
"""
|
|
221
|
+
try:
|
|
222
|
+
completed_process = process_runner(
|
|
223
|
+
[sys.executable, str(probe_path)],
|
|
224
|
+
capture_output=True,
|
|
225
|
+
text=True,
|
|
226
|
+
check=False,
|
|
227
|
+
shell=False,
|
|
228
|
+
timeout=SOL_USAGE_PROBE_TIMEOUT_SECONDS,
|
|
229
|
+
)
|
|
230
|
+
if completed_process.returncode != 0:
|
|
231
|
+
return _preflight_fallback(
|
|
232
|
+
f"{SOL_PREFLIGHT_FAILURE_REASON}: probe exit {completed_process.returncode}",
|
|
233
|
+
None,
|
|
234
|
+
)
|
|
235
|
+
percent_left, parse_reason = _parse_probe_percent(completed_process.stdout)
|
|
236
|
+
if parse_reason is not None:
|
|
237
|
+
return _preflight_fallback(
|
|
238
|
+
f"{SOL_PREFLIGHT_FAILURE_REASON}: {parse_reason}", None
|
|
239
|
+
)
|
|
240
|
+
usage_gate = _load_usage_gate(probe_path)
|
|
241
|
+
if not callable(usage_gate) or percent_left is None:
|
|
242
|
+
return _preflight_fallback(
|
|
243
|
+
f"{SOL_PREFLIGHT_FAILURE_REASON}: usage meter is unknown", None
|
|
244
|
+
)
|
|
245
|
+
if not usage_gate(percent_left):
|
|
246
|
+
return _preflight_fallback(
|
|
247
|
+
f"{SOL_PREFLIGHT_FAILURE_REASON}: usage meter is at or below the gate",
|
|
248
|
+
percent_left,
|
|
249
|
+
fallback_kind=SOL_FALLBACK_KIND_DECLINED,
|
|
250
|
+
)
|
|
251
|
+
except subprocess.TimeoutExpired as probe_error:
|
|
252
|
+
return _preflight_fallback(f"{SOL_PROBE_TIMEOUT_REASON}: {probe_error}", None)
|
|
253
|
+
except (
|
|
254
|
+
OSError,
|
|
255
|
+
subprocess.SubprocessError,
|
|
256
|
+
ImportError,
|
|
257
|
+
AttributeError,
|
|
258
|
+
TypeError,
|
|
259
|
+
ValueError,
|
|
260
|
+
) as probe_error:
|
|
261
|
+
return _preflight_fallback(
|
|
262
|
+
f"{SOL_PREFLIGHT_FAILURE_REASON}: {probe_error}", None
|
|
263
|
+
)
|
|
264
|
+
return SolPreflight(True, percent_left, "usage meter is above the Sol gate")
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def resolve_codex_executable(
|
|
268
|
+
setting_by_name: Mapping[str, str] | None,
|
|
269
|
+
) -> str | None:
|
|
270
|
+
"""Resolve the Codex CLI executable to an invocable name or path.
|
|
271
|
+
|
|
272
|
+
A bare "codex" name fails Windows `CreateProcess`, since the npm shim
|
|
273
|
+
directory holds only `codex` (a sh script), `codex.cmd`, and `codex.ps1`.
|
|
274
|
+
`shutil.which` finds `codex.cmd` via `PATHEXT`. An explicit override
|
|
275
|
+
always wins and is trusted without a `which` check.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
setting_by_name: Optional environment-like settings mapping.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
An invocable executable name or path, or None when unresolved.
|
|
282
|
+
"""
|
|
283
|
+
resolved_setting_by_name = _resolved_setting_by_name(setting_by_name)
|
|
284
|
+
executable_override = resolved_setting_by_name.get(ADVISOR_CODEX_EXECUTABLE_ENV_VAR, "").strip()
|
|
285
|
+
if executable_override:
|
|
286
|
+
return executable_override
|
|
287
|
+
return shutil.which(CODEX_EXECUTABLE)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def build_codex_arguments(
|
|
291
|
+
codex_executable: str,
|
|
292
|
+
session_id: str | None = None,
|
|
293
|
+
) -> list[str]:
|
|
294
|
+
"""Build the installed CLI's shell-free bind or resume argv.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
codex_executable: Resolved executable name or path to invoke.
|
|
298
|
+
session_id: Optional existing session to resume.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
The shell-free Codex command argument vector.
|
|
302
|
+
"""
|
|
303
|
+
command_arguments = [
|
|
304
|
+
codex_executable,
|
|
305
|
+
CODEX_EXEC_SUBCOMMAND,
|
|
306
|
+
CODEX_MODEL_FLAG,
|
|
307
|
+
ADVISOR_CODEX_MODEL_ID,
|
|
308
|
+
CODEX_CONFIG_FLAG,
|
|
309
|
+
CODEX_REASONING_CONFIG,
|
|
310
|
+
CODEX_SANDBOX_FLAG,
|
|
311
|
+
CODEX_READ_ONLY_SANDBOX,
|
|
312
|
+
CODEX_JSON_FLAG,
|
|
313
|
+
]
|
|
314
|
+
if session_id is not None:
|
|
315
|
+
command_arguments.extend([CODEX_RESUME_SUBCOMMAND, session_id])
|
|
316
|
+
command_arguments.append(CODEX_PROMPT_FROM_STDIN)
|
|
317
|
+
return command_arguments
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _guidance_signal(guidance: str) -> str | None:
|
|
321
|
+
for each_line in guidance.splitlines():
|
|
322
|
+
stripped_line = each_line.strip()
|
|
323
|
+
if not stripped_line:
|
|
324
|
+
continue
|
|
325
|
+
return stripped_line if stripped_line in ALL_ADVISOR_GUIDANCE_SIGNALS else None
|
|
326
|
+
return None
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def parse_codex_jsonl_reply(
|
|
330
|
+
jsonl_text: str,
|
|
331
|
+
existing_session_id: str | None,
|
|
332
|
+
is_sol_enabled: bool,
|
|
333
|
+
) -> CodexSolAdvisorReply:
|
|
334
|
+
"""Parse strict Codex JSONL into a session id and final guidance.
|
|
335
|
+
|
|
336
|
+
Args:
|
|
337
|
+
jsonl_text: JSONL emitted by the Codex CLI.
|
|
338
|
+
existing_session_id: Optional session id required on resume.
|
|
339
|
+
is_sol_enabled: Whether the attempted route had Sol enabled.
|
|
340
|
+
|
|
341
|
+
Returns:
|
|
342
|
+
The parsed guidance or an explicit Fable fallback reply.
|
|
343
|
+
"""
|
|
344
|
+
discovered_session_id: str | None = None
|
|
345
|
+
final_guidance: str | None = None
|
|
346
|
+
try:
|
|
347
|
+
for each_line in jsonl_text.splitlines():
|
|
348
|
+
if not each_line.strip():
|
|
349
|
+
continue
|
|
350
|
+
event = json.loads(each_line)
|
|
351
|
+
if not isinstance(event, dict):
|
|
352
|
+
return _reply_fallback(SOL_MALFORMED_JSONL_REASON, is_sol_enabled)
|
|
353
|
+
if event.get("type") == "thread.started":
|
|
354
|
+
thread_id = event.get("thread_id")
|
|
355
|
+
if isinstance(thread_id, str) and thread_id.strip():
|
|
356
|
+
discovered_session_id = thread_id.strip()
|
|
357
|
+
completed_event = event.get("item")
|
|
358
|
+
if (
|
|
359
|
+
event.get("type") == "item.completed"
|
|
360
|
+
and isinstance(completed_event, dict)
|
|
361
|
+
and completed_event.get("type") == "agent_message"
|
|
362
|
+
and isinstance(completed_event.get("text"), str)
|
|
363
|
+
):
|
|
364
|
+
final_guidance = completed_event["text"].strip()
|
|
365
|
+
except (TypeError, json.JSONDecodeError):
|
|
366
|
+
return _reply_fallback(SOL_MALFORMED_JSONL_REASON, is_sol_enabled)
|
|
367
|
+
if discovered_session_id is None:
|
|
368
|
+
return _reply_fallback(SOL_MISSING_SESSION_REASON, is_sol_enabled)
|
|
369
|
+
if (
|
|
370
|
+
existing_session_id is not None
|
|
371
|
+
and discovered_session_id != existing_session_id
|
|
372
|
+
):
|
|
373
|
+
return _reply_fallback(SOL_MISSING_SESSION_REASON, is_sol_enabled)
|
|
374
|
+
if not final_guidance:
|
|
375
|
+
return _reply_fallback(SOL_REPLY_FAILURE_REASON, is_sol_enabled)
|
|
376
|
+
guidance_signal = _guidance_signal(final_guidance)
|
|
377
|
+
if guidance_signal is None:
|
|
378
|
+
return _reply_fallback(SOL_INVALID_SIGNAL_REASON, is_sol_enabled)
|
|
379
|
+
return _reply_success(discovered_session_id, final_guidance, guidance_signal)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _resolve_sol_preflight(
|
|
383
|
+
preflight: SolPreflight | None,
|
|
384
|
+
probe_path: Path | None,
|
|
385
|
+
process_runner: Callable[..., subprocess.CompletedProcess[str]],
|
|
386
|
+
) -> SolPreflight:
|
|
387
|
+
if preflight is not None:
|
|
388
|
+
return preflight
|
|
389
|
+
resolved_probe_path = (
|
|
390
|
+
resolve_usage_probe_path(Path.home()) if probe_path is None else probe_path
|
|
391
|
+
)
|
|
392
|
+
return run_sol_preflight(
|
|
393
|
+
probe_path=resolved_probe_path, process_runner=process_runner
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def run_codex_sol_advisor(
|
|
398
|
+
prompt: str,
|
|
399
|
+
working_directory: Path,
|
|
400
|
+
preflight: SolPreflight | None,
|
|
401
|
+
probe_path: Path | None,
|
|
402
|
+
setting_by_name: Mapping[str, str] | None,
|
|
403
|
+
session_id: str | None,
|
|
404
|
+
process_runner: Callable[..., subprocess.CompletedProcess[str]],
|
|
405
|
+
) -> CodexSolAdvisorReply:
|
|
406
|
+
"""Run one usage-gated read-only Sol bind or resume attempt.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
prompt: Advisor charter or delta consult sent to Codex.
|
|
410
|
+
working_directory: Repository directory supplied to the CLI.
|
|
411
|
+
preflight: Optional precomputed usage-meter decision.
|
|
412
|
+
probe_path: Optional installed usage-probe path.
|
|
413
|
+
setting_by_name: Optional environment-like settings mapping.
|
|
414
|
+
session_id: Existing session id for a resume attempt.
|
|
415
|
+
process_runner: Callable used to execute the probe and Codex.
|
|
416
|
+
|
|
417
|
+
Returns:
|
|
418
|
+
The parsed Sol guidance or an explicit Fable fallback reply.
|
|
419
|
+
"""
|
|
420
|
+
if not is_sol_advisor_enabled(setting_by_name):
|
|
421
|
+
return _reply_fallback(
|
|
422
|
+
"Sol advisor flag is disabled",
|
|
423
|
+
False,
|
|
424
|
+
fallback_kind=SOL_FALLBACK_KIND_DECLINED,
|
|
425
|
+
)
|
|
426
|
+
codex_executable = resolve_codex_executable(setting_by_name)
|
|
427
|
+
if codex_executable is None:
|
|
428
|
+
return _reply_fallback(SOL_EXECUTABLE_NOT_FOUND_REASON, True)
|
|
429
|
+
resolved_preflight = _resolve_sol_preflight(preflight, probe_path, process_runner)
|
|
430
|
+
if not resolved_preflight.eligible:
|
|
431
|
+
return _reply_fallback(
|
|
432
|
+
resolved_preflight.reason,
|
|
433
|
+
True,
|
|
434
|
+
fallback_kind=resolved_preflight.fallback_kind,
|
|
435
|
+
)
|
|
436
|
+
try:
|
|
437
|
+
completed_process = process_runner(
|
|
438
|
+
build_codex_arguments(codex_executable, session_id=session_id),
|
|
439
|
+
cwd=str(working_directory),
|
|
440
|
+
input=prompt,
|
|
441
|
+
capture_output=True,
|
|
442
|
+
text=True,
|
|
443
|
+
check=False,
|
|
444
|
+
shell=False,
|
|
445
|
+
timeout=SOL_CODEX_TIMEOUT_SECONDS,
|
|
446
|
+
)
|
|
447
|
+
except subprocess.TimeoutExpired as bind_error:
|
|
448
|
+
return _reply_fallback(f"{SOL_CODEX_TIMEOUT_REASON}: {bind_error}", True)
|
|
449
|
+
except (OSError, subprocess.SubprocessError) as bind_error:
|
|
450
|
+
return _reply_fallback(f"{SOL_BIND_FAILURE_REASON}: {bind_error}", True)
|
|
451
|
+
if completed_process.returncode != 0:
|
|
452
|
+
return _reply_fallback(
|
|
453
|
+
f"{SOL_BIND_FAILURE_REASON}: process exit {completed_process.returncode}",
|
|
454
|
+
True,
|
|
455
|
+
)
|
|
456
|
+
return parse_codex_jsonl_reply(
|
|
457
|
+
completed_process.stdout,
|
|
458
|
+
existing_session_id=session_id,
|
|
459
|
+
is_sol_enabled=True,
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def build_argument_parser() -> argparse.ArgumentParser:
|
|
464
|
+
"""Build the command-line parser for Sol bind and resume.
|
|
465
|
+
|
|
466
|
+
Returns:
|
|
467
|
+
The parser for the helper's bind and resume modes.
|
|
468
|
+
"""
|
|
469
|
+
argument_parser = argparse.ArgumentParser(
|
|
470
|
+
description="Bind or consult a read-only Codex Sol xhigh advisor."
|
|
471
|
+
)
|
|
472
|
+
mode_group = argument_parser.add_mutually_exclusive_group(required=True)
|
|
473
|
+
mode_group.add_argument("--bind", action="store_true")
|
|
474
|
+
mode_group.add_argument("--resume", metavar=SOL_SESSION_ID_METAVAR)
|
|
475
|
+
argument_parser.add_argument("--cwd", required=True, type=Path)
|
|
476
|
+
argument_parser.add_argument(
|
|
477
|
+
SOL_ENABLE_FLAG,
|
|
478
|
+
dest="is_sol_requested",
|
|
479
|
+
action="store_true",
|
|
480
|
+
help="Open the Sol rung for this invocation without an environment flag.",
|
|
481
|
+
)
|
|
482
|
+
return argument_parser
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def main(all_cli_arguments: Sequence[str]) -> int:
|
|
486
|
+
"""Run one bind or resume from stdin and print a JSON response.
|
|
487
|
+
|
|
488
|
+
Args:
|
|
489
|
+
all_cli_arguments: Command-line arguments without the program name.
|
|
490
|
+
|
|
491
|
+
Returns:
|
|
492
|
+
Zero for a successful Sol response, or one for an explicit fallback.
|
|
493
|
+
"""
|
|
494
|
+
parsed_arguments = build_argument_parser().parse_args(list(all_cli_arguments))
|
|
495
|
+
setting_by_name: Mapping[str, str] = os.environ
|
|
496
|
+
if parsed_arguments.is_sol_requested:
|
|
497
|
+
setting_by_name = {**os.environ, SOL_ENV_VAR: "1"}
|
|
498
|
+
advisor_reply = run_codex_sol_advisor(
|
|
499
|
+
prompt=sys.stdin.read(),
|
|
500
|
+
working_directory=parsed_arguments.cwd,
|
|
501
|
+
preflight=None,
|
|
502
|
+
probe_path=None,
|
|
503
|
+
setting_by_name=setting_by_name,
|
|
504
|
+
session_id=parsed_arguments.resume if not parsed_arguments.bind else None,
|
|
505
|
+
process_runner=subprocess.run,
|
|
506
|
+
)
|
|
507
|
+
reply_payload = asdict(advisor_reply)
|
|
508
|
+
reply_payload[SPAWN_OUTCOME_KEY] = reply_payload.pop("outcome")
|
|
509
|
+
print(json.dumps(reply_payload, sort_keys=True))
|
|
510
|
+
return 0 if advisor_reply.successful else 1
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
if __name__ == "__main__":
|
|
514
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Shared advisor_route_constants for advisor selection and replies."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
ADVISOR_MODEL_TIER: str = "Sol"
|
|
6
|
+
ADVISOR_CODEX_MODEL_ID: str = "gpt-5.6-sol"
|
|
7
|
+
ADVISOR_FALLBACK_TIER: str = "Fable"
|
|
8
|
+
ADVISOR_FALLBACK_RESULT: str = "fable"
|
|
9
|
+
ALL_ADVISOR_GUIDANCE_SIGNALS: frozenset[str] = frozenset(
|
|
10
|
+
{"ENDORSE", "CORRECTION", "PLAN", "STOP"}
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
TIER_KEY: str = "tier"
|
|
14
|
+
SPAWN_OUTCOME_KEY: str = "result"
|
|
15
|
+
SPAWN_SUCCESS_TOKEN: str = "spawned"
|
|
16
|
+
CLI_BIND_SUCCESS_TOKEN: str = "cli"
|
|
17
|
+
CODEX_BIND_SUCCESS_TOKEN: str = "codex"
|
|
18
|
+
|
|
19
|
+
ALL_CODEX_MODEL_ID_BY_TIER: dict[str, str] = {
|
|
20
|
+
ADVISOR_MODEL_TIER: ADVISOR_CODEX_MODEL_ID,
|
|
21
|
+
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"""Constants for the model-tier-run validator and CLI / Agent alias map.
|
|
2
2
|
|
|
3
3
|
They name the parts of a spawn-walk log: the tier ladder (strongest
|
|
4
|
-
first), the two host profiles, the
|
|
5
|
-
|
|
4
|
+
first), the two host profiles, and the validation messages. Shared log
|
|
5
|
+
keys and bind-result tokens live in ``advisor_route_constants``.
|
|
6
6
|
|
|
7
7
|
::
|
|
8
8
|
|
|
9
|
-
attempt = {"tier": "Opus", "result": "spawned"}
|
|
10
|
-
^^^^^^ ^^^^^^^^^
|
|
11
|
-
a ladder tier SPAWN_SUCCESS_TOKEN
|
|
12
|
-
ok: "cli" marks a CLI Claude-chain bind (CLI_BIND_SUCCESS_TOKEN)
|
|
13
|
-
flag: any other result token counts as no bind
|
|
14
|
-
|
|
15
9
|
The alias map turns each tier into its short CLI / Agent name (``opus``,
|
|
16
10
|
``third-party``), never a dated full model ID.
|
|
17
11
|
|
|
@@ -24,6 +18,11 @@ Host-profile detection (see ``detect_host_profile``):
|
|
|
24
18
|
|
|
25
19
|
from __future__ import annotations
|
|
26
20
|
|
|
21
|
+
from advisor_scripts_constants.advisor_route_constants import (
|
|
22
|
+
ADVISOR_FALLBACK_TIER,
|
|
23
|
+
ADVISOR_MODEL_TIER,
|
|
24
|
+
)
|
|
25
|
+
|
|
27
26
|
HOST_PROFILE_CLAUDE: str = "Claude"
|
|
28
27
|
HOST_PROFILE_THIRD_PARTY: str = "ThirdParty"
|
|
29
28
|
ALL_HOST_PROFILES: tuple[str, ...] = (
|
|
@@ -31,32 +30,35 @@ ALL_HOST_PROFILES: tuple[str, ...] = (
|
|
|
31
30
|
HOST_PROFILE_THIRD_PARTY,
|
|
32
31
|
)
|
|
33
32
|
|
|
34
|
-
ALL_MODEL_TIERS: tuple[str, ...] = (
|
|
33
|
+
ALL_MODEL_TIERS: tuple[str, ...] = (
|
|
34
|
+
ADVISOR_FALLBACK_TIER,
|
|
35
|
+
"Opus",
|
|
36
|
+
"Sonnet",
|
|
37
|
+
"Haiku",
|
|
38
|
+
)
|
|
35
39
|
THIRD_PARTY_MODEL_TIER: str = "ThirdParty"
|
|
36
|
-
ALL_KNOWN_TIER_NAMES: tuple[str, ...] = (
|
|
40
|
+
ALL_KNOWN_TIER_NAMES: tuple[str, ...] = (
|
|
41
|
+
ADVISOR_MODEL_TIER,
|
|
42
|
+
*ALL_MODEL_TIERS,
|
|
43
|
+
THIRD_PARTY_MODEL_TIER,
|
|
44
|
+
)
|
|
37
45
|
THIRD_PARTY_CLI_ADVISOR_FLOOR_TIER: str = "Opus"
|
|
38
46
|
|
|
39
47
|
ADVISOR_SENDMESSAGE_REPLY_WAIT_SECONDS: int = 120
|
|
40
48
|
|
|
41
49
|
ALL_CLI_MODEL_ID_BY_TIER: dict[str, str] = {
|
|
42
|
-
|
|
50
|
+
ADVISOR_FALLBACK_TIER: "fable",
|
|
43
51
|
"Opus": "opus",
|
|
44
52
|
"Sonnet": "sonnet",
|
|
45
53
|
"Haiku": "haiku",
|
|
46
54
|
THIRD_PARTY_MODEL_TIER: "third-party",
|
|
47
55
|
}
|
|
48
|
-
|
|
49
56
|
HOST_PROFILE_ENV_VAR: str = "ADVISOR_HOST_PROFILE"
|
|
50
57
|
THIRD_PARTY_ENV_VAR: str = "THIRD_PARTY"
|
|
51
58
|
ALL_THIRD_PARTY_TRUTHY_VALUES: frozenset[str] = frozenset(
|
|
52
59
|
{"1", "true", "yes", "on"}
|
|
53
60
|
)
|
|
54
61
|
|
|
55
|
-
TIER_KEY: str = "tier"
|
|
56
|
-
SPAWN_OUTCOME_KEY: str = "result"
|
|
57
|
-
SPAWN_SUCCESS_TOKEN: str = "spawned"
|
|
58
|
-
CLI_BIND_SUCCESS_TOKEN: str = "cli"
|
|
59
|
-
|
|
60
62
|
UNKNOWN_OWN_TIER_MESSAGE: str = "own_tier is not a known model tier"
|
|
61
63
|
UNKNOWN_LADDER_NAME_ERROR: str = "ladder name is not a known model tier: {!r}"
|
|
62
64
|
UNKNOWN_HOST_PROFILE_ERROR: str = "host profile is not a known profile: {!r}"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Constants for the optional Codex Sol xhigh advisor bind."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
CODEX_EXECUTABLE: str = "codex"
|
|
6
|
+
ADVISOR_CODEX_EXECUTABLE_ENV_VAR: str = "ADVISOR_CODEX_EXECUTABLE"
|
|
7
|
+
CODEX_READ_ONLY_SANDBOX: str = "read-only"
|
|
8
|
+
CODEX_JSON_FLAG: str = "--json"
|
|
9
|
+
CODEX_MODEL_FLAG: str = "--model"
|
|
10
|
+
CODEX_CONFIG_FLAG: str = "--config"
|
|
11
|
+
CODEX_REASONING_CONFIG: str = 'model_reasoning_effort="xhigh"'
|
|
12
|
+
CODEX_PROMPT_FROM_STDIN: str = "-"
|
|
13
|
+
CODEX_EXEC_SUBCOMMAND: str = "exec"
|
|
14
|
+
CODEX_RESUME_SUBCOMMAND: str = "resume"
|
|
15
|
+
CODEX_SANDBOX_FLAG: str = "--sandbox"
|
|
16
|
+
CLAUDE_CONFIG_DIRECTORY_NAME: str = ".claude"
|
|
17
|
+
SOL_SESSION_ID_METAVAR: str = "SESSION_ID"
|
|
18
|
+
SOL_CODEX_TIMEOUT_SECONDS: float = 120.0
|
|
19
|
+
SOL_USAGE_PROBE_TIMEOUT_SECONDS: float = 30.0
|
|
20
|
+
SOL_ENV_VAR: str = "ADVISOR_SOL_XHIGH"
|
|
21
|
+
ALL_SOL_TRUTHY_VALUES: frozenset[str] = frozenset({"1", "true", "yes", "on"})
|
|
22
|
+
SOL_PREFLIGHT_FAILURE_REASON: str = "sol preflight did not establish an eligible Codex meter"
|
|
23
|
+
SOL_BIND_FAILURE_REASON: str = "Codex Sol xhigh bind failed"
|
|
24
|
+
SOL_REPLY_FAILURE_REASON: str = "Codex Sol xhigh returned no advisor guidance"
|
|
25
|
+
SOL_PROBE_TIMEOUT_REASON: str = "Codex Sol meter check timed out"
|
|
26
|
+
SOL_CODEX_TIMEOUT_REASON: str = "Codex Sol xhigh request timed out"
|
|
27
|
+
SOL_MALFORMED_JSONL_REASON: str = "Codex Sol xhigh returned malformed JSONL"
|
|
28
|
+
SOL_MISSING_SESSION_REASON: str = "Codex Sol xhigh returned no session id"
|
|
29
|
+
SOL_INVALID_SIGNAL_REASON: str = "Codex Sol xhigh returned an invalid guidance signal"
|
|
30
|
+
SOL_EXECUTABLE_NOT_FOUND_REASON: str = "Codex Sol xhigh could not find the codex executable on PATH"
|
|
31
|
+
SOL_FALLBACK_KIND_DECLINED: str = "declined"
|
|
32
|
+
SOL_FALLBACK_KIND_BROKEN: str = "broken"
|
|
33
|
+
SOL_ENABLE_FLAG: str = "--enable-sol"
|