Skip to content

[Feature]: Deterministic HookExecutor bridge via user_prompt_submit runtime events (for lean and custom presets) #5532

Backlog

Description

@markuswondrak

Problem Statement

Spec Kit's extension lifecycle hooks (hooks.before_<cmd> / hooks.after_<cmd> in .specify/extensions.yml) currently rely entirely on static prompt boilerplate embedded in each core command template (templates/commands/*.md). This causes three concrete gaps:

  1. presets/lean and custom strategy: replace presets silently drop extension hooks:
    Any preset overriding core command templates with strategy: replace either duplicates ~65–75 lines of YAML-parsing hook instructions per template or silently ignores installed extensions (such as git or agent-context). Today, specify preset add lean stops before_* / after_* hooks from firing.
  2. HookExecutor exists in Python, but shipped prompts bypass it:
    HookExecutor in src/specify_cli/extensions/__init__.py (get_hooks_for_event, should_execute_hook, check_hooks_for_event, format_hook_message, _render_hook_invocation) already implements priority sorting, condition evaluation (config.*, env.*), and agent-specific invocation formatting. Shipped command templates instead instruct the LLM to read .specify/extensions.yml directly—ignoring priority and skipping hooks with non-empty condition expressions (as noted in design/extension.md).
  3. Unconditional prompt overhead and output noise:
    All nine core command templates carry pre- and post-hook boilerplate on every invocation even when zero extensions or hooks are configured.

Proposed Solution

