Skip to content

[#266] Consolidate hook metadata into HookRegistration struct#268

Merged
bguidolim merged 3 commits intomainfrom
bruno/266-hook-registration-struct
Mar 22, 2026
Merged

[#266] Consolidate hook metadata into HookRegistration struct#268
bguidolim merged 3 commits intomainfrom
bruno/266-hook-registration-struct

Conversation

@bguidolim
Copy link
Copy Markdown
Collaborator

Summary

Replaces four flat optional fields (hookEvent, hookTimeout, hookAsync, hookStatusMessage) on ComponentDefinition and ExternalComponentDefinition with a single HookRegistration? struct. This reduces parameter sprawl, enforces semantic grouping (hook metadata can only exist with an event), and unifies the export path's HookInfo type. Also syncs validEvents with the latest Claude Code hooks documentation (+5 missing events).

Closes #266

Changes

  • Define HookRegistration struct in Component.swift with event: String, timeout: Int?, isAsync: Bool?, statusMessage: String?
  • ComponentDefinition: 4 flat fields → hookRegistration: HookRegistration?
  • ExternalComponentDefinition: same, with flat YAML CodingKeys preserved for pack author ergonomics
  • Remove ConfigurationDiscovery.HookInfo — replaced by HookRegistration
  • DiscoveredFile: 4 flat fields → hookRegistration: HookRegistration?
  • "Metadata without hookEvent" validation removed — now a compile-time guarantee (HookRegistration.event is non-optional)
  • Add 5 missing hook events: StopFailure, InstructionsLoaded, PostCompact, Elicitation, ElicitationResult
  • Net -75 lines

Test plan

  • swift test passes locally (797 tests)
  • swiftformat --lint . and swiftlint pass without violations
  • Affected commands verified with a real pack (e.g. mcs sync, mcs doctor)
Checklist for engine changes
  • Integration tests updated for new features (LifecycleIntegrationTests or DoctorRunnerIntegrationTests)

- Replace four flat fields (hookEvent/hookTimeout/hookAsync/hookStatusMessage) with single HookRegistration? on ComponentDefinition and ExternalComponentDefinition
- Remove ConfigurationDiscovery.HookInfo (replaced by HookRegistration)
- Add 5 missing hook events from official docs: StopFailure, InstructionsLoaded, PostCompact, Elicitation, ElicitationResult
- Restore orphaned hook metadata rejection (decode-time DecodingError)
- Add Equatable conformance to HookRegistration
- Remove dual-parameter hookComponent helper — use hookRegistration only
- Clean up stale blank lines in ExternalPackAdapterTests
- Strengthen orphaned metadata test: assert DecodingError.dataCorrupted with message check
- Include component ID in DecodingError debugDescription for actionable messages
- Use try #require to unwrap hookRegistration before asserting nil sub-fields
- Add timeout: 0 boundary test for off-by-one guard
- Clean up stray blank line in ExternalPackAdapterTests
@bguidolim bguidolim merged commit a0559d2 into main Mar 22, 2026
4 checks passed
@bguidolim bguidolim deleted the bruno/266-hook-registration-struct branch March 22, 2026 21:25
@bguidolim bguidolim mentioned this pull request Mar 22, 2026
3 tasks
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.

Consolidate hook metadata fields into HookRegistration struct

1 participant