Skip to content

feat(captain-msg): add two-way captain messaging over Twilio RCS for Business - #42

Merged
Bre77 merged 2 commits into
mainfrom
fm/fm-captain-sms
Jul 28, 2026
Merged

Bre77 merged 2 commits into
mainfrom
fm/fm-captain-sms

Conversation

@Bre77

@Bre77 Bre77 commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Intent

  • Give the captain a two-way text channel to firstmate over Twilio RCS for Business, so his Tesla can read messages aloud and take dictated replies through his phone's default messaging app (Google Messages) - that in-car experience is the whole point.
    • The sender ("Teslemetry") is a business RCS sender with no phone number, so there is no automatic SMS fallback: a rejected or failed send must be a loud, nonzero-exit failure, never silent.
    • bin/fm-captain-msg.sh enforces a strict speech contract in the tool itself (plain text only, no URLs, no markdown, no code fences, <=300 chars) before it ever calls Twilio, since every outbound message gets read aloud by a car or headset.
  • Architecture choice: extend the existing ClickStack/BetterStack receiver's shared listener process with a /captain-msg path instead of standing up a new daemon, mirroring PR feat(webhooks): add BetterStack status-page webhook route #14's reasoning exactly - the reverse proxy forwards the whole host to one port, so a second listener would be unreachable without an out-of-repo change.
    • bin/fm-clickstack-recv.sh / bin/fm-clickstack-arm.sh now start the shared daemon when any of the three gates is present, and the listener dispatches by path, 404-ing each route independently unless its own gate is present.
    • Inbound webhooks are validated with Twilio's own signed-request algorithm (HMAC-SHA1 over the exact webhook URL plus sorted POST params, keyed by the Account Auth Token) - reimplemented in the listener's stdlib Python rather than depending on twilio-python, since pip/the package itself was not available in this fork's build environment and the daemon deliberately carries no dependencies. Verified byte-for-byte against Twilio's own documented canonical test vector.
    • From must additionally match the configured captain number even with a valid signature - defense in depth beyond "this Twilio account sent it."
    • ClickStack's and BetterStack's own behavior is unchanged when only their gates are present: both pre-existing suites still pass unmodified (a real regression from an unbound-variable bug in the shared cmd_serve config resolution was caught by re-running them and fixed before this PR).
  • New pieces, mirroring the ClickStack/BetterStack file set: bin/fm-captain-msg-lib.sh (config + speech contract + 1Password lookups), bin/fm-captain-msg.sh (the send tool), bin/fm-captain-msg-poll.sh (watcher check shim), bin/fm-captain-msg-arm.sh (always restarts the shared daemon on arm, since the Account Auth Token is fetched fresh from 1Password on every daemon start rather than cached), docs/captain-messaging.md (authority contract, speech contract, setup, config schema), .agents/skills/captain-msg-response/SKILL.md, tests/fm-captain-msg.test.sh.
  • Authority contract (docs/captain-messaging.md): a verified inbound reply carries the captain's authority for routine, reversible actions only, exactly like any other trusted channel - destructive/irreversible/security-sensitive actions still need the captain's explicit word elsewhere.
  • Two Twilio secrets are kept in separate 1Password items on purpose: Twilio API key (a Restricted API Key, for outbound sends) and Twilio Auth token (the Account Auth Token, for inbound signature validation) - Twilio always signs webhooks with the Account Auth Token, never an API key secret, so one credential cannot serve both purposes.
  • The account has no Messaging Service - the RCS sender is addressed directly by channel (CAPTAIN_MSG_FROM_ADDRESS, e.g. rcs:teslemetry_fwz8vdzw_agent), which also means the real inbound From Twilio sends is channel-prefixed (rcs:+<E.164>); the config schema and the inbound From-match both account for this (CAPTAIN_MSG_MESSAGING_SERVICE_SID stays supported as an alternative for an account that has one - exactly one of the two is required).

Live verification and smoke test

