agent-relay 2.0.19 → 2.0.20

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 (141) hide show
  1. package/bin/relay-pty-darwin-arm64 +0 -0
  2. package/bin/relay-pty-darwin-x64 +0 -0
  3. package/bin/relay-pty-linux-x64 +0 -0
  4. package/dist/dashboard/out/404.html +1 -1
  5. package/dist/dashboard/out/app/onboarding.html +1 -1
  6. package/dist/dashboard/out/app/onboarding.txt +1 -1
  7. package/dist/dashboard/out/app.html +1 -1
  8. package/dist/dashboard/out/app.txt +1 -1
  9. package/dist/dashboard/out/cloud/link.html +1 -1
  10. package/dist/dashboard/out/cloud/link.txt +1 -1
  11. package/dist/dashboard/out/complete-profile.html +1 -1
  12. package/dist/dashboard/out/complete-profile.txt +1 -1
  13. package/dist/dashboard/out/connect-repos.html +1 -1
  14. package/dist/dashboard/out/connect-repos.txt +1 -1
  15. package/dist/dashboard/out/history.html +1 -1
  16. package/dist/dashboard/out/history.txt +1 -1
  17. package/dist/dashboard/out/index.html +1 -1
  18. package/dist/dashboard/out/index.txt +1 -1
  19. package/dist/dashboard/out/login.html +1 -1
  20. package/dist/dashboard/out/login.txt +1 -1
  21. package/dist/dashboard/out/metrics.html +1 -1
  22. package/dist/dashboard/out/metrics.txt +1 -1
  23. package/dist/dashboard/out/pricing.html +1 -1
  24. package/dist/dashboard/out/pricing.txt +1 -1
  25. package/dist/dashboard/out/providers/setup/claude.html +1 -1
  26. package/dist/dashboard/out/providers/setup/claude.txt +1 -1
  27. package/dist/dashboard/out/providers/setup/codex.html +1 -1
  28. package/dist/dashboard/out/providers/setup/codex.txt +1 -1
  29. package/dist/dashboard/out/providers/setup/cursor.html +1 -1
  30. package/dist/dashboard/out/providers/setup/cursor.txt +1 -1
  31. package/dist/dashboard/out/providers.html +1 -1
  32. package/dist/dashboard/out/providers.txt +1 -1
  33. package/dist/dashboard/out/signup.html +1 -1
  34. package/dist/dashboard/out/signup.txt +1 -1
  35. package/package.json +23 -17
  36. package/packages/api-types/package.json +2 -2
  37. package/packages/bridge/dist/spawner.d.ts +2 -0
  38. package/packages/bridge/dist/spawner.js +75 -23
  39. package/packages/bridge/package.json +8 -8
  40. package/packages/cli-tester/README.md +277 -0
  41. package/packages/cli-tester/dist/index.d.ts +21 -0
  42. package/packages/cli-tester/dist/index.js +21 -0
  43. package/packages/cli-tester/dist/utils/credential-check.d.ts +56 -0
  44. package/packages/cli-tester/dist/utils/credential-check.js +230 -0
  45. package/packages/cli-tester/dist/utils/socket-client.d.ts +76 -0
  46. package/packages/cli-tester/dist/utils/socket-client.js +153 -0
  47. package/packages/cli-tester/docker/entrypoint.sh +58 -0
  48. package/packages/cli-tester/package.json +32 -0
  49. package/packages/cli-tester/scripts/clear-auth.sh +101 -0
  50. package/packages/cli-tester/scripts/inject-message.sh +42 -0
  51. package/packages/cli-tester/scripts/start.sh +71 -0
  52. package/packages/cli-tester/scripts/test-cli.sh +56 -0
  53. package/packages/cli-tester/scripts/test-full-spawn.sh +238 -0
  54. package/packages/cli-tester/scripts/test-registration.sh +182 -0
  55. package/packages/cli-tester/scripts/test-setup-flow.sh +202 -0
  56. package/packages/cli-tester/scripts/test-spawn.sh +140 -0
  57. package/packages/cli-tester/scripts/test-with-daemon.sh +247 -0
  58. package/packages/cli-tester/scripts/verify-auth.sh +112 -0
  59. package/packages/cloud/package.json +6 -6
  60. package/packages/config/dist/cli-auth-config.js +65 -0
  61. package/packages/config/package.json +2 -2
  62. package/packages/continuity/package.json +1 -1
  63. package/packages/daemon/dist/router.js +4 -4
  64. package/packages/daemon/dist/server.js +38 -19
  65. package/packages/daemon/dist/spawn-manager.d.ts +4 -0
  66. package/packages/daemon/dist/spawn-manager.js +2 -0
  67. package/packages/daemon/package.json +12 -12
  68. package/packages/dashboard/dist/server.js +4 -0
  69. package/packages/dashboard/package.json +14 -14
  70. package/packages/dashboard/ui-dist/404.html +1 -1
  71. package/packages/dashboard/ui-dist/app/onboarding.html +1 -1
  72. package/packages/dashboard/ui-dist/app/onboarding.txt +1 -1
  73. package/packages/dashboard/ui-dist/app.html +1 -1
  74. package/packages/dashboard/ui-dist/app.txt +1 -1
  75. package/packages/dashboard/ui-dist/cloud/link.html +1 -1
  76. package/packages/dashboard/ui-dist/cloud/link.txt +1 -1
  77. package/packages/dashboard/ui-dist/complete-profile.html +1 -1
  78. package/packages/dashboard/ui-dist/complete-profile.txt +1 -1
  79. package/packages/dashboard/ui-dist/connect-repos.html +1 -1
  80. package/packages/dashboard/ui-dist/connect-repos.txt +1 -1
  81. package/packages/dashboard/ui-dist/history.html +1 -1
  82. package/packages/dashboard/ui-dist/history.txt +1 -1
  83. package/packages/dashboard/ui-dist/index.html +1 -1
  84. package/packages/dashboard/ui-dist/index.txt +1 -1
  85. package/packages/dashboard/ui-dist/login.html +1 -1
  86. package/packages/dashboard/ui-dist/login.txt +1 -1
  87. package/packages/dashboard/ui-dist/metrics.html +1 -1
  88. package/packages/dashboard/ui-dist/metrics.txt +1 -1
  89. package/packages/dashboard/ui-dist/pricing.html +1 -1
  90. package/packages/dashboard/ui-dist/pricing.txt +1 -1
  91. package/packages/dashboard/ui-dist/providers/setup/claude.html +1 -1
  92. package/packages/dashboard/ui-dist/providers/setup/claude.txt +1 -1
  93. package/packages/dashboard/ui-dist/providers/setup/codex.html +1 -1
  94. package/packages/dashboard/ui-dist/providers/setup/codex.txt +1 -1
  95. package/packages/dashboard/ui-dist/providers/setup/cursor.html +1 -1
  96. package/packages/dashboard/ui-dist/providers/setup/cursor.txt +1 -1
  97. package/packages/dashboard/ui-dist/providers.html +1 -1
  98. package/packages/dashboard/ui-dist/providers.txt +1 -1
  99. package/packages/dashboard/ui-dist/signup.html +1 -1
  100. package/packages/dashboard/ui-dist/signup.txt +1 -1
  101. package/packages/dashboard-server/dist/server.js +4 -0
  102. package/packages/dashboard-server/package.json +12 -12
  103. package/packages/hooks/package.json +4 -4
  104. package/packages/mcp/package.json +2 -2
  105. package/packages/memory/package.json +2 -2
  106. package/packages/policy/package.json +2 -2
  107. package/packages/protocol/package.json +1 -1
  108. package/packages/resiliency/package.json +1 -1
  109. package/packages/sdk/README.md +512 -58
  110. package/packages/sdk/dist/client.d.ts +135 -1
  111. package/packages/sdk/dist/client.js +338 -0
  112. package/packages/sdk/dist/index.d.ts +2 -1
  113. package/packages/sdk/dist/index.js +2 -0
  114. package/packages/sdk/dist/logs.d.ts +61 -0
  115. package/packages/sdk/dist/logs.js +95 -0
  116. package/packages/sdk/dist/protocol/index.d.ts +1 -1
  117. package/packages/sdk/dist/protocol/types.d.ts +186 -1
  118. package/packages/sdk/package.json +3 -3
  119. package/packages/spawner/package.json +2 -2
  120. package/packages/state/package.json +1 -1
  121. package/packages/storage/dist/sqlite-adapter.js +2 -0
  122. package/packages/storage/package.json +2 -2
  123. package/packages/telemetry/package.json +1 -1
  124. package/packages/trajectory/package.json +2 -2
  125. package/packages/user-directory/package.json +2 -2
  126. package/packages/utils/package.json +1 -1
  127. package/packages/wrapper/dist/base-wrapper.js +27 -10
  128. package/packages/wrapper/dist/relay-pty-orchestrator.js +7 -5
  129. package/packages/wrapper/dist/tmux-wrapper.js +16 -0
  130. package/packages/wrapper/package.json +7 -7
  131. package/scripts/hooks/install.sh +16 -0
  132. package/scripts/hooks/pre-commit +60 -0
  133. package/specs/PRIMITIVES_ROADMAP.md +2154 -0
  134. /package/dist/dashboard/out/_next/static/{cREcLZyPb-5NyVZje0Qfe → PwtT8u1tFMW_S1HUv0i5S}/_buildManifest.js +0 -0
  135. /package/dist/dashboard/out/_next/static/{cREcLZyPb-5NyVZje0Qfe → PwtT8u1tFMW_S1HUv0i5S}/_ssgManifest.js +0 -0
  136. /package/packages/dashboard/ui-dist/_next/static/{N3ajGnJqRESKyCjDvyU52 → 52xh7eSCZzG97BVf5zzLY}/_buildManifest.js +0 -0
  137. /package/packages/dashboard/ui-dist/_next/static/{N3ajGnJqRESKyCjDvyU52 → 52xh7eSCZzG97BVf5zzLY}/_ssgManifest.js +0 -0
  138. /package/packages/dashboard/ui-dist/_next/static/{UQiyWwBxIP-9it3GYVBDL → NN1eZ4W4r5XU6mkmJWV2-}/_buildManifest.js +0 -0
  139. /package/packages/dashboard/ui-dist/_next/static/{UQiyWwBxIP-9it3GYVBDL → NN1eZ4W4r5XU6mkmJWV2-}/_ssgManifest.js +0 -0
  140. /package/packages/dashboard/ui-dist/_next/static/{cREcLZyPb-5NyVZje0Qfe → PwtT8u1tFMW_S1HUv0i5S}/_buildManifest.js +0 -0
  141. /package/packages/dashboard/ui-dist/_next/static/{cREcLZyPb-5NyVZje0Qfe → PwtT8u1tFMW_S1HUv0i5S}/_ssgManifest.js +0 -0
