agent-relay-plugin 0.4.33 → 0.4.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/poll-inbox.sh +25 -5
- package/hooks/relay-monitor.sh +1 -0
- package/hooks/set-status.sh +19 -0
- package/package.json +1 -1
package/hooks/poll-inbox.sh
CHANGED
|
@@ -25,6 +25,7 @@ fi
|
|
|
25
25
|
# PID file so session-start.sh can find and kill us on /clear or /compact.
|
|
26
26
|
pid_file="/tmp/agent-relay-poll-${AGENT_ID}.pid"
|
|
27
27
|
status_file="/tmp/agent-relay-status-${AGENT_ID}.state"
|
|
28
|
+
delivered_file="/tmp/agent-relay-delivered-${AGENT_ID}.queue"
|
|
28
29
|
project=$(basename "${PWD:-unknown}")
|
|
29
30
|
if [ -n "$CLAUDE_RIG_NAME" ]; then rig="$CLAUDE_RIG_NAME"
|
|
30
31
|
elif [ -n "$CLAUDE_CONFIG_DIR" ]; then rig=$(basename "$CLAUDE_CONFIG_DIR")
|
|
@@ -52,6 +53,27 @@ current_status() {
|
|
|
52
53
|
esac
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
deliver_message() {
|
|
57
|
+
local line="$1"
|
|
58
|
+
if [ "${AGENT_RELAY_CLAUDE_DELIVERY:-monitor}" = "tmux" ] && [ -n "${AGENT_RELAY_CLAUDE_TMUX_SESSION:-}" ] && command -v tmux >/dev/null 2>&1; then
|
|
59
|
+
if tmux set-buffer "$line" 2>/dev/null &&
|
|
60
|
+
tmux paste-buffer -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" 2>/dev/null &&
|
|
61
|
+
tmux send-keys -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" C-m 2>/dev/null; then
|
|
62
|
+
return 0
|
|
63
|
+
fi
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
printf '%s\n' "$line"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
mark_read_or_queue() {
|
|
70
|
+
local mid="$1"
|
|
71
|
+
curl -s -X PATCH "${RELAY_URL}/api/messages/${mid}" "${auth_header_args[@]}" \
|
|
72
|
+
-H 'Content-Type: application/json' \
|
|
73
|
+
-d "{\"readBy\":\"${AGENT_ID}\"}" > /dev/null 2>&1 ||
|
|
74
|
+
printf '%s\n' "$mid" >> "$delivered_file"
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
re_register() {
|
|
56
78
|
local machine rig project reg_code
|
|
57
79
|
machine=$(hostname)
|
|
@@ -170,11 +192,9 @@ while true; do
|
|
|
170
192
|
fi
|
|
171
193
|
fi
|
|
172
194
|
|
|
173
|
-
printf '%s' "$msg" | jq -r '(.meta.pairId // empty) as $pair | (if $pair != "" then " [pair:\($pair)]" else "" end) as $pairText | if .type == "system" then "⚠ SYSTEM [msg:\(.id)]\($pairText): \(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
-H 'Content-Type: application/json' \
|
|
177
|
-
-d "{\"readBy\":\"${AGENT_ID}\"}" > /dev/null 2>&1 || true
|
|
195
|
+
line=$(printf '%s' "$msg" | jq -r '(.meta.pairId // empty) as $pair | (if $pair != "" then " [pair:\($pair)]" else "" end) as $pairText | (.body | gsub("\r"; "\\r") | gsub("\n"; "\\n")) as $body | if .type == "system" then "⚠ SYSTEM [msg:\(.id)]\($pairText): \($body)" else "[msg:\(.id)]\($pairText) \(.from) → \(.to) | \(.subject // "(no subject)"): \($body)" end')
|
|
196
|
+
deliver_message "$line"
|
|
197
|
+
mark_read_or_queue "$mid"
|
|
178
198
|
done
|
|
179
199
|
since_id=$(echo "$msgs" | jq '[.[].id] | max')
|
|
180
200
|
fi
|
package/hooks/relay-monitor.sh
CHANGED
|
@@ -140,6 +140,7 @@ To check messages:
|
|
|
140
140
|
|
|
141
141
|
To mark read:
|
|
142
142
|
curl -s -X PATCH ${RELAY_URL}/api/messages/ID${auth_header_example} -H 'Content-Type: application/json' -d '{"readBy":"${agent_id}"}'
|
|
143
|
+
The inbox monitor marks read after it successfully delivers a message to Claude. The Stop hook retries any failed read acknowledgements.
|
|
143
144
|
|
|
144
145
|
To find agents by capability:
|
|
145
146
|
curl -s${auth_header_example} '${RELAY_URL}/api/agents/find?capability=review'
|
package/hooks/set-status.sh
CHANGED
|
@@ -36,4 +36,23 @@ curl -s -o /dev/null -X PATCH "${RELAY_URL}/api/agents/${agent_id}/status" "${au
|
|
|
36
36
|
-d "{\"status\":\"${status}\"}" \
|
|
37
37
|
2>/dev/null || true
|
|
38
38
|
|
|
39
|
+
if [ "$status" = "idle" ]; then
|
|
40
|
+
delivered_file="/tmp/agent-relay-delivered-${agent_id}.queue"
|
|
41
|
+
if [ -s "$delivered_file" ]; then
|
|
42
|
+
processing_file="${delivered_file}.$$"
|
|
43
|
+
if mv "$delivered_file" "$processing_file" 2>/dev/null; then
|
|
44
|
+
sort -n -u "$processing_file" | while IFS= read -r mid; do
|
|
45
|
+
case "$mid" in
|
|
46
|
+
''|*[!0-9]*) continue ;;
|
|
47
|
+
esac
|
|
48
|
+
curl -s -o /dev/null -X PATCH "${RELAY_URL}/api/messages/${mid}" "${auth_header_args[@]}" \
|
|
49
|
+
-H 'Content-Type: application/json' \
|
|
50
|
+
-d "{\"readBy\":\"${agent_id}\"}" \
|
|
51
|
+
2>/dev/null || printf '%s\n' "$mid" >> "$delivered_file"
|
|
52
|
+
done
|
|
53
|
+
rm -f "$processing_file"
|
|
54
|
+
fi
|
|
55
|
+
fi
|
|
56
|
+
fi
|
|
57
|
+
|
|
39
58
|
exit 0
|
package/package.json
CHANGED