Add main-loop enable/disable per-agent toggle
- self_main_loop.py: 'enabled' map in config (default all True); do_check skips disabled agents (marks disabled:true in results); new enable/disable actions with optional --agent. - box-ctl.py: main-loop enable|disable [--agent <name>] actions, USAGE updated. Check skips disabled agents so the loop can be toggled per Chromebox without stopping the systemd timer. Session: sidechat/chromebox-ops
This commit is contained in:
+40
-2
@@ -93,11 +93,16 @@ def get_config(st):
|
||||
agents = [a for a in agents if a in DEFAULT_AGENTS]
|
||||
prompt = dict(DEFAULT_PROMPT_SIDECHAT)
|
||||
prompt.update(cfg.get("prompt_sidechat") or {})
|
||||
enabled = dict(cfg.get("enabled") or {})
|
||||
# Default any unlisted agent to enabled.
|
||||
for a in agents:
|
||||
enabled.setdefault(a, True)
|
||||
return {
|
||||
"agents": agents or list(DEFAULT_AGENTS),
|
||||
"prompt_sidechat": prompt,
|
||||
"sender": cfg.get("sender") or DEFAULT_SENDER,
|
||||
"read_limit": int(cfg.get("read_limit") or READ_LIMIT),
|
||||
"enabled": enabled,
|
||||
}
|
||||
|
||||
|
||||
@@ -180,11 +185,15 @@ def do_check(only_agent=None):
|
||||
return {"ok": False, "error": "unknown agent: %s" % only_agent}
|
||||
|
||||
agents_state = st.get("agents") or {}
|
||||
enabled = cfg.get("enabled") or {}
|
||||
results = {}
|
||||
prompted = 0
|
||||
errors = 0
|
||||
|
||||
for agent in agents:
|
||||
if not enabled.get(agent, True):
|
||||
results[agent] = {"ok": True, "new": 0, "disabled": True}
|
||||
continue
|
||||
wm = agents_state.get(agent) or {}
|
||||
ok, payload = read_main_chat(agent, cfg["read_limit"])
|
||||
if not ok:
|
||||
@@ -231,19 +240,40 @@ def do_check(only_agent=None):
|
||||
st["config"] = {"agents": cfg["agents"],
|
||||
"prompt_sidechat": cfg["prompt_sidechat"],
|
||||
"sender": cfg["sender"],
|
||||
"read_limit": cfg["read_limit"]}
|
||||
"read_limit": cfg["read_limit"],
|
||||
"enabled": dict(cfg.get("enabled") or
|
||||
{a: True for a in cfg["agents"]})}
|
||||
save_state(st)
|
||||
return {"ok": errors == 0, "prompted": prompted, "errors": errors,
|
||||
"new_total": sum(r.get("new", 0) for r in results.values()),
|
||||
"agents": results}
|
||||
|
||||
|
||||
def _set_enabled(agent, value):
|
||||
"""Enable/disable the loop for one agent (or all if agent is None)."""
|
||||
st = load_state()
|
||||
cfg = st.get("config") or {}
|
||||
agents = cfg.get("agents") or list(DEFAULT_AGENTS)
|
||||
agents = [a for a in agents if a in DEFAULT_AGENTS] or list(DEFAULT_AGENTS)
|
||||
if agent and agent not in DEFAULT_AGENTS:
|
||||
return {"ok": False, "error": "unknown agent: %s" % agent}
|
||||
enabled = dict(cfg.get("enabled") or {})
|
||||
targets = [agent] if agent else agents
|
||||
for a in targets:
|
||||
enabled[a] = value
|
||||
cfg["enabled"] = enabled
|
||||
st["config"] = cfg
|
||||
save_state(st)
|
||||
return {"ok": True, "enabled": {a: enabled.get(a, True) for a in targets}}
|
||||
|
||||
|
||||
def do_status():
|
||||
st = load_state()
|
||||
cfg = get_config(st)
|
||||
agents_state = st.get("agents") or {}
|
||||
return {"ok": True,
|
||||
"config": cfg,
|
||||
"enabled": cfg.get("enabled") or {},
|
||||
"watermark": agents_state,
|
||||
"last_run": st.get("last_run"),
|
||||
"last_result": st.get("last_result")}
|
||||
@@ -261,8 +291,16 @@ def main(argv):
|
||||
print(json.dumps(do_status()))
|
||||
return 0
|
||||
|
||||
if action == "enable":
|
||||
print(json.dumps(_set_enabled(only_agent, True)))
|
||||
return 0
|
||||
|
||||
if action == "disable":
|
||||
print(json.dumps(_set_enabled(only_agent, False)))
|
||||
return 0
|
||||
|
||||
if action != "check":
|
||||
print(json.dumps({"ok": False, "error": "usage: check|status [--agent X]"}))
|
||||
print(json.dumps({"ok": False, "error": "usage: check|status|enable|disable [--agent X]"}))
|
||||
return 2
|
||||
|
||||
# Overlap guard: timer may fire while a slow run is still going.
|
||||
|
||||
Reference in New Issue
Block a user