Commit Graph

6 Commits

Author SHA1 Message Date
alt-glitch
7defffc296 fix(lint): clear the findings ruff preview reports
Turning on ruff preview (needed for PLW1514, unspecified-encoding) also
widens some stable rules. Clearing what it reports first lets the config
change that enables it land with no ignore list:

- evals workers: 20 text-mode open() calls get encoding="utf-8".
- a2a and weixin adapters: legacy "# type:" comments become annotations.
- agent/lsp/client.py, gateway/run_turn.py: two prose comments started a
  line with "type:", which type checkers read as a type comment.
- sorted(x)[0] becomes min(x) (plugins_session_env, one test).
- test_plugin_session_fork: the attempts default is built per call
  instead of a shared list inside a tuple.

The pinned ruff 0.15.22 passes with today's config and with preview on.
2026-11-15 14:02:40 +05:30
unsupportedpastels
463abea009 fix(plugins): one plugin may declare its own session env name twice
The duplicate check refused any overlapping registration in a profile, so a
plugin calling ctx.register_session_env twice for the same name now failed
to load, where it used to load with the later registration's value winning.

Registrations now record their owning plugin (PluginContext passes its
plugin id). Only another plugin claiming a held name is refused, naming the
holder. One plugin's overlapping registrations stack as before: the later
live one's value wins, and disposing either leaves the other's value.
Registrations are keyed by a token again, as before.
2026-11-06 20:22:31 -05:00
unsupportedpastels
26e16e3834 fix(plugins): one plugin per session env name, and names stay in their own profile
ctx.register_session_env merged every registration with out.update, so two
plugins of one profile declaring the same name were a silent last-wins by load
order. The later registration is now refused with the usual conflict error
("session env 'PANE' is already registered by 'holder'"). Unload frees the
name; the same plugin reloading declares it again. The check lives in
hermes_cli/plugins_session_env.py: the holder is read from the scope's plugin
manager ownership ledger, so PluginContext is unchanged.

Declared names were also one process-wide set, so on a multiplexed gateway a
plugin of profile A stopped profile B's own `export NAME=...` from carrying to
B's next command. The names are now kept per profile scope; a scope's names
still stay excluded after its plugin unloads, as before.
2026-11-06 20:22:31 -05:00
alt-glitch
26874afd73 fix(plugins): an unloaded plugin's session env names stay out of shell snapshots
The snapshot exclusions came from the currently registered names. A value injected around a
registration (wrapper built before the plugin registered, env resolved after) could enter a
snapshot, and once the plugin unloaded its name was no longer excluded, so a later command could
restore another session's value. session_env_names() now returns every name declared in this
process, unloaded plugins' included. Found by Copilot on #142008.
2026-11-06 11:17:45 -05:00
alt-glitch
a964e46371 fix(plugins): session env names act on the inherited Windows variable
Windows environment names are case-insensitive and os.environ holds them upper-cased, so a
plugin name spelled `pane` neither unset the inherited `PANE` nor replaced it (the child got both).
On Windows the registry now keeps names upper-cased and maps each resolver key the same way, so the
child env, the shell-snapshot exclusions and the resolver results use one spelling. Found by
Copilot on #142008.
2026-11-06 11:17:45 -05:00
Siddharth Balyan
450ece86c4 feat(plugins): ctx.register_session_env gives each session's commands its own environment values
Tools run in the shared gateway, so a variable of the terminal or pane that
shows a conversation (a pane id, its socket) never reaches the commands the
agent runs for it. A plugin could only rewrite each `terminal` command with
`tool_request` middleware to prefix an `export`, which changes the command
text and does not cover every spawn.

`ctx.register_session_env(names, resolver)` declares the names and a
`resolver(session_id) -> {name: str | None}`. The child-env bridge
(`tools/environments/local.py::_inject_session_context_env`) calls the active
profile's resolvers with the child's own HERMES_SESSION_ID each time it builds
a local child env: terminal foreground and background, `execute_code`'s
`terminal()`, and the other children that already get HERMES_SESSION_*.
`None` unsets a name; an omitted name keeps the gateway's value.

- Names must be valid env names outside HERMES_*, so core session vars stay
  core's. Values pass the same internal-secret and provider-blocklist
  predicates as the scrub, so a plugin cannot put a credential back.
- LocalEnvironment keeps the declared names out of the shared bash snapshot
  (the existing save/restore + dump exclusion for passthrough names). Without
  that, the snapshot sourced before each command replaces the fresh value with
  a stale one when a session's pane changes or goes away.
- A resolver that raises is logged with its traceback and contributes nothing.
- Registrations are scoped to the plugin manager's profile and released on
  unload through the registration ledger.
- Remote backends (Docker, SSH, Modal) are out of scope: they do not receive
  session context vars today either.

The new registrar lives in the hermes_cli/plugins_session_env.py sibling; the
facade method is a delegate, offset by a duplicated docstring paragraph in
_delivery_manager so plugins.py does not grow.
2026-11-06 11:17:45 -05:00