Overview
CareSupport’s runtime is composed of single-purpose scripts that handle message processing, polling, webhooks, review, and maintenance. All scripts import fromruntime/config.py for paths and settings.
Location: runtime/scripts/
Core Pipeline Scripts
sms_handler.py
The 13-step pipeline that processes inbound messages and generates responses.
Arguments:
--from- Phone number (E.164 format:+16517037981)--body- Message text--dry-run- Process without sending--service- Transport service (default:iMessage)
runtime/scripts/sms_handler.py:1
poll_inbound.py
Polls Linq for new inbound messages and processes them throughsms_handler.py.
This is the polling fallback. The preferred path is
webhook_receiver.py (push-based, real-time). Use polling only when webhooks aren’t available.- Lists recent inbound messages from Linq API
- Filters out already-processed messages (tracked by message ID)
- Processes each new message through
sms_handler.py - Sends responses via Linq
- Handles outreach to other family members
- Auto-registers outreach recipients in
routing.json
--once- Run once and exit (for cron)--interval- Seconds between polls (default: 15)
.processed_sids.json in runtime/scripts/
Location: runtime/scripts/poll_inbound.py:1
webhook_receiver.py
Real-time webhook receiver for Linq Partner API events.- HMAC-SHA256 signature verification
- Replay attack prevention (5-minute window)
- Routes through full
sms_handler.pyenforcement pipeline - Webhook event logging to
logs/webhooks/
message.created- New inbound messagemessage.updated- Message status changechat.created- New conversation started
role_filterpre-filters context by access levelphi_auditlogs every PHI access- Leakage post-check scans outbound messages
approval_pipelinegates medication/member changes
runtime/scripts/webhook_receiver.py:1
Transport Scripts
linq_gateway.py
Linq Partner API V3 client for iMessage-first messaging.create_chat(phone, message, service)- Start new conversationsend_message(chat_id, message)- Send to existing chatlist_chats()- Get all active conversationsget_messages(chat_id, limit)- Fetch message historystart_typing(chat_id)- Show typing indicatormark_as_read(chat_id)- Mark conversation as readsend_reaction(chat_id, message_id, reaction)- React to message
runtime/scripts/linq_config.json
runtime/scripts/linq_gateway.py:1
Review & Learning Scripts
review_loop.py
Rule-based conversation review that catches mechanical violations and generates findings.-
Mechanical tier (automated)
- Multi-question detection
- Forbidden phrase usage
- Skill violation patterns
-
Contextual tier (requires Opus)
- Agent contradicting itself
- Missing member context
- Flows with no protocol
--stage: Every run writes lessons to real files (mutations)
With --stage: Findings → staging/reviews/ (scratch pad, no mutations)
Arguments:
--since- Time window (2h,24h,7d)--family- Specific family ID--full- Include full transcript in output--stage- Write to staging (no production changes)--json- JSON output format--dry-run- Preview only
runtime/scripts/review_loop.py:1
review_staging.py
Staging environment for review testing - prevents production mutations during testing.reviews/ - Disposable test output
reviews/ - Disposable test output
- Accumulates with each
--stagerun - Cleared on
reset - You don’t care about most of these
saved/ - Curated material
saved/ - Curated material
- Reviews flagged as worth revisiting
- Survives resets
- Opus’s reading pile for proposals
proposals/ - Where Opus writes back
proposals/ - Where Opus writes back
- Future use for AI-generated improvements
- Markdown format (not schema)
- Can surface unexpected gaps
Location:
runtime/scripts/review_staging.py:1
Cron Scripts
heartbeat.py
48-hour lookahead scanner that readsfamily.md and returns alerts.
- Uncovered shifts - No one assigned or
status=uncovered - Med coverage gaps - Shift requires
med_admincapability but caregiver lacks it - Appointment logistics - Appointments within 48h missing transport or escort
- Tentative shifts - Shifts not confirmed
family.md, parses YAML schedule blocks, evaluates rules. Does NOT use AI - fully deterministic.
Output format:
runtime/scripts/heartbeat.py:1
maintenance.py
Garbage collection and validation forfamily.md.
| Section | Strategy |
|---|---|
| Schedule | Keep current + next 2 weeks. Past shifts removed. |
| Recent Events | Keep last ~50 entries. Oldest pruned first. |
| Active Issues | Resolved issues ([x]) removed. |
| Appointments | Past appointments removed. |
| Patterns | Manual review - not auto-pruned |
| Members | Manual review - not auto-pruned |
| Medications | Only pruned when discontinued |
- Members referenced in Schedule exist in Members section
- YAML blocks still parseable
- Required sections present
- No orphaned member references
family_editor backup/validate for safety.
Location: runtime/scripts/maintenance.py:1
Utility Scripts
prompt_builder.py
Assembles the system prompt for AI calls.SOUL.md- Agent identityruntime/learning/capabilities.md- CAN/CANNOT listruntime/learning/lessons.md- Corrections (max 20)- Filtered family context
- Access level constraints
runtime/scripts/prompt_builder.py:1
care_router.py
Model cost optimization - routes messages to appropriate tier.fast- Haiku 4.5 (simple queries, confirmations)reason- Sonnet 4.6 (scheduling, coordination)critical- Opus 4.6 (complex conflicts, sensitive situations)
runtime/scripts/care_router.py:1
session.py
Session management for cache reuse observability.runtime/scripts/session.py:1
reaction_handler.py
Handles message reactions (thumbs up/down for feedback). Location:runtime/scripts/reaction_handler.py:1
Configuration
runtime/config.py
Single source of truth for all paths and settings. Every runtime script imports from here.- All paths derived from
CARESUPPORT_ROOTenv var (defaults to/work) - No hardcoded absolute paths allowed
- Tested by
test_structural.py
runtime/config.py:1
Related
- Testing Guide - Test suites for runtime scripts
- Project Structure - Directory layout
- Enforcement Layer - Safety gates used by scripts