Phase 1: Matcher Support for Pack Authors
Context
The matcher field on HookGroup exists in the data model (for JSON round-tripping), but the engine always sets it to nil when auto-deriving hook entries from pack components. Pack authors cannot target specific tools (e.g., only run a linting hook after Edit|Write calls).
Problem
A pack that installs a PostToolUse hook for code formatting currently fires on every tool call. The author should be able to specify matcher: "Edit|Write" so it only runs when files change.
Proposed Solution
Add a hookMatcher: String? field to ExternalComponentDefinition (alongside existing hookEvent). When the engine auto-derives hook settings entries, use this value for the HookGroup.matcher field.
Example Pack YAML
components:
- id: format-hook
description: Auto-format on file changes
hookEvent: PostToolUse
hookMatcher: "Edit|Write"
hook:
source: hooks/format.sh
destination: format.sh
Files to Modify
Sources/mcs/ExternalPack/ExternalPackManifest.swift — add hookMatcher to component definition
Sources/mcs/TechPack/Component.swift — add hookMatcher to ComponentDefinition
Sources/mcs/Install/Configurator.swift or settings composition — use hookMatcher when creating HookGroup
- Validation: if
hookMatcher is set, hookEvent must also be set
- Tests
Acceptance Criteria
Reference
Phase 1: Matcher Support for Pack Authors
Context
The
matcherfield onHookGroupexists in the data model (for JSON round-tripping), but the engine always sets it tonilwhen auto-deriving hook entries from pack components. Pack authors cannot target specific tools (e.g., only run a linting hook afterEdit|Writecalls).Problem
A pack that installs a
PostToolUsehook for code formatting currently fires on every tool call. The author should be able to specifymatcher: "Edit|Write"so it only runs when files change.Proposed Solution
Add a
hookMatcher: String?field toExternalComponentDefinition(alongside existinghookEvent). When the engine auto-derives hook settings entries, use this value for theHookGroup.matcherfield.Example Pack YAML
Files to Modify
Sources/mcs/ExternalPack/ExternalPackManifest.swift— addhookMatcherto component definitionSources/mcs/TechPack/Component.swift— addhookMatchertoComponentDefinitionSources/mcs/Install/Configurator.swiftor settings composition — usehookMatcherwhen creatingHookGrouphookMatcheris set,hookEventmust also be setAcceptance Criteria
hookMatcherin component definitionsHookGroupentries use the specified matcherhookMatcherwithouthookEventUserPromptSubmit,Stop, etc.) get a validation warningReference