Skip to content

feat(agy): deliver session_start context through Antigravity hooks - #5617

Open
markuswondrak wants to merge 21 commits into
github:mainfrom
markuswondrak:feat/5533-agy-context-delivery
Open

markuswondrak wants to merge 21 commits into
github:mainfrom
markuswondrak:feat/5533-agy-context-delivery

Conversation

@markuswondrak

@markuswondrak markuswondrak commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part of #5533. Stacked: #5616 (framework) ← #5621 (Copilot) ← this PR ← #5623 (pi).

Depends on #5621, which depends on #5616. Stacked on #5616 (d3f26104) and #5621 (4e6c73f2). After the predecessors merge, this PR will be rebased onto main.

This PR adds session_start runtime event support to the agy (Antigravity) integration and declares context delivery, so workflow command steps with additional_context work with agy.

The shared event framework additions (json-named, events_cwd_is_config_dir, injectSteps, and EVENT_CONTEXT_ENVELOPES with its stale-CLI fallback) have been moved into #5616 (049bd4d9) per the integration delivery boundary feedback. This PR now contains only agy-specific integration changes, docs, and tests (fb72c77e on top of 4e6c73f2):

Area Change
agy integration Adds CANONICAL_TO_NATIVE = {"session_start": "SessionStart"}, events_config_file = ".agents/hooks.json", events_format = "json-named", events_cwd_is_config_dir = True, events_context_envelope = {"session_start": "injectSteps"}, and context_delivery_events = frozenset({"session_start"}). agy inherits the base dispatch_command, which already accepts additional_context.
Docs docs/integrations/agy.md (runtime events, preconditions, symlink refusal across init / integration install / switch / upgrade), docs/integrations/cli.md, and the support table in docs/workflow-steps/types.md.
Tests tests/integrations/test_integration_agy.py (init inventory, --events false, upgrade/uninstall preserving user hooks, symlink preflight across install / switch / upgrade, deleted-.venv context-delivery rejection) and "agy, copilot" expectation in tests/specify_cli/events/test_context_delivery.py.

Generated .agents/hooks.json after specify init --integration agy:

{
  "__speckit_event__": {
    "SessionStart": [
      {
        "type": "command",
        "command": "python3 ../.specify/events.py __speckit_additional_context__ session_start 60 injectSteps",
        "timeout": 65
      }
    ]
  }
}

Review update at fb72c77e

  • The prerequisite feat(workflows): add additional_context to command steps #5616 rejects linked named-hook files and parent directories during preflight (r4810315461) and gives repair guidance for malformed or unreadable named configuration (r4809891420).
  • For Specify-launched integrations, feat(workflows): add additional_context to command steps #5616 anchors relative PATH entries to the invoking directory, including when agy runs hooks from .agents (r4810315486). Limitation: manually started agy sessions do not receive that normalized environment, so their hooks can still fail with a relative PATH; this part is deferred. External custom dispatch overrides must use the shared environment helper. An entirely empty PATH remains unchanged.
  • On this rebased head: 716 passed, 12 skipped on Linux/Python 3.14; Ruff passed. This includes a temporary test using the real AgyIntegration class and a simulated CLI; no new live agy CLI run was performed. Native Windows and Windows PowerShell 5.1 validation remain pending.

Testing

