Skip to content
Closed
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
40 changes: 40 additions & 0 deletions harnesses/hermes/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# syntax=docker/dockerfile:1
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BASE_IMAGE
FROM ${BASE_IMAGE}

ARG HERMES_VERSION=

# Install Node.js 22 LTS (required by Hermes for tool execution)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install ripgrep (required by Hermes for code search)
RUN apt-get update && apt-get install -y --no-install-recommends ripgrep \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Hermes Agent via pip (available in scion-base)
RUN if [ -n "${HERMES_VERSION}" ]; then \
pip install --no-cache-dir "hermes-agent==${HERMES_VERSION}"; \
else \
pip install --no-cache-dir hermes-agent; \
fi

RUN mkdir -p /home/scion/.hermes /home/scion/.hermes/skills \
&& chown -R scion:scion /home/scion/.hermes

CMD ["hermes"]
47 changes: 47 additions & 0 deletions harnesses/hermes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Hermes Harness Bundle

Scion harness configuration for [Hermes Agent](https://github.com/nousresearch/hermes-agent),
Nous Research's AI coding agent (MIT license).

## Install

From a repository checkout:

```sh
scion harness-config install harnesses/hermes
```

Or directly from GitHub:

```sh
scion harness-config install github.com/GoogleCloudPlatform/scion/tree/main/harnesses/hermes
```

## Auth Modes

| Mode | Env Var | Notes |
|------|---------|-------|
| `api-key` (default) | `ANTHROPIC_API_KEY` | Anthropic key (highest precedence) |
| `api-key` | `OPENAI_API_KEY` | OpenAI key |
| `api-key` | `GOOGLE_API_KEY` | Google AI Studio key |

## Bundle Layout

```
hermes/
config.yaml # Harness configuration (provisioner, capabilities, auth)
provision.py # Container-side provisioner (pre-start hook)
capture_auth.py # Credential capture for no-auth flow
Dockerfile # Image build (FROM scion-base)
cloudbuild.yaml # Cloud Build configuration
```

## Build the Image

```sh
# Local Docker build
docker build --build-arg BASE_IMAGE=scion-base:latest -t scion-hermes:latest -f Dockerfile .

# Cloud Build
gcloud builds submit --config cloudbuild.yaml .
```
168 changes: 168 additions & 0 deletions harnesses/hermes/capture_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env python3
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Hermes capture-auth script.

Scans for credential files on disk and stores them as project-scoped secrets
via `sciontool secret set`. Designed to run after the user authenticates
interactively inside a no-auth agent container.

Reads credential mappings from inputs/capture-auth-config.json (derived from
the harness config.yaml's auth.types.*.required_files declarations). This
avoids hardcoding paths or key names in the script.

Exit codes:
0 = at least one credential captured
1 = error
2 = no credentials found (not an error, but nothing was stored)
"""

from __future__ import annotations

import argparse
import json
import os
import subprocess
import sys
from typing import Any

EXIT_OK = 0
EXIT_ERROR = 1
EXIT_NO_CREDS = 2

HARNESS_BUNDLE = os.path.join(
os.environ.get("HOME") or os.path.expanduser("~"),
".scion", "harness",
)


def _expand(path: str) -> str:
return os.path.expanduser(os.path.expandvars(path))


def _load_config(bundle: str) -> list[dict[str, Any]]:
config_path = os.path.join(bundle, "inputs", "capture-auth-config.json")
if not os.path.isfile(config_path):
return []
with open(config_path, "r", encoding="utf-8") as f:
try:
data = json.load(f)
except (json.JSONDecodeError, OSError):
return []
creds = data.get("credentials")
Comment on lines +58 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If capture-auth-config.json is malformed or contains a non-object (like a list or string), json.load(f) will succeed but data won't be a dictionary, causing data.get to raise an AttributeError. We should verify isinstance(data, dict) before calling .get().

Suggested change
with open(config_path, "r", encoding="utf-8") as f:
try:
data = json.load(f)
except (json.JSONDecodeError, OSError):
return []
creds = data.get("credentials")
with open(config_path, "r", encoding="utf-8") as f:
try:
data = json.load(f)
except (json.JSONDecodeError, OSError):
return []
if not isinstance(data, dict):
return []
creds = data.get("credentials")

if not isinstance(creds, list):
return []
return creds


def _capture_one(
entry: dict[str, Any], force: bool
) -> tuple[bool, str | None]:
"""Attempt to capture a single credential. Returns (success, error_msg)."""
key = entry.get("key", "")
source = _expand(entry.get("source", ""))
secret_type = entry.get("type", "file")
target = entry.get("target", "")

if not key or not source:
return False, "invalid entry: missing key or source"

if not os.path.isfile(source):
return False, None

cmd = [
"sciontool", "secret", "set", key, f"@{source}",
"--type", secret_type,
"--target", target,
]
if force:
cmd.append("--force")

try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=30,
)
except FileNotFoundError:
return False, "sciontool not found in PATH"
except subprocess.TimeoutExpired:
return False, f"sciontool timed out for key {key}"

if result.returncode != 0:
stderr = result.stderr.strip()
return False, f"sciontool failed for {key}: {stderr}"

return True, None


def main() -> int:
parser = argparse.ArgumentParser(
description="Capture auth credentials and store as project secrets"
)
parser.add_argument(
"--force",
action="store_true",
help="Overwrite existing secrets",
)
parser.add_argument(
"--bundle",
default=HARNESS_BUNDLE,
help="Path to harness bundle directory",
)
args = parser.parse_args()

entries = _load_config(args.bundle)
if not entries:
print(
"capture-auth: no credential mappings found in "
"inputs/capture-auth-config.json",
file=sys.stderr,
)
return EXIT_NO_CREDS

captured = 0
errors = 0

for entry in entries:
key = entry.get("key", "<unknown>")
source = entry.get("source", "")
expanded = _expand(source) if source else ""

if not expanded or not os.path.isfile(expanded):
print(f"capture-auth: {key}: source not found ({source})")
continue

ok, err = _capture_one(entry, args.force)
if err:
print(f"capture-auth: {key}: {err}", file=sys.stderr)
errors += 1
elif ok:
print(f"capture-auth: {key}: captured from {source}")
captured += 1

if errors > 0 and captured == 0:
return EXIT_ERROR

if captured == 0:
print("capture-auth: no credentials found to capture")
return EXIT_NO_CREDS

print(f"capture-auth: {captured} credential(s) captured successfully")
return EXIT_OK


if __name__ == "__main__":
sys.exit(main())
57 changes: 57 additions & 0 deletions harnesses/hermes/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Per-bundle Cloud Build configuration for the Hermes harness image.
# Builds scion-hermes on top of scion-base:<_TAG>.
steps:
- name: 'gcr.io/cloud-builders/docker'
id: 'setup-buildx'
args: ['buildx', 'create', '--name', 'mybuilder', '--use']
env:
- 'DOCKER_CLI_EXPERIMENTAL=enabled'

- name: 'gcr.io/cloud-builders/docker'
id: 'bootstrap-buildx'
args: ['buildx', 'inspect', '--bootstrap']
env:
- 'DOCKER_CLI_EXPERIMENTAL=enabled'

- name: 'gcr.io/cloud-builders/docker'
id: 'build-scion-hermes'
args:
- 'buildx'
- 'build'
- '--platform'
- 'linux/amd64,linux/arm64'
- '--build-arg'
- 'BASE_IMAGE=$_REGISTRY/scion-base:$_TAG'
- '-t'
- '$_REGISTRY/scion-hermes:$_SHORT_SHA'
- '-t'
- '$_REGISTRY/scion-hermes:$_TAG'
- '-f'
- 'Dockerfile'
- '--pull'
- '--push'
- '.'
env:
- 'DOCKER_CLI_EXPERIMENTAL=enabled'

substitutions:
_REGISTRY: 'us-central1-docker.pkg.dev/${PROJECT_ID}/public-docker'
_TAG: 'latest'
options:
dynamicSubstitutions: true
machineType: 'E2_HIGHCPU_8'
timeout: 1200s
Loading
Loading