feat(reset): multi-agent-mux-reset skill - reset.sh, SKILL.md, packaging (#78)
This commit is contained in:
1 parent
ca2532307f
commit
fb1895030f
12 files changed
+1248
-58
No files matched your search
@@ -13,6 +13,8 @@ import datetime
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -38,8 +40,50 @@ def spec_path(workspace: str) -> str:
|
||||
return os.path.join(_real(workspace), SPEC_REL)
|
||||
|
||||
|
||||
def _state() -> dict:
|
||||
return json.loads(os.environ.get("MAM_STATE_JSON") or "{}") or {}
|
||||
def _state(workspace: str = "") -> dict:
|
||||
raw = os.environ.get("MAM_STATE_JSON")
|
||||
if raw is not None:
|
||||
return json.loads(raw or "{}") or {}
|
||||
yaml_path = os.environ.get("AGENT_SESSIONS_YAML") or (
|
||||
os.path.join(_real(workspace), ".mam", "agent-sessions.yaml") if workspace else ""
|
||||
)
|
||||
if not yaml_path:
|
||||
return {}
|
||||
db_path = os.path.splitext(yaml_path)[0] + ".db"
|
||||
if os.path.exists(db_path):
|
||||
tmp_dir = tempfile.mkdtemp(prefix="mam-reset-ro.")
|
||||
try:
|
||||
tmp_db = os.path.join(tmp_dir, "agent-sessions.db")
|
||||
shutil.copyfile(db_path, tmp_db)
|
||||
for suf in ("-wal", "-shm"):
|
||||
if os.path.exists(db_path + suf):
|
||||
shutil.copyfile(db_path + suf, tmp_db + suf)
|
||||
conn = sqlite3.connect(tmp_db, timeout=60.0)
|
||||
try:
|
||||
d: dict = {}
|
||||
row = conn.execute("SELECT data FROM state WHERE id=1").fetchone()
|
||||
if row:
|
||||
d = json.loads(row[0])
|
||||
cursor = conn.execute("SELECT data FROM sessions")
|
||||
d["herdr_sessions"] = [json.loads(r[0]) for r in cursor.fetchall()]
|
||||
return d
|
||||
finally:
|
||||
conn.close()
|
||||
except Exception as exc:
|
||||
raise ValueError("the registry %s cannot be read (%s); fix it first" % (yaml_path, exc))
|
||||
finally:
|
||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||
if os.path.exists(yaml_path):
|
||||
try:
|
||||
import yaml
|
||||
with open(yaml_path, encoding="utf-8") as fh:
|
||||
data = yaml.safe_load(fh)
|
||||
if data is not None and not isinstance(data, dict):
|
||||
raise ValueError("top-level YAML is not a mapping")
|
||||
return data or {}
|
||||
except Exception as exc:
|
||||
raise ValueError("the registry %s cannot be read (%s); fix it first" % (yaml_path, exc))
|
||||
return {}
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- D2: target selection
|
||||
@@ -638,8 +682,13 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
return 0
|
||||
|
||||
try:
|
||||
state = _state()
|
||||
state = _state(ws)
|
||||
except ValueError as exc:
|
||||
if a.cmd == "dry-run":
|
||||
refs = list(a.refusal or []) + [str(exc)]
|
||||
out, rc = format_dry_run(ws, {}, os.environ, extra_refusals=refs)
|
||||
print(out)
|
||||
return rc
|
||||
if a.cmd == "precheck":
|
||||
print("registry: cannot parse MAM_STATE_JSON (%s)" % exc)
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user