Skip to content

feat(workflows): add additional_context to command steps - #5616

Open
markuswondrak wants to merge 15 commits into
github:mainfrom
markuswondrak:feat/5533-command-additional-context
Open

markuswondrak wants to merge 15 commits into
github:mainfrom
markuswondrak:feat/5533-command-additional-context

Conversation

@markuswondrak

@markuswondrak markuswondrak commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part of #5533. See the addendum on the issue for the updated decisions. These PRs are stacked:

  1. This PR: the additional_context framework. No built-in integration declares delivery here, per the integration delivery boundary. This is deliberate: Copilot's declaration was split out into feat(copilot): declare additional_context delivery #5621 after review (r4732278577).
  2. feat(copilot): declare additional_context delivery #5621: Copilot declaration (stacked on this PR).
  3. feat(agy): deliver session_start context through Antigravity hooks #5617: agy event support and declaration (stacked on feat(copilot): declare additional_context delivery #5621).
  4. feat(pi): deliver session_start context through a pi extension #5623: pi event support and declaration (stacked on feat(agy): deliver session_start context through Antigravity hooks #5617).

A command step can now carry additional_context, which the agent receives as model context once per session_start. $ARGUMENTS, the prompt, and the installed command templates are unchanged.

- id: plan
  command: speckit.plan
  integration: copilot   # once an integration declares support (#5621)
  additional_context: "{{ inputs.background }}"

With this PR alone, no built-in integration declares support, so a step that sets additional_context fails before the CLI starts with … context delivery is not declared. Supporting integrations: none. No integration installs the built-in handler, so init and upgrade output is unchanged for users.

What changes

Area Change
Step CommandStep validates literals in validate() and expression results in execute(): string only, no NUL, encodable on POSIX, at most 16,384 UTF-8 bytes. null and "" mean unset. A failed expression fails the step with a message that does not include the value, so continue_on_error applies. The value is recorded in output.additional_context and never written to log.jsonl. Errors report only type or length.
Transport dispatch_command(..., additional_context=) in IntegrationBase and in CopilotIntegration's override, on all three subprocess paths. run_captured and _ProcessTree take env. Child environment helpers remove an inherited SPECKIT_ADDITIONAL_CONTEXT (case-insensitively on Windows) and set the requested value only for the child. Prompt and shell steps also clear inherited context; explicit shell env: bindings still apply.
Dispatch PATH Command and prompt dispatch anchor relative PATH entries to the calling directory in the child environment, keeping the parent environment unchanged. An entirely empty PATH and shell-step PATH behavior are unchanged. Existing Copilot executable-selection behavior remains unchanged.
Delivery The reserved handler __speckit_additional_context__ is handled in the generated .specify/events.py after the capped stdin read and before importing specify_cli, so a stale global install cannot drop it. resolve_and_run_event_command handles it too. Output goes through the existing envelopes plus injectSteps. EVENT_CONTEXT_ENVELOPES advertises supported envelopes; when an older confinement-safe specify_cli lacks the requested envelope, the generated dispatcher runs resolve_and_run_event_command(..., envelope="plain") with stdout capture and wraps the output locally via _emit(), preserving bundled-template lookup.
Named format & config cwd Adds the json-named event format (reserving __speckit_event__ while preserving user definitions) with _read_json_named_handlers, and IntegrationBase.events_cwd_is_config_dir so dispatcher and project-relative venv interpreter paths render relative to the config directory. Tested independently with FakeNamedIntegration in tests/specify_cli/events/test_json_named.py.
Support Explicit opt-in through IntegrationBase.context_delivery_events. Effective support also requires a session_start mapping, a supported non-suppressing envelope (including plain output), and a dispatch_command that accepts the keyword (supports_context_delivery). Declaring integrations get the built-in handler in resolve_events layer 2.
Installed-hook check IntegrationBase.installed_event_handlers(project_root) is the read counterpart of emit_events/remove_events. It dispatches by events_format to per-format readers, which arrive with each declaring integration (plus json-named here). Commands must match _dispatcher_command for the integration, project, and target, including the interpreter and native event. .specify/events.py must exactly match the current template (LF or CRLF, the same comparison as dispatcher cleanup).
Pre-flight context_delivery_error() runs before executable detection and gives one reason per failure: not declared, mapping contradicts the declaration, keyword not accepted, no project root, unreadable state, not installed, --events false, override without the handler, handlers unreadable, missing or outdated files. Remedies use integration status wording: fix or delete .specify/integration.json, specify integration install <key>, and upgrade only for missing or outdated event files.
Event lifecycle Event config writes accept linked ancestors above the project root; symlinks at or below the root are still rejected, using the manifest path validation. Removing a native hook file prunes the directories it leaves empty, using the prune loop extracted from manifest uninstall. Both are pre-existing gaps, reproducible on main with extension-provided events.
Docs docs/workflow-steps/types.md: the new section, an override example, the support list (checked against the registry by a test), and the plain-text state warning. docs/integrations/cli.md: the default handler. design/integration.md and docs/integrations/api.md: the declaration, json-named, events_cwd_is_config_dir, and reader contract. dispatch_command docstring.

