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
28 changes: 28 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## What kind of change is this?

- [ ] bug fix
- [ ] bug fix + test
- [ ] feature
- [ ] refactor / cleanup
- [ ] docs / comments
- [ ] test-only
- [ ] security fix

## Summary

Briefly describe the change and why it is needed.

## Branch

This PR was opened from a branch using one of:
- `fix/…`
- `bugs/…`
- `feature/…`

## Checklist

- [ ] Tests pass: `python -m pytest -q`
- [ ] `verify.py` is green
- [ ] No raw tokens/secrets in code, logs, or tool output
- [ ] Adapter stays loopback-only unless an explicit guard is added
- [ ] Updated docs/README if user-facing behavior changed
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ jobs:
HERMES_HOME: ${{ env.HERMES_HOME }}
run: |
set -euo pipefail
# Adapter tests bind a local port and can hang in CI; the same subset
# is excluded when running locally.
python -m pytest -q -k "not adapter"
python -m pytest -q

- name: Run plugin self-checks (verify.py)
working-directory: ${{ env.HERMES_HOME }}/plugins/builder
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/pr-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PR auto-label by branch prefix

on:
pull_request:
types: [opened, synchronize, reopened]
Comment on lines +3 to +5

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Fork PR labeling fails

For normal fork PRs, pull_request supplies a read-only token. Requesting pull-requests: write does not override that restriction. A fork branch named fix/... or feature/... therefore reaches addLabels and fails with a permission error. Use pull_request_target for this metadata-only job, without checking out or running PR code.

Suggested change
on:
pull_request:
types: [opened, synchronize, reopened]
on:
pull_request_target:
types: [opened, synchronize, reopened]

Fix in Cursor


jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
const branch = context.payload.pull_request.head.ref
const labels = {
'fix/': 'bug',
'bugs/': 'bug',
'feature/': 'enhancement'
}
const mapping = Object.entries(labels).find(([prefix]) => branch.startsWith(prefix))
if (!mapping) return
const [, label] = mapping
await github.rest.issues.addLabels({
...context.repo,
issue_number: context.issue.number,
labels: [label]
})
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ set up, test, and submit changes.
`test(builder):`, `refactor(builder):`, `sec(builder):`. Bodies only
when a critical bug/security reason must be recorded. Keep subjects ≤ ~72
chars.
- **Branches:** use one of `fix/`, `bugs/`, or `feature/` plus a short
descriptor. Examples: `fix/setup-dual-activation`, `feature/chat-tools`.
This repo uses lightweight auto-labeling, so matching these prefixes keeps
PRs labeled automatically.

## Development setup

Expand Down
2 changes: 1 addition & 1 deletion backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _resolve_model_id(model: Optional[str]) -> str:
return requested
import logging