At a6085015 (run by the agent in this checkout's .venv):

  • ruff check src tests: passed.
  • git diff --check be0c8d65 a6085015: passed.
  • .venv/bin/python -m pytest tests/integrations/test_integration_agy.py tests/integrations/test_integration_copilot.py tests/specify_cli/events/ tests/test_agent_config_consistency.py -q and standalone tests/specify_cli/test_command_init.py (175 passed): passed (in a single-process run after test_integration_agy.py, test_init_here_rollback_removes_a_commands_dir_created_before_the_first_write[agy] hits a pre-existing monkeypatch.setattr(instance, "list_command_templates", ...) leak in tests/integrations/test_integration_base_skills.py; standalone test_command_init.py passes).
  • Full sandboxed suite .venv/bin/python -m pytest -q -n 4: 17,765 passed, 697 skipped, 10 failed (4 network/catalog tests fail in the no-network sandbox, 1 unrelated Click 8.2 uppercase PRESET_ID formatting mismatch in test_preset_update_cli_contract, and 5 subprocess timeout failures under -n 4 contention that passed 4/4 and 69/69 when re-run standalone).

Earlier probe and live runs (on the same agy integration code):

Probe of agy 1.5.20 on Linux, before implementation (manual hooks, isolated HOME, 8 runs):

  • SessionStart fires once per --print run with Spec Kit's invocation (--add-dir <root>, cwd = root), before the first model call.
  • The process environment reaches the hook.
  • injectSteps reaches the model.
  • No trust approval was needed in the default configuration.
  • Hooks run with cwd .agents/.
  • Hook errors and timeouts fail open: the exit code is 0, nothing goes to stderr, and the error appears only in the CLI log.

Live evidence with this implementation (agy 1.5.20, default model). Setup: a sample project from specify init --integration agy, a local probe extension command that replies with a PROBE-CTX-… token from its context or NONE, and a workflow command step with integration: agy and additional_context: "{{ inputs.ctx }}".

Run Result
-i ctx=PROBE-CTX-6bda4df8 Exit 0, captured stdout PROBE-CTX-6bda4df8. The value is in state.json and not in log.jsonl.
No context Exit 0, NONE. output.additional_context is null, and the handler writes 0 bytes.
After the first rebase and round 1 (6532110b, same agy code as 4ee6ad96), -i ctx=PROBE-CTX-22cf6f0a Exit 0, captured stdout PROBE-CTX-22cf6f0a.

Lifecycle, checked by hand: an existing user definition mine in .agents/hooks.json survives init. After integration switch none, only mine is left.

Not verified:

  • agy on Windows: its shell, quoting, and execution. No Windows host was available, and no PowerShell form was invented. The docs say so.
  • Same-name definitions in the global and workspace hooks.json, non-default trust or managed policies, and resumed sessions. These are documented as untested.

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 decision.

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

  • Review round 2 & stack split (a6085015): Antigravity (Gemini 4 Hydrogen, interactive human-supervised review decisions with @markuswondrak / autonomous code, test, rebase, and PR updates) moved shared runtime changes to feat(workflows): add additional_context to command steps #5616, added the AgyIntegration deleted-.venv test, and rebased onto feat(copilot): declare additional_context delivery #5621 (4fedec2d).

  • Review and stack update (fb72c77e): pi coding agent (gpt-6.1-terra via GitHub Copilot; reasoning effort not supplied; interactive, human-directed) investigated the findings, applied reader and test fixes, rebased the stack, ran validation, and updated the PR. The shared PATH change was implemented by an autonomous pi worker (gpt-6.1-terra, high reasoning), with autonomous review by pi (gpt-6.2-sol, high) and plan review by pi (gemini-4-carbon, high).

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 17:10

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

An older importable specify_cli can pass the confinement check yet emit plain-text injectSteps, silently dropping ordinary Antigravity event-handler context.

1 open issue
What changed in this PR

Adds Antigravity (agy) context delivery for workflow command steps, building on the framework in #5616 toward #5533. The Antigravity-specific changes are in commit 012c40a6; the supplied diff also includes prerequisite changes.

Changes:

  • Declares session_start support with Antigravity’s injectSteps envelope.
  • Adds named hook configuration with user-definition preservation and config-directory-relative command paths.
  • Adds lifecycle and delivery coverage, plus documentation of agent-side requirements and unverified platforms.

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

File Description
tests/​workflows/​test_step_capture.py Tests inherited-context removal for prompt steps.
tests/​workflows/​test_command_additional_context.py Tests context validation, isolation, and resume behavior.
tests/​specify_cli/​events/​test_json_named.py Tests Antigravity hook format, paths, and lifecycle.
tests/​specify_cli/​events/​test_events.py Tests safe destinations and empty-directory cleanup.
tests/​specify_cli/​events/​test_context_delivery.py Tests capability checks and delivery envelopes.
tests/​integrations/​test_integration_copilot.py Updates expected Copilot event-file inventories.
tests/​integrations/​test_integration_agy.py Tests Antigravity event installation and removal.
tests/​integrations/​test_context.py Tests child-only context transport.
tests/​integrations/​test_capture.py Updates the process mock for environment forwarding.
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 Validates and forwards additional context.
src/​specify_cli/​workflows/​step/​_env_values.py Adds shared environment-value validation.
src/​specify_cli/​integrations/​manifest.py Extracts safe empty-parent cleanup.
src/​specify_cli/​integrations/​copilot/​__init__.py Declares context delivery and forwards child environments.
src/​specify_cli/​integrations/​base.py Adds context capability and hook working-directory contracts.
src/​specify_cli/​integrations/​agy/​__init__.py Declares Antigravity hooks and context delivery.
src/​specify_cli/​integrations/​_context.py Creates isolated dispatch environments.
src/​specify_cli/​integrations/​_capture.py Forwards explicit environments to captured processes.
src/​specify_cli/​events/​__init__.py Adds named hooks, envelopes, relative paths, and lifecycle handling.
docs/​workflow-steps/​types.md Documents additional context and supported integrations.
docs/​integrations/​copilot.md Explains Copilot folder-trust requirements.
docs/​integrations/​cli.md Documents default context handlers and Antigravity event support.
docs/​integrations/​api.md Defines external-adapter context declarations.
docs/​integrations/​agy.md Documents Antigravity hooks, requirements, and limitations.
design/​integration.md Defines context-delivery and named-hook contracts.

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/events/__init__.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)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 29, 2026
- Delegate from the generated dispatcher to an importable specify_cli
  only when it advertises the requested envelope (new
  EVENT_CONTEXT_ENVELOPES; versions without the constant support the
  legacy set). Otherwise use the inline path, so an older install
  cannot emit injectSteps output as plain text.
