Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4822dd6
feat(workflows): add additional_context to command steps
Nov 29, 2026
ece26d6
fix(workflows): address #5616 review round 1
Nov 29, 2026
feca1cb
fix(workflows): address #5616 review round 2
Nov 29, 2026
377d852
fix(workflows): validate context hooks and JSON expressions
Dec 1, 2026
e97b6e0
Merge upstream/main into context delivery branch
Dec 1, 2026
4bfdba1
refactor(workflows): narrow JSON helper contract
Dec 1, 2026
615f907
fix(events): centralize state errors and check session_start matcher
Dec 1, 2026
2b0aab1
fix(events): migrate added filesystem I/O to FileHelper
Dec 2, 2026
251e44a
fix(integrations): enforce directory-only deletion in _prune_empty_pa…
Dec 2, 2026
b5b17b0
fix(events): give repair advice for unreadable native hook config
Dec 2, 2026
ff90039
fix(events): preflight lifecycle destinations before writes
Dec 5, 2026
049bd4d
feat(events): add json-named format, injectSteps envelope, and stale-…
Dec 5, 2026
6e6337a
fix(events): reject unsafe and unreadable named hook configs
Dec 5, 2026
35eb15e
fix(dispatch): stabilize relative PATH for integration processes
Dec 5, 2026
d3f2610
test(events): isolate fake integration state
Dec 5, 2026
c9164ce
feat(copilot): declare additional_context delivery
Nov 29, 2026
498ca2e
fix(copilot): validate event setup and installed hooks
Dec 2, 2026
266b04f
fix(copilot): validate hook working directory and cleanup preflight
Dec 3, 2026
067b9e5
refactor(copilot): rely on lifecycle event preflight
Dec 5, 2026
4e6c73f
fix(copilot): reject symlinked installed hook configs
Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion design/file-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ does not reopen the root pathname, so replacement followed by restoration cannot
substitute a different retained object. The metadata query uses a temporary
non-inheritable duplicate and leaves the original reference open.
If that reference or identity query is unavailable, the native capability error
is deferred to `delete()` rather than preventing ordinary read/write operations.
is deferred to `delete()` and `rmdir()` rather than preventing ordinary
read/write operations.
The cached error remains traceback-free; each failed deletion raises an
independent shallow copy retaining the native error type and filesystem details.

Expand Down Expand Up @@ -219,6 +220,7 @@ descriptor-relative or change their documented concurrency limitations.
| Non-atomic text overwrite/upsert | Reject accessed links | Update the resolved regular-file target in place and preserve every link |
| Delete leaf link | Reject without mutation | Unlink the link, including dangling, cyclic, or external-target links |
| Delete through linked parent | Reject without mutation | Delete the contained target entry, leaving the parent link intact |
| Remove empty directory (`rmdir`) | Reject accessed links without mutation | Resolve contained parent links; reject leaf links with `NotADirectoryError` without unlinking or following them |
| Recursive delete | Preflight all descendants and reject any link before mutation | Preflight all descendants; unlink links without traversing their targets |
| Create symlink | Reject | Require an existing contained file/directory target |

Expand Down Expand Up @@ -377,6 +379,15 @@ descriptor-relative or change their documented concurrency limitations.
being unconditionally linear in the directory count. Windows retains its
native-handle traversal instead of evicting handles needed for child-relative
operations. The complete plan is still preflighted before any removal.
- `rmdir(path)` removes an empty directory using the same retained-root and
anchored-parent machinery as `delete()`, while enforcing directory-only
removal at mutation time. Regular files raise `NotADirectoryError`, denied
links raise `SymlinkDeniedError`, allowed leaf links raise
`NotADirectoryError` without unlinking or following the link, and special
files or unsupported reparse points raise `UnsupportedPathError`. POSIX
removes the entry with descriptor-relative `rmdir`; Windows validates that the
opened leaf handle is a non-reparse directory before marking that handle for
deletion. The established root cannot be removed.
- `symlink(target, path)` creates a link exclusively. Relative targets are
interpreted relative to the link parent, not the helper root.

