Overview
The /rules command family allows you to activate and manage content rules that modify the AI’s behavior. Rules are defined in YAML files and can control tone, content restrictions, narrative style, and more.
Commands
/rules add
Activates a specific rule by its ID.
/rules clear
Deactivates all currently active rules.
/nsfw
Quick toggle for NSFW (Not Safe For Work) mode.
/rules add
Syntax
Parameters
| Parameter | Type | Required | Description |
|---|
rule_id | string | Yes | The identifier of the rule to activate (must correspond to a YAML file in assets/rules/) |
Behavior
- Checks if the rule file exists at
assets/rules/<rule_id>.yaml
- If the file exists and the rule isn’t already active:
- Adds
rule_id to state.ACTIVE_RULES list
- Persists state via
state.save_state()
- Sends confirmation message
- Broadcasts state change to all clients
- If the rule is already active, it remains in the list (idempotent)
- If the file doesn’t exist, the command is silently ignored
Multiple rules can be active simultaneously. They are applied in the order they appear in the ACTIVE_RULES list.
Examples
Activate a Custom Rule
Expected Output:
✓ Rule 'dark_fantasy' activated
Activate a Tone Rule
Expected Output:
✓ Rule 'dramatic' activated
Activate Multiple Rules
/rules add horror
/rules add first_person
/rules add detailed_descriptions
Expected Output:
✓ Rule 'horror' activated
✓ Rule 'first_person' activated
✓ Rule 'detailed_descriptions' activated
WebSocket Response
{
"event": "system_update",
"payload": {
"content": "✓ Rule 'dark_fantasy' activated",
"metadata": {
"active_rules": ["dark_fantasy"]
}
}
}
/rules clear
Syntax
Parameters
No parameters required.
Behavior
- Clears all entries from
state.ACTIVE_RULES list
- Persists the change via
state.save_state()
- Sends confirmation message
- Broadcasts state change to all clients
Examples
Clear All Rules
Expected Output:
✓ All active rules cleared
WebSocket Response
{
"event": "system_update",
"payload": {
"content": "✓ All active rules cleared",
"metadata": {
"active_rules": []
}
}
}
Use /rules clear to reset to default AI behavior before activating a new set of rules.
/nsfw
Syntax
Parameters
No parameters required.
Behavior
The /nsfw command is a special toggle that:
- Checks if
"nsfw" is in state.ACTIVE_RULES
- If NOT active:
- Verifies
assets/rules/nsfw.yaml exists
- Adds
"nsfw" to state.ACTIVE_RULES
- Sends “NSFW mode ENABLED” message
- If already active:
- Removes
"nsfw" from state.ACTIVE_RULES
- Sends “NSFW mode DISABLED” message
- Persists state and broadcasts changes
NSFW mode removes content restrictions and allows unrestricted adult content. Use responsibly and in accordance with your AI provider’s terms of service.
Examples
Enable NSFW Mode
Expected Output (when disabled):
✓ NSFW mode ENABLED - Unrestricted adult content
Disable NSFW Mode
Expected Output (when enabled):
✓ NSFW mode DISABLED - Back to standard content
WebSocket Response (Enabling)
{
"event": "system_update",
"payload": {
"content": "✓ NSFW mode ENABLED - Unrestricted adult content",
"metadata": {
"active_rules": ["nsfw"]
}
}
}
WebSocket Response (Disabling)
{
"event": "system_update",
"payload": {
"content": "✓ NSFW mode DISABLED - Back to standard content",
"metadata": {
"active_rules": []
}
}
}
NSFW File Not Found
If assets/rules/nsfw.yaml doesn’t exist:
Expected Output:
✗ NSFW rule file not found.
Source Code Reference
Implemented in engine/commands.py:75-130:
elif cmd == "/rules":
if len(parts) >= 3 and parts[1] == "add":
rule_id = parts[2].strip()
if os.path.exists(f"assets/rules/{rule_id}.yaml"):
if rule_id not in state.ACTIVE_RULES:
state.ACTIVE_RULES.append(rule_id)
state.save_state()
await websocket.send_text(
build_ws_payload(
"system_update",
f"✓ Rule '{rule_id}' activated",
{"active_rules": state.ACTIVE_RULES},
)
)
await broadcast_sync_state(websocket)
elif len(parts) >= 2 and parts[1] == "clear":
state.ACTIVE_RULES.clear()
state.save_state()
await websocket.send_text(
build_ws_payload(
"system_update",
"✓ All active rules cleared",
{"active_rules": state.ACTIVE_RULES},
)
)
await broadcast_sync_state(websocket)
elif cmd == "/nsfw":
# Quick toggle for NSFW mode
if "nsfw" not in state.ACTIVE_RULES:
if os.path.exists("assets/rules/nsfw.yaml"):
state.ACTIVE_RULES.append("nsfw")
state.save_state()
await websocket.send_text(
build_ws_payload(
"system_update",
"✓ NSFW mode ENABLED - Unrestricted adult content",
{"active_rules": state.ACTIVE_RULES},
)
)
await broadcast_sync_state(websocket)
else:
await websocket.send_text(
build_ws_payload("system_update", "✗ NSFW rule file not found.")
)
else:
state.ACTIVE_RULES.remove("nsfw")
state.save_state()
await websocket.send_text(
build_ws_payload(
"system_update",
"✓ NSFW mode DISABLED - Back to standard content",
{"active_rules": state.ACTIVE_RULES},
)
)
await broadcast_sync_state(websocket)
Rule Files
Rules are defined as YAML files in the assets/rules/ directory. Each rule file typically contains:
- name: Display name for the rule
- description: What the rule does
- instructions: Directives for the AI model
- examples: Sample outputs demonstrating the rule
Example Rule Structure
name: Dark Fantasy
description: Emphasizes grim, dark fantasy themes
instructions: |
Use darker, more gothic language.
Emphasize danger, moral ambiguity, and consequences.
Maintain a somber, atmospheric tone.
examples:
- "The shadows seem to watch you with hungry eyes."
- "Victory came at a terrible price."
Use Cases
Creating a Horror Atmosphere
/rules add horror
/rules add dark_atmosphere
/rules add suspenseful
Setting Narrative Style
/rules add first_person
/rules add descriptive
Enabling Mature Content
Resetting to Default
Common Issues
Rule not found: If the YAML file doesn’t exist in assets/rules/, the command is silently ignored. Verify your rule files are properly placed.
Rule not taking effect: Rules are applied during AI prompt construction. You may need to send a new message to see the effect.
Rule IDs must exactly match the filename (without .yaml extension). Rules are case-sensitive.
State Persistence
Active rules are persisted to disk via state.save_state(), meaning:
- Rules remain active across engine restarts
- Rule state is synchronized across all connected clients
- Changes take effect immediately for new messages
Multiple Rules Interaction
When multiple rules are active:
- Rules are applied in the order they appear in
ACTIVE_RULES
- Later rules can modify or enhance earlier rules
- Conflicting rules may produce unpredictable results
Experiment with different rule combinations to find the perfect narrative style for your story.