logging.getLogger(__name__).warning(
logging.getLogger(__name__).debug(
"builder: unknown model %r not in catalog %s; using 'auto' "
"(Q returns HTTP 500 for unsupported modelId)",
requested,
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# core. CI therefore checks out Hermes core (hermes-agent) as a sibling and runs
# the suite from that layout (see .github/workflows/ci.yml). These pins match
# the versions in the hermes-agent venv so CI behaves like the real environment.
hermes-agent @ git+https://github.com/NousResearch/hermes-agent.git@main#egg=hermes-agent
hermes-agent @ git+https://github.com/NousResearch/hermes-agent.git@a88512b114059fff642d60d54cbf30d5793c6c37#egg=hermes-agent
pytest==9.0.3
requests==2.33.0
PyYAML==6.0.3
botocore==1.42.97
cryptography==48.0.1
cryptography>=46.0.7
94 changes: 70 additions & 24 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# compatible adapter (adapter.py, launched by register()) that translates to
# Amazon Q. This script adds the providers: builder entry pointing at that
# adapter (localhost :8077) — NO :8088 bridge daemon, no orphaned ref.
# It ALSO adds builder to plugins.enabled so the plugin module loads and
# register() actually starts the adapter. Without both, the model picker
# shows a dead endpoint.
#
# SAFE: idempotent (skips if already present), always backs up config.yaml
# first. Does NOT touch any other provider. User-invoked (never auto-run by
Expand All @@ -20,69 +23,112 @@ CONFIG="${HERMES_HOME:-$HOME/.hermes}/config.yaml"
BACKUP="${CONFIG}.bak.$(date +%Y%m%d_%H%M%S)"
PORT="${AWS_BUILD_ADAPTER_PORT:-8077}"


if [[ ! -f "$CONFIG" ]]; then
echo "✗ config.yaml not found at $CONFIG" >&2
exit 1
fi

# Idempotency: already present?
if grep -qE '^[[:space:]]*builder:' "$CONFIG"; then
echo "✓ providers: builder already present in $CONFIG — nothing to do."
echo " Restart Hermes if you haven't since installing the plugin."
exit 0
# Resolve a Python that has PyYAML. Prefer `python3` on PATH; fall back to
# the Hermes venv if the user's PATH is minimal.
PYTHON="$(command -v python3 || true)"
if [[ -z "$PYTHON" ]]; then
Comment on lines +33 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Setup picks Python without PyYAML

If system Python is on PATH but PyYAML is installed only in the Hermes virtual environment, the new unconditional import yaml fails before setup edits the config. Interpreter selection only checks whether python3 exists, so it never tries the Hermes environment. Check that each candidate can import yaml before selecting it.

Fix in Cursor

# Try the Hermes venv under HERMES_HOME or ~/.hermes.
HM="${HERMES_HOME:-$HOME/.hermes}"
for candidate in \
"$HM/hermes-agent/venv/bin/python3" \
"$HM/venv/bin/python3"; do
if [[ -x "$candidate" ]]; then
PYTHON="$candidate"
break
fi
done
fi
if [[ -z "$PYTHON" ]]; then
echo "✗ python3 is required for config edits (install Python or add it to PATH)." >&2
exit 1
fi

# Backup
# Backup once
cp "$CONFIG" "$BACKUP"
echo "✓ backed up config → $BACKUP"

# Insert the block as a top-level providers: key, using Python
# (reliable indentation handling). Idempotent: only if absent.
# Write the block to a temp file (real newlines, not escaped).
# Resolve plugin root and manifest.
PLUGIN_DIR="${HERMES_HOME:-$HOME/.hermes}/plugins/builder"
PLUGIN_YAML="$PLUGIN_DIR/plugin.yaml"

# Write the provider block to a temp file.
# NOTE: model list is read from plugin.yaml at install time so setup.sh and
# backend.py cannot drift. key_env removed: the adapter does not need one.
BLOCK_FILE="$(mktemp)"
cat > "$BLOCK_FILE" <<EOF
builder:
name: AWS Builder ID
transport: openai_chat
base_url: http://127.0.0.1:${PORT}/v1
key_env: AWS_BUILD_ADAPTER_DUMMY
models:
- auto
- claude-sonnet-4.5
- claude-sonnet-4
- claude-haiku-4.5
EOF

python3 - "$CONFIG" "$BLOCK_FILE" <<'PY'
"$PYTHON" - "$PLUGIN_YAML" "$BLOCK_FILE" <<'PY'
import sys, yaml
from pathlib import Path
yaml_path = Path(sys.argv[1])
block_path = Path(sys.argv[2])
raw = yaml.safe_load(yaml_path.read_text()) or {}
models = raw.get("models") or []
block = block_path.read_text()
if models:
for m in models:
block += f"\n - {m}"
else:
block += "\n - auto"
block_path.write_text(block)
PY

# 1) Insert providers: builder block (idempotent: Python exits 0 if already present)
"$PYTHON" - "$CONFIG" "$BLOCK_FILE" <<'PY'
import sys
cfg, blockfile = sys.argv[1], sys.argv[2]
block = open(blockfile).read().rstrip("\n")
lines = open(cfg).read().splitlines()
if any(l.strip() == "builder:" for l in lines):
sys.exit(0) # idempotent guard (shell already checked)
sys.exit(0)
# If no providers: block exists, insert one first.
if not any(l.strip() == "providers:" for l in lines):
lines.append("providers:")
Comment on lines +95 to +97

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Setup fails without providers

The new missing-providers fallback appends providers: as the last line, but the loop checks in_prov before setting it for that line. The builder block is never written, so the final check restores the backup and exits with an error. Insert the block together with the new section, and test a config without providers.

Fix in Cursor

out, i, n, in_prov, done = [], 0, len(lines), False, False
while i < n:
out.append(lines[i])
# We are inside the providers: block (set when we saw 'providers:'
# at col 0). Append the builder block once, right before the
# block closes (next line at col 0, or EOF).
if not done and in_prov and (
i + 1 == n or (lines[i + 1] and not lines[i + 1].startswith(" "))
):
out.extend(block.splitlines())
done = True
if lines[i] == "providers:":
if lines[i].strip() == "providers:":
in_prov = True
elif lines[i] and not lines[i].startswith(" ") and lines[i] != "providers:":
in_prov = False # left the providers block (next top-level key)
elif lines[i] and not lines[i].startswith(" ") and lines[i].strip() != "providers:":
in_prov = False
i += 1
open(cfg, "w").write("\n".join(out) + "\n")
PY
rm -f "$BLOCK_FILE"

# 2) Ensure builder is in plugins.enabled (idempotent)
"$PYTHON" - "$CONFIG" <<'PY'
import sys
import yaml
cfg = sys.argv[1]
c = yaml.safe_load(open(cfg)) or {}
en = (c.get("plugins") or {}).get("enabled") or []
if "builder" not in [str(x) for x in en]:
c.setdefault("plugins", {})["enabled"] = [str(x) for x in en] + ["builder"]
yaml.safe_dump(c, open(cfg, "w"), sort_keys=False, default_flow_style=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Setup erases config comments

Adding builder to plugins.enabled now rewrites all of config.yaml with yaml.safe_dump. On a normal first setup, this removes every existing YAML comment, including notes beside unrelated providers. Update only the enabled list, or use a YAML editor that preserves comments.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Cursor

print("added_builder_to_enabled")
else:
print("builder_already_enabled")
PY

if grep -qE '^[[:space:]]*builder:' "$CONFIG"; then
echo "✓ added providers: builder → http://127.0.0.1:${PORT}/v1 (transport: openai_chat)"
echo "✓ providers: builder → http://127.0.0.1:${PORT}/v1 (transport: openai_chat)"
echo "✓ NO :8088 bridge — adapter launches inside the plugin on register()."
echo
echo "NEXT: restart Hermes, then in TUI/CLI use '-m builder' or pick 'AWS Builder ID'."
Expand Down
52 changes: 34 additions & 18 deletions scripts/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ if [[ ! -f "$CONFIG" ]]; then
exit 1
fi

# Idempotency: nothing to remove?
if ! grep -qE '^[[:space:]]*builder:' "$CONFIG"; then
echo "✓ providers: builder already absent from $CONFIG — nothing to do."
# still normalize plugins.enabled (in case it lists builder without a provider block)
else
# Backup (once)
BACKUP="${CONFIG}.bak.$(date +%Y%m%d_%H%M%S)"
cp "$CONFIG" "$BACKUP"
echo "✓ backed up config → $BACKUP"
# Resolve a Python that can execute the inline config-edit scripts.
PYTHON="$(command -v python3 || true)"
if [[ -z "$PYTHON" ]]; then
HM="${HERMES_HOME:-$HOME/.hermes}"
for candidate in \
"$HM/hermes-agent/venv/bin/python3" \
"$HM/venv/bin/python3"; do
if [[ -x "$candidate" ]]; then
PYTHON="$candidate"
break
fi
done
fi
if [[ -z "$PYTHON" ]]; then
echo "✗ python3 is required for config edits (install Python or add it to PATH)." >&2
exit 1
fi

# Remove the providers: builder block (the 'builder:' key, which is
# indented under 'providers:', plus its child lines). Match on stripped
# line == 'builder:' (unique key, any indentation).
python3 - "$CONFIG" <<'PY'
# Backup once
BACKUP="${CONFIG}.bak.$(date +%Y%m%d_%H%M%S)"
cp "$CONFIG" "$BACKUP"
echo "✓ backed up config → $BACKUP"

# 1) Remove the providers: builder block (idempotent)
"$PYTHON" - "$CONFIG" <<'PY'
import sys
cfg = sys.argv[1]
lines = open(cfg).read().splitlines()
Expand All @@ -52,21 +63,26 @@ for ln in lines:
out.append(ln)
open(cfg, "w").write("\n".join(out).rstrip("\n") + "\n")
PY

if grep -qE '^[[:space:]]*builder:' "$CONFIG"; then
echo "✓ providers: builder still present — check backup $BACKUP"
else
echo "✓ removed providers: builder from $CONFIG"
fi

# Normalize plugins.enabled (remove builder if present) — backup-safe.
python3 - "$CONFIG" <<'PY'
# 2) Normalize plugins.enabled (remove builder if present)
"$PYTHON" - "$CONFIG" <<'PY'
import sys, yaml
cfg = sys.argv[1]
c = yaml.safe_load(open(cfg))
c = yaml.safe_load(open(cfg)) or {}
en = (c.get("plugins") or {}).get("enabled") or []
en = [str(x) for x in en]
if "builder" in en:
c.setdefault("plugins", {})["enabled"] = [x for x in en if x != "builder"]
yaml.safe_dump(c, open(cfg, "w"), sort_keys=False, default_flow_style=False)
print("✓ removed builder from plugins.enabled")
print("removed_builder_from_enabled")
else:
print("✓ builder not in plugins.enabled — nothing to do.")
print("builder_not_in_enabled")
PY

echo
Expand Down
3 changes: 2 additions & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ def iter_content(self, chunk_size=1024):
# Refresh "succeeds" but the next 401 still happens -> bounded retry.
monkeypatch.setattr(sso_oidc, "refresh_token", lambda: True)
with pytest.raises(RuntimeError):
backend.chat("hi", model="claude-sonnet-4")
# The first call retries once after refresh; the second 401 must raise
# rather than recursing forever.
backend.chat("hi", model="claude-sonnet-4")


Expand Down
Loading
Loading