@@ -1197,6 +1197,55 @@ def _locate_release_script() -> tuple[Path, str]:
11971197 raise FileNotFoundError (f"Release script '{ name } ' not found in core_pack or source checkout" )
11981198
11991199
1200+ def _install_shared_infra (
1201+ project_path : Path ,
1202+ script_type : str ,
1203+ tracker : StepTracker | None = None ,
1204+ ) -> bool :
1205+ """Install shared infrastructure files into *project_path*.
1206+
1207+ Copies ``.specify/scripts/``, ``.specify/templates/``, and
1208+ ``.specify/memory/`` from the bundled core_pack or source checkout.
1209+ Returns ``True`` on success.
1210+ """
1211+ core = _locate_core_pack ()
1212+
1213+ # Scripts
1214+ if core and (core / "scripts" ).is_dir ():
1215+ scripts_src = core / "scripts"
1216+ else :
1217+ repo_root = Path (__file__ ).parent .parent .parent
1218+ scripts_src = repo_root / "scripts"
1219+
1220+ if scripts_src .is_dir ():
1221+ dest_scripts = project_path / ".specify" / "scripts"
1222+ dest_scripts .mkdir (parents = True , exist_ok = True )
1223+ variant_dir = "bash" if script_type == "sh" else "powershell"
1224+ variant_src = scripts_src / variant_dir
1225+ if variant_src .is_dir ():
1226+ dest_variant = dest_scripts / variant_dir
1227+ if dest_variant .exists ():
1228+ shutil .rmtree (dest_variant )
1229+ shutil .copytree (variant_src , dest_variant )
1230+
1231+ # Page templates (not command templates, not vscode-settings.json)
1232+ if core and (core / "templates" ).is_dir ():
1233+ templates_src = core / "templates"
1234+ else :
1235+ repo_root = Path (__file__ ).parent .parent .parent
1236+ templates_src = repo_root / "templates"
1237+
1238+ if templates_src .is_dir ():
1239+ dest_templates = project_path / ".specify" / "templates"
1240+ dest_templates .mkdir (parents = True , exist_ok = True )
1241+ for f in templates_src .iterdir ():
1242+ if f .is_file () and f .name != "vscode-settings.json" and not f .name .startswith ("." ):
1243+ # Skip command templates directory
1244+ shutil .copy2 (f , dest_templates / f .name )
1245+
1246+ return True
1247+
1248+
12001249def scaffold_from_core_pack (
12011250 project_path : Path ,
12021251 ai_assistant : str ,
@@ -1828,6 +1877,7 @@ def init(
18281877 offline : bool = typer .Option (False , "--offline" , help = "Use assets bundled in the specify-cli package instead of downloading from GitHub (no network access required). Bundled assets will become the default in v0.6.0 and this flag will be removed." ),
18291878 preset : str = typer .Option (None , "--preset" , help = "Install a preset during initialization (by preset ID)" ),
18301879 branch_numbering : str = typer .Option (None , "--branch-numbering" , help = "Branch numbering strategy: 'sequential' (001, 002, ...) or 'timestamp' (YYYYMMDD-HHMMSS)" ),
1880+ integration : str = typer .Option (None , "--integration" , help = "Use the new integration system (e.g. --integration copilot). Mutually exclusive with --ai." ),
18311881):
18321882 """
18331883 Initialize a new Specify project.
@@ -1889,6 +1939,34 @@ def init(
18891939 if ai_assistant :
18901940 ai_assistant = AI_ASSISTANT_ALIASES .get (ai_assistant , ai_assistant )
18911941
1942+ # --integration and --ai are mutually exclusive
1943+ if integration and ai_assistant :
1944+ console .print ("[red]Error:[/red] --integration and --ai are mutually exclusive" )
1945+ console .print ("[yellow]Use:[/yellow] --integration for the new integration system, or --ai for the legacy path" )
1946+ raise typer .Exit (1 )
1947+
1948+ # Auto-promote: --ai copilot → integration path with a nudge
1949+ use_integration = False
1950+ if integration :
1951+ from .integrations import get_integration
1952+ resolved_integration = get_integration (integration )
1953+ if not resolved_integration :
1954+ console .print (f"[red]Error:[/red] Unknown integration: '{ integration } '" )
1955+ console .print ("[yellow]Available integrations:[/yellow] copilot" )
1956+ raise typer .Exit (1 )
1957+ use_integration = True
1958+ # Map integration key to the ai_assistant variable for downstream compatibility
1959+ ai_assistant = integration
1960+ elif ai_assistant == "copilot" :
1961+ from .integrations import get_integration
1962+ resolved_integration = get_integration ("copilot" )
1963+ if resolved_integration :
1964+ use_integration = True
1965+ console .print (
1966+ "[dim]Tip: Use [bold]--integration copilot[/bold] instead of "
1967+ "--ai copilot. The --ai flag will be deprecated in a future release.[/dim]"
1968+ )
1969+
18921970 if project_name == "." :
18931971 here = True
18941972 project_name = None # Clear project_name to use existing validation logic
@@ -2057,7 +2135,10 @@ def init(
20572135 "This will become the default in v0.6.0."
20582136 )
20592137
2060- if use_github :
2138+ if use_integration :
2139+ tracker .add ("integration" , "Install integration" )
2140+ tracker .add ("shared-infra" , "Install shared infrastructure" )
2141+ elif use_github :
20612142 for key , label in [
20622143 ("fetch" , "Fetch latest release" ),
20632144 ("download" , "Download template" ),
@@ -2092,7 +2173,35 @@ def init(
20922173 verify = not skip_tls
20932174 local_ssl_context = ssl_context if verify else False
20942175
2095- if use_github :
2176+ if use_integration :
2177+ # Integration-based scaffolding (new path)
2178+ from .integrations .manifest import IntegrationManifest
2179+ tracker .start ("integration" )
2180+ manifest = IntegrationManifest (
2181+ resolved_integration .key , project_path , version = get_speckit_version ()
2182+ )
2183+ resolved_integration .setup (
2184+ project_path , manifest ,
2185+ script_type = selected_script ,
2186+ )
2187+ manifest .save ()
2188+
2189+ # Write .specify/agent.json
2190+ agent_json = project_path / ".specify" / "agent.json"
2191+ agent_json .parent .mkdir (parents = True , exist_ok = True )
2192+ agent_json .write_text (json .dumps ({
2193+ "integration" : resolved_integration .key ,
2194+ "version" : get_speckit_version (),
2195+ }, indent = 2 ) + "\n " , encoding = "utf-8" )
2196+
2197+ tracker .complete ("integration" , resolved_integration .config .get ("name" , resolved_integration .key ))
2198+
2199+ # Install shared infrastructure (scripts, templates)
2200+ tracker .start ("shared-infra" )
2201+ _install_shared_infra (project_path , selected_script , tracker = tracker )
2202+ tracker .complete ("shared-infra" , f"scripts ({ selected_script } ) + templates" )
2203+
2204+ elif use_github :
20962205 with httpx .Client (verify = local_ssl_context ) as local_client :
20972206 download_and_extract_template (
20982207 project_path ,
@@ -2227,7 +2336,7 @@ def init(
22272336 # Persist the CLI options so later operations (e.g. preset add)
22282337 # can adapt their behaviour without re-scanning the filesystem.
22292338 # Must be saved BEFORE preset install so _get_skills_dir() works.
2230- save_init_options ( project_path , {
2339+ init_opts = {
22312340 "ai" : selected_ai ,
22322341 "ai_skills" : ai_skills ,
22332342 "ai_commands_dir" : ai_commands_dir ,
@@ -2237,7 +2346,10 @@ def init(
22372346 "offline" : offline ,
22382347 "script" : selected_script ,
22392348 "speckit_version" : get_speckit_version (),
2240- })
2349+ }
2350+ if use_integration :
2351+ init_opts ["integration" ] = resolved_integration .key
2352+ save_init_options (project_path , init_opts )
22412353
22422354 # Install preset if specified
22432355 if preset :
0 commit comments