feat(scripts): add SPECIFY_INIT_DIR to target a member project from the repo root#2892
Draft
PascalThuet wants to merge 3 commits into
Draft
feat(scripts): add SPECIFY_INIT_DIR to target a member project from the repo root#2892PascalThuet wants to merge 3 commits into
PascalThuet wants to merge 3 commits into
Conversation
…utside its directory Adds a project-root override so a non-interactive / CI caller can run a Spec Kit command against a member project (e.g. apps/web in a monorepo) from outside that directory, without cd. SPECIFY_INIT_DIR names the project root — the directory containing .specify/ — and is honored by get_repo_root in scripts/bash/common.sh, mirrored in scripts/powershell/common.ps1. Strict by design, per maintainer guidance on github#2834: when set, the path must exist and contain .specify/, otherwise the resolver hard-errors and never falls back to the current directory or the git toplevel (which would silently write to the wrong project's specs/). Relative paths normalize against the current directory (with CDPATH="" to avoid CDPATH-based misresolution); trailing slashes are tolerated; an empty string is treated as unset. Resolution stays two independent axes: SPECIFY_INIT_DIR selects the project, while SPECIFY_FEATURE_DIRECTORY / .specify/feature.json / branch detection select the feature within it (project-then-feature). The bash get_repo_root call sites that feed real resolution are split into decl/assignment so the hard error propagates instead of being masked by `local`. Env var only; the --project CLI flag is deferred. Adds tests/test_init_dir.py (positive + negative, bash and PowerShell) and documents the variable and the two-axis precedence in docs/reference/core.md. Refs: github#2834 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
SPECIFY_INIT_DIR, an environment variable that lets Spec Kit scripts target an explicit project root from another directory.This covers monorepo use cases such as running from the repository root while targeting
apps/web, withoutcd apps/web.Behavior
SPECIFY_INIT_DIRmust point to the project root: the directory containing.specify/.SPECIFY_FEATURE_DIRECTORY>.specify/feature.json> branch lookup.Changes
scripts/bash/common.shandscripts/powershell/common.ps1honorSPECIFY_INIT_DIRin root resolution.create-new-feature.shexits when root resolution fails.agent-contextupdate scripts honorSPECIFY_INIT_DIR, so context updates are written to the selected project.Validation
uv run pytest tests/test_init_dir.py tests/test_timestamp_branches.py::TestGetFeaturePathsSinglePrefix tests/test_timestamp_branches.py::TestFeatureDirectoryResolution -vpwshis not installed.uvx ruff check tests/test_init_dir.pyOut of Scope
--projectCLI flag.Related to #2834.