-
Notifications
You must be signed in to change notification settings - Fork 10.8k
feat: add Hermes Agent integration (with review fixes) #2651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6a17aab
feat: add Hermes Agent integration
Zhaoxiaoguang001 cd91046
feat: add Hermes Agent integration
Zhaoxiaoguang001 e83cd54
feat: add Hermes Agent integration
Zhaoxiaoguang001 541b278
feat: add Hermes Agent integration (with review fixes)
majordave f19a57e
feat: write Hermes skills directly to global ~/.hermes/skills/
majordave 70f5732
fix: address Copilot review feedback on Hermes integration
majordave a5fd163
Merge upstream/main into feat/hermes-integration (local only, no push)
majordave 6e9af2b
fix: address second Copilot review round — 6 remaining observations
majordave 3da5e0b
fix: add first-class global/home-based agent dir support in CommandRe…
majordave b938619
fix: address remaining 3 Copilot review observations (round 3)
majordave a90862b
fix: address Copilot round 4 — home-relative dir resolution + project…
majordave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,257 @@ | ||
| """Hermes Agent integration — skills-based agent. | ||
|
|
||
| Hermes Agent (https://github.com/NousResearch/hermes-agent) is an open-source | ||
| AI agent framework by Nous Research. It stores skills in | ||
| ``~/.hermes/skills/`` (user-global) rather than a project-local directory. | ||
|
|
||
| Usage:: | ||
|
|
||
| specify init my-project --integration hermes | ||
| specify init --here --ai hermes | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
| from shutil import rmtree | ||
| from typing import Any | ||
|
|
||
| from ..base import IntegrationOption, SkillsIntegration | ||
| from ..manifest import IntegrationManifest | ||
|
|
||
|
|
||
| class HermesIntegration(SkillsIntegration): | ||
| """Integration for Hermes Agent skills. | ||
|
|
||
| Hermes loads skills from ``~/.hermes/skills/`` (user home directory) | ||
| rather than a project-local path. Skills are installed directly to | ||
| the global directory — no project-local copies are created since | ||
| Hermes discovers them globally. A project-local marker directory | ||
| (``.hermes/skills/`` empty) is created so extension commands (e.g. | ||
| git) can detect Hermes as an active integration. Uninstall removes | ||
| both the marker and global skills. | ||
|
mnriem marked this conversation as resolved.
Outdated
|
||
| """ | ||
|
|
||
| key = "hermes" | ||
| config = { | ||
| "name": "Hermes Agent", | ||
| "folder": ".hermes/", | ||
| "commands_subdir": "skills", | ||
| "install_url": "https://github.com/NousResearch/hermes-agent", | ||
| "requires_cli": True, | ||
| } | ||
| registrar_config = { | ||
| "dir": ".hermes/skills", | ||
| "format": "markdown", | ||
| "args": "$ARGUMENTS", | ||
| "extension": "/SKILL.md", | ||
| } | ||
|
mnriem marked this conversation as resolved.
|
||
| context_file = "AGENTS.md" | ||
|
|
||
| # -- Helpers ----------------------------------------------------------- | ||
|
|
||
| @staticmethod | ||
| def _hermes_home_skills_dir() -> Path: | ||
| """Return ``~/.hermes/skills/`` — the global skills directory.""" | ||
| return Path.home() / ".hermes" / "skills" | ||
|
|
||
| # -- Options ----------------------------------------------------------- | ||
|
|
||
| @classmethod | ||
| def options(cls) -> list[IntegrationOption]: | ||
| return [ | ||
| IntegrationOption( | ||
| "--skills", | ||
| is_flag=True, | ||
| default=True, | ||
| help="Install as agent skills (default for Hermes Agent)", | ||
| ), | ||
| ] | ||
|
|
||
| # -- Setup ------------------------------------------------------------- | ||
|
|
||
| def setup( | ||
| self, | ||
| project_root: Path, | ||
| manifest: IntegrationManifest, | ||
| parsed_options: dict[str, Any] | None = None, | ||
| **opts: Any, | ||
| ) -> list[Path]: | ||
| """Install command templates as global Hermes skills. | ||
|
|
||
| Writes each skill directly to | ||
| ``~/.hermes/skills/speckit-<name>/SKILL.md`` where Hermes | ||
| discovers them at runtime. No project-local SKILL.md copies are | ||
| created — the global directory is the single source of truth. | ||
| A project-local marker (``.hermes/skills/`` empty) is created | ||
| so extension commands (e.g. git) can detect Hermes as an active | ||
| integration. | ||
|
mnriem marked this conversation as resolved.
|
||
| """ | ||
| templates = self.list_command_templates() | ||
| if not templates: | ||
| return [] | ||
|
|
||
| script_type = opts.get("script_type", "sh") | ||
| arg_placeholder = ( | ||
| self.registrar_config.get("args", "$ARGUMENTS") | ||
| if self.registrar_config | ||
| else "$ARGUMENTS" | ||
| ) | ||
|
|
||
| global_skills_dir = self._hermes_home_skills_dir() | ||
| global_skills_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
|
mnriem marked this conversation as resolved.
|
||
| created: list[Path] = [] | ||
|
|
||
| for src_file in templates: | ||
| raw = src_file.read_text(encoding="utf-8") | ||
|
|
||
| # Derive the skill name from the template stem | ||
| command_name = src_file.stem # e.g. "plan" | ||
| skill_name = f"speckit-{command_name.replace('.', '-')}" | ||
|
|
||
| # Parse frontmatter for description | ||
| frontmatter: dict[str, Any] = {} | ||
| if raw.startswith("---"): | ||
| parts = raw.split("---", 2) | ||
| if len(parts) >= 3: | ||
| import yaml | ||
|
|
||
| try: | ||
| fm = yaml.safe_load(parts[1]) | ||
| if isinstance(fm, dict): | ||
| frontmatter = fm | ||
| except yaml.YAMLError: | ||
| pass | ||
|
mnriem marked this conversation as resolved.
|
||
|
|
||
| # Process body through the standard template pipeline | ||
| processed_body = self.process_template( | ||
| raw, | ||
| self.key, | ||
| script_type, | ||
| arg_placeholder, | ||
| context_file=self.context_file or "", | ||
| invoke_separator=self.invoke_separator, | ||
| ) | ||
| # Strip the processed frontmatter — we rebuild it for skills. | ||
| if processed_body.startswith("---"): | ||
| parts = processed_body.split("---", 2) | ||
| if len(parts) >= 3: | ||
| processed_body = parts[2] | ||
|
|
||
| # Select description | ||
| description = frontmatter.get("description", "") | ||
| if not description: | ||
| description = f"Spec Kit: {command_name} workflow" | ||
|
|
||
| # Build SKILL.md with manually formatted frontmatter | ||
| def _quote(v: str) -> str: | ||
| escaped = v.replace("\\", "\\\\").replace('"', '\\"') | ||
| return f'"{escaped}"' | ||
|
|
||
| skill_content = ( | ||
| f"---\n" | ||
| f"name: {_quote(skill_name)}\n" | ||
| f"description: {_quote(description)}\n" | ||
| f"compatibility: " | ||
| f"{_quote('Requires spec-kit project structure with .specify/ directory')}\n" | ||
| f"metadata:\n" | ||
| f" author: {_quote('github-spec-kit')}\n" | ||
| f" source: {_quote('templates/commands/' + src_file.name)}\n" | ||
| f"---\n" | ||
| f"{processed_body}" | ||
| ) | ||
|
|
||
| # Write directly to global ~/.hermes/skills/speckit-<name>/SKILL.md | ||
| skill_dir = global_skills_dir / skill_name | ||
| skill_dir.mkdir(parents=True, exist_ok=True) | ||
| skill_file = skill_dir / "SKILL.md" | ||
| normalized = skill_content.replace("\r\n", "\n") | ||
| skill_file.write_bytes(normalized.encode("utf-8")) | ||
| created.append(skill_file) | ||
|
|
||
| # Upsert managed context section into the agent context file | ||
| self.upsert_context_section(project_root) | ||
|
|
||
| # Create project-local marker directory so extension commands | ||
| # (e.g. git) can detect Hermes as an active integration. | ||
| # Hermes itself ignores this directory — skills live globally. | ||
| (project_root / ".hermes" / "skills").mkdir(parents=True, exist_ok=True) | ||
|
mnriem marked this conversation as resolved.
|
||
|
|
||
| return created | ||
|
|
||
| # -- Uninstall --------------------------------------------------------- | ||
|
|
||
| def teardown( | ||
| self, | ||
| project_root: Path, | ||
| manifest: IntegrationManifest, | ||
| *, | ||
| force: bool = False, | ||
| ) -> tuple[list[Path], list[Path]]: | ||
|
mnriem marked this conversation as resolved.
|
||
| """Uninstall integration files and clean up global skills. | ||
|
|
||
| Removes the managed context section from AGENTS.md, removes the | ||
| project-local marker directory, and deletes all ``speckit-*`` | ||
| directories from ``~/.hermes/skills/``. | ||
| """ | ||
| # Remove managed context section from AGENTS.md | ||
| self.remove_context_section(project_root) | ||
|
|
||
| # Remove project-local marker directory if empty | ||
| local_skills_dir = project_root / ".hermes" / "skills" | ||
| if local_skills_dir.is_dir() and not any(local_skills_dir.iterdir()): | ||
| local_skills_dir.rmdir() | ||
| hermes_dir = project_root / ".hermes" | ||
| if hermes_dir.is_dir() and not any(hermes_dir.iterdir()): | ||
| hermes_dir.rmdir() | ||
|
|
||
|
mnriem marked this conversation as resolved.
|
||
| # Remove global Hermes skills for speckit | ||
| removed: list[Path] = [] | ||
| global_skills_dir = self._hermes_home_skills_dir() | ||
| if global_skills_dir.is_dir(): | ||
| for skill_dir in sorted(global_skills_dir.iterdir()): | ||
| if skill_dir.is_dir() and skill_dir.name.startswith("speckit-"): | ||
| skill_file = skill_dir / "SKILL.md" | ||
| if skill_file.exists(): | ||
| removed.append(skill_file) | ||
|
mnriem marked this conversation as resolved.
Outdated
|
||
| rmtree(skill_dir, ignore_errors=True) | ||
|
|
||
| return removed, [] | ||
|
|
||
| # -- CLI dispatch ------------------------------------------------------ | ||
|
|
||
| def build_exec_args( | ||
| self, | ||
| prompt: str, | ||
| *, | ||
| model: str | None = None, | ||
| output_json: bool = True, | ||
| ) -> list[str] | None: | ||
| """Build Hermes CLI invocation for programmatic dispatch. | ||
|
|
||
| Uses ``hermes chat -Q -q`` for one-shot queries in quiet mode, | ||
| mapping slash-command invocations to the appropriate skill-based | ||
| dispatch. | ||
| """ | ||
| args = [self.key, "chat", "-Q"] | ||
|
|
||
| if model: | ||
| args.extend(["-m", model]) | ||
| if output_json: | ||
| args.append("--json") | ||
|
|
||
| # If prompt starts with a slash command, pass it directly | ||
| # so Hermes can dispatch to the appropriate skill. | ||
| if prompt.startswith("/"): | ||
| command, _, remainder = prompt[1:].partition(" ") | ||
| if command: | ||
| args.extend(["-s", command]) | ||
| if remainder: | ||
| args.extend(["-q", remainder]) | ||
| else: | ||
| args.extend(["-q", prompt]) | ||
| else: | ||
| args.extend(["-q", prompt]) | ||
|
|
||
| return args | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.