meshai/work/docker-entrypoint.sh
malice 3c900091d7
docs: point onboarding at the dashboard; drop 3 phantom keys from the seeded default (#147)
* fix(entrypoint): drop three phantom history keys from the seeded default

The config written on first boot -- what EVERY fresh Docker install starts
from -- seeded three keys that do not exist on HistoryConfig and are
silently discarded on load:

    auto_cleanup: true
    cleanup_interval_hours: 24
    max_age_days: 30

HistoryConfig has only `database`, `max_messages_per_user`, and
`conversation_timeout`.

To be precise about the impact: history cleanup DOES work -- cleanup_expired()
is wired at main.py:237 and _prune_history() honours max_messages_per_user.
What never existed is the time-based retention model these keys describe (a
30-day age cutoff on a 24h interval). An operator setting max_age_days: 90
expecting 90-day retention was silently ignored.

Not implemented here -- whether time-based retention should exist is a
product decision, not a cleanup. This only stops the default config
promising it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs: point onboarding at the dashboard, not the legacy example config

The documented setup path was `cp config.example.yaml config.yaml`, but that
file is ~40% incomplete: of the 20 top-level Config fields it covers 15,
omitting coverage (the universal bbox), danger_zones, generic_sources,
meshcore_context, commands, and the current notification model
(toggles/destinations/region_routes). Its own notifications header still says
the schema "will be replaced in v0.3 by the 8-toggle model" -- which shipped
long ago. Anyone following the project's own instructions landed on a
degraded surface with no signal a richer config existed.

It is also read by NOTHING at runtime: docker-entrypoint.sh sets
MESHAI_CONFIG=/data/config.yaml and writes its own inline default on first
boot. The Dockerfile still COPYs config.example.yaml into the image, so it is
kept and now labelled reference-only rather than a starting point.

- README: Docker quick-start seeds itself; configure via the dashboard. The
  pip path still uses config.example.yaml (nothing seeds one there) but now
  carries an honest note that it is a minimal bootstrap, not a reference.
  Adds an Advanced section for the split /data/config/ layout and the
  migrate_config_v03 path into it.
- docker-compose.yml: the comment claimed config lives at /data/config.yaml
  as though that were the only layout; corrected to describe both, and note
  secrets live in /data/secrets/.env.
- Dockerfile: document why config.example.yaml is still shipped.

Not done deliberately: config.example.yaml is NOT expanded to cover all 20
sections. A second hand-maintained schema is what caused this drift; the
dashboard is the authoritative surface. The legacy single-file loader is
untouched and still fully supported.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(readme): move dashboard-first onboarding rewrite to root README

work/README.md is about to become a symlink to root README.md on
docs/single-readme. Retarget the Docker/dashboard-first quick start
and config.example.yaml honesty note added in be867d23 from
work/README.md to root README.md, adapted to the root file's own
Quick start structure (cd meshai/work, /work/-prefixed curl URLs), so
none of it is silently dropped when that symlink lands.

---------

Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 14:07:31 -06:00

116 lines
2.8 KiB
Bash
Executable file

#!/bin/bash
# MeshAI Docker Entrypoint
# Writes a default config on first run, then runs the bot
export MESHAI_CONFIG="/data/config.yaml"
export TERM="${TERM:-xterm-256color}"
# First run - no config exists, create defaults
if [ ! -f "$MESHAI_CONFIG" ]; then
mkdir -p /data
cat > "$MESHAI_CONFIG" << 'EOF'
# MeshAI Configuration
# Edit this file directly, or configure via the dashboard
bot:
name: ai
owner: ""
respond_to_dms: true
filter_bbs_protocols: true
connection:
type: tcp
serial_port: /dev/ttyUSB0
tcp_host: localhost
tcp_port: 4403
response:
delay_min: 2.2
delay_max: 3.0
max_length: 150
max_messages: 2
history:
database: /data/conversations.db
max_messages_per_user: 50
conversation_timeout: 86400
memory:
enabled: true
window_size: 4
summarize_threshold: 8
context:
enabled: true
observe_channels: []
ignore_nodes: []
max_age: 1209600
max_context_items: 20
llm:
backend: openai
api_key: ${GOOGLE_API_KEY} # secret: set via dashboard or /data/secrets/.env
base_url: https://api.openai.com/v1
model: gpt-4o-mini
timeout: 30
system_prompt: >-
You are a helpful assistant on a Meshtastic mesh network.
Keep responses VERY brief - under 250 characters total.
Be concise but friendly. No markdown formatting.
google_grounding: false
meshmonitor:
enabled: false
inject_into_prompt: true
EOF
mkdir -p /data/secrets
[ -f /data/secrets/.env ] || : > /data/secrets/.env
echo "Default config created at $MESHAI_CONFIG. Edit it or configure via the dashboard."
fi
# Kill bot gracefully with SIGKILL fallback
kill_bot() {
local pid=$1
if ! kill -0 "$pid" 2>/dev/null; then
return
fi
kill "$pid" 2>/dev/null || true
echo "Sent SIGTERM to bot (PID $pid)"
# Wait up to 5 seconds for graceful shutdown
for i in 1 2 3 4 5; do
kill -0 "$pid" 2>/dev/null || return
sleep 1
done
# Force kill if still alive
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid" 2>/dev/null || true
echo "Sent SIGKILL to bot (PID $pid)"
fi
}
# Start the bot in a loop with integrated restart watcher
echo "Starting MeshAI..."
rm -f /tmp/meshai_restart
while true; do
python -m meshai -v --config-file "$MESHAI_CONFIG" &
BOT_PID=$!
echo "$BOT_PID" > /tmp/meshai.pid
echo "Bot started (PID $BOT_PID)"
# Poll: wait for bot to exit OR restart signal
while kill -0 $BOT_PID 2>/dev/null; do
if [ -f /tmp/meshai_restart ]; then
rm -f /tmp/meshai_restart
echo "Restart signal received, restarting bot..."
kill_bot $BOT_PID
break
fi
sleep 1
done
wait $BOT_PID 2>/dev/null || true
rm -f /tmp/meshai.pid
echo "Bot exited. Restarting in 3s..."
sleep 3
done