The from_json filter now normalizes excessive-nesting RecursionError to ValueError for all workflow expressions, not only additional_context.

Known follow-up for the stack: the strict command comparison re-resolves a host-target interpreter at preflight. If a valid hook was installed with python3 and a project .venv is added later, the old hook can still run but will no longer match.

Review update at d3f26104

  • Named-hook preflight reads through deny-mode FileHelper; linked files and ancestors are rejected. Malformed or unreadable configuration receives the existing repair-or-move-aside guidance; missing configuration retains the upgrade hint.
  • Shared dispatch stabilizes relative PATH entries for Spec Kit-launched integrations. It does not change os.environ, shell steps, or an entirely empty PATH. Manually started agents and external overrides that do not use the shared environment helper are outside this guarantee; interpreter fallback remains tracked in [Feature]: Portable interpreter fallback and interpreter check for generated event hooks #5619.
  • Test fixtures restore fake integration caches, preventing test-order pollution.
  • On this head: 6,029 passed, 20 skipped on Linux/Python 3.14; Ruff and Markdownlint passed. The linked-file/parent, malformed-configuration, relative-PATH, and test-order regressions were shown failing before and passing after. Native Windows and Windows PowerShell 5.1 validation remain pending.

Testing

The full suite ran in this checkout's .venv:

  • .venv/bin/python -m pytest -q -n 4: 17,407 passed, 676 skipped (Python 3.14, Linux).
  • uvx ruff@0.15.0 check src tests: passed. npx --yes markdownlint-cli2@0.21.0 docs/integrations/api.md: passed.
  • Python 3.11: seven focused JSON tests passed in a temporary environment with this checkout on PYTHONPATH. A real deeply nested JSON input aborted the workflow before the fix and returned a failed step while continuing after it.
  • DocFX 2.81.0: the integration-contract link emitted an InvalidFileLink warning before the fix and renders as the absolute GitHub URL afterward. Two unrelated warnings remained in the temporary build (a missing generated preset directory and an OMP link).
  • Positive and negative coverage, against fake declaring integrations (tests/fixtures/context_delivery.py and FakeNamedIntegration in tests/specify_cli/events/test_json_named.py), for:
    • validation
    • transport: every path, inherited-value removal in dispatch, prompt, and shell, and os.environ unchanged
    • the predicate and declaration consistency
    • layer-2 resolution and overrides
    • every pre-flight reason
    • the reader contract and command round-trip parsing (POSIX and PowerShell)
    • handler envelopes (including injectSteps) on both dispatcher paths, stdin drain, and a stale specify_cli (preserving bundled-template lookup via envelope="plain" capture + _emit)
    • json-named merge, removal, empty-parent pruning, malformed JSON preservation, config-directory-relative paths, and deleted-.venv rejection
    • fan-out isolation, resume, recording, and the docs list
  • On 049bd4d9: 402 tests across tests/specify_cli/events/, tests/integrations/test_context.py, and tests/specify_cli/integrations/test_preflight_setup.py, plus 60 tests across tests/test_agent_config_consistency.py and tests/workflows/test_command_additional_context.py, and ruff check on touched files all passed.
  • Tests that fail before the fix and pass after it:
    • prompt- and shell-step inheritance
    • the linked-parent event writes
    • empty-directory pruning
    • the reserved handler's stdin guard
    • value-free expression failures
    • the repair hints
    • a modified dispatcher that only contains the handler name
    • stale specify_cli delegation with envelope="plain" capture for injectSteps when .specify/templates/commands/ is absent
  • specify init --integration copilot writes neither .github/hooks/speckit.json nor .specify/events.py; the behavior is unchanged until feat(copilot): declare additional_context delivery #5621.

