agent-relay-plugin 0.4.34 → 0.4.39
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 +19 -8
- package/hooks/profile-lib.sh +2 -2
- package/hooks/relay-monitor.sh +3 -1
- package/hooks/session-end.sh +23 -16
- package/hooks/set-status.sh +8 -1
- package/package.json +1 -1
package/hooks/poll-inbox.sh
CHANGED
|
@@ -56,11 +56,12 @@ current_status() {
|
|
|
56
56
|
deliver_message() {
|
|
57
57
|
local line="$1"
|
|
58
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
|
|
60
|
-
tmux paste-buffer -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" 2>/dev/null &&
|
|
59
|
+
if tmux send-keys -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" -l "$line" 2>/dev/null &&
|
|
61
60
|
tmux send-keys -t "$AGENT_RELAY_CLAUDE_TMUX_SESSION" C-m 2>/dev/null; then
|
|
62
61
|
return 0
|
|
63
62
|
fi
|
|
63
|
+
echo "warn: tmux delivery failed for ${AGENT_RELAY_CLAUDE_TMUX_SESSION}" >&2
|
|
64
|
+
return 1
|
|
64
65
|
fi
|
|
65
66
|
|
|
66
67
|
printf '%s\n' "$line"
|
|
@@ -175,7 +176,8 @@ while true; do
|
|
|
175
176
|
|
|
176
177
|
count=$(echo "$msgs" | jq 'length' 2>/dev/null || echo 0)
|
|
177
178
|
if [ "$count" -gt 0 ] 2>/dev/null && [ "$count" != "0" ]; then
|
|
178
|
-
|
|
179
|
+
delivery_failed=false
|
|
180
|
+
while IFS= read -r msg; do
|
|
179
181
|
mid=$(printf '%s' "$msg" | jq -r '.id')
|
|
180
182
|
claimable=$(printf '%s' "$msg" | jq -r '.claimable // false')
|
|
181
183
|
if [ "$(ar_message_matches_channels "$msg")" != "true" ]; then
|
|
@@ -192,11 +194,20 @@ while true; do
|
|
|
192
194
|
fi
|
|
193
195
|
fi
|
|
194
196
|
|
|
195
|
-
line=$(printf '%s' "$msg" | jq -r '(.meta.pairId //
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
|
200
211
|
fi
|
|
201
212
|
|
|
202
213
|
sleep "$INTERVAL"
|
package/hooks/profile-lib.sh
CHANGED
|
@@ -6,12 +6,12 @@ ar_csv_json() {
|
|
|
6
6
|
|
|
7
7
|
ar_profile_value() {
|
|
8
8
|
local key="$1"
|
|
9
|
-
printf '%s' "${AR_PROFILE_JSON
|
|
9
|
+
printf '%s' "${AR_PROFILE_JSON}" | jq -r --arg key "$key" '.[$key] // empty | if type == "string" then gsub("^\\s+|\\s+$"; "") else empty end'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
ar_profile_array() {
|
|
13
13
|
local key="$1"
|
|
14
|
-
printf '%s' "${AR_PROFILE_JSON
|
|
14
|
+
printf '%s' "${AR_PROFILE_JSON}" | jq -c --arg key "$key" 'if (.[$key] | type) == "array" then .[$key] | map(select(type == "string") | gsub("^\\s+|\\s+$"; "") | select(length > 0)) | reduce .[] as $x ([]; if index($x) then . else . + [$x] end) else [] end'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
ar_init_profile() {
|
package/hooks/relay-monitor.sh
CHANGED
|
@@ -40,6 +40,8 @@ ar_init_profile "claude" "$rig" "$project"
|
|
|
40
40
|
session_key="${CLAUDE_CODE_SESSION_ID:-$PPID}"
|
|
41
41
|
if command -v shasum >/dev/null 2>&1; then
|
|
42
42
|
short_pid=$(printf '%s' "$session_key" | shasum -a 1 | head -c 6)
|
|
43
|
+
elif command -v sha1sum >/dev/null 2>&1; then
|
|
44
|
+
short_pid=$(printf '%s' "$session_key" | sha1sum | head -c 6)
|
|
43
45
|
else
|
|
44
46
|
short_pid=$(printf '%s' "$session_key" | md5sum | head -c 6)
|
|
45
47
|
fi
|
|
@@ -175,7 +177,7 @@ if [ -n "$version_warning" ]; then
|
|
|
175
177
|
fi
|
|
176
178
|
|
|
177
179
|
# --- Check for unread messages ---
|
|
178
|
-
unread=$(curl -s "${auth_header_args[@]}" "${RELAY_URL}/api/messages?for=${agent_id}&unread=true" 2>/dev/null)
|
|
180
|
+
unread=$(curl -s --fail "${auth_header_args[@]}" "${RELAY_URL}/api/messages?for=${agent_id}&unread=true" 2>/dev/null)
|
|
179
181
|
unread_count=$(echo "$unread" | jq 'length' 2>/dev/null || echo "0")
|
|
180
182
|
if [ "$unread_count" -gt 0 ] 2>/dev/null && [ "$unread_count" != "0" ]; then
|
|
181
183
|
echo ""
|
package/hooks/session-end.sh
CHANGED
|
@@ -11,28 +11,35 @@ auth_header_args=()
|
|
|
11
11
|
if [ -n "${AGENT_RELAY_TOKEN:-}" ]; then
|
|
12
12
|
auth_header_args=(-H "X-Agent-Relay-Token: ${AGENT_RELAY_TOKEN}")
|
|
13
13
|
fi
|
|
14
|
-
|
|
14
|
+
input=$(cat)
|
|
15
|
+
session_key="${CLAUDE_CODE_SESSION_ID:-}"
|
|
16
|
+
if [ -z "$session_key" ] && [ -n "$input" ]; then
|
|
17
|
+
session_key=$(printf '%s' "$input" | jq -r '.session_id // empty' 2>/dev/null)
|
|
18
|
+
fi
|
|
19
|
+
if [ -z "$session_key" ]; then
|
|
20
|
+
exit 0
|
|
21
|
+
fi
|
|
15
22
|
instance_state="/tmp/agent-relay-instance-${session_key}.state"
|
|
16
23
|
|
|
17
24
|
if [ -f "$instance_state" ]; then
|
|
18
25
|
agent_id=$(head -1 "$instance_state" 2>/dev/null)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
rm -f "$poll_pid_file"
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
if [ -n "${agent_id:-}" ]; then
|
|
29
|
+
poll_pid_file="/tmp/agent-relay-poll-${agent_id}.pid"
|
|
30
|
+
if [ -f "$poll_pid_file" ]; then
|
|
31
|
+
poll_pid=$(cat "$poll_pid_file" 2>/dev/null)
|
|
32
|
+
if [ -n "$poll_pid" ] && kill -0 "$poll_pid" 2>/dev/null; then
|
|
33
|
+
kill "$poll_pid" 2>/dev/null
|
|
28
34
|
fi
|
|
29
|
-
|
|
30
|
-
curl -s -X PATCH "${RELAY_URL}/api/agents/${agent_id}/status" "${auth_header_args[@]}" \
|
|
31
|
-
-H 'Content-Type: application/json' \
|
|
32
|
-
-d '{"status":"offline"}' \
|
|
33
|
-
> /dev/null 2>&1 &
|
|
35
|
+
rm -f "$poll_pid_file"
|
|
34
36
|
fi
|
|
35
|
-
|
|
37
|
+
printf 'offline\n' > "/tmp/agent-relay-status-${agent_id}.state"
|
|
38
|
+
curl -s -X PATCH "${RELAY_URL}/api/agents/${agent_id}/status" "${auth_header_args[@]}" \
|
|
39
|
+
-H 'Content-Type: application/json' \
|
|
40
|
+
-d '{"status":"offline"}' \
|
|
41
|
+
> /dev/null 2>&1 &
|
|
42
|
+
[ -n "$instance_state" ] && [ -f "$instance_state" ] && rm -f "$instance_state"
|
|
36
43
|
fi
|
|
37
44
|
|
|
38
45
|
exit 0
|
package/hooks/set-status.sh
CHANGED
|
@@ -17,7 +17,14 @@ auth_header_args=()
|
|
|
17
17
|
if [ -n "${AGENT_RELAY_TOKEN:-}" ]; then
|
|
18
18
|
auth_header_args=(-H "X-Agent-Relay-Token: ${AGENT_RELAY_TOKEN}")
|
|
19
19
|
fi
|
|
20
|
-
|
|
20
|
+
input=$(cat)
|
|
21
|
+
session_key="${CLAUDE_CODE_SESSION_ID:-}"
|
|
22
|
+
if [ -z "$session_key" ] && [ -n "$input" ]; then
|
|
23
|
+
session_key=$(printf '%s' "$input" | jq -r '.session_id // empty' 2>/dev/null)
|
|
24
|
+
fi
|
|
25
|
+
if [ -z "$session_key" ]; then
|
|
26
|
+
exit 0
|
|
27
|
+
fi
|
|
21
28
|
instance_state="/tmp/agent-relay-instance-${session_key}.state"
|
|
22
29
|
|
|
23
30
|
if [ ! -f "$instance_state" ]; then
|
package/package.json
CHANGED