@@ -990,26 +990,35 @@ def init(
990990 # Install bundled agent-context extension (opt-out via
991991 # `specify extension disable agent-context`). Owns the managed
992992 # section in coding agent context files (CLAUDE.md, etc.).
993- # Installed AFTER init-options are saved so hooks can read from
994- # the project. After install, the extension config is updated
995- # with the active integration's context_file.
993+ # Installed after init-options are saved so project metadata
994+ # reflects the selected integration before extension setup.
995+ # The extension config is then updated (in finally) with the
996+ # active integration's context_file.
996997 tracker .start ("agent-context" )
997998 _ac_bundled : Path | None = None
998999 _ac_err_msg : str | None = None
1000+ _ac_terminal : str | None = None
1001+ _ac_terminal_detail = ""
9991002 try :
10001003 from .extensions import ExtensionManager as _AgentCtxMgr
10011004 _ac_bundled = _locate_bundled_extension ("agent-context" )
10021005 if _ac_bundled :
10031006 ac_manager = _AgentCtxMgr (project_path )
10041007 if ac_manager .registry .is_installed ("agent-context" ):
1005- tracker .complete ("agent-context" , "already installed" )
1008+ _ac_terminal = "complete"
1009+ _ac_terminal_detail = "already installed"
1010+ tracker .complete ("agent-context" , _ac_terminal_detail )
10061011 else :
10071012 ac_manager .install_from_directory (
10081013 _ac_bundled , get_speckit_version ()
10091014 )
1010- tracker .complete ("agent-context" , "installed" )
1015+ _ac_terminal = "complete"
1016+ _ac_terminal_detail = "installed"
1017+ tracker .complete ("agent-context" , _ac_terminal_detail )
10111018 else :
1012- tracker .skip ("agent-context" , "bundled extension not found" )
1019+ _ac_terminal = "skip"
1020+ _ac_terminal_detail = "bundled extension not found"
1021+ tracker .skip ("agent-context" , _ac_terminal_detail )
10131022 except Exception as ac_err :
10141023 sanitized_ac = str (ac_err ).replace ('\n ' , ' ' ).strip ()
10151024 _ac_err_msg = f"install failed: { sanitized_ac [:120 ]} "
@@ -1037,7 +1046,22 @@ def init(
10371046 else :
10381047 _ac_err_msg = cfg_msg
10391048 if _ac_err_msg is not None :
1040- tracker .error ("agent-context" , _ac_err_msg )
1049+ if _ac_terminal == "complete" :
1050+ tracker .complete (
1051+ "agent-context" ,
1052+ f"{ _ac_terminal_detail } ; { _ac_err_msg } "
1053+ if _ac_terminal_detail
1054+ else _ac_err_msg ,
1055+ )
1056+ elif _ac_terminal == "skip" :
1057+ tracker .skip (
1058+ "agent-context" ,
1059+ f"{ _ac_terminal_detail } ; { _ac_err_msg } "
1060+ if _ac_terminal_detail
1061+ else _ac_err_msg ,
1062+ )
1063+ else :
1064+ tracker .error ("agent-context" , _ac_err_msg )
10411065
10421066 # Fix permissions after all installs (scripts + extensions)
10431067 ensure_executable_scripts (project_path , tracker = tracker )
@@ -1568,12 +1592,11 @@ def _clear_init_options_for_integration(project_root: Path, integration_key: str
15681592 opts .pop ("ai" , None )
15691593 opts .pop ("ai_skills" , None )
15701594 save_init_options (project_root , opts )
1571- # Clear context_file in the extension config too.
1572- ext_cfg_path = project_root / _AGENT_CTX_EXT_CONFIG
1573- if ext_cfg_path .exists ():
1574- _update_agent_context_config_file (
1575- project_root , "" , preserve_markers = True
1576- )
1595+ # Clear context_file in the extension config too. If the config file
1596+ # does not exist yet, create it so no stale target can persist.
1597+ _update_agent_context_config_file (
1598+ project_root , "" , preserve_markers = True
1599+ )
15771600 elif has_legacy_context_keys :
15781601 save_init_options (project_root , opts )
15791602
0 commit comments