- Add the json-named installed-handler reader. It reads only the
  reserved __speckit_event__ definition and checks event and envelope.
  _parse_dispatcher_command now accepts the config-directory-relative
  dispatcher path of integrations with events_cwd_is_config_dir, and
  still requires an exact re-render.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak
markuswondrak force-pushed the feat/5533-agy-context-delivery branch from 012c40a to 6532110 Compare November 29, 2026 18:35
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 18:35
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review round 1 is addressed in 6532110b. The branch was also rebased onto #5621 (Copilot), so it now sits on top of #5616's round-1 changes.

Changed:

  • Envelope delegation gate: specify_cli.events exports EVENT_CONTEXT_ENVELOPES. The generated dispatcher delegates only when the imported module advertises the requested envelope; versions without the constant support the legacy set. Otherwise it uses the inline path. Tests cover a stale package without the constant with injectSteps (inline path, exactly one JSON copy), a stale package with plain (still delegates), and a current package with injectSteps (delegates).
  • Added the json-named installed-handler reader for feat(workflows): add additional_context to command steps #5616's installed_event_handlers(), and parser support for the config-directory-relative dispatcher path.

Full suite: 17,430 passed, 676 skipped (Linux). Live check after the rebase: agy 1.5.20 received the context (PROBE-CTX-22cf6f0a). 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 the disposition. The fix was 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.

🔵 Needs a closer look

Dispatcher delegation, config-relative command execution, and shared-hook lifecycle changes interact across runtime contracts beyond the limited scope of automated approval, warranting human review.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

- 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)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 30, 2026
- Delegate from the generated dispatcher to an importable specify_cli
  only when it advertises the requested envelope (new
  EVENT_CONTEXT_ENVELOPES; versions without the constant support the
  legacy set). Otherwise use the inline path, so an older install
  cannot emit injectSteps output as plain text.
- Add the json-named installed-handler reader. It reads only the
  reserved __speckit_event__ definition and checks event and envelope.
  _parse_dispatcher_command now accepts the config-directory-relative
  dispatcher path of integrations with events_cwd_is_config_dir, and
  still requires an exact re-render.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak
markuswondrak force-pushed the feat/5533-agy-context-delivery branch from 6532110 to 677ac6d Compare November 30, 2026 05:54
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 05:54
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Nov 30, 2026
Add session_start runtime event support to the pi integration and declare context delivery, so workflow command steps with additional_context work with pi (github#5533, stacked on github#5617).

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

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

Setup preflight fails to reject symlinked hook destinations before mutation, so switching to agy can remove the existing integration and leave generated files untracked when setup and rollback fail.

4 open issues

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
@mnriem mnriem added the triage-nice-to-have Verdict: evidence-backed fix or greenlit feature — land after review label Nov 30, 2026
@mnriem

mnriem commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Markus and others added 6 commits December 1, 2026 18:00
Validate the full generated dispatcher command, including the interpreter and native event, and reject malformed timeout tokens. Reject unsupported context-delivery envelopes before dispatch.

Normalize deeply nested JSON parsing failures to ValueError so additional_context respects continue_on_error. Link the integration contract to its published repository location.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Resolve the shell-step conflict by preserving both context environment isolation and the opt-in output_encoding behavior. Add regression coverage for their interaction.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Describe the helper as JSON text loading for workflow expressions and remove the unused strict_constants option. Existing callers continue to reject non-JSON numeric constants.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Address PR github#5616 review round 5:

- Centralize IntegrationReadError message, reason, detail, remedy, and summary formatting in integration_state.py so schema_too_new advises upgrading Spec Kit (never deleting .specify/integration.json) across context_delivery_error(), integration status, _helpers, _lifecycle, generic, extensions, and event refresh.
- Require at least one unfiltered session_start __speckit_additional_context__ handler (matcher omitted, empty, or '*') in context_delivery_error(), and document the native-filter requirement on installed_event_handlers() in base.py, design/integration.md, docs/integrations/api.md, and docs/workflow-steps/types.md.
- Add unit and regression tests for all IntegrationReadError kinds, schema_too_new remedies across callers, restrictive override matchers, and a contract-compliant json-nested native handler reader.

Assisted-by: Antigravity (model: Gemini 4 Neon, autonomous)
Migrate the direct Path I/O calls introduced in events/__init__.py and
integrations/manifest.py to deny-mode FileHelper operations so the PR
satisfies the FileHelper migration boundary check:

- Read .specify/events.py in context_delivery_error() via FileHelper
  without following symlinks.
- Validate event destination project roots via FileHelper from the
  nearest existing ancestor while still permitting linked parent
  directories above project_root.
- Prune empty parent directories via FileHelper.directory_exists() and
  FileHelper.delete(..., recursive=False) without following symlinks or
  removing regular files.
- Add positive and negative regression coverage across context delivery,
  safe event destinations, and manifest parent pruning.

Assisted-by: GitHub Copilot CLI (model: gpt-6.1-terra, autonomous)
Assisted-by: GitHub Copilot CLI (model: Gemini 4 Carbon, autonomous)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…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>
Markus added 2 commits December 2, 2026 21:55
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)
Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Dec 5, 2026
Add session_start runtime event support to the pi integration and declare context delivery, so workflow command steps with additional_context work with pi (github#5533, stacked on github#5617).

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak
markuswondrak force-pushed the feat/5533-agy-context-delivery branch from 677ac6d to d921281 Compare December 5, 2026 07:47
Copilot AI adaptive 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.

🟡 Changes recommended

Unresolved hook-delivery defects can skip handlers or duplicate context, malformed hook files receive ineffective repair guidance, and shared runtime changes lack the required independent justification.

6 open issues
2 resolved since last review

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/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
…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)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Dec 5, 2026
Add session_start runtime event support to the pi integration and declare context delivery, so workflow command steps with additional_context work with pi (github#5533, stacked on github#5617).

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak
markuswondrak force-pushed the feat/5533-agy-context-delivery branch from d921281 to a608501 Compare December 5, 2026 09:30
Copilot AI adaptive review requested due to automatic review settings December 5, 2026 09:30
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Addressed Copilot review feedback in a6085015 (stacked on rebased #5621 4fedec2d and updated #5616 049bd4d9):

  • Hook destination preflight (r4735535872): Already resolved by feat(workflows): add additional_context to command steps #5616's preflight_integration_events() (ff900391) and agy lifecycle preflight tests in tests/integrations/test_integration_agy.py.
  • Stale specify_cli bundled-template lookup (r4735535919, r4809891383): Fixed in feat(workflows): add additional_context to command steps #5616 (049bd4d9). _EVENTS_DISPATCHER_TEMPLATE now delegates to confinement-safe specify_cli installs using envelope="plain" with stdout capture and wraps output locally with _emit(), keeping bundled core command resolution intact and adding regression tests without .specify/templates/commands/.
  • Deleted-.venv context handler validation (r4735535947): _parse_dispatcher_command already rejects missing .venv interpreters via full-command re-rendering; added test_named_delivery_rejects_deleted_venv in tests/specify_cli/events/test_json_named.py (049bd4d9) and test_agy_deleted_venv_rejects_context_delivery in tests/integrations/test_integration_agy.py (a6085015).
  • Integration delivery boundary (r4735535971, r4809891441): Moved json-named, events_cwd_is_config_dir, injectSteps, EVENT_CONTEXT_ENVELOPES, design/integration.md, and FakeNamedIntegration tests out of this PR into feat(workflows): add additional_context to command steps #5616 (049bd4d9). This PR now contains only AgyIntegration's declaration, docs, and agy-specific tests.

Verification at a6085015: ruff check src tests passed, git diff --check be0c8d65 a6085015 passed, tests/specify_cli/test_command_init.py passed (175 passed), and 742 tests across pi, agy, copilot, events, and agent-config consistency passed on top of the stack.

AI disclosure: Posted on behalf of @markuswondrak by Antigravity (model: Gemini 4 Hydrogen, interactive human-supervised review decisions with @markuswondrak / autonomous implementation, rebase, and verification). 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.

🟡 Changes recommended

The hook reader allows preflight to pass when symlinked directories redirect the dispatcher outside the project, and malformed configurations receive upgrade advice that cannot repair them.

2 open issues
6 resolved since last review

Review effort: Max (adaptive)

Comment thread src/specify_cli/events/__init__.py Resolved
Comment thread src/specify_cli/events/__init__.py Resolved
Markus added 9 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)
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)
Reject symlinked event destinations before lifecycle writes, preserving no-op disabled setups. Distinguish unreadable hook configuration from absent hooks and reject explicit non-command types while honoring the native default for omitted type. Normalize platform separators in symlink assertions.

Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
Assisted-by: pi coding agent (model: mai-code-2, autonomous)
Reject context hooks whose working directory is not the project root. Check dispatcher cleanup before an events-disabled setup can write files, and exercise symlink refusal and opt-out during switch.

