agent-relay 2.0.19 → 2.0.21

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.
Files changed (142) hide show
  1. package/CHANGELOG.md +217 -24
  2. package/bin/relay-pty-darwin-arm64 +0 -0
  3. package/bin/relay-pty-darwin-x64 +0 -0
  4. package/bin/relay-pty-linux-x64 +0 -0
  5. package/dist/dashboard/out/404.html +1 -1
  6. package/dist/dashboard/out/app/onboarding.html +1 -1
  7. package/dist/dashboard/out/app/onboarding.txt +1 -1
  8. package/dist/dashboard/out/app.html +1 -1
  9. package/dist/dashboard/out/app.txt +1 -1
  10. package/dist/dashboard/out/cloud/link.html +1 -1
  11. package/dist/dashboard/out/cloud/link.txt +1 -1
  12. package/dist/dashboard/out/complete-profile.html +1 -1
  13. package/dist/dashboard/out/complete-profile.txt +1 -1
  14. package/dist/dashboard/out/connect-repos.html +1 -1
  15. package/dist/dashboard/out/connect-repos.txt +1 -1
  16. package/dist/dashboard/out/history.html +1 -1
  17. package/dist/dashboard/out/history.txt +1 -1
  18. package/dist/dashboard/out/index.html +1 -1
  19. package/dist/dashboard/out/index.txt +1 -1
  20. package/dist/dashboard/out/login.html +1 -1
  21. package/dist/dashboard/out/login.txt +1 -1
  22. package/dist/dashboard/out/metrics.html +1 -1
  23. package/dist/dashboard/out/metrics.txt +1 -1
  24. package/dist/dashboard/out/pricing.html +1 -1
  25. package/dist/dashboard/out/pricing.txt +1 -1
  26. package/dist/dashboard/out/providers/setup/claude.html +1 -1
  27. package/dist/dashboard/out/providers/setup/claude.txt +1 -1
  28. package/dist/dashboard/out/providers/setup/codex.html +1 -1
  29. package/dist/dashboard/out/providers/setup/codex.txt +1 -1
  30. package/dist/dashboard/out/providers/setup/cursor.html +1 -1
  31. package/dist/dashboard/out/providers/setup/cursor.txt +1 -1
  32. package/dist/dashboard/out/providers.html +1 -1
  33. package/dist/dashboard/out/providers.txt +1 -1
  34. package/dist/dashboard/out/signup.html +1 -1
  35. package/dist/dashboard/out/signup.txt +1 -1
  36. package/package.json +23 -17
  37. package/packages/api-types/package.json +2 -2
  38. package/packages/bridge/dist/spawner.d.ts +2 -0
  39. package/packages/bridge/dist/spawner.js +76 -24
  40. package/packages/bridge/package.json +8 -8
  41. package/packages/cli-tester/README.md +277 -0
  42. package/packages/cli-tester/dist/index.d.ts +21 -0
  43. package/packages/cli-tester/dist/index.js +21 -0
  44. package/packages/cli-tester/dist/utils/credential-check.d.ts +56 -0
  45. package/packages/cli-tester/dist/utils/credential-check.js +230 -0
  46. package/packages/cli-tester/dist/utils/socket-client.d.ts +76 -0
  47. package/packages/cli-tester/dist/utils/socket-client.js +153 -0
  48. package/packages/cli-tester/docker/entrypoint.sh +58 -0
  49. package/packages/cli-tester/package.json +32 -0
  50. package/packages/cli-tester/scripts/clear-auth.sh +101 -0
  51. package/packages/cli-tester/scripts/inject-message.sh +42 -0
  52. package/packages/cli-tester/scripts/start.sh +71 -0
  53. package/packages/cli-tester/scripts/test-cli.sh +56 -0
  54. package/packages/cli-tester/scripts/test-full-spawn.sh +238 -0
  55. package/packages/cli-tester/scripts/test-registration.sh +182 -0
  56. package/packages/cli-tester/scripts/test-setup-flow.sh +202 -0
  57. package/packages/cli-tester/scripts/test-spawn.sh +140 -0
  58. package/packages/cli-tester/scripts/test-with-daemon.sh +247 -0
  59. package/packages/cli-tester/scripts/verify-auth.sh +112 -0
  60. package/packages/cloud/package.json +6 -6
  61. package/packages/config/dist/cli-auth-config.js +65 -0
  62. package/packages/config/package.json +2 -2
  63. package/packages/continuity/package.json +1 -1
  64. package/packages/daemon/dist/router.js +4 -4
  65. package/packages/daemon/dist/server.js +38 -19
  66. package/packages/daemon/dist/spawn-manager.d.ts +4 -0
  67. package/packages/daemon/dist/spawn-manager.js +2 -0
  68. package/packages/daemon/package.json +12 -12
  69. package/packages/dashboard/dist/server.js +4 -0
  70. package/packages/dashboard/package.json +14 -14
  71. package/packages/dashboard/ui-dist/404.html +1 -1
  72. package/packages/dashboard/ui-dist/app/onboarding.html +1 -1
  73. package/packages/dashboard/ui-dist/app/onboarding.txt +1 -1
  74. package/packages/dashboard/ui-dist/app.html +1 -1
  75. package/packages/dashboard/ui-dist/app.txt +1 -1
  76. package/packages/dashboard/ui-dist/cloud/link.html +1 -1
  77. package/packages/dashboard/ui-dist/cloud/link.txt +1 -1
  78. package/packages/dashboard/ui-dist/complete-profile.html +1 -1
  79. package/packages/dashboard/ui-dist/complete-profile.txt +1 -1
  80. package/packages/dashboard/ui-dist/connect-repos.html +1 -1
  81. package/packages/dashboard/ui-dist/connect-repos.txt +1 -1
  82. package/packages/dashboard/ui-dist/history.html +1 -1
  83. package/packages/dashboard/ui-dist/history.txt +1 -1
  84. package/packages/dashboard/ui-dist/index.html +1 -1
  85. package/packages/dashboard/ui-dist/index.txt +1 -1
  86. package/packages/dashboard/ui-dist/login.html +1 -1
  87. package/packages/dashboard/ui-dist/login.txt +1 -1
  88. package/packages/dashboard/ui-dist/metrics.html +1 -1
  89. package/packages/dashboard/ui-dist/metrics.txt +1 -1
  90. package/packages/dashboard/ui-dist/pricing.html +1 -1
  91. package/packages/dashboard/ui-dist/pricing.txt +1 -1
  92. package/packages/dashboard/ui-dist/providers/setup/claude.html +1 -1
  93. package/packages/dashboard/ui-dist/providers/setup/claude.txt +1 -1
  94. package/packages/dashboard/ui-dist/providers/setup/codex.html +1 -1
  95. package/packages/dashboard/ui-dist/providers/setup/codex.txt +1 -1
  96. package/packages/dashboard/ui-dist/providers/setup/cursor.html +1 -1
  97. package/packages/dashboard/ui-dist/providers/setup/cursor.txt +1 -1
  98. package/packages/dashboard/ui-dist/providers.html +1 -1
  99. package/packages/dashboard/ui-dist/providers.txt +1 -1
  100. package/packages/dashboard/ui-dist/signup.html +1 -1
  101. package/packages/dashboard/ui-dist/signup.txt +1 -1
  102. package/packages/dashboard-server/dist/server.js +4 -0
  103. package/packages/dashboard-server/package.json +12 -12
  104. package/packages/hooks/package.json +4 -4
  105. package/packages/mcp/package.json +2 -2
  106. package/packages/memory/package.json +2 -2
  107. package/packages/policy/package.json +2 -2
  108. package/packages/protocol/package.json +1 -1
  109. package/packages/resiliency/package.json +1 -1
  110. package/packages/sdk/README.md +512 -58
  111. package/packages/sdk/dist/client.d.ts +135 -1
  112. package/packages/sdk/dist/client.js +338 -0
  113. package/packages/sdk/dist/index.d.ts +2 -1
  114. package/packages/sdk/dist/index.js +2 -0
  115. package/packages/sdk/dist/logs.d.ts +61 -0
  116. package/packages/sdk/dist/logs.js +95 -0
  117. package/packages/sdk/dist/protocol/index.d.ts +1 -1
  118. package/packages/sdk/dist/protocol/types.d.ts +186 -1
  119. package/packages/sdk/package.json +3 -3
  120. package/packages/spawner/package.json +2 -2
  121. package/packages/state/package.json +1 -1
  122. package/packages/storage/dist/sqlite-adapter.js +2 -0
  123. package/packages/storage/package.json +2 -2
  124. package/packages/telemetry/package.json +1 -1
  125. package/packages/trajectory/package.json +2 -2
  126. package/packages/user-directory/package.json +2 -2
  127. package/packages/utils/package.json +1 -1
  128. package/packages/wrapper/dist/base-wrapper.js +27 -10
  129. package/packages/wrapper/dist/relay-pty-orchestrator.js +16 -16
  130. package/packages/wrapper/dist/tmux-wrapper.js +16 -0
  131. package/packages/wrapper/package.json +7 -7
  132. package/scripts/hooks/install.sh +16 -0
  133. package/scripts/hooks/pre-commit +60 -0
  134. package/specs/PRIMITIVES_ROADMAP.md +2154 -0
  135. /package/dist/dashboard/out/_next/static/{cREcLZyPb-5NyVZje0Qfe → 7MZPqYkVGw3EGzVBkVmY9}/_buildManifest.js +0 -0
  136. /package/dist/dashboard/out/_next/static/{cREcLZyPb-5NyVZje0Qfe → 7MZPqYkVGw3EGzVBkVmY9}/_ssgManifest.js +0 -0
  137. /package/packages/dashboard/ui-dist/_next/static/{N3ajGnJqRESKyCjDvyU52 → 7MZPqYkVGw3EGzVBkVmY9}/_buildManifest.js +0 -0
  138. /package/packages/dashboard/ui-dist/_next/static/{N3ajGnJqRESKyCjDvyU52 → 7MZPqYkVGw3EGzVBkVmY9}/_ssgManifest.js +0 -0
  139. /package/packages/dashboard/ui-dist/_next/static/{UQiyWwBxIP-9it3GYVBDL → iJ3Uiz3IrqUJL7IxKZHiV}/_buildManifest.js +0 -0
  140. /package/packages/dashboard/ui-dist/_next/static/{UQiyWwBxIP-9it3GYVBDL → iJ3Uiz3IrqUJL7IxKZHiV}/_ssgManifest.js +0 -0
  141. /package/packages/dashboard/ui-dist/_next/static/{cREcLZyPb-5NyVZje0Qfe → l-jd878zUJ_IlraqEWMZc}/_buildManifest.js +0 -0
  142. /package/packages/dashboard/ui-dist/_next/static/{cREcLZyPb-5NyVZje0Qfe → l-jd878zUJ_IlraqEWMZc}/_ssgManifest.js +0 -0
