b63b79e51e
确保 write_file 和 edit_file 修改已存在的文件前必须先调用 read_file - 在 AgentToolExecutor 中添加 readFiles 状态跟踪已读文件 - 创建 read-before-write.ts hook 拦截写操作并验证 - 在 Agent 初始化时注册验证 hook - 提供 AI 友好的错误消息引导正确操作
52 lines
966 B
TypeScript
52 lines
966 B
TypeScript
/**
|
|
* Hook 系统模块
|
|
*
|
|
* 提供工具执行前后的 hook 功能,支持自定义命令执行
|
|
* 参考 open-code 的实现
|
|
*/
|
|
|
|
// Hook 管理器
|
|
export {
|
|
HookManager,
|
|
getHookManager,
|
|
initHookManager,
|
|
resetHookManager,
|
|
} from './manager.js';
|
|
|
|
// 配置加载
|
|
export {
|
|
loadProjectConfig,
|
|
loadHookConfig,
|
|
loadPluginList,
|
|
createDefaultConfig,
|
|
getConfigFilePath,
|
|
type ProjectConfig,
|
|
} from './config-loader.js';
|
|
|
|
// Read-Before-Write Hook
|
|
export { createReadBeforeWriteHook } from './read-before-write.js';
|
|
|
|
// 类型导出
|
|
export type {
|
|
HookType,
|
|
HookConfig,
|
|
HookEvent,
|
|
HookEventListener,
|
|
ShellCommandConfig,
|
|
FileHookConfig,
|
|
Hooks,
|
|
Plugin,
|
|
PluginInput,
|
|
ToolExecuteBeforeInput,
|
|
ToolExecuteBeforeOutput,
|
|
ToolExecuteAfterInput,
|
|
ToolExecuteAfterOutput,
|
|
SessionStartInput,
|
|
SessionEndInput,
|
|
MessageBeforeInput,
|
|
MessageBeforeOutput,
|
|
MessageAfterInput,
|
|
FileChangeInput,
|
|
FileChangeOutput,
|
|
} from './types.js';
|