【Kiro】钩子示例(Hook Examples)
以下示例展示了真实场景中的钩子实现,你可以根据需要进行调整。每个示例包括触发类型、目标文件匹配模式和完整的钩子指令。
安全提交前扫描器(Security Pre-Commit Scanner)
该钩子在提交前扫描文件,防止安全泄漏。
触发类型: 文件保存 目标: **/*
钩子指令:
Review changed files for potential security issues:
1. Look for API keys, tokens, or credentials in source code
2. Check for private keys or sensitive credentials
3. Scan for encryption keys or certificates
4. Identify authentication tokens or session IDs
5. Flag passwords or secrets in configuration files
6. Detect IP addresses containing sensitive data
7. Find hardcoded internal URLs
8. Spot database connection credentials
For each issue found:
1. Highlight the specific security risk
2. Suggest a secure alternative approach
3. Recommend security best practices
国际化助手(Internationalization Helper)
该钩子确保主语言文件更新时,翻译文件同步更新。
触发类型: 文件保存 目标: src/locales/en/*.json
钩子指令:
When an English locale file is updated:
1. Identify which string keys were added or modified
2. Check all other language files for these keys
3. For missing keys, add them with a "NEEDS_TRANSLATION" marker
4. For modified keys, mark them as "NEEDS_REVIEW"
5. Generate a summary of changes needed across all languages
文档生成器(Documentation Generator)
该钩子在代码变更时自动更新文档。
触发类型: 手动触发
钩子指令:
Generate comprehensive documentation for the current file:
1. Extract function and class signatures
2. Document parameters and return types
3. Provide usage examples based on existing code
4. Update the README.md with any new exports
5. Ensure documentation follows project standards
测试覆盖维护者(Test Coverage Maintainer)
该钩子确保代码演进时测试覆盖率保持高水平。
触发类型: 文件保存 目标: src/**/*.{js,ts,jsx,tsx}
钩子指令:
When a source file is modified:
1. Identify new or modified functions and methods
2. Check if corresponding tests exist and cover the changes
3. If coverage is missing, generate test cases for the new code
4. Run the tests to verify they pass
5. Update coverage reports
与 MCP 集成(Integration with MCP)
Agent Hooks 可以通过 Model Context Protocol(MCP)增强功能:
访问外部工具:钩子可调用 MCP 服务器访问专业工具和 API
增强上下文:MCP 提供更多上下文信息,实现更智能的钩子操作
领域知识:专业 MCP 服务器提供行业专有知识
使用 MCP 与钩子集成步骤:
在钩子指令中引用 MCP 工具
为常用工具设置合适的自动批准
应用场景:
确保遵循 Figma 设计系统
任务完成后自动更新工单状态
从项目文件夹中的样例文件同步数据库
示例:验证 Figma 设计
该钩子监控 HTML 和 CSS 文件,使用 Figma MCP 验证文件是否符合 Figma 设计规范。
触发类型: 文件保存钩子 目标: *.css
*.html
钩子指令:
Use the Figma MCP to analyze the updated html or css files and check that they follow
established design patterns in the figma design. Verify elements like hero sections,
feature highlights, navigation elements, colors, and button placements align.