feat(scripts): add SPECIFY_INIT_DIR to target a member project from the repo root
Summary
Adds SPECIFY_INIT_DIR as an explicit project-root override for Spec Kit scripts that may be invoked from outside the target project, such as a monorepo root or CI task.
Behavior
SPECIFY_INIT_DIR=/path/to/projectmakes supported core scripts operate on that Spec Kit project.- The value must resolve to an existing directory containing
.specify/. - Invalid values fail fast. Scripts do not silently fall back to
cwdor the git toplevel. - The git extension feature-branch entrypoint inherits the core resolver when available; if
SPECIFY_INIT_DIRis set but only minimal or stale core helpers are available, it errors instead of guessing a root.
Changes
- Adds Bash and PowerShell project-root resolvers for
SPECIFY_INIT_DIRin the core common scripts. - Applies the override through core repo/feature path resolution and core feature creation.
- Makes the bundled git extension feature-branch creation use the centralized core resolver without duplicating validation logic.
- Documents the environment variable in the core reference.
- Adds tests for valid targets, invalid targets, relative paths, monorepo-style invocation, file-path rejection, and missing/stale-core git extension fallback.
Validation
uv run pytest tests/test_init_dir.py tests/extensions/git/test_git_extension.py -quvx ruff check tests/extensions/git/test_git_extension.pybash -n extensions/git/scripts/bash/create-new-feature-branch.sh scripts/bash/common.sh scripts/bash/create-new-feature.shgit diff --check
pwsh is not available in my local environment, so PowerShell runtime tests are included but skipped locally.
Architectural feedback
Thanks for the thorough work here — the strict contract (must exist + must contain .specify/) and test coverage are solid.
However, the resolver duplication across 3 script families (core, git-common, agent-context) diverges from how other env var overrides work in Spec Kit. Compare with SPECIFY_FEATURE_DIRECTORY:
- Read once in core
get_feature_paths()/Get-FeaturePathsEnv - Extensions that source core get it for free
- No per-extension copies of the resolution logic
SPECIFY_INIT_DIR should follow the same pattern:
- Resolve once in
get_repo_root()(corecommon.sh/common.ps1) — you already do this, and it works. - Drop the duplicated resolvers from
git-common.sh,git-common.ps1, andupdate-agent-context.{sh,ps1}. Extensions that source core already inheritget_repo_root(). Extensions that don't (agent-context) can read the project root from.specify/init-options.jsonor simply rely on the caller havingcd'd — same as today. - The "extensions can run without core installed" scenario is already handled by the existing
_find_project_rootwalk-up-from-script-dir logic in those extensions.SPECIFY_INIT_DIRdoesn't need a separate code path for that — if core isn't installed, the env var isn't being resolved by core either, so the contract is moot.
This eliminates ~60 lines of duplicated validation and the drift risk across 3 independent copies, while keeping the strict fail-fast behavior you designed.
@mnriem done — centralized on the core resolver and dropped the per-extension resolver copies.
git-common.{sh,ps1}andupdate-agent-context.{sh,ps1}: resolver copies removed.- Git feature-branch creation now inherits
get_repo_root/Get-RepoRootby sourcing core; there is no duplicateSPECIFY_INIT_DIRresolver in the extension. auto-commit.{sh,ps1}: override dropped; the existing script-dir walk-up still resolves the installed member project.- agent-context: back to cwd-based behavior.
One gap this exposed: if SPECIFY_INIT_DIR is set but the git extension only has minimal or stale core helpers available, it could silently ignore the override and target the wrong root. Rather than re-add resolver duplication, the extension now guards that case: SPECIFY_INIT_DIR set + core resolver unavailable → hard error instead of guessing.
Updated on behalf of @PascalThuet by Codex (GPT-5).
Commit: 5ca5f55cfdbcce148a7063dd5c91cc4cbb550ff9
What changed:
- Merged current
origin/mainintofeat/monorepo-init-dirand resolved theCHANGELOG.mdconflict while preserving the PR changelog entry above the0.10.3release section. - Addressed the two open Copilot comments in
tests/test_init_dir.pyby assertingFEATURE_DIRoutput exists before normalizing separators.
Validation run locally:
uv run pytest tests/test_init_dir.py tests/extensions/git/test_git_extension.py -q-> 49 passed, 27 skippeduvx ruff check tests/test_init_dir.py tests/extensions/git/test_git_extension.py-> passedbash -n extensions/git/scripts/bash/create-new-feature-branch.sh scripts/bash/common.sh scripts/bash/create-new-feature.sh-> passedgit diff --check-> passed
GitHub now reports the PR as mergeable.
Please address Copilot feedback and revert changes to CHANGELOG.md