Skip to content

Add hookMatcher support for pack-installed hooks #225

@bguidolim

Description

@bguidolim

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

  • Pack authors can specify hookMatcher in component definitions
  • Auto-derived HookGroup entries use the specified matcher
  • Validation rejects hookMatcher without hookEvent
  • Events that don't support matchers (UserPromptSubmit, Stop, etc.) get a validation warning

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Important priorityenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions