Merge remote changes, keeping local version improvements
This commit is contained in:
110
scripts/macp
Executable file
110
scripts/macp
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
# 🤖 MACP Quick Command v2.1 (Unified Edition)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
AGENT_ID_FILE=".agent/current_agent"
|
||||
|
||||
resolve_agent_id() {
|
||||
if [ -n "${MACP_AGENT_ID:-}" ]; then
|
||||
echo "$MACP_AGENT_ID"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f "$AGENT_ID_FILE" ]; then
|
||||
cat "$AGENT_ID_FILE"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Error: MACP agent identity is not set. Export MACP_AGENT_ID or create .agent/current_agent." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
resolve_agent_name() {
|
||||
python3 - <<'PY2'
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
agent_id = os.environ.get("MACP_AGENT_ID", "").strip()
|
||||
if not agent_id:
|
||||
path = os.path.join(os.getcwd(), ".agent", "current_agent")
|
||||
if os.path.exists(path):
|
||||
with open(path, "r", encoding="utf-8") as handle:
|
||||
agent_id = handle.read().strip()
|
||||
|
||||
db_path = os.path.join(os.getcwd(), ".agent", "agent_hub.db")
|
||||
name = agent_id or "Agent"
|
||||
|
||||
if agent_id and os.path.exists(db_path):
|
||||
conn = sqlite3.connect(db_path)
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT name FROM agents WHERE id = ?", (agent_id,))
|
||||
row = cur.fetchone()
|
||||
conn.close()
|
||||
if row and row[0]:
|
||||
name = row[0]
|
||||
|
||||
sys.stdout.write(name)
|
||||
PY2
|
||||
}
|
||||
|
||||
AGENT_ID="$(resolve_agent_id)"
|
||||
export MACP_AGENT_ID="$AGENT_ID"
|
||||
AGENT_NAME="$(resolve_agent_name)"
|
||||
|
||||
CMD="${1:-}"
|
||||
if [ -z "$CMD" ]; then
|
||||
echo "Usage: ./scripts/macp [/status|/ping|/study|/broadcast|/summon|/handover|/note|/check|/resolve]" >&2
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
case "$CMD" in
|
||||
/study)
|
||||
TOPIC="$1"
|
||||
shift
|
||||
DESC="$*"
|
||||
if [ -n "$DESC" ]; then
|
||||
python3 scripts/agent_sync.py study "$AGENT_ID" "$TOPIC" --desc "$DESC"
|
||||
else
|
||||
python3 scripts/agent_sync.py study "$AGENT_ID" "$TOPIC"
|
||||
fi
|
||||
;;
|
||||
/broadcast)
|
||||
python3 scripts/agent_sync.py broadcast "$AGENT_ID" manual "$*"
|
||||
;;
|
||||
/summon)
|
||||
TO_AGENT="$1"
|
||||
shift
|
||||
python3 scripts/agent_sync.py assign "$AGENT_ID" "$TO_AGENT" "$*" --role worker --priority high
|
||||
;;
|
||||
/handover)
|
||||
TO_AGENT="$1"
|
||||
shift
|
||||
python3 scripts/agent_sync.py assign "$AGENT_ID" "$TO_AGENT" "$*" --role worker
|
||||
python3 scripts/agent_sync.py register "$AGENT_ID" "$AGENT_NAME" "Idle"
|
||||
;;
|
||||
/note)
|
||||
TOPIC="$1"
|
||||
shift
|
||||
python3 scripts/agent_sync.py note "$AGENT_ID" "$TOPIC" "$*" --type note
|
||||
;;
|
||||
/check)
|
||||
python3 scripts/agent_sync.py check
|
||||
;;
|
||||
/resolve)
|
||||
TOPIC="$1"
|
||||
shift
|
||||
python3 scripts/agent_sync.py resolve "$AGENT_ID" "$TOPIC" "$*"
|
||||
;;
|
||||
/ping)
|
||||
python3 scripts/agent_sync.py status | grep "\["
|
||||
;;
|
||||
/status)
|
||||
python3 scripts/agent_sync.py status
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ./scripts/macp [/status|/ping|/study|/broadcast|/summon|/handover|/note|/check|/resolve]"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user