refactor: migrate guardrails to plugin hook system#1
Merged
Reapor-Yurnero merged 4 commits intofeat/guardrail_interfacefrom Feb 2, 2026
Merged
refactor: migrate guardrails to plugin hook system#1Reapor-Yurnero merged 4 commits intofeat/guardrail_interfacefrom
Reapor-Yurnero merged 4 commits intofeat/guardrail_interfacefrom
Conversation
Unify the guardrails system with the existing plugin hook infrastructure: - Add before_request and after_response hooks to plugin types - Extend before_tool_call/after_tool_call with richer context and modify capabilities (after_tool_call now returns results) - Wire up all four hook stages in the agent runner and tool adapter - Move Gray Swan implementation to extensions/grayswan/ plugin - Remove guardrail registry and apply functions The Gray Swan guardrail now follows the standard plugin pattern, registering handlers via api.on() for each stage. Configuration remains unchanged (guardrails.grayswan in openclaw.json). This enables third-party guardrail plugins using the same hook API.
…guration and move config responsibility to each plugin. Extract shared guardrail-utils
5 tasks
Add a shared base class/factory that simplifies guardrail extension implementations by handling common hook registration boilerplate. Extensions now implement a simple interface: - evaluate(ctx, config, api) -> GuardrailEvaluation - formatViolationMessage(evaluation, location) -> string - onRegister(api, config) [optional] The factory handles: - All 4 hook registrations (before_request, before_tool_call, after_tool_call, after_response) - Stage config resolution (enabled, mode, blockMode, includeHistory) - Error handling with failOpen support - Monitor mode (log-only) - Content extraction per stage Refactored extensions: - llamaguard: 634 → 373 lines (-41%) - grayswan: 590 → 394 lines (-33%) - gpt-oss-safeguard: 550 → 311 lines (-43%) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add two new execution-safety guardrails using the createGuardrailPlugin framework: command-safety-guard: - Blocks destructive commands (rm -rf, dd, mkfs, fork bombs) - Prevents credential exfiltration (cat ~/.ssh/id_*, base64 | curl) - Detects privilege escalation attempts (sudo passwd, visudo) - Configurable: extra patterns, allow patterns, disable rules security-audit: - Restricts access to sensitive files (SSH keys, API tokens, shell configs) - Covers cloud credentials (AWS, GCloud, Azure) - Covers package manager auth (npm, PyPI) - Operation-aware: some rules block read, others block write - Configurable: extra paths, allow paths, disable rules Both plugins support monitor mode for logging without blocking. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reapor-Yurnero
pushed a commit
that referenced
this pull request
Feb 9, 2026
Reapor-Yurnero
pushed a commit
that referenced
this pull request
Feb 9, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Unify the guardrails system with the existing plugin hook infrastructure:
The Gray Swan guardrail now follows the standard plugin pattern, registering handlers via api.on() for each stage. Configuration remains unchanged (guardrails.grayswan in openclaw.json).
This enables third-party guardrail plugins using the same hook API.