Repository navigation
feat(hooks): tool_pattern 正则工具匹配器(对齐 Claude Code / Codex matcher) - #565
Merged
Merged
Conversation
Extend tool-event hook declarations with an optional tool_pattern: a single Go regular expression (unanchored against the tool name, at most 256 bytes, compiled at registry replacement and stored beside the sorted registrations) that replaces the exact tool_names list. Both external harnesses match tools with regular expressions; dynamic MCP tool families cannot be expressed as a 64-entry exact list. The pattern participates in the registry generation fingerprint, fails closed when it does not compile, and rejects a byte order mark so the web parser and the Go projection agree on every byte. The plugin diagnostics projection exposes the declared pattern, the OpenAPI snapshot and the generated TypeScript schema are regenerated with a maxLength constraint, and the web hook diagnostics parser and declared-rules view learn the new field.
Qiyuanqiii
changed the base branch from
feat/user-prompt-submit-hooks
to
main
November 12, 2026 03:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动背景
继续对齐 Claude Code 与 Codex 的 hooks 能力:两者的工具事件 matcher 都支持正则(Claude Code 为非锚定 JS 正则、Codex 为正则字符串),而本项目的 hook 只能按
tool_names精确列表过滤且上限 64 条。真实工具家族会让精确列表失效——MCP server 的工具名是动态的(mcp_github_create_issue、mcp_github_create_pr、…),一个已审查插件想禁止整个写家族,要么逐一枚举、要么耗尽整个列表预算。关键设计
tool_names精确列表 或 单条tool_patternGo 正则(对工具名非锚定匹配,与竞品的实际匹配行为一致),声明两者同时存在会被拒绝;^(Bash|Edit)$这类交替可覆盖任意并集。HookDeclarationView)同步暴露tool_pattern,操作者视图渲染真实过滤器而非空列表。user_prompt_submit、run/session/compaction/subagent/checkpoint 边界没有工具名,两种过滤器均按既有规则拒绝。docs/openapi.json再生成 →web/src/api/schema.d.ts(npm run generate:api)→ 前端 exact-keys 校验(允许空串、与 GovalidText同样要求 trim 一致、非空时互斥 + 工具事件限定)→ 声明规则面板显示/pattern/。验证方式
go vet、gofmt、go test -race -count=1 ./internal/hooks/通过。internal/hooks:校验(互斥/超长/不可编译/NUL/非工具事件)、非锚定匹配(命中/不命中/无关工具)、generation 随 pattern 变化推进、Replace 时编译失败关闭。internal/httpapiHook/Extension 子集通过;internal/plugins全套通过。npm run generate:api+check:api(契约一致性)、typecheck通过、plugin-lifecycle 相关 vitest 24/24 通过。docs/extensions.md双语 hook 契约补充过滤器规则;新增 ADR 0199。