fix(work): import hashlib and wire heal subparser into main CLI

This commit is contained in:
operator
2026-10-09 23:13:43 +00:00
parent c3b4b1cd28
commit f75977ca6e
202 changed files with 4185 additions and 4142 deletions
+42 -27
View File
@@ -1223,23 +1223,41 @@ def act_chrome_errors(no_advance=False):
fail("SCAN_ERROR", "chrome-error-scan.sh failed", {"stderr": r.stderr})
_SUPER_CLI_MOD = None
def _super_cli_mod():
"""Lazily import super-cli.py once per process (amortized over calls)."""
global _SUPER_CLI_MOD
if _SUPER_CLI_MOD is None:
import importlib.util
spec = importlib.util.spec_from_file_location(
"super_cli_boxctl", str(BIN / "super-cli.py"))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
_SUPER_CLI_MOD = mod
return _SUPER_CLI_MOD
def act_dm_log(limit=50, agent=None):
if agent is not None and agent not in VALID_AGENTS:
fail("BAD_NODE", f"unknown agent: {agent}")
audit("dm-log", f"{agent or 'all'}/{limit}")
cmd = [sys.executable, str(BIN / "super-cli.py"), "dm", "log", "--json", "-n", str(limit)]
if agent:
cmd += ["--agent", agent]
r = subprocess.run(cmd, capture_output=True, text=True)
if r.returncode == 0:
try:
data = json.loads(r.stdout)
data["dms"] = data.get("entries", [])
print(json.dumps(data))
return
except Exception:
pass
fail("DM_LOG_ERROR", "failed to read dm log", {"stderr": r.stderr})
try:
import argparse
import io
from contextlib import redirect_stdout
sc = _super_cli_mod()
args = argparse.Namespace(n=limit, agent=agent, filter=None, json=True)
buf = io.StringIO()
with redirect_stdout(buf):
sc.cmd_dm_log(args)
data = json.loads(buf.getvalue())
data["dms"] = data.get("entries", [])
print(json.dumps(data))
return
except Exception as e:
fail("DM_LOG_ERROR", "failed to read dm log", {"stderr": str(e)})
def act_unread(agent=None):
@@ -1482,20 +1500,9 @@ def _policy_scan():
except OSError:
return None, {"error": f"cannot read {DM_LOG}"}
for line in lines:
line = line.strip()
if not line:
continue
try:
ev = json.loads(line)
except json.JSONDecodeError:
continue
tags = ev.get("tags")
if isinstance(tags, dict) and "allow_main_chat" in tags:
ts = ev.get("ts") or ""
if adoption_ts is None or ts < adoption_ts:
adoption_ts = ts
# Single parse pass: stash parsed events because the classification
# pass needs adoption_ts, a minimum over the whole file.
events = []
for line in lines:
line = line.strip()
if not line:
@@ -1506,6 +1513,14 @@ def _policy_scan():
except json.JSONDecodeError:
malformed += 1
continue
events.append(ev)
tags = ev.get("tags")
if isinstance(tags, dict) and "allow_main_chat" in tags:
ts = ev.get("ts") or ""
if adoption_ts is None or ts < adoption_ts:
adoption_ts = ts
for ev in events:
ts = ev.get("ts") or ""
if adoption_ts is not None and ts < adoption_ts:
if ev.get("type") == "sent" and ev.get("target") == "main":