patchcord 0.3.85 → 0.3.87

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patchcord",
3
- "version": "0.3.85",
3
+ "version": "0.3.87",
4
4
  "description": "Cross-machine agent messaging for Claude Code and Codex",
5
5
  "author": "ppravdin",
6
6
  "license": "MIT",
@@ -1,19 +1,12 @@
1
1
  #!/bin/bash
2
2
  set -euo pipefail
3
3
 
4
- find_patchcord_mcp_json() {
5
- # Only check CWD itself — don't walk up.
6
- # Walking up leaks agent identity from parent dirs into unrelated projects.
7
- local dir="${1:-$PWD}"
8
- if [ -f "$dir/.mcp.json" ]; then
9
- printf '%s\n' "$dir/.mcp.json"
10
- return 0
11
- fi
12
- return 1
13
- }
14
-
15
4
  INPUT=$(cat)
16
5
 
6
+ # Get project cwd from Claude Code's input JSON, fall back to $PWD
7
+ PROJECT_CWD=$(echo "$INPUT" | jq -r '.cwd // empty' 2>/dev/null || true)
8
+ [ -z "$PROJECT_CWD" ] || [ "$PROJECT_CWD" = "null" ] && PROJECT_CWD="$PWD"
9
+
17
10
  # Guard against infinite loops: stop_hook_active is true when Claude
18
11
  # is already continuing because a previous Stop hook told it to.
19
12
  STOP_ACTIVE=$(echo "$INPUT" | jq -r '.stop_hook_active // false' 2>/dev/null || echo "false")
@@ -40,7 +33,8 @@ fi
40
33
  # Resolve config from project-scoped .mcp.json only.
41
34
  TOKEN=""
42
35
  URL=""
43
- MCP_JSON=$(find_patchcord_mcp_json "$PWD" || true)
36
+ MCP_JSON=""
37
+ [ -f "$PROJECT_CWD/.mcp.json" ] && MCP_JSON="$PROJECT_CWD/.mcp.json"
44
38
 
45
39
  if [ -n "$MCP_JSON" ]; then
46
40
  MCP_URL=$(jq -r '.mcpServers.patchcord.url // empty' "$MCP_JSON" 2>/dev/null || true)
@@ -94,7 +88,7 @@ if [ -n "$NAMESPACE" ] && [ -n "$AGENT_ID" ]; then
94
88
 
95
89
  if [ -n "$SKILL_RESP" ]; then
96
90
  SKILL_TEXT=$(echo "$SKILL_RESP" | jq -r '.skill_text // empty' 2>/dev/null || true)
97
- SKILL_HASH=$(echo "$SKILL_TEXT" | md5sum | cut -d' ' -f1)
91
+ SKILL_HASH=$(printf '%s' "$SKILL_TEXT" | (md5sum 2>/dev/null || md5 2>/dev/null) | cut -d' ' -f1 || echo "nohash")
98
92
  CACHE_FILE="/tmp/patchcord_skill_hash_${NAMESPACE}_${AGENT_ID}"
99
93
  OLD_HASH=$(cat "$CACHE_FILE" 2>/dev/null || echo "")
100
94
 
@@ -111,10 +105,20 @@ if [ -n "$NAMESPACE" ] && [ -n "$AGENT_ID" ]; then
111
105
  fi
112
106
  fi
113
107
 
114
- # ── Inbox notification ────────────────────────────────────────
108
+ # ── Inbox notification (deduplicated across Stop + Notification hooks) ──
115
109
  COUNT=$(echo "$RESPONSE" | jq -r '.count // .pending_count // 0' 2>/dev/null || echo "0")
116
110
 
117
111
  if [ "$COUNT" -gt 0 ]; then
112
+ NOTIFY_LOCK="/tmp/patchcord_notify_lock"
113
+ LOCK_AGE=5
114
+ if [ -f "$NOTIFY_LOCK" ]; then
115
+ LOCK_MTIME=$(stat -c %Y "$NOTIFY_LOCK" 2>/dev/null || stat -f %m "$NOTIFY_LOCK" 2>/dev/null || echo "0")
116
+ NOW=$(date +%s)
117
+ if [ $(( NOW - LOCK_MTIME )) -lt $LOCK_AGE ]; then
118
+ exit 0 # Already notified within 5s
119
+ fi
120
+ fi
121
+ touch "$NOTIFY_LOCK"
118
122
  jq -n --arg count "$COUNT" '{
119
123
  "decision": "block",
120
124
  "reason": ($count + " patchcord message(s) waiting. Call inbox() and reply to all immediately.")
@@ -12,17 +12,6 @@ for arg in "$@"; do
12
12
  [ "$arg" = "--full" ] && FULL=true
13
13
  done
14
14
 
15
- find_patchcord_mcp_json() {
16
- # Only check CWD itself — don't walk up.
17
- # Walking up leaks agent identity from parent dirs into unrelated projects.
18
- local dir="$1"
19
- if [ -f "$dir/.mcp.json" ]; then
20
- printf '%s\n' "$dir/.mcp.json"
21
- return 0
22
- fi
23
- return 1
24
- }
25
-
26
15
  input=$(cat)
27
16
 
28
17
  if [ -z "$input" ]; then
@@ -48,7 +37,8 @@ cwd=$(echo "$input" | jq -r '.cwd // ""')
48
37
 
49
38
  pc_token=""
50
39
  pc_url=""
51
- mcp_json=$(find_patchcord_mcp_json "$cwd" || true)
40
+ mcp_json=""
41
+ [ -f "$cwd/.mcp.json" ] && mcp_json="$cwd/.mcp.json"
52
42
 
53
43
  if [ -n "$mcp_json" ]; then
54
44
  mcp_url=$(jq -r '.mcpServers.patchcord.url // empty' "$mcp_json" 2>/dev/null || true)