Commit Graph

198 Commits

Author SHA1 Message Date
Alexander Russell
962f885501 fix(code-execution): per-call launch keeps the session cwd out of its scratch dir
The per-call execute_code launch ran `cd <scratch> && ( ... )` in the session
wrapper's own shell, so the wrapper's cwd marker made the scratch dir env.cwd.
The cleanup then deletes that dir from "/", and the new restore in
BaseEnvironment.execute puts env.cwd back to it: every later file op on the
sandbox, an absolute read_file included, fails at `cd` with "working directory
... does not exist". Doing the `cd` inside the subshell leaves env.cwd alone.

(cherry picked from commit 2dd00f2e45409d3cbee8dba5207ff9cc9e1449c2)
2026-11-17 10:29:07 -08:00
alt-glitch
d2480ea076 refactor(code-files): inline _ship_file_to_remote, move the kernel kill into code_kernel
_ship_file_to_remote was _remote_write(..., check=True) under another
name; its five call sites (code_execution_tool, code_kernel_remote) call
_remote_write with check=True directly. code_kernel_remote now imports
_remote_write, _execute_checked and _private_dirs_cmd from
code_execution_rpc at module top, which drops two function-level imports
back into the tool file.

_kill_process_group lived in code_execution_tool but its one caller is
SessionKernel.teardown in code_kernel, which always passed escalate=True.
It moves to code_kernel without the parameter (always SIGTERM, wait 5s,
SIGKILL), with signal and agent.deadline imported at module top. The
escalate=False branch was reached only by tests.

Tests patch _remote_write in both modules where they patched the wrapper.
test_code_kernel_owned_group stubs the teardown kill to a SIGTERM-only
tree kill for its precondition instead of passing escalate=False.
2026-11-16 21:55:16 +05:30
alt-glitch
782e0b42c9 refactor(code-files): delete unreached sandbox gate, checkpoint helpers, py shell linter
Removed. A search for callers by name, attribute and string (Python, TypeScript,
docs, the plugin API list and the frozen old-updater list) finds no supported
path that reaches any of them:

- tools/code_execution_tool.py::SANDBOX_AVAILABLE (constant True) and its
  two `if not SANDBOX_AVAILABLE` branches; the duplicated gateway-lifecycle
  comment in execute_code
- tests: test_windows_returns_error (only flipped the constant) and the
  constant's monkeypatch in test_execute_code_lifecycle_guard_deadline
- tools/checkpoint_manager.py: the no-op `store = _store_path(base)` /
  `_ = store` pair in _migrate_legacy_store; unused imports
  clear_stale_tmp_packs, rmtree_readonly, Dict, List, Set, Tuple;
  _list_project_refs (test-only) and its one assertion
- hermes_cli/cli_auto_maintenance.py::_run_checkpoint_auto_maintenance
  (imported by cli.py, never called), its cli.py import, its orphaned
  `threading` import and its no-op test monkeypatch
- tools/file_operations.py::ShellFileOperations._run_python_snippet
- tools/file_operations_lint.py: the '.py' entry in LINTERS (the in-process
  LINTERS_INPROC['.py'] always answers first)

- test_profile_rename_checkpoints: assert the migrate-identity retry deletes the leftover old checkpoint ref (via _ref_tip), replacing the deleted _list_project_refs check.
- docs(checkpoints-and-rollback): auto-prune runs only on the gateway housekeeping tick; the CLI never runs it.
2026-11-16 15:22:48 +05:30
Maciej Lisiewski
fa0fdfe0dd Merge pull request #155468 from NousResearch/sec3/122024-redact-exec-spill
fix(code-execution): redact and privatize execute_code stdout spills
2026-11-15 01:14:30 +01:00
Maciej Lisiewski
d3facb6a61 Merge pull request #155502 from NousResearch/sec3/146582-exec-code-lifecycle-guard-literals
fix(code-exec): don't refuse cells that only mention a gateway restart
2026-11-14 22:25:49 +01:00
Maciej Lisiewski
9582474d5f fix(code-execution): keep group bits when tightening an existing cache/exec
ensure_spill_dir(private=True) chmods an existing leaf to exactly 0700, which
strips group access a shared-group home (HERMES_HOME_MODE=2770) granted.
keep_group=True drops only the world bits; a new dir is still 0700 and spill
files are still 0600.

Refs #122024
2026-11-14 21:02:31 +01:00
beardthelion
ad63dc4e5c fix(code-execution): sanitize stdout spills and harden spill-path handling
Oversized execute_code stdout is spilled to disk so the model can page it
with read_file, but both spill emitters wrote raw output: the host-side
_spill_full_stdout spilled before _clean_output's ANSI strip + secret
redaction, and the session-kernel runner wrote cell stdout into its tmpdir
with a plain open() that follows symlinks. The result warning then directs
the model to read the file, so the on-disk copy kept credentials the inline
result masked.

- _spill_full_stdout now ANSI-strips and redacts (code_file=True) before
  writing, and uses ensure_spill_dir + default-private
  write_text_exclusive: 0700 dir, 0600 file, symlink-safe create/replace.
  The stale bind-mount rationale is corrected: cache/exec is not in
  credential_files._CACHE_DIRS and is never mounted into remote backends.
- The generated kernel runner spills via O_CREAT|O_EXCL|O_NOFOLLOW at 0600,
  so a cell squatting cell_NNNNNN_stdout.txt with a symlink cannot redirect
  the write onto a host file.
- _cell_result re-publishes runner-side spills through _spill_full_stdout
  instead of advertising the tmpdir path. _sanitize_cell_spill confines the
  read to a resolved direct child of the kernel tmpdir (dir_fd-anchored,
  realpath gate, O_NONBLOCK, regular-file and size cap), so a forged reply
  frame or swapped-in FIFO/huge file cannot block the host under kernel.lock
  or redirect the read/unlink outside the sandbox. The raw tmpdir copy is
  removed on every outcome, and the published cache/exec path survives the
  kernel teardown that follows sys.exit() cells.
