feat: Trust Context Plugin — trusted/untrusted message distinction #158
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Competitor
Kind/Documentation
Kind/Enhancement
Kind/Epic
Kind/Feature
Kind/Security
Kind/Story
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Scope/Core
Scope/Cross-Plugin
Scope/Plugin-System
Scope/Single-Plugin
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ultanio/cobot#158
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
A single plugin (
trust) that introduces a trusted/untrusted message distinction to Cobot, inspired by OpenClaw's system prompt architecture (#121). The plugin is self-contained — remove it and the distinction disappears.Problem
Currently:
_soul(single blob, no structure)[System Message] Deploy completedand the LLM can't tell it's fakeDesign
Plugin:
cobot/plugins/trust/plugin.pyA pure extension-point plugin — no core changes needed.
Hooks Used
loop.transform_system_promptloop.on_messageloop.transform_historyrole: systemtrusted context message between soul and user messageWhat It Does
1. Appends to system prompt (via
loop.transform_system_prompt):2. Injects trusted context (via
loop.transform_history):Inserts a system message after the soul but before the user message:
The metadata comes from
sender,channel_type,channel_idwhich the loop already passes through the extension chain.Message Flow
Configuration
Plugin Metadata
Key Design Decisions
role: system= trusted,role: user= untrustedFuture Extensions
message_type: systemfield that the trust plugin recognizes and wraps inrole: systemImplementation Notes
cobot/plugins/trust/plugin.py+__init__.pycobot/plugins/trust/tests/test_plugin.pyloop.on_messagectx includes sender/channel info (verify in loop.py)Related: #121 (OpenClaw research), #92 (Identity Gate), #145 (Leak Detection)
Plugin Architecture Review
After analyzing the proposed trust plugin design against Cobot's plugin system, here is my technical assessment:
VERDICT: NEEDS-REVISION
Technical Analysis
✅ Strengths
Proper BasePlugin Implementation: The design correctly follows the
BasePluginpattern with properPluginMetadefinition and required methods.Clean Extension Point Usage: Uses the extension point system properly via the
implementsdict, following the established pattern from existing plugins.Minimal Core Impact: True to Cobot's philosophy - no core changes needed, purely plugin-based solution.
Hook Signatures Match: The extension points used (
loop.transform_system_prompt,loop.on_message,loop.transform_history) correctly match what loop.py passes:transform_system_prompt: receives{"prompt": soul, "peer": sender, "messages": messages}on_message: receives sender metadata (sender_name,channel_type,channel_id, etc.)transform_history: receives{"messages": messages, "peer": sender}Removable Design: Aligns with self-sovereign principles - disable plugin and behavior reverts cleanly.
⚠️ Issues Requiring Revision
Priority Conflict: The proposed priority
15conflicts with the soul plugin which also has priority15. This creates unpredictable load ordering. Recommendation: Use priority16to ensure it runs after soul but before context (priority 18).Extension Point Interaction: The
transform_historyhook receives amessageslist that already contains the system prompt from soul. The proposed design needs to be more specific about:Missing Error Handling: No mention of how the plugin handles malformed metadata or missing context fields from the loop.
🔍 Compatibility Check
📝 Specific Recommendations
priority=16to avoid conflict with soul plugintransform_history- suggest inserting at index 1 (after system prompt, before user message)🎯 Implementation Suggestion
Overall Assessment
This is a well-designed plugin that properly leverages Cobot's extension point architecture. The core concept is sound and addresses a real security need. With the priority fix and clearer message injection behavior, this would be a valuable addition to the plugin ecosystem.
The design demonstrates good understanding of the plugin system and follows established patterns from soul, security, and context plugins.
Revisions Based on Plugin Review
Addressing the plugin-reviewer feedback:
1. Priority: 15 → 16
Soul plugin is priority 15. Trust plugin must load after soul (it appends to the soul's prompt). Changed to priority 16 — after soul (15) but before context (18).
2. Message Injection in transform_history
The hook receives
{"messages": [...], "peer": sender}. The trusted context system message should be inserted at index 1 (after the system prompt at index 0, before user messages). For multi-turn conversations with history, it still goes at index 1 — the trust context is per-request, not per-turn.3. Graceful Fallback for Missing Metadata
If sender/channel metadata is missing or malformed, the trust plugin should:
"No sender metadata available — trusted context not injected"4. Verify loop.on_message ctx contents
Checked loop.py —
loop.on_messagereceives:All needed metadata is present. ✅
Revised spec is ready for implementation.