; Process supervisor for the CoderAI distributable image.
; Starts nginx (public :8776) plus the main server and the bundled tool web UIs,
; all bound to localhost behind nginx. Logs go to stdout/stderr so `docker logs`
; shows everything.

[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
; pid + control socket under /tmp so the container runs as root OR `--user UID`.
pidfile=/tmp/supervisord.pid

[unix_http_server]
file=/tmp/supervisor.sock

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:coderai]
; The OCI launcher seeds /config and binds the main server to localhost:18776.
command=/usr/local/bin/coderai
environment=CODERAI_HOST="127.0.0.1",CODERAI_PORT="18776"
autostart=true
autorestart=true
startsecs=5
stopwaitsecs=30
priority=10
; Signal the whole process group so the front's engine subprocesses (and the
; optional `tee` used for file logging) stop/kill together with the launcher.
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:nginx]
command=/usr/sbin/nginx -c /etc/nginx/nginx.conf
autostart=true
autorestart=true
startsecs=3
priority=20
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

; Bundled demo tool web UIs. Each program's autostart is driven by an env var
; (CODERAI_TOOL_*) seeded with a default in the entrypoint, so the run script (or
; any `docker run -e`) can enable/disable individual demos at start — no rebuild.
[program:video_editor]
command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app/tools/video_editor.py
    --no-browser --host 127.0.0.1 --port 8420
    --base-url http://127.0.0.1:8776
    --config /cache/video_editor/video_editor.config.json
    --session --session-dir /cache/video_editor/sessions
    %(ENV_CODERAI_VIDEO_EDITOR_ARGS)s
directory=/opt/coderai/app
autostart=%(ENV_CODERAI_TOOL_VIDEO_EDITOR)s
autorestart=true
startsecs=5
startretries=5
priority=30
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:videogen]
command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app/tools/videogen.py
    --host 127.0.0.1 --web-port 7790
    --base-url http://127.0.0.1:8776
    --out-dir /cache/videogen_output
    %(ENV_CODERAI_VIDEOGEN_ARGS)s
directory=/opt/coderai/app
autostart=%(ENV_CODERAI_TOOL_VIDEOGEN)s
autorestart=true
startsecs=5
startretries=5
priority=30
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:township]
command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app/tools/gen_township_fighters.py
    --web-port 7788
    --base-url http://127.0.0.1:8776
    --out-dir /cache/township_output
    --config /cache/township_output/township_config.json
    %(ENV_CODERAI_TOWNSHIP_ARGS)s
directory=/opt/coderai/app
autostart=%(ENV_CODERAI_TOOL_TOWNSHIP)s
autorestart=true
startsecs=5
startretries=5
priority=30
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

; Parler-TTS runs in its OWN bundled venv (transformers 4.46, pinned). Its
; site-packages is prepended to PYTHONPATH so it shadows the main stack; torch and
; the rest resolve from the standalone Python's site-packages underneath — exactly
; the local --system-site-packages layering. Internal-only (not proxied by nginx);
; coderai reaches it via a TTS model config { "service_url": "http://127.0.0.1:8123" }.
; Disabled by default (CODERAI_TOOL_PARLER=false): enable with the run script's
; --enable-tool parler (or -e CODERAI_TOOL_PARLER=true) once a parler model is
; configured. Won't be fatal if the model isn't present.
[program:parler]
command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app/tools/parler_tts_service.py
    --model %(ENV_CODERAI_PARLER_MODEL)s --port 8123
    %(ENV_CODERAI_PARLER_ARGS)s
environment=PYTHONPATH="/opt/coderai/parler-venv/site-packages"
directory=/opt/coderai/app
autostart=%(ENV_CODERAI_TOOL_PARLER)s
autorestart=true
startsecs=10
startretries=3
priority=40
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