Live agent evidence comes with each declaration PR: Copilot in #5621, agy in #5617, pi in #5623.

Not run: Windows PowerShell 5.1, because no Windows host was available. No PowerShell scripts or generated PowerShell commands change. The Windows case-insensitive removal and PowerShell command parsing are covered by unit tests.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Opened on behalf of @markuswondrak by the pi coding agent.

  • Planning, review, live runs, and this PR text: pi with model claude-opus-5.5 (github-copilot, reasoning effort xhigh), interactive and human-supervised. @markuswondrak made each design and review decision.

  • Code, tests, and docs: written autonomously by a pi subagent with model gpt-6.1-terra (github-copilot, reasoning effort high), then reviewed by the supervising agent.

  • Review-round 3: pi with model gpt-6.1-terra (github-copilot, reasoning effort xhigh), interactive and human-directed, reviewed existing local changes, added timeout regression handling and the documentation-link fix, ran checks, and prepared the commit and PR update. The existing uncommitted changes predated this session.

  • FileHelper migration fix (2b0aab1c): GitHub Copilot CLI (gemini-4-carbon, human-directed) planned, reviewed, and refined the FileHelper boundary migration implemented by a delegated gpt-6.1-terra (high reasoning effort) subagent, ran local validation, and updated this PR.

  • Review round 6 (251e44af): GitHub Copilot CLI (gemini-4-carbon, interactive and human-directed, with an autonomous code-review subagent check) implemented FileHelper.rmdir(path), updated _prune_empty_parents() and design/file-helper.md, ran regression and lint checks, and posted the round-6 update.

  • Shared event additions & stale-CLI fallback (049bd4d9): Antigravity (Gemini 4 Hydrogen, autonomous implementation after human-supervised review decisions with @markuswondrak) moved the shared json-named, events_cwd_is_config_dir, injectSteps, and EVENT_CONTEXT_ENVELOPES framework changes from feat(agy): deliver session_start context through Antigravity hooks #5617 into this PR with FakeNamedIntegration tests, preserved bundled-template delegation via envelope="plain" capture for older specify_cli installs, and added the deleted-.venv regression test.

  • PATH and reader review update (d3f26104): pi coding agent (gpt-6.1-terra via GitHub Copilot; reasoning effort not supplied; interactive, human-directed) investigated, tested, and updated the PR. A pi worker (gpt-6.1-terra, high reasoning, autonomous) implemented PATH handling; pi reviewers (gpt-6.2-sol and gemini-4-carbon, high reasoning, autonomous) reviewed implementation and plan. The human chose the scope and behavior.

The change was not reviewed line by line by a human.

A command step can now carry additional_context, a string (literal or
expression) that the dispatched agent receives as model context once per
session_start, without changing $ARGUMENTS, the prompt, or the installed
command templates (github#5533).

- Transport: the value is passed only to the child process in
  SPECKIT_ADDITIONAL_CONTEXT. Every dispatch removes an inherited value
  first (base and Copilot dispatch_command, and prompt steps), so nested
  runs cannot leak context. os.environ is never changed.
- Delivery: a reserved built-in session_start handler emits the value
  through the integration's existing envelope. The generated events.py
  handles it before importing specify_cli, so a stale global install
  cannot drop it.
- Support is an explicit opt-in: context_delivery_events on the
  integration, effective only with a session_start mapping, an envelope
  other than suppress, and a dispatch_command that accepts the keyword.
  Copilot declares it. Declaring integrations install the built-in
  handler by default.
- The step fails before the CLI starts when the value is invalid (type,
  NUL, encoding, more than 16,384 UTF-8 bytes) or the integration cannot
  deliver it (not declared, events disabled, handler overridden, hooks
  missing or outdated). Errors never include the text.
- Event lifecycle: event config writes accept linked ancestors above the
  project root (symlinks inside the project are still rejected), and
  removing a native hook file prunes the directories it leaves empty.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved defects can overwrite user-owned dispatchers and leak inherited context into nested sessions, while locale-dependent I/O breaks context-delivery tests on Windows.

11 open issues
What changed in this PR

Adds optional additional_context to workflow command steps, introducing shared context-delivery support with Copilot as the first supported integration while preserving command arguments and templates.

Changes:

  • Add context validation, state recording, child-scoped environment transport, and preflight checks.
  • Install a reserved startup-event handler and update event-file validation and cleanup.
  • Expand tests and document delivery capabilities, configuration, and Copilot folder-trust requirements.
File Description
tests/​workflows/​test_step_capture.py Tests prompt environment isolation.
tests/​workflows/​test_command_additional_context.py Covers validation, dispatch, concurrency, resume, and recording.
tests/​specify_cli/​events/​test_events.py Adds path-safety and directory-cleanup regressions.
tests/​specify_cli/​events/​test_context_delivery.py Tests envelopes, capabilities, resolution, and installation checks.
tests/​integrations/​test_integration_copilot.py Updates expected installed hook files.
tests/​integrations/​test_context.py Tests child-environment transport across dispatch paths.
tests/​integrations/​test_capture.py Updates the process-tree test double.
src/​specify_cli/​workflows/​step/​shell/​__init__.py Reuses shared environment-value validation.
src/​specify_cli/​workflows/​step/​prompt/​__init__.py Clears inherited command context before dispatch.
src/​specify_cli/​workflows/​step/​command/​__init__.py Evaluates, validates, records, and forwards context.
src/​specify_cli/​workflows/​step/​_env_values.py Centralizes environment-value validation.
src/​specify_cli/​integrations/​manifest.py Extracts guarded empty-directory pruning.
src/​specify_cli/​integrations/​copilot/​__init__.py Declares context support and forwards child environments.
src/​specify_cli/​integrations/​base.py Adds the capability predicate and dispatch keyword.
src/​specify_cli/​integrations/​_context.py Builds isolated child environments.
src/​specify_cli/​integrations/​_capture.py Passes explicit environments through bounded capture.
src/​specify_cli/​events/​__init__.py Adds context handling, preflight checks, and lifecycle updates.
docs/​workflow-steps/​types.md Documents command context and support requirements.
docs/​integrations/​copilot.md Explains the folder-trust precondition.
docs/​integrations/​cli.md Documents the default startup handler.
docs/​integrations/​api.md Describes external-adapter context declarations.
design/​integration.md Defines context-delivery and isolation contracts.

Review effort: Max (adaptive)

Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/integrations/base.py Resolved
Make this PR framework-only, per the integration delivery boundary in
design/integration.md: no built-in integration declares context
delivery here. Copilot keeps the additional_context transport in its
dispatch_command override, and its declaration, trust docs, and init
inventory move to a stacked follow-up PR. Tests use a fake declaring
integration.

- Installed-hook check: integrations report their installed handlers
  through installed_event_handlers(), the read counterpart of
  emit_events/remove_events. The default dispatches by events_format to
  per-format readers, which arrive with each declaring integration.
  Commands are parsed back only when they round-trip through
  _dispatcher_command. .specify/events.py must exactly match the
  current template (LF or CRLF), reusing the cleanup comparison. This
  replaces the substring checks.
- Capability hints: an unreadable state says to fix or delete
  .specify/integration.json, and a missing integration says to run
  'specify integration install', using the wording from integration
  status. Upgrade is suggested only for missing or outdated event files.
- Shell steps start from dispatch_environment(None), so a nested run
  does not pass on an inherited SPECKIT_ADDITIONAL_CONTEXT; explicit
  env bindings still apply.
- A failed additional_context expression fails the step with a message
  that does not include the value, so continue_on_error applies.
- Document the additional_context contract on dispatch_command, and use
  UTF-8 explicitly in the context-delivery tests.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 18:11
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review round 1 is addressed in ece26d61.

Changed:

  • Framework only: Copilot's declaration, trust docs, and init inventory moved to feat(copilot): declare additional_context delivery #5621, per the integration delivery boundary. Tests use a fake declaring integration.
  • Installed-hook check: added IntegrationBase.installed_event_handlers() with per-format readers that arrive with each declaring integration, round-trip command parsing, and an exact match of events.py against the current template. This replaces the substring checks.
  • Repair hints use the integration status wording: unreadable state says to fix or delete .specify/integration.json, and a missing integration says to run specify integration install.
  • Shell steps start from dispatch_environment(None).
  • A failed additional_context expression fails the step with a value-free message.
  • dispatch_command docstring.
  • UTF-8 in the context-delivery tests.

Deferred:

Dismissed:

  • Journaling of empty-directory removal. Pre-existing in manifest uninstall, which this PR only reuses.

Full suite: 17,381 passed, 676 skipped (Linux). Windows PowerShell 5.1 not run.

AI disclosure: Posted on behalf of @markuswondrak by the pi coding agent (provider github-copilot, model claude-opus-5.5, reasoning effort xhigh, interactive and human-supervised). @markuswondrak decided each disposition. The fixes were written by a pi subagent (model gpt-6.1-terra, reasoning effort high, autonomous) and reviewed by the supervising agent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread docs/workflow-steps/types.md Resolved
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 29, 2026
Add session_start runtime event support to the agy integration and
declare context delivery, so workflow command steps with
additional_context work with Antigravity (github#5533, stacked on github#5616).

- Native config: .agents/hooks.json in a new json-named format. Spec Kit
  owns only the reserved __speckit_event__ definition; merge replaces
  it, removal deletes it, and user definitions are kept.
- agy runs workspace hooks from the hooks file's directory. The new
  events_cwd_is_config_dir attribute renders the dispatcher and a
  project-relative interpreter relative to that directory.
- New injectSteps envelope in both dispatcher output paths; empty output
  writes nothing.
- agy declares context_delivery_events = {session_start}.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
- Restore main's order in _remove_native_event_hooks: an absent native
  config returns before the destination check, so a symlinked hook
  directory without a Spec Kit config is a no-op again. An existing
  config is still validated before it is read or removed.
- Document that shell steps drop an inherited SPECKIT_ADDITIONAL_CONTEXT
  unless an explicit env binding sets it.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Validation gaps accept hook commands that do not run the dispatcher and unsupported context envelopes, while uncaught JSON nesting errors can abort workflows despite continue_on_error.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Validate the full dispatcher command and event

src/​specify_cli/​events/​__init__.py:1470

Replacing the interpreter with echo still parses as the installed context handler, even though the hook no longer runs the dispatcher. The same check accepts a wrong native event for hookSpecificOutput and discards that argument from its result. Validate the complete command against _dispatcher_command for the integration, project and target shell, and add negative reader tests for these changes.

AI-generated review by GitHub Copilot (model unknown; automated) for the requesting reviewer.

High severity Reject unsupported context envelopes during validation

src/​specify_cli/​integrations/​base.py:224

A declaring adapter with an unknown envelope such as additionalcontext passes this predicate, but the dispatcher falls back to plain text, which a JSON-only hook protocol cannot use as context. Validate envelope names against the dispatcher's supported formats while retaining None and plain for plain-output adapters. Apply the same validation in context_delivery_error() so preflight rejects the invalid declaration too.

AI-generated review by GitHub Copilot (model unknown; automated) for the requesting reviewer.

Medium severity Handle RecursionError from deeply nested JSON

src/​specify_cli/​workflows/​step/​command/​__init__.py:161

On supported Python versions, {{ inputs.ctx | from_json }} can raise RecursionError for a deeply nested JSON string, rather than ValueError (see _safe_json_load in the workflow engine). That exception escapes this handler, aborts the whole run and bypasses continue_on_error, contrary to design/workflow-step.md's “Step contract”. Catch excessive-nesting failures here as well and return the same value-free failure.

AI-generated review by GitHub Copilot (model unknown; automated) for the requesting reviewer.

10 resolved since last review

Review effort: Max (adaptive)

markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 30, 2026
Declare session_start context delivery for GitHub Copilot, so workflow
command steps with additional_context work with Copilot (github#5533, stacked
on github#5616).

- CopilotIntegration.context_delivery_events = {session_start}. With
  events enabled, Copilot projects now get .specify/events.py and
  .github/hooks/speckit.json with the built-in session_start handler by
  default.
- New copilot-json installed-handler reader: only Spec Kit-marked
  entries, mapped through CANONICAL_TO_NATIVE, using the current
  platform's command field (bash or powershell), and only when the
  parsed event and envelope match what Spec Kit renders.
- Docs: Copilot folder-trust precondition (hooks load in -p mode only
  in a trusted folder; untrusted runs drop the context and still exit
  0; Spec Kit adds no trust flags), default event files, and the
  support table entry.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 30, 2026
Add session_start runtime event support to the agy integration and
declare context delivery, so workflow command steps with
additional_context work with Antigravity (github#5533, stacked on github#5616).

- Native config: .agents/hooks.json in a new json-named format. Spec Kit
  owns only the reserved __speckit_event__ definition; merge replaces
  it, removal deletes it, and user definitions are kept.
- agy runs workspace hooks from the hooks file's directory. The new
  events_cwd_is_config_dir attribute renders the dispatcher and a
  project-relative interpreter relative to that directory.
- New injectSteps envelope in both dispatcher output paths; empty output
  writes nothing.
- agy declares context_delivery_events = {session_start}.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review round 2 is addressed in feca1cbf.

Changed:

  • Native hook removal checks that the config exists before it validates the destination again, as on main. A symlinked hook directory without a Spec Kit config is a no-op again, while an existing config behind a symlink is still refused before it is read or removed (r4732590468).
  • Shell-step docs now say that an inherited SPECKIT_ADDITIONAL_CONTEXT is dropped unless an explicit env: binding sets it (r4732590492).
  • The description now states the framework-only split explicitly (r4732590479).

Deferred:

Dismissed, with reasons in the threads:

  • A raw_options-only setting with invalid options (r4732590437). Not produced by Spec Kit, and the same state already fails on main.
  • A reserved handler configured twice (r4732590452). Same as main for every handler.

Full suite: 17,390 passed, 676 skipped (Linux). Windows PowerShell 5.1 not run. The stacked PRs #5621, #5617, and #5623 are rebased onto this commit.

AI disclosure: Posted on behalf of @markuswondrak by the pi coding agent (provider github-copilot, model claude-opus-5.5, reasoning effort xhigh, interactive and human-supervised). @markuswondrak decided each disposition. The fixes were written by a pi subagent (model gpt-6.1-terra, reasoning effort high, autonomous) and reviewed by the supervising agent.

@mnriem mnriem added the triage-nice-to-have Verdict: evidence-backed fix or greenlit feature — land after review label Nov 30, 2026
@markuswondrak
markuswondrak requested an adaptive review from Copilot November 30, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Command validation accepts a substituted executable, allowing context preflight to pass even when the hook never runs events.py or delivers context.

2 open issues

Review effort: Max (adaptive)

Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread docs/integrations/api.md Resolved
…rents

Address PR github#5616 review round 6 (r4770693310):

- Add FileHelper.rmdir(path) to remove empty directories using the
  helper's retained-root and anchored-parent machinery while enforcing
  directory-only removal at mutation time (descriptor-relative os.rmdir
  on POSIX and opened-handle directory validation before _windows_delete
  on Windows), never unlinking regular files or leaf symlinks.
- Document FileHelper.rmdir(path) in design/file-helper.md.
- Switch _prune_empty_parents() in integrations/manifest.py from
  directory_exists() + delete(..., recursive=False) to rmdir() so a
  concurrent directory-to-file replacement is preserved.
- Add unit, portable Windows handle, and replacement-race regression
  tests in test_file_helper.py and test_manifest.py.

Assisted-by: GitHub Copilot CLI (model: Gemini 4 Carbon, autonomous)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 15:13
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review round 6 is addressed in 251e44af.

Changed:

  • Added FileHelper.rmdir(path) in src/specify_cli/file_helper.py (and documented it in design/file-helper.md) using the helper's retained-root and anchored-parent machinery while enforcing directory-only removal at mutation time: descriptor-relative os.rmdir on POSIX and opened-handle directory validation before _windows_delete on Windows, rejecting regular files with NotADirectoryError, denied links with SymlinkDeniedError, and allowed leaf links with NotADirectoryError without unlinking or following them.
  • Updated _prune_empty_parents() in src/specify_cli/integrations/manifest.py to call files.rmdir(relative) directly so a concurrent replacement with a regular file or symlink is preserved and stops parent cleanup (r4770693310).
  • Added unit, portable Windows handle, and mutation-time replacement-race regression tests in tests/test_file_helper.py and tests/integrations/test_manifest.py.

Verification (Linux, Python 3.11):

  • Reproduced TestPruneEmptyParents::test_preserves_directory_replaced_before_removal[file] failing on 2b0aab1c before the fix and passing on 251e44af.
  • pytest tests/integrations/test_manifest.py tests/test_file_helper.py tests/contract/test_file_helper_migration_guard.py: 708 passed, 115 skipped.
  • pytest -n auto tests/specify_cli/events/ tests/specify_cli/integrations/ tests/workflows/test_command_additional_context.py: 1,683 passed.
  • ruff check src tests and .github/scripts/check_file_helper_migration.py (against both merge-base and simulated origin/main merge commit) passed with 0 issues.
  • Windows PowerShell 5.1 was not run; generated PowerShell commands did not change.

AI disclosure: Posted on behalf of @markuswondrak by GitHub Copilot CLI (model Gemini 4 Carbon, interactive and human-directed; diff checked with an autonomous code-review subagent). The agent implemented and tested the fix, updated the PR, and drafted this comment; no line-by-line human review of the diff is claimed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change couples workflow evaluation, subprocess isolation, hook verification, and cross-platform cleanup, requiring broader review of interacting runtime and lifecycle contracts.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Dec 2, 2026
Declare session_start context delivery for GitHub Copilot, so workflow
command steps with additional_context work with Copilot (github#5533, stacked
on github#5616).

- CopilotIntegration.context_delivery_events = {session_start}. With
  events enabled, Copilot projects now get .specify/events.py and
  .github/hooks/speckit.json with the built-in session_start handler by
  default.
- New copilot-json installed-handler reader: only Spec Kit-marked
  entries, mapped through CANONICAL_TO_NATIVE, using the current
  platform's command field (bash or powershell), and only when the
  parsed event and envelope match what Spec Kit renders.
- Docs: Copilot folder-trust precondition (hooks load in -p mode only
  in a trusted folder; untrusted runs drop the context and still exit
  0; Spec Kit adds no trust flags), default event files, and the
  support table entry.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
When a registered reader cannot inspect its declared configuration, name the file and explain how to repair it before upgrading. Keep the existing diagnostic for integrations without a readable format.

Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Dec 2, 2026
Declare session_start context delivery for GitHub Copilot, so workflow
command steps with additional_context work with Copilot (github#5533, stacked
on github#5616).

- CopilotIntegration.context_delivery_events = {session_start}. With
  events enabled, Copilot projects now get .specify/events.py and
  .github/hooks/speckit.json with the built-in session_start handler by
  default.
- New copilot-json installed-handler reader: only Spec Kit-marked
  entries, mapped through CANONICAL_TO_NATIVE, using the current
  platform's command field (bash or powershell), and only when the
  parsed event and envelope match what Spec Kit renders.
- Docs: Copilot folder-trust precondition (hooks load in -p mode only
  in a trusted folder; untrusted runs drop the context and still exit
  0; Spec Kit adds no trust flags), default event files, and the
  support table entry.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
Copilot AI balanced review requested due to automatic review settings December 2, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting changes to workflow validation, subprocess isolation, hook verification, and cross-platform cleanup require broader review of runtime and lifecycle effects.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting changes to workflow validation, subprocess environments, hook lifecycle, and cross-platform directory deletion exceed the scope of a limited-consequence review.

No open issues 🎉

Review effort: Balanced

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Copilot AI balanced review requested due to automatic review settings December 5, 2026 07:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Coupled workflow evaluation, subprocess isolation, hook verification, and POSIX/Windows directory cleanup cross runtime and ownership boundaries beyond the limited-consequence automated-approval scope.

No open issues 🎉

Review effort: Balanced

…CLI fallback

Move shared event framework additions (json-named native config format, events_cwd_is_config_dir relative path rebasing, injectSteps envelope, and EVENT_CONTEXT_ENVELOPES delegation gate) into the context-delivery framework PR with agy-independent tests.

Keep delegating to importable confinement-safe specify_cli packages with envelope='plain' and wrap captured stdout in the requested envelope when an older package lacks the envelope, preserving bundled-template resolution. Add a removed-venv regression test for json-named handlers.

Assisted-by: Antigravity (model: Gemini 4 Hydrogen, autonomous)
Copilot AI balanced review requested due to automatic review settings December 5, 2026 09:30
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Moved the shared event framework additions (json-named, events_cwd_is_config_dir, injectSteps, and EVENT_CONTEXT_ENVELOPES) from #5617 into this PR in commit 049bd4d9, per the integration delivery boundary review feedback on #5617:

  • src/specify_cli/integrations/base.py: events_cwd_is_config_dir and injectSteps envelope documentation.
  • src/specify_cli/events/__init__.py: json-named install/removal/handler-reader support, config-directory-relative path rebasing, injectSteps in CONTEXT_DELIVERY_ENVELOPES / _emit / _emit_event_stdout, and EVENT_CONTEXT_ENVELOPES. When an importable specify_cli passes EVENT_SCRIPT_PATH_CONFINEMENT but lacks the requested envelope, _EVENTS_DISPATCHER_TEMPLATE now invokes resolve_and_run_event_command(..., envelope="plain") with stdout capture and wraps the output locally via _emit(), preserving bundled-template lookup.
  • design/integration.md: json-named and events_cwd_is_config_dir contract.
  • tests/specify_cli/events/test_json_named.py & tests/specify_cli/events/test_context_delivery.py: added FakeNamedIntegration coverage (independent of agy), stale-CLI bundled-template regression tests (failed before fix, passed after), and a deleted-.venv regression test.

Verification on 049bd4d9: 402 tests (tests/specify_cli/events/, tests/integrations/test_context.py, tests/specify_cli/integrations/test_preflight_setup.py), 60 tests (tests/test_agent_config_consistency.py, tests/workflows/test_command_additional_context.py), and ruff check on the modified files all passed.

AI disclosure: Posted on behalf of @markuswondrak by Antigravity (model: Gemini 4 Hydrogen, interactive human-supervised decisions with @markuswondrak / autonomous code and test edits). The change was not reviewed line by line by a human.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting workflow, subprocess-isolation, hook-lifecycle, and cleanup contracts exceed the limited review scope, while Windows handle-based deletion requires native filesystem review beyond portable mocks.

No open issues 🎉

Review effort: Balanced

Markus added 3 commits December 5, 2026 15:10
Read installed named hook definitions with FileHelper in deny mode. Reject symlinked files and ancestors, and distinguish malformed or unreadable configs from missing hooks so preflight suggests a repair that can work.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Capture the calling directory for workflow dispatch and normalize relative PATH entries in integration child environments without mutating the parent environment. Preserve shell-step and empty-PATH behavior, existing Copilot lookup semantics, and context isolation. Add real-subprocess and portable Windows regressions; native Windows validation remains pending.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
Remove test-only integrations before refreshing derived agent caches so event and dispatch tests do not leak fake agents into later tests. The previously failing test-order regressions now pass.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Copilot AI balanced review requested due to automatic review settings December 5, 2026 14:18
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review update at d3f26104:

  • Named-hook preflight rejects linked files and parents and returns repair guidance for unreadable configuration.
  • Shared command/prompt dispatch stabilizes caller-relative PATH entries in child environments; shell steps and an entirely empty PATH retain their existing behavior. Fake-integration fixtures now restore derived caches.
  • The existing host-interpreter comparison after a .venv change remains a known follow-up. Interpreter fallback remains [Feature]: Portable interpreter fallback and interpreter check for generated event hooks #5619; manually started agents and custom overrides that bypass the shared environment helper are outside this update.

Validation: 6,029 passed, 20 skipped on Linux/Python 3.14; Ruff and Markdownlint passed. The new symlink, malformed-config, relative-PATH and test-order regressions failed before and pass after. Native Windows and Windows PowerShell 5.1 tests have not run.

AI disclosure: Written and posted for @markuswondrak by the pi coding agent (gpt-6.1-terra via GitHub Copilot, reasoning effort not supplied, autonomous after human-directed decisions). A pi worker (gpt-6.1-terra, high, autonomous) implemented PATH handling; pi reviewers (gpt-6.2-sol and gemini-4-carbon, high, autonomous) reviewed implementation and plan. No human line-by-line review is claimed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Executable lookup, PATH inheritance, nested/concurrent workflows, hook verification, and lifecycle cleanup create interacting cross-platform contracts that need human review, especially with native Windows behavior unvalidated.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

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

Labels

triage-nice-to-have Verdict: evidence-backed fix or greenlit feature — land after review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants