Skip to content

feat(hooks): unified Hook Matcher DSL for hook filtering#704

Merged
Cai-Tang-www merged 3 commits into
1024XEngineer:mainfrom
Cai-Tang-www:feat/hook-matcher-684
Jun 1, 2026
Merged

feat(hooks): unified Hook Matcher DSL for hook filtering#704
Cai-Tang-www merged 3 commits into
1024XEngineer:mainfrom
Cai-Tang-www:feat/hook-matcher-684

Conversation

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator

@Cai-Tang-www Cai-Tang-www commented May 29, 2026

@

概要

  • 新增 hook item 的 match 字段,支持三种匹配维度:tool_nametool_name_regexarguments_contains
  • 匹配过滤在 executor 调度层执行 —— 未命中的 hook 直接跳过,不影响原有 block/failure 语义
  • 字段间 AND 组合,同字段多值间 OR 组合
  • 新增 tool_arguments_preview(脱敏 + 截断)注入到 before_tool_call metadata,同时继续剥离 tool_arguments 原文
  • 对旧 warn_on_tool_call 参数做向后兼容桥接,旧新参数共存时发送迁移提示
  • 更新设计文档和示例配置,统一使用 match 语法

关键文件

  • matcher.go / matcher_test.go — 新增 matcher 类型与编译器
  • executor.go — 调度层接入 matcher 过滤
  • types.go — match 类型、tool_arguments_preview、能力模型
  • runtime_hooks.go — match 语法与点位约束的配置校验
  • user_hooks.go / repo_hooks.go — warn_on_tool_call 向后兼容桥接
  • toolexec.go — tool_arguments_preview 生成与注入

测试计划

  • go test ./internal/runtime/hooks/... ✅
  • go test ./internal/config/... ✅
  • 使用示例 hook 配置做手工冒烟测试
  • 验证旧新参数共存时迁移通知正常触发
    @

feat(hooks): add unified Hook Matcher DSL with tool_name/tool_name_regex/arguments_contains

Introduce a match field on hook items that supports three matcher dimensions
(AND within fields, OR across values). Matcher filtering is applied at the
executor scheduling layer — non-matching hooks are skipped without affecting
existing block/failure semantics. Includes backward-compatible bridging of the
legacy warn_on_tool_call params, plus a migration notification when old and new
parameters coexist.

- New matcher types and compiler in internal/runtime/hooks/matcher.go
- Executor integration to skip non-matching hooks before running handlers
- tool_arguments_preview (sanitized + truncated) added to before_tool_call metadata
- Config validation for match syntax and hook-point capability constraints
- Backward-compatible warn_on_tool_call bridging with deprecation notification
- Updated design docs and example configs

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

fennoai[bot]

This comment was marked as outdated.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

refactor(hooks): remove warn_on_tool_call backward compat, reject unknown match fields

- Remove legacy warn_on_tool_call bridging: params.tool_name/tool_names no
  longer route through matcher; handler only reads "message" param.
- Reject unknown match keys at CompileHookMatcher level instead of silently
  ignoring, preventing misconfigured hooks from running unfiltered.
- Strip MatcherMigrationWarning from HookSpec, emitMatcherMigrationWarning,
  and all migration-notification infrastructure.
- Remove ~140 lines of compat helpers across config and runtime packages.
- Raise hooks package coverage to 95.9% with new matcher edge-case tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@
@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

/review

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary: found three noteworthy issues across validation, secret masking, and docs accuracy. Performance pass: no issues found.

Comment thread internal/runtime/hooks/matcher.go
Comment thread internal/runtime/toolexec.go Outdated
Comment thread docs/runtime-hooks-design.md Outdated
@Cai-Tang-www Cai-Tang-www merged commit 5bb2b80 into 1024XEngineer:main Jun 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant