Load ~/hero/cfg/env/*.env at supervisor startup (#109) #110

Merged
timur merged 1 commit from issue-109-path-root-env into development 2026-05-20 05:55:14 +00:00
Owner

Closes #109. New hero_proc_server::env_load module scans ~/hero/cfg/env/*.env at startup, parses export K=V style, injects via std::env::set_var only when key is unset (shell overrides win). HERO_CFG_ENV_DIR override for tests. set_var runs pre-tokio (2024-edition safety). 7/7 unit tests pass; cargo check clean.

Closes #109. New hero_proc_server::env_load module scans ~/hero/cfg/env/*.env at startup, parses `export K=V` style, injects via std::env::set_var only when key is unset (shell overrides win). HERO_CFG_ENV_DIR override for tests. set_var runs pre-tokio (2024-edition safety). 7/7 unit tests pass; cargo check clean.
fix(hero_proc_server): load ~/hero/cfg/env/*.env at startup (#109)
All checks were successful
Tests / test (pull_request) Successful in 3m31s
Build and Test / build (pull_request) Successful in 7m1s
72849b8697
`hero_proc_server` spawns child processes via `tokio::process::Command`
without calling `env_clear()`, so children inherit the supervisor's
environment. The bug surfaces when the supervisor itself is launched
without HERO_* env vars in its own environment (e.g. via `screen`,
`systemd`, or a non-login shell that did not source ~/hero/cfg/env/*.env).
Children then panic at startup because PATH_ROOT / HERO_SOCKET_DIR / etc.
are missing.

This change adds `hero_proc_server::env_load`, which at startup scans
~/hero/cfg/env/*.env, parses each file as a minimal shell-style env file
(supports `export KEY=VALUE`, `KEY=VALUE`, comments, blanks, and
surrounding single/double quotes), and injects every assignment into the
supervisor's own env via `std::env::set_var` — but only if the key is
NOT already set, so an explicit override in the invoking shell still
wins. Once the supervisor's env is populated, the existing fork path
inherits naturally, so no change to the spawn code is needed.

`HERO_CFG_ENV_DIR` overrides the dir for tests. The `set_var` call runs
before tokio spawns threads, matching the 2024-edition safety contract.

Includes unit tests for the parser (basic export, quoted values,
comments, inline trailing comments, invalid keys, and the
"existing-value-wins" precedence rule).

Refs: hero_proc#109; discovered in hero_skills#261.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
timur merged commit e038ed208d into development 2026-05-20 05:55:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_proc!110
No description provided.