Initial import of watchdog-discord-route skill
This commit is contained in:
75
scripts/owner_report_consumer.py
Normal file
75
scripts/owner_report_consumer.py
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Minimal owner-report consumer.
|
||||
|
||||
Reads a pending owner report markdown file with simple front-matter-like key/value
|
||||
lines and emits normalized JSON to stdout.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
OWNER_REPORT_ROOT = Path.home() / ".clawteam" / "owner-reports"
|
||||
PENDING_DIR = OWNER_REPORT_ROOT / "pending"
|
||||
|
||||
|
||||
def parse_pending_report(path: Path) -> dict:
|
||||
raw = path.read_text(encoding="utf-8")
|
||||
data: dict[str, str] = {}
|
||||
for line in raw.splitlines():
|
||||
line = line.strip()
|
||||
if not line or ":" not in line:
|
||||
continue
|
||||
key, value = line.split(":", 1)
|
||||
data[key.strip()] = value.strip()
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"path": str(path),
|
||||
"filename": path.name,
|
||||
"report_id": data.get("report_id") or path.stem,
|
||||
"team": data.get("team"),
|
||||
"source": data.get("source"),
|
||||
"report_kind": data.get("report_kind") or "checkpoint",
|
||||
"created_at": data.get("created_at"),
|
||||
"message": _unquote(data.get("message", "")),
|
||||
"raw": data,
|
||||
}
|
||||
|
||||
|
||||
def _unquote(value: str) -> str:
|
||||
value = value.strip()
|
||||
if len(value) >= 2 and value[0] == '"' and value[-1] == '"':
|
||||
return value[1:-1]
|
||||
return value
|
||||
|
||||
|
||||
def resolve_input(name_or_path: str) -> Path:
|
||||
p = Path(name_or_path).expanduser()
|
||||
if p.exists():
|
||||
return p
|
||||
candidate = PENDING_DIR / name_or_path
|
||||
if candidate.exists():
|
||||
return candidate
|
||||
if not candidate.suffix:
|
||||
md_candidate = candidate.with_suffix(".md")
|
||||
if md_candidate.exists():
|
||||
return md_candidate
|
||||
raise FileNotFoundError(f"pending report not found: {name_or_path}")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description="Emit JSON for a pending owner report")
|
||||
ap.add_argument("report", help="Pending report path, filename, or report_id")
|
||||
args = ap.parse_args()
|
||||
|
||||
path = resolve_input(args.report)
|
||||
payload = parse_pending_report(path)
|
||||
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user