j126: read bot settings from a .env file (default ./.env, --env-file flag, TR_ENV_FILE); file wins over shell leftovers, boot report labels (source: .env)

This commit is contained in:
2026-09-26 09:08:39 +02:00
parent 8e109bae0b
commit 2d8b7d7875
10 changed files with 495 additions and 6 deletions
+16 -4
View File
@@ -20,6 +20,7 @@
## printed, because unrelated variables may hold secrets or machine paths.
import std/[os, strutils, algorithm, times, sets]
import env_dotenv
import gun_harness/virtual_bullets
import gun_harness/selector
import movements/ram_decision
@@ -89,13 +90,19 @@ proc tieBreakName(t: TieBreakMode): string =
proc sourceOf(name: string): string =
## Parsed-value knobs go through `getEnv(name, "")`; an empty value means the
## shipped default, so a non-empty value is the only thing that counts as
## "from the env".
if getEnv(name, "").len > 0: "env" else: "default"
## "from the env". A value that came from the resolved .env file is labelled
## `.env` even though the file applied it with putEnv (so `getEnv` finds it).
if isFromEnvFile(name): ".env"
elif getEnv(name, "").len > 0: "env"
else: "default"
proc sourceOfPresence(name: string): string =
## Flags read with `existsEnv` are "from the env" whenever they are present,
## even if their value is "0" (presence is what the code tests).
if existsEnv(name): "env" else: "default"
## even if their value is "0" (presence is what the code tests). A value that
## came from the .env file is labelled `.env`.
if isFromEnvFile(name): ".env"
elif existsEnv(name): "env"
else: "default"
proc disabledGunsString(guns: HashSet[int]): string =
if guns.len == 0: return "none"
@@ -461,6 +468,8 @@ proc knownEnvNames*(): seq[string] =
"TR_TRACKER_PROBE", "TR_TRACKER_PROBE_PATH", "TR_VBULLET_ADMIT_ONLY",
"TR_POWER_LOG",
"TR_RESULT_LOG",
# the .env loader's own environment hook (TR_ENV_FILE names the file)
"TR_ENV_FILE",
"TR_RAM_OPPORTUNITY", "TR_RAM_OPP_DIST", "TR_RAM_OPP_MARGIN",
"TR_RAM_ABORT_DMG", "TR_RAM_PLAN", "TR_RAM_PLAN_DIST",
"TR_RAM_PLAN_MARGIN", "TR_RAM_PLAN_HITRATE", "TR_RAM_LOG",
@@ -609,6 +618,9 @@ proc printEnvReport*(ctx: EnvReportContext) =
return
echo "[env] === ENVIRONMENT (boot report) ==="
echo "[env] env file: ",
(if envFilePath().len > 0: envFilePath() & " (source: " & envFileSource() & ")"
else: "none")
printRawEnvironment()
printMistakeWarnings()
printEffectiveValues(ctx)