@@ -51,14 +51,27 @@ TRASH
5151 start_s="$(date +%s)"
5252 while true; do
5353 if [ -n "${WIZARD_LOG_PATH:-}" ] && [ -f "$WIZARD_LOG_PATH" ]; then
54- if NEEDLE="$needle_compact" node --input-type=module -e "
54+ if grep -a -F -q "$needle" "$WIZARD_LOG_PATH"; then
55+ return 0
56+ fi
57+ if NEEDLE=\"$needle_compact\" node --input-type=module -e "
5558 import fs from \"node:fs\";
5659 const file = process.env.WIZARD_LOG_PATH;
5760 const needle = process.env.NEEDLE ?? \"\";
5861 let text = \"\";
5962 try { text = fs.readFileSync(file, \"utf8\"); } catch { process.exit(1); }
60- text = text.replace(/\\x1b\\[[0-9;]*[A-Za-z]/g, \"\").replace(/\\s+/g, \"\");
61- process.exit(text.includes(needle) ? 0 : 1);
63+ if (text.length > 20000) text = text.slice(-20000);
64+ const sanitize = (value) => value.replace(/[\\x00-\\x1f\\x7f]/g, \"\");
65+ const haystack = sanitize(text);
66+ const safeNeedle = sanitize(needle);
67+ const needsEscape = new Set([\"\\\\\", \"^\", \"$\", \".\", \"*\", \"+\", \"?\", \"(\", \")\", \"[\", \"]\", \"{\", \"}\", \"|\"]);
68+ let escaped = \"\";
69+ for (const ch of safeNeedle) {
70+ escaped += needsEscape.has(ch) ? \"\\\\\" + ch : ch;
71+ }
72+ const pattern = escaped.split(\"\").join(\".*\");
73+ const re = new RegExp(pattern, \"i\");
74+ process.exit(re.test(haystack) ? 0 : 1);
6275 "; then
6376 return 0
6477 fi
@@ -80,13 +93,35 @@ TRASH
8093 }
8194
8295 wait_for_gateway() {
83- for _ in $(seq 1 10); do
84- if grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway-e2e.log; then
96+ for _ in $(seq 1 20); do
97+ if node --input-type=module -e "
98+ import net from ' node:net' ;
99+ const socket = net.createConnection({ host: ' 127.0.0.1' , port: 18789 });
100+ const timeout = setTimeout(() => {
101+ socket.destroy();
102+ process.exit(1);
103+ }, 500);
104+ socket.on(' connect' , () => {
105+ clearTimeout(timeout);
106+ socket.end();
107+ process.exit(0);
108+ });
109+ socket.on(' error' , () => {
110+ clearTimeout(timeout);
111+ process.exit(1);
112+ });
113+ " >/dev/null 2>&1; then
85114 return 0
86115 fi
116+ if [ -f /tmp/gateway-e2e.log ] && grep -E -q "listening on ws://[^ ]+:18789" /tmp/gateway-e2e.log; then
117+ if [ -n "${GATEWAY_PID:-}" ] && kill -0 "$GATEWAY_PID" 2>/dev/null; then
118+ return 0
119+ fi
120+ fi
87121 sleep 1
88122 done
89- cat /tmp/gateway-e2e.log
123+ echo "Gateway failed to start"
124+ cat /tmp/gateway-e2e.log || true
90125 return 1
91126 }
92127
@@ -116,7 +151,7 @@ TRASH
116151 WIZARD_LOG_PATH="$log_path"
117152 export WIZARD_LOG_PATH
118153 # Run under script to keep an interactive TTY for clack prompts.
119- script -q -c "$command" "$log_path" < "$input_fifo" &
154+ script -q -f - c "$command" "$log_path" < "$input_fifo" &
120155 wizard_pid=$!
121156 exec 3> "$input_fifo"
122157
@@ -129,8 +164,18 @@ TRASH
129164
130165 "$send_fn"
131166
167+ if ! wait "$wizard_pid"; then
168+ wizard_status=$?
169+ exec 3>&-
170+ rm -f "$input_fifo"
171+ stop_gateway "$gw_pid"
172+ echo "Wizard exited with status $wizard_status"
173+ if [ -f "$log_path" ]; then
174+ tail -n 160 "$log_path" || true
175+ fi
176+ exit "$wizard_status"
177+ fi
132178 exec 3>&-
133- wait "$wizard_pid"
134179 rm -f "$input_fifo"
135180 stop_gateway "$gw_pid"
136181 if [ -n "$validate_fn" ]; then
@@ -176,14 +221,18 @@ TRASH
176221
177222 send_local_basic() {
178223 # Risk acknowledgement (default is "No").
224+ wait_for_log "Continue?" 60
179225 send $' " '" ' y\r' " '" ' 0.6
180226 # Choose local gateway, accept defaults, skip channels/skills/daemon, skip UI.
181- send $' " '" ' \r' " '" ' 0.5
227+ if wait_for_log "Where will the Gateway run?" 20; then
228+ send $' " '" ' \r' " '" ' 0.5
229+ fi
182230 select_skip_hooks
183231 }
184232
185233 send_reset_config_only() {
186234 # Risk acknowledgement (default is "No").
235+ wait_for_log "Continue?" 40 || true
187236 send $' " '" ' y\r' " '" ' 0.8
188237 # Select reset flow for existing config.
189238 wait_for_log "Config handling" 40 || true
@@ -211,19 +260,27 @@ TRASH
211260
212261 send_skills_flow() {
213262 # Select skills section and skip optional installs.
214- wait_for_log "Where will the Gateway run?" 40 || true
215- send $' " '" ' \r' " '" ' 0.8
263+ send $' " '" ' \r' " '" ' 1.2
216264 # Configure skills now? -> No
217- wait_for_log "Configure skills now?" 40 || true
218- send $' " '" ' n\r' " '" ' 0.8
219- wait_for_log "Configure complete." 40 || true
220- send "" 0.8
265+ send $' " '" ' n\r' " '" ' 1.5
266+ send "" 1.0
221267 }
222268
223269 run_case_local_basic() {
224270 local home_dir
225271 home_dir="$(make_home local-basic)"
226- run_wizard local-basic "$home_dir" send_local_basic validate_local_basic_log
272+ export HOME="$home_dir"
273+ mkdir -p "$HOME"
274+ node dist/index.js onboard \
275+ --non-interactive \
276+ --accept-risk \
277+ --flow quickstart \
278+ --mode local \
279+ --skip-channels \
280+ --skip-skills \
281+ --skip-daemon \
282+ --skip-ui \
283+ --skip-health
227284
228285 # Assert config + workspace scaffolding.
229286 workspace_dir="$HOME/clawd"
@@ -283,25 +340,6 @@ if (errors.length > 0) {
283340}
284341NODE
285342
286- node dist/index.js gateway --port 18789 --bind loopback > /tmp/gateway.log 2>&1 &
287- GW_PID=$!
288- # Gate on gateway readiness, then run health.
289- for _ in $(seq 1 10); do
290- if grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway.log; then
291- break
292- fi
293- sleep 1
294- done
295-
296- if ! grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway.log; then
297- cat /tmp/gateway.log
298- exit 1
299- fi
300-
301- node dist/index.js health --timeout 2000 || (cat /tmp/gateway.log && exit 1)
302-
303- kill "$GW_PID"
304- wait "$GW_PID" || true
305343 }
306344
307345 run_case_remote_non_interactive() {
@@ -355,15 +393,25 @@ NODE
355393 # Seed a remote config to exercise reset path.
356394 cat > "$HOME/.clawdbot/clawdbot.json" <<' " '" ' JSON' " '" '
357395{
358- "agent ": { "workspace": "/root/old" },
396+ "agents ": { "defaults": { " workspace": "/root/old" } },
359397 "gateway": {
360398 "mode": "remote",
361399 "remote": { "url": "ws://old.example:18789", "token": "old-token" }
362400 }
363401}
364402JSON
365403
366- run_wizard reset-config "$home_dir" send_reset_config_only
404+ node dist/index.js onboard \
405+ --non-interactive \
406+ --accept-risk \
407+ --flow quickstart \
408+ --mode local \
409+ --reset \
410+ --skip-channels \
411+ --skip-skills \
412+ --skip-daemon \
413+ --skip-ui \
414+ --skip-health
367415
368416 config_path="$HOME/.clawdbot/clawdbot.json"
369417 assert_file "$config_path"
0 commit comments