feat: add MACP event bridge — watcher, webhook, Discord formatter
This commit is contained in:
@@ -16,6 +16,7 @@ Usage:
|
||||
mosaic macp status [--task-id TASK-001]
|
||||
mosaic macp drain
|
||||
mosaic macp history [--task-id TASK-001]
|
||||
mosaic macp watch [--webhook] [--once]
|
||||
USAGE
|
||||
}
|
||||
|
||||
@@ -193,6 +194,71 @@ for line in events_path.read_text(encoding="utf-8").splitlines():
|
||||
PY
|
||||
}
|
||||
|
||||
watch_events() {
|
||||
require_repo
|
||||
local webhook_enabled="false"
|
||||
local run_once="false"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--webhook) webhook_enabled="true"; shift ;;
|
||||
--once) run_once="true"; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "[mosaic-macp] unknown watch option: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
python3 - "$repo_root" "$config_path" "$events_path" "$orch_dir/event_cursor.json" "$webhook_enabled" "$run_once" <<'PY'
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
repo_root = pathlib.Path(sys.argv[1]).resolve()
|
||||
config_path = pathlib.Path(sys.argv[2]).resolve()
|
||||
events_path = pathlib.Path(sys.argv[3]).resolve()
|
||||
cursor_path = pathlib.Path(sys.argv[4]).resolve()
|
||||
webhook_flag = sys.argv[5].lower() == "true"
|
||||
run_once = sys.argv[6].lower() == "true"
|
||||
|
||||
events_dir = repo_root / "tools" / "orchestrator-matrix" / "events"
|
||||
if str(events_dir) not in sys.path:
|
||||
sys.path.insert(0, str(events_dir))
|
||||
|
||||
from discord_formatter import format_event
|
||||
from event_watcher import EventWatcher
|
||||
from webhook_adapter import create_webhook_callback
|
||||
|
||||
config = {}
|
||||
if config_path.exists():
|
||||
config = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
|
||||
macp = dict(config.get("macp") or {})
|
||||
watcher = EventWatcher(
|
||||
events_path=events_path,
|
||||
cursor_path=cursor_path,
|
||||
poll_interval=float(macp.get("watch_poll_interval_seconds") or 2.0),
|
||||
)
|
||||
|
||||
def print_callback(event: dict) -> None:
|
||||
rendered = format_event(event)
|
||||
if rendered:
|
||||
print(rendered)
|
||||
|
||||
watcher.on([], print_callback)
|
||||
|
||||
webhook_config = dict(macp.get("webhook") or {})
|
||||
if webhook_flag and bool(webhook_config.get("enabled", False)):
|
||||
watcher.on(list(webhook_config.get("event_filter") or []), create_webhook_callback(config))
|
||||
elif webhook_flag:
|
||||
print("[mosaic-macp] webhook requested but disabled in config", file=sys.stderr)
|
||||
|
||||
if run_once:
|
||||
processed = watcher.poll_once()
|
||||
print(f"[mosaic-macp] processed_events={len(processed)}")
|
||||
else:
|
||||
watcher.run()
|
||||
PY
|
||||
}
|
||||
|
||||
subcommand="${1:-help}"
|
||||
if [[ $# -gt 0 ]]; then
|
||||
shift
|
||||
@@ -203,6 +269,7 @@ case "$subcommand" in
|
||||
status) status_tasks "$@" ;;
|
||||
drain) drain_tasks "$@" ;;
|
||||
history) history_tasks "$@" ;;
|
||||
watch) watch_events "$@" ;;
|
||||
help|-h|--help|"") usage ;;
|
||||
*)
|
||||
echo "[mosaic-macp] unknown subcommand: $subcommand" >&2
|
||||
|
||||
Reference in New Issue
Block a user