fix(agent-context): support multiple context files safely
Summary
This PR lets the bundled agent-context extension manage more than one coding-agent context file from the same Spec Kit run.
The motivating workflow is a repo that uses Claude Code and Codex interchangeably and wants Spec Kit's generated context block synced to both CLAUDE.md and AGENTS.md. The implementation keeps the existing singular context_file behavior, while adding an optional context_files list for projects that intentionally keep multiple agent anchors in sync.
What Changed
- Added optional
context_filessupport to the agent-context config template. - Updated the bash and PowerShell update scripts to refresh every configured context file.
- Updated Python integration setup/removal paths to upsert and remove the managed block across configured files.
- Rendered command templates with a readable multi-file context target when
context_filesis configured. - Preserved existing non-empty
context_filesduring integration switches. - Added project-root containment validation for context file paths:
- rejects absolute paths
- rejects Windows drive paths
- rejects backslash separators
- rejects
..path segments - confirms the resolved target stays inside the project root
- Kept
specify extension disable agent-contextas a full opt-out: disabled projects skip upsert/removal and ignore stalecontext_filesduring command rendering. - Updated agent-context docs and command help to describe multi-file configuration and safety behavior.
Why
Today Spec Kit stores one managed context block target in context_file. That works well for a single coding agent, but mixed-agent projects can need more than one context anchor. For example, Codex reads AGENTS.md, while Claude-oriented setups often use CLAUDE.md. Without first-class multi-file support, teams have to choose one anchor or maintain duplicate context manually.
This change makes the multi-agent case explicit and configurable without hard-coding any specific agent names or file paths.
Safety Notes
The script and Python integration paths now enforce matching path constraints so a configured context file cannot escape the project root. The disabled-extension path also avoids validating stale config before the opt-out gate, so disabling agent-context remains a complete opt-out even if old config contains invalid paths.
Validation
bash -n extensions/agent-context/scripts/bash/update-agent-context.shpython -m compileall -q src\specify_clipytest tests/extensions/test_extension_agent_context.py -q50 passed
pytest tests/integrations/test_integration_codex.py::TestCodexInitFlow::test_plan_skill_references_configured_context_files tests/integrations/test_integration_codex.py::TestCodexInitFlow::test_plan_skill_ignores_context_files_when_agent_context_disabled -q2 passed
pytest tests/test_agent_config_consistency.py -q28 passed
specify --help- Manual PowerShell smoke test:
- configured
context_files: [AGENTS.md, CLAUDE.md] - ran
update-agent-context.ps1 specs/123-test/plan.md - verified both files were updated
- configured
- Manual bash smoke test:
- configured
context_files: [AGENTS.md, CLAUDE.md] - ran
update-agent-context.sh specs/123-test/plan.md - verified both files were updated
- configured
Known Existing Test Failure
The broader Codex integration slice still has two inventory failures:
TestCodexIntegration.test_complete_file_inventory_shTestCodexIntegration.test_complete_file_inventory_ps
Both failures reproduce on a clean upstream/main worktree at 1b0556c, before this PR's changes. They expect bundled agent-context extension artifacts in the generated project, but the generated project does not include them. The focused tests added by this PR pass.
AI Assistance Disclosure
I used Codex/ChatGPT to inspect the integration paths, draft the implementation, and generate test coverage. I reviewed the code paths and validated the behavior locally with automated and manual checks.
Hi maintainers, I've marked this PR as ready for review. It looks like the workflows are awaiting approval before the checks can run. Thanks for taking a look.
Addressed the Copilot review feedback in commit 10cbff3.
Summary:
- Validated
context_files/context_filebefore rendering skill placeholders. - Restored a string fallback for disabled agent-context template rendering.
- Added bash and PowerShell resolved-path containment checks before context-file writes.
- Added PowerShell backslash rejection for configured context files.
- Added targeted tests for invalid config paths, backslashes, symlink/junction escape paths, and disabled-extension behavior.
Validation:
pytest tests/extensions/test_extension_agent_context.py tests/integrations/test_integration_codex.py::TestCodexInitFlow -qgit diff --checkbash -n extensions/agent-context/scripts/bash/update-agent-context.sh- PowerShell parser syntax check
Posted by @AustinZ21 with fixes prepared using Codex.
Please address Copilot feedback
Addressed the latest Copilot feedback and the Windows CI failures in commit 9458a6b.
Summary:
- Preserved
__CONTEXT_FILE__rendering whenagent-contextis disabled by falling back to the extension config’s singularcontext_file. - Kept disabled-mode behavior from using stale
context_files. - Updated the PowerShell updater tests so the subprocess uses the same Python environment as pytest, ensuring PyYAML is available in CI.
Validation:
pytest tests/extensions/test_extension_agent_context.py tests/integrations/test_integration_codex.py::TestCodexInitFlow -qgit diff --checkpython -m compileall -q src/specify_cli/agents.py tests/extensions/test_extension_agent_context.py
The previous Windows failures were from commit 10cbff3; the fix is now pushed in 9458a6b.
Addressed the latest Copilot review follow-ups in commit e3a1b55.
Summary:
- Replaced WSL-only
/mnt/<drive>path handling in bash-related tests with a helper that preferscygpath -ufor Git-for-Windows/MSYS bash, with a WSL fallback for local runs. - Updated Windows symlink setup in the bash updater test to use the same path conversion helper.
- Corrected the bash updater parser comment to clarify that only
context_filesis emitted as JSON and markers are plain strings. - Cached
context_file_displaybefore template loops so agent-context config parsing/validation is not repeated per template.
Please address Copilot feedback
Addressed the latest Copilot feedback in commit e6dc328.
Summary:
- Made Python context upsert/remove fall back to the agent-context config's singular
context_filebefore the integration class default. - Validated the legacy init-options
context_filefallback when agent-context is enabled. - Aligned the Bash updater's
context_filefallback with the trimmed behavior used forcontext_files. - Updated the agent-context update command docs to describe file(s) and the full path constraints.
Validation:
PYTHONPATH=src python -m pytest tests/extensions/test_extension_agent_context.py tests/integrations/test_integration_codex.py -q-> 115 passed, 3 skippedpython -m compileall -q src tests/extensions/test_extension_agent_context.pygit diff --check
GitHub Actions are still awaiting maintainer approval for forked workflow runs.
Posted on behalf of @AustinZ21 by Codex (GPT-5).
Please address Copilot feedback
Posted on behalf of @AustinZ21 by Codex (GPT-5).
Pushed follow-up commit 1343799 to address the latest review round. It centralizes context file resolution, de-duplication, validation, and display formatting in IntegrationBase and uses that from CommandRegistrar; adds the PowerShell drive-qualified path guard for C:tmp/out.md; and replaces brittle script source-substring assertions with behavior-level updater coverage while expanding invalid-path coverage.
Local validation:
PYTHONPATH=src python -m pytest tests/extensions/test_extension_agent_context.py tests/integrations/test_integration_codex.py tests/integrations/test_integration_claude.py -q(152 passed, 4 skipped)PYTHONPATH=src python -m pytest tests/integrations/test_integration_base_markdown.py tests/integrations/test_integration_base_skills.py tests/integrations/test_integration_base_toml.py tests/integrations/test_integration_base_yaml.py tests/integrations/test_integration_generic.py tests/integrations/test_registry.py -q(1027 passed)PYTHONPATH=src python -m compileall -q src tests/extensions/test_extension_agent_context.pygit diff --check
I also ran tests/test_registrar_path_traversal.py with the local Windows symlink-privilege case deselected; the remaining 21 tests passed. The unfiltered symlink case needs a symlink-capable Windows environment.
Thank you!