Expand Down
68 changes: 67 additions & 1 deletion design/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ setting. An integration that declares support and then ignores the value, for
example by absorbing it in `**kwargs`, drops it silently: a declaration is a
promise to translate the setting.

### Context delivery for command steps

An integration may declare `context_delivery_events` as a set or frozenset of
canonical events. This is a promise that its non-interactive CLI loads the
project hooks, fires the event, passes its environment to the hook, and feeds
the envelope output to the model. Effective support also requires a native
mapping, an envelope other than `suppress`, and a `dispatch_command` accepting
`additional_context` (or `**kwargs`). Declarations inherit normally; an
overriding adapter must honor the promise. Test declaration consistency and
provide live evidence for the agent-side behavior. The integration must also
report its installed canonical handlers through `installed_event_handlers()`,
either using a reader for its event format or overriding the method. For
formats with native event filters, `installed_event_handlers()` must exclude
handlers whose filter restricts normal fresh-session dispatch (for example, a
`resume`-only `session_start` matcher); only unfiltered or wildcard handlers
(absent, `""`, or `"*"`) qualify. `None` means the installation cannot be
inspected; a missing handler prevents dispatch. The shared dispatcher must
exactly match the current generated template.

Spec Kit installs the hook, runs the handler and writes the envelope. Agent-side
preconditions such as trust, feature flags and authentication belong in each
integration's guide; Spec Kit does not bypass them. The base dispatch removes
inherited context from the child environment even when unset. Legacy overrides
that do not accept the keyword cannot receive context and must clear inherited
context themselves when unset.

Native `json-named` event configs reserve the `__speckit_event__` definition;
its event arrays contain command handlers directly, while other named
entries remain user-owned. Integrations whose native hooks run from the config
file's directory declare `events_cwd_is_config_dir`; dispatcher and
project-relative interpreter paths are rendered relative to that directory.

## Output flavors

Choose the smallest base class that matches the agent's native format. The
Expand Down Expand Up @@ -485,7 +517,7 @@ them. Keep agent-specific settings and events consistent with that lifecycle.
`preflight_setup(project_root, parsed_options, *, script_type)` before they
write shared templates, scripts or integration files. Override it to reject a
setup that would fail partway, raising `ValueError` or `OSError`; the CLI then
exits with the message and changes nothing. The default accepts every setup.
exits with the message and changes nothing. The default accepts every setup. The lifecycle also runs shared event-destination preflight before writes and passes the resolved event map to setup.

Event cleanup releases only the departing integration's dispatcher claim.
It deletes `.specify/events.py` only when that integration's current or prior
Expand Down Expand Up @@ -555,3 +587,37 @@ they have merged. See the
and devcontainer setup if the agent needs additional tooling.

Prefer existing bases and shared processing over copied setup loops.

### Workflow dispatch search environment

Command and prompt dispatch capture the caller's working directory at workflow
run or resume. Each dispatch copies the current environment and anchors relative
PATH entries to that location for the integration process and its descendants.
This changes the search locations for **all** programs in that child, including
native hooks, not only Python. PATH order and duplicates are retained; an
absent PATH stays absent and an entirely empty PATH remains empty. Direct
integration dispatch preserves its existing empty-PATH subprocess fallback,
which can search the child working directory. Individual empty segments in a
nonempty PATH refer to the caller's directory. If anchoring would insert a PATH
separator into an entry, dispatch fails rather than search unintended paths.
The shell step does not use this PATH transformation. No process-global
environment or working-directory changes are made.

Base command dispatch, Copilot's override and prompt dispatch use the shared
integration environment. Base and prompt dispatch use the shared executable
lookup; Copilot retains its existing executable probe and subprocess launch.
On Windows that launch does not use the child PATH or cwd to locate the CLI,
so its selection can still differ from workflow preflight. An explicit relative
Copilot executable override remains relative to the child working directory on
POSIX. Prompt dispatch also retains its existing fallback when the integration
key is found but the executable in its argv is not.

