CHAT_OUTPUT_BEGIN
COMMAND_ID=RUNNER-FAILURE-DIAGNOSTIC-HOOK-DISCOVERY-261
STATUS=OK
RC=0
HOST=pve01
MODE=read-only
COMPONENT=cluster-audit
REFERENCE_REGISTER_CHECK=OK
REFERENCE_SHA256=5763f2f8edc75fcf6f3951f8c95896d1cc112ceccb6cf5b64a383f540a4deb8e
ERROR_REGISTER_CHECK=OK
ERROR_REGISTER_SHA256=08b3a769b8e38eaa1acec915352fb328180d70caa7ff6cd9d1ec0da426262752
COMMAND_SHA256=352caa763388abe52f7800d70b48b752023cd8e19277127fb3ac421823680210
DUPLICATE_FAILED_COMMAND_BLOCKED=false
EXECUTION_STARTED=true
CHANGES_MADE=false
SANITIZED=yes
SECRETS_INCLUDED=no
PRIVATE_ADDRESSES_INCLUDED=no
RAW_EVIDENCE_SHA256=0eadf0475d642be592cd8964c1aec57e12fc87ff0d41844e9f4b13fc910a78a3
SANITIZED_OUTPUT_SHA256=bf8edda14ec575719275d87ab74aa3e5212762dff54939003287742c89cc8866
OUTPUT_BEGIN
PREVIOUS_COMMAND_ID=GITEA-READER-NGINX-APPLY-FAILURE-260
=== RESULT_BUILD_AND_PUBLICATION ===
25:COMMAND_ID="$1"
66:    sha256sum \
119:REFERENCE_SHA256="$(sha256sum "$REFERENCE" | awk '{print $1}')"
120:ERROR_REGISTER_SHA256="$(sha256sum "$ERROR_REGISTER" | awk '{print $1}')"
128:    sha256sum |
132:PREVIOUS_FAILED_RC="$(
161:    RC=73
162:    STATUS='BLOCKED'
167:        echo "PREVIOUS_RC=$PREVIOUS_FAILED_RC"
189:        RC=$?
192:        RC=$?
198:        STATUS='OK'
200:        STATUS='FAIL'
205:RAW_SHA256="$(sha256sum "$RAW_FILE" | awk '{print $1}')"
310:    sha256sum "$SANITIZED_FILE" |
353:    sanitized_sha,
389:    "reference_sha256": reference_sha,
391:    "error_register_sha256": error_sha,
392:    "command_sha256": command_sha,
397:    "sanitized": True,
401:    "raw_evidence_sha256": raw_sha,
402:    "sanitized_output_sha256": sanitized_sha,
404:    "full_sanitized_output_url": (
423:    echo 'CHAT_OUTPUT_BEGIN'
424:    echo "COMMAND_ID=$COMMAND_ID"
425:    echo "STATUS=$STATUS"
426:    echo "RC=$RC"
443:    echo 'OUTPUT_BEGIN'
446:    echo 'OUTPUT_END'
447:    echo 'CHAT_OUTPUT_END'
519:    echo "COMMAND_ID=$COMMAND_ID"
520:    echo "LOCAL_RAW_FILE=$RAW_FILE"
534:echo "COMMAND_ID=$COMMAND_ID"
535:echo "STATUS=$STATUS"
536:echo "RC=$RC"
542:echo "LOCAL_RAW_FILE=$RAW_FILE"
=== RELEVANT_SOURCE_BLOCKS ===
----- LINES 403-458 -----
    "output_truncated_in_json": output_truncated,
    "full_sanitized_output_url": (
        "https://git.gram1.ru/.well-known/"
        "homelab-runtime/latest.txt"
    ),
    "output": output_preview,
}

Path(json_path).write_text(
    json.dumps(
        document,
        ensure_ascii=False,
        indent=2,
    )
    + "\n",
    encoding="utf-8",
)
PY

{
    echo 'CHAT_OUTPUT_BEGIN'
    echo "COMMAND_ID=$COMMAND_ID"
    echo "STATUS=$STATUS"
    echo "RC=$RC"
    echo "HOST=$HOST_SHORT"
    echo "MODE=$MODE"
    echo "COMPONENT=$COMPONENT"
    echo 'REFERENCE_REGISTER_CHECK=OK'
    echo "REFERENCE_SHA256=$REFERENCE_SHA256"
    echo 'ERROR_REGISTER_CHECK=OK'
    echo "ERROR_REGISTER_SHA256=$ERROR_REGISTER_SHA256"
    echo "COMMAND_SHA256=$COMMAND_SHA256"
    echo "DUPLICATE_FAILED_COMMAND_BLOCKED=$REPEAT_BLOCKED"
    echo "EXECUTION_STARTED=$RUN_STARTED"
    echo "CHANGES_MADE=$CHANGES_MADE"
    echo 'SANITIZED=yes'
    echo 'SECRETS_INCLUDED=no'
    echo 'PRIVATE_ADDRESSES_INCLUDED=no'
    echo "RAW_EVIDENCE_SHA256=$RAW_SHA256"
    echo "SANITIZED_OUTPUT_SHA256=$SANITIZED_SHA256"
    echo 'OUTPUT_BEGIN'
    cat "$SANITIZED_FILE"
    echo
    echo 'OUTPUT_END'
    echo 'CHAT_OUTPUT_END'
} >"$TXT_FILE"

