handover_compact.py
python
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠ breaking
22 hours ago
| 1 | """``ok handover-compact`` command (§LT.6).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 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 is_within_repo, resolve_config_path, resolve_repo_root |
| 12 | from cli.sanitize import format_config_error |
| 13 | from tools.handover_compact import compact_handover_change_log |
| 14 | |
| 15 | |
| 16 | def run_handover_compact_command(args: Namespace, ctx: CliContext) -> int: |
| 17 | """Archive old handover change-log bullets.""" |
| 18 | if args.write and args.dry_run: |
| 19 | ctx.output.error("handover-compact: cannot use --write and --dry-run together") |
| 20 | return 2 |
| 21 | |
| 22 | keep = args.keep |
| 23 | if keep < 5: |
| 24 | ctx.output.error("handover-compact: --keep must be an integer >= 5") |
| 25 | return 2 |
| 26 | |
| 27 | repo_root = resolve_repo_root(cwd=ctx.cwd, repo_arg=args.repo, command="handover-compact") |
| 28 | config_path = resolve_config_path(repo_root, args.config) |
| 29 | if not is_within_repo(repo_root, config_path): |
| 30 | ctx.output.error("refused: config path outside repo root") |
| 31 | return 4 |
| 32 | |
| 33 | try: |
| 34 | config = load_config(config_path) |
| 35 | except ConfigError as exc: |
| 36 | ctx.output.error(format_config_error(exc, repo_root)) |
| 37 | return 2 |
| 38 | |
| 39 | write = bool(args.write) |
| 40 | report = compact_handover_change_log( |
| 41 | config, |
| 42 | repo_root, |
| 43 | keep=keep, |
| 44 | write=write, |
| 45 | lane=getattr(args, "lane", None), |
| 46 | ) |
| 47 | |
| 48 | if not report.ok: |
| 49 | ctx.output.error(f"handover-compact: {report.reason}") |
| 50 | return 2 |
| 51 | |
| 52 | if ctx.output.json_mode: |
| 53 | ctx.output.emit_json( |
| 54 | { |
| 55 | "ok": True, |
| 56 | "compacted": report.compacted, |
| 57 | "keep": report.keep, |
| 58 | "archive": report.archive, |
| 59 | "wrote": report.wrote, |
| 60 | } |
| 61 | ) |
| 62 | else: |
| 63 | ctx.output.emit( |
| 64 | f"handover-compact: compacted={report.compacted} keep={report.keep} " |
| 65 | f"archive={report.archive}" |
| 66 | ) |
| 67 | |
| 68 | return 0 |
File History
1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠
22 hours ago