【Kiro】钩子类型(Hook Types)
Agent Hooks 支持多种触发类型,每种类型针对特定的自动化场景。理解这些类型能帮助你为工作流程选择合适的方法。
文件创建时触发(On File Create)
当工作区中新建符合特定模式的文件时触发。
应用场景:
为新组件生成模板代码
给新文件添加版权声明头
创建实现文件时自动建立测试文件
示例:React 组件设置
When a new React component file is created, add:
1. Import statements for React and necessary hooks
2. A functional component with TypeScript props interface
3. Export statement
4. Basic styling if applicable
5. A skeleton test file in the appropriate directory
文件保存时触发(On File Save)
当保存符合特定模式的文件时触发。
应用场景:
运行代码风格检查和格式化
更新相关文件
生成文档
运行变更文件的测试
示例:更新测试覆盖率
When a JavaScript/TypeScript file is saved:
1. Identify the corresponding test file
2. Update tests to maintain coverage for any new functions
3. Run the tests to verify they pass
4. Update any snapshots if necessary
文件删除时触发(On File Delete)
当删除符合特定模式的文件时触发。
应用场景:
清理相关文件
更新其他文件中的导入引用
维护项目完整性
示例:清理引用
When a component file is deleted:
1. Find all imports of this component across the codebase
2. Remove or comment out those import statements
3. Suggest replacements if appropriate
手动触发(Manual Trigger)
手动执行钩子。
应用场景:
按需代码审查
文档生成
安全扫描
性能优化
示例:代码审查按钮
Review the current file for:
1. Code quality issues
2. Potential bugs
3. Performance optimizations
4. Security vulnerabilities
5. Accessibility concerns