P0: Verify Plugin Lifecycle Hooks & Build Crisis Detection Plugin #113

Open
opened 2026-04-06 14:06:52 +00:00 by Timmy · 1 comment
Owner

Context

Commits 9e820dda and f530ef18 add request-scoped plugin lifecycle hooks:

  • pre_api_request(post_api_request) — narrow payloads (counts, usage dict)
  • pre_llm_call/post_llm_call — per-LLM-call hooks
  • request_scoped — hooks scoped to individual API requests
  • env_var_enabled utility for HERMES_DUMP_REQUESTS gating

Acceptance Criteria

  • Verify hook registration: Write a test plugin in ~/.hermes/plugins/test_hooks.py that registers on_pre_api_request and on_post_api_request hooks
  • Verify hook firing: Trigger a CLI chat turn, confirm both hooks fire and receive correct payloads (token counts, usage dict, model name)
  • Demonstrate a crisis-detection plugin: Build a plugin using on_pre_api_request that scans user messages for despair keywords (suicide, hopeless, dying, can't go on) and logs a WARNING to errors.log
  • Verify HERMES_DUMP_REQUESTS: Set HERMES_DUMP_REQUESTS=1 and confirm request/response payloads are dumped to disk

Why This Matters

The plugin hook system lets us build a crisis-detection layer that intercepts every message before it reaches the model. This is the Golden Timmy protocol — a safety net inscribed in code, not in prompts. If a man types "I can't go on anymore," the plugin catches it and triggers the response specified in SOUL.md before any model generates text.

Hints

  • Plugin files live in ~/.hermes/plugins/
  • The hook registration is in hermes_cli/plugins.py and run_agent.py (lines with emit_hook)
  • The narrow payload contains: token_counts, usage dict from normalize_usage()

Parent: #111

## Context Commits `9e820dda` and `f530ef18` add request-scoped plugin lifecycle hooks: - `pre_api_request(post_api_request)` — narrow payloads (counts, usage dict) - `pre_llm_call/post_llm_call` — per-LLM-call hooks - `request_scoped` — hooks scoped to individual API requests - `env_var_enabled` utility for HERMES_DUMP_REQUESTS gating ## Acceptance Criteria - [ ] **Verify hook registration**: Write a test plugin in `~/.hermes/plugins/test_hooks.py` that registers `on_pre_api_request` and `on_post_api_request` hooks - [ ] **Verify hook firing**: Trigger a CLI chat turn, confirm both hooks fire and receive correct payloads (token counts, usage dict, model name) - [ ] **Demonstrate a crisis-detection plugin**: Build a plugin using `on_pre_api_request` that scans user messages for despair keywords (suicide, hopeless, dying, can't go on) and logs a WARNING to `errors.log` - [ ] **Verify HERMES_DUMP_REQUESTS**: Set `HERMES_DUMP_REQUESTS=1` and confirm request/response payloads are dumped to disk ## Why This Matters The plugin hook system lets us build a crisis-detection layer that intercepts every message before it reaches the model. This is the Golden Timmy protocol — a safety net inscribed in code, not in prompts. If a man types "I can't go on anymore," the plugin catches it and triggers the response specified in SOUL.md before any model generates text. ## Hints - Plugin files live in `~/.hermes/plugins/` - The hook registration is in `hermes_cli/plugins.py` and `run_agent.py` (lines with `emit_hook`) - The narrow payload contains: `token_counts`, `usage` dict from `normalize_usage()` Parent: #111
Member

🏷️ Automated Triage Check

Timestamp: 2026-04-06T16:45:44.097775
Agent: Allegro Heartbeat

This issue has been identified as needing triage:

Checklist

  • Clear acceptance criteria defined
  • Priority label assigned (p0-critical / p1-important / p2-backlog)
  • Size estimate added (quick-fix / day / week / epic)
  • Owner assigned
  • Related issues linked

Context

  • No comments yet — needs engagement
  • No labels — needs categorization
  • Part of automated backlog maintenance

Automated triage from Allegro 15-minute heartbeat

## 🏷️ Automated Triage Check **Timestamp:** 2026-04-06T16:45:44.097775 **Agent:** Allegro Heartbeat This issue has been identified as needing triage: ### Checklist - [ ] Clear acceptance criteria defined - [ ] Priority label assigned (p0-critical / p1-important / p2-backlog) - [ ] Size estimate added (quick-fix / day / week / epic) - [ ] Owner assigned - [ ] Related issues linked ### Context - No comments yet — needs engagement - No labels — needs categorization - Part of automated backlog maintenance --- *Automated triage from Allegro 15-minute heartbeat*
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Timmy_Foundation/hermes-agent#113