Custom adapter `dispatch_command()` overrides starting subprocesses must use
`integration_dispatch()` as a context manager around the shared
`integration_environment()` and `dispatch_which()` helpers to obtain the same
child environment and preserve context isolation; overrides not using them and
agents started manually are outside this guarantee. Direct base dispatch captures
its own caller location. Hook files remain portable and contain no machine-specific
interpreter paths. Strict native-hook verification can still reject a hook if
the interpreter selected at installation differs from the one selected at
run time; reinstall or upgrade the integration in that environment.
2 changes: 2 additions & 0 deletions design/workflow-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Per-step `strict: true` rejects expression markers in `run` during validation
and execution. Its optional `env` mapping evaluates string templates separately,
requires NUL-free string results encodable for the process environment on
POSIX, and overrides only the child environment.
The shell step drops inherited `SPECKIT_ADDITIONAL_CONTEXT`, but an explicit
`env:` binding can set it.
`SPECKIT_WORKFLOW_DIR` remains engine-owned. This prevents workflow expression
values from becoming shell source in strict mode; it is not a sandbox or a
guarantee that an authored script handles environment data safely.
Expand Down
35 changes: 35 additions & 0 deletions docs/integrations/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,38 @@ see [runtime events](cli.md#runtime-events) for supported events and options.
- [Descriptor and catalog schemas](catalog.md)
- [Integration CLI and trust](cli.md)
- [Per-step workflow integration configuration](../workflow-steps/types.md#per-step-integration-configuration)

## Context delivery declaration

External adapters can declare `context_delivery_events = frozenset({"session_start"})`
only when their non-interactive CLI loads and fires the hook, passes the
environment through, and injects its output into the model. The event must be
mapped to a native event with a non-suppressing envelope, and
`dispatch_command` must accept and honor `additional_context`. Document trust,
authentication, or feature-flag preconditions and provide live evidence. Implement
`installed_event_handlers(project_root)` when the event format has no shared
reader; return canonical event names mapped to lists of installed handler names,
or `None` if the installation cannot be inspected. For formats with native event
filters, exclude handlers on filterable events such as `session_start` whose
filter restricts normal fresh-session dispatch (for example, a `resume`-only
matcher), reporting only unfiltered or wildcard handlers (absent, `""`, or
`"*"`). See
[the integration contract](https://github.com/github/spec-kit/blob/main/design/integration.md#context-delivery-for-command-steps).

### Subprocess search environment

Workflow command and prompt dispatch anchor relative PATH entries to the
caller directory captured at run or resume. This applies to every program
searched by the integration child and its hooks. Copilot retains its existing
executable launch: on Windows, the initial CLI lookup does not use this child
PATH; on POSIX, explicit relative executable overrides remain relative to the
child cwd. Prompt dispatch retains its existing executable fallback. An unset or
wholly empty PATH is left unchanged; direct dispatch can still search the child
working directory when PATH is empty. Dispatch fails if anchoring inserts a PATH
separator into an entry. Shell steps retain their existing environment semantics. Adapter
`dispatch_command()` overrides that start their own subprocesses should
use `specify_cli.integrations._context.integration_dispatch()` as a context
manager around `integration_environment()` and `dispatch_which()` for the
child environment and executable selection, and
must continue to isolate additional context. Overrides that do not use these
helpers, and agents started outside Spec Kit, do not receive this guarantee.
31 changes: 28 additions & 3 deletions docs/integrations/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,15 @@ Other agent-specific details are listed in the
Event-capable integrations accept `--events true|false` through the setup
`--integration-options` string; the default is enabled. Handler definitions
come from integration defaults, installed extensions, and
`.specify/integration-events.yml`. Enabling events does not create handlers
where none are configured, and an integration emits only the native events
it supports.
`.specify/integration-events.yml`. Integrations that declare context delivery
install a built-in `session_start` handler by default. Otherwise enabling
events does not create handlers where none are configured. An integration
emits only the native events it supports.

`integration install`, `switch`, and `upgrade` preflight event and dispatcher
destinations for symlink and path safety before changing files. Even with
`--events false`, an unsafe existing hook or dispatcher file that requires
cleanup is refused.

To configure project overrides, create `.specify/integration-events.yml`.
Replace `<key>` with your integration key and the example command with an
Expand Down Expand Up @@ -561,3 +567,22 @@ Use `upgrade` when you've upgraded Spec Kit and want to refresh an installed int
### Do extensions and presets I install apply to every installed integration?

No. Extensions (`specify extension add`) and presets (`specify preset add`) register their command overrides for the currently active (default) integration only, even if other integrations are installed. A non-default integration does not receive those artifacts until it becomes the default: `specify integration use <key>` (or `switch <key>`) rescaffolds every enabled extension and preset for the newly active integration. `specify integration upgrade` follows the same rule — it only re-registers extensions and presets when upgrading the active integration.

### PATH during workflow dispatch

When Spec Kit launches an integration for a command or prompt step, relative
PATH entries are anchored to the directory from which the workflow was run or
resumed. This affects lookup of tools in the integration process and its hooks.
Copilot retains its existing CLI launch behavior: on Windows, the initial CLI
lookup does not use this child PATH; on POSIX, explicit relative executable
overrides remain relative to the child working directory. Prompt steps retain
their existing executable fallback. An unset PATH remains unset; an entirely
empty PATH stays empty. With an empty PATH, a shell or a direct integration dispatch may still search its child
working directory, so that case is not stabilized. If anchoring a relative
entry would insert a PATH separator into that entry (for example, `:` in a
POSIX caller directory), dispatch fails rather than search unintended paths;
use absolute entries or start from a directory without that separator.
Shell steps and manually started agents are unchanged. Custom adapters that start
subprocesses without the shared dispatch helpers are not covered. A native
hook whose interpreter selection changed since installation can still fail
strict verification; upgrade the integration in the current environment.
27 changes: 26 additions & 1 deletion docs/integrations/copilot.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ specify init my-project --integration copilot
For an existing Spec Kit project, use `specify integration install copilot`.
See [integration management](cli.md) for activation, upgrades, and removal.

## Additional Context and Folder Trust

Copilot CLI loads repository hooks in `-p` mode only in a trusted folder.
Trust the folder through Copilot's trust prompt or `trustedFolders` in
`~/.copilot/config.json`, or use `--trust-folder` for a single run.
Comment on lines +23 to +24
`COPILOT_ALLOW_ALL=true` also trusts the folder but approves all tools. In an
untrusted folder Copilot skips hooks, drops additional context, and still exits
successfully. Spec Kit does not add trust flags automatically.

Spec Kit does not write hooks through a symlinked `.github/hooks` directory or
a symlinked `.specify/events.py` dispatcher. When Copilot hooks are configured,
`init` fails there, and `integration install`, `switch`, and `upgrade` refuse
before changing project files. Use `--integration-options="--events false"` to
opt out of `additional_context` delivery and extension event hooks. This allows
a symlinked `.github/hooks` directory only when no existing `speckit.json`
target exists there to inspect (regardless of ownership), and allows a
symlinked `.specify/events.py` only when cleanup would skip it (for example,
when it is unowned or another installed integration still references it).

If `.github/hooks/speckit.json` cannot be read as a JSON object, upgrade
preserves it rather than overwriting it. Fix the file or move it aside, then
run `specify integration upgrade copilot` to restore context delivery.

## Default Skills Layout

Skills are installed as `.github/skills/speckit-<command>/SKILL.md`.
Expand Down Expand Up @@ -102,7 +125,9 @@ a newly created settings file is manifest-tracked.

## Runtime Events and Workflow Permissions

Native events use `.github/hooks/speckit.json`.
With events enabled, Copilot projects get `.specify/events.py` and
`.github/hooks/speckit.json` by default, including a built-in `session_start`
handler for additional context.
`--integration-options="--events false"` disables Spec Kit event handlers.
See [runtime events](cli.md#runtime-events).

Expand Down
Loading