agent-relay-plugin 0.4.35 → 0.6.0

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.6.0"
5
5
  }
@@ -194,7 +194,7 @@ while true; do
194
194
  fi
195
195
  fi
196
196
 
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
197
+ if ! line=$(printf '%s' "$msg" | jq -r '(.payload.pairId // "") as $pair | (if $pair != "" then " [pair:\($pair)]" else "" end) as $pairText | (.body | gsub("\r"; "\\r") | gsub("\n"; "\\n")) as $body | if .kind == "system" or .kind == "control" then "⚠ SYSTEM [msg:\(.id)]\($pairText): \($body)" else "[msg:\(.id)]\($pairText) \(.from) → \(.to) | \(.subject // "(no subject)"): \($body)" end') || [ -z "$line" ]; then
198
198
  echo "warn: failed to format relay message ${mid}" >&2
199
199
  delivery_failed=true
200
200
  continue
@@ -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() {
@@ -38,8 +38,11 @@ fi
38
38
  ar_init_profile "claude" "$rig" "$project"
39
39
 
40
40
  session_key="${CLAUDE_CODE_SESSION_ID:-$PPID}"
41
+ safe_session_key=$(printf '%s' "$session_key" | sed 's/[^A-Za-z0-9_.:-]/_/g')
41
42
  if command -v shasum >/dev/null 2>&1; then
42
43
  short_pid=$(printf '%s' "$session_key" | shasum -a 1 | head -c 6)
44
+ elif command -v sha1sum >/dev/null 2>&1; then
45
+ short_pid=$(printf '%s' "$session_key" | sha1sum | head -c 6)
43
46
  else
44
47
  short_pid=$(printf '%s' "$session_key" | md5sum | head -c 6)
45
48
  fi
@@ -64,6 +67,25 @@ if [ -f "$instance_state" ]; then
64
67
  fi
65
68
  printf '%s\n' "$agent_id" > "$instance_state"
66
69
 
70
+ context_dir="${HOME:-/tmp}/.agent-relay/contexts"
71
+ context_path="${context_dir}/${safe_session_key}.json"
72
+ mkdir -p "$context_dir" 2>/dev/null || true
73
+ jq -n \
74
+ --arg agentId "$agent_id" \
75
+ --arg relayUrl "$RELAY_URL" \
76
+ --arg cwd "${PWD:-}" \
77
+ --arg session "$session_key" \
78
+ --arg updatedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
79
+ '{
80
+ version: 1,
81
+ agentId: $agentId,
82
+ provider: "claude",
83
+ relayUrl: $relayUrl,
84
+ cwd: $cwd,
85
+ matchEnv: [{name: "CLAUDE_CODE_SESSION_ID", value: $session}],
86
+ updatedAt: $updatedAt
87
+ }' > "$context_path" 2>/dev/null || true
88
+
67
89
  reg_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST "${RELAY_URL}/api/agents" "${auth_header_args[@]}" \
68
90
  -H 'Content-Type: application/json' \
69
91
  -d "$(jq -n \
@@ -86,7 +108,7 @@ fi
86
108
  server_version=$(curl -s "${auth_header_args[@]}" "${RELAY_URL}/api/stats" 2>/dev/null | jq -r '.version // empty' 2>/dev/null)
87
109
  version_warning=""
88
110
  if [ -z "$server_version" ]; then
89
- version_warning="⚠ Server does not report its version — consider updating: bunx agent-relay-server@latest"
111
+ version_warning="⚠ Server does not report its version — consider updating: agent-relay upgrade"
90
112
  elif [ "$PLUGIN_VERSION" = "unknown" ]; then
91
113
  version_warning="⚠ Version mismatch — server ${server_version}, plugin unknown. Restart Claude Code or update the Agent Relay plugin."
92
114
  elif [ "$server_version" != "$PLUGIN_VERSION" ]; then
@@ -126,7 +148,7 @@ To reply to a message (threading):
126
148
  Anti-loop rule: do not auto-reply to pure acknowledgements, "thanks", or "received" messages; acknowledge once, then only send follow-ups when there is new work, a decision, or a deliverable.
127
149
 
128
150
  To send a claimable task (only one agent can claim it):
129
- curl -s -X POST ${RELAY_URL}/api/messages${auth_header_example} -H 'Content-Type: application/json' -d '{"from":"${agent_id}","to":"cap:review","body":"TASK","claimable":true}'
151
+ curl -s -X POST ${RELAY_URL}/api/messages${auth_header_example} -H 'Content-Type: application/json' -d '{"from":"${agent_id}","to":"cap:review","kind":"task","body":"TASK","claimable":true,"payload":{"title":"TASK"}}'
130
152
 
131
153
  To claim a task:
132
154
  curl -s -X POST ${RELAY_URL}/api/messages/MSG_ID/claim${auth_header_example} -H 'Content-Type: application/json' -d '{"agentId":"${agent_id}"}'
@@ -175,7 +197,7 @@ if [ -n "$version_warning" ]; then
175
197
  fi
176
198
 
177
199
  # --- Check for unread messages ---
178
- unread=$(curl -s "${auth_header_args[@]}" "${RELAY_URL}/api/messages?for=${agent_id}&unread=true" 2>/dev/null)
200
+ unread=$(curl -s --fail "${auth_header_args[@]}" "${RELAY_URL}/api/messages?for=${agent_id}&unread=true" 2>/dev/null)
179
201
  unread_count=$(echo "$unread" | jq 'length' 2>/dev/null || echo "0")
180
202
  if [ "$unread_count" -gt 0 ] 2>/dev/null && [ "$unread_count" != "0" ]; then
181
203
  echo ""
@@ -11,28 +11,38 @@ 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"
23
+ safe_session_key=$(printf '%s' "$session_key" | sed 's/[^A-Za-z0-9_.:-]/_/g')
24
+ context_path="${HOME:-/tmp}/.agent-relay/contexts/${safe_session_key}.json"
16
25
 
17
26
  if [ -f "$instance_state" ]; then
18
27
  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"
28
+ fi
29
+
30
+ if [ -n "${agent_id:-}" ]; then
31
+ poll_pid_file="/tmp/agent-relay-poll-${agent_id}.pid"
32
+ if [ -f "$poll_pid_file" ]; then
33
+ poll_pid=$(cat "$poll_pid_file" 2>/dev/null)
34
+ if [ -n "$poll_pid" ] && kill -0 "$poll_pid" 2>/dev/null; then
35
+ kill "$poll_pid" 2>/dev/null
28
36
  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 &
37
+ rm -f "$poll_pid_file"
34
38
  fi
35
- rm -f "$instance_state"
39
+ printf 'offline\n' > "/tmp/agent-relay-status-${agent_id}.state"
40
+ curl -s -X PATCH "${RELAY_URL}/api/agents/${agent_id}/status" "${auth_header_args[@]}" \
41
+ -H 'Content-Type: application/json' \
42
+ -d '{"status":"offline"}' \
43
+ > /dev/null 2>&1 &
44
+ [ -n "$instance_state" ] && [ -f "$instance_state" ] && rm -f "$instance_state"
45
+ [ -f "$context_path" ] && rm -f "$context_path"
36
46
  fi
37
47
 
38
48
  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.6.0",
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",