The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): ${HERMES_PYTHON} runs a script the way Hermes runs itself
alt-glitchf269dfc8b2ca
diff --git a/agent/skill_preprocessing.py b/agent/skill_preprocessing.pyindex 2f14f3fe40c..e9e23ac0030 100644--- a/agent/skill_preprocessing.py+++ b/agent/skill_preprocessing.py@@ -3,7 +3,9 @@ inline ``!`cmd``` shell expansion."""import loggingimport re+import shleximport subprocess+import sysfrom pathlib import Pathfrom agent.compression_marker import elide@@ -32,12 +34,17 @@ def load_skills_config() -> dict:return {}-def _project_python() -> str | None:- from pm.environments import project_python+def _hermes_python() -> str:+ from hermes_cli._launchers import runtime_commandfrom pm.paths import repo_root- python = project_python(repo_root())- return str(python) if python.is_file() else None+ command = runtime_command(+ repo_root(),+ code="sys.argv[:1] = []; sys.path.insert(0, os.path.dirname(os.path.abspath(sys.argv[0]))); "+ "runpy.run_path(sys.argv[0], run_name='__main__')",+ python=sys.executable if sys.prefix != sys.base_prefix else None,+ )+ return shlex.join(["HERMES_DISABLE_LAZY_INSTALLS=1", *command])def substitute_template_vars(content: str, skill_dir: Path | None, session_id: str | None) -> str:@@ -47,7 +54,7 @@ def substitute_template_vars(content: str, skill_dir: Path | None, session_id: svalues = {"HERMES_SKILL_DIR": str(skill_dir) if skill_dir else None,"HERMES_SESSION_ID": str(session_id) if session_id else None,- "HERMES_PYTHON": _project_python() if "${HERMES_PYTHON}" in content else None,+ "HERMES_PYTHON": _hermes_python() if "${HERMES_PYTHON}" in content else None,}return _SKILL_TEMPLATE_RE.sub(lambda m: values[m.group(1)] or m.group(0), content)diff --git a/optional-skills/productivity/initiate-setup/SKILL.md b/optional-skills/productivity/initiate-setup/SKILL.mdindex 22a1d2438b2..8fb14b90f21 100644--- a/optional-skills/productivity/initiate-setup/SKILL.md+++ b/optional-skills/productivity/initiate-setup/SKILL.md@@ -53,7 +53,7 @@ Session facts (added by the builder):Host facts (from `scripts/host_facts.py`, filled in when this skill loads):-!`"${HERMES_PYTHON}" scripts/host_facts.py`+!`${HERMES_PYTHON} scripts/host_facts.py`| Field | Meaning | How to use it ||---|---|---|diff --git a/website/docs/developer-guide/creating-skills.md b/website/docs/developer-guide/creating-skills.mdindex 3da80fb1d67..d95ac79bfcc 100644--- a/website/docs/developer-guide/creating-skills.md+++ b/website/docs/developer-guide/creating-skills.md@@ -289,7 +289,7 @@ When a skill is loaded, the activation message exposes the absolute skill direct|---|---|| `${HERMES_SKILL_DIR}` | Absolute path to the skill's directory || `${HERMES_SESSION_ID}` | The active session id (left in place if there is no session) |-| `${HERMES_PYTHON}` | Absolute path to the interpreter of Hermes's own dependency environment, as the package manager selected it (it has Hermes's code and dependencies importable) |+| `${HERMES_PYTHON}` | A shell-quoted command prefix that runs a Python script the way Hermes runs itself: this install's interpreter, its live code and dependencies, lazy installs off. Write it unquoted: `${HERMES_PYTHON} scripts/tool.py` |So a SKILL.md can tell the agent to run a bundled script directly with:diff --git a/website/docs/user-guide/skills/optional/productivity/productivity-initiate-setup.md b/website/docs/user-guide/skills/optional/productivity/productivity-initiate-setup.mdindex ea40e3f2eeb..f879e59c267 100644--- a/website/docs/user-guide/skills/optional/productivity/productivity-initiate-setup.md+++ b/website/docs/user-guide/skills/optional/productivity/productivity-initiate-setup.md@@ -70,7 +70,7 @@ Session facts (added by the builder):Host facts (from `scripts/host_facts.py`, filled in when this skill loads):-!`"${HERMES_PYTHON}" scripts/host_facts.py`+!`${HERMES_PYTHON} scripts/host_facts.py`| Field | Meaning | How to use it ||---|---|---|diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/creating-skills.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/creating-skills.mdindex 20ee3d2adef..edfeeeb1bd6 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/creating-skills.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/creating-skills.md@@ -284,7 +284,7 @@ Skill 加载时,激活消息会将 skill 目录的绝对路径以 `[Skill dire|---|---|| `${HERMES_SKILL_DIR}` | skill 目录的绝对路径 || `${HERMES_SESSION_ID}` | 当前会话 ID(若无会话则保留原样) |-| `${HERMES_PYTHON}` | 包管理器为 Hermes 自身依赖环境选定的 Python 解释器的绝对路径(可导入 Hermes 的代码和依赖) |+| `${HERMES_PYTHON}` | 已做 shell 转义的命令前缀,以 Hermes 运行自身的方式运行 Python 脚本:本安装的解释器、当前代码和依赖,并关闭按需安装。不要加引号:`${HERMES_PYTHON} scripts/tool.py` |因此,SKILL.md 可以直接告知 agent 运行内置脚本: