governance_sync.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
2 days ago
| 1 | """``overseer governance-sync`` command (§9A-5).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | from adapters.config import load_config |
| 8 | from adapters.errors import ConfigError |
| 9 | from adapters.factory import create_adapter |
| 10 | from cli.context import CliContext |
| 11 | from cli.paths import is_within_repo, resolve_config_path, resolve_repo_root |
| 12 | from cli.sanitize import format_config_error |
| 13 | from tools.governance_hygiene.engine import run_governance_sync |
| 14 | |
| 15 | |
| 16 | def run_governance_sync_command(args: Namespace, ctx: CliContext) -> int: |
| 17 | """Execute ``overseer governance-sync`` (default: dry-run).""" |
| 18 | repo_root = resolve_repo_root(cwd=ctx.cwd, repo_arg=args.repo, command="governance-sync") |
| 19 | config_path = resolve_config_path(repo_root, args.config) |
| 20 | if not is_within_repo(repo_root, config_path): |
| 21 | ctx.output.error("refused: config path outside repo root") |
| 22 | return 4 |
| 23 | |
| 24 | try: |
| 25 | config = load_config(config_path) |
| 26 | except ConfigError as exc: |
| 27 | ctx.output.error(format_config_error(exc, repo_root)) |
| 28 | return 2 |
| 29 | |
| 30 | adapter = create_adapter(config, repo_root, runner=ctx.runner) |
| 31 | dry_run = not args.write |
| 32 | messages: list[str] = [] |
| 33 | |
| 34 | def emit(line: str) -> None: |
| 35 | messages.append(line) |
| 36 | if not ctx.output.quiet: |
| 37 | if ctx.output.json_mode: |
| 38 | return |
| 39 | ctx.output.emit(line) |
| 40 | |
| 41 | result = run_governance_sync( |
| 42 | config, |
| 43 | repo_root, |
| 44 | adapter, |
| 45 | ctx.runner, |
| 46 | dry_run=dry_run, |
| 47 | lane=getattr(args, "lane", None), |
| 48 | all_lanes=getattr(args, "all_lanes", False), |
| 49 | emit=emit, |
| 50 | kit_root=ctx.kit, |
| 51 | ) |
| 52 | |
| 53 | if ctx.output.json_mode: |
| 54 | payload = { |
| 55 | "dry_run": result.dry_run, |
| 56 | "exit_code": result.exit_code, |
| 57 | "committed": result.committed, |
| 58 | "commit_sha": result.commit_sha, |
| 59 | "error_command": result.error_command, |
| 60 | "messages": list(result.messages) + messages, |
| 61 | "workspace_relay": result.workspace_relay, |
| 62 | } |
| 63 | if result.drift is not None: |
| 64 | payload["drift"] = { |
| 65 | "d1": result.drift.d1_handover_vs_git, |
| 66 | "d2": result.drift.d2_anchor_vs_canonical, |
| 67 | "d3": result.drift.d3_queue_vs_merged, |
| 68 | "details": result.drift.details, |
| 69 | } |
| 70 | if result.reads is not None: |
| 71 | payload["reads"] = { |
| 72 | "regime": result.reads.regime, |
| 73 | "r1_github_main_sha": result.reads.r1_github_main_sha, |
| 74 | "r2_anchor_sha": result.reads.r2_anchor_sha, |
| 75 | "r3_canonical_main_sha": result.reads.r3_canonical_main_sha, |
| 76 | "r5_branch": result.reads.r5_branch, |
| 77 | "r5_dirty": result.reads.r5_dirty, |
| 78 | "merged_pr_count": len(result.reads.r4_merged_prs), |
| 79 | } |
| 80 | if result.plan is not None: |
| 81 | payload["plan"] = { |
| 82 | "patched_sections": list(result.plan.patched_sections), |
| 83 | "feature_branch": result.plan.feature_branch, |
| 84 | "realign_planned": result.plan.realign_planned, |
| 85 | "pr_url": result.plan.pr_url, |
| 86 | } |
| 87 | ctx.output.emit_json(payload) |
| 88 | |
| 89 | return result.exit_code |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
2 days ago