verify_step.py python
116 lines 3.8 KB
Raw
sha256:8d7f41aafae41deee70035a92f93602ef1722a290153597451e5932af503a42c docs: queue board-identity follow-ups so they survive the session Human 12 hours ago
1 """``overseer verify-step`` command (§K9.5)."""
2
3 from __future__ import annotations
4
5 import sys
6 from argparse import Namespace
7
8 from adapters.config import load_config
9 from adapters.errors import ConfigError
10 from cli.context import CliContext
11 from cli.paths import resolve_config_path, resolve_repo_root
12 from cli.sanitize import format_config_error
13 from tools.checkpoints.executor import SubprocessScriptExecutor
14 from tools.checkpoints.orchestrator import VerifyStepOptions, run_verify_step
15
16
17 def _build_options(args: Namespace) -> VerifyStepOptions:
18 through_current = False
19 if getattr(args, "through", None) == "current":
20 through_current = True
21 return VerifyStepOptions(
22 manifest=args.manifest,
23 step_id=args.step,
24 through_current=through_current,
25 verify_all=bool(args.all),
26 policy=args.policy,
27 dry_run=bool(args.dry_run),
28 emit_json=bool(args.json),
29 )
30
31
32 def run_verify_step_command(args: Namespace, ctx: CliContext) -> int:
33 """Execute ``overseer verify-step``."""
34 if getattr(args, "through", None) is not None and args.through != "current":
35 ctx.output.error("usage: --through accepts only the literal token 'current'")
36 if args.json:
37 from tools.checkpoints.types import VerifyStepJson
38
39 payload = VerifyStepJson(
40 ok=False,
41 exit_code=1,
42 mode="through",
43 dry_run=bool(args.dry_run),
44 manifest=args.manifest,
45 steps=[],
46 error="usage",
47 )
48 ctx.output.emit_json(payload.to_dict())
49 return 1
50
51 repo_root = resolve_repo_root(cwd=ctx.cwd, repo_arg=args.repo, command="verify-step")
52 overseer_dir = repo_root / ".overseer"
53 if not overseer_dir.is_dir():
54 ctx.output.error("not initialized — run ok init first")
55 if args.json:
56 from tools.checkpoints.types import VerifyStepJson
57
58 ctx.output.emit_json(
59 VerifyStepJson(
60 ok=False,
61 exit_code=2,
62 dry_run=bool(args.dry_run),
63 steps=[],
64 error="config",
65 ).to_dict()
66 )
67 return 2
68
69 config_path = resolve_config_path(repo_root, args.config)
70 try:
71 config = load_config(config_path)
72 except ConfigError as exc:
73 ctx.output.error(format_config_error(exc, repo_root))
74 if args.json:
75 from tools.checkpoints.types import VerifyStepJson
76
77 ctx.output.emit_json(
78 VerifyStepJson(
79 ok=False,
80 exit_code=2,
81 dry_run=bool(args.dry_run),
82 steps=[],
83 error="config",
84 ).to_dict()
85 )
86 return 2
87
88 for warning in config.extension_warnings:
89 ctx.output.warn(warning)
90
91 options = _build_options(args)
92 executor = ctx.script_executor or SubprocessScriptExecutor()
93 result = run_verify_step(
94 config=config,
95 repo_root=repo_root,
96 options=options,
97 executor=executor,
98 )
99
100 if result.stderr_extra:
101 print(result.stderr_extra, file=sys.stderr)
102
103 if options.emit_json:
104 ctx.output.emit_json(result.json_payload.to_dict())
105 elif result.exit_code == 4 and not config.checkpoints.enabled:
106 ctx.output.error("refused: checkpoints.enabled is false")
107 elif result.exit_code != 0 and result.json_payload.error == "refused":
108 ctx.output.error("refused: path or module gate")
109 elif result.exit_code == 10:
110 ctx.output.error("verify failed")
111 elif result.exit_code == 11:
112 ctx.output.error("step order violation")
113 elif result.exit_code == 5:
114 ctx.output.error("manifest write failed")
115
116 return result.exit_code
File History 1 commit
sha256:8d7f41aafae41deee70035a92f93602ef1722a290153597451e5932af503a42c docs: queue board-identity follow-ups so they survive the session Human 12 hours ago