feat(kpi): add autonomous worker auto-spawn engine and watchdog reconciliation

This commit is contained in:
operator
2026-10-06 23:03:52 +00:00
parent 02a2189773
commit 0c6d2235ab
5 changed files with 244 additions and 13 deletions
+26
View File
@@ -1525,6 +1525,28 @@ def cmd_kpi(args):
else:
print(c_red(f"✘ Failed to spawn worker: {res.get('error')}"), file=sys.stderr)
sys.exit(1)
elif act == "auto-spawn":
nodes = [args.node] if getattr(args, "node", None) else None
results = kpi.auto_spawn_workers(nodes=nodes, dry_run=getattr(args, "dry_run", False))
if as_json:
print(json.dumps(results, indent=2))
return
dry_label = c_yellow(" (DRY-RUN)") if getattr(args, "dry_run", False) else ""
print("\n" + c_bold(f"=== AUTO-SPAWN WORKER RECONCILIATION{dry_label} ==="))
for r in results:
n = r.get("node")
action = r.get("action")
if action == "spawned":
print(c_green(f" ✔ @{n:<5} : SPAWNED session '{r.get('session')}' ({r.get('work_type')}: {r.get('work_name')})"))
elif action == "would_spawn":
print(c_cyan(f" ? @{n:<5} : WOULD SPAWN session '{r.get('session')}' ({r.get('work_type')}: {r.get('work_name')})"))
elif action == "skip":
print(c_dim(f" - @{n:<5} : SKIP ({r.get('reason')})"))
elif action == "idle":
print(c_dim(f" - @{n:<5} : IDLE ({r.get('reason')})"))
elif action == "error":
print(c_red(f" ✘ @{n:<5} : ERROR ({r.get('error')})"))
print()
# ---------------------------------------------------------------------------
@@ -5449,6 +5471,10 @@ def build_parser():
p_kpi_spawn.add_argument("session", help="Session label")
p_kpi_spawn.add_argument("worker_command", help="Command to run in background")
p_kpi_autospawn = kpi_sub.add_parser("auto-spawn", parents=[common], help="Reconcile idle agents and auto-spawn background tmux workers")
p_kpi_autospawn.add_argument("--node", choices=VALID_NODES, default=None, help="Filter by node")
p_kpi_autospawn.add_argument("--dry-run", action="store_true", help="Observe and report what would be spawned without executing")
# Domain: CHROMEBOX
p_chromebox = subparsers.add_parser("chromebox", parents=[common], help="Agent browser settings-menu toggles (chromebox RPA)")