Repository navigation
feat(agy): deliver session_start context through Antigravity hooks - #5617
markuswondrak wants to merge 21 commits into
Conversation
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)
There was a problem hiding this comment.
🟡 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_startsupport with Antigravity’sinjectStepsenvelope. - 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)
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)
- 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)
012c40a to
6532110
Compare
|
Review round 1 is addressed in Changed:
Full suite: 17,430 passed, 676 skipped (Linux). Live check after the rebase: agy 1.5.20 received the context ( AI disclosure: Posted on behalf of @markuswondrak by the pi coding agent (provider |
There was a problem hiding this comment.
🔵 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)
- 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)
6532110 to
677ac6d
Compare
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)
There was a problem hiding this comment.
🟡 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)
|
Please address Copilot feedback |
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>
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)
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)
677ac6d to
d921281
Compare
There was a problem hiding this comment.
🟡 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
Canonicalize command names in the inline resolver · New Do not make restrictive matchers unconditional · New Treat malformed hook files as unavailable for repair guidance · New Keep shared runtime changes out of the agy-specific PR Preserve bundled-template lookup in the older resolver fallback Keep shared runtime changes out of the integration PR · New
2 resolved since last review
Review effort: Max (adaptive)
…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)
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)
d921281 to
a608501
Compare
|
Addressed Copilot review feedback in
Verification at AI disclosure: Posted on behalf of @markuswondrak by Antigravity (model: |
There was a problem hiding this comment.
🟡 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
Treat malformed hook files as unavailable for repair guidance Do not make restrictive matchers unconditional Canonicalize command names in the inline resolver Keep shared runtime changes out of the agy-specific PR Preserve bundled-template lookup in the older resolver fallback Keep shared runtime changes out of the integration PR
Review effort: Max (adaptive)
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)
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)
a608501 to
fb72c77
Compare
|
Review update at
Validation: 716 passed, 12 skipped on Linux/Python 3.14; Ruff passed. A temporary test exercised the real AI disclosure: Written and posted for @markuswondrak by the pi coding agent ( |
There was a problem hiding this comment.
🔵 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 resolved since last review
Review effort: Balanced (adaptive)



Description
Part of #5533. Stacked: #5616 (framework) ← #5621 (Copilot) ← this PR ← #5623 (pi).
This PR adds
session_startruntime event support to theagy(Antigravity) integration and declares context delivery, so workflowcommandsteps withadditional_contextwork with agy.The shared event framework additions (
json-named,events_cwd_is_config_dir,injectSteps, andEVENT_CONTEXT_ENVELOPESwith its stale-CLI fallback) have been moved into #5616 (049bd4d9) per the integration delivery boundary feedback. This PR now contains onlyagy-specific integration changes, docs, and tests (fb72c77eon top of4e6c73f2):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"}, andcontext_delivery_events = frozenset({"session_start"}). agy inherits the basedispatch_command, which already acceptsadditional_context.docs/integrations/agy.md(runtime events, preconditions, symlink refusal acrossinit/integration install/switch/upgrade),docs/integrations/cli.md, and the support table indocs/workflow-steps/types.md.tests/integrations/test_integration_agy.py(init inventory,--events false, upgrade/uninstall preserving user hooks, symlink preflight acrossinstall/switch/upgrade, deleted-.venvcontext-delivery rejection) and"agy, copilot"expectation intests/specify_cli/events/test_context_delivery.py.Generated
.agents/hooks.jsonafterspecify 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
fb72c77ePATHentries 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 relativePATH; this part is deferred. External custom dispatch overrides must use the shared environment helper. An entirely emptyPATHremains unchanged.AgyIntegrationclass 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 -qand standalonetests/specify_cli/test_command_init.py(175 passed): passed (in a single-process run aftertest_integration_agy.py,test_init_here_rollback_removes_a_commands_dir_created_before_the_first_write[agy]hits a pre-existingmonkeypatch.setattr(instance, "list_command_templates", ...)leak intests/integrations/test_integration_base_skills.py; standalonetest_command_init.pypasses)..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 uppercasePRESET_IDformatting mismatch intest_preset_update_cli_contract, and 5 subprocess timeout failures under-n 4contention that passed4/4and69/69when re-run standalone).Earlier probe and live runs (on the same
agyintegration code):Probe of agy 1.5.20 on Linux, before implementation (manual hooks, isolated HOME, 8 runs):
SessionStartfires once per--printrun with Spec Kit's invocation (--add-dir <root>, cwd = root), before the first model call.injectStepsreaches the model..agents/.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 aPROBE-CTX-…token from its context orNONE, and a workflowcommandstep withintegration: agyandadditional_context: "{{ inputs.ctx }}".-i ctx=PROBE-CTX-6bda4df8PROBE-CTX-6bda4df8. The value is instate.jsonand not inlog.jsonl.NONE.output.additional_contextisnull, and the handler writes 0 bytes.6532110b, same agy code as4ee6ad96),-i ctx=PROBE-CTX-22cf6f0aPROBE-CTX-22cf6f0a.Lifecycle, checked by hand: an existing user definition
minein.agents/hooks.jsonsurvivesinit. Afterintegration switch none, onlymineis left.Not verified:
hooks.json, non-default trust or managed policies, and resumed sessions. These are documented as untested.AI Disclosure
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 effortxhigh), 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 efforthigh), 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 theAgyIntegrationdeleted-.venvtest, and rebased onto feat(copilot): declare additional_context delivery #5621 (4fedec2d).Review and stack update (
fb72c77e): pi coding agent (gpt-6.1-terravia 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.