Some checks failed
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
Docs Search Monitor / probe (push) Has been cancelled
* feat(pm): a launcher can name the install-state folder of its process A sandbox that runs Hermes on the host's own files grants the selected dependency environment read-only and nothing else of installs/<key>. On Windows the process inside still sees that folder, because it is an ancestor of a grant, while reading facts.json and taking the install lock are refused. Start-up took that for an install state it has to use and ended with "install state is not writable by this user", so a sandbox on an installer-made Hermes on Windows did not start. HERMES_INSTALL_STATE_DIR names the folder a process and its children keep their install state in. A process started with it runs on the interpreter it was given: it selects no environment, from the install's own state or from the named folder, it is not restarted on another interpreter, and it writes nothing into the install's own state. A Linux sandbox gets the same from a mount of an empty folder over installs/<key>; Windows has no mount. * fix(pm): start-up reads nothing from a folder a launcher named A process whose launcher named its install-state folder still acted at start on that folder and on the checkout's markers: - An update that stopped half way leaves .update-incomplete in the checkout. The process ran the repair, which builds into the named folder, and cleared the marker the install's own next start needs. - A publication.json placed in the named folder, which the process can write, was replayed: it could put a config.yaml back, and a damaged one ended the start. Start-up now takes the path of a process with no install state: no lock, no journal, no recorded selection, and the named folder is left as it is. A sealed install still selects the environment its manifest names, which is part of its tree. * fix(env): the install-state folder a launcher named is launch-only A .env line that names HERMES_INSTALL_STATE_DIR replaced the launcher's value when the file was loaded, after start-up, and every later lock and marker went to the other folder. The same line made the variable residue of the launch profile, so a worker started for another profile lost it. The variable joins LAUNCH_ONLY_ENV_KEYS: no .env, secret source or .env writer sets it. * fix(pm): refuse to build an environment no process would select In a process whose launcher named its state folder, `hermes pm install --extra` built an environment in that folder and reported it installed. No process selects an environment recorded there. `hermes pm repair` did the same, and counted a failed attempt against the install's marker. Both entries of the venv sync (pm.client, pm.install) and the explicit repair now refuse first and say why. * docs(reference): what a named install-state folder does The row for HERMES_INSTALL_STATE_DIR says what start-up leaves alone, which commands are refused, that a sealed install keeps the environment it ships, that the variable is launch-only, and that the launcher keeps the interpreter's environment in place while the process runs.
68 lines
4.6 KiB
Python
68 lines
4.6 KiB
Python
"""The environment the kanban dispatcher hands its worker client: an allowlist, not a scrub.
|
|
|
|
The client (``hermes_cli.kanban_worker_client``) only submits a claim to the assignee's gateway and
|
|
waits for the receipt. When that gateway is not running, the client starts it, and the daemon is
|
|
built from the client's own environment plus the assignee's secrets
|
|
(``gateway_runtime_start`` -> ``served_profile_child_env``). Anything else the client carries
|
|
therefore reaches the assignee's turns, and an overlay can replace a value but never remove one. A
|
|
scrub of the dispatcher's environment only catches the names it knows (provider keys, the
|
|
dispatcher's ``terminal.env_passthrough``); a token systemd or ``op run`` injected under any other
|
|
name went through. So the dispatcher's environment is reduced to host process plumbing and
|
|
Hermes' own location before the dispatcher adds the claim.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Mapping
|
|
|
|
# Exact names (Windows matches case-insensitively). Host plumbing, never a profile's settings.
|
|
_HOST_NAMES = frozenset({
|
|
"PATH", "HOME", "USER", "LOGNAME", "SHELL", "TERM", "TZ", "LANG", "LANGUAGE",
|
|
"TMPDIR", "TMP", "TEMP", "PYTHONPATH", "PYTHONUTF8", "PYTHONIOENCODING", "VIRTUAL_ENV", "CONDA_PREFIX",
|
|
# The user systemd manager (a gateway started from a system unit still scopes its children).
|
|
"DBUS_SESSION_BUS_ADDRESS", "SUDO_USER",
|
|
# The login session's agent and display sockets (git over ssh, browser/computer-use tools).
|
|
"SSH_AUTH_SOCK", "DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY",
|
|
# TLS trust and proxies are the host's network, which a cold-started gateway needs to reach a provider.
|
|
"SSL_CERT_FILE", "SSL_CERT_DIR", "REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE", "NODE_EXTRA_CA_CERTS",
|
|
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
|
|
# Windows: without these the CRT cannot open a socket or resolve cmd.exe.
|
|
"SYSTEMROOT", "SYSTEMDRIVE", "WINDIR", "COMSPEC", "PATHEXT", "OS", "PROCESSOR_ARCHITECTURE",
|
|
"NUMBER_OF_PROCESSORS", "PUBLIC", "ALLUSERSPROFILE", "PROGRAMDATA", "PROGRAMFILES",
|
|
"PROGRAMFILES(X86)", "PROGRAMW6432", "APPDATA", "LOCALAPPDATA", "USERPROFILE", "USERDOMAIN",
|
|
"USERNAME", "HOMEDRIVE", "HOMEPATH", "COMPUTERNAME", "PROCESSOR_ARCHITEW6432",
|
|
# Hermes' own location, install and host policy, read before any profile config loads: the
|
|
# host-wide gateway lock directory (else a cold-started gateway takes a different "host" lock),
|
|
# the no-install policy, the state folder a launcher named, and the shared board root and its
|
|
# lock's busy timeout.
|
|
"HERMES_HOME", "HERMES_REAL_HOME", "HERMES_SCRATCH_DIR", "HERMES_RUNTIME_DIR", "HERMES_INSTALL_ROOT",
|
|
"HERMES_PYTHON_SRC_ROOT", "HERMES_DATA_DIR_SUFFIX", "HERMES_HOME_MODE", "HERMES_MANAGED",
|
|
"HERMES_CONTAINER", "HERMES_SKIP_CHMOD", "HERMES_GATEWAY_LOCK_DIR", "HERMES_DISABLE_LAZY_INSTALLS",
|
|
"HERMES_INSTALL_STATE_DIR", "HERMES_KANBAN_HOME", "HERMES_KANBAN_BUSY_TIMEOUT_MS",
|
|
# The administrator-managed scope directory (an IT bootstrap override, never in any profile's
|
|
# ``.env``): without it a cold-started gateway loses the managed overlay stored elsewhere.
|
|
"HERMES_MANAGED_DIR",
|
|
# The XDG base directories by exact name (state: the host gateway lock; config: the package
|
|
# index). Not the XDG_ prefix: XDG_ACTIVATION_TOKEN and any user-chosen XDG_* name can be a secret.
|
|
"XDG_RUNTIME_DIR", "XDG_STATE_HOME", "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "XDG_DATA_HOME",
|
|
"XDG_DATA_DIRS", "XDG_CACHE_HOME",
|
|
# Termux detection (hermes_platform.host.runtime).
|
|
"PREFIX", "TERMUX_VERSION",
|
|
})
|
|
_HOST_PREFIXES = ("LC_",)
|
|
|
|
|
|
def worker_client_env(env: Mapping[str, str], assignee_home: str | Path) -> dict[str, str]:
|
|
"""*env* reduced to what the worker client for *assignee_home*, and a gateway it starts, may take
|
|
from the host. The launch profile's ``.env`` / source residue goes first: an allowlisted name it
|
|
defines (an ``HTTPS_PROXY`` with credentials in the URL) is that profile's, not the host's."""
|
|
from hermes_cli.config_backend import deployment_env_names
|
|
from tools.environments.local import strip_launch_profile_env
|
|
host = strip_launch_profile_env(dict(env), assignee_home)
|
|
# The config backend's deployment (which backend, plane and instance) is the instance's, not a
|
|
# profile's; without it the assignee's gateway reads its config from the file backend. Its
|
|
# credential is not part of it: the assignee resolves its own and fails closed without it.
|
|
names = _HOST_NAMES | {name.upper() for name in deployment_env_names()}
|
|
return {k: v for k, v in host.items() if k.upper() in names or k.upper().startswith(_HOST_PREFIXES)}
|