feat: first-class agent-native runtime hooks for integrations#3704
feat: first-class agent-native runtime hooks for integrations#3704kanfil wants to merge 1 commit into
Conversation
|
Thanks for this — the agent-runtime wiring is a real gap and the canonical→native event mapping, marker-based surgical teardown, and layered resolution are the right instincts. Sharing some architectural feedback before this goes further; happy to pair on any of it. 1. Call the feature "events", and use snake_case names consistent with the existing event vocabulary.
Adapters translate those canonical snake_case names to each agent's native casing (Claude 2. Drive adapters from the integration registry, not a parallel 3. Split sourcing from writing so
4. The dispatcher is agent-agnostic → make it core. One 5. Two capabilities the PR description advertises aren't actually wired yet — make sure the reworked versions are real and covered by tests. As filed: the disable flag reads 6. Missing Copilot CLI adapter. Copilot CLI has first-class hooks (docs): native events ( Smaller correctness notes: the Codex adapter embeds Net: the writing mechanism belongs in the integration layer as you have it — the main structural change is splitting the one module in two: native-config writing stays per-integration (registry-driven), while event sourcing moves to an injected core resolver, with the dispatcher lifted to core. Add the terminology change and the Copilot adapter and I think this is in great shape. Glad to help implement or review. Posted on behalf of @mnriem by GitHub Copilot (model: Claude Opus 4.8). |
mnriem
left a comment
There was a problem hiding this comment.
Please address my feedback above. Great proposal!
🎯 Problem & Motivation
While Spec Kit excels at scaffolding commands and prompt templates during
specify init, there was previously no first-class mechanism for event-driven hook execution natively tied to AI coding agents in upstream.This PR introduces an agent-native runtime hooks layer that bridges Spec Kit directly to agent lifecycle events (like
SessionStart,PreToolUse,PostToolUse,Stop, etc.).✨ Key Features Added
The Hook Bridge (
.specify/hooks/bridge.py):A lightweight, zero-dependency Python script scaffolded in projects during
specify init. It maps registered Spec Kit commands to their underlying scripts and executes them on demand, passing any payload throughstdin.Agent Hook Adapters:
Individual, target-aware adapters for multiple agent environments that generate/merge native hook configurations seamlessly during
setup()andteardown():.claude/settings.json(nested JSON structure).cursor/hooks.json(flat, camelCase structure).codex/config.toml(TOML format).opencode/plugin/speckit-hooks.ts+opencode.json(TypeScript plugin)Layered Hook Resolution:
Hooks are resolved cleanly using a 4-tier priority stack:
--hooks falseduring init disables hooks entirely..specify/integration-hooks.ymlto override hook behaviors.runtime_hooks:in theirextension.yml(completely decoupling core code from extension details!).🛠️ Example Usage
An extension can declare runtime hooks in
extension.yml:When the user runs
specify init --integration claude, the Claude adapter automatically detects this, generates the Hook Bridge, and injects the hook into.claude/settings.json. When Claude Code launches, it natively triggers the bridge, booting the team context seamlessly.🧪 Verification & Dependencies
pyyaml(already a spec-kit dependency) to parse extension-declared hooks. No new external dependencies.specify integration uninstallto cleanly strip all native hook config lines/plugins, leaving the user's files exactly as they were.