scripts/write-run-overrides

#!/usr/bin/env luajit
-- write-run-overrides
-- Stamp this run's command-line choices onto the shared notepad in RAM
-- (tmp/run-overrides.lua) so every helper program the pipeline launches
-- afterward reads the same answers -- the embedding model, especially.
--
-- General description (for a CEO): the pipeline runs as a series of separate
-- little programs. Before this existed, a flag like --model reached only the
-- programs run.sh remembered to hand it to, and the rest quietly used the
-- default from the config file -- so the website could be built half with one
-- model and half with another. This tool writes the operator's choices down in
-- one place, once, at the start of the run. It is written fresh every run, so a
-- choice from a previous run can never leak into this one.
--
-- Usage:
-- scripts/write-run-overrides DIR [--key value]...
-- e.g. scripts/write-run-overrides "$DIR" --model qwen3-embedding:4b
-- DIR defaults to the hard-coded project root; pass it (as run.sh does) to be
-- safe. Empty values are skipped: an absent key means "no override; use
-- config.lua", so --model "" correctly records no model override at all.

-- {{{ setup_dir_path(provided)
local function setup_dir_path(provided)
if provided and provided ~= "" then return provided end
return "/mnt/mtwo/programming/ai-stuff/neocities-modernization"
end
-- }}}

-- {{{ parse_args(args)
-- First bare (non --) argument is DIR; every "--key value" pair becomes an
-- override, skipping empty values so callers can pass through-unset flags
-- verbatim without building the argument list conditionally.
local function parse_args(args)
local dir = nil
local overrides = {}
local i = 1
while i <= #(args or {}) do
local a = args[i]
if a:sub(1, 2) == "--" then
local key = a:sub(3)
local value = args[i + 1] or ""
if value ~= "" then overrides[key] = value end
i = i + 2
else
if not dir then dir = a end
i = i + 1
end
end
return dir, overrides
end
-- }}}

local provided_dir, overrides = parse_args(arg)
local DIR = setup_dir_path(provided_dir)
package.path = DIR .. "/libs/?.lua;" .. DIR .. "/src/?.lua;" .. package.path
local runtime_overrides = require("runtime-overrides")
runtime_overrides.set_project_root(DIR)
runtime_overrides.write(overrides)