@@ -0,0 +1,71 @@
1
+ #!/bin/bash
2
+ # Start the CLI tester Docker environment
3
+ # Usage: ./start.sh [--clean] [--build] [--daemon]
4
+
5
+ set -e
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ PACKAGE_DIR="$(dirname "$SCRIPT_DIR")"
9
+ DOCKER_DIR="$PACKAGE_DIR/docker"
10
+
11
+ # Parse arguments
12
+ CLEAN=false
13
+ BUILD=false
14
+ WITH_DAEMON=false
15
+ while [[ $# -gt 0 ]]; do
16
+ case $1 in
17
+ --clean)
18
+ CLEAN=true
19
+ shift
20
+ ;;
21
+ --build)
22
+ BUILD=true
23
+ shift
24
+ ;;
25
+ --daemon)
26
+ WITH_DAEMON=true
27
+ shift
28
+ ;;
29
+ *)
30
+ echo "Unknown option: $1"
31
+ echo "Usage: ./start.sh [--clean] [--build] [--daemon]"
32
+ echo " --clean Remove credential volumes before starting"
33
+ echo " --build Force rebuild of Docker image"
34
+ echo " --daemon Start with relay daemon for full integration testing"
35
+ exit 1
36
+ ;;
37
+ esac
38
+ done
39
+
40
+ cd "$DOCKER_DIR"
41
+
42
+ # Clean volumes if requested
43
+ if [ "$CLEAN" = true ]; then
44
+ echo "Removing credential volumes..."
45
+ docker compose down -v 2>/dev/null || true
46
+ fi
47
+
48
+ # Build compose args
49
+ COMPOSE_ARGS=()
50
+ if [ "$WITH_DAEMON" = true ]; then
51
+ COMPOSE_ARGS+=(--profile daemon)
52
+ fi
53
+
54
+ # Build if requested or if image doesn't exist
55
+ if [ "$BUILD" = true ]; then
56
+ echo "Building Docker image..."
57
+ docker compose "${COMPOSE_ARGS[@]}" build
58
+ fi
59
+
60
+ # Start the container interactively
61
+ echo ""
62
+ if [ "$WITH_DAEMON" = true ]; then
63
+ echo "Starting CLI tester environment with daemon..."
64
+ echo "The daemon will be available at http://daemon:3377"
65
+ else
66
+ echo "Starting CLI tester environment..."
67
+ fi
68
+ echo "Use Ctrl+D or 'exit' to leave the container."
69
+ echo ""
70
+
71
+ docker compose "${COMPOSE_ARGS[@]}" run --rm cli-tester
@@ -0,0 +1,56 @@
1
+ #!/bin/bash
2
+ # Test a specific CLI with relay-pty
3
+ # Usage: ./test-cli.sh <cli> [extra-args...]
4
+ # Example: ./test-cli.sh claude
5
+ # ./test-cli.sh codex --device-auth
6
+ # DEBUG=1 ./test-cli.sh cursor
7
+
8
+ set -e
9
+
10
+ CLI=${1:-claude}
11
+ shift 2>/dev/null || true # Shift to get extra args, ignore if no more args
12
+
13
+ # Map CLI name to actual command (cursor installs as 'agent')
14
+ CLI_CMD="$CLI"
15
+ if [ "$CLI" = "cursor" ]; then
16
+ CLI_CMD="agent"
17
+ fi
18
+
19
+ NAME="test-${CLI}"
20
+ SOCKET="/tmp/relay-pty-${NAME}.sock"
21
+
22
+ # Remove stale socket if exists
23
+ rm -f "$SOCKET"
24
+
25
+ echo "========================================"
26
+ echo " Testing: $CLI"
27
+ echo "========================================"
28
+ echo ""
29
+ echo "Session name: $NAME"
30
+ echo "Socket path: $SOCKET"
31
+ echo ""
32
+ echo "After authenticating, open another terminal and run:"
33
+ echo " verify-auth.sh $CLI"
34
+ echo " inject-message.sh $NAME 'Hello world'"
35
+ echo ""
36
+ echo "Press Ctrl+C to stop the session."
37
+ echo "========================================"
38
+ echo ""
39
+
40
+ # Build relay-pty args
41
+ RELAY_ARGS=(
42
+ --name "$NAME"
43
+ --socket "$SOCKET"
44
+ --idle-timeout 500
45
+ )
46
+
47
+ # Add debug output if DEBUG is set
48
+ if [ -n "$DEBUG" ]; then
49
+ RELAY_ARGS+=(--json-output)
50
+ echo "[DEBUG] JSON output enabled - relay commands will be printed to stderr"
51
+ echo ""
52
+ fi
53
+
54
+ # Run relay-pty with the CLI
55
+ # Pass through any extra arguments to the CLI
56
+ exec relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" "$@"
@@ -0,0 +1,238 @@
1
+ #!/bin/bash
2
+ # Full spawn simulation - replicates the EXACT spawner flow
3
+ # This is the most accurate test for debugging registration timeouts
4
+ #
5
+ # Usage: ./test-full-spawn.sh <cli> [interactive]
6
+ # Example: ./test-full-spawn.sh cursor # Non-interactive (with --force)
7
+ # ./test-full-spawn.sh cursor true # Interactive (no --force, like setup terminal)
8
+ # DEBUG=1 ./test-full-spawn.sh cursor true
9
+
10
+ set -e
11
+
12
+ CLI=${1:-cursor}
13
+ INTERACTIVE=${2:-false}
14
+
15
+ # Map CLI to command
16
+ CLI_CMD="$CLI"
17
+ if [ "$CLI" = "cursor" ]; then
18
+ CLI_CMD="agent"
19
+ fi
20
+
21
+ # Generate name
22
+ if [ "$INTERACTIVE" = "true" ]; then
23
+ TIMESTAMP=$(date +%s | tail -c 8)
24
+ RANDOM_SUFFIX=$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 4)
25
+ NAME="__setup__${CLI}-${TIMESTAMP}${RANDOM_SUFFIX}"
26
+ else
27
+ NAME="spawn-test-${CLI}"
28
+ fi
29
+
30
+ SOCKET="/tmp/relay-pty-${NAME}.sock"
31
+ LOG_FILE="/tmp/relay-spawn-${NAME}.log"
32
+ REGISTRATION_TIMEOUT=30
33
+
34
+ echo "========================================"
35
+ echo " Full Spawn Simulation: $CLI"
36
+ echo "========================================"
37
+ echo ""
38
+ echo "Mode: $([ "$INTERACTIVE" = "true" ] && echo "INTERACTIVE (setup terminal)" || echo "NON-INTERACTIVE (normal spawn)")"
39
+ echo ""
40
+ echo "Configuration:"
41
+ echo " CLI: $CLI_CMD"
42
+ echo " Agent name: $NAME"
43
+ echo " Interactive: $INTERACTIVE"
44
+ echo " Registration timeout: ${REGISTRATION_TIMEOUT}s"
45
+ echo ""
46
+
47
+ # Build CLI args based on mode
48
+ CLI_ARGS=()
49
+ if [ "$INTERACTIVE" != "true" ]; then
50
+ case $CLI in
51
+ cursor)
52
+ CLI_ARGS+=(--force)
53
+ echo " Adding: --force (non-interactive cursor)"
54
+ ;;
55
+ claude)
56
+ CLI_ARGS+=(--dangerously-skip-permissions)
57
+ echo " Adding: --dangerously-skip-permissions (non-interactive claude)"
58
+ ;;
59
+ copilot)
60
+ # Copilot uses device flow for headless auth
61
+ CLI_ARGS+=(auth login --device)
62
+ echo " Adding: auth login --device (non-interactive copilot)"
63
+ ;;
64
+ codex)
65
+ # Codex supports device flow
66
+ CLI_ARGS+=(login --device-auth)
67
+ echo " Adding: login --device-auth (non-interactive codex)"
68
+ ;;
69
+ esac
70
+ else
71
+ echo " No auto-accept flags (interactive mode)"
72
+ # For interactive copilot, still need auth login command
73
+ if [ "$CLI" = "copilot" ]; then
74
+ CLI_ARGS+=(auth login)
75
+ echo " Adding: auth login (interactive copilot)"
76
+ fi
77
+ fi
78
+ echo ""
79
+
80
+ # Cleanup
81
+ cleanup() {
82
+ echo ""
83
+ echo "========================================"
84
+ echo " Cleanup"
85
+ echo "========================================"
86
+ rm -f "$SOCKET"
87
+ if [ -n "$PTY_PID" ] && kill -0 $PTY_PID 2>/dev/null; then
88
+ echo "Stopping relay-pty (PID: $PTY_PID)..."
89
+ kill $PTY_PID 2>/dev/null || true
90
+ fi
91
+ echo ""
92
+ echo "Log file: $LOG_FILE"
93
+ if [ -f "$LOG_FILE" ]; then
94
+ echo ""
95
+ echo "Last 30 lines of output:"
96
+ echo "----------------------------------------"
97
+ tail -30 "$LOG_FILE"
98
+ echo "----------------------------------------"
99
+ fi
100
+ }
101
+ trap cleanup EXIT
102
+
103
+ # Remove stale files
104
+ rm -f "$SOCKET" "$LOG_FILE"
105
+
106
+ echo "========================================"
107
+ echo " Phase 1: Start PTY"
108
+ echo "========================================"
109
+ echo ""
110
+
111
+ # This is what spawner does: pty.start()
112
+ RELAY_ARGS=(
113
+ --name "$NAME"
114
+ --socket "$SOCKET"
115
+ --idle-timeout 300
116
+ )
117
+
118
+ if [ -n "$DEBUG" ]; then
119
+ RELAY_ARGS+=(--json-output)
120
+ fi
121
+
122
+ echo "[$(date +%T)] Starting: relay-pty ${RELAY_ARGS[*]} -- $CLI_CMD ${CLI_ARGS[*]}"
123
+ echo ""
124
+
125
+ # Start relay-pty and capture output
126
+ if [ ${#CLI_ARGS[@]} -gt 0 ]; then
127
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" "${CLI_ARGS[@]}" > "$LOG_FILE" 2>&1 &
128
+ else
129
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" > "$LOG_FILE" 2>&1 &
130
+ fi
131
+ PTY_PID=$!
132
+
133
+ echo "[$(date +%T)] PTY started (PID: $PTY_PID)"
134
+
135
+ # Brief wait for startup
136
+ sleep 1
137
+
138
+ if ! kill -0 $PTY_PID 2>/dev/null; then
139
+ echo "[$(date +%T)] ERROR: PTY exited immediately!"
140
+ echo ""
141
+ cat "$LOG_FILE"
142
+ exit 1
143
+ fi
144
+
145
+ echo "[$(date +%T)] PTY is running"
146
+ echo ""
147
+
148
+ echo "========================================"
149
+ echo " Phase 2: Wait for Registration"
150
+ echo "========================================"
151
+ echo ""
152
+ echo "In the real spawner, this calls waitForAgentRegistration()"
153
+ echo "which polls connected-agents.json and agents.json for ${REGISTRATION_TIMEOUT}s"
154
+ echo ""
155
+ echo "Without a daemon, these files won't be updated, causing timeout."
156
+ echo "But we can still see if the CLI starts successfully."
157
+ echo ""
158
+
159
+ # Simulate the spawner's registration polling
160
+ START_TIME=$(date +%s)
161
+ POLL_COUNT=0
162
+
163
+ while true; do
164
+ POLL_COUNT=$((POLL_COUNT + 1))
165
+ CURRENT_TIME=$(date +%s)
166
+ ELAPSED=$((CURRENT_TIME - START_TIME))
167
+
168
+ # Check if PTY is still running
169
+ if ! kill -0 $PTY_PID 2>/dev/null; then
170
+ echo ""
171
+ echo "[$(date +%T)] PTY exited after ${ELAPSED}s (${POLL_COUNT} polls)"
172
+ echo ""
173
+ echo "Exit could be normal (auth complete) or an error."
174
+ echo "Check log output below."
175
+ exit 0
176
+ fi
177
+
178
+ # Check socket status
179
+ SOCKET_STATUS="no socket"
180
+ if [ -S "$SOCKET" ]; then
181
+ RESPONSE=$(echo '{"type":"status"}' | timeout 1 nc -U "$SOCKET" 2>/dev/null | head -1 || echo "")
182
+ if [ -n "$RESPONSE" ]; then
183
+ IDLE=$(echo "$RESPONSE" | grep -o '"agent_idle":[^,}]*' | cut -d: -f2 || echo "?")
184
+ QUEUE=$(echo "$RESPONSE" | grep -o '"queue_length":[^,}]*' | cut -d: -f2 || echo "?")
185
+ SOCKET_STATUS="idle=$IDLE queue=$QUEUE"
186
+ else
187
+ SOCKET_STATUS="no response"
188
+ fi
189
+ fi
190
+
191
+ # Log poll (like spawner does for first 3 and every 10th)
192
+ if [ $POLL_COUNT -le 3 ] || [ $((POLL_COUNT % 10)) -eq 0 ]; then
193
+ echo "[$(date +%T)] Poll #$POLL_COUNT: elapsed=${ELAPSED}s socket=[$SOCKET_STATUS]"
194
+ fi
195
+
196
+ # Check registration timeout (what spawner does)
197
+ if [ $ELAPSED -ge $REGISTRATION_TIMEOUT ]; then
198
+ echo ""
199
+ echo "========================================"
200
+ echo " REGISTRATION TIMEOUT (${REGISTRATION_TIMEOUT}s)"
201
+ echo "========================================"
202
+ echo ""
203
+ echo "This is where the real spawner would fail with:"
204
+ echo " 'Agent registration timeout'"
205
+ echo ""
206
+ echo "The CLI started but didn't register with daemon."
207
+ echo ""
208
+ echo "Possible causes:"
209
+ if [ "$INTERACTIVE" = "true" ]; then
210
+ echo " 1. CLI is waiting for user input (trust prompt, auth)"
211
+ echo " 2. No daemon running to register with"
212
+ echo " 3. CLI crashed silently"
213
+ else
214
+ echo " 1. --force flag not working as expected"
215
+ echo " 2. No daemon running to register with"
216
+ echo " 3. CLI has other blocking prompts"
217
+ fi
218
+ echo ""
219
+ echo "To see what the CLI is doing, check the log file:"
220
+ echo " cat $LOG_FILE"
221
+ echo ""
222
+ echo "Or tail it live in another terminal:"
223
+ echo " tail -f $LOG_FILE"
224
+ echo ""
225
+
226
+ # Show recent output
227
+ echo "Recent output (last 20 lines):"
228
+ echo "----------------------------------------"
229
+ tail -20 "$LOG_FILE" 2>/dev/null || echo "(no output)"
230
+ echo "----------------------------------------"
231
+ echo ""
232
+ echo "Process is still running. Press Enter to stop."
233
+ read -r
234
+ exit 1
235
+ fi
236
+
237
+ sleep 0.5
238
+ done
@@ -0,0 +1,182 @@
1
+ #!/bin/bash
2
+ # Test agent registration flow - monitors what happens during spawn
3
+ # This tests the critical registration step that's timing out for cursor
4
+ #
5
+ # Usage: ./test-registration.sh <cli> [timeout_seconds]
6
+ # Example: ./test-registration.sh cursor 60
7
+ # DEBUG_SPAWN=1 ./test-registration.sh cursor
8
+
9
+ set -e
10
+
11
+ CLI=${1:-cursor}
12
+ TIMEOUT_SEC=${2:-60}
13
+
14
+ # Map CLI name to actual command
15
+ CLI_CMD="$CLI"
16
+ if [ "$CLI" = "cursor" ]; then
17
+ CLI_CMD="agent"
18
+ fi
19
+
20
+ NAME="reg-test-${CLI}"
21
+ SOCKET="/tmp/relay-pty-${NAME}.sock"
22
+
23
+ # Test data directories (mimic real daemon structure)
24
+ TEST_DATA_DIR="/tmp/relay-registration-test"
25
+ AGENTS_FILE="$TEST_DATA_DIR/agents.json"
26
+ CONNECTED_FILE="$TEST_DATA_DIR/connected-agents.json"
27
+
28
+ # Create directories
29
+ mkdir -p "$TEST_DATA_DIR"
30
+
31
+ # Initialize empty registration files
32
+ echo '{"agents":[],"updatedAt":'$(date +%s000)'}' > "$CONNECTED_FILE"
33
+ echo '{}' > "$AGENTS_FILE"
34
+
35
+ # Cleanup function
36
+ cleanup() {
37
+ echo ""
38
+ echo "========================================"
39
+ echo " Final State"
40
+ echo "========================================"
41
+ echo ""
42
+ echo "Connected agents file ($CONNECTED_FILE):"
43
+ cat "$CONNECTED_FILE" 2>/dev/null | jq . 2>/dev/null || cat "$CONNECTED_FILE" 2>/dev/null || echo " (empty/missing)"
44
+ echo ""
45
+ echo "Agents registry file ($AGENTS_FILE):"
46
+ cat "$AGENTS_FILE" 2>/dev/null | jq . 2>/dev/null || cat "$AGENTS_FILE" 2>/dev/null || echo " (empty/missing)"
47
+ echo ""
48
+ echo "Cleaning up processes..."
49
+ rm -f "$SOCKET"
50
+ pkill -f "relay-pty.*${NAME}" 2>/dev/null || true
51
+ }
52
+ trap cleanup EXIT
53
+
54
+ # Remove stale socket
55
+ rm -f "$SOCKET"
56
+
57
+ echo "========================================"
58
+ echo " Registration Flow Test: $CLI"
59
+ echo "========================================"
60
+ echo ""
61
+ echo "This test monitors the registration files that the spawner polls."
62
+ echo "When the spawner times out, it's because these files don't show"
63
+ echo "the agent as registered within 30 seconds."
64
+ echo ""
65
+ echo "Test config:"
66
+ echo " CLI: $CLI_CMD"
67
+ echo " Name: $NAME"
68
+ echo " Socket: $SOCKET"
69
+ echo " Timeout: ${TIMEOUT_SEC}s"
70
+ echo " Connected file: $CONNECTED_FILE"
71
+ echo " Agents file: $AGENTS_FILE"
72
+ echo ""
73
+
74
+ # Build CLI arguments
75
+ CLI_ARGS=()
76
+ case $CLI in
77
+ claude)
78
+ CLI_ARGS+=(--dangerously-skip-permissions)
79
+ ;;
80
+ cursor)
81
+ CLI_ARGS+=(--force)
82
+ ;;
83
+ esac
84
+
85
+ echo "Command: $CLI_CMD ${CLI_ARGS[*]}"
86
+ echo ""
87
+ echo "========================================"
88
+ echo " Phase 1: Starting CLI"
89
+ echo "========================================"
90
+ echo ""
91
+
92
+ # Start relay-pty in background
93
+ RELAY_ARGS=(
94
+ --name "$NAME"
95
+ --socket "$SOCKET"
96
+ --idle-timeout 300
97
+ --json-output
98
+ )
99
+
100
+ if [ ${#CLI_ARGS[@]} -gt 0 ]; then
101
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" "${CLI_ARGS[@]}" 2>&1 &
102
+ else
103
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" 2>&1 &
104
+ fi
105
+
106
+ PTY_PID=$!
107
+ echo "[$(date +%T)] Started relay-pty (PID: $PTY_PID)"
108
+
109
+ # Give it a moment to start
110
+ sleep 1
111
+
112
+ # Check if process is still running
113
+ if ! kill -0 $PTY_PID 2>/dev/null; then
114
+ echo "[$(date +%T)] ERROR: relay-pty exited immediately"
115
+ wait $PTY_PID || true
116
+ exit 1
117
+ fi
118
+
119
+ echo "[$(date +%T)] relay-pty is running"
120
+ echo ""
121
+
122
+ echo "========================================"
123
+ echo " Phase 2: Monitoring Registration"
124
+ echo "========================================"
125
+ echo ""
126
+ echo "Polling for agent registration (timeout: ${TIMEOUT_SEC}s)..."
127
+ echo "In a real spawn, the daemon would update these files."
128
+ echo ""
129
+
130
+ # Poll for registration (simulating what spawner does)
131
+ START_TIME=$(date +%s)
132
+ POLL_COUNT=0
133
+
134
+ while true; do
135
+ POLL_COUNT=$((POLL_COUNT + 1))
136
+ CURRENT_TIME=$(date +%s)
137
+ ELAPSED=$((CURRENT_TIME - START_TIME))
138
+
139
+ # Check if process is still running
140
+ if ! kill -0 $PTY_PID 2>/dev/null; then
141
+ echo ""
142
+ echo "[$(date +%T)] ERROR: relay-pty exited after ${ELAPSED}s"
143
+ echo ""
144
+ echo "This is likely the issue - the CLI crashed or exited before registration."
145
+ echo "Check the output above for error messages."
146
+ wait $PTY_PID || true
147
+ exit 1
148
+ fi
149
+
150
+ # Check socket exists
151
+ if [ -S "$SOCKET" ]; then
152
+ # Try to get status from socket
153
+ STATUS=$(echo '{"type":"status"}' | timeout 2 nc -U "$SOCKET" 2>/dev/null || echo "timeout")
154
+ if [ "$STATUS" != "timeout" ]; then
155
+ echo "[$(date +%T)] Poll #$POLL_COUNT: Socket active, status: $(echo "$STATUS" | head -c 100)..."
156
+ else
157
+ echo "[$(date +%T)] Poll #$POLL_COUNT: Socket exists but no response"
158
+ fi
159
+ else
160
+ echo "[$(date +%T)] Poll #$POLL_COUNT: Socket not yet created"
161
+ fi
162
+
163
+ # Check timeout
164
+ if [ $ELAPSED -ge $TIMEOUT_SEC ]; then
165
+ echo ""
166
+ echo "========================================"
167
+ echo " TIMEOUT after ${ELAPSED}s"
168
+ echo "========================================"
169
+ echo ""
170
+ echo "This simulates what happens when the spawner times out."
171
+ echo "In a real scenario, the daemon would need to see this agent"
172
+ echo "and update the registration files within 30 seconds."
173
+ echo ""
174
+ echo "To debug further:"
175
+ echo " 1. Check if the CLI started correctly (auth issues?)"
176
+ echo " 2. Check if relay-pty connected to the daemon"
177
+ echo " 3. Check daemon logs for this agent name"
178
+ exit 1
179
+ fi
180
+
181
+ sleep 1
182
+ done