Skip to content

Commit fd300cf

Browse files
ci: improve event stream handling in doc-check workflow
1 parent 006ac48 commit fd300cf

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

.github/workflows/doc-check.yaml

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,21 @@ jobs:
412412
echo "::endgroup::"
413413
414414
echo "::group::Streaming AI task output..."
415-
echo "╔════════════════════════════════════════════════════════════════╗"
416-
echo "║ Task: ${TASK_NAME}"
417-
echo "║ Streaming AgentAPI events from http://localhost:3284/events"
418-
echo "╚════════════════════════════════════════════════════════════════╝"
415+
echo "╔══════════════════════════════════════════════════════════════╗"
416+
printf "║ Task: %-53s ║\n" "${TASK_NAME}"
417+
echo "║ Streaming AgentAPI events from http://localhost:3284/events"
418+
echo "╚══════════════════════════════════════════════════════════════╝"
419419
echo ""
420420
421421
# Stream events from AgentAPI via SSH
422422
# The AgentAPI sends Server-Sent Events (SSE) with:
423-
# - event: message_update (new message content)
423+
# - event: message_update (contains full terminal output including tool calls)
424424
# - event: status_change (status transitions)
425425
# - data: JSON payload
426426
CURRENT_STATUS="running"
427427
coder ssh "${TASK_NAME}" -- timeout 600 curl -sN http://localhost:3284/events 2>/dev/null | \
428428
while IFS= read -r line; do
429-
# Skip empty lines and comments
429+
# Skip empty lines and SSE comments
430430
[[ -z "$line" || "$line" == :* ]] && continue
431431
432432
# Track event type
@@ -443,23 +443,11 @@ jobs:
443443
444444
case "$EVENT_TYPE" in
445445
message_update)
446-
# Extract and display message content
447-
# Try different JSON structures the API might use
448-
CONTENT=$(echo "$DATA" | jq -r '
449-
.content //
450-
.message.content //
451-
.message //
452-
.text //
453-
empty
454-
' 2>/dev/null)
455-
446+
# The API returns: {"id":N,"role":"agent|user","message":"..."}
447+
# The message field contains formatted terminal output with tool calls
448+
CONTENT=$(echo "$DATA" | jq -r '.message // empty' 2>/dev/null)
456449
if [[ -n "$CONTENT" && "$CONTENT" != "null" ]]; then
457-
ROLE=$(echo "$DATA" | jq -r '.role // .message.role // "assistant"' 2>/dev/null)
458-
if [[ "$ROLE" == "assistant" ]]; then
459-
echo "$CONTENT"
460-
elif [[ "$ROLE" == "user" ]]; then
461-
echo "[User]: $CONTENT"
462-
fi
450+
echo "$CONTENT"
463451
fi
464452
;;
465453
@@ -472,13 +460,14 @@ jobs:
472460
473461
if [[ "$NEW_STATUS" == "stable" ]]; then
474462
echo ""
475-
echo "╔════════════════════════════════════════════════════════════════╗"
476-
echo "║ Task completed successfully"
477-
echo "╚════════════════════════════════════════════════════════════════╝"
463+
echo "╔══════════════════════════════════╗"
464+
echo "║ Task completed successfully"
465+
echo "╚══════════════════════════════════╝"
478466
break
479467
fi
480468
fi
481469
;;
470+
482471
esac
483472
484473
# Reset event type for next event
@@ -490,23 +479,22 @@ jobs:
490479
echo "Stream ended."
491480
echo "::endgroup::"
492481
493-
# TEMPORARILY DISABLED FOR DEBUGGING - uncomment when done
494-
# - name: Cleanup Task and Workspace
495-
# if: always()
496-
# env:
497-
# TASK_NAME: ${{ steps.create_task.outputs.task-name }}
498-
# run: |
499-
# echo "::group::Cleaning up task and workspace..."
500-
#
501-
# if [[ -n "${TASK_NAME}" ]]; then
502-
# echo "Deleting task: ${TASK_NAME}"
503-
# coder task delete --yes "${TASK_NAME}" 2>&1 || echo "Task deletion failed or already deleted"
504-
# echo "Cleanup complete"
505-
# else
506-
# echo "No task name found, skipping cleanup"
507-
# fi
508-
#
509-
# echo "::endgroup::"
482+
- name: Cleanup Task and Workspace
483+
if: always()
484+
env:
485+
TASK_NAME: ${{ steps.create_task.outputs.task-name }}
486+
run: |
487+
echo "::group::Cleaning up task and workspace..."
488+
489+
if [[ -n "${TASK_NAME}" ]]; then
490+
echo "Deleting task: ${TASK_NAME}"
491+
coder task delete --yes "${TASK_NAME}" 2>&1 || echo "Task deletion failed or already deleted"
492+
echo "Cleanup complete"
493+
else
494+
echo "No task name found, skipping cleanup"
495+
fi
496+
497+
echo "::endgroup::"
510498
511499
- name: Write Final Summary
512500
if: always()

0 commit comments

Comments
 (0)