- On republish failure the warning names the host-side partial spill
  explicitly rather than leaving a path it contradicts.
- Shared _sanitize_output_text helper replaces four open-coded copies of
  the ANSI-strip + redact pipeline.

Tests: real-kernel e2e for both emitters (masked on disk, ANSI-stripped,
0600 in 0700), symlink-squat e2e proving a planted link is not followed,
sys.exit() teardown survival, FIFO/link/../ confinement, oversized swap
rejection, and fail-closed fallback semantics. The kernel e2e places the
secret past the runner's 1MB clip so the published file can only come from
the runner spill, not the host-side fallback.
2026-11-14 21:02:30 +01:00
Maciej Lisiewski
2fbd502eed Merge pull request #155493 from NousResearch/sec3/145870-nested-tool-session-id
fix(execute_code): forward session/turn identity to nested tool calls
2026-11-14 19:15:57 +01:00
Maciej Lisiewski
ca0ec761f7 fix(code-exec): redact the remote kernel's error field; pin redact_code_output's keep paths
The remote runner's `error` (last traceback line) skipped redact_code_output
while the same text in `output` was masked. New tests cover the non-secret
env-line gate, quote/inline-assignment shape and the redaction-off switch.

Refs #95509

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-14 16:10:52 +01:00
Maciej Lisiewski
e768d80f84 fix(code-exec): mask whole multi-word env values; redact remote output before the cap
An env-dump line is one assignment, so mask its full value (quoted or raw)
instead of _ENV_ASSIGN_RE's first \S+ word. The remote _clean_output now strips
ANSI and redacts before _truncate_stdout_text, as the local kernel already does,
so the head/tail cut cannot separate DB_PASSWORD= from its value.

Refs #95509
2026-11-14 16:10:52 +01:00
Maciej Lisiewski
ed828d4c5e fix(code-exec): mask env-dump lines in execute_code output
execute_code redacted stdout/stderr with code_file=True, which skips the
ENV-assignment pass, so a script printing .env-style lines
(MY_SERVICE_TOKEN=<opaque>) returned prefix-less credentials raw. The
terminal tool picks the pass from the command line; execute_code has no
command, so classify by output shape instead: whole lines of
[export ]NAME=value get the ENV-assignment pass, everything else keeps
code_file=True (MAX_TOKENS = 100, indented source, f-strings unchanged,
per #43025). Applied to the shared remote pipeline and the local kernel.

Fixes #95509
2026-11-14 16:10:51 +01:00
Maciej Lisiewski
8d0513202d fix(execute_code): let documentation-only cells mention lifecycle commands
A cell that only prints or writes text quoting a gateway lifecycle command was
refused with no hint of what matched. Allow a cell whose parsed code provably
cannot start or signal a process (pure-module imports only, no process-like
attributes, every name a builtin or bound in the cell); every other cell is
scanned exactly as before. The refusal now names the matched text.

Fixes #146582
2026-11-14 16:09:36 +01:00
Maciej Lisiewski
0199d5261f fix(execute_code): forward conversation_id to nested tool calls
Nested calls from execute_code carried the outer session_id/turn_id but
not conversation_id, so pre/post_tool_call, transform_tool_result and the
tool middleware saw conversation_id="" for them -- the field the hooks docs
tell plugins to key per-conversation state on. Thread it through the same
sites as session_id/turn_id (handler, local CellAuthority, both remote RPC
routes). Adds a test driving both remote routes (persistent kernel and
per-call fallback) through handle_function_call.

Refs #145870

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-14 15:34:38 +01:00
salch-cred
128820b70e fix(execute_code): forward session identity to nested tool calls
Tool calls made from inside execute_code reached pre_tool_call hooks with an empty session_id: the RPC dispatchers called handle_function_call with only task_id. In a gateway serving several conversations from one process, a hook could therefore attribute a nested call to whichever conversation bound a turn most recently.

Thread the outer call session_id and turn_id from the execute_code dispatch through the handler, the local session kernel CellAuthority, and both remote RPC paths (per-call poll loop and remote session kernel), so nested calls fire hooks with the same identity as direct calls.

Closes #145870.
2026-11-14 15:34:38 +01:00
Christopher
b07a2ad8d9 fix(tools): enforce sandbox grants at RPC boundaries
Address the review follow-up by testing local and remote RPC authorization directly, keeping sandbox failure hints tri-state-aware, and proving partial grants cannot dispatch unapproved tools.
2026-11-13 17:26:03 -08:00
Christopher
3a80d6047b fix(tools): share execute_code sandbox-tool tri-state helper
Local UDS and remote file-RPC now resolve enabled_tools through one
helper so the deny-all / legacy-default contract cannot drift.
2026-11-13 17:26:03 -08:00
Christopher
812b6f0f40 fix(tools): empty execute_code capability set denies all sandbox tools
enabled_tools=[] was conflated with enabled_tools=None via truthiness, so an
explicit empty grant broadened to every SANDBOX_ALLOWED_TOOLS stub instead of
denying all. Preserve tri-state semantics: None keeps the legacy default
(every sandbox tool), an explicit list (possibly empty) uses the exact
intersection, so [] and a non-overlapping list both deny all.

Fixes #84271
2026-11-13 17:26:03 -08:00
Ben Barclay
0a4a3368bd fix(sandbox): an allowed hosted tool leaves nothing on this host; skills and shell hooks are host features
- execute_code: an oversized remote stdout spills into the agent's own
  sandbox (as the generic result spill does) or is truncated inline; it is
  never written to cache/exec.
- skills: one host feature consulted by the shared loader, preload,
  auto-load, the skills index prompt, slash-command scans and skill_view /
  skills_list for direct callers. No host skill file is read in a hosted scope.
- shell hooks: a host feature, off in a hosted scope at the callback and at
  the one subprocess site. A refused hosted call is decided before Relay and
  every request/execution middleware, so no host-side callback sees it.
- background processes: a hosted record is never written to the host
  checkpoint (whoever triggers the write) and gets no host completion
  receipt; its live state stays in memory.
- other per-call artifacts of allowed tools (terminal output spill, saved
  blocked scripts, the verification ledger) are off in a hosted scope.
2026-11-11 10:22:54 -05:00
Ben Barclay
178b1d0349 feat(sandbox): a hosted scope's tools reach only its agent's sandbox
Hosted Hermes serves many tenants' agents from one process, and each agent's
commands, code, background processes and files must live in that agent's own
remote sandbox. Until now the environment a tool reached was keyed by task id,
session key or profile path, so nothing tied it to the agent the bound scope
names, and a hosted scope could fall back to running on this host.

The sandbox an operation reaches is now derived from the bound scope's
(tenant, agent) alone (tools/environments/sandbox_scope.py). In a hosted scope:

- every environment key is the agent's sandbox key, whatever task id a call
  carries; the terminal.backend provider must declare serves_hosted_scopes
  (built-ins are refused) and receives scope= and sandbox= at creation, with
  task_id set to the identity's key;
- core wraps the returned environment in ScopedEnvironment, which refuses any
  call made under another agent's scope (or none) and passes the bound scope
  to execute/fetch_* when the backend declares it; a cached environment that is
  not the agent's own is refused at lookup;
- terminal, execute_code (always the remote kernel), background processes and
  read/write/patch/search go through that environment; file-tool bookkeeping
  never stats or opens the requested path on the host;
- background processes carry the sandbox key they were started under, and
  another agent's process is indistinguishable from a missing one (get, list,
  prefix lookup, kill sweeps).