@@ -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
@@ -0,0 +1,202 @@
1
+ #!/bin/bash
2
+ # Test the EXACT setup terminal flow used for provider onboarding
3
+ # This replicates what TerminalProviderSetup.tsx does when you click "Connect"
4
+ #
5
+ # The setup flow:
6
+ # 1. Frontend calls POST /api/workspaces/{id}/agents with { name, provider, interactive: true }
7
+ # 2. Spawner runs: relay-pty --name __setup__cursor-xxx -- agent (NO --force flag!)
8
+ # 3. Spawner waits up to 30s for agent to register with daemon
9
+ # 4. If timeout, spawn fails with "Agent registration timeout"
10
+ #
11
+ # Usage: ./test-setup-flow.sh <cli> [timeout_seconds]
12
+ # Example: ./test-setup-flow.sh cursor 60
13
+ # DEBUG=1 ./test-setup-flow.sh cursor
14
+
15
+ set -e
16
+
17
+ CLI=${1:-cursor}
18
+ TIMEOUT_SEC=${2:-60}
19
+
20
+ # Generate setup agent name like frontend does
21
+ TIMESTAMP=$(date +%s | tail -c 8)
22
+ RANDOM_SUFFIX=$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 4)
23
+ NAME="__setup__${CLI}-${TIMESTAMP}${RANDOM_SUFFIX}"
24
+
25
+ # Map CLI to command
26
+ CLI_CMD="$CLI"
27
+ if [ "$CLI" = "cursor" ]; then
28
+ CLI_CMD="agent"
29
+ fi
30
+
31
+ SOCKET="/tmp/relay-pty-${NAME}.sock"
32
+
33
+ echo "========================================"
34
+ echo " Setup Terminal Flow Test: $CLI"
35
+ echo "========================================"
36
+ echo ""
37
+ echo "This test replicates the EXACT flow from TerminalProviderSetup.tsx"
38
+ echo ""
39
+ echo "Key difference from test-spawn.sh:"
40
+ echo " - interactive=true means NO auto-accept flags (--force, etc.)"
41
+ echo " - This is how setup terminals work - user must respond to prompts"
42
+ echo ""
43
+ echo "Configuration:"
44
+ echo " CLI: $CLI_CMD"
45
+ echo " Agent name: $NAME"
46
+ echo " Socket: $SOCKET"
47
+ echo " Interactive: true (no --force, no --dangerously-skip-permissions)"
48
+ echo " Timeout: ${TIMEOUT_SEC}s"
49
+ echo ""
50
+
51
+ # Interactive mode - no auto-accept flags, but some CLIs need auth subcommands
52
+ CLI_ARGS=()
53
+ case $CLI in
54
+ copilot)
55
+ CLI_ARGS+=(auth login)
56
+ ;;
57
+ opencode)
58
+ CLI_ARGS+=(auth login)
59
+ ;;
60
+ droid)
61
+ CLI_ARGS+=(--login)
62
+ ;;
63
+ codex)
64
+ CLI_ARGS+=(login)
65
+ ;;
66
+ esac
67
+
68
+ if [ ${#CLI_ARGS[@]} -gt 0 ]; then
69
+ echo "Command: relay-pty --name $NAME -- $CLI_CMD ${CLI_ARGS[*]}"
70
+ else
71
+ echo "Command: relay-pty --name $NAME -- $CLI_CMD"
72
+ fi
73
+ echo " (no auto-accept flags because interactive=true)"
74
+ echo ""
75
+
76
+ # Cleanup
77
+ cleanup() {
78
+ echo ""
79
+ echo "Cleaning up..."
80
+ rm -f "$SOCKET"
81
+ if [ -n "$PTY_PID" ]; then
82
+ kill $PTY_PID 2>/dev/null || true
83
+ fi
84
+ }
85
+ trap cleanup EXIT
86
+
87
+ # Remove stale socket
88
+ rm -f "$SOCKET"
89
+
90
+ echo "========================================"
91
+ echo " Starting Setup Terminal"
92
+ echo "========================================"
93
+ echo ""
94
+
95
+ # Build relay-pty args
96
+ RELAY_ARGS=(
97
+ --name "$NAME"
98
+ --socket "$SOCKET"
99
+ --idle-timeout 300
100
+ )
101
+
102
+ # Add verbose output
103
+ if [ -n "$DEBUG" ]; then
104
+ RELAY_ARGS+=(--json-output)
105
+ echo "[DEBUG] JSON output enabled"
106
+ echo ""
107
+ fi
108
+
109
+ # Start in background so we can monitor
110
+ if [ ${#CLI_ARGS[@]} -gt 0 ]; then
111
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" "${CLI_ARGS[@]}" 2>&1 &
112
+ else
113
+ relay-pty "${RELAY_ARGS[@]}" -- "$CLI_CMD" 2>&1 &
114
+ fi
115
+ PTY_PID=$!
116
+
117
+ echo "[$(date +%T)] Started relay-pty (PID: $PTY_PID)"
118
+ echo ""
119
+ echo "The CLI is now running. In a real setup flow, you would see"
120
+ echo "the terminal output in the browser and respond to prompts there."
121
+ echo ""
122
+ echo "Watch for:"
123
+ echo " - Trust prompts (workspace trust, etc.)"
124
+ echo " - Auth URL being printed"
125
+ echo " - Any errors or crashes"
126
+ echo ""
127
+
128
+ # Give it a moment
129
+ sleep 2
130
+
131
+ # Check if still running
132
+ if ! kill -0 $PTY_PID 2>/dev/null; then
133
+ echo "[$(date +%T)] ERROR: relay-pty exited immediately!"
134
+ echo ""
135
+ echo "This means the CLI crashed on startup."
136
+ echo "Common causes:"
137
+ echo " - CLI not installed"
138
+ echo " - Missing dependencies"
139
+ echo " - Permission issues"
140
+ exit 1
141
+ fi
142
+
143
+ echo "========================================"
144
+ echo " Monitoring (${TIMEOUT_SEC}s timeout)"
145
+ echo "========================================"
146
+ echo ""
147
+ echo "In a real spawn, the spawner would poll registration files here."
148
+ echo "The timeout you're seeing is because this polling fails."
149
+ echo ""
150
+ echo "Press Ctrl+C to stop, or wait for timeout."
151
+ echo ""
152
+
153
+ START_TIME=$(date +%s)
154
+
155
+ while true; do
156
+ CURRENT_TIME=$(date +%s)
157
+ ELAPSED=$((CURRENT_TIME - START_TIME))
158
+
159
+ # Check process
160
+ if ! kill -0 $PTY_PID 2>/dev/null; then
161
+ echo ""
162
+ echo "[$(date +%T)] CLI exited after ${ELAPSED}s"
163
+ echo ""
164
+ echo "If this was unexpected, check the output above for errors."
165
+ echo "If the CLI authenticated and exited normally, that's OK."
166
+ exit 0
167
+ fi
168
+
169
+ # Check socket
170
+ if [ -S "$SOCKET" ]; then
171
+ STATUS=$(echo '{"type":"status"}' | timeout 2 nc -U "$SOCKET" 2>/dev/null | head -1 || echo "")
172
+ if [ -n "$STATUS" ]; then
173
+ IDLE=$(echo "$STATUS" | grep -o '"agent_idle":[^,}]*' | cut -d: -f2 || echo "unknown")
174
+ echo "[$(date +%T)] +${ELAPSED}s: Socket OK, idle=$IDLE"
175
+ else
176
+ echo "[$(date +%T)] +${ELAPSED}s: Socket exists, no status response"
177
+ fi
178
+ else
179
+ echo "[$(date +%T)] +${ELAPSED}s: Waiting for socket..."
180
+ fi
181
+
182
+ # Timeout check
183
+ if [ $ELAPSED -ge $TIMEOUT_SEC ]; then
184
+ echo ""
185
+ echo "========================================"
186
+ echo " Test Complete (${TIMEOUT_SEC}s elapsed)"
187
+ echo "========================================"
188
+ echo ""
189
+ echo "The CLI ran for ${TIMEOUT_SEC}s without exiting."
190
+ echo ""
191
+ echo "If this were a real spawn:"
192
+ echo " - The spawner would have timed out at 30s"
193
+ echo " - You'd see 'Agent registration timeout' error"
194
+ echo ""
195
+ echo "To continue interacting with the CLI, the process"
196
+ echo "is still running. Press Enter to stop it."
197
+ read -r
198
+ exit 0
199
+ fi
200
+
201
+ sleep 3
202
+ done