agent-relay-plugin 0.4.35 → 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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "agent-relay",
3
3
  "description": "Client connector for Agent Relay — auto-registers Claude Code sessions as agents and enables inter-agent messaging via a lightweight HTTP message bus",
4
- "version": "0.4.35"
4
+ "version": "0.4.39"
5
5
  }
@@ -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:-{}}" | jq -r --arg key "$key" '.[$key] // empty | if type == "string" then gsub("^\\s+|\\s+$"; "") else empty end'
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:-{}}" | 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'
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() {
@@ -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 ""
@@ -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
- session_key="${CLAUDE_CODE_SESSION_ID:-$PPID}"
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
- if [ -n "$agent_id" ]; then
20
- # Kill the poll-inbox process so it stops heartbeating.
21
- poll_pid_file="/tmp/agent-relay-poll-${agent_id}.pid"
22
- if [ -f "$poll_pid_file" ]; then
23
- poll_pid=$(cat "$poll_pid_file" 2>/dev/null)
24
- if [ -n "$poll_pid" ] && kill -0 "$poll_pid" 2>/dev/null; then
25
- kill "$poll_pid" 2>/dev/null
26
- fi
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
- printf 'offline\n' > "/tmp/agent-relay-status-${agent_id}.state"
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
- rm -f "$instance_state"
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
@@ -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
- session_key="${CLAUDE_CODE_SESSION_ID:-$PPID}"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-relay-plugin",
3
- "version": "0.4.35",
3
+ "version": "0.4.39",
4
4
  "description": "Claude Code plugin for Agent Relay — auto-registers sessions as agents and enables inter-agent messaging",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",