Migrated error()/warning() calls across 10 branches to use CLI display API which routes to stderr. 48 files modified across ai_mail, api, backup, daemon, flow, memory, prax, seedgo, spawn, trigger. Seedgo stderr_routing standard created (24th standard) with full-file scanning. System average 49% → 69%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
132 lines
4.2 KiB
Python
132 lines
4.2 KiB
Python
# =================== AIPass ====================
|
|
# Name: sync_registry.py
|
|
# Description: Registry repair — thin CLI layer for registry synchronization
|
|
# Version: 1.1.0
|
|
# Created: 2026-03-07
|
|
# Modified: 2026-03-07
|
|
# =============================================
|
|
|
|
"""Registry synchronization for branch lifecycle management.
|
|
|
|
Thin CLI module that parses arguments and delegates to the sync handler.
|
|
All implementation logic lives in apps/handlers/sync_registry_ops.py.
|
|
"""
|
|
|
|
from aipass.prax import logger
|
|
# CLI service: from cli.apps.modules import console (via aipass namespace)
|
|
from aipass.cli.apps.modules import console, error, warning
|
|
|
|
from aipass.spawn.apps.handlers.sync_registry_ops import sync_registry
|
|
|
|
|
|
def print_introspection():
|
|
"""Display module introspection info."""
|
|
console.print()
|
|
console.print("sync_registry Module")
|
|
console.print("Registry repair — detect and fix mismatches between AIPASS_REGISTRY and filesystem")
|
|
console.print()
|
|
console.print("Connected Handlers:")
|
|
console.print(" handlers/")
|
|
console.print(" - sync_registry_ops.py (sync_registry — scan filesystem, detect stale/unregistered, auto-repair)")
|
|
console.print()
|
|
|
|
|
|
# =============================================================================
|
|
# DRONE ROUTING
|
|
# =============================================================================
|
|
|
|
def handle_command(command: str, args: list) -> bool:
|
|
"""Handle commands routed by the entry point.
|
|
|
|
Args:
|
|
command: The command string (e.g. "sync-registry")
|
|
args: List of arguments for the command
|
|
|
|
Returns:
|
|
True if command was handled, False otherwise.
|
|
"""
|
|
if command == "sync-registry":
|
|
return handle_sync_registry(args) == 0
|
|
return False
|
|
|
|
|
|
# =============================================================================
|
|
# PUBLIC API
|
|
# =============================================================================
|
|
|
|
def handle_sync_registry(args: list[str]) -> int:
|
|
"""Parse args and execute sync.
|
|
|
|
Args patterns:
|
|
[] -> report only (show mismatches)
|
|
["--fix"] -> auto-repair mismatches
|
|
|
|
Returns exit code (0=success, 1=failure).
|
|
"""
|
|
if args and args[0] in ["--help", "-h"]:
|
|
warning("Usage: drone @spawn sync-registry [--fix]")
|
|
console.print()
|
|
console.print(" [green](no args)[/green] Report mismatches between registry and filesystem")
|
|
console.print(" [green]--fix[/green] Auto-repair: remove stale, add unregistered")
|
|
return 0
|
|
|
|
fix = "--fix" in args
|
|
|
|
try:
|
|
result = sync_registry(fix=fix)
|
|
except Exception as exc:
|
|
logger.error(f"[sync-registry] Unexpected error: {exc}")
|
|
error(str(exc))
|
|
return 1
|
|
|
|
_print_summary(result)
|
|
return 0
|
|
|
|
|
|
# =============================================================================
|
|
# OUTPUT HELPERS
|
|
# =============================================================================
|
|
|
|
def _print_summary(result: dict) -> None:
|
|
"""Print a rich summary of the sync operation."""
|
|
stale = result.get("stale", [])
|
|
unregistered = result.get("unregistered", [])
|
|
healthy = result.get("healthy", [])
|
|
fixed = result.get("fixed", False)
|
|
|
|
console.print()
|
|
console.print("[bold]Registry Sync Report[/bold]")
|
|
console.print()
|
|
|
|
# Healthy
|
|
if healthy:
|
|
console.print(f" [green]Healthy ({len(healthy)}):[/green]")
|
|
for name in sorted(healthy):
|
|
console.print(f" {name}")
|
|
|
|
# Stale
|
|
if stale:
|
|
error(f"Stale ({len(stale)}): registered but missing/invalid")
|
|
for name in sorted(stale):
|
|
console.print(f" {name}")
|
|
else:
|
|
console.print(" [green]No stale entries[/green]")
|
|
|
|
# Unregistered
|
|
if unregistered:
|
|
warning(f"Unregistered ({len(unregistered)}): on disk but not in registry")
|
|
for name in sorted(unregistered):
|
|
console.print(f" {name}")
|
|
else:
|
|
console.print(" [green]No unregistered branches[/green]")
|
|
|
|
# Fix status
|
|
if fixed:
|
|
console.print()
|
|
console.print(" [green]Registry has been repaired.[/green]")
|
|
elif stale or unregistered:
|
|
console.print()
|
|
console.print(" [dim]Run with --fix to auto-repair.[/dim]")
|
|
|
|
console.print()
|