mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 23:21:08 +02:00
Two related AI-infrastructure hardenings landing together because both
touch the same nutriphi/planta route definitions:
═══ 1. Wire-format schema versioning ═══
Adds AI_SCHEMA_VERSION + AiResponseEnvelope<T> in @mana/shared-types so
every AI structured-output endpoint speaks a single envelope dialect:
{ schemaVersion: '1', data: <validated object> }
Backend wraps via a small `envelope()` helper in each module's routes.ts;
frontend api.ts unwraps via `unwrapEnvelope<T>()` which throws an
AiSchemaVersionMismatchError if the server returns a version this
client wasn't compiled against.
Why this matters before launch:
- Catches stale-cache scenarios immediately ("client v1 talking to
server v2") with an actionable error in the network panel, not a
cascade of "field is undefined" bugs further down the stack
- Forces explicit version bumps when we make non-additive schema
changes — the bump rules are documented inline next to the constant
- Cheap to remove if it ever feels overkill: drop the envelope() call
on the backend and the unwrapEnvelope on the frontend, ~10 lines
═══ 2. Anthropic prompt-caching directive (forward-compat) ═══
Adds `providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }`
on the system message in nutriphi + planta routes via a SYSTEM_CACHE_HINT
constant. This is a NO-OP today because:
- mana-llm currently routes to Gemini, not Claude
- Our system prompts are ~50 tokens, well under Anthropic's 1024-token
cache minimum
Kept anyway because it's ~5 lines per route and lights up automatically
when either condition flips (e.g. when we add per-user dietary preferences
as system context, pushing prompts past the threshold). The day we point
mana-llm at Claude Sonnet, every existing call site already has caching
enabled — no scavenger hunt through the routes.
System messages had to migrate from the `system:` shorthand to a full
messages[] entry to attach providerOptions, which is a tiny readability
loss but the only way to get per-message metadata into the AI SDK.
═══ Tests ═══
13 new cases in apps/mana/apps/web/.../nutriphi/ai-schemas.test.ts cover:
- AI_SCHEMA_VERSION presence + AiSchemaVersionMismatchError shape
- MealAnalysisSchema acceptance/rejection (confidence bounds, missing
nutrients, optional food fields, default empty arrays)
- PlantIdentificationSchema (every-field-optional design, defaults,
confidence range)
(Test file lives in the web app rather than packages/shared-types
because the latter has no test runner configured — adding vitest there
just for these would be overkill.)
Total nutriphi + planta suite: 62/62 passing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| launchd | ||
| backup-databases.sh | ||
| bootstrap.sh | ||
| build-app.sh | ||
| build-landings.sh | ||
| check-disk-space.sh | ||
| configure-ollama.sh | ||
| deploy-v2.sh | ||
| deploy.sh | ||
| ensure-containers-running.sh | ||
| health-check.sh | ||
| init-deploy-tracking.sql | ||
| memory-baseline.sh | ||
| migrate-to-colima.sh | ||
| move-colima-to-external-ssd.sh | ||
| notifications.env.example | ||
| push-schemas.sh | ||
| README.md | ||
| rebuild-tunnel.sh | ||
| restart.sh | ||
| setup-autostart.sh | ||
| setup-cloudflared-service.sh | ||
| setup-docker-logging.sh | ||
| setup-forgejo.sh | ||
| setup-notifications.sh | ||
| setup-ssh-client.sh | ||
| setup-umami-db.sh | ||
| startup.sh | ||
| status.sh | ||
| stop.sh | ||
| sync-tunnel-config.sh | ||
| tune-tcp.sh | ||
| weekly-report.sh | ||
Mac Mini Server Scripts
Scripts for managing the Mana production environment on Mac Mini.
Quick Start (After System Update)
# 1. SSH into Mac Mini (from your local machine)
ssh mac-mini
# 2. Navigate to project
cd ~/projects/mana-monorepo
# 3. Setup auto-start (only needed once)
./scripts/mac-mini/setup-autostart.sh
# 4. Check status
./scripts/mac-mini/status.sh
Scripts Overview
| Script | Purpose |
|---|---|
setup-autostart.sh |
Configure automatic startup on boot (run once) |
startup.sh |
Main startup script (called by launchd) |
health-check.sh |
Check all services health |
status.sh |
Show full system status |
restart.sh |
Restart all Docker containers |
stop.sh |
Stop all Docker containers |
deploy.sh |
Pull latest images and deploy |
First-Time Setup
1. Prerequisites on Mac Mini
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install required tools
brew install cloudflared git docker
# Install Docker Desktop
# Download from: https://www.docker.com/products/docker-desktop/
2. Clone Repository
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/Memo-2023/mana-monorepo.git
cd mana-monorepo
3. Configure Cloudflare Tunnel
# Login to Cloudflare
cloudflared tunnel login
# The tunnel is already created (ID: bb0ea86d-8253-4a54-838b-107bb7945be9)
# Credentials should be at: ~/.cloudflared/bb0ea86d-8253-4a54-838b-107bb7945be9.json
4. Configure Environment
# Copy and edit the environment file
cp .env.macmini.example .env.macmini
nano .env.macmini
5. Enable Auto-Start
# This sets up all launchd services
./scripts/mac-mini/setup-autostart.sh
6. Configure Docker Desktop
Open Docker Desktop and enable:
- Settings > General > Start Docker Desktop when you sign in
Daily Operations
Check Status
./scripts/mac-mini/status.sh
Run Health Check
./scripts/mac-mini/health-check.sh
Restart Services
# Normal restart
./scripts/mac-mini/restart.sh
# Pull latest images and restart
./scripts/mac-mini/restart.sh --pull
# Force recreate containers
./scripts/mac-mini/restart.sh --force
View Logs
# Startup log
tail -f /tmp/mana-startup.log
# Health check log
tail -f /tmp/mana-health.log
# Cloudflare tunnel log
tail -f /tmp/cloudflared.log
# Specific container logs
docker logs -f mana-auth
docker logs -f chat-backend
Stop Services
./scripts/mac-mini/stop.sh
LaunchD Services
Three services are configured to run automatically:
| Service | Label | Purpose |
|---|---|---|
| Cloudflared | com.cloudflare.cloudflared |
Tunnel to Cloudflare |
| Docker Startup | com.mana.docker-startup |
Start containers on boot |
| Health Check | com.mana.health-check |
Check every 5 minutes |
| STT Service | com.mana.stt |
Speech-to-Text (Whisper + Voxtral) |
Manual Service Control
# Check status
launchctl list | grep -E 'cloudflare|mana'
# Restart a service
launchctl kickstart -k gui/$(id -u)/com.mana.docker-startup
# Stop a service
launchctl unload ~/Library/LaunchAgents/com.mana.docker-startup.plist
# Start a service
launchctl load ~/Library/LaunchAgents/com.mana.docker-startup.plist
Troubleshooting
Docker not starting
# Check if Docker Desktop is running
docker info
# Start Docker Desktop manually
open -a Docker
Cloudflare tunnel not connecting
# Check cloudflared status
pgrep -x cloudflared
# View tunnel logs
tail -50 /tmp/cloudflared.log
# Restart tunnel
launchctl kickstart -k gui/$(id -u)/com.cloudflare.cloudflared
Container health check failing
# Check specific container
docker logs <container-name>
# Restart specific container
docker restart <container-name>
# Check database connectivity
docker exec mana-postgres pg_isready -U postgres
Services not starting on boot
# Re-run setup
./scripts/mac-mini/setup-autostart.sh
# Check launchd errors
launchctl error <exit-code>
# Verify plist files
plutil ~/Library/LaunchAgents/com.mana.*.plist
Push Notifications (Optional)
To receive notifications when health checks fail:
- Create a topic at ntfy.sh
- Add to your shell profile:
export NTFY_TOPIC=your-topic-name - Subscribe on your phone using the ntfy app
URLs
Once running, services are available at:
| Service | URL |
|---|---|
| Unified App | https://mana.how |
| Auth API | https://auth.mana.how |
| API Gateway | https://api.mana.how |
| Forgejo (Git) | https://git.mana.how |
| Grafana | https://grafana.mana.how |
| Status Page | https://status.mana.how |
| GlitchTip | https://glitchtip.mana.how |
| Umami | https://stats.mana.how |
| SSH | ssh mac-mini (via cloudflared) |
Native Services (non-Docker)
Ollama (LLM)
Ollama runs natively on Mac Mini for LLM inference:
# Check status
curl http://localhost:11434/api/tags
# List models
ollama list
# Pull a model
ollama pull gemma3:4b
AI Services (STT, TTS, LLM, Image-Gen, Video-Gen)
These have moved off the Mac Mini entirely. They run on the Windows GPU
server (mana-server-gpu) as Windows Scheduled Tasks. See
docs/WINDOWS_GPU_SERVER_SETUP.md
for setup, and the per-service services/mana-{stt,tts,llm,image-gen,video-gen}/CLAUDE.md
files for endpoint details.
Public URLs (proxied via Cloudflare Tunnel + the Mac Mini gpu-proxy):
https://gpu-stt.mana.howhttps://gpu-tts.mana.howhttps://gpu-llm.mana.howhttps://gpu-img.mana.howhttps://gpu-video.mana.how