chmod 0600 \
    "$RAW_FILE" \
    "$SANITIZED_FILE" \
    "$JSON_FILE" \
    "$TXT_FILE"

TARGET=debian@[PRIVATE_IP]
REMOTE_PREFIX="/tmp/homelab-runtime-${COMMAND_ID}-$$"

----- LINES 423-478 -----
    echo 'CHAT_OUTPUT_BEGIN'
    echo "COMMAND_ID=$COMMAND_ID"
    echo "STATUS=$STATUS"
    echo "RC=$RC"
    echo "HOST=$HOST_SHORT"
    echo "MODE=$MODE"
    echo "COMPONENT=$COMPONENT"
    echo 'REFERENCE_REGISTER_CHECK=OK'
    echo "REFERENCE_SHA256=$REFERENCE_SHA256"
    echo 'ERROR_REGISTER_CHECK=OK'
    echo "ERROR_REGISTER_SHA256=$ERROR_REGISTER_SHA256"
    echo "COMMAND_SHA256=$COMMAND_SHA256"
    echo "DUPLICATE_FAILED_COMMAND_BLOCKED=$REPEAT_BLOCKED"
    echo "EXECUTION_STARTED=$RUN_STARTED"
    echo "CHANGES_MADE=$CHANGES_MADE"
    echo 'SANITIZED=yes'
    echo 'SECRETS_INCLUDED=no'
    echo 'PRIVATE_ADDRESSES_INCLUDED=no'
    echo "RAW_EVIDENCE_SHA256=$RAW_SHA256"
    echo "SANITIZED_OUTPUT_SHA256=$SANITIZED_SHA256"
    echo 'OUTPUT_BEGIN'
    cat "$SANITIZED_FILE"
    echo
    echo 'OUTPUT_END'
    echo 'CHAT_OUTPUT_END'
} >"$TXT_FILE"

chmod 0600 \
    "$RAW_FILE" \
    "$SANITIZED_FILE" \
    "$JSON_FILE" \
    "$TXT_FILE"

TARGET=debian@[PRIVATE_IP]
REMOTE_PREFIX="/tmp/homelab-runtime-${COMMAND_ID}-$$"

SSH_OPTS=(
    -o BatchMode=yes
    -o ConnectTimeout=10
    -o ConnectionAttempts=1
    -o StrictHostKeyChecking=yes
    -o UserKnownHostsFile=[SENSITIVE_PATH]
)

scp \
    -q \
    "${SSH_OPTS[@]}" \
    "$JSON_FILE" \
    "${TARGET}:${REMOTE_PREFIX}.json"

scp \
    -q \
    "${SSH_OPTS[@]}" \
    "$TXT_FILE" \
    "${TARGET}:${REMOTE_PREFIX}.txt"

----- LINES 500-555 -----
    CONTENT="$(
        curl -fsS \
            --max-time 15 \
            "$PUBLIC_URL" 2>/dev/null ||
        true
    )"

    if printf '%s\n' "$CONTENT" |
       grep -Fq "\"command_id\": \"$COMMAND_ID\""; then
        PUBLIC_VISIBLE=true
        break
    fi

    sleep 2
done

if [ "$PUBLIC_VISIBLE" != true ]; then
    echo 'RESULT=FAIL'
    echo 'REASON=PUBLIC_RUNTIME_RESULT_NOT_VISIBLE'
    echo "COMMAND_ID=$COMMAND_ID"
    echo "LOCAL_RAW_FILE=$RAW_FILE"
    exit 75
fi

printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
    "$FINISHED_AT" \
    "$COMMAND_ID" \
    "$COMMAND_SHA256" \
    "$RC" \
    "$STATUS" \
    "$COMPONENT" >>"$LEDGER"

echo
echo '===== HOMELAB CHAT RUN COMPLETE ====='
echo "COMMAND_ID=$COMMAND_ID"
echo "STATUS=$STATUS"
echo "RC=$RC"
echo 'REFERENCE_REGISTER_CHECK=OK'
echo 'ERROR_REGISTER_CHECK=OK'
echo "DUPLICATE_FAILED_COMMAND_BLOCKED=$REPEAT_BLOCKED"
echo 'GITEA_PUBLICATION=OK'
echo "PUBLIC_URL=$PUBLIC_URL"
echo "LOCAL_RAW_FILE=$RAW_FILE"
echo 'SHELL_SESSION_PRESERVED=yes'

exit "$RC"
----- LINES 522-577 -----
fi

printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
    "$FINISHED_AT" \
    "$COMMAND_ID" \
    "$COMMAND_SHA256" \
    "$RC" \
    "$STATUS" \
    "$COMPONENT" >>"$LEDGER"

echo
echo '===== HOMELAB CHAT RUN COMPLETE ====='
echo "COMMAND_ID=$COMMAND_ID"
echo "STATUS=$STATUS"
echo "RC=$RC"
echo 'REFERENCE_REGISTER_CHECK=OK'
echo 'ERROR_REGISTER_CHECK=OK'
echo "DUPLICATE_FAILED_COMMAND_BLOCKED=$REPEAT_BLOCKED"
echo 'GITEA_PUBLICATION=OK'
echo "PUBLIC_URL=$PUBLIC_URL"
echo "LOCAL_RAW_FILE=$RAW_FILE"
echo 'SHELL_SESSION_PRESERVED=yes'

exit "$RC"
CHANGES_MADE=NO

OUTPUT_END
CHAT_OUTPUT_END
