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
1 change: 1 addition & 0 deletions hermes_cli/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _cmd_list(_args) -> None:
},
"on_session_start": {"session_id": "test-session"},
"on_session_end": {"session_id": "test-session"},
"on_turn_end": {"session_id": "test-session", "completed": True, "interrupted": False},
"on_session_finalize": {"session_id": "test-session"},
"on_session_reset": {"session_id": "test-session"},
"pre_api_request": {
Expand Down
1 change: 1 addition & 0 deletions hermes_cli/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _install_plugin_debug_handler(force: bool = False) -> None:
"post_api_request",
"on_session_start",
"on_session_end",
"on_turn_end",
"on_session_finalize",
"on_session_reset",
"subagent_stop",
Expand Down
2 changes: 1 addition & 1 deletion plugins/disk-cleanup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _handle_slash(raw_args: str) -> Optional[str]:

def register(ctx) -> None:
ctx.register_hook("post_tool_call", _on_post_tool_call)
ctx.register_hook("on_session_end", _on_session_end)
ctx.register_hook("on_turn_end", _on_session_end)
ctx.register_command(
"disk-cleanup",
handler=_handle_slash,
Expand Down
11 changes: 6 additions & 5 deletions run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15700,21 +15700,22 @@ def _stop_spinner():
# handled by the CLI (atexit / /reset) and gateway (session expiry /
# _reset_session).

# Plugin hook: on_session_end
# Fired at the very end of every run_conversation call.
# Plugins can use this for cleanup, flushing buffers, etc.
# Plugin hook: on_turn_end (fires every run_conversation call,
# i.e. once per user message — NOT at session boundaries).
# Use on_session_end for actual session-end cleanup (CLI exit,
# /reset, gateway session expiry).
try:
from hermes_cli.plugins import invoke_hook as _invoke_hook
_invoke_hook(
"on_session_end",
"on_turn_end",
session_id=self.session_id,
completed=completed,
interrupted=interrupted,
model=self.model,
platform=getattr(self, "platform", None) or "",
)
except Exception as exc:
logger.warning("on_session_end hook failed: %s", exc)
logger.warning("on_turn_end hook failed: %s", exc)

return result

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/test_disk_cleanup_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* ``disk_cleanup`` library: track / forget / dry_run / quick / status,
``is_safe_path`` and ``guess_category`` filtering.
* Plugin ``__init__``: ``post_tool_call`` hook auto-tracks files created
by ``write_file`` / ``terminal``; ``on_session_end`` hook runs quick
by ``write_file`` / ``terminal``; ``on_turn_end`` hook runs quick
cleanup when anything was tracked during the turn.
* Slash command handler: status / dry-run / quick / track / forget /
unknown subcommand behaviours.
Expand Down Expand Up @@ -394,7 +394,7 @@ def test_disk_cleanup_loads_when_enabled(self, _isolate_env):
loaded = mgr._plugins["disk-cleanup"]
assert loaded.enabled
assert "post_tool_call" in loaded.hooks_registered
assert "on_session_end" in loaded.hooks_registered
assert "on_turn_end" in loaded.hooks_registered
assert "disk-cleanup" in loaded.commands_registered

def test_disabled_beats_enabled(self, _isolate_env):
Expand Down
Loading