@@ -13,9 +13,6 @@ set -euo pipefail
1313COMPOSE_URL=" https://raw.githubusercontent.com/pRizz/opencode-cloud/main/docker-compose.yml"
1414COMPOSE_FILE=" docker-compose.yml"
1515CONTAINER_NAME=" opencode-cloud-sandbox"
16- # Coupling: must match entrypoint.sh greppable_iotp_prefix (line 104).
17- # Do not change this string without updating entrypoint.sh and vice versa.
18- IOTP_GREP_PATTERN=" INITIAL ONE-TIME PASSWORD (IOTP): "
1916IOTP_MAX_WAIT_SECONDS=120
2017IOTP_POLL_INTERVAL=3
2118SERVICE_URL=" http://localhost:3000"
@@ -385,12 +382,16 @@ get_container_id() {
385382}
386383
387384# Coupling: queries opencode-cloud-bootstrap status inside the container.
388- # The JSON contract (active, reason fields) is defined in
385+ # The JSON contract (ok, active, reason, otp fields) is defined in
389386# opencode-cloud-bootstrap.sh emit_status(). Do not change that contract
390387# without updating this function.
388+ #
389+ # --include-secret returns the raw IOTP value in the "otp" field when
390+ # bootstrap is active. This is safe because the caller already has
391+ # docker exec access to the container.
391392query_bootstrap_status () {
392393 docker exec " $CONTAINER_NAME " \
393- /usr/local/bin/opencode-cloud-bootstrap status 2> /dev/null || true
394+ /usr/local/bin/opencode-cloud-bootstrap status --include-secret 2> /dev/null || true
394395}
395396
396397# ---------------------------------------------------------------------------
@@ -431,9 +432,8 @@ start_services() {
431432check_status_and_iotp () {
432433 header " Checking Setup Status"
433434
434- local elapsed=0 status_json=" " active=" " reason=" "
435+ local elapsed=0 status_json=" " active=" " reason=" " iotp= " "
435436
436- # Phase 1: poll bootstrap status via docker exec until a terminal state
437437 info " Waiting for container to initialize..."
438438 while [ " $elapsed " -lt " $IOTP_MAX_WAIT_SECONDS " ]; do
439439 status_json=" $( query_bootstrap_status) "
@@ -442,7 +442,15 @@ check_status_and_iotp() {
442442 reason=" $( printf ' %s' " $status_json " | jq -r ' .reason // empty' 2> /dev/null || true) "
443443
444444 if [ " $active " = " true" ]; then
445- break # IOTP is active — proceed to phase 2
445+ # IOTP is active — extract value directly from JSON
446+ iotp=" $( printf ' %s' " $status_json " | jq -r ' .otp // empty' 2> /dev/null || true) "
447+ if [ -n " $iotp " ]; then
448+ printf ' \n' >&2
449+ display_fresh_setup " $iotp "
450+ return 0
451+ fi
452+ # otp field missing (shouldn't happen with --include-secret, but
453+ # keep polling in case of a race during container startup)
446454 fi
447455
448456 case " $reason " in
@@ -475,37 +483,10 @@ check_status_and_iotp() {
475483 printf ' .' >&2
476484 done
477485
478- if [ " $active " != " true" ]; then
479- printf ' \n' >&2
480- warn " Container did not produce bootstrap status within ${IOTP_MAX_WAIT_SECONDS} s."
481- warn " Check container logs: docker logs $CONTAINER_NAME "
482- return 0
483- fi
484-
485- # Phase 2: IOTP is active — extract the actual value from container logs
486- printf ' \n' >&2
487- info " IOTP is active. Extracting from container logs..."
488- local iotp=" "
489- while [ " $elapsed " -lt " $IOTP_MAX_WAIT_SECONDS " ]; do
490- iotp=" $( docker logs " $CONTAINER_NAME " 2>&1 \
491- | grep -F " $IOTP_GREP_PATTERN " \
492- | tail -n1 \
493- | sed " s/.*${IOTP_GREP_PATTERN} //" || true) "
494-
495- if [ -n " $iotp " ]; then
496- display_fresh_setup " $iotp "
497- return 0
498- fi
499-
500- sleep " $IOTP_POLL_INTERVAL "
501- elapsed=$(( elapsed + IOTP_POLL_INTERVAL))
502- printf ' .' >&2
503- done
504-
505486 printf ' \n' >&2
506- warn " Could not extract IOTP from logs within ${IOTP_MAX_WAIT_SECONDS} s."
507- warn " The IOTP should be in the container logs :"
508- warn " docker logs $CONTAINER_NAME | grep -F \" INITIAL ONE-TIME PASSWORD (IOTP): \" "
487+ warn " Container did not produce bootstrap status within ${IOTP_MAX_WAIT_SECONDS} s."
488+ warn " Check status manually :"
489+ warn " docker exec $CONTAINER_NAME /usr/local/bin/opencode-cloud-bootstrap status --include-secret "
509490}
510491
511492# ---------------------------------------------------------------------------
0 commit comments