Repository navigation
Deterministic HookExecutor bridge via user_prompt_submit runtime events (for lean and custom presets) #5527
markuswondrak
started this conversation in
Ideas
Replies: 1 comment
|
Yes please! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Revisiting a topic I raised earlier from the workflow angle in #3473 and #4557 — this time strictly on the direct agent/IDE command side, using the runtime
events:mechanism that landed since then.In #4557, @mnriem clarified the intended boundary: overlays and slots extend workflows, while hooks extend commands for users invoking slash commands/skills directly in their agent or IDE (without routing hooks through the workflow engine, per #2104 and #3473). Keeping that boundary intact, there is still an unresolved gap in how command-side hooks are delivered today.
Why it matters
Right now, Spec Kit's extension lifecycle hooks (
hooks.before_<cmd>/hooks.after_<cmd>in.specify/extensions.yml) rely entirely on static prompt boilerplate embedded in each core command template:presets/lean(and customreplacepresets) silently drop extension hooks:Because lifecycle hooks are purely prompt-driven today, every command that overrides a core template with
strategy: replacemust either copy ~65–75 lines of YAML-parsing hook instructions or silently ignore installed extensions (such asgitoragent-context). Currently, installingspecify preset add leanstops allbefore_*/after_*hooks from firing.HookExecutoralready exists in Python, but core prompts bypass it:HookExecutorinsrc/specify_cli/extensions/__init__.py(get_hooks_for_event,should_execute_hook,check_hooks_for_event,_render_hook_invocation) already implementsprioritysorting,conditionevaluation (config.*,env.*), and agent-specific command formatting. However, as noted indesign/extension.md, shipped command templates read.specify/extensions.ymlvia LLM instructions instead—ignoringpriorityand skipping every hook with a non-emptycondition.All nine core command templates carry pre- and post-hook boilerplate on every invocation even when zero extensions are installed (related to #2943, #3128, and #4200).
Proposal
Introduce an opt-in bundled companion extension (e.g.,
hook-bridgeorlifecycle-hooks, ideal alongsidepresets/leanand reusable by any custom preset) powered by Spec Kit's existing runtimeevents:dispatcher (.specify/events.py):sh/pswrappers) toevents.user_prompt_submit.constitution,specify,clarify,plan,tasks,implement,converge, etc.) is being invoked across slash/dollar/skill invocation styles.HookExecutor(with a stdlib fallback whenspecify_cliis not installed in the active runtime) forbefore_<phase>andafter_<phase>—honoringenabled,priority, andconditionexpressions.0 bytesonstdout→ zero extra context tokens and zero hook boilerplate needed inside preset prompts.EXECUTE_COMMANDforoptional: false, optional hint foroptional: true), which.specify/events.pyalready wraps into each agent's native context envelope (additionalContext,hookSpecificOutput,additional_context, plain stdout, etc.).Known trade-offs & scope questions
copilot,claude,cursor-agent,codex,gemini,opencode,qwen,devin,tabnine, etc.) already supportuser_prompt_submitcontext injection, whereas file-only integrations (generic,cline, etc.) do not fire runtime events. Shipping this as a bundled extension first (rather than immediately stripping hook blocks from core templates) keeps non-event integrations working while immediately unlocking full hook support—includingpriorityandcondition—forleanand custom presets.after_<phase>handling: Becausestopcannot initiate a new slash-command turn across all agents, resolving bothbefore_<phase>andafter_<phase>duringuser_prompt_submitand injecting pre/post obligations into the active turn keeps behavior uniform across event-capable agents.Would a bundled companion extension (or pairing it with
presets/lean) align with the roadmap? Happy to prototype and submit a focused PR with tests if this direction makes sense.AI Disclosure (per CONTRIBUTING.md): Drafted on behalf of @markuswondrak with GitHub Copilot CLI (model: Gemini 4 Carbon /
gemini-4-carbon, interactive/supervised mode; codebase analysis and discussion draft).All reactions