docs-review-gregbaron-metabase-mysandbox
审查文档更改是否符合Metabase写作风格指南
目录 / 文档处理 / writing-rules
--- name: writing-rules description: | Writes hookify rules in markdown that block dangerous commands or restrict AI behavior version: 1.10.3 triggers: - hookify - rules - patterns - validation - safety - adding guardrails metadata: {"openclaw": {"homepage": "https://github.com/athola/claude-night-market/tree/master/plugins/hookify", "emoji": "\ud83e\udd9e"}} source: claude-night-market source_plugin: hookify --- > **Night Market Skill**: ported from [claude-night-market/hookify](https://github.com/athola/claude-night-market/tree/master/plugins/hookify). For the full experience with agents, hooks, and commands, install the Claude Code plugin. # Hookify Rule Writing Guide ## When To Use - Creating behavioral rules to prevent unwanted actions - Defining persistent guardrails for Claude Code sessions ## When NOT To Use - Complex multi-step workflows - use agents instead - One-time operations that do not need persistent behavioral rules ## Overview Hookify rules are markdown files with YAML frontmatter that define patterns to watch for and messages to show when those patterns match. Rules are stored in `.claude/hookify.{rule-name}.local.md` files. ## Quick Start Create `.claude/hookify.dangerous-rm.local.md`: ```yaml --- name: dangerous-rm enabled: true event: bash pattern: rm\s+-rf action: block --- 🛑 **Dangerous rm command detected!** This command could delete important files. ``` **Verification:** Run the command with `--help` flag to verify availability. The rule activates immediately - no restart needed! ## Rule File Format ### Frontmatter Fields **name** (required): Unique identifier (kebab-case) **enabled** (required): `true` or `false` **event** (required): `bash`, `file`, `stop`, `prompt`, or `all` **action** (optional): `warn` (default) or `block` **pattern** (simple): Regex pattern to match ### Event Types - **bash**: Bash tool commands - **file**: Edit, Write, MultiEdit tools - **stop**: When agent wants to stop - **prompt**: User prompt submission - **all**: All events ### Advanced Conditions For multiple field checks: ```yaml --- name: warn-env-edits enabled: true event: file action: warn conditions: - field: file_path operator: regex_match pattern: \.env$ - field: new_text operator: contains pattern: API_KEY --- 🔐 **API key in .env file!** Ensure file is in .gitignore. ``` ### Operators - `regex_match`: Pattern matching - `contains`: Substring check - `equals`: Exact match - `not_contains`: Must NOT contain - `starts_with`: Prefix check - `ends_with`: Suffix check ### Field Reference **bash events:** `command` **file events:** `file_path`, `new_text`, `old_text`, `content` **prompt events:** `user_prompt` **stop events:** `transcript` ## Pattern Writing ### Regex Basics - `\s` - whitespace - `\d` - digit - `\w` - word character - `.` - any character (use `\.` for literal dot) - `+` - one or more - `*` - zero or more - `|` - OR ### Examples ``` rm\s+-rf → rm -rf console\.log\( → console.log( chmod\s+777 → chmod 777 ``` ### Test Patterns ```bash python3 -c "import re; print(re.search(r'pattern', 'text'))" ``` ## Example Rules ### Block Destructive Commands ```yaml --- name: block-destructive enabled: true event: bash pattern: rm\s+-rf|dd\s+if=|mkfs action: block --- 🛑 **Destructive operation blocked!** Can cause data loss. ``` ### Warn About Debug Code ```yaml --- name: warn-debug enabled: true event: file pattern: console\.log\(|debugger; action: warn --- 🐛 **Debug code detected!** Remove before committing. ``` ### Require Tests ```yaml --- name: require-tests enabled: true event: stop action: warn conditions: - field: transcript operator: regex_match pattern: \A(?![\s\S]*(?:pytest|npm test)) --- ⚠️ **Tests not run!** Please verify changes. ``` ### Protect Production Files ```yaml --- name: protect-prod enabled: true event: file action: block conditions: - field: file_path operator: regex_match pattern: /production/|\.prod\. --- 🚨 **Production file!** Requires review. ``` ## Management **Enable/Disable:** Edit `.local.md` file: `enabled: false` **Delete:** ```bash rm .claude/hookify.my-rule.local.md ``` **List:** ```bash /hookify:list ``` ## Related Skills - **abstract:hook-scope-guide** - Hook placement decisions - **abstract:hook-authoring** - SDK hook development - **abstract:hooks-eval** - Hook evaluation ## Best Practices 1. Start with simple patterns 2. Test regex thoroughly 3. Use clear, helpful messages 4. Prefer warnings over blocks initially 5. Name rules descriptively 6. Document intent in messages ## Troubleshooting ### Common Issues If a rule doesn't trigger, verify that the `event` type matches the tool being used (e.g., use `bash` for command line tools). Check that the regex `pattern` is valid and matches the target text by testing it with a short Python script. If you encounter permission errors when creating rule files in `.claude/`, ensure that the directory is writable by your user. ## Exit Criteria - [ ] Rule file exists at `.claude/hookify.<rule-name>.local.md` with all required frontmatter fields present: `name` (kebab-case), `enabled`, `event`, and either `pattern` or `conditions` - [ ] Regex pattern validated with `python3 -c "import re; print(re.search(r'<pattern>', '<test>'))" before the rule is saved; no untested patterns shipped - [ ] Rule triggers correctly on a matching input: `warn` action shows the message body, `block` action prevents the operation - [ ] Rule does not fire on a non-matching input; false positive tested with at least one known-safe example
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v1 | 2026-11-17 04:17 | 511ff5f5 | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
审查文档更改是否符合Metabase写作风格指南
在创建OpenCode代理时使用 - 提供带有YAML前导的Markdown格式、模式/工具/权限配置,以及为专业AI助手提供的最佳实践
将Markdown文本转换并输出为PDF的技术
将markdown文档和聊天摘要转换为格式化的EPUB电子书文件,这些文件可以在任何设备上阅读或上传到Kindle
针对Markdown提供拆分能力,帮助用户快速完成相关任务并减少返工
抖音热点榜采集工具:实时抓取抖音热点词、热度值、搜索页链接,导出 Markdown+JSON
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。