feat: add bootstrap hook and soul-evil hook

This commit is contained in:
Peter Steinberger
2026-01-18 05:24:47 +00:00
parent 7e2d91f3b7
commit ad3c12a43a
15 changed files with 678 additions and 9 deletions

View File

@@ -32,6 +32,20 @@ Logs all command events to a centralized audit file.
clawdbot hooks enable command-logger
```
### 😈 soul-evil
Swaps injected `SOUL.md` content with `SOUL_EVIL.md` during a purge window or by random chance.
**Events**: `agent:bootstrap`
**What it does**: Overrides the injected SOUL content before the system prompt is built.
**Output**: No files written; swaps happen in-memory only.
**Enable**:
```bash
clawdbot hooks enable soul-evil
```
## Hook Structure
Each hook is a directory containing:
@@ -140,6 +154,7 @@ Currently supported events:
- **command:new**: `/new` command specifically
- **command:reset**: `/reset` command
- **command:stop**: `/stop` command
- **agent:bootstrap**: Before workspace bootstrap files are injected
More event types coming soon (session lifecycle, agent errors, etc.).

View File

@@ -0,0 +1,72 @@
---
name: soul-evil
description: "Swap SOUL.md with SOUL_EVIL.md during a purge window or by random chance"
homepage: https://docs.clawd.bot/hooks#soul-evil
metadata:
{
"clawdbot":
{
"emoji": "😈",
"events": ["agent:bootstrap"],
"requires":
{ "config": ["hooks.internal.entries.soul-evil.enabled"] },
"install": [{ "id": "bundled", "kind": "bundled", "label": "Bundled with Clawdbot" }],
},
}
---
# SOUL Evil Hook
Replaces the injected `SOUL.md` content with `SOUL_EVIL.md` during a daily purge window or by random chance.
## What It Does
When enabled and the trigger conditions match, the hook swaps the **injected** `SOUL.md` content before the system prompt is built. It does **not** modify files on disk.
## Files
- `SOUL.md` — normal persona (always read)
- `SOUL_EVIL.md` — alternate persona (read only when triggered)
You can change the filename via hook config.
## Configuration
Add this to your config (`~/.clawdbot/clawdbot.json`):
```json
{
"hooks": {
"internal": {
"enabled": true,
"entries": {
"soul-evil": {
"enabled": true,
"file": "SOUL_EVIL.md",
"chance": 0.1,
"purge": { "at": "21:00", "duration": "15m" }
}
}
}
}
}
```
### Options
- `file` (string): alternate SOUL filename (default: `SOUL_EVIL.md`)
- `chance` (number 01): random chance per run to swap in SOUL_EVIL
- `purge.at` (HH:mm): daily purge window start time (24h)
- `purge.duration` (duration): window length (e.g. `30s`, `10m`, `1h`)
**Precedence:** purge window wins over chance.
## Requirements
- `hooks.internal.entries.soul-evil.enabled` must be set to `true`
## Enable
```bash
clawdbot hooks enable soul-evil
```

View File

@@ -0,0 +1,61 @@
import type { ClawdbotConfig } from "../../../config/config.js";
import { isSubagentSessionKey } from "../../../routing/session-key.js";
import { resolveHookConfig } from "../../config.js";
import type { AgentBootstrapHookContext, HookHandler } from "../../hooks.js";
import {
applySoulEvilOverride,
type SoulEvilConfig,
} from "../../soul-evil.js";
const HOOK_KEY = "soul-evil";
function resolveSoulEvilConfig(entry: Record<string, unknown> | undefined): SoulEvilConfig | null {
if (!entry) return null;
const file = typeof entry.file === "string" ? entry.file : undefined;
const chance = typeof entry.chance === "number" ? entry.chance : undefined;
const purge =
entry.purge && typeof entry.purge === "object"
? {
at: typeof (entry.purge as { at?: unknown }).at === "string"
? (entry.purge as { at?: string }).at
: undefined,
duration:
typeof (entry.purge as { duration?: unknown }).duration === "string"
? (entry.purge as { duration?: string }).duration
: undefined,
}
: undefined;
if (!file && chance === undefined && !purge) return null;
return { file, chance, purge };
}
const soulEvilHook: HookHandler = async (event) => {
if (event.type !== "agent" || event.action !== "bootstrap") return;
const context = event.context as AgentBootstrapHookContext;
if (context.sessionKey && isSubagentSessionKey(context.sessionKey)) return;
const cfg = context.cfg as ClawdbotConfig | undefined;
const hookConfig = resolveHookConfig(cfg, HOOK_KEY);
if (!hookConfig || hookConfig.enabled === false) return;
const soulConfig = resolveSoulEvilConfig(hookConfig as Record<string, unknown>);
if (!soulConfig) return;
const workspaceDir = context.workspaceDir;
if (!workspaceDir || !Array.isArray(context.bootstrapFiles)) return;
const updated = await applySoulEvilOverride({
files: context.bootstrapFiles,
workspaceDir,
config: soulConfig,
userTimezone: cfg?.agents?.defaults?.userTimezone,
log: {
warn: (message) => console.warn(`[soul-evil] ${message}`),
debug: (message) => console.debug?.(`[soul-evil] ${message}`),
},
});
context.bootstrapFiles = updated;
};
export default soulEvilHook;