agent-relay-plugin 0.4.33 → 0.4.35
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 +39 -8
- 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,28 @@ 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 send-keys -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" -l "$line" 2>/dev/null &&
|
|
60
|
+
tmux send-keys -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" C-m 2>/dev/null; then
|
|
61
|
+
return 0
|
|
62
|
+
fi
|
|
63
|
+
echo "warn: tmux delivery failed for ${AGENT_RELAY_CLAUDE_TMUX_SESSION}" >&2
|
|
64
|
+
return 1
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
printf '%s\n' "$line"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
mark_read_or_queue() {
|
|
71
|
+
local mid="$1"
|
|
72
|
+
curl -s -X PATCH "${RELAY_URL}/api/messages/${mid}" "${auth_header_args[@]}" \
|
|
73
|
+
-H 'Content-Type: application/json' \
|
|
74
|
+
-d "{\"readBy\":\"${AGENT_ID}\"}" > /dev/null 2>&1 ||
|
|
75
|
+
printf '%s\n' "$mid" >> "$delivered_file"
|
|
76
|
+
}
|
|
77
|
+
|
|
55
78
|
re_register() {
|
|
56
79
|
local machine rig project reg_code
|
|
57
80
|
machine=$(hostname)
|
|
@@ -153,7 +176,8 @@ while true; do
|
|
|
153
176
|
|
|
154
177
|
count=$(echo "$msgs" | jq 'length' 2>/dev/null || echo 0)
|
|
155
178
|
if [ "$count" -gt 0 ] 2>/dev/null && [ "$count" != "0" ]; then
|
|
156
|
-
|
|
179
|
+
delivery_failed=false
|
|
180
|
+
while IFS= read -r msg; do
|
|
157
181
|
mid=$(printf '%s' "$msg" | jq -r '.id')
|
|
158
182
|
claimable=$(printf '%s' "$msg" | jq -r '.claimable // false')
|
|
159
183
|
if [ "$(ar_message_matches_channels "$msg")" != "true" ]; then
|
|
@@ -170,13 +194,20 @@ while true; do
|
|
|
170
194
|
fi
|
|
171
195
|
fi
|
|
172
196
|
|
|
173
|
-
printf '%s' "$msg" | jq -r '(.meta.pairId //
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
if ! line=$(printf '%s' "$msg" | jq -r '(.meta.pairId // "") 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') || [ -z "$line" ]; then
|
|
198
|
+
echo "warn: failed to format relay message ${mid}" >&2
|
|
199
|
+
delivery_failed=true
|
|
200
|
+
continue
|
|
201
|
+
fi
|
|
202
|
+
if deliver_message "$line"; then
|
|
203
|
+
mark_read_or_queue "$mid"
|
|
204
|
+
else
|
|
205
|
+
delivery_failed=true
|
|
206
|
+
fi
|
|
207
|
+
done < <(echo "$msgs" | jq -c '.[]')
|
|
208
|
+
if [ "$delivery_failed" = "false" ]; then
|
|
209
|
+
since_id=$(echo "$msgs" | jq '[.[].id] | max')
|
|
210
|
+
fi
|
|
180
211
|
fi
|
|
181
212
|
|
|
182
213
|
sleep "$INTERVAL"
|
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