patchcord 0.5.83 → 0.5.85
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
|
@@ -24,5 +24,9 @@ if command -v jq >/dev/null 2>&1; then
|
|
|
24
24
|
fi
|
|
25
25
|
fi
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# --force tells kimi-subscribe.sh to kill any orphan listener (from a prior
|
|
28
|
+
# Kimi session for this same project) before claiming the pidfile. Subscribe
|
|
29
|
+
# resolves the project-specific pidfile name from .kimi/mcp.json itself, so
|
|
30
|
+
# concurrent sessions for OTHER projects are untouched.
|
|
31
|
+
nohup bash "$KIMI_SUB" --force 5 >/dev/null 2>&1 &
|
|
28
32
|
exit 0
|
|
@@ -14,6 +14,19 @@ set -euo pipefail
|
|
|
14
14
|
|
|
15
15
|
command -v jq >/dev/null 2>&1 || { echo "jq required" >&2; exit 1; }
|
|
16
16
|
|
|
17
|
+
# Parse --force flag (kills any existing listener for THIS project first).
|
|
18
|
+
# SessionStart hook passes --force so fresh sessions always get a fresh listener.
|
|
19
|
+
FORCE=0
|
|
20
|
+
ARGS=()
|
|
21
|
+
for arg in "$@"; do
|
|
22
|
+
if [ "$arg" = "--force" ]; then
|
|
23
|
+
FORCE=1
|
|
24
|
+
else
|
|
25
|
+
ARGS+=("$arg")
|
|
26
|
+
fi
|
|
27
|
+
done
|
|
28
|
+
set -- "${ARGS[@]+"${ARGS[@]}"}"
|
|
29
|
+
|
|
17
30
|
# Resolve MCP config: per-project first, then global
|
|
18
31
|
KIMI_MCP=""
|
|
19
32
|
dir="$PWD"
|
|
@@ -60,14 +73,28 @@ fi
|
|
|
60
73
|
PIDFILE="/tmp/patchcord_subscribe_${NAMESPACE_ID}_${AGENT_ID}.pid"
|
|
61
74
|
NOTIFY_FILE="${HOME}/.kimi/patchcord-subscribe-notify.txt"
|
|
62
75
|
|
|
63
|
-
# Pidfile guard
|
|
64
|
-
#
|
|
65
|
-
#
|
|
76
|
+
# Pidfile guard.
|
|
77
|
+
# --force: kill the existing listener (if any) and take over. Used by SessionStart
|
|
78
|
+
# so a fresh Kimi session always gets a fresh listener for this project.
|
|
79
|
+
# default: if another instance is alive, exit 0 with a clear message so user-
|
|
80
|
+
# invoked flow skill calls are idempotent (no "background task failed").
|
|
66
81
|
if [ -f "$PIDFILE" ]; then
|
|
67
82
|
OLD_PID=$(cat "$PIDFILE" 2>/dev/null || echo "")
|
|
68
83
|
if [ -n "$OLD_PID" ] && kill -0 "$OLD_PID" 2>/dev/null; then
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
if [ "$FORCE" = "1" ]; then
|
|
85
|
+
kill "$OLD_PID" 2>/dev/null || true
|
|
86
|
+
# Wait briefly for the old process to clean up its pidfile
|
|
87
|
+
for _ in 1 2 3 4 5; do
|
|
88
|
+
kill -0 "$OLD_PID" 2>/dev/null || break
|
|
89
|
+
sleep 0.2
|
|
90
|
+
done
|
|
91
|
+
rm -f "$PIDFILE" 2>/dev/null || true
|
|
92
|
+
else
|
|
93
|
+
echo "Patchcord listener already running (pid $OLD_PID)"
|
|
94
|
+
exit 0
|
|
95
|
+
fi
|
|
96
|
+
else
|
|
97
|
+
rm -f "$PIDFILE" 2>/dev/null || true
|
|
71
98
|
fi
|
|
72
99
|
fi
|
|
73
100
|
echo $$ > "$PIDFILE"
|
|
@@ -96,11 +123,12 @@ while true; do
|
|
|
96
123
|
if [ "$COUNT" -gt 0 ] 2>/dev/null; then
|
|
97
124
|
# Write notification file so the agent sees context on wake
|
|
98
125
|
echo "PATCHCORD: ${COUNT} message(s) waiting" > "$NOTIFY_FILE"
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
# Kimi auto-triggers a new agent turn when ANY background task reaches a
|
|
127
|
+
# terminal state — exit code doesn't matter. Use exit 0 so Kimi shows
|
|
128
|
+
# "completed" (not "failed"), and emit the wake-up text to stdout so it
|
|
129
|
+
# appears in the agent's task output preview.
|
|
130
|
+
printf '%s\n' "📬 Patchcord: ${COUNT} pending message(s). Call inbox(), reply to each, then re-arm by running 'patchcord subscribe --kimi 5' as a background Shell task (run_in_background=true, timeout=86400)."
|
|
131
|
+
exit 0
|
|
104
132
|
fi
|
|
105
133
|
|
|
106
134
|
sleep "$INTERVAL"
|