township: auto-load mapped township_config.json in the bundled launcher

The bundled township tool (supervisord [program:township]) launched without
-c/--config, so a township_config.json bind-mounted via --map into
/cache/township_output was never read — the web UI came up with blank API key /
league upload credentials / options every restart.

* supervisord: pass --config /cache/township_output/township_config.json so a
  mapped config auto-loads. Map the bare-metal dir with
    coderai-docker --map /path/to/township_output:/cache/township_output
  and the saved settings + credentials come up automatically.
* gen_township_fighters.py: a MISSING --config file is no longer fatal (fresh
  install with no mapped dir) — fall back to defaults and start normally; a
  malformed config still errors. The web UI's Save already writes back to
  <out-dir>/township_config.json, so first-run saves persist into the mapped dir.

Bump version to 0.1.4.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RdMufYvtTbtGDWsiZVoXce
parent 707c89bb
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# Canonical product version for CoderAI — single source of truth. Both the API # Canonical product version for CoderAI — single source of truth. Both the API
# metadata and the admin web UI read from here. # metadata and the admin web UI read from here.
__version__ = "0.1.3" __version__ = "0.1.4"
# Configure the CUDA caching allocator BEFORE torch is imported anywhere. # Configure the CUDA caching allocator BEFORE torch is imported anywhere.
# expandable_segments lets the allocator return freed pages to the driver even # expandable_segments lets the allocator return freed pages to the driver even
......
...@@ -83,6 +83,7 @@ command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app ...@@ -83,6 +83,7 @@ command=/usr/local/bin/with-env /opt/coderai/python/bin/python3 /opt/coderai/app
--web-port 7788 --web-port 7788
--base-url http://127.0.0.1:18776 --base-url http://127.0.0.1:18776
--out-dir /cache/township_output --out-dir /cache/township_output
--config /cache/township_output/township_config.json
directory=/opt/coderai/app directory=/opt/coderai/app
autostart=%(ENV_CODERAI_TOOL_TOWNSHIP)s autostart=%(ENV_CODERAI_TOOL_TOWNSHIP)s
autorestart=true autorestart=true
......
...@@ -11473,10 +11473,19 @@ OUTPUT LAYOUT ...@@ -11473,10 +11473,19 @@ OUTPUT LAYOUT
if pre.config: if pre.config:
try: try:
cfg = load_config(pre.config) cfg = load_config(pre.config)
except FileNotFoundError:
# A missing config is not an error: the bundled launcher always passes
# --config <out-dir>/township_config.json so a mapped config auto-loads,
# but on a fresh install (no mapped dir) the file simply isn't there yet
# — fall back to defaults instead of failing to start.
cfg = {}
_log(f" Config {pre.config} not found — starting with defaults "
f"(it'll be created when you Save from the web UI)")
except Exception as e: except Exception as e:
parser.error(f"cannot load config {pre.config}: {e}") parser.error(f"cannot load config {pre.config}: {e}")
parser.set_defaults(**cfg) if cfg:
_log(f" Loaded {len(cfg)} option(s) from config: {pre.config}") parser.set_defaults(**cfg)
_log(f" Loaded {len(cfg)} option(s) from config: {pre.config}")
args = parser.parse_args() args = parser.parse_args()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment