Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions agents/hermes-01x/Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
# The image PATH puts the Hermes virtual environment first, so a plain
# python3 is Hermes' own interpreter, which these packages must not change.
# - No OpenClaw skill or openclaw.json change. The Hermes browser tools use
# the base image's agent-browser: config.yaml and the managed policy set
# browser.backend "off", and /etc/chromium.d/nemoclaw-openshell adds the
# Chromium flags that an OpenShell sandbox requires.
# the base image's agent-browser: config.yaml, the managed policy, and the
# Hermes default for named profiles set browser.backend "off", and
# /etc/chromium.d/nemoclaw-openshell adds the Chromium flags that an
# OpenShell sandbox requires.
#
# The final image keeps the base image's user, entrypoint, command, working
# directory, environment, healthcheck, and controlled package versions. It
Expand Down Expand Up @@ -218,7 +219,8 @@ RUN --mount=type=bind,from=downloads,target=/downloads \
NPM_CONFIG_OFFLINE=false npm install -g --no-audit --no-fund /downloads/pnpm-12.16.1.tgz

# The printf and python -c arguments are literal text, not shell expansions.
# hadolint ignore=DL3003,SC2016
# The only pipe ends in sha256sum -c, whose status is the pipe status.
# hadolint ignore=DL3003,DL4006,SC2016
RUN set -eu; \
# Offline frontend projects start from a copy of this template. pnpm's
# store keeps a SQLite index that cannot be opened from a read-only path,
Expand All @@ -245,9 +247,12 @@ RUN set -eu; \
# Keep Hermes on its built-in browser tools instead of the Browser Use CLI
# that `uvx browser-use` fetches from PyPI (configure-tools-browser.py
# explains why). The managed policy gets the same value, or the dashboard
# config seeder refuses the gateway config (#79). Then seal config.yaml
# again exactly as the base image does; only the config.yaml hash line
# changes.
# config seeder refuses the gateway config (#79). Named profiles have no
# config.yaml, so the script also changes the browser.backend default in
# two Hermes source files (#83). The hashes below are those files in
# BASE_IMAGE: check the script's edits against a new base image before
# changing them. Then seal config.yaml again exactly as the base image
# does; only the config.yaml hash line changes.
config=/sandbox/.hermes/config.yaml; \
policy=/usr/local/share/nemoclaw/hermes-managed-policy.json; \
seal=/etc/nemoclaw/hermes.config-hash; \
Expand All @@ -256,8 +261,16 @@ RUN set -eu; \
test "$(stat -c '%U:%G %a' "$seal")" = "root:root 444"; \
sha256sum -c --quiet "$seal"; \
mcp_line=$(grep '^# nemoclaw-hermes-mcp-state-v1 ' "$seal"); \
/usr/bin/python3 -I /tmp/nemoclaw-tools/configure-tools-browser.py "$config" "$policy"; \
printf '%s %s\n' \
d990eecd35d5b3447ca6f81ba1c6618d0702e2d4281b932974a5e64b29d8436b /opt/hermes/tools/browser_use_cli.py \
13e4261f6b47269b92c9cf0f13eac385c8c070a96190d4177639eea239d21def /opt/hermes/hermes_cli/config_defaults.py \
| sha256sum -c --quiet -; \
/usr/bin/python3 -I /tmp/nemoclaw-tools/configure-tools-browser.py "$config" "$policy" /opt/hermes; \
test "$(stat -c '%U:%G %a' "$policy")" = "root:root 444"; \
# Replace the base image's bytecode of the two changed modules, so Hermes
# does not compile them on every start.
/opt/hermes/.venv/bin/python -I -m py_compile \
/opt/hermes/tools/browser_use_cli.py /opt/hermes/hermes_cli/config_defaults.py; \
( cd /opt/hermes && HERMES_HOME=/sandbox/.hermes /opt/hermes/.venv/bin/python -I -c \
'import sys; sys.path.insert(0, "/opt/hermes"); from tools.browser_use_cli import get_browser_backend, is_browser_use_cli_mode; assert get_browser_backend() == "off" and not is_browser_use_cli_mode()' ); \
mcp_digest="$(/opt/hermes/.venv/bin/python -I /usr/local/lib/nemoclaw/build-hermes-mcp-digest.py --guard /usr/local/lib/nemoclaw/hermes-runtime-config-guard.py --config "$config")"; \
Expand All @@ -281,6 +294,20 @@ RUN set -eu; \
setpriv --reuid=sandbox --regid=sandbox --init-groups \
/opt/hermes/.venv/bin/python -I /tmp/nemoclaw-tools/image-build-probes.py dashboard-policy "$probe"; \
test ! -e "$probe"; \
# Repeat the base image's profile-policy probe on a new named profile,
# which has no config.yaml. It compares every managed path, browser.backend
# included. get_browser_backend() must also return "off" for the named
# profile, so Hermes does not use the Browser Use CLI.
profile_root=$(mktemp -d); \
HOME="$profile_root" HERMES_HOME="$profile_root/.hermes" \
/usr/local/bin/hermes profile create nemoclaw-policy-probe --no-alias --no-skills; \
profile_home="$profile_root/.hermes/profiles/nemoclaw-policy-probe"; \
test ! -e "$profile_home/config.yaml"; \
HOME="$profile_root" HERMES_HOME="$profile_home" \
/opt/hermes/.venv/bin/python -I /tmp/nemoclaw-tools/image-build-probes.py profile-policy; \
( cd /opt/hermes && HOME="$profile_root" HERMES_HOME="$profile_home" /opt/hermes/.venv/bin/python -I -c \
'import sys; sys.path.insert(0, "/opt/hermes"); from tools.browser_use_cli import get_browser_backend, is_browser_use_cli_mode; assert get_browser_backend() == "off" and not is_browser_use_cli_mode()' ); \
rm -rf "$profile_root"; \
rm -rf /tmp/nemoclaw-tools /root/.npm /root/.cache /root/.local/share/pnpm

# Same user name as the base image configuration.
Expand Down
55 changes: 49 additions & 6 deletions agents/hermes-01x/configure-tools-browser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Keep the Hermes tools image on Hermes' built-in browser tools (derekhsu/NemoClaw#74, #79).
"""Keep the Hermes tools image on Hermes' built-in browser tools (derekhsu/NemoClaw#74, #79, #83).

Usage: configure-tools-browser.py <config.yaml> <managed-policy.json>
Usage: configure-tools-browser.py <config.yaml> <managed-policy.json> <hermes-source-dir>

With browser.backend unset, Hermes replaces its browser tools with the Browser
Use CLI whenever uvx is on PATH, and that CLI is fetched from PyPI with
Expand All @@ -19,9 +19,19 @@
managed path. The dashboard config seeder copies the gateway config only when
each managed section equals the policy, and it copies the managed paths into
the dashboard profile, so the dashboard also gets browser.backend "off" (#79).

A named profile created with `hermes profile create` has no config.yaml, and
Hermes reads browser.backend from the profile's own YAML without the defaults,
so the two edits above do not reach it (#83). The script therefore changes two
Hermes source files under <hermes-source-dir>: a missing browser.backend reads
as "off" in tools/browser_use_cli.py, and the browser.backend default in
hermes_cli/config_defaults.py becomes "off". A profile that sets
browser.backend itself keeps its value. Each edit replaces one exact line and
fails if the line is missing or already changed.
"""

import json
import os
import sys

BROWSER_BLOCK = "browser:"
Expand All @@ -30,6 +40,23 @@
# Keep the browser paths together in the policy's managed_paths list.
BACKEND_PATH_AFTER = "browser.restrict_evaluate"

# Hermes source edits for profiles without browser.backend (#83): path under
# the Hermes source directory, the exact upstream text, and its replacement.
SOURCE_EDITS = (
(
"tools/browser_use_cli.py",
' raw = _read_browser_cfg().get("backend")\n',
" # NemoClaw tools image: a missing browser.backend keeps the built-in browser tools.\n"
' raw = _read_browser_cfg().get("backend", BACKEND_DISABLED)\n',
),
(
"hermes_cli/config_defaults.py",
' "backend": "",\n "inactivity_timeout": 120,\n',
" # NemoClaw tools image: the built-in browser tools, not the Browser Use CLI.\n"
' "backend": "off",\n "inactivity_timeout": 120,\n',
),
)


def configure(text: str) -> str:
"""Return ``text`` with browser.backend set to "off"; raise ValueError otherwise."""
Expand Down Expand Up @@ -66,21 +93,37 @@ def configure_policy(text: str) -> str:
return json.dumps(policy, indent=2, ensure_ascii=False) + "\n"


def source_edit(old: str, new: str):
"""Return a change that replaces the one ``old`` text with ``new``."""

def change(text: str) -> str:
if text.count(new):
raise ValueError("the browser.backend default is already changed")
if text.count(old) != 1:
raise ValueError(f"expected one {old.strip()!r}, found {text.count(old)}")
return text.replace(old, new)

return change


def main() -> int:
if len(sys.argv) != 3:
if len(sys.argv) != 4:
print(__doc__.strip().splitlines()[2], file=sys.stderr)
return 2
changes = [(sys.argv[1], configure), (sys.argv[2], configure_policy)]
for relative, old, new in SOURCE_EDITS:
changes.append((os.path.join(sys.argv[3], relative), source_edit(old, new)))
updates = []
for path, change in ((sys.argv[1], configure), (sys.argv[2], configure_policy)):
for path, change in changes:
with open(path, encoding="utf-8") as handle:
text = handle.read()
try:
updates.append((path, change(text)))
except ValueError as error:
print(f"{path}: {error}", file=sys.stderr)
return 1
# Check both files before writing either. Write in place so the base
# image's owner and mode stay unchanged.
# Check every file before writing any. Write in place so the base image's
# owner and mode stay unchanged.
for path, updated in updates:
with open(path, "w", encoding="utf-8") as handle:
handle.write(updated)
Expand Down
Loading
Loading