Assisted-by: pi coding agent (model: gemini-4-hydrogen, autonomous)
Assisted-by: pi coding agent (model: gpt-6.2-sol, autonomous)
Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Read the native hook file through deny-mode FileHelper during context-delivery preflight, preserving missing and malformed configuration diagnostics. Cover linked files and linked parents without changing their targets.

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
… hooks

Keep only agy integration declaration, documentation, and agy-specific tests in this PR after moving shared event framework changes into github#5616. Add agy removed-venv context delivery regression test.

Assisted-by: Antigravity (model: Gemini 4 Hydrogen, autonomous)
markuswondrak pushed a commit to markuswondrak/spec-kit that referenced this pull request Dec 5, 2026
Add session_start runtime event support to the pi integration and declare context delivery, so workflow command steps with additional_context work with pi (github#5533, stacked on github#5617).

Assisted-by: pi coding agent (model: gpt-6.1-terra, autonomous)
Assisted-by: pi coding agent (model: claude-opus-5.5, autonomous)
@markuswondrak
markuswondrak force-pushed the feat/5533-agy-context-delivery branch from a608501 to fb72c77 Compare December 5, 2026 14:18
Copilot AI adaptive review requested due to automatic review settings December 5, 2026 14:18
@markuswondrak

Copy link
Copy Markdown
Contributor Author

Review update at fb72c77e, stacked on #5621 4e6c73f2 and #5616 d3f26104:

  • The shared reader rejects symlinked hook files and parent directories (r4810315461). Malformed or unreadable named configs now receive repair guidance (r4809891420).
  • For Specify-launched workflows, the child environment anchors relative PATH entries to the invoking directory (r4810315486). Deferred limitation: manually started agy sessions do not receive that environment and their hooks can still fail with a relative PATH; generated hook commands are unchanged.

Validation: 716 passed, 12 skipped on Linux/Python 3.14; Ruff passed. A temporary test exercised the real AgyIntegration class with a simulated CLI; no new live agy CLI run was performed. 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). The reader and tests were agent-authored; a pi worker (gpt-6.1-terra, high, autonomous) implemented PATH handling and pi (gpt-6.2-sol, high, autonomous) reviewed it. 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, native hooks, and lifecycle cleanup interact across integrations, while Antigravity’s Windows hook execution and quoting remain unvalidated and require human cross-platform verification.

1 open issue
1 resolved since last review

Review effort: Balanced (adaptive)

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