Read-only inspection of the real account (messaging.twilio.com/v1/Services, the account's own Messages.json) confirmed the no-Messaging-Service shape and the corrected 1Password item names above, and surfaced the account's own history: a prior bare-number send with no Messaging Service had failed, while rcs:-prefixed direct addressing succeeded and was read.
That evidence is what shaped the final config schema and the inbound-From fix.

The live smoke test was run for real with bin/fm-captain-msg.sh against the production sender and destination: sent: sid=SM86a3a59bbacd18d013bc58327c8c6ad4 status=queued, later confirmed status=delivered.
Nothing remains for the captain except pasting the webhook URL into the Twilio console and filling in config/captain-msg.env on the live instance (bin/fm-captain-msg-arm.sh --show-url prints the exact URL once armed) - see docs/captain-messaging.md "Setup".

Testing

  • tests/fm-captain-msg.test.sh (new, 31 cases): speech-contract accept/reject (URLs, markdown, code fences, over-length, empty), send-tool config/argument validation with op/curl mocked (no live Twilio calls), the CAPTAIN_MSG_FROM_ADDRESS/CAPTAIN_MSG_MESSAGING_SERVICE_SID exactly-one-of contract and their distinct request shapes, the real signature-validation algorithm against a live loopback listener (accept/reject/From-mismatch, with and without the rcs: prefix), idempotent inbox naming and atomic writes, the real fm-clickstack-recv.sh -> mocked-1Password -> listener chain, the poll shim, and bootstrap activate/opt-out/incomplete-config reporting.
  • tests/fm-clickstack.test.sh and tests/fm-betterstack.test.sh (pre-existing, unmodified): both still fully green, confirming no regression to the two routes already live in production.
  • bin/fm-lint.sh (shellcheck, the CI command): clean.
  • bin/fm-doc-audience-check.sh: clean, with docs/captain-messaging.md and docs/examples/captain-msg.env registered in docs/documentation-audiences.json.
  • One real send-and-receive-confirmed smoke test against production, described above.
Full narrative / original brief

FORK-ONLY: build firstmate's two-way captain messaging channel over Twilio RCS for Business. The captain provisioned it today: Twilio account credentials are in the 1Password CLI vault item "Twilio", the RCS sender is named "Teslemetry", a business sender with no phone number. His Android runs Google Messages (RCS-capable); his Tesla reads the phone's default messaging app aloud and takes dictated replies - that in-car experience is the product.

Read data/rcs-twilio-claude-scout/report.md first for the researched integration shape (twilio-python client + RequestValidator, adapt the fork's existing webhook-inbox-wake plumbing, build only thin send/receive surfaces); the RCS Business sender replaces that report's assumed AU mobile number.

Build: a send tool with a strict speech contract, an inbound webhook route mirroring the existing ClickStack/BetterStack pattern with Twilio signature validation, an authority-contract doc, colocated tests with no live Twilio calls, and one authorized live smoke send if the destination config exists.

Delivered fork-only, never upstreamed.

Bre77 added 2 commits July 28, 2026 20:51
…Business

Give the captain a text channel to firstmate that his Tesla can read aloud
and take dictated replies through, sharing the existing ClickStack/
BetterStack webhook receiver and durable wake-queue plumbing.
…inst the live account

Live read-only inspection (messaging.twilio.com, the account's own Messages.json)
confirmed the real account has no Messaging Service, uses the corrected
1Password item names, and that Twilio's actual inbound "From" is
channel-prefixed (rcs:+<E.164>), which the original inbound From-match would
have wrongly rejected. Adds CAPTAIN_MSG_FROM_ADDRESS as an alternative to
CAPTAIN_MSG_MESSAGING_SERVICE_SID (exactly one required) and strips the rcs:
prefix before comparing inbound From to the configured destination.
@Bre77
Bre77 merged commit fd0aa56 into main Jul 28, 2026
10 checks passed
Bre77 added a commit that referenced this pull request Jul 29, 2026
…#45)

* feat(provenance): label fleet PRs and drop Claude's co-author trailer

The captain's commits now carry a single identity everywhere, so fleet
work needs metadata-based provenance instead: an "fm" PR label (name
configurable via config/pr-label) applied once fm-pr-check.sh records
pr=, covering every delivery mode that opens a PR (no-mistakes,
direct-PR, fork-only) from one call site, degrading to a stderr
warning rather than ever losing a PR.

Claude Code injects its own Co-Authored-By trailer regardless of
AGENTS.md's no-agent-co-author rule; fm-spawn.sh now scopes
--settings '{"attribution":{"commit":""}}' to every claude
crewmate/secondmate launch, verified empirically against a real
self-drafted commit. Codex and opencode were checked and do not
inject an equivalent trailer in firstmate's actual launch shape; pi,
grok, and kimi were unavailable to check and are left unverified
rather than guessed at.

* fix(tests): restore the executable bit on fm-captain-msg.test.sh

Committed as mode 100644 by #42/#44, so bin/fm-fork-deliver.sh's local
gate (which execs each tests/*.test.sh directly) hits Permission
denied; real CI is unaffected since bin/fm-test-run.sh invokes tests
via `bash "$script"`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant