@@ -598,6 +598,19 @@ def _remove_env_keys(env_path: Path, keys: tuple[str, ...]) -> None:
598598 env_path .write_text ("\n " .join (kept ) + ("\n " if kept else "" ))
599599
600600
601+ def _read_env_key (env_path : Path | None , key : str ) -> str | None :
602+ """Read a simple KEY=value assignment from a .env file."""
603+ if env_path is None or not env_path .exists ():
604+ return None
605+ prefix = f"{ key } ="
606+ for line in env_path .read_text ().splitlines ():
607+ stripped = line .strip ()
608+ if not stripped or stripped .startswith ("#" ) or not stripped .startswith (prefix ):
609+ continue
610+ return stripped [len (prefix ) :].strip ().strip ('"' ).strip ("'" ) or None
611+ return None
612+
613+
601614def _run_smart_install (plugin_dir : Path ) -> None :
602615 """Run the plugin's first-run installer so uv/.venv land before first hook."""
603616 script = plugin_dir / "scripts" / "smart-install.sh"
@@ -676,7 +689,7 @@ def _install_openclaw_integration(env_path: Path) -> bool:
676689 # this, the gateway silently drops every plugin-side hook dispatch
677690 # with: '[plugins] typed hook "agent_end" blocked because non-bundled
678691 # plugins must set ...hooks.allowConversationAccess=true'.
679- subprocess .run (
692+ access_cfg = subprocess .run (
680693 [
681694 cli ,
682695 "config" ,
@@ -688,6 +701,12 @@ def _install_openclaw_integration(env_path: Path) -> bool:
688701 capture_output = True ,
689702 text = True ,
690703 )
704+ if access_cfg .returncode != 0 :
705+ typer .echo (
706+ "Error: could not persist openClaw conversation-access permission: "
707+ f"{ access_cfg .stderr or access_cfg .stdout } "
708+ )
709+ raise typer .Exit (1 )
691710 except subprocess .CalledProcessError as exc :
692711 typer .echo (f"Error: openclaw command failed: { exc .stderr or exc .stdout } " )
693712 raise typer .Exit (1 ) from exc
@@ -733,7 +752,7 @@ def _uninstall_openclaw(env_path: Path | None = None, purge: bool = False) -> No
733752 "This will remove the Reflexio integration from openClaw. Continue?" ,
734753 abort = True ,
735754 )
736- cli = shutil .which ("openclaw" )
755+ cli = _read_env_key ( env_path , "OPENCLAW_BIN" ) or shutil .which ("openclaw" )
737756 if cli :
738757 subprocess .run (
739758 [cli , "plugins" , "disable" , _OPENCLAW_PLUGIN_ID ],
@@ -748,7 +767,10 @@ def _uninstall_openclaw(env_path: Path | None = None, purge: bool = False) -> No
748767 text = True ,
749768 )
750769 else :
751- typer .echo ("Warning: openclaw CLI not found on PATH, skipping plugin removal" )
770+ typer .echo (
771+ "Warning: openclaw CLI not found in OPENCLAW_BIN or PATH, "
772+ "skipping plugin removal"
773+ )
752774
753775 if env_path is not None :
754776 _remove_env_keys (env_path , ("OPENCLAW_BIN" , "OPENCLAW_SMART_USE_LOCAL_CLI" ))
@@ -832,6 +854,13 @@ def openclaw(
832854 typer .echo ("Error: could not locate or create a .env file" )
833855 raise typer .Exit (1 )
834856
857+ if repair and (uninstall or purge ):
858+ typer .echo ("Error: --repair cannot be combined with --uninstall or --purge" )
859+ raise typer .Exit (1 )
860+ if purge and not uninstall :
861+ typer .echo ("Error: --purge requires --uninstall" )
862+ raise typer .Exit (1 )
863+
835864 if repair :
836865 _repair_openclaw ()
837866 return
0 commit comments