mirror of
https://github.com/github/spec-kit.git
synced 2026-07-06 22:32:13 +08:00
* feat(cli): honor SPECIFY_INIT_DIR in the specify CLI project resolver The shell resolver honors SPECIFY_INIT_DIR (#2892), but the Python CLI did not: it resolved the project as Path.cwd() + a .specify/ check and never read the override. So setup-plan.sh respected it while `specify integration install` ignored it, and you still had to cd into the member project. Route project resolution through a shared _resolve_init_dir_override() that applies the shell resolver's validation rules (relative to cwd, must exist and contain .specify/, hard error, no fallback, same error strings). It's wired into _require_specify_project() — the chokepoint for every project-scoped subcommand (integration/extension/workflow/preset/...) — and the `workflow run <file>` standalone path, which re-applies its symlinked-.specify guard on the override branch too. init is unchanged: it creates .specify/, so the must-pre-exist rule doesn't apply. The resolver canonicalizes symlinks via Path.resolve() while the shell keeps the logical path; they agree for non-symlinked paths (documented in the resolver). Tests in tests/test_init_dir_cli.py mirror the strict cases from test_init_dir.py through the CLI; conftest now strips SPECIFY_* for the whole suite so a stray export can't perturb the now-env-reading resolver. Docs note the CLI applies the same rules. Discussion: github/spec-kit#2834 (Disclosure: I used an AI coding agent to audit the call sites and resolver, draft the change, and run an adversarial code review; reviewed by me.) * fix(cli): honor SPECIFY_INIT_DIR for bundle commands Assisted-by: Codex (model: GPT-5, autonomous) * fix(bundler): refuse symlinked .specify on the SPECIFY_INIT_DIR override path find_project_root refuses a symlinked .specify (following it could read/write outside the tree, and a test pins that), but the SPECIFY_INIT_DIR override added for bundle commands returned early and skipped that guard: _resolve_init_dir_override validates .specify with is_dir(), which follows symlinks. So `specify bundle` accepted via the override a layout the cwd path rejects. Re-check the override result with the same guard, plus a regression test. (Disclosure: found via an AI code review and fixed with an AI coding agent; reviewed by me.) * fix(cli): keep SPECIFY_INIT_DIR strict for bundles Treat an explicit symlinked SPECIFY_INIT_DIR project as a hard bundle error instead of returning no project, which could initialize the current directory. Align the docs with the actual unset resolver behavior. Assisted-by: Codex (model: GPT-5, autonomous) * docs(core): note symlinked .specify handling differs across CLI surfaces A symlinked .specify is followed by integration/extension/workflow (matching the shell resolver) but refused by bundle and workflow run <file> (write confinement). Document the asymmetry so it reads as intentional. (Disclosure: AI-assisted; reviewed by me.) * docs(core): reframe symlinked .specify note around the override invariant Per maintainer feedback on #3186: SPECIFY_INIT_DIR relocates where the project is, not how a surface treats symlinks. Each surface keeps its cwd-path stance (write surfaces refuse a symlinked .specify, read/config surfaces follow it), so the split is one policy relocated, not an inconsistency. * docs: address Copilot review on resolver docstrings - _project.py: the error messages "mirror" the shell wording rather than "match" it (the CLI renders a Rich `Error:` line, the shell a plain `ERROR:`). - find_project_root: document that honoring SPECIFY_INIT_DIR when start is None can raise typer.Exit / BundlerError, so the Path | None signature isn't surprising to direct callers. * docs(bundler): note require_project_root inherits the override raise behavior find_project_root can raise typer.Exit / BundlerError under the SPECIFY_INIT_DIR override (start=None); require_project_root inherits that, so document it alongside its own BundlerError-on-missing-project. * docs: clarify symlinked project root behavior Assisted-by: OpenAI Codex (model: GPT-5, autonomous) * Address SPECIFY_INIT_DIR review feedback Assisted-by: OpenAI Codex (model: GPT-5, autonomous) * Route workflow JSON errors to stderr Assisted-by: OpenAI Codex (model: GPT-5, autonomous)
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""specify integration scaffold command handler."""
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
from pathlib import Path
|
|
|
|
import typer
|
|
|
|
from .._console import console
|
|
from ..integration_scaffold import supported_integration_scaffold_types
|
|
from ._commands import integration_app
|
|
|
|
|
|
INTEGRATION_SCAFFOLD_TYPES = supported_integration_scaffold_types()
|
|
_IntegrationScaffoldType = Enum(
|
|
"_IntegrationScaffoldType",
|
|
{name: name for name in INTEGRATION_SCAFFOLD_TYPES},
|
|
type=str,
|
|
)
|
|
|
|
|
|
@integration_app.command("scaffold")
|
|
def integration_scaffold(
|
|
key: str = typer.Argument(help="Integration key in lowercase kebab-case, e.g. my-agent"),
|
|
integration_type: _IntegrationScaffoldType = typer.Option(
|
|
_IntegrationScaffoldType.markdown,
|
|
"--type",
|
|
case_sensitive=False,
|
|
help=f"Scaffold type: {', '.join(INTEGRATION_SCAFFOLD_TYPES)}",
|
|
),
|
|
):
|
|
"""Create a minimal built-in integration package and test skeleton."""
|
|
from ..integration_scaffold import scaffold_integration
|
|
|
|
# scaffold targets the Spec Kit *source* repo layout (_is_spec_kit_repo_root),
|
|
# not a .specify/ member project, so SPECIFY_INIT_DIR does not apply here.
|
|
project_root = Path.cwd()
|
|
try:
|
|
result = scaffold_integration(project_root, key, integration_type.value)
|
|
except (OSError, ValueError) as exc:
|
|
# OSError covers filesystem failures during mkdir()/write_text()
|
|
# (permission denied, read-only checkout, a path component that is a
|
|
# file, ...) as well as FileExistsError; surface them as a clean CLI
|
|
# error instead of a traceback.
|
|
console.print(f"[red]Error:[/red] {exc}")
|
|
raise typer.Exit(1)
|
|
|
|
console.print(f"[green]Created integration scaffold:[/green] {result.key}")
|
|
console.print(f" {result.integration_file.relative_to(project_root).as_posix()}")
|
|
console.print(f" {result.test_file.relative_to(project_root).as_posix()}")
|
|
console.print()
|
|
console.print("[bold]Next steps:[/bold]")
|
|
for index, step in enumerate(result.next_steps, start=1):
|
|
console.print(f"{index}. {step}")
|