Introduce an opt-in bundled companion extension (e.g., hook-bridge) powered by Spec Kit's existing runtime events: dispatcher (.specify/events.py / src/specify_cli/events/):

  • Integration scope: Derived from the events abstraction — support integrations with verified model-context injection on user_prompt_submit (claude, codex, gemini, qwen, tabnine, devin, opencode); event support alone is insufficient. cursor-agent (suppress), vibe (no user_prompt_submit event), and copilot (userPromptSubmitted command hooks drop stdout; see [Bug]: Copilot integration maps user_prompt_submit to additionalContext, which Copilot command hooks drop #5544), along with file-only integrations, are excluded in v1. Document the supported integrations and their event-specific delivery behavior.
  • Declare a user_prompt_submit handler in the bundled extension's extension.yml (backed by a standalone Python script with thin sh / ps wrappers, following existing bundled extensions like git and agent-context without importing specify_cli at runtime).
  • On user_prompt_submit, deterministically parse the submitted prompt ({"prompt": ...} and OpenCode chat.message output.parts) to detect Spec Kit phase commands (constitution, specify, clarify, plan, tasks, checklist, analyze, implement, converge, etc.) across slash (/speckit.<cmd>, /speckit-<cmd>), dollar-skill ($speckit-<cmd>), and /skill:speckit-<cmd> invocation styles.
  • Support optional command filtering in hook-bridge-config.yml (with local-config.yml override) via include_commands and exclude_commands so users can scope the bridge to replaced commands (e.g., the 5 commands replaced by presets/lean) without duplicate instructions on non-overridden core templates.
  • Resolve before_<phase> and after_<phase> with full contract parity to HookExecutor (enabled, ascending priority, config.* / env.* condition expressions, and agent-specific invocation rendering from .specify/init-options.json), using PyYAML when available and a lightweight stdlib reader for Spec Kit's configuration YAML subset when PyYAML is absent.
  • Zero-hook fast path: Emit 0 bytes on stdout when the prompt is not an eligible phase command or no executable hooks match, adding zero context tokens.
  • Just-in-time context injection: Only when executable hooks exist for the detected phase, emit concise pre-/post-hook instructions (EXECUTE_COMMAND / EXECUTE_COMMAND_INVOCATION for optional: false, prompt/hint for optional: true), which .specify/events.py wraps in the supported integration's native context envelope for user_prompt_submit.
  • Intended use and non-goals: Pair the bridge with presets/lean and custom presets whose commands do not already handle extension hooks. Do not combine it on the same command with templates that already perform their own hook handling (use include_commands / exclude_commands for partial presets like lean). Automatic detection of hook-handling prompt content, deduplication, and changes to core command templates are out of scope.
  • Update extension & preset authoring documentation: Document the new bundled bridge in docs/extensions/developing.md, docs/extensions/api.md, docs/presets/developing.md (plus design/extension.md, extensions/README.md, and presets/lean/README.md) so extension and preset authors know:
    • priority and condition (config.*, env.*) are evaluated deterministically when the bridge extension is installed on integrations supporting context injection at user_prompt_submit (whereas core template boilerplate alone falls back to YAML order and skips hooks with condition).
    • Presets without their own hook handling (like lean) do not need to duplicate hook YAML-parsing boilerplate when paired with the bridge extension, and partial presets can scope commands via include_commands / exclude_commands. Commands that already handle hooks must not additionally use the bridge, to avoid duplicate hook instructions; no automatic detection or validation is provided. Integrations without context injection at user_prompt_submit (including Cursor, Vibe, Copilot until [Bug]: Copilot integration maps user_prompt_submit to additionalContext, which Copilot command hooks drop #5544 is addressed, and file-only integrations) still require template-level hook handling.

Alternatives Considered

  • Copying hook boilerplate into presets/lean templates: Defeats the purpose of lean ("just the prompt, just the artifact"), keeps hook execution non-deterministic, and still ignores priority and condition.
  • Removing hook boilerplate from core templates immediately: Breaks hooks on file-only integrations that do not support user_prompt_submit runtime events. Shipping this as an opt-in bundled extension preserves existing behavior while enabling deterministic hook resolution on integrations supporting context injection at user_prompt_submit.
  • Resolving after_<phase> on stop events: stop hooks cannot reliably trigger a new slash-command/skill turn across all agents, whereas resolving both before_<phase> and after_<phase> during user_prompt_submit gives uniform pre/post obligations inside the active turn.

Component

Agent integrations (command files, workflows)

AI Agent (if applicable)

Integrations with verified context injection at user_prompt_submit (claude, codex, gemini, qwen, tabnine, devin, opencode). cursor-agent, vibe, copilot (#5544), and file-only integrations are excluded in v1.

Use Cases

  1. Using presets/lean together with extensions/git (before_specify, before_plan, etc.) and extensions/agent-context (after_specify, after_plan) so lifecycle hooks still run automatically without prompt boilerplate.
  2. Authoring custom strategy: replace presets without their own hook handling that stay minimal without duplicating hook YAML-parsing instructions.
  3. Defining extension hooks with priority ordering and condition expressions (config.* / env.*) and having them evaluated deterministically.

Acceptance Criteria

  • Bundled extension added under extensions/ and registered in extensions/catalog.json (plus packaging/tests as needed).
  • Supported integrations (claude, codex, gemini, qwen, tabnine, devin, opencode) are documented and verified specifically for context injection at user_prompt_submit; negative tests cover non-injecting event paths (cursor-agent suppress, vibe omitted event) so event support alone is never treated as bridge support.
  • user_prompt_submit handler detects Spec Kit phase commands across slash, skill-slash, and dollar-skill invocation formats from standard {"prompt": ...} payloads and OpenCode chat.message output.parts payloads, honoring optional include_commands / exclude_commands config (hook-bridge-config.yml + local-config.yml).
  • Standalone handler (no runtime specify_cli import) resolves before_<phase> and after_<phase> with contract-tested HookExecutor parity (enabled, priority, condition, and invocation rendering), both with and without PyYAML.
  • Emits 0 bytes on stdout when the prompt is not an eligible Spec Kit phase command or no executable hooks match.
  • Emits agent-formatted pre/post hook instructions wrapped by .specify/events.py when executable hooks match.
  • Documentation explicitly limits bridge use to commands without their own hook handling, provides include_commands / exclude_commands guidance (including presets/lean and custom preset migration), warns against combining it with existing hook-handling commands, and states that there is no automatic detection, validation, or deduplication. Core command templates remain unchanged.
  • Automated tests cover positive and negative cases (prompt matching across payload shapes, include_commands/exclude_commands, zero-hook fast path, priority ordering, condition evaluation, HookExecutor contract parity with and without PyYAML, integration envelope conformance, and Windows PowerShell 5.1 compatibility if .ps1 wrapper is included).
  • Extension and preset authoring docs updated (docs/extensions/developing.md, docs/extensions/api.md, docs/presets/developing.md, design/extension.md, extensions/README.md, presets/lean/README.md) to explain the bundled bridge, priority/condition evaluation on supported integrations vs. core templates, the event-specific support boundary, and guidance for strategy: replace preset authors.

Additional Context

AI Disclosure

Drafted with the pi coding agent (provider: github-copilot, model: gemini-4-hydrogen, reasoning effort: high, human-supervised) based on Discussion #5527 and codebase inspection. The issue was posted on behalf of @markuswondrak without prior review of its text.

Disclosure correction by the pi coding agent (GitHub Copilot, model: gpt-6.1-terra, reasoning effort: high, interactive mode); removed an unsupported claim of prior review.

Scope clarification on behalf of @markuswondrak by the pi coding agent (provider: github-copilot, model: gpt-6.1-sol, reasoning effort: high, interactive/human-supervised mode): applied the agreed event-specific integration support boundary and corresponding documentation/test requirements.

Usage-boundary clarification on behalf of @markuswondrak by the pi coding agent (provider: github-copilot, model: gpt-6.1-sol, reasoning effort: high, interactive/human-supervised mode): recorded the agreed documentation-only boundary for commands without existing hook handling; no prompt inspection, validation, deduplication, or core-template changes.

Assessment clarifications synced on behalf of @markuswondrak by the pi coding agent (provider: github-copilot, model: gemini-4-carbon, reasoning effort: high, interactive/human-supervised mode): aligned v1 integration matrix (referencing #5544), added optional include_commands/exclude_commands config, and simplified runtime execution to a standalone script without importing specify_cli.

Activity

  1. added
    feature-assess
    on Nov 23, 2026
  2. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Feature assessment — deterministic-hook-bridge · Stage 1/5: Intake

    Idea Intake: Deterministic HookExecutor bridge for runtime hook injection

    Idea (as captured)

    “Spec Kit's extension lifecycle hooks (hooks.before_ / hooks.after_ in .specify/extensions.yml) currently rely entirely on static prompt boilerplate embedded in each core command template...”

    The request proposes a bundled, opt-in hook-bridge extension that resolves hook execution via runtime user_prompt_submit events and HookExecutor semantics (including priority and condition) so lean/custom presets do not have to duplicate hook boilerplate and can still execute hooks deterministically. It explicitly limits support to integrations that can inject context on user_prompt_submit, excludes Cursor in this version, requires a zero-byte fast path when no hooks apply, and asks for documentation and test updates.

    Related references included by the author:

    Restated

    Introduce an optional bridge extension that computes applicable lifecycle hooks at runtime for phase commands, using the existing hook execution model instead of template-embedded YAML parsing. This should preserve minimal prompts for lean/replace presets, keep current behavior for unsupported integrations, and document strict usage boundaries to avoid duplicate hook instructions.

    Origin & Context

    First-Glance Unknowns

    • [NEEDS CLARIFICATION: Which integrations are in-scope for v1 support beyond the explicit Cursor exclusion, and what verification matrix is required per integration?]
    • [NEEDS CLARIFICATION: Should bridge output format reuse existing hook instruction phrasing verbatim, or may it introduce a new compact envelope as long as semantics match?]
    • [NEEDS CLARIFICATION: How should mixed environments be handled where specify_cli importability differs between local and ephemeral runtime execution paths?]
    • [NEEDS CLARIFICATION: What is the expected migration guidance for users currently depending on template-level hook handling in custom presets?]

    Generated by 💡 Assess a Feature Request by Installing and Running Spec Kit for #5532 · copilot · gpt53codex · 69.6 AIC · ⌖ 0.703 AIC · ⊞ 26.4K · ◷

  3. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Feature assessment — deterministic-hook-bridge · Stage 2/5: Research

    Idea Research: Deterministic HookExecutor bridge via user_prompt_submit events

    • Slug: deterministic-hook-bridge
    • Created: 2026-11-23T18:16:29Z
    • Evidence confidence (overall): medium

    Users & Demand

    Prior Art

    • The repository already has a runtime events subsystem (.specify/events.py dispatcher and integration mappings), so an event-triggered bridge aligns with existing architecture instead of introducing a new execution channel. — [source: src/specify_cli/events/__init__.py; docs/extensions/api.md] (confidence: high)
    • HookExecutor already implements core logic the issue wants reused (enabled filtering, condition evaluation on config.*/env.*, priority ordering, and invocation rendering), and design docs explicitly state core templates do not use this executor today. — [source: design/extension.md lines 326–334; src/specify_cli/extensions/__init__.py] (confidence: high)
    • Core command templates currently perform direct .specify/extensions.yml parsing in prompt text (including condition-skipping behavior), validating the duplication/drift risk called out by the request. — [source: templates/commands/specify.md pre-execution hook section; similar pattern across command templates] (confidence: high)
    • Lean preset intentionally keeps command prompts minimal and replaces core templates, which supports the claim that duplicating hook boilerplate there conflicts with lean goals. — [source: presets/lean/README.md] (confidence: high)

    Market & Context

    • Spec Kit has moved toward integration-native runtime event wiring across multiple agents; adding extension behavior via event dispatch is directionally consistent with this trajectory. — [source: newsletters/2026-July.md; docs/extensions/api.md] (confidence: medium)
    • Teams increasingly run autonomous/low-touch agent flows; in that context, behavior that depends on template boilerplate or voluntary command invocation is less deterministic than runtime event dispatch. — [source: [Feature]: Let extensions contribute always-on instructions (not just on-demand commands + hooks) #4200; ASSUMPTION informed by issue narrative] (confidence: low)

    Data & Constraints

    • Integration behavior is event-specific: Copilot maps user_prompt_submit to an envelope that can inject context, while Cursor maps the same canonical event to suppress output, making Cursor ineligible for context injection through this event in current architecture. — [source: src/specify_cli/integrations/copilot/__init__.py; src/specify_cli/integrations/cursor_agent/__init__.py; tests/specify_cli/events/test_events.py] (confidence: high)
    • Bundled extension registration exists and is catalog-backed (extensions/catalog.json), so adding an opt-in bundled bridge is mechanically compatible with current packaging/discovery flow. — [source: extensions/catalog.json] (confidence: high)
    • Event handlers execute scripts, not markdown instructions, so any bridge must provide command/script assets compatible with event dispatch semantics. — [source: docs/extensions/api.md “Extension Runtime Events”] (confidence: high)

    Evidence Against the Idea

    Gaps & Open Questions

    Sources

    Generated by 💡 Assess a Feature Request by Installing and Running Spec Kit for #5532 · copilot · gpt53codex · 69.6 AIC · ⌖ 0.703 AIC · ⊞ 26.4K · ◷

  4. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Feature assessment — deterministic-hook-bridge · Stage 3/5: Problem

    Problem Definition: Non-deterministic extension hook behavior across presets and integrations

    • Slug: deterministic-hook-bridge
    • Created: 2026-11-23T18:16:29Z
    • Inputs used: intake.md + research.md

    Problem Statement

    Spec Kit users who adopt lean or custom replace-style presets can lose reliable extension hook behavior because hook handling currently depends on template-embedded parsing that is duplicated, omitted, or semantically inconsistent with runtime hook rules. This creates unpredictable extension outcomes across integrations and increases maintenance burden at the moment teams are trying to simplify and standardize their workflow.

    Affected Users & Stakeholders

    • Users: Preset authors and teams using strategy: replace command templates — they may silently lose expected hook behavior or receive inconsistent hook execution semantics.
    • Users: Extension authors relying on priority and conditional hooks — their extension behavior may differ from declared intent when templates bypass runtime hook semantics.
    • Stakeholders: Spec Kit maintainers — responsible for architecture consistency, integration compatibility, and documentation clarity.
    • Stakeholders: Integration maintainers (Copilot/Cursor/others) — impacted by event-specific context delivery constraints and support boundaries.

    Goals

    • Ensure extension hook behavior is predictable and consistent where supported.
    • Reduce duplication of hook-handling prompt boilerplate for lean/custom preset authors.
    • Preserve clear boundaries for unsupported integration/event combinations to avoid false expectations.
    • Maintain backwards compatibility for existing workflows that depend on current template behavior.

    Non-Goals

    • Defining a full implementation design for hook execution or event dispatch.
    • Removing or rewriting all existing core command template hook logic in this stage.
    • Guaranteeing universal parity across every integration without explicit support evidence.
    • Solving unrelated extension reliability problems outside lifecycle hook resolution.

    Success Metrics

    • Affected workflows can identify whether hook behavior is deterministic under documented support conditions (baseline: inconsistent/unclear in current issue narrative).
    • Documentation provides explicit do/do-not usage boundaries for preset + hook handling combinations (baseline: insufficiently explicit per issue claim).
    • Supported integrations for the relevant event/context path are enumerated with passing verification criteria (baseline: [NEEDS CLARIFICATION: final supported set and matrix]).
    • Reported cases of silent hook omission in lean/custom replace usage decrease after adoption (baseline: [NEEDS CLARIFICATION: no quantified current rate in repository telemetry]).

    Cost of Inaction

    Preset and extension authors continue to choose between duplicated boilerplate and unreliable hook behavior, leading to inconsistent user experiences, avoidable support/debug effort, and reduced trust that extension declarations map to real runtime behavior.

    Open Questions

    Generated by 💡 Assess a Feature Request by Installing and Running Spec Kit for #5532 · copilot · gpt53codex · 69.6 AIC · ⌖ 0.703 AIC · ⊞ 26.4K · ◷

  5. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Feature assessment — deterministic-hook-bridge · Stage 4/5: Concept

    Concept: Deterministic hook delivery for lean/custom preset workflows

    • Slug: deterministic-hook-bridge
    • Created: 2026-11-23T18:16:29Z
    • Recommended option: Option B — Opt-in runtime hook bridge extension

    Options

    Option A — Template-only documentation hardening (smallest viable)

    • Sketch: Keep current behavior but tighten guidance so preset authors explicitly copy and maintain hook-handling boilerplate (including limits around conditions/ordering) when replacing core templates.
    • Appetite: small
    • Trade-offs: Fastest to ship and lowest engineering risk; does not solve semantic drift or deterministic execution, and keeps duplication burden on users.
    • Rabbit holes: Documentation may reduce confusion but not behavior variance; users can still silently misconfigure or omit hooks.

    Option B — Opt-in runtime hook bridge extension

    • Sketch: Offer a bundled optional extension that injects concise pre/post hook obligations at prompt-submit time only for supported integrations and only when matching hooks exist, while preserving existing template paths for other contexts.
    • Appetite: medium
    • Trade-offs: Improves determinism and reduces duplicated prompt boilerplate for lean/custom presets; introduces boundary management (avoid double-handling with templates) and requires clear integration support/testing contracts.
    • Rabbit holes: Edge cases in command detection across invocation styles, fallback parity when runtime imports differ, and support-matrix drift across integrations.

    Option C — Unified runtime-only hook model across all commands/integrations

    • Sketch: Migrate hook behavior away from template-level handling to a single runtime event-driven model intended to cover all commands and integrations.
    • Appetite: large
    • Trade-offs: Highest long-term consistency if successful; highest migration risk, broad compatibility surface, and likely regressions for integrations/events that cannot inject context.
    • Rabbit holes: Backward compatibility breaks, rollout sequencing, and integration-specific blockers (e.g., events with suppressed output).

    Recommendation

    Recommend Option B. It directly targets the stated pain (lean/custom preset duplication and non-deterministic hook semantics) while containing scope through opt-in adoption and explicit integration boundaries. It best aligns with the goals of deterministic behavior, reduced boilerplate, and compatibility preservation, without requiring an all-at-once migration.

    Out of Scope (for the recommended option)

    • Replacing or removing existing core template hook sections globally.
    • Automatic detection/deduplication of bridge usage alongside template-level hook handling unless explicitly added later.
    • Guaranteeing support for integrations/events that cannot provide prompt-time context injection (including current Cursor constraints).
    • Full redesign of the extension/hook/event architecture.

    Assumptions to Validate

    • Supported integrations can reliably inject context for user_prompt_submit without introducing malformed output or user-visible noise.
    • Users can follow documentation boundaries to avoid combining duplicate hook-handling paths.
    • Runtime hook selection via existing hook semantics provides materially better predictability than template parsing for the target workflows.
    • The fallback path (when runtime imports are unavailable) can preserve practical parity for ordering/conditions in supported environments.

    Generated by 💡 Assess a Feature Request by Installing and Running Spec Kit for #5532 · copilot · gpt53codex · 69.6 AIC · ⌖ 0.703 AIC · ⊞ 26.4K · ◷

  6. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Feature assessment — deterministic-hook-bridge · Stage 5/5: Decision — verdict needs-clarification

    Decision: Deterministic hook bridge for preset workflows

    • Slug: deterministic-hook-bridge
    • Decided: 2026-11-23T18:16:29Z
    • Verdict: needs-clarification
    • Artifacts reviewed: intake.md | research.md | problem.md | concept.md

    Scorecard

    Criterion Rating Justification
    Problem validity strong The problem is concrete and repeatedly observed: hook behavior can become inconsistent/silently absent in lean/custom replace flows.
    Evidence strength adequate Repository docs/code and issue history support the core claim, but integration support matrix and some linked historical references remain incomplete/unverified.
    Value vs. inaction adequate Inaction preserves duplication, ambiguity, and inconsistent hook semantics for affected users; addressing it likely improves reliability and authoring ergonomics.
    Feasibility / appetite adequate A medium-scope opt-in bridge concept is plausible within existing event/extension architecture, but fallback and compatibility details are still unsettled.
    Strategic fit adequate The direction aligns with runtime-event architecture and extension UX goals, while preserving optional adoption.
    Risk posture weak The largest risks (duplicate instruction paths, integration-boundary drift, and parity of fallback behavior) are known but not yet concretely mitigated with agreed guardrails/tests.

    Verdict & Rationale

    Verdict: needs-clarification. The idea appears valuable and directionally feasible, but the current evidence package is not yet strong enough for a clean go because key support boundaries and risk controls are unresolved. Specifically, confidence depends on an explicit integration support matrix, enforcement/mitigation for duplicate hook handling, and clearer parity expectations for runtime-vs-fallback behavior.

    If needs-clarification

    • Blocking questions:
      • [NEEDS CLARIFICATION: Final v1 supported integrations for user_prompt_submit context injection, with explicit exclusions and rationale.]
      • [NEEDS CLARIFICATION: Required test matrix per supported integration, including negative coverage for non-injectable paths (e.g., Cursor suppress behavior).]
      • [NEEDS CLARIFICATION: Product boundary for duplicate handling (documentation-only vs. runtime warnings/validation) and acceptance criteria for that boundary.]
      • [NEEDS CLARIFICATION: Behavioral parity contract for stdlib fallback when specify_cli is unavailable.]
    • Revisit stage: research

    If go — Handoff to /speckit-specify

    Not applicable until blocking clarifications above are resolved.

    Generated by 💡 Assess a Feature Request by Installing and Running Spec Kit for #5532 · copilot · gpt53codex · 69.6 AIC · ⌖ 0.703 AIC · ⊞ 26.4K · ◷

  7. added
    feature-needs-clarification
    on Nov 23, 2026
  8. mnriem commented on Nov 23, 2026

    @mnriem
    Collaborator

    @markuswondrak As I stated before it is a go, but please keep in mind that I would like to see the open questions answered so we know what we specifically are targeting

  9. markuswondrak commented on Nov 23, 2026

    @markuswondrak
    ContributorAuthor

    Clarifications for the open questions from the feature assessment, posted on behalf of @markuswondrak. These are the decisions the implementation will be built and reviewed against.

    1. Supported integrations (derived from the events abstraction)

    • Architectural rule: The bridge extension couples strictly to Spec Kit's canonical events.user_prompt_submit mechanism (stdin JSON -> plain-text stdout -> .specify/events.py context envelope). The extension itself contains no integration-specific branching or agent lists (beyond reading .specify/init-options.json to render the active agent's hook invocation syntax, matching HookExecutor).
    • Eligibility rule: An integration delivers bridge output when user_prompt_submit is mapped in CANONICAL_TO_NATIVE, its resolved events_context_envelope for user_prompt_submit is not "suppress", and its native runtime actually consumes command-hook output as model context.
    • v1 integration matrix (current repository state):
      • Supported in v1 (7):
        • claude, codex — UserPromptSubmit with plain stdout passthrough
        • gemini, tabnine — BeforeAgent with hookSpecificOutput.additionalContext
        • qwen, devin — UserPromptSubmit with hookSpecificOutput.additionalContext
        • opencode — chat.message TS plugin injecting a synthetic TextPart into output.parts
      • Excluded in v1 (and rationale):
        • cursor-agent — maps user_prompt_submit to beforeSubmitPrompt with envelope "suppress" (block/allow only, no context-injection channel).
        • vibe — native hook schema (pre_tool, post_tool, post_agent) has no user_prompt_submit event.
        • copilot — although CopilotIntegration currently sets additionalContext on userPromptSubmitted, Copilot command hooks drop stdout on userPromptSubmitted (filed separately as [Bug]: Copilot integration maps user_prompt_submit to additionalContext, which Copilot command hooks drop #5544). Until Copilot per-prompt context injection is supported by Spec Kit's event layer, copilot is documented as unsupported for the bridge.
        • File-only integrations (33, e.g., generic, cline, pi, goose, zed, …) — do not install or run .specify/events.py; they continue to rely on template-level hook handling.
    • Relationship to [Feature]: Add additional_context on workflow command steps for curated context provisioning #5533 (additional_context on workflow command steps): Orthogonal, with no ordering dependency. [Feature]: Add additional_context on workflow command steps for curated context provisioning #5533 uses a built-in session_start handler scoped to child-process env (SPECKIT_ADDITIONAL_CONTEXT), while [Feature]: Deterministic HookExecutor bridge via user_prompt_submit runtime events (for lean and custom presets) #5532 is an opt-in bundled extension on user_prompt_submit.

    2. Required conformance test matrix

    Deterministic CI tests cover the two runtime boundaries without launching live agent CLIs:

    1. Inbound stdin payload extraction (handler unit tests):
      • Standard command-hook JSON payload ({"prompt": "..."}) used by claude, codex, gemini, qwen, tabnine, and devin.
      • OpenCode chat.message plugin payload ({"input": ..., "output": {"parts": [{"type": "text", "text": "..."}]}}).
      • Phase command matching across /speckit.<cmd>, /speckit-<cmd>, $speckit-<cmd>, and /skill:speckit-<cmd> (plus negative cases: ordinary chat text, non-phase commands, malformed/empty JSON -> exit 0 and 0 bytes on stdout).
    2. End-to-end event wiring & envelope conformance (parametrized across integrations):
      • Positive coverage across all 7 supported integrations verifying native event installation and .specify/events.py output shape (plain, hookSpecificOutput with the integration's native hookEventName, and OpenCode chat.message synthetic TextPart generation).
      • Negative coverage: cursor-agent (suppress -> 0 bytes), vibe (user_prompt_submit skipped cleanly), and zero-hook fast path emitting 0 bytes under every envelope (never an empty JSON wrapper).
      • Wrapper parity across .py, .sh, and Windows PowerShell 5.1 .ps1.

    3. Duplicate-handling boundary, command filtering, and migration guidance

    • No runtime template/prompt inspection or deduplication: Core command templates (templates/commands/*.md) remain unchanged, and the bridge does not inspect Markdown files to guess whether a command already handles hooks.
    • User-controlled command filtering (hook-bridge-config.yml + gitignored local-config.yml override):
      • include_commands: [] — empty by default (all recognized phase commands eligible); when non-empty, acts as an explicit allowlist.
      • exclude_commands: [] — explicit blocklist (takes precedence over include_commands), accepting short phase names (plan) or full command IDs (speckit.plan).
      • This cleanly solves partial replace presets without magic: for example, presets/lean replaces 5 of the 9 core commands (constitution, specify, plan, tasks, implement) while leaving clarify, checklist, analyze, and converge on core templates. Setting include_commands: [constitution, specify, plan, tasks, implement] prevents duplicate hook instructions on the 4 non-overridden core commands.
    • Migration guidance in docs (presets/lean/README.md, docs/presets/developing.md, docs/extensions/developing.md):
      • Ready-to-copy include_commands configuration for presets/lean.
      • For custom strategy: replace presets that previously copied the YAML hook-parsing block: either remove the copied hook block when adopting hook-bridge on supported integrations, or list those commands in exclude_commands.

    4. Standalone runtime execution (no specify_cli import) & output format

    • Single standalone runtime path — specify_cli import dropped: Following existing bundled extensions (extensions/agent-context, extensions/git), the bridge script will not import specify_cli at runtime. Importing the full CLI package on every user_prompt_submit turn adds unnecessary startup overhead and creates two divergent execution modes. Instead, the extension uses one lightweight Python implementation (PyYAML when available in the interpreter, with a small stdlib reader for Spec Kit's configuration YAML subset when PyYAML is absent; if a hand-edited YAML file uses unsupported YAML constructs without PyYAML, report the parse error on stderr rather than silently skipping mandatory hooks or corrupting stdout).
    • Contract parity with HookExecutor: Automated contract tests run identical .specify/extensions.yml, <ext>-config.yml / local-config.yml, env.*, and .specify/init-options.json fixtures through both HookExecutor and the bridge script, asserting identical hook selection (enabled), ascending priority ordering (stable on ties), evaluation of all 5 HookExecutor condition forms (config.<path> is set, ==, !=; env.<VAR> is set, ==, !=), and agent-specific command invocation rendering.
    • Output format: Reuses HookExecutor.format_hook_message()'s per-hook block syntax (**Automatic Hook** with EXECUTE_COMMAND / EXECUTE_COMMAND_INVOCATION, and **Optional Hook** with Prompt / To execute), framed by concise phase-level instructions distinguishing before_<phase> (run mandatory hooks and wait before starting the phase; surface optional hooks first) from after_<phase> (run/offer after the phase completes). When neither before_<phase> nor after_<phase> has executable hooks (including when all conditions evaluate to False), stdout is strictly 0 bytes.

    5. Unresolved historical reference IDs (#3128, #3473, #4557)


    AI disclosure: Drafted on behalf of @markuswondrak by the pi coding agent (provider: github-copilot, model: gemini-4-carbon, reasoning effort: high, interactive and human-supervised). Each decision was discussed and approved by @markuswondrak based on codebase inspection.

  10. markuswondrak commented on Nov 25, 2026

    @markuswondrak
    ContributorAuthor

    @mnriem does this work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-assessfeature-needs-clarification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions