feat(comms): P1 presence — minimal Synapse + fleet presence room + mosaic.presence heartbeat + liveness
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful

Implements RFC-001 P1 (the first shippable slice): deterministic Matrix
presence/liveness on a single-instance dev Synapse.

- infra/matrix/: DEV Synapse (RFC-002 Mode B, federation OFF, self-signed TLS,
  enable_registration:false, appservice registration wired). Rendered from
  parameterized templates — zero hardcoded topology. .data is gitignored.
- packages/comms/: minimal MACP presence SDK — set presence, run the
  mosaic.presence heartbeat (seq + interval per RFC-001 §4.5), and a
  deterministic liveness reader (online/away/offline from heartbeat age, NOT
  native-presence-timeout). Liveness core written RED-FIRST. 19 vitest tests.
- tools/matrix-presence-harness/: minimal provisioner (registers >=3 agent
  MXIDs, creates the fleet presence room, joins them — reuses the existing
  @mosaicstack/appservice intent lib) + an E2E validation harness proving
  A2/A3/A4 against a real Synapse.
- eslint.config.mjs: register packages/comms/vitest.config.ts with the
  type-aware project service (same as other packages' vitest configs).

DEV-compose validated only; production deploy is a separate coordinated step
(deploy-holds respected).

Part of the comms-evolution program (RFC-001 P1)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158NZqN2n2ymKFeJAZ4GUCb
This commit is contained in:
mosaic-coder
2026-07-24 20:18:18 -05:00
parent 529c177830
commit 2e7c124e4d
33 changed files with 2140 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# ============================================================================
# run.sh — RFC-001 P1 presence validation harness (A1A5) *** DEV-ONLY ***
# ============================================================================
#
# Assumes the dev Synapse is already up (infra/matrix/dev-up.sh). Provisions 3
# agents, heartbeats them, proves A2/A3/A4 against the LOCAL dev homeserver,
# exercising @mosaicstack/comms over the self-signed TLS endpoint (A1).
#
# NODE_TLS_REJECT_UNAUTHORIZED=0 is set ONLY because the dev cert is
# self-signed. This is a DEV convenience and must never be used in prod.
# ----------------------------------------------------------------------------
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO="$(cd "${HERE}/../.." && pwd)"
DATA="${REPO}/infra/matrix/.data"
if [[ ! -f "${DATA}/dev-secrets.env" ]]; then
echo "run.sh: ${DATA}/dev-secrets.env not found — run infra/matrix/dev-up.sh first" >&2
exit 1
fi
# shellcheck disable=SC1091
set -a; source "${DATA}/dev-secrets.env"; set +a
export MATRIX_SERVER_NAME="${MATRIX_SERVER_NAME:-matrix.localhost}"
export MATRIX_TLS_PORT="${MATRIX_TLS_PORT:-18448}"
# Exercise the SDK over the self-signed TLS listener (A1). Use the plain HTTP
# port instead by exporting MATRIX_CS_URL=http://127.0.0.1:18008 before running.
export MATRIX_CS_URL="${MATRIX_CS_URL:-https://127.0.0.1:${MATRIX_TLS_PORT}}"
export NODE_TLS_REJECT_UNAUTHORIZED=0
export HEARTBEAT_INTERVAL_MS="${HEARTBEAT_INTERVAL_MS:-1000}"
export MISS_TOLERANCE="${MISS_TOLERANCE:-2}"
export DARK_THRESHOLD_MS="${DARK_THRESHOLD_MS:-6000}"
export AGENT_SLUGS="${AGENT_SLUGS:-alpha,bravo,charlie}"
export VICTIM_SLUG="${VICTIM_SLUG:-charlie}"
TSX_CLI="$(ls -d "${REPO}"/node_modules/.pnpm/tsx@*/node_modules/tsx/dist/cli.mjs 2>/dev/null | head -1)"
if [[ -z "${TSX_CLI}" ]]; then
echo "run.sh: tsx not found under node_modules — run pnpm install first" >&2
exit 1
fi
export TSX_CLI
echo "[run] CS=${MATRIX_CS_URL} server_name=${MATRIX_SERVER_NAME} dark_threshold=${DARK_THRESHOLD_MS}ms"
cd "${REPO}"
exec node "${TSX_CLI}" "${HERE}/validate.ts"