Environments gain start_process/attach_process/stop_process with a
bidirectional byte stream (ProcessStream), implemented for the local backend
and exec-prefix backends; a ProcessRef naming another sandbox is refused.
Credentials are typed as broker references only (CredentialRef); no broker
exists yet, so none are passed.

Local installs are unchanged: with no hosted scope bound every branch keeps
today's keying and backends. A conformance module with a recording stub
backend runs the isolation checks through the real tool registry, so a hosted
backend plugin can run the same checks against its own provider.

process_registry.py's handoff handler moves to process_registry_handoff.py to
keep the facade under its size cap.
2026-11-11 10:22:54 -05:00
Teknium
8300964930 feat(tools): refuse built-in tool calls missing a required argument, flag unknown ones
A call such as search_files without `pattern` ran anyway and returned matches, and a
typo'd or invented argument was dropped with no signal, so the model assumed an option
had taken effect. One check now sits in front of every tool Hermes ships
(registry dispatch and the agent's inline executors; model_tools.py is untouched):

- a missing `required` argument is refused before the handler runs, naming the field
  (with its allowed values when the schema enumerates them) and the valid parameters;
- an argument the schema does not declare still reaches the handler exactly as sent;
  the result gains a `_warning` naming it. Nothing is stripped.

Slim redo of #142503. What differs from it, and why:

- scope is built-in tools only. MCP and plugin tools, and schemas that are open or
  union-shaped at the root, pass through untouched: a third-party `properties` list is
  not a promise about what the handler accepts.
- nothing is stripped, so handlers that read an undeclared key and execution middleware
  that rewrites arguments keep main's contract.
- legacy call shapes and tool-owned guidance are declared by each tool at registration
  (`compat_args`, `self_checked_args`) instead of a central table: skill_manage and memory
  flat shapes, delegate_task's single-task shape, patch's V4A mode, terminal(code=...),
  video_generate(video_url=...), and the handlers whose own missing-argument message says
  more than a generic refusal can.
- the dynamic schema is only built when the registered one reports a finding.

Co-authored-by: Elisa Martinez Abad <elisam@nvidia.com>
Co-authored-by: James Nolan <jnolan@nvidia.com>
2026-11-10 22:29:30 -08:00
Teknium
06d3a0a757 fix: keep the runnable helper import line in the execute_code schema
The dedupe replaced "Helpers require imports: `from hermes_tools import
json_parse, shell_quote, retry`" with a prose pointer. That line is the one
instruction the model can copy verbatim, and
tests/tools/test_execute_helper_contract.py executes exactly what the schema
teaches: with the line gone the probe ran without the import and failed with
NameError on CI (Python tests 1/3).

Restore the sentence and re-render the prompt-surface snapshot. Costs back a
few of the 80 tokens the execute_code dedupe saved.
2026-11-10 20:13:57 -08:00
Teknium
2453c963b3 refactor: state each rule once in seven core tool schemas
search_files, memory, manage_connections, execute_code, browser_exec,
skill_manage and terminal repeated the same rule in the tool description
and again in a parameter description (or only restated the JSON schema:
"default: 50" beside "default": 50). Every model call pays for both
copies. Each rule now appears once, on the parameter it governs where
there is one. Parameter names, types, enums, defaults and required lists
are unchanged; with descriptions stripped the seven schemas are identical
to main.

Measured on anthropic/claude-fable-5.2 (provider prompt tokens, one tool
per request): search_files 732 -> 557, memory 885 -> 767,
manage_connections 1,563 -> 1,333, execute_code 1,165 -> 1,085,
browser_exec 1,187 -> 1,145, skill_manage 1,340 -> 1,313, terminal
919 -> 895. All seven together: 8,077 -> 7,381 (-696 per call).

memory: the user/memory store meanings moved from the description to the
`target` parameter, so the single-store narrowing now rewrites only that
parameter. A disabled store is still never named in the schema (new test).

browser_exec keeps page_info() and fill_input() in the helper list: the
"work text-first" sentence that also names them is absent from the
native-vision and Lightpanda variants.

manage_connections keeps its two short opening sentences: the tool_search
catalog line is the first sentence and must not be clipped.

memory also keeps "Reusable procedures belong in a skill, not memory" at the
end of its SKIP list although the WHEN paragraph says the same: with the
sentence gone a weak model stored a procedure in memory in 1 of 9 runs (0 of
9 on main).

Prompt-surface snapshot re-rendered.
2026-11-10 20:13:57 -08:00
unsupportedpastels
ebb840e8cd refactor(terminal): move _call_in_flight into the lifecycle sibling
Its only consumer is the idle reaper in terminal_tool_lifecycle, so it
belongs beside it. Like the rest of that module it reads the env cache
state (_calls_in_flight, _env_lock, _last_activity) from terminal_tool at
call time, so that state stays where tests patch it and no import cycle is
added; terminal_tool re-exports the helper and _execute_remote imports it
from the sibling. No behaviour change.

Refs #143547
2026-10-25 19:14:26 -04:00
unsupportedpastels
e24c9a5086 fix(terminal): keep the idle reaper off an environment with a call in flight
_cleanup_inactive_envs reaped any key whose _last_activity was older than
lifetime_seconds (default 300 s). Only background processes refresh that
stamp, while a foreground command may run for 600 s, so a long build or
test suite had its Docker workspace container stopped (exit 137), its
Modal sandbox terminated or its SSH control master closed mid-command.

terminal_tool and the remote execute_code path now hold the env keys they
were stamped under (_call_in_flight, refcounted, released in finally) from
acquisition through the approval wait and execution; the reaper skips held
keys, and release restamps so the idle countdown starts at call end.

Refs #143547

Co-authored-by: Genesis Guerrero Martinez <2824293+gengue@users.noreply.github.com>
2026-10-25 19:14:26 -04:00
Teknium
89963452ee fix(terminal): make persistent_shell / TERMINAL_*_PERSISTENT actually work
Since the spawn-per-call rewrite (d684d7ee7e) the persistence knobs were read
into config but never reached the environment: SSHEnvironment took no such
param and _create_environment dropped local_config. Every local and SSH
session carried cwd + exported env across commands regardless of the setting.

BaseEnvironment gains persist_env (default True). When False the per-command
wrapper still sources the login-time snapshot and still emits the cwd marker,
but skips the post-command export re-dump, so exports from one command do not
reach the next. SSHEnvironment/LocalEnvironment accept persistent=...;
_build_ssh_env forwards ssh_config['persistent'] and every local construction
path (terminal, file tools, execute_code, ensure_task_env) now forwards
TERMINAL_LOCAL_PERSISTENT via _local_config_from_config.

Defaults equal today's real behaviour: TERMINAL_LOCAL_PERSISTENT now defaults
to true (it was documented false but ignored), SSH keeps following
terminal.persistent_shell (true). Only users who explicitly set the knob to
false see a change: they get the isolation they asked for.

Docs: the Persistent Shell section claimed plain shell vars persist and that
local was non-persistent; rewritten to state exactly what carries over.
2026-10-11 16:53:57 -07:00
Maciej Lisiewski
4278b6aa24 ci: RUF013, RUF015 2026-10-08 21:29:48 +02:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
teknium1
25c1b008c8 feat(telemetry): wire memory, curator, delegation and backend call sites
- memory tool: one row per operation (a batch counts each op); gate/validation
  refusals are "rejected", store-level non-application "failed". Memory provider
  tools are counted in MemoryManager.handle_tool_call with the op read from the
  action arg or tool-name verb.
- curator: run_curator_review records one row per pass (dry run = skipped) with
  the before/after diff bucketed; a scheduled pass whose claim is held by another
  process counts as skipped. The home is captured before the review thread starts.
- delegate_task: _run_batch opens the call, each joined unit folds its results in,
  and the last unit emits the call's single row, so group-split background calls
  are not counted per unit.
- terminal / execute_code / browser: counted per call that reached the backend;
  the backend is resolved from the owning profile at call time (terminal plan
  env_type, code local/remote, browser CDP > Camofox > cloud provider > engine, or
  "extension" when the extension controller served the call). Guard refusals and
  Hermes' own _host_local commands are not counted.

Tests read rows back from the real store; each call-site group is red with its
source reverted.
2026-09-28 12:43:03 -07:00
Teknium
a5bd246865 Old pre-decomposition import paths are gone: plugin compat layer removed on schedule (#126164)
* refactor(plugins): remove the Sep 2026 decomposition compat layer on schedule

The PLUGIN-COMPAT layer (2776813df3 + d63e380324 + 0a5164cebe) kept pre-#102117 import paths
alive for external plugins until 2026-09-14. That window closed two weeks ago; since then the loader
has already been skipping plugins that use the old paths. This removes the layer itself:

- 328 appended `PLUGIN-COMPAT` blocks (lazy `__getattr__` pointer tables, re-exported third-party
  names, restored dead definitions) and the three re-export stub modules
  (gateway/startup_watchdog, hermes_cli/observability/relay_runtime, tools/environments/modal_utils)
- COMPAT_MANIFEST.md, compat_manifest.json, scripts/check_compat_pointers.py and its lint step
- the reporting surfaces: CLI banner notice, `hermes plugins compat`, the `hermes doctor` section,
  the post-update notice, the Desktop one-time dialog, the loader's pre-import skip and the
  `plugins.allow_deprecated_imports` escape hatch

An external plugin that still imports an old path now fails to load with its ImportError as the
reason in `hermes plugins list`, the same path as any broken plugin.

hermes_cli/plugin_compat.py stays as three inert stubs (compat_report, removal_in_effect,
summary_lines): an already-running pre-removal `hermes update` lazy-imports them after the checkout
swap (tests/compat/old_updater_surface.json).

In-tree fallout, both already dead: hermes_cli/setup.py::_check_espeak_ng (no callers; its
`shutil` came from a compat block) and gateway/config.py::SessionResetPolicy ("retained solely for
the scheduled plugin-compat window"). Two test_run_agent patches targeted the removed
`run_agent.handle_function_call` pointer; they now patch `model_tools.handle_function_call`, the
seam production reads, like every sibling test in that file.

* chore: retrigger CI (zero-job startup_failure phantom)

* test: drop resolution allowlist rows for the two deleted which() sites

hermes_cli/setup.py::_check_espeak_ng (dead) and tools/skillevaluator_scan.py::scanner_available
(a restored definition inside a PLUGIN-COMPAT block) no longer exist; the stale-row gate requires
their allowlist entries go with them.
2026-09-28 10:21:41 -07:00
teknium1
3e1bfb2935 fix(execute_code): report in-script tool errors the script ignored
A script that calls hermes_tools.write_file/patch and never prints the
returned {"error": ...} got status=success with empty output, so the
model believed the write happened. In a cross-agent bench this cost 3 of
18 Opus runs 4-6 extra turns (write_file refused by the read-before-write
guard, then re-probing and re-emitting whole files). The result now
carries tool_errors for that cell, and the in-script write_file doc says
existing files must be read first.
2026-09-28 10:11:33 -07:00
kshitijk4poor
1a748cc85a refactor(code-execution): one checked-execute helper, complete launch command
Gate follow-ups on the remote lockdown:
- _execute_checked(env, cmd, what, **kw) in code_execution_rpc replaces
  the three copy-pasted "execute, raise if returncode != 0" blocks
  (per-call setup, kernel dir setup, file ship via
  _remote_write(check=True)). env.execute always returns a dict, so the
  isinstance/(r or {}) guards go; the error carries command output only,
  never the payload.
- _ship_env_file_and_launch_prefix returned a half-built "( ... && "
  that both callers had to close; a caller that dropped the ")" or
  composed it differently would lose the load-bearing subshell. It now
  takes the launch command, builds the shared env map (RPC dir, token,
  PYTHONDONTWRITEBYTECODE, routed TZ) itself, and returns the complete
  command; the kernel passes only HERMES_KERNEL_DIR/PYTHONPATH, which
  drops its duplicated TZ block and lazy hermes_time import.
- _private_dirs_cmd(root, *subdirs): every caller spelled each path
  twice for mkdir and chmod.
- _run_remote_cell publishes the cell request with one atomic
  _remote_write instead of ship-to-.tmp then a separate unchecked mv,
  saving a backend round-trip per cell.
2026-09-27 00:56:31 +05:30
kshitijk4poor
19cf343c74 fix(code-execution): always send remote-write payloads as stdin_data
_remote_write branched on getattr(env, "_stdin_mode", "pipe") and only
passed stdin_data on pipe backends, echoing base64 into argv elsewhere.
BaseEnvironment.execute already embeds stdin_data as a heredoc for
heredoc-mode backends (modal/daytona/vercel), and managed_modal forwards
it as stdinData; _write_to_sandbox already relies on that for every
backend. The branch duplicated base-class logic, and its defensive
getattr default meant a fake env with neither _stdin_mode nor a
stdin_data parameter raised TypeError on every RPC response write. The
poll loop swallowed the error, so no res_* file appeared and
test_code_execution_file_rpc hung forever (it passes on base).

Collapse to one path that always passes stdin_data, and teach the
file-RPC Shell fake to accept it and feed it as input. ScriptedEnv no
longer needs its _stdin_mode stub.
2026-09-27 00:56:31 +05:30
beardthelion
5b8fd7fc32 fix(code-execution): lock down remote kernel/RPC dirs, keep RPC token out of argv
On shared remote backends the execute_code channel created kernel and
sandbox dirs under shared temp at the process umask (775 group-writable
under umask 002), wrote request/result files group-readable, and carried
HERMES_RPC_TOKEN on remote command lines where co-tenant users read argv
via ps for the whole run. A co-tenant could read tool arguments and
results, and on group-writable dirs forge RPC requests dispatched under
the user's approval context.

- All remote dirs are created owner-only (umask 077 + chmod 700, checked
  fail-closed) and every Hermes file write is mode 600.
- The token travels in a sourced env file inside a subshell so the vars
  never enter the backend's session-snapshot dump, and ships via stdin on
  pipe-capable backends so it never enters argv at all.
- The RPC poll loop rejects non-int seq requests before dispatch instead
  of replaying them every cycle.
- tool_result_storage gets the same owner-only treatment for archived
  tool output.

(cherry picked from commit aef21731d7fb8a4e0a6ada4ff9889264df4a8893)
2026-09-27 00:56:31 +05:30
ethernet
abe76b5176 fix: restore upstream behavior lost in PM conflict resolutions 2026-09-24 23:59:55 -04:00
ethernet
e1576d06a6 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
Resolved toward the branch: PM provisions uv/python (main's install.ps1 uv-shim
salvage + its test and workflow steps dropped), the shim re-exec stays retired,
package.json carries no electron-builder block (afterExtract identity stamp wired
into electron-builder.config.cjs instead; after-pack.mjs keeps signing only),
Desktop workspace-deps helpers stay retired. Main's scratch-dir bootstrap
(export_scratch_tmp_env) is taken and re-run after profile resolution.
2026-09-19 22:57:07 -04:00
teknium1
e16fee4db1 refactor: resolve runtime temp paths via tempfile/TMPDIR instead of literal /tmp
Hermes now routes scratch space through HERMES_HOME/cache/scratch (exported as
TMPDIR), so every production path that still spelled out /tmp bypassed that and
kept teaching the agent the habit. Fallbacks in tool_result_storage,
code_execution_tool, process_registry, the ACP child HOME, mini_swe_runner's
local cwd, and the CI/profiling scripts now use tempfile.gettempdir(); shell
installers fall back to $TMPDIR (then HERMES_HOME) when mktemp is missing, and
repro/eval shells use `mktemp -d -t`. User-facing help text and sample payloads
(hermes send, approvals test, hooks test, voice-mode WSL hints, meet_bot debug
line) no longer suggest /tmp.

Container-side paths (mini_swe_runner docker cwd, sandbox base env, remote
sync tarballs) keep the literal because they name the sandbox filesystem,
not the host.
2026-09-19 10:44:26 -07:00
ethernet
82a5affdd3 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	hermes_cli/backup.py
#	tests/hermes_cli/test_gateway_restart_loop.py
#	website/docs/developer-guide/web-search-provider-plugin.md
#	website/docs/getting-started/installation.md
#	website/docs/getting-started/updating.md
#	website/docs/index.mdx
#	website/docs/reference/cli-commands.md
#	website/docs/user-guide/docker.md
#	website/docs/user-guide/windows-wsl-quickstart.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/plugins/index.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/web-search-provider-plugin.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/index.mdx
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/cli-commands.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/environment-variables.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/docker.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/plugins.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/security.md
#	website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/windows-wsl-quickstart.md
2026-09-18 18:41:16 -04:00
teknium1
1f1fa9a87e fix(tools): execute_code shares the interpreter-kill rejection text; collapse redundant supervisor branch
- HOST_INTERPRETER_KILL_REJECTION is one constant in cron/lifecycle_guard;
  terminal_tool_guards and the execute_code lifecycle guard both use it,
  so an image-name kill inside a cell now names the proc_* / explicit-PID
  route instead of the generic "cannot restart or stop the gateway" text.
  One invariant test with the generic path as control.
- gateway/restart.is_supervised_gateway_launch: the callee already maps
  None to os.environ; pass environ straight through.
2026-09-18 12:49:13 -07:00
ethernet
b4a294fff9 Merge origin/main; keep PM as plugin dependency owner
Reconcile plugin declarations and validation through PM's atomic generation publication; preserve external runtimes, target markers, and conflict refusal. Keep one source-update completion owner and port upstream lifecycle changes to the PM desktop/runtime paths.
2026-09-17 13:52:05 -04:00
teknium1
30b22b54ae fix(tools): bound execute_code's lifecycle probe and keep the terminal guard answerable to /stop
execute_code ran the same unbounded _is_supervised_gateway_process() probe
ahead of every cell, so the wedge #111922 bounds in terminal_tool still hung
an execute_code call (and its cron slot) forever: share the cell's deadline
and fail closed with a retryable error when the probe renders no verdict.

Moving the terminal pre-exec guard onto a deadline worker made it blind to
/stop, which keys on the tool thread's ident: record the acting-for tid in a
contextvar (copied into the worker by run_bounded_sync) so is_interrupted()
on the worker honours the tool thread's bit too.

Floor the guard's share of the deadline at 30s so a short command timeout
does not turn the guard's own cold-start cost (imports, git probes under
load) into a refusal — tests/tools/test_terminal_error_redaction.py was red
on the branch for exactly that.
2026-09-15 19:09:29 -07:00
teknium1
23036e20a6 fix(ux): plain-language, actionable user-facing messages (core)
Squashed integration of the user-facing message audit for this surface set.
Full per-finding receipts: /tmp/ux-audit/lanes/*-receipt.md (campaign artifacts).
2026-09-15 04:12:13 -07:00
ethernet
612d542281 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	.gitignore
#	Dockerfile
#	agent/onboarding.py
#	apps/desktop/electron/main.ts
#	apps/desktop/electron/pool-stop.ts
#	apps/desktop/src/components/model-picker.test.tsx
#	apps/desktop/src/store/updates.ts
#	apps/desktop/vite.config.ts
#	datagen-config-examples/run_browser_tasks.sh
#	docs/rca-ssl-cacert-post-git-pull.md
#	gateway/run.py
#	hermes_cli/backup.py
#	hermes_cli/credential_lifecycle.py
#	hermes_cli/dashboard_procs.py
#	hermes_cli/doctor_state.py
#	hermes_cli/env_loader.py
#	hermes_cli/gateway_windows.py
#	hermes_cli/local_runtime/endpoint.py
#	hermes_cli/psutil_android.py
#	hermes_cli/update_cmd.py
#	hermes_cli/update_cmd_windows.py
#	hermes_cli/web_routers/local_models.py
#	hermes_cli/web_server_config.py
#	hermes_cli/web_server_cron.py
#	plugins/memory/hindsight/__init__.py
#	plugins/memory/holographic/__init__.py
#	plugins/memory/honcho/cli.py
#	plugins/memory/mem0/__init__.py
#	plugins/platforms/google_chat/oauth.py
#	plugins/platforms/photon/adapter.py
#	scripts/ci/list_os_marked_tests.py
#	scripts/run_tests.sh
#	tests/agent/test_compression_stall_fallback.py
#	tests/agent/test_create_openai_client_ssl_verify.py
#	tests/gateway/test_google_chat_oauth_dependencies.py
#	tests/hermes_cli/conftest.py
#	tests/hermes_cli/test_cli_init.py
#	tests/hermes_cli/test_gateway_migrate_multiplex.py
#	tests/hermes_cli/test_psutil_android_extract.py
#	tests/hermes_cli/test_relaunch.py
#	tests/hermes_cli/test_update_check.py
#	tests/hermes_cli/test_update_handoff_desktop_rebuild.py
#	tests/hermes_cli/test_worktree_gc.py
#	tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py
#	tests/scripts/desktop_update/test_desktop_update_windows_retry_policy.py
#	tests/scripts/desktop_update/test_desktop_update_windows_timestamp.py
#	tests/scripts/install/test_install_autostash_conflict_recovery.py
#	tests/scripts/install/test_install_clone_throttle_fallback.py
#	tests/scripts/install/test_install_commit_pin_rollback.py
#	tests/scripts/install/test_install_diverged_update.py
#	tests/scripts/install/test_install_lockfile_churn.py
#	tests/scripts/install/test_install_macos_launcher.py
#	tests/scripts/install/test_install_no_initial_commit.py
#	tests/scripts/install/test_install_ps1_ascii_only.py
#	tests/scripts/install/test_install_ps1_browser_install.py
#	tests/scripts/install/test_install_ps1_managed_node_swap.py
#	tests/scripts/install/test_install_ps1_native_stderr_eap.py
#	tests/scripts/install/test_install_ps1_node_path_for_npm.py
#	tests/scripts/install/test_install_ps1_python_fallback_venv.py
#	tests/scripts/install/test_install_ps1_resolver_strictmode.py
#	tests/scripts/install/test_install_ps1_uv_install_fallback.py
#	tests/scripts/install/test_install_ps1_uv_powershell_host.py
#	tests/scripts/install/test_install_ps1_venv_process_tree.py
#	tests/scripts/install/test_install_ps1_venv_recreate_safety.py
#	tests/scripts/install/test_install_ps1_venv_rename_abort.py
#	tests/scripts/install/test_install_ps1_venv_transaction_boundary.py
#	tests/scripts/install/test_install_ps1_web_server_syntax_probe.py
#	tests/scripts/install/test_install_scripts_computer_use.py
#	tests/scripts/install/test_install_sh_acp_launcher.py
#	tests/scripts/install/test_install_sh_bootstrap_marker.py
#	tests/scripts/install/test_install_sh_browser_install.py
#	tests/scripts/install/test_install_sh_install_method_stamp.py
#	tests/scripts/install/test_install_sh_node_deps_failure.py
#	tests/scripts/install/test_install_sh_node_deps_workspaces.py
#	tests/scripts/install/test_install_sh_node_global_prefix.py
#	tests/scripts/install/test_install_sh_node_npm_check.py
#	tests/scripts/install/test_install_sh_node_prerelease.py
#	tests/scripts/install/test_install_sh_node_probe.py
#	tests/scripts/install/test_install_sh_node_tarball_without_xz.py
#	tests/scripts/install/test_install_sh_pythonpath_sanitization.py
#	tests/scripts/install/test_install_sh_reuse_supported_python.py
#	tests/scripts/install/test_install_sh_root_fhs_uv_python_path.py
#	tests/scripts/install/test_install_sh_setup_wizard_tty_probe.py
#	tests/scripts/install/test_install_sh_symlink_stomp.py
#	tests/scripts/install/test_install_sh_termux_network_prereqs.py
#	tests/scripts/install/test_install_sh_termux_python_bounds.py
#	tests/scripts/install/test_install_sh_uv_lock_config.py
#	tests/scripts/install/test_install_unmerged_index.py
#	tests/scripts/test_run_tests_parallel.py
#	tests/test_managed_runtime_resolution.py
#	tests/test_project_metadata.py
#	tests/tools/test_browser_use_cli.py
#	tests/tools/test_tts_pythonpath_fallback.py
#	tests/tui_gateway/test_hosted_room_driver_runtime.py
#	tests/tui_gateway/test_tui_gateway_server.py
#	tools/lazy_deps.py
#	tools/voice_mode.py
#	uv.lock
#	website/docs/developer-guide/macos-bundle-updates.md
#	website/docs/developer-guide/pm-audit-status.md
#	website/docs/developer-guide/shared-bundle-builds.md
#	website/docs/developer-guide/source-update-completion.md
#	website/docs/developer-guide/stable-releases.md
2026-09-14 15:38:34 -04:00
teknium1
1512edfb85 refactor(tools): terminal, execute_code, MCP and the bounded collector truncate through one head/tail helper
Four copies of the 40/60 head/tail algorithm with a near-identical notice
(terminal_tool_result, mcp_tool_content, code_execution_tool,
environments/base_output) collapse into tools/tool_output_truncate.py, so the
ratio and the `... [<LABEL> TRUNCATED - N <unit> omitted out of T total] ...`
marker are defined once. execute_code keeps byte mode + spill path and only
shares the notice/split. Visible change: the terminal notice now uses
thousands separators like the other three (`9,000 chars` not `9000 chars`).

kanban_specify._truncate: comment claimed escape stripping the body never did;
comment now says what the plain clamp is for.
2026-09-13 05:09:43 -07:00
teknium1
469a87f7a5 refactor(config): collapse thin _load_config copies onto the canonical readers
doctor_live and kanban_decompose carried byte-identical
`try: load_config() or {}` wrappers; local_models wrapped load_config in
_quiet; each is now a direct load_config_readonly() call (read-only callers;
the canonical already fails open and returns a mapping). Tests that patched the
local wrappers patch hermes_cli.config.load_config_readonly instead.

tools/code_execution_tool._load_config read the RAW file, so a managed-pinned
`code_execution.mode` and the DEFAULT_CONFIG keys were invisible at tool
discovery — it now reads load_config_readonly() (behavior change: the managed
overlay applies to execute_code's mode/timeout). onboarding.mark_seen and
credential_lifecycle's config mirror scrub parsed config.yaml with a bare
safe_load; both are read→mutate→write round-trips and use read_user_config_raw,
the documented write-back primitive.
2026-09-13 05:09:06 -07:00
ethernet
cc01ae9d44 merge: connector UI e2e v2 into bundled onboarding (rebuilt)
# Conflicts:
#	apps/desktop/electron/main.ts
#	apps/desktop/src/app/settings/local-models-settings.test.tsx
#	hermes_wisdom/agent_led/share_flow.py
#	plugins/memory/hindsight/__init__.py
#	scripts/lib/wisdom-demo-env.sh
#	scripts/release.py
#	tests/skills/test_collective_wisdom_install_skill.py
#	tools/checkpoint_manager.py
2026-09-11 21:10:19 -04:00
Teknium
adf23550f5 fix(tools): profile-scoped checkpoint/snapshot paths, tool caches, TZ and schema paths under multiplex
Under `gateway.multiplex_profiles` one gateway process serves every profile
under ~/.hermes/profiles/NAME/; each routed turn runs with a context-local
HERMES_HOME override while `os.environ` still holds the DEFAULT profile's
values. Anything evaluated once at import, or memoised in a single unkeyed
module slot, therefore freezes the LAUNCH profile's value and leaks it into
every other profile's turns. This lands the tools-side half of that class:

- tools/process_registry.py, tools/environments/{modal,singularity}.py:
  `_checkpoint_path()` / `_snapshot_store()` resolve `get_hermes_home()` at
  call time (same seam as `tools/skills_tool._skills_dir`, so the existing
  `monkeypatch.setattr(CHECKPOINT_PATH)` test sites keep working). Completes
  the checkpoint_manager / sticker_cache half cherry-picked from #56315.
- plugins/platforms/feishu/feishu_comment_rules.py: `_MtimeCache` is now
  path-keyed (accepts a Path or a zero-arg resolver, one (mtime, data) slot
  per resolved path) with `invalidate()`; `_rules_file()` / `_pairing_file()`
  resolve the routed profile's files. Proposed in #63962.
- tools/tool_output_limits.py, tools/browser_tool.py, tools/browser_camofox.py:
  the process-lifetime config caches are dicts keyed by `hermes_home_key()`;
  the `_X_resolved` flags and the lifecycle reset keep their shape.
  tools/file_tools.py drops its private `file_read_max_chars` memo and reads
  the already mtime+path-cached `load_config_readonly()`.
- hermes_time.py: `get_timezone_name()`; when `is_multiplex_active()` the
  env `HERMES_TIMEZONE` (bridged from the default profile's config at gateway
  startup) is ignored in favour of the routed profile's config.yaml. Both
  sandbox TZ sites (code_execution_env/_tool) now use it.
- tools/cronjob_tools.py, tools/tts_tool.py, tools/skill_manager_tool.py:
  the static schema text is profile-neutral and `dynamic_schema_overrides=`
  rebuilds the `display_hermes_home()` / create-dir hint per
  `get_definitions()`, so a routed profile's model sees its own paths.

Refs #95685.

Co-authored-by: Nathan Shan <nathanielcrush51@gmail.com>
(cherry picked from commit 6d3fc6b07b3155c6196b1fd61a829283f1d7855c)
2026-09-11 15:44:00 -07:00
ethernet
7d2b3b767d merge: integrate upstream/main into ethie/pm-clean
Merge upstream b1f003e186 while preserving PM runtime ownership and
Python 3.14 worker startup, Windows signing, and macOS wait recovery.

Keep retired runtime modules deleted. Port upstream updater preflight
checks into the checkout strategy and preserve live build logging.
Carry checkpoint filename handling and process recovery into the current
module layout. Regenerate locks and adapt incoming platform test markers.

Focused Python and JavaScript tests, desktop and root-test typechecks,
conflict-path lint checks, lock validation, and retired-import checks pass.
The full test suite and packaged release builds were not run.
2026-09-08 19:17:39 -04:00
Teknium
65f033a1a2 fix(execute-code): teach the working helper import contract
Slim adaptation of #83772 to the current schema and failure-hint table.
Generated helpers are module exports on every execution path, not globals.
Correct schema, recovery hints and CLI tip rather than injecting names or
changing the execution boundary. Two registry-driven invariants reproduce
both misleading instructions on main and execute the corrected guidance.

Additional tool fix discovered during campaign #104904.
Original diagnosis and correction: @yuzilongleif-collab (#83772).

Co-authored-by: yuzilongleif-collab <235949691+yuzilongleif-collab@users.noreply.github.com>
2026-09-07 06:12:24 -07:00
ethernet
ce49cdbc59 merge: reconcile upstream main with pm audit closeout
Merge upstream 5e645791ac.

Retain the PM feature-flag owner and add upstream connection options.
Use the deny-only window-open policy while trusted external links keep
the existing IPC path. Keep both session-import and external-link copy.
Preserve captured timeout output when adding terminal yield handoff.
Quickstart tests patch the explicit upstream model-assignment owner.
Migrate incoming legacy OS markers to the branch's platforms gate.

Desktop renderer and Electron typechecks passed. Targeted Electron tests
passed (42 tests), Python conflict checks passed (26 tests, 3 skips),
and the plugin-compat import checker passed. CI owns the broad merge gate.
2026-09-06 13:17:07 -04:00
ethernet
92686159d1 fix(pm): integrate audited runtime and lifecycle repairs
Prepare dependency generations before selecting them. Keep shipped tool
bytes separate from writable additions, and store facts beside their entries.
Validate proposed plugin sets before config publication. Restore the previous
config if the facts write fails.

Consolidate duplicate updater, backup, setup, and voice helpers. Repair
launcher selection, dependency consumers, download ownership, update feeds,
and native Windows process and file handling.

Verification: 206 changed/prior-failing Python files reported 4630 passed,
one failed, and 330 skipped. Fix the remaining Hindsight fixture boundary.
The final targeted rerun reported 234 passed and two skipped. The store
review regression batch reported 83 passed and one skipped. Desktop
TypeScript checks, 56 selected Electron tests, 24 release tests, and the
removed-import/compatibility guards passed.

This is an integration checkpoint, not full audit acceptance. The complete
Python suite has not run on this fixed tree. Crash-atomic plugin publication,
generation cleanup, receipt correlation, and packaged lifecycle acceptance
remain open in docs/pm-audit-status.md.
2026-09-05 22:36:48 -04:00