Skip to content

Forward login-shell env vars (bashrc/zshrc exports) to harness children - #330

Open
labkita7 wants to merge 1 commit into
zeronsh:mainfrom
labkita7:hoplite/sybaris-c04e0061
Open

Forward login-shell env vars (bashrc/zshrc exports) to harness children#330
labkita7 wants to merge 1 commit into
zeronsh:mainfrom
labkita7:hoplite/sybaris-c04e0061

Conversation

@labkita7

@labkita7 labkita7 commented Sep 11, 2026

Copy link
Copy Markdown

Problem

When zeron runs as a headed app (Dock/Finder/launchd/systemd), the daemon never runs shell init, so harness children inherit a minimal environment. The login-shell snapshot (crates/harness/src/shell_env.rs) already fixes PATH resolution — but it kept only PATH and dropped every other export. Provider CLIs behind the harnesses (pi via pi-acp, and the rest) that read custom variables configured in ~/.bashrc / ~/.zshrc — API keys, base URLs, proxy settings — therefore failed even though the same CLIs work fine from the user's terminal.

Fix

  • The snapshot now keeps the full environment dumped between the markers (LoginShellEnv { path, vars }), with the same hostile-init defenses (last-begin-marker parse, PATH-presence validity gate, probe-marker drop).
  • compose_path — the single choke point every harness child spawn goes through (pi/ACP, Claude, Codex, Cursor, opencode, npm adapter installs, engine git/gh) — now also forwards snapshot variables the daemon's own environment doesn't already define. Explicit process env always wins; PWD/OLDPWD/SHLVL/_ and the probe's own ZERON_RESOLVING_ENVIRONMENT / TERM=dumb pairs are never forwarded.
  • ZERON_NO_LOGIN_SHELL_ENV=1 opts out of variable forwarding while keeping the PATH composition (ZERON_NO_LOGIN_SHELL=1 still disables the snapshot entirely).

Verification

  • cargo test -p zeron-harness --tests: 13 test binaries, 207 passed, 0 failed (10 ignored real-lifecycle tests by design).
  • New/extended tests:
    • unit: full-env parse (PATH excluded from vars), probe-pair dropping, duplicate keys, no-PATH dumps rejected, fake-shell end-to-end snapshot;
    • shell_env_resolution e2e: a var exported by the fake login shell reaches a spawned child command, an existing process var is not overridden, the probe marker never leaks.
  • cargo fmt --check clean for the touched files; remaining clippy/fmt findings in the crate are pre-existing on main (unrelated files, not touched here).

Open in Hoplite


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

GUI/service launches never run shell init, so the login-shell snapshot
is the daemon's only view of the user's environment — but it kept only
the PATH, dropping every other export. Provider CLIs (pi-acp and the
rest) that read custom variables configured in ~/.bashrc or ~/.zshrc
(API keys, base URLs, proxies) therefore failed under the headed app.

The snapshot now keeps the full environment between the markers and
compose_path forwards variables the daemon's own env doesn't already
define (explicit process env always wins; shell bookkeeping and the
probe's own markers are never forwarded). ZERON_NO_LOGIN_SHELL_ENV=1
opts out while keeping the PATH composition.

Co-authored-by: fajar sidik <jardik.oryza@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant