Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(show-runtime): make replacement outcomes truthful (#1643)
Call Whitebf96c1612943
diff --git a/core/show_runtime.py b/core/show_runtime.pyindex b2efad0d0..f55a1bfa3 100644--- a/core/show_runtime.py+++ b/core/show_runtime.py@@ -190,6 +190,40 @@ class ShowRuntimeServingState(str, Enum):START_FAILED = "start_failed"+class _ShowRuntimeOperationState(str, Enum):+ COMPLETED = "completed"+ FAILED = "failed"+ NOT_APPLICABLE = "not_applicable"+++@dataclass(frozen=True)+class _ShowRuntimeOperationOutcome:+ state: _ShowRuntimeOperationState+ reason: str | None++ def __post_init__(self) -> None:+ if self.state is _ShowRuntimeOperationState.COMPLETED and self.reason:+ raise ValueError("completed operation cannot carry a failure reason")+ if self.state is not _ShowRuntimeOperationState.COMPLETED and not self.reason:+ raise ValueError("incomplete operation requires a reason")++ @property+ def ok(self) -> bool:+ return self.state is _ShowRuntimeOperationState.COMPLETED+++@dataclass(frozen=True)+class _ManagedInstallAttempt:+ command: list[str] | None+ operation_reason: str | None = None++ def __post_init__(self) -> None:+ if self.command and self.operation_reason:+ raise ValueError("successful install attempt cannot carry an operation failure")+ if not self.command and not self.operation_reason:+ raise ValueError("failed install attempt requires an operation reason")++@dataclass(frozen=True)class ShowRuntimeArchive:platform: str@@ -226,6 +260,7 @@ class ShowRuntimeAvailability:policy_reason: str | None = Noneinstall_reason: str | None = Noneinstall_failure_class: ShowRuntimeFailureClass | None = None+ install_dir: str | None = Noneinstall_runtime_version: str | None = Noneinstall_matches_manifest: bool | None = Noneruntime_reason: str | None = None@@ -250,6 +285,7 @@ class ShowRuntimeAvailability:install: ShowRuntimeInstallState | None = None,policy_reason: str | None = None,install_reason: str | None = None,+ install_dir: Path | str | None = None,install_runtime_version: str | None = None,install_matches_manifest: bool | None = None,) -> "ShowRuntimeAvailability":@@ -269,6 +305,7 @@ class ShowRuntimeAvailability:install_failure_class=(classify_show_runtime_failure(install_reason) if install is ShowRuntimeInstallState.FAILED else None),+ install_dir=str(install_dir) if install_dir is not None else None,install_runtime_version=install_runtime_version,install_matches_manifest=install_matches_manifest,)@@ -282,6 +319,7 @@ class ShowRuntimeAvailability:"reason": self.install_reason,"failure_class": self.install_failure_class.value if self.install_failure_class else None,"command": command,+ "install_dir": self.install_dir,"runtime_version": self.install_runtime_version,"matches_manifest": self.install_matches_manifest,},@@ -785,7 +823,7 @@ class ShowRuntimeManager:)if command:return self._publish_install_availability(command=command)- admission = await asyncio.to_thread(+ admission, _operation = await asyncio.to_thread(self._attempt_managed_install,force=self.force_install,offline=self.offline,@@ -807,7 +845,7 @@ class ShowRuntimeManager:)return admissionif self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:- admission = await asyncio.to_thread(+ admission, _operation = await asyncio.to_thread(self._attempt_managed_install,force=self.force_install,offline=self.offline,@@ -837,7 +875,7 @@ class ShowRuntimeManager:command = self._installed_github_runtime_command()if command:return self._publish_install_availability(command=command)- admission = await asyncio.to_thread(+ admission, _operation = await asyncio.to_thread(self._attempt_managed_install,force=self.force_install,offline=self.offline,@@ -855,48 +893,122 @@ class ShowRuntimeManager:force: bool,offline: bool,automatic: bool = False,- ) -> ShowRuntimeAvailability:+ ) -> tuple[ShowRuntimeAvailability, _ShowRuntimeOperationOutcome]:if self._command_explicit:command = _resolve_command(self.command)- return self._publish_install_availability(+ availability = self._publish_install_availability(command=command,install_reason=None if command else "runtime_command_missing",)+ if force:+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.NOT_APPLICABLE,+ "VIBE_SHOW_RUNTIME_BIN",+ )+ elif command:+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.COMPLETED,+ None,+ )+ else:+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.FAILED,+ "runtime_command_missing",+ )+ return availability, operationskipped_reason = self._managed_install_opt_out_reason(automatic=automatic)if skipped_reason:- return self._publish_policy_skip(skipped_reason)+ return self._publish_policy_skip(skipped_reason), _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.NOT_APPLICABLE,+ skipped_reason,+ )if self._managed_command and not force:- return self._publish_install_availability(command=self._managed_command)+ availability = self._publish_install_availability(command=self._managed_command)+ operation = _ShowRuntimeOperationOutcome(_ShowRuntimeOperationState.COMPLETED, None)+ return availability, operationif automatic and not force and self._install_attempted:- return self._publish_install_availability(- install_reason=self._install_reason or "runtime_install_failed"+ reason = self._install_reason or "runtime_install_failed"+ availability = self._publish_install_availability(install_reason=reason)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.FAILED,+ reason,)+ return availability, operationwith self._install_guard_locked() as (acquired, guard_reason):if not acquired:command = None if force else self._installed_managed_runtime_command(offline=offline)if command:- return self._publish_install_availability(command=command)- return self._publish_install_availability(install_reason=guard_reason)+ availability = self._publish_install_availability(command=command)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.COMPLETED,+ None,+ )+ return availability, operation+ reason = guard_reason or "runtime_install_guard_unavailable"+ availability = self._publish_install_availability(install_reason=reason)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.FAILED,+ reason,+ )+ return availability, operationskipped_reason = self._managed_install_opt_out_reason(automatic=automatic)if skipped_reason:- return self._publish_policy_skip(skipped_reason)+ return self._publish_policy_skip(skipped_reason), _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.NOT_APPLICABLE,+ skipped_reason,+ )if self._managed_command and not force:- return self._publish_install_availability(command=self._managed_command)+ availability = self._publish_install_availability(command=self._managed_command)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.COMPLETED,+ None,+ )+ return availability, operationif automatic and not force and self._install_attempted:- return self._publish_install_availability(- install_reason=self._install_reason or "runtime_install_failed"+ reason = self._install_reason or "runtime_install_failed"+ availability = self._publish_install_availability(install_reason=reason)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.FAILED,+ reason,)+ return availability, operationif automatic:self._install_attempted = True- command = self._install_managed_runtime_locked(force=force, offline=offline)- if command:- return self._publish_install_availability(command=command)- return self._publish_install_availability(- install_reason=self._install_reason or "runtime_install_failed"+ raw_attempt = self._install_managed_runtime_locked(+ force=force,+ offline=offline,+ automatic=automatic,+ )+ attempt = (+ raw_attempt+ if isinstance(raw_attempt, _ManagedInstallAttempt)+ else _ManagedInstallAttempt(+ raw_attempt,+ None if raw_attempt else self._install_reason or "runtime_install_failed",+ )+ )+ if attempt.command:+ availability = self._publish_install_availability(command=attempt.command)+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.COMPLETED,+ None,+ )+ return availability, operation+ reason = attempt.operation_reason+ installed_command = self._installed_managed_runtime_command(offline=True)+ availability = (+ self._publish_install_availability(command=installed_command)+ if installed_command+ else self._publish_install_availability(install_reason=reason))+ operation = _ShowRuntimeOperationOutcome(+ _ShowRuntimeOperationState.FAILED,+ reason,+ )+ return availability, operationdef _managed_install_opt_out_reason(self, *, automatic: bool) -> str | None:if automatic and _env_flag_enabled("VIBE_INSTALL_SKIP_SHOW_RUNTIME", default=False):@@ -962,23 +1074,75 @@ class ShowRuntimeManager:self._availability = availabilityreturn availability- def _install_managed_runtime_locked(self, *, force: bool, offline: bool) -> list[str] | None:+ def _managed_install_operation_command(+ self,+ command: list[str] | None,+ *,+ replacement_required: bool,+ replacement_completed: bool = False,+ ) -> list[str] | None:+ """Return a command only when it satisfies the requested operation.++ An ordinary prepare asks only for an available runtime, so a verified+ existing command is sufficient even when a refresh fails. A forced+ prepare asks for replacement; reusing the old command must preserve the+ failure and report that operation as unsuccessful.+ """+ if not command or (replacement_required and not replacement_completed):+ return None+ self._install_reason = None+ return command++ def _remove_managed_runtime_tree_for_replacement(self, path: Path, *, label: str) -> bool:+ """Invalidate cached install facts before removing managed runtime bytes."""+ self._managed_command = None+ self._availability = replace(+ self._availability,+ install=ShowRuntimeInstallState.ABSENT,+ command=None,+ install_reason=None,+ install_failure_class=None,+ )+ try:+ if os.path.lexists(path):+ shutil.rmtree(path)+ except OSError:+ logger.warning("Failed to remove the %s Show Runtime tree before replacement", label, exc_info=True)+ self._install_reason = "runtime_install_failed"+ return False+ if os.path.lexists(path):+ self._install_reason = "runtime_install_failed"+ return False+ return True++ def _install_managed_runtime_locked(+ self,+ *,+ force: bool,+ offline: bool,+ automatic: bool = False,+ ) -> _ManagedInstallAttempt:command: list[str] | Noneif self.runtime_source == _RUNTIME_SOURCE_MANIFEST:command = self._install_manifest_runtime_locked(force=force, offline=offline)elif self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:- command = self._install_archive_runtime(offline=offline)+ command = self._install_archive_runtime(force=force, offline=offline)elif self.runtime_source == _RUNTIME_SOURCE_GITHUB:- command = self._install_github_runtime(force=force)+ attempt = self._install_github_runtime(force=force)+ if attempt.command:+ self._download_error = None+ self._clean_after_managed_install(attempt.command)+ return attemptelif self.runtime_source == _RUNTIME_SOURCE_NPM:- command = self._install_npm_runtime()+ command = self._install_npm_runtime(force=force)else:self._install_reason = "runtime_source_unsupported"- return None+ return _ManagedInstallAttempt(None, self._install_reason)if command:self._download_error = Noneself._clean_after_managed_install(command)- return command+ return _ManagedInstallAttempt(command)+ return _ManagedInstallAttempt(None, self._install_reason or "runtime_install_failed")def _installed_managed_runtime_command(self, *, offline: bool) -> list[str] | None:if self.runtime_source == _RUNTIME_SOURCE_MANIFEST:@@ -1039,6 +1203,7 @@ class ShowRuntimeManager:archive_status: dict[str, Any] | None = Noneinstalled_runtime_version: str | None = Noneinstalled_matches: bool | None = None+ github_source_status: dict[str, Any] | None = Noneinstalled = configured_command is not Nonemanifest_status = _manifest_status_payload(manifest)if not configured_command and self.runtime_source == _RUNTIME_SOURCE_MANIFEST:@@ -1080,6 +1245,7 @@ class ShowRuntimeManager:installed_dir = self._github_source_dir()installed_command = self._github_runtime_command(installed_dir, node or ["node"])installed = installed_command is not None+ github_source_status = self._github_source_status(installed_dir)elif not configured_command and self.runtime_source == _RUNTIME_SOURCE_NPM:managed = _resolve_executable_path(self._managed_bin_path())installed_command = [managed] if managed else None@@ -1089,6 +1255,7 @@ class ShowRuntimeManager:install_payload = ShowRuntimeAvailability.from_install(command=installed_command,install=(ShowRuntimeInstallState.INSTALLED if installed else ShowRuntimeInstallState.ABSENT),+ install_dir=installed_dir if installed else None,install_runtime_version=installed_runtime_version,install_matches_manifest=installed_matches,).as_payload()["install"]@@ -1101,15 +1268,13 @@ class ShowRuntimeManager:"node_supported": node_supported,"manifest": manifest_status,"archive": archive_status or _archive_status_payload(archive),+ "github_source": github_source_status,"install": install_payload,"runtime": {"state": ShowRuntimeServingState.UNCHECKED.value,"reason": None,"base_url": None,},- "installed": installed,- "installed_matches_manifest": install_payload["matches_manifest"],- "install_dir": str(installed_dir) if installed_dir else None,"command": installed_command,"reason": self._install_reason,"download_error": self._download_error,@@ -1987,12 +2152,15 @@ class ShowRuntimeManager:) -> dict[str, Any]:effective_force = self.force_install if force is None else forceeffective_offline = self.offline if offline is None else offline- admission = self._attempt_managed_install(+ admission, operation = self._attempt_managed_install(force=effective_force,offline=effective_offline,automatic=automatic,)payload = admission.as_payload()+ payload["ok"] = operation.ok+ if not operation.ok:+ payload["reason"] = operation.reasonstatus_offline = True if admission.policy is ShowRuntimePolicyState.SKIPPED else effective_offlinepayload.update({@@ -2264,7 +2432,10 @@ class ShowRuntimeManager:if not archive:return Nonecommand = self._verified_manifest_runtime_command_for_manifest(manifest, archive, node)- return self._reuse_existing_archive_runtime(command)+ return self._managed_install_operation_command(+ command,+ replacement_required=False,+ )except Exception:return None@@ -2296,11 +2467,16 @@ class ShowRuntimeManager:)else:self._write_current_manifest_pointer(manifest, archive, verified_install_dir)- self._install_reason = None- return verified_existing_command+ return self._managed_install_operation_command(+ verified_existing_command,+ replacement_required=False,+ )archive_path = self._resolve_manifest_archive(archive, offline=offline)if not archive_path:- return self._reuse_existing_archive_runtime(verified_existing_command)+ return self._managed_install_operation_command(+ verified_existing_command,+ replacement_required=force,+ )self.runtime_dir.mkdir(parents=True, exist_ok=True)tmp_dir = Path(tempfile.mkdtemp(prefix="manifest-", dir=self.runtime_dir))try:@@ -2309,19 +2485,37 @@ class ShowRuntimeManager:command = self._manifest_runtime_command(tmp_dir, node)if not command:self._install_reason = "runtime_install_missing_bin"- return self._reuse_existing_archive_runtime(verified_existing_command)- if install_dir.exists():- shutil.rmtree(install_dir)+ return self._managed_install_operation_command(+ verified_existing_command,+ replacement_required=force,+ )+ if os.path.lexists(install_dir):+ if not self._remove_managed_runtime_tree_for_replacement(install_dir, label="manifest"):+ return self._managed_install_operation_command(+ None,+ replacement_required=force,+ )+ verified_existing_command = Noneinstall_dir.parent.mkdir(parents=True, exist_ok=True)shutil.move(str(tmp_dir), str(install_dir))self._write_manifest_install_metadata(install_dir, manifest, archive)self._write_current_manifest_pointer(manifest, archive, install_dir)- self._install_reason = None- return self._manifest_runtime_command(install_dir, node)+ installed_command = self._manifest_runtime_command(install_dir, node)+ if not installed_command:+ self._install_reason = "runtime_install_missing_bin"+ # The staged tree was moved onto the managed identity before this command resolved.+ return self._managed_install_operation_command(+ installed_command,+ replacement_required=force,+ replacement_completed=force and installed_command is not None,+ )except Exception:logger.exception("Failed to install manifest Show Runtime")self._install_reason = "runtime_install_failed"- return self._reuse_existing_archive_runtime(verified_existing_command)+ return self._managed_install_operation_command(+ verified_existing_command,+ replacement_required=force,+ )finally:if tmp_dir.exists():shutil.rmtree(tmp_dir, ignore_errors=True)@@ -2585,7 +2779,7 @@ class ShowRuntimeManager:return Nonereturn self._archive_runtime_command(self._archive_install_dir(), node)- def _install_archive_runtime(self, *, offline: bool | None = None) -> list[str] | None:+ def _install_archive_runtime(self, *, force: bool, offline: bool | None = None) -> list[str] | None:node = _resolve_node_command()if not node:self._install_reason = "runtime_node_missing"@@ -2595,11 +2789,16 @@ class ShowRuntimeManager:existing_command = self._archive_runtime_command(install_dir, node)archive = self._resolve_prebuilt_archive(offline=offline)if not archive:- return self._reuse_existing_archive_runtime(existing_command)+ return self._managed_install_operation_command(+ existing_command,+ replacement_required=force,+ )archive_digest = _file_sha256(archive)- if existing_command and self._archive_manifest_matches(archive_digest):- self._install_reason = None- return existing_command+ if not force and existing_command and self._archive_manifest_matches(archive_digest):+ return self._managed_install_operation_command(+ existing_command,+ replacement_required=False,+ )tmp_dir = Path(tempfile.mkdtemp(prefix="prebuilt-", dir=self.runtime_dir))try:with tarfile.open(archive, "r:gz") as tar:@@ -2607,18 +2806,36 @@ class ShowRuntimeManager:command = self._archive_runtime_command(tmp_dir, node)if not command:self._install_reason = "runtime_install_missing_bin"- return self._reuse_existing_archive_runtime(existing_command)- if install_dir.exists():- shutil.rmtree(install_dir)+ return self._managed_install_operation_command(+ existing_command,+ replacement_required=force,+ )+ if os.path.lexists(install_dir):+ if not self._remove_managed_runtime_tree_for_replacement(install_dir, label="archive"):+ return self._managed_install_operation_command(+ None,+ replacement_required=force,+ )+ existing_command = Noneinstall_dir.parent.mkdir(parents=True, exist_ok=True)shutil.move(str(tmp_dir), str(install_dir))self._write_archive_manifest(archive_digest)- self._install_reason = None- return self._archive_runtime_command(install_dir, node)+ installed_command = self._archive_runtime_command(install_dir, node)+ if not installed_command:+ self._install_reason = "runtime_install_missing_bin"+ # The staged tree was moved onto the managed identity before this command resolved.+ return self._managed_install_operation_command(+ installed_command,+ replacement_required=force,+ replacement_completed=force and installed_command is not None,+ )except Exception:logger.exception("Failed to install prebuilt Show Runtime")self._install_reason = "runtime_install_failed"- return self._reuse_existing_archive_runtime(existing_command)+ return self._managed_install_operation_command(+ existing_command,+ replacement_required=force,+ )finally:if tmp_dir.exists():shutil.rmtree(tmp_dir, ignore_errors=True)@@ -2703,50 +2920,86 @@ class ShowRuntimeManager:return Nonereturn [*node, str(cli_path)]- def _reuse_existing_archive_runtime(self, command: list[str] | None) -> list[str] | None:- if command:- self._install_reason = None- return command- return None-def _installed_github_runtime_command(self) -> list[str] | None:node = _resolve_node_command()if not node:return Nonereturn self._github_runtime_command(self._github_source_dir(), node)- def _install_github_runtime(self, *, force: bool | None = None) -> list[str] | None:+ def _github_install_attempt(+ self,+ command: list[str] | None,+ *,+ replacement_required: bool,+ replacement_completed: bool = False,+ operation_reason: str | None = None,+ ) -> _ManagedInstallAttempt:+ resolved = self._managed_install_operation_command(+ command,+ replacement_required=replacement_required,+ replacement_completed=replacement_completed,+ )+ if resolved:+ return _ManagedInstallAttempt(resolved)+ reason = operation_reason or self._install_reason or "runtime_install_failed"+ self._install_reason = None+ return _ManagedInstallAttempt(None, reason)++ def _install_github_runtime(+ self,+ *,+ force: bool | None = None,+ ) -> _ManagedInstallAttempt:+ replacement_required = self.force_install if force is None else forcenode = _resolve_node_command()if not node:self._install_reason = "runtime_node_missing"- return None+ return self._github_install_attempt(None, replacement_required=replacement_required)self.runtime_dir.mkdir(parents=True, exist_ok=True)source_dir = self._github_source_dir()existing_command = self._github_runtime_command(source_dir, node)git = _resolve_command("git")npm = _resolve_command("npm")if not git:- if existing_command:- self._install_reason = None- return existing_commandself._install_reason = "runtime_git_missing"- return None+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ )if not npm:- if existing_command:- self._install_reason = None- return existing_commandself._install_reason = "runtime_npm_missing"- return None+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ )if not source_dir.exists():source_dir.parent.mkdir(parents=True, exist_ok=True)- if not self._run_install_command([*git, "clone", "--depth", "1", "--branch", self.github_ref, self.github_repo, str(source_dir)]):- return None+ if not self._run_install_command(+ [*git, "clone", "--depth", "1", "--branch", self.github_ref, self.github_repo, str(source_dir)]+ ):+ return self._github_install_attempt(+ None,+ replacement_required=replacement_required,+ )else:if not self._run_install_command([*git, "-C", str(source_dir), "fetch", "--depth", "1", "origin", self.github_ref]):- return self._reuse_existing_github_runtime(existing_command)+ self._install_reason = None+ update_failure_reason = "runtime_github_source_update_failed"+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ operation_reason=update_failure_reason,+ )fetched = self._git_revision(git, source_dir, "FETCH_HEAD")+ if not fetched:+ update_failure_reason = "runtime_github_source_update_failed"+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ operation_reason=update_failure_reason,+ )if (- not (self.force_install if force is None else force)+ not replacement_requiredand existing_commandand fetchedand self._read_github_build_marker(source_dir) == fetched@@ -2754,25 +3007,54 @@ class ShowRuntimeManager:# The runtime already on disk was built from exactly this# commit, so `npm ci` and `npm run build` would spend a minute# reproducing it byte for byte.- self._install_reason = None- return existing_command+ return self._github_install_attempt(+ existing_command,+ replacement_required=False,+ )if not self._run_install_command([*git, "-C", str(source_dir), "checkout", "FETCH_HEAD"]):- return self._reuse_existing_github_runtime(existing_command)+ self._install_reason = None+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ operation_reason="runtime_github_source_update_failed",+ )# From here on the artifact the marker describes is being replaced:# ``npm ci`` empties node_modules and the build writes into dist. Drop# the marker first so a failure anywhere below leaves "unknown" rather# than a commit that no longer describes what is on disk.self._write_github_build_marker(source_dir, None)+ if replacement_required:+ build_output = source_dir / "packages" / "runtime" / "dist"+ if not self._remove_managed_runtime_tree_for_replacement(build_output, label="GitHub"):+ return self._github_install_attempt(+ None,+ replacement_required=True,+ )+ existing_command = Noneif not self._run_install_command([*npm, "ci"], cwd=source_dir):- return self._reuse_existing_github_runtime(existing_command)+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ )if not self._run_install_command([*npm, "run", "build"], cwd=source_dir):- return self._reuse_existing_github_runtime(existing_command)+ return self._github_install_attempt(+ existing_command,+ replacement_required=replacement_required,+ )command = self._github_runtime_command(source_dir, node)if not command:self._install_reason = "runtime_install_missing_bin"- return None+ return self._github_install_attempt(+ None,+ replacement_required=replacement_required,+ )self._write_github_build_marker(source_dir, self._git_revision(git, source_dir, "HEAD"))- return command+ # A forced build starts with no dist tree, so resolving this command proves replacement.+ return self._github_install_attempt(+ command,+ replacement_required=replacement_required,+ replacement_completed=replacement_required,+ )def _github_build_marker_path(self, source_dir: Path) -> Path:return source_dir / ".avibe-runtime-build"@@ -2803,6 +3085,9 @@ class ShowRuntimeManager:except OSError:pass+ def _github_source_status(self, source_dir: Path) -> dict[str, Any]:+ return {"built_revision": self._read_github_build_marker(source_dir)}+def _git_revision(self, git: list[str], source_dir: Path, ref: str) -> str | None:try:result = subprocess.run(@@ -2825,49 +3110,73 @@ class ShowRuntimeManager:return Nonereturn [*node, str(cli_path)]- def _reuse_existing_github_runtime(self, command: list[str] | None) -> list[str] | None:- if command:- self._install_reason = None- return command- return None-- def _install_npm_runtime(self) -> list[str] | None:+ def _install_npm_runtime(self, *, force: bool | None = None) -> list[str] | None:+ replacement_required = self.force_install if force is None else forcenpm = _resolve_command("npm")if not npm:self._install_reason = "runtime_npm_missing"- return None+ return self._managed_install_operation_command(+ None,+ replacement_required=replacement_required,+ )self.runtime_dir.mkdir(parents=True, exist_ok=True)install_root = self.runtime_dir / "package"install_root.mkdir(parents=True, exist_ok=True)package_json = install_root / "package.json"if not package_json.exists():package_json.write_text('{"private":true,"type":"module"}\n', encoding="utf-8")- with self.install_log_path.open("w", encoding="utf-8") as log:- result = subprocess.run(- [- *npm,- "install",- "--prefix",- str(install_root),- "--no-audit",- "--no-fund",- self.package_spec,- ],- stdout=log,- stderr=subprocess.STDOUT,- text=True,- timeout=180,- check=False,- **isolated_subprocess_kwargs(),+ if replacement_required:+ managed_tree = install_root / "node_modules"+ if not self._remove_managed_runtime_tree_for_replacement(managed_tree, label="npm"):+ return self._managed_install_operation_command(+ None,+ replacement_required=True,+ )+ try:+ with self.install_log_path.open("w", encoding="utf-8") as log:+ result = subprocess.run(+ [+ *npm,+ "install",+ "--prefix",+ str(install_root),+ "--no-audit",+ "--no-fund",+ self.package_spec,+ ],+ stdout=log,+ stderr=subprocess.STDOUT,+ text=True,+ timeout=180,+ check=False,+ **isolated_subprocess_kwargs(),+ )+ except (OSError, subprocess.SubprocessError):+ logger.warning("Failed to install the npm Show Runtime", exc_info=True)+ self._install_reason = "runtime_install_failed"+ return self._managed_install_operation_command(+ None,+ replacement_required=replacement_required,)if result.returncode != 0:self._install_reason = "runtime_install_failed"- return None+ return self._managed_install_operation_command(+ None,+ replacement_required=replacement_required,+ )resolved = _resolve_executable_path(self._managed_bin_path())if not resolved:self._install_reason = "runtime_install_missing_bin"- return None- return [resolved]+ return self._managed_install_operation_command(+ None,+ replacement_required=replacement_required,+ )+ # A forced install starts with no node_modules tree, so this command proves replacement.+ return self._managed_install_operation_command(+ [resolved],+ replacement_required=replacement_required,+ replacement_completed=replacement_required,+ )def _managed_bin_path(self) -> Path:suffix = ".cmd" if os.name == "nt" else ""@@ -2880,18 +3189,23 @@ class ShowRuntimeManager:return self.runtime_dir / "source" / "github" / repo_part / ref_partdef _run_install_command(self, command: list[str], *, cwd: Path | None = None) -> bool:- with self.install_log_path.open("a", encoding="utf-8") as log:- log.write(f"$ {' '.join(command)}\n")- result = subprocess.run(- command,- cwd=str(cwd) if cwd else None,- stdout=log,- stderr=subprocess.STDOUT,- text=True,- timeout=300,- check=False,- **isolated_subprocess_kwargs(),- )+ try:+ with self.install_log_path.open("a", encoding="utf-8") as log:+ log.write(f"$ {' '.join(command)}\n")+ result = subprocess.run(+ command,+ cwd=str(cwd) if cwd else None,+ stdout=log,+ stderr=subprocess.STDOUT,+ text=True,+ timeout=300,+ check=False,+ **isolated_subprocess_kwargs(),+ )+ except (OSError, subprocess.SubprocessError):+ logger.warning("Show Runtime install command failed", exc_info=True)+ self._install_reason = "runtime_install_failed"+ return Falseif result.returncode != 0:self._install_reason = "runtime_install_failed"return Falsediff --git a/docs/plans/show-runtime-availability.md b/docs/plans/show-runtime-availability.mdindex bec6d9faa..8fecea147 100644--- a/docs/plans/show-runtime-availability.md+++ b/docs/plans/show-runtime-availability.md@@ -759,12 +759,11 @@ determine" is never reported as `runtime_start_failed`; it carriesfailure nobody observed is the same lie as claiming a replacement nobodyperformed.-**The destructive transition is itself a boundary, and it owns three things.**-Making replacement structural moved real destruction into the install path, and the-code around it still assumed nothing is ever removed. Three findings landed on the-same seam — a stale cache, unverified build inputs, and delegate failures escaping —-so the boundary that performs the destruction owns all three rather than each-provider handling its own.+**The destructive transition is itself a boundary.** Making replacement structural+moved real destruction into the install path, and the code around it still assumed+nothing is ever removed. The shipped boundary owns cache invalidation and delegate+failures; authorization to move a developer-visible checkout leaves for the successor+section below.*Invalidate before destroying.* `_managed_command` is a manager-level cache read atseven sites as proof that installed bytes exist, including `ensure()`'s spawn fast@@ -778,6 +777,17 @@ same insight one level up, which is where every fix in this section has ended upis invalidated before the artifact is destroyed, not after the replacement isjudged.**+#### Successor: protect the managed GitHub checkout++The baseline this successor must replace is deliberately named rather than implied.+Once the cheap build-marker short-circuit stops matching, master runs+`git checkout FETCH_HEAD` without authorization. A developer with local commits in the+managed checkout can therefore have them displaced by any `/show/` request. Removing+checkout ownership from 2b′ does not introduce that hazard because none of this work+has merged, but it does leave the known pre-existing behavior unfixed. Protecting the+managed checkout is the successor's headline; a three-valued decision type is the+means, not the project.+*Refuse rather than coerce.* Deleting the build output proves the build wrote output;it says nothing about what the build was fed. `git checkout FETCH_HEAD` keeps localmodifications to tracked files, and at the same revision it changes nothing at all,@@ -929,12 +939,140 @@ a stale record and a clean directory would let a loose assertion pass on the brocode. If a fourth head lands another exit-invariant violation, the remedy stops being amove and becomes one update-outcome owner that cannot be bypassed.+The fourth findings-bearing head exposed two remaining boundaries and closes this+class with two rules whose enforcement is structural rather than conventional.+First, an unknown revision is absence of evidence, not a value that may compare+equal to another unknown. `_git_revision` failure becomes a structured source-update+failure before any checkout-record comparison. Revision comparisons live only on the+checkout-record type, whose authorization methods accept a proven string revision;+callers do not compare `revision` or `pending` fields directly. This makes a normal+stable record with `pending = null` incapable of authorizing an unreadable `HEAD`.++Second, checkout creation and ownership publication are one transition. Avibe clones+into a same-parent staging directory, writes the schema-versioned ownership record+inside that checkout, and only then renames the complete directory to `source_dir`.+Therefore an Avibe-published `source_dir` is never externally reachable without its+ownership evidence. Best-effort staging cleanup is hygiene rather than correctness:+if cloning, revision inspection, record persistence, or publication fails, the final+path was never exposed and the next attempt can retry without adopting or deleting an+unverified checkout. Existing unverified directories remain user-owned evidence and+are not mutated by a healing shortcut.++This is the final in-PR consolidation for checkout evidence and the destructive+boundary. If a fifth findings-bearing head produces another instance of this class,+the two-valued record model itself must be reconsidered; another exit guard is not an+acceptable remedy.++The fifth head fired that tripwire, so the promise is discharged here: the+two-valued record was reconsidered and the evidence exonerates it. No finding+on any of five heads has been about `revision` / `pending` semantics. The+tripwire fired on the wrong axis because it bounded an artifact — "the record"+— when the property at risk was every piece of evidence about the checkout,+wherever it is stored. A governance rule that names an artifact instead of a+property is the same inadequate-proxy defect this document is about, one level+up.++What head five actually showed is cheaper to state: each of its three findings+is a rule already written above, applied at the site a reviewer named rather+than owned by a module. An unowned rule buys exactly one more review round, so+three unowned rules bought this one. The closing rules therefore name owners.+Checkout evidence lives inside the checkout it describes, so a successful+publish retires it by rename and no deletion is a transaction boundary. A+dimension of state has no flat mirror beside its structured payload, so a+consumer cannot reach a location without holding the state that makes the+location meaningful. Artifact provenance is published from the build marker and+cited from nowhere else, so a revision claim cannot be satisfied by checkout+identity. Each remedy removes a mechanism or publishes an owner that already+existed; none adds a branch.++New boundary, stated as a property rather than an artifact: a rule enters this+document with the name of the module that makes violating it impossible. If a+sixth head returns either a rule with no named owner or a payload field whose+meaning depends on a sibling field, the update record and the status payload+leave this PR and become their own change.++The sixth head fired that boundary. The persisted update record used+`state = "skipped"` for both a known target that checkout takeover refused and+a fetch or revision-inspection failure whose target might not exist. A consumer+could interpret that field only by pairing it with `reason` and the nullable+`target_revision`, so the state was another inadequate proxy. The record, its+`github_source.update` status member, and the prepare/status copy leave this PR+rather than acquiring a failure-specific consumer branch.++The install dimension stays. Its location is a different member of the status+payload, its flat mirrors were removed on head five, and no later finding has+implicated its owner or consumers. The checkout record, build-marker+provenance, and operation outcome contract stay for the same reason: the sixth+finding disproves none of them. This is a split by the property that recurred,+not a rollback of adjacent owners that have held.++The follow-up starts from the reason the update record existed, not from its+schema. Doctor can already report a failed managed update from the immediate+operation reason, but an ordinary prepare may still succeed by reusing the old+runtime and therefore clears that top-level failure. The record persisted that+degraded side effect so a later status call could repeat it. That past event is+not current state: `vibe runtime status` performs no network I/O and cannot know+whether an update is available. The leading design is therefore for the+operation to report its degraded side effect in band to the caller that just+performed the fetch, while status makes no update claim it cannot verify. The+follow-up may depart from that design only with a stated reason.++The next boundary is again a property: if a seventh findings-bearing head+returns a finding against one of the remaining owners -- checkout evidence,+the install dimension, build provenance, or the operation outcome contract --+that owner leaves this PR as its own change. Another site-level patch is not an+acceptable remedy.+The reason this one predicate absorbed seven probes is worth naming even though it isout of scope here: one directory is both Avibe's build input and a place a developermay work, so every rule about it has to infer which role it is in. An eighth inputwould be another inference. If the predicate needs narrowing again, the answer is tostop conflating the two roles, not to add a term.+The seventh findings-bearing head fired that boundary, but on a different axis than+the artifact and owner boundaries above. One two-valued type repeatedly carried a+three-valued reality, and every consumer promoted "cannot determine" to one of the two+definite answers:++| Type | Two represented values | The third value it could not represent |+| --- | --- | --- |+| `ok: bool` | available / unavailable | the requested operation did not run |+| raw `revision` / `pending` comparison | equal / different | neither revision is known |+| update `state = "skipped"` | skipped / absent | fetch never produced a target |+| takeover `allowed: bool` | permitted / refused | ownership could not be determined |+| `install_dir` beside `installed` | present / absent | intended, not achieved |+| `current_revision` used as provenance | a revision / none | checked out but never built |++The governance boundary named the wrong axis twice. Head five bounded the update+record when the property covered every piece of checkout evidence; head six bounded+owners when the recurring risk lived in the two-valued type those owners shared. The+seventh finding made the consequence concrete: a failed legacy ownership-record write+returned `allowed = false`; the automatic consumer treated that as developer-owned,+skipped the checkout, cleared the released build marker, and used the same boolean to+decide not to restore it. One boolean gated both moving the checkout and destroying+build evidence even though those actions have different safety conditions.++That gate and its ownership-record subgraph leave 2b′. The finding disappears with+the gate: the retained path returns to master's unconditional build-marker restoration,+so there is no site-level branch to patch. The successor takes the takeover decision,+its consumers, and ownership-record transactionality. It starts with a named outcome+of **proven / refused / undetermined** and structurally separates "may move this+checkout" from "may destroy build evidence". Undetermined answers no to both. A write+failure while adopting legacy evidence therefore returns the existing command+untouched, preserves the marker, and recovers when permissions recover. Departing from+that shape requires a stated reason.++2b′ keeps the install dimension, build-marker provenance, the operation outcome+contract, provider replacement evidence, destructive cache invalidation and delegate+failure normalization, and Doctor's first-install/reinstall copy split. These owners+have drawn no finding for two heads, and 2c depends on the operation contract rather+than checkout ownership. The successor may consume the shipped `_github_install_attempt`,+generic update-failure reason, `_git_revision`, and `_read_github_build_marker`; those+are one-way dependencies on retained contracts, not checkout ownership leaking back+into 2b′.++#### Shipped in 2b′+*One execution boundary for delegated work.* The shared install-command helperalready passed a five-minute timeout and let `TimeoutExpired` escape — someonedecided a hung subprocess must not block forever and never decided what that means@@ -1170,7 +1308,8 @@ exposure predates these PRs and shipping the truthful row strictly reduces it.| 1 | W2 | avibe | Small, surgical, unit-testable. Start here. || 2a | W4 admission outcome | avibe | The policy/install/runtime contract and every consumer projecting from it. || 2b | W5 readiness proof | avibe | `ensure()` health-probes a fresh start; `doctor` inherits it. Independent of 2a. Bounded retry plus Doctor's three-state startability; claims nothing about replacement. |-| 2b′ | W4 replacement operation contract | avibe | What `prepare()` claims, what a provider must prove, and the destructive boundary. Split out of 2b after six findings-bearing heads. |+| 2b′ | W4 replacement operation contract | avibe | What `prepare()` claims, what a provider must prove, install-state ownership, build provenance, and destructive cache/delegate boundaries. Split out of 2b after six findings-bearing heads; checkout ownership is not shipped here. |+| 2b″ | Protect the managed GitHub checkout | avibe | Replace master's unconditional checkout takeover with a three-valued decision that keeps undetermined ownership away from both checkout movement and build-evidence destruction. || 2c | W4 retry + W5 page | avibe | Retry classification and the recovery page/poll, on top of 2a's reason. || 3 | W1 | vibe-show-runtime | Independent; effect appears at the next runtime release. || 4 | W3.1 | avibe | Source ladder. Valuable on its own — removes the single point of failure using only tiers that exist today. |diff --git a/tests/test_local_deps.py b/tests/test_local_deps.pyindex 837ab1448..8032090be 100644--- a/tests/test_local_deps.py+++ b/tests/test_local_deps.py@@ -1173,8 +1173,7 @@ def test_dependencies_status_shape(monkeypatch):class _Mgr:def status(self):return {- "installed": True,- "install": {"runtime_version": "1.4.0", "matches_manifest": True},+ "install": {"state": "installed", "runtime_version": "1.4.0", "matches_manifest": True},"manifest": {"runtime_version": "1.4.0"},"node_available": True,"node_version": "20.11",@@ -1225,8 +1224,7 @@ def test_dependencies_status_shape(monkeypatch):pytest.param({"provider": "manifest-cache",- "installed": True,- "install": {"runtime_version": "runtime-installed", "matches_manifest": False},+ "install": {"state": "installed", "runtime_version": "runtime-installed", "matches_manifest": False},"manifest": {"runtime_version": "runtime-selected"},"node_available": True,"node_supported": True,@@ -1238,8 +1236,7 @@ def test_dependencies_status_shape(monkeypatch):pytest.param({"provider": "github-source",- "installed": True,- "install": {"runtime_version": None, "matches_manifest": None},+ "install": {"state": "installed", "runtime_version": None, "matches_manifest": None},"manifest": None,"node_available": True,"node_supported": True,@@ -1554,6 +1551,31 @@ def test_prepare_show_runtime_job_surfaces_retry_diagnostics(monkeypatch):assert "after 3 attempts" in result["message"]+def test_prepare_show_runtime_job_reports_failed_replacement_with_old_install(monkeypatch):+ import core.show_runtime as show_runtime++ manager = Mock()+ manager.prepare.return_value = {+ "ok": False,+ "reason": "runtime_archive_download_failed",+ "install": {+ "state": "installed",+ "reason": None,+ },+ "status": {+ "installed": True,+ "command": ["node", "runtime-cli.js"],+ },+ }+ monkeypatch.setattr(show_runtime, "get_show_runtime_manager", lambda: manager)++ result = api._prepare_show_runtime_job()++ assert result["ok"] is False+ assert result["reason"] == "runtime_archive_download_failed"+ assert "runtime_archive_download_failed" in result["message"]++def test_start_dependency_install_job_runs_askill(monkeypatch):import time as _tdiff --git a/tests/test_show_runtime_archive_cleanup.py b/tests/test_show_runtime_archive_cleanup.pyindex 4166ae129..c236e971c 100644--- a/tests/test_show_runtime_archive_cleanup.py+++ b/tests/test_show_runtime_archive_cleanup.py@@ -535,9 +535,11 @@ def test_install_guard_unavailable_falls_back_to_verified_install(tmp_path: Pathreal_open = os.openmonkeypatch.setattr(os, "open", _unwritable_open)- command = manager._attempt_managed_install(force=False, offline=True).command+ availability, operation = manager._attempt_managed_install(force=False, offline=True)+ command = availability.commandassert command is not None and command[-1].endswith("cli.js")+ assert operation.ok is Truedef test_partial_removal_reports_removed_and_failed_counts(monkeypatch, capsys) -> None:@@ -670,9 +672,11 @@ def test_forced_prepare_fails_structured_when_guard_unavailable(tmp_path: Path,monkeypatch.setattr("os.open", _unwritable_open)- command = manager._attempt_managed_install(force=True, offline=True).command+ availability, operation = manager._attempt_managed_install(force=True, offline=True)+ command = availability.commandassert command is None+ assert operation.ok is Falseassert manager._install_reason == "runtime_install_guard_unavailable"diff --git a/tests/test_show_runtime_github_source.py b/tests/test_show_runtime_github_source.pyindex 6a6118608..39c892b7f 100644--- a/tests/test_show_runtime_github_source.py+++ b/tests/test_show_runtime_github_source.py@@ -42,6 +42,7 @@ def make_upstream(tmp_path: Path) -> Path:upstream.mkdir()git("init", "-b", "main", cwd=upstream)(upstream / "package.json").write_text('{"name": "runtime"}\n', encoding="utf-8")+ (upstream / ".gitignore").write_text("node_modules\npackages/runtime/dist\n", encoding="utf-8")git("add", "-A", cwd=upstream)git("commit", "-m", "one", cwd=upstream)return upstream@@ -87,20 +88,22 @@ def test_first_install_builds_and_records_the_commit_it_built(tmp_path: Path) ->upstream = make_upstream(tmp_path)harness = Harness(tmp_path, upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandassert [command[1:] for command in harness.npm_commands] == [["ci"], ["run", "build"]]source_dir = harness.manager._github_source_dir()- assert harness.manager._read_github_build_marker(source_dir) == git("rev-parse", "HEAD", cwd=upstream)+ expected_revision = git("rev-parse", "HEAD", cwd=upstream)+ assert harness.manager._read_github_build_marker(source_dir) == expected_revision+ assert harness.manager.status()["github_source"] == {"built_revision": expected_revision}def test_unchanged_upstream_reuses_the_build_instead_of_repeating_it(tmp_path: Path) -> None:upstream = make_upstream(tmp_path)harness = Harness(tmp_path, upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandharness.npm_commands.clear()- command = harness.manager._install_github_runtime()+ command = harness.manager._install_github_runtime().commandassert command # the runtime is still usableassert harness.npm_commands == []@@ -110,13 +113,13 @@ def test_unchanged_upstream_reuses_the_build_instead_of_repeating_it(tmp_path: Pdef test_a_new_upstream_commit_is_still_picked_up(tmp_path: Path) -> None:upstream = make_upstream(tmp_path)harness = Harness(tmp_path, upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandharness.npm_commands.clear()(upstream / "package.json").write_text('{"name": "runtime", "version": "2"}\n', encoding="utf-8")git("commit", "-am", "two", cwd=upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandassert [command[1:] for command in harness.npm_commands] == [["ci"], ["run", "build"]]source_dir = harness.manager._github_source_dir()@@ -126,15 +129,156 @@ def test_a_new_upstream_commit_is_still_picked_up(tmp_path: Path) -> None:def test_force_install_rebuilds_even_when_the_commit_matches(tmp_path: Path) -> None:upstream = make_upstream(tmp_path)harness = Harness(tmp_path, upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandharness.npm_commands.clear()- harness.manager.force_install = True- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime(force=True).commandassert [command[1:] for command in harness.npm_commands] == [["ci"], ["run", "build"]]+def test_force_install_fails_before_build_when_old_output_remains(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+) -> None:+ upstream = make_upstream(tmp_path)+ harness = Harness(tmp_path, upstream)+ assert harness.manager._install_github_runtime().command+ harness.npm_commands.clear()+ monkeypatch.setattr(show_runtime.shutil, "rmtree", lambda _path: None)++ attempt = harness.manager._install_github_runtime(force=True)++ assert attempt.command is None+ assert attempt.operation_reason == "runtime_install_failed"+ assert harness.manager._install_reason is None+ assert harness.npm_commands == []+++def test_forced_update_failure_reports_failed_operation_and_installed_state(tmp_path: Path) -> None:+ upstream = make_upstream(tmp_path)+ harness = Harness(tmp_path, upstream)+ installed = harness.manager.prepare()+ assert installed["ok"] is True++ def fail_update(_command: list[str], *, cwd: Path | None = None) -> bool:+ del cwd+ harness.manager._install_reason = "runtime_install_failed"+ return False++ harness.manager._run_install_command = fail_update # type: ignore[method-assign]++ result = harness.manager.prepare(force=True)++ assert result["ok"] is False+ assert result["reason"] == "runtime_github_source_update_failed"+ assert result["command"] == installed["command"]+ assert result["install"]["state"] == "installed"+ assert result["install"]["reason"] is None+ assert result["status"]["install"]["state"] == "installed"+ assert result["status"]["reason"] is None+ assert result["status"]["command"] == installed["command"]+++def test_failed_github_build_does_not_publish_checkout_revision_as_artifact_provenance(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+ capsys: pytest.CaptureFixture[str],+) -> None:+ from vibe import cli++ upstream = make_upstream(tmp_path)+ installed = Harness(tmp_path, upstream)+ first = installed.manager.prepare()+ source_dir = installed.manager._github_source_dir()+ old_command = first["command"]+ (upstream / "package.json").write_text('{"name": "runtime", "version": "2"}\n', encoding="utf-8")+ git("commit", "-am", "upstream update", cwd=upstream)+ target_revision = git("rev-parse", "HEAD", cwd=upstream)+ attempt = Harness(tmp_path, upstream)+ real_run = attempt._run++ def fail_npm_ci(command: list[str], *, cwd: Path | None = None) -> bool:+ if Path(command[0]).name == "npm" and command[1:] == ["ci"]:+ attempt.npm_commands.append(command)+ return False+ return real_run(command, cwd=cwd)++ attempt.manager._run_install_command = fail_npm_ci # type: ignore[method-assign]+ result = attempt.manager.prepare(automatic=True)++ assert result["ok"] is True+ assert result["command"] == old_command+ assert attempt.manager._read_github_build_marker(source_dir) is None+ assert result["status"]["github_source"]["built_revision"] is None+ monkeypatch.setattr(cli, "_configured_cli_language", lambda: "en")+ cli._print_runtime_status(result["status"])+ output = capsys.readouterr().out+ assert target_revision not in output+ assert "prepared from" not in output+ assert "serving local revision" not in output+++def test_failed_forced_build_invalidates_the_cached_command_before_retry(tmp_path: Path) -> None:+ upstream = make_upstream(tmp_path)+ harness = Harness(tmp_path, upstream)+ installed = harness.manager.prepare()+ assert installed["ok"] is True+ real_run = harness._run++ def fail_the_build(command: list[str], *, cwd: Path | None = None) -> bool:+ if command[1:] == ["run", "build"]:+ harness.npm_commands.append(command)+ harness.manager._install_reason = "runtime_install_failed"+ return False+ return real_run(command, cwd=cwd)++ harness.manager._run_install_command = fail_the_build # type: ignore[method-assign]+ harness.npm_commands.clear()++ forced = harness.manager.prepare(force=True)+ retried = harness.manager.prepare()++ assert forced["ok"] is False+ assert forced["status"]["install"]["state"] == "absent"+ assert retried["ok"] is False+ assert retried["reason"] == "runtime_install_failed"+ assert harness.manager._managed_command is None+ assert [command[1:] for command in harness.npm_commands] == [+ ["ci"],+ ["run", "build"],+ ["ci"],+ ["run", "build"],+ ]+++ "delegate_outcome",+ (+ subprocess.CompletedProcess(args=["git", "fetch"], returncode=1),+ OSError("git spawn failed"),+ subprocess.TimeoutExpired(cmd=["git", "fetch"], timeout=300),+ ),+)+def test_github_delegate_failures_are_structured(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+ delegate_outcome: subprocess.CompletedProcess | Exception,+) -> None:+ manager = show_runtime.ShowRuntimeManager(runtime_dir=tmp_path / "runtime")+ manager.runtime_dir.mkdir(parents=True)++ def run_delegate(*_args, **_kwargs):+ if isinstance(delegate_outcome, Exception):+ raise delegate_outcome+ return delegate_outcome++ monkeypatch.setattr(show_runtime.subprocess, "run", run_delegate)++ assert manager._run_install_command(["git", "fetch"]) is False+ assert manager._install_reason == "runtime_install_failed"++def test_a_failed_build_leaves_no_marker_licensing_a_skip(tmp_path: Path) -> None:"""A marker may only ever describe artifacts that exist right now.@@ -152,14 +296,14 @@ def test_a_failed_build_leaves_no_marker_licensing_a_skip(tmp_path: Path) -> Nonreturn real_run(command, cwd=cwd)harness.manager._run_install_command = fail_the_build # type: ignore[method-assign]- assert harness.manager._install_github_runtime() is None+ assert harness.manager._install_github_runtime().command is Nonesource_dir = harness.manager._github_source_dir()assert harness.manager._read_github_build_marker(source_dir) is Noneharness.manager._run_install_command = real_run # type: ignore[method-assign]harness.npm_commands.clear()- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandassert [command[1:] for command in harness.npm_commands] == [["ci"], ["run", "build"]]@@ -178,7 +322,7 @@ def test_a_failed_rebuild_retracts_the_marker_it_had_already_earned(tmp_path: Pa"""upstream = make_upstream(tmp_path)harness = Harness(tmp_path, upstream)- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandbuilt = harness.manager._read_github_build_marker(harness.manager._github_source_dir())assert built@@ -200,5 +344,5 @@ def test_a_failed_rebuild_retracts_the_marker_it_had_already_earned(tmp_path: Paharness.manager._run_install_command = real_run # type: ignore[method-assign]harness.manager.force_install = Falseharness.npm_commands.clear()- assert harness.manager._install_github_runtime()+ assert harness.manager._install_github_runtime().commandassert [command[1:] for command in harness.npm_commands] == [["ci"], ["run", "build"]]diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.pyindex 069023ab3..2e53c0c96 100644--- a/tests/test_ui_show_pages.py+++ b/tests/test_ui_show_pages.py@@ -4,9 +4,11 @@ import hashlibimport ioimport jsonimport os+import shutilimport socketimport sslimport struct+import subprocessimport tarfileimport threadingimport urllib.error@@ -6632,7 +6634,7 @@ def test_show_runtime_manager_installs_from_prebuilt_archive(monkeypatch, tmp_pa)monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- assert manager._install_managed_runtime_locked(force=False, offline=False) == [+ assert manager._install_managed_runtime_locked(force=False, offline=False).command == ["/bin/node",str(tmp_path / "runtime" / "prebuilt" / "current" / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"),]@@ -6664,8 +6666,9 @@ def test_show_runtime_manager_installs_prebuilt_archive_with_internal_symlinks(m)monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- command = manager._install_managed_runtime_locked(force=False, offline=False)+ command = manager._install_managed_runtime_locked(force=False, offline=False).command+ assert command is not Noneassert command == ["/bin/node",str(tmp_path / "runtime" / "prebuilt" / "current" / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"),@@ -6717,10 +6720,50 @@ def test_show_runtime_manager_reuses_installed_prebuilt_runtime_without_archive()monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False).command == ["/bin/node", str(cli_path)]assert manager._install_reason is None+def test_show_runtime_manager_forced_archive_fallback_reports_failed_operation_and_installed_state(+ monkeypatch,+ tmp_path,+):+ cli_path = (+ tmp_path+ / "runtime"+ / "prebuilt"+ / "current"+ / "node_modules"+ / "@avibe"+ / "show-runtime"+ / "dist"+ / "cli.js"+ )+ cli_path.parent.mkdir(parents=True)+ cli_path.write_text("#!/usr/bin/env node\n", encoding="utf-8")+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="archive",+ archive_path=tmp_path / "missing.tgz",+ )+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/node"] if command == "node" else None,+ )++ result = manager.prepare(force=True)++ assert result["ok"] is False+ assert result["reason"] == "runtime_archive_missing"+ assert result["command"] == ["/bin/node", str(cli_path)]+ assert result["install"]["state"] == "installed"+ assert result["install"]["reason"] is None+ assert result["status"]["install"]["state"] == "installed"+ assert result["status"]["command"] == ["/bin/node", str(cli_path)]+ assert result["status"]["reason"] is None++def test_show_runtime_manager_archive_source_honors_offline_mode(monkeypatch, tmp_path):manager = ShowRuntimeManager(workspace_root=tmp_path / "show",@@ -6763,6 +6806,34 @@ def test_show_runtime_manager_refreshes_stale_prebuilt_archive(monkeypatch, tmp_assert installed_cli.read_text(encoding="utf-8") == "new runtime\n"+def test_show_runtime_manager_force_refreshes_matching_prebuilt_archive(monkeypatch, tmp_path):+ archive_root = tmp_path / "archive-root"+ archive_cli = archive_root / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"+ archive_cli.parent.mkdir(parents=True)+ archive_cli.write_text("healthy runtime\n", encoding="utf-8")+ archive_path = tmp_path / "vibe-show-runtime-node.tgz"+ with tarfile.open(archive_path, "w:gz") as tar:+ tar.add(archive_root / "node_modules", arcname="node_modules")++ runtime_dir = tmp_path / "runtime"+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ runtime_source="archive",+ archive_path=archive_path,+ )+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)++ first = manager.prepare()+ installed_cli = Path(first["command"][1])+ installed_cli.write_text("corrupt runtime\n", encoding="utf-8")++ repaired = manager.prepare(force=True)++ assert repaired["ok"] is True+ assert installed_cli.read_text(encoding="utf-8") == "healthy runtime\n"++def test_show_runtime_manager_installs_from_manifest_cache(monkeypatch, tmp_path):archive_path = _write_runtime_archive(tmp_path)manifest_path = _write_runtime_manifest(tmp_path, archive_path)@@ -6790,8 +6861,66 @@ def test_show_runtime_manager_installs_from_manifest_cache(monkeypatch, tmp_pathassert metadata["manifest_sha256"] == manifest.digestassert metadata["archive_sha256"] == _sha256(archive_path)status = manager.status()- assert status["installed"] is True- assert status["installed_matches_manifest"] is True+ assert status["install"]["state"] == "installed"+ assert status["install"]["matches_manifest"] is True+++def test_show_runtime_manager_forced_manifest_fallback_reports_failed_operation_and_installed_state(+ monkeypatch,+ tmp_path,+):+ archive_path = _write_runtime_archive(tmp_path)+ manifest_path = _write_runtime_manifest(tmp_path, archive_path)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ manifest_path=manifest_path,+ )+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/node"] if command == "node" else None,+ )+ installed = manager.prepare()+ assert installed["ok"] is True++ def fail_archive_resolution(*_args, **_kwargs):+ manager._install_reason = "runtime_archive_download_failed"+ return None++ monkeypatch.setattr(manager, "_resolve_manifest_archive", fail_archive_resolution)++ result = manager.prepare(force=True)++ assert result["ok"] is False+ assert result["reason"] == "runtime_archive_download_failed"+ assert result["command"] == installed["command"]+ assert result["install"]["state"] == "installed"+ assert result["install"]["reason"] is None+ assert result["status"]["install"]["state"] == "installed"+ assert result["status"]["command"] == installed["command"]+ assert result["status"]["reason"] is None+++def test_show_runtime_manager_force_refreshes_matching_manifest_install(monkeypatch, tmp_path):+ archive_path = _write_runtime_archive(tmp_path, text="healthy runtime\n")+ manifest_path = _write_runtime_manifest(tmp_path, archive_path)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ manifest_path=manifest_path,+ )+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/node"] if command == "node" else None,+ )+ installed = manager.prepare()+ installed_cli = Path(installed["command"][1])+ installed_cli.write_text("corrupt runtime\n", encoding="utf-8")++ replaced = manager.prepare(force=True)++ assert replaced["ok"] is True+ assert installed_cli.read_text(encoding="utf-8") == "healthy runtime\n"def test_show_runtime_manager_preserves_structured_http_download_error(monkeypatch, tmp_path):@@ -6975,7 +7104,7 @@ def test_show_runtime_manager_manifest_install_dir_includes_runtime_and_archive_assert new_cli != old_cliassert new_cli.read_text(encoding="utf-8") == "new runtime\n"assert old_cli.read_text(encoding="utf-8") == "old runtime\n"- assert new_manager.status()["installed_matches_manifest"] is True+ assert new_manager.status()["install"]["matches_manifest"] is Truedef test_show_runtime_manager_manifest_install_identity_ignores_other_platform_edits(monkeypatch, tmp_path):@@ -7019,7 +7148,7 @@ def test_show_runtime_manager_manifest_install_identity_ignores_other_platform_eassert edited_result["ok"] is Trueassert edited_result["command"] == initial_result["command"]- assert edited_result["status"]["installed_matches_manifest"] is True+ assert edited_result["status"]["install"]["matches_manifest"] is Truedef test_show_runtime_manager_adopts_previous_fingerprint_and_preserves_gc_protection(monkeypatch, tmp_path):@@ -7402,6 +7531,35 @@ def test_show_runtime_prepare_with_explicit_command_does_not_clean_managed_instaassert local_bin.exists() is True+def test_show_runtime_forced_prepare_refuses_explicit_command_replacement(monkeypatch, tmp_path):+ local_bin = tmp_path / "development" / "show-runtime"+ local_bin.parent.mkdir()+ local_bin.write_text("#!/bin/sh\n", encoding="utf-8")+ manager = ShowRuntimeManager(+ command=str(local_bin),+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr(+ manager,+ "_install_managed_runtime_locked",+ lambda **_kwargs: pytest.fail("an explicit command must not enter managed replacement"),+ )++ result = manager.prepare(force=True)++ assert result["ok"] is False+ assert result["reason"] == "VIBE_SHOW_RUNTIME_BIN"+ assert result["policy"] == {+ "state": "allowed",+ "reason": None,+ }+ assert result["install"]["state"] == "installed"+ assert result["install"]["command"] == [str(local_bin)]+ assert result["status"]["install"]["state"] == "installed"++def test_show_runtime_failed_prepare_does_not_clean_managed_installs(monkeypatch, tmp_path):runtime_dir = tmp_path / "runtime"install_dirs = [@@ -7623,7 +7781,7 @@ def test_show_runtime_prepare_policy_truth_table(monkeypatch.setattr(manager,"_install_managed_runtime_locked",- lambda *, force, offline: calls.append((force, offline)) or command,+ lambda *, force, offline, automatic: calls.append((force, offline, automatic)) or command,)monkeypatch.setattr(manager, "status", lambda **_kwargs: {})@@ -7637,7 +7795,7 @@ def test_show_runtime_prepare_policy_truth_table(assert result["install"]["state"] == ("absent" if expected_skip else "installed")assert result["runtime"]["state"] == "unchecked"assert result["ok"] is (not expected_skip)- assert calls == ([] if expected_skip else [(force, False)])+ assert calls == ([] if expected_skip else [(force, False, automatic)])def test_show_runtime_automatic_opt_out_does_not_fetch_remote_manifest(monkeypatch, tmp_path):@@ -7681,8 +7839,8 @@ def test_show_runtime_remote_manifest_install_remains_installed_when_source_is_uassert skipped["install"]["state"] == "installed"assert skipped["runtime"]["state"] == "unchecked"assert skipped["command"] == command- assert skipped["status"]["installed"] is True- assert skipped["status"]["install_dir"] == str(install_dir)+ assert skipped["status"]["install"]["state"] == "installed"+ assert skipped["status"]["install"]["install_dir"] == str(install_dir)def fail_manifest_fetch(*_args, **_kwargs):raise OSError("manifest host unavailable")@@ -7690,12 +7848,11 @@ def test_show_runtime_remote_manifest_install_remains_installed_when_source_is_umonkeypatch.setattr("core.show_runtime.fetch_bytes", fail_manifest_fetch)status = manager.status()- assert status["installed"] is Trueassert status["install"]["state"] == "installed"assert status["runtime"]["state"] == "unchecked"assert status["install"]["runtime_version"] == "runtime-test-ref"assert status["install"]["matches_manifest"] is None- assert status["installed_matches_manifest"] is None+ assert status["install"]["matches_manifest"] is Noneassert status["command"] == commandassert status["manifest"]["source"] == manifest_urlassert status["reason"] == "runtime_manifest_download_failed"@@ -7725,18 +7882,19 @@ def test_show_runtime_status_keeps_installed_identity_separate_from_selected_manstatus = manager.status()- assert status["installed"] is Trueassert status["install"] == {"state": "installed","reason": None,"failure_class": None,"command": command,+ "install_dir": str(install_dir),"runtime_version": "runtime-test-ref","matches_manifest": False,}- assert status["installed_matches_manifest"] is Falseassert status["manifest"]["runtime_version"] == "runtime-selected-ref"- assert status["install_dir"] == str(install_dir)+ assert "installed" not in status+ assert "installed_matches_manifest" not in status+ assert "install_dir" not in statusdef test_show_runtime_disk_install_fact_does_not_require_node(monkeypatch, tmp_path):@@ -7759,7 +7917,8 @@ def test_show_runtime_disk_install_fact_does_not_require_node(monkeypatch, tmp_passert result["install"]["state"] == "installed"assert result["install"]["command"] is Noneassert result["runtime"]["state"] == "unchecked"- assert result["ok"] is True+ assert result["ok"] is False+ assert result["reason"] == "VIBE_SHOW_RUNTIME_AUTO_INSTALL"@pytest.mark.parametrize(@@ -7840,7 +7999,7 @@ def test_show_runtime_availability_classifies_install_failure(runtime_source="npm",)- def fail_install(*, force, offline):+ def fail_install(*, force, offline, automatic):manager._install_reason = reasonreturn None@@ -7854,6 +8013,7 @@ def test_show_runtime_availability_classifies_install_failure("reason": reason,"failure_class": expected_class,"command": None,+ "install_dir": None,"runtime_version": None,"matches_manifest": None,}@@ -7872,13 +8032,13 @@ def test_show_runtime_prepare_options_do_not_mutate_shared_manager_state(monkeypmonkeypatch.setattr(manager,"_install_managed_runtime_locked",- lambda *, force, offline: calls.append((force, offline)) or ["/tmp/runtime"],+ lambda *, force, offline, automatic: calls.append((force, offline, automatic)) or ["/tmp/runtime"],)result = manager.prepare(force=True, offline=True)assert result["install"]["state"] == "installed"- assert calls == [(True, True)]+ assert calls == [(True, True, False)]assert manager.force_install is Falseassert manager.offline is False@@ -7894,8 +8054,8 @@ def test_show_runtime_prepare_and_request_share_one_install_admission(monkeypatccommand = [str(tmp_path / "runtime" / "avibe-show-runtime")]calls = []- def install(*, force, offline):- calls.append((force, offline))+ def install(*, force, offline, automatic):+ calls.append((force, offline, automatic))entered.set()assert release.wait(timeout=5)return command@@ -7915,7 +8075,7 @@ def test_show_runtime_prepare_and_request_share_one_install_admission(monkeypatcresolved = asyncio.run(resolve_during_prepare())prepare_thread.join(timeout=5)- assert calls == [(False, False)]+ assert calls == [(False, False, False)]assert prepared[0]["install"]["state"] == "installed"assert resolved.install.value == "installed"assert resolved.command == command@@ -7934,7 +8094,11 @@ def test_show_runtime_manager_installs_without_blocking_event_loop(monkeypatch,bin_path.chmod(0o755)return [str(bin_path)]- monkeypatch.setattr(manager, "_install_managed_runtime_locked", lambda *, force, offline: fake_install())+ monkeypatch.setattr(+ manager,+ "_install_managed_runtime_locked",+ lambda *, force, offline, automatic: fake_install(),+ )calls = []async def fake_to_thread(func, *args, **kwargs):@@ -8007,28 +8171,31 @@ def test_show_runtime_manager_installs_from_github_source(monkeypatch, tmp_path)return Truemonkeypatch.setattr(manager, "_run_install_command", fake_run)+ monkeypatch.setattr(manager, "_git_revision", lambda *_args: "0123456789abcdef")++ attempt = manager._install_managed_runtime_locked(force=False, offline=False)- assert manager._install_managed_runtime_locked(force=False, offline=False) == [+ assert attempt.command == ["/bin/node",str(source_dir / "packages" / "runtime" / "dist" / "cli.js"),]- assert commands == [- (- [- "/bin/git",- "clone",- "--depth",- "1",- "--branch",- "main",- "https://github.com/avibe-bot/vibe-show-runtime.git",- str(source_dir),- ],- None,- ),+ clone_command, clone_cwd = commands[0]+ assert clone_command[:-1] == [+ "/bin/git",+ "clone",+ "--depth",+ "1",+ "--branch",+ "main",+ "https://github.com/avibe-bot/vibe-show-runtime.git",+ ]+ assert clone_cwd is None+ assert Path(clone_command[-1]) == source_dir+ assert commands[1:] == [(["/bin/npm", "ci"], source_dir),(["/bin/npm", "run", "build"], source_dir),]+ assert manager.status()["github_source"] == {"built_revision": "0123456789abcdef"}def test_show_runtime_manager_reuses_installed_github_runtime_when_update_fails(monkeypatch, tmp_path):@@ -8058,7 +8225,7 @@ def test_show_runtime_manager_reuses_installed_github_runtime_when_update_fails(monkeypatch.setattr(manager, "_run_install_command", fake_run)- assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False).command == ["/bin/node", str(cli_path)]assert manager._install_reason is Noneassert commands == [(@@ -8088,7 +8255,7 @@ def test_show_runtime_manager_reuses_installed_github_runtime_without_git(monkeylambda command: ["/bin/node"] if command == "node" else None,)- assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False).command == ["/bin/node", str(cli_path)]assert manager._install_reason is None@@ -8137,10 +8304,154 @@ def test_show_runtime_manager_can_use_npm_source(monkeypatch, tmp_path):runtime_source="npm",)called = []- monkeypatch.setattr(manager, "_install_npm_runtime", lambda: called.append("npm") or ["/tmp/avibe-show-runtime"])+ monkeypatch.setattr(+ manager,+ "_install_npm_runtime",+ lambda *, force: called.append(force) or ["/tmp/avibe-show-runtime"],+ )++ assert manager._install_managed_runtime_locked(force=False, offline=False).command == ["/tmp/avibe-show-runtime"]+ assert called == [False]+++def test_show_runtime_destructive_replacement_invalidates_cached_install_before_removal(monkeypatch, tmp_path):+ runtime_dir = tmp_path / "runtime"+ managed_tree = runtime_dir / "package" / "node_modules"+ managed_bin = managed_tree / ".bin" / "avibe-show-runtime"+ managed_bin.parent.mkdir(parents=True)+ managed_bin.write_text("old runtime\n", encoding="utf-8")+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ runtime_source="npm",+ )+ manager._publish_install_availability(command=[str(managed_bin)])+ real_rmtree = shutil.rmtree++ def remove_after_observing_invalidated_state(path):+ assert manager._managed_command is None+ assert manager._availability.command is None+ assert manager._availability.install.value == "absent"+ real_rmtree(path)- assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/tmp/avibe-show-runtime"]- assert called == ["npm"]+ monkeypatch.setattr("core.show_runtime.shutil.rmtree", remove_after_observing_invalidated_state)++ assert manager._remove_managed_runtime_tree_for_replacement(managed_tree, label="test") is True+++def test_show_runtime_manager_forced_npm_replacement_fails_when_old_tree_remains(monkeypatch, tmp_path):+ runtime_dir = tmp_path / "runtime"+ managed_bin = runtime_dir / "package" / "node_modules" / ".bin" / "avibe-show-runtime"+ managed_bin.parent.mkdir(parents=True)+ managed_bin.write_text("old runtime\n", encoding="utf-8")+ managed_bin.chmod(0o755)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ runtime_source="npm",+ )+ manager._managed_command = [str(managed_bin)]+ install_calls = []+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/npm"] if command == "npm" else None,+ )+ monkeypatch.setattr("core.show_runtime.shutil.rmtree", lambda _path: None)+ monkeypatch.setattr(+ "core.show_runtime.subprocess.run",+ lambda *_args, **_kwargs: install_calls.append(True) or SimpleNamespace(returncode=0),+ )++ result = manager.prepare(force=True)++ assert result["ok"] is False+ assert result["reason"] == "runtime_install_failed"+ assert result["status"]["install"]["state"] == "installed"+ assert managed_bin.read_text(encoding="utf-8") == "old runtime\n"+ assert install_calls == []+++def test_show_runtime_manager_forced_npm_replacement_removes_old_tree_before_install(monkeypatch, tmp_path):+ runtime_dir = tmp_path / "runtime"+ managed_bin = runtime_dir / "package" / "node_modules" / ".bin" / "avibe-show-runtime"+ managed_bin.parent.mkdir(parents=True)+ managed_bin.write_text("old runtime\n", encoding="utf-8")+ managed_bin.chmod(0o755)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ runtime_source="npm",+ )+ manager._managed_command = [str(managed_bin)]+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/npm"] if command == "npm" else None,+ )++ def install_after_removal(*_args, **_kwargs):+ assert not managed_bin.parent.parent.exists()+ managed_bin.parent.mkdir(parents=True)+ managed_bin.write_text("new runtime\n", encoding="utf-8")+ managed_bin.chmod(0o755)+ return SimpleNamespace(returncode=0)++ monkeypatch.setattr("core.show_runtime.subprocess.run", install_after_removal)++ result = manager.prepare(force=True)++ assert result["ok"] is True+ assert managed_bin.read_text(encoding="utf-8") == "new runtime\n"+++ "install_error",+ (+ OSError("npm spawn failed"),+ subprocess.TimeoutExpired(cmd=["npm", "install"], timeout=180),+ ),+)+def test_show_runtime_manager_forced_npm_replacement_reports_delegate_exception(+ monkeypatch,+ tmp_path,+ install_error,+):+ runtime_dir = tmp_path / "runtime"+ managed_bin = runtime_dir / "package" / "node_modules" / ".bin" / "avibe-show-runtime"+ managed_bin.parent.mkdir(parents=True)+ managed_bin.write_text("old runtime\n", encoding="utf-8")+ managed_bin.chmod(0o755)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ runtime_source="npm",+ )+ manager._managed_command = [str(managed_bin)]+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["/bin/npm"] if command == "npm" else None,+ )++ install_calls = []++ def fail_install(*_args, **_kwargs):+ install_calls.append(True)+ assert not managed_bin.parent.parent.exists()+ raise install_error++ monkeypatch.setattr("core.show_runtime.subprocess.run", fail_install)++ result = manager.prepare(force=True)+ retried = manager.prepare()++ assert result["ok"] is False+ assert result["reason"] == "runtime_install_failed"+ assert result["install"]["state"] == "failed"+ assert result["status"]["install"]["state"] == "absent"+ assert retried["ok"] is False+ assert retried["reason"] == "runtime_install_failed"+ assert manager._managed_command is None+ assert install_calls == [True, True]+ assert managed_bin.exists() is Falsedef test_show_runtime_shutdown_stops_manager():diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex adb87f9d3..3ae768da9 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -1787,7 +1787,7 @@ def test_show_runtime_doctor_fast_mode_reports_local_state_without_network(monke"name": "vibe-show-runtime-node-linux-x64.tgz","url": "https://github.com/avibe-bot/avibe/releases/download/v3.0.5/vibe-show-runtime-node-linux-x64.tgz",},- "installed": False,+ "install": {"state": "absent", "install_dir": None},}manager = SimpleNamespace(status=lambda: status,@@ -2225,7 +2225,7 @@ def test_repair_show_runtime_returns_structured_download_failure(monkeypatch):"provider": "manifest-cache","platform": "linux-x64","archive": {"url": archive_url},- "installed": False,+ "install": {"state": "absent", "install_dir": None},},prepare=lambda force=False: {"ok": False,@@ -2265,7 +2265,7 @@ def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):"provider": "manifest-cache","platform": "linux-x64","command": [str(tmp_path / "runtime-cli")],- "status": {"install_dir": str(tmp_path / "runtime")},+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "runtime")}},}manager = SimpleNamespace(@@ -2273,7 +2273,7 @@ def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):"provider": "manifest-cache","platform": "linux-x64","archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},- "installed": False,+ "install": {"state": "absent", "install_dir": None},},prepare=prepare,ensure=ensure,@@ -2285,10 +2285,62 @@ def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):assert result["status"] == "repaired"assert result["install_dir"] == str(tmp_path / "runtime")+ assert result["message"] == "Installed and started Show Runtime."assert prepared == [False]assert stopped == [True]+def test_repair_show_runtime_first_github_install_failure_does_not_claim_preserved_install(+ monkeypatch,+ tmp_path,+):+ from core.show_runtime import ShowRuntimeManager++ real_manager = ShowRuntimeManager(+ runtime_dir=tmp_path / "runtime",+ runtime_source="github-source",+ github_repo=str(tmp_path / "upstream"),+ github_ref="main",+ )+ status = real_manager.status()+ source_dir = real_manager._github_source_dir()+ prepared = []++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": False,+ "reason": "runtime_github_source_update_failed",+ "provider": "github-source",+ "platform": "linux-x64",+ "command": None,+ "status": status,+ }++ manager = SimpleNamespace(status=lambda: status, prepare=prepare)+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", lambda **_kwargs: manager)+ monkeypatch.setattr(cli, "_configured_cli_language", lambda: "en")++ result = cli._repair_show_runtime()++ assert status["install"] == {+ "state": "absent",+ "reason": None,+ "failure_class": None,+ "command": None,+ "install_dir": None,+ "runtime_version": None,+ "matches_manifest": None,+ }+ assert "installed" not in status+ assert "installed_matches_manifest" not in status+ assert "install_dir" not in status+ assert str(source_dir) not in result["message"]+ assert result["message"] == "Show Runtime preparation failed: runtime_github_source_update_failed"+ assert result["installed"] is False+ assert prepared == [False]++def test_repair_show_runtime_does_not_reinstall_startable_runtime(monkeypatch, tmp_path):constructor_calls = []verifier_stops = []@@ -2297,9 +2349,8 @@ def test_repair_show_runtime_does_not_reinstall_startable_runtime(monkeypatch, tstatus=lambda: {"provider": "manifest-cache","platform": "linux-x64",- "install_dir": str(tmp_path / "installed"),+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},"archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},- "installed": True,"command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},prepare=lambda force=False: pytest.fail("startable runtime must not be reinstalled"),@@ -2343,13 +2394,11 @@ def test_repair_show_runtime_refuses_explicit_command_before_hypothetical_recoveSimpleNamespace(available=True, reason=None),]explicit_command = str(tmp_path / "explicit-runtime")-manager = SimpleNamespace(status=lambda: {"provider": "command","platform": "linux-x64",- "install_dir": None,- "installed": True,+ "install": {"state": "installed", "install_dir": None},"command": [explicit_command],"explicit_command": explicit_command,},@@ -2397,16 +2446,15 @@ def test_repair_show_runtime_reinstalls_unstartable_runtime_and_verifies_recover"provider": "manifest-cache","platform": "linux-x64","command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],- "status": {"install_dir": str(tmp_path / "installed")},+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "installed")}},}manager = SimpleNamespace(status=lambda: {"provider": "manifest-cache","platform": "linux-x64",- "install_dir": str(tmp_path / "installed"),+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},"archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},- "installed": True,"command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},prepare=prepare,@@ -2425,6 +2473,7 @@ def test_repair_show_runtime_reinstalls_unstartable_runtime_and_verifies_recoverresult = cli._repair_show_runtime()assert result["status"] == "repaired"+ assert result["message"] == "Reinstalled and started Show Runtime."assert prepared == [True]@@ -2439,16 +2488,15 @@ def test_repair_show_runtime_reports_runtime_that_still_cannot_start(monkeypatch"provider": "manifest-cache","platform": "linux-x64","command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],- "status": {"install_dir": str(tmp_path / "installed")},+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "installed")}},}manager = SimpleNamespace(status=lambda: {"provider": "manifest-cache","platform": "linux-x64",- "install_dir": str(tmp_path / "installed"),+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},"archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},- "installed": True,"command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},prepare=prepare,@@ -2471,11 +2519,48 @@ def test_repair_show_runtime_reports_runtime_that_still_cannot_start(monkeypatchassert result["status"] == "failed"assert result["reason"] == "runtime_start_health_timeout"- assert "could not start" in result["message"]+ assert result["message"] == "Show Runtime was reinstalled but could not start: runtime_start_health_timeout"assert prepared == [True]assert verifier_stops == [True, True]+def test_repair_show_runtime_reports_first_install_that_cannot_start(monkeypatch, tmp_path):+ manager = SimpleNamespace(+ status=lambda: {+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "archive": {"url": str(tmp_path / "runtime.tgz")},+ "install": {"state": "absent", "install_dir": None},+ },+ prepare=lambda force=False: {+ "ok": True,+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "installed")}},+ },+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(+ 0,+ result=SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ ),+ stop=lambda: None,+ )++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_start_health_timeout"+ assert result["message"] == "Show Runtime was installed but could not start: runtime_start_health_timeout"++def test_repair_show_runtime_preserves_undetermined_post_repair_verification(monkeypatch, tmp_path):prepared = []verification_index = 0@@ -2511,16 +2596,15 @@ def test_repair_show_runtime_preserves_undetermined_post_repair_verification(mon"provider": "manifest-cache","platform": "linux-x64","command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],- "status": {"install_dir": str(tmp_path / "installed")},+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "installed")}},}manager = SimpleNamespace(status=lambda: {"provider": "manifest-cache","platform": "linux-x64",- "install_dir": str(tmp_path / "installed"),+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},"archive": {"url": str(tmp_path / "runtime.tgz")},- "installed": True,"command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},prepare=prepare,@@ -2546,6 +2630,133 @@ def test_repair_show_runtime_preserves_undetermined_post_repair_verification(monassert prepared == [True]+def test_repair_show_runtime_reports_failed_replacement_while_old_runtime_remains_installed(+ monkeypatch,+ tmp_path,+):+ prepared = []++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": False,+ "reason": "runtime_archive_download_failed",+ "provider": "archive",+ "platform": "linux-x64",+ "command": None,+ "status": {+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "archive",+ "platform": "linux-x64",+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},+ "archive": {"url": str(tmp_path / "runtime.tgz")},+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ prepare=prepare,+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(+ 0,+ result=SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ ),+ stop=lambda: None,+ )++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_archive_download_failed"+ assert result["installed"] is True+ assert result["install_dir"] == str(tmp_path / "installed")+ assert prepared == [True]+++ ("language", "expected_cause", "expected_action"),+ [+ (+ "en",+ "could not complete the managed source update",+ "Check directory permissions and the Avibe log",+ ),+ (+ "zh",+ "\u65e0\u6cd5\u5728",+ "\u68c0\u67e5\u76ee\u5f55\u6743\u9650\u548c Avibe \u65e5\u5fd7",+ ),+ ],+)+def test_repair_show_runtime_names_github_update_failure_and_remediation(+ monkeypatch,+ tmp_path,+ language,+ expected_cause,+ expected_action,+):+ source_dir = tmp_path / "github-source"+ prepared = []++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": False,+ "reason": "runtime_github_source_update_failed",+ "provider": "github-source",+ "platform": "linux-x64",+ "command": None,+ "status": {+ "install": {"state": "installed", "install_dir": str(source_dir)},+ },+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "github-source",+ "platform": "linux-x64",+ "install": {"state": "installed", "install_dir": str(source_dir)},+ "command": [str(tmp_path / "node"), str(source_dir / "cli.js")],+ },+ prepare=prepare,+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(+ 0,+ result=SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ ),+ stop=lambda: None,+ )++ monkeypatch.setattr(cli, "_configured_cli_language", lambda: language)+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_github_source_update_failed"+ assert result["installed"] is True+ assert result["install_dir"] == str(source_dir)+ assert str(source_dir) in result["message"]+ assert expected_cause in result["message"]+ assert expected_action in result["message"]+ assert prepared == [True]++def test_runtime_prepare_strict_does_not_report_policy_skip_as_ready(monkeypatch, capsys):manager = SimpleNamespace(prepare=lambda **_kwargs: {@@ -2580,6 +2791,42 @@ def test_runtime_prepare_strict_does_not_report_policy_skip_as_ready(monkeypatchassert "VIBE_INSTALL_SKIP_SHOW_RUNTIME" in captured.err+def test_runtime_prepare_force_does_not_report_explicit_command_as_replaced(monkeypatch, capsys):+ manager = SimpleNamespace(+ prepare=lambda **_kwargs: {+ "ok": False,+ "reason": "VIBE_SHOW_RUNTIME_BIN",+ "policy": {+ "state": "skipped",+ "reason": "VIBE_SHOW_RUNTIME_BIN",+ },+ "install": {"state": "installed", "reason": None},+ "runtime": {"state": "unchecked", "reason": None},+ "status": {"install": {"state": "installed", "install_dir": None}},+ }+ )+ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: manager)+ monkeypatch.setattr(cli, "_ensure_askill_during_prepare", lambda **_kwargs: {"ok": True})+ monkeypatch.setattr(cli, "_ensure_tmux_during_prepare", lambda **_kwargs: {"ok": True})+ monkeypatch.setattr(cli, "_ensure_git_during_prepare", lambda **_kwargs: {"ok": True, "mode": "system"})+ monkeypatch.setattr(cli, "_ensure_avault_during_prepare", lambda **_kwargs: {"ok": True})++ exit_code = cli.cmd_runtime(+ SimpleNamespace(+ runtime_command="prepare",+ offline=False,+ force=True,+ json=False,+ strict=True,+ )+ )++ captured = capsys.readouterr()+ assert exit_code == 1+ assert "Show Runtime ready" not in captured.out+ assert "VIBE_SHOW_RUNTIME_BIN" in captured.err++@pytest.mark.parametrize("failure_phase", ["temporary_directory", "verifier", "cleanup"])def test_repair_show_runtime_reports_verification_workspace_failures(monkeypatch, tmp_path, failure_phase):prepared = []@@ -2606,16 +2853,15 @@ def test_repair_show_runtime_reports_verification_workspace_failures(monkeypatch"provider": "archive","platform": "linux-x64","command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],- "status": {"install_dir": str(tmp_path / "installed")},+ "status": {"install": {"state": "installed", "install_dir": str(tmp_path / "installed")}},}manager = SimpleNamespace(status=lambda: {"provider": "archive","platform": "linux-x64",- "install_dir": str(tmp_path / "installed"),+ "install": {"state": "installed", "install_dir": str(tmp_path / "installed")},"archive": {"url": str(tmp_path / "runtime.tgz")},- "installed": True,"command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},prepare=prepare,diff --git a/vibe/api.py b/vibe/api.pyindex 01c248ee3..4ac3ccca4 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -8438,10 +8438,15 @@ def dependencies_status(*, offline: bool = False) -> dict:srt_manager = ShowRuntimeManager(offline=True) if offline else get_show_runtime_manager()srt = srt_manager.status()except Exception as exc: # noqa: BLE001- srt = {"installed": False, "node_available": None, "node_version": None, "reason": str(exc)}+ srt = {+ "install": {"state": "absent", "runtime_version": None, "matches_manifest": None},+ "node_available": None,+ "node_version": None,+ "reason": str(exc),+ }manifest = srt.get("manifest") if isinstance(srt.get("manifest"), dict) else {}install = srt.get("install") if isinstance(srt.get("install"), dict) else {}- srt_installed = bool(srt.get("installed"))+ srt_installed = install.get("state") == "installed"installed_matches_manifest = install.get("matches_manifest")deps.append({@@ -8556,8 +8561,8 @@ def _prepare_show_runtime_job() -> dict:payload = get_show_runtime_manager().prepare(force=True)install = payload.get("install") if isinstance(payload.get("install"), dict) else {}- ok = install.get("state") == "installed"- reason = install.get("reason") or payload.get("reason")+ ok = bool(payload.get("ok"))+ reason = payload.get("reason") or install.get("reason")result = {"ok": ok,"message": (diff --git a/vibe/cli.py b/vibe/cli.pyindex 211e4af09..4a59b25e5 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -11001,6 +11001,11 @@ def _managed_dependencies_doctor_items(*, deep: bool = False) -> list[dict]:return items+def _show_runtime_install(payload: dict) -> dict:+ install = payload.get("install")+ return install if isinstance(install, dict) else {}++def _show_runtime_doctor_items(*, deep: bool = False) -> list[dict]:from core.show_runtime import ShowRuntimeManager@@ -11061,10 +11066,12 @@ def _show_runtime_doctor_items(*, deep: bool = False) -> list[dict]:code="show_runtime.archive_cache_clean",)+ install = _show_runtime_install(status)+ installed = install.get("state") == "installed"provider = str(status.get("provider") or "unknown")explicit_command = status.get("explicit_command")if explicit_command:- if status.get("installed"):+ if installed:_add_doctor_item(items, "pass", f"Show Runtime explicit command is available: {explicit_command}")else:_add_doctor_item(@@ -11150,7 +11157,7 @@ def _show_runtime_doctor_items(*, deep: bool = False) -> list[dict]:code="show_runtime.provider_unsupported",)- if status.get("installed"):+ if installed:_add_doctor_item(items,"pass",@@ -12338,6 +12345,9 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:manager = ShowRuntimeManager()before = manager.status()+ before_install = _show_runtime_install(before)+ before_installed = before_install.get("state") == "installed"+ before_install_dir = before_install.get("install_dir")def verify_startability(command_value: Any) -> _ShowRuntimeStartability:command = command_value if isinstance(command_value, list) else []@@ -12364,7 +12374,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:return _ShowRuntimeStartability.not_startable(result.reason or "runtime_start_failed")language = _configured_cli_language()- if before.get("installed"):+ if before_installed:startability = verify_startability(before.get("command"))if startability.state is _ShowRuntimeStartabilityState.UNDETERMINED:return _doctor_repair_result(@@ -12373,7 +12383,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:i18n_t("runtime.doctor.repairVerificationFailed", language, detail=startability.detail),provider=before.get("provider"),platform=before.get("platform"),- install_dir=before.get("install_dir"),+ install_dir=before_install_dir,installed=True,reason="runtime_start_verification_failed",start_error=startability.detail,@@ -12385,7 +12395,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:i18n_t("runtime.doctor.repairHealthy", language),provider=before.get("provider"),platform=before.get("platform"),- install_dir=before.get("install_dir"),+ install_dir=before_install_dir,)if startability.state is not _ShowRuntimeStartabilityState.NOT_STARTABLE:raise AssertionError(f"Unhandled Show Runtime startability: {startability.state}")@@ -12397,7 +12407,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:i18n_t("runtime.doctor.repairExplicitCommandFailed", language, reason=reason),provider=before.get("provider"),platform=before.get("platform"),- install_dir=before.get("install_dir"),+ install_dir=before_install_dir,installed=True,reason=reason,explicit_command=before.get("explicit_command"),@@ -12417,28 +12427,46 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:archive_url=archive_url,)- result = manager.prepare(force=bool(before.get("installed")))+ result = manager.prepare(force=before_installed)status = result.get("status") if isinstance(result.get("status"), dict) else {}+ status_install = _show_runtime_install(status)+ install_dir = status_install.get("install_dir")+ status_installed = status_install.get("state") == "installed"if result.get("ok"):startability = verify_startability(result.get("command"))if startability.state is _ShowRuntimeStartabilityState.STARTABLE:return _doctor_repair_result(target,"repaired",- i18n_t("runtime.doctor.repairStarted", language),+ i18n_t(+ (+ "runtime.doctor.repairReinstalled"+ if before_installed+ else "runtime.doctor.repairInstalled"+ ),+ language,+ ),provider=result.get("provider"),platform=result.get("platform"),- install_dir=status.get("install_dir"),+ install_dir=install_dir,)if startability.state is _ShowRuntimeStartabilityState.NOT_STARTABLE:reason = startability.reason or "runtime_start_failed"return _doctor_repair_result(target,"failed",- i18n_t("runtime.doctor.repairStartFailed", language, reason=reason),+ i18n_t(+ (+ "runtime.doctor.repairReinstallStartFailed"+ if before_installed+ else "runtime.doctor.repairInstallStartFailed"+ ),+ language,+ reason=reason,+ ),provider=result.get("provider"),platform=result.get("platform"),- install_dir=status.get("install_dir"),+ install_dir=install_dir,reason=reason,)if startability.state is _ShowRuntimeStartabilityState.UNDETERMINED:@@ -12448,7 +12476,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:i18n_t("runtime.doctor.repairPostVerificationFailed", language, detail=startability.detail),provider=result.get("provider"),platform=result.get("platform"),- install_dir=status.get("install_dir"),+ install_dir=install_dir,reason="runtime_start_verification_failed",start_error=startability.detail,)@@ -12462,12 +12490,27 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:detail = f"{detail}: {download_error['url']}"else:detail = reason+ github_refusal_messages = {+ "runtime_github_source_update_failed": "runtime.doctor.repairGitHubSourceUpdateFailed",+ }+ refusal_message = github_refusal_messages.get(reason)+ message = (+ i18n_t(+ refusal_message,+ language,+ path=install_dir,+ )+ if refusal_message and install_dir+ else i18n_t("runtime.doctor.repairPrepareFailed", language, detail=detail)+ )return _doctor_repair_result(target,"failed",- i18n_t("runtime.doctor.repairPrepareFailed", language, detail=detail),+ message,provider=result.get("provider"),platform=result.get("platform"),+ install_dir=install_dir,+ installed=status_installed,reason=reason,download_error=download_error,)@@ -14415,9 +14458,10 @@ def _print_runtime_status(payload: dict) -> None:if archive:print(f" Archive: {archive.get('name')}")print(f" Archive sha256: {archive.get('sha256')}")- print(f" Installed: {'yes' if payload.get('installed') else 'no'}")- if payload.get("install_dir"):- print(f" Install dir: {payload.get('install_dir')}")+ install = _show_runtime_install(payload)+ print(f" Installed: {'yes' if install.get('state') == 'installed' else 'no'}")+ if install.get("install_dir"):+ print(f" Install dir: {install.get('install_dir')}")if payload.get("reason"):print(f" Reason: {payload.get('reason')}")git = payload.get("git") or {}@@ -14460,7 +14504,7 @@ def cmd_runtime(args) -> int:payload["git"] = gitinstall = payload.get("install") if isinstance(payload.get("install"), dict) else {}policy = payload.get("policy") if isinstance(payload.get("policy"), dict) else {}- runtime_prepared = install.get("state") == "installed"+ runtime_prepared = bool(payload.get("ok"))if getattr(args, "json", False):print(json.dumps(payload, indent=2))else:@@ -14468,8 +14512,9 @@ def cmd_runtime(args) -> int:if runtime_prepared:print(i18n_t("runtime.prepare.prepared", language))status = payload.get("status") or {}- if status.get("install_dir"):- print(f"Install dir: {status['install_dir']}")+ status_install = _show_runtime_install(status)+ if status_install.get("install_dir"):+ print(f"Install dir: {status_install['install_dir']}")elif policy.get("state") == "skipped":print(i18n_t(@@ -14484,7 +14529,7 @@ def cmd_runtime(args) -> int:i18n_t("runtime.prepare.failed",language,- reason=install.get("reason") or "unknown",+ reason=payload.get("reason") or install.get("reason") or "unknown",),file=sys.stderr,)diff --git a/vibe/i18n/en.json b/vibe/i18n/en.jsonindex 5015f6dc3..1a41d16d3 100644--- a/vibe/i18n/en.json+++ b/vibe/i18n/en.json@@ -929,8 +929,11 @@"archiveCacheSkippedAction": "Wait for the running install or clean to finish, then rerun Doctor.","archiveCacheSkippedInspectionAction": "Check runtime directory permissions and the Avibe log; retry Doctor once fixed.","repairHealthy": "Show Runtime starts successfully; no repair is needed.",- "repairStarted": "Reinstalled and started the manifest-selected Show Runtime.",- "repairStartFailed": "Show Runtime was reinstalled but could not start: {reason}",+ "repairGitHubSourceUpdateFailed": "Show Runtime was not rebuilt because Avibe could not complete the managed source update at {path}. The installed runtime was left in place. Check directory permissions and the Avibe log, then rerun Doctor.",+ "repairInstalled": "Installed and started Show Runtime.",+ "repairReinstalled": "Reinstalled and started Show Runtime.",+ "repairInstallStartFailed": "Show Runtime was installed but could not start: {reason}",+ "repairReinstallStartFailed": "Show Runtime was reinstalled but could not start: {reason}","repairVerificationFailed": "Show Runtime startability could not be verified, so no reinstall was attempted: {detail}","repairPostVerificationFailed": "Show Runtime preparation completed, but startability could not be verified: {detail}","repairExplicitCommandFailed": "The Show Runtime command from VIBE_SHOW_RUNTIME_BIN could not start: {reason}. Fix or remove the override, then rerun Doctor.",diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.jsonindex 150418b52..f0b2420a5 100644--- a/vibe/i18n/zh.json+++ b/vibe/i18n/zh.json@@ -929,11 +929,14 @@"archiveCacheSkippedAction": "等待正在进行的安装或清理结束后,重新运行 Doctor。","archiveCacheSkippedInspectionAction": "\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u548c Avibe \u65e5\u5fd7\uff0c\u4fee\u590d\u540e\u91cd\u8bd5 Doctor\u3002","repairHealthy": "Show Runtime \u53ef\u4ee5\u6b63\u5e38\u542f\u52a8\uff0c\u65e0\u9700\u4fee\u590d\u3002",- "repairStarted": "\u5df2\u91cd\u65b0\u5b89\u88c5\u5e76\u6210\u529f\u542f\u52a8\u6e05\u5355\u9009\u5b9a\u7684 Show Runtime\u3002",- "repairStartFailed": "Show Runtime \u5df2\u91cd\u65b0\u5b89\u88c5\uff0c\u4f46\u4ecd\u65e0\u6cd5\u542f\u52a8\uff1a{reason}",- "repairVerificationFailed": "\u65e0\u6cd5\u9a8c\u8bc1 Show Runtime \u662f\u5426\u53ef\u4ee5\u542f\u52a8\uff0c\u56e0\u6b64\u672a\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5\uff1a{detail}",- "repairPostVerificationFailed": "Show Runtime \u51c6\u5907\u5df2\u5b8c\u6210\uff0c\u4f46\u65e0\u6cd5\u9a8c\u8bc1\u5b83\u662f\u5426\u53ef\u4ee5\u542f\u52a8\uff1a{detail}","repairExplicitCommandFailed": "VIBE_SHOW_RUNTIME_BIN \u6307\u5b9a\u7684 Show Runtime \u547d\u4ee4\u65e0\u6cd5\u542f\u52a8\uff1a{reason}\u3002\u8bf7\u4fee\u590d\u6216\u79fb\u9664\u8be5\u8986\u76d6\u540e\u91cd\u65b0\u8fd0\u884c Doctor\u3002",+ "repairGitHubSourceUpdateFailed": "Show Runtime 未重新构建,因为 Avibe 无法在 {path} 完成托管源代码更新。已安装的 runtime 保持不变。请检查目录权限和 Avibe 日志,然后重新运行 Doctor。",+ "repairInstalled": "\u5df2\u5b89\u88c5\u5e76\u6210\u529f\u542f\u52a8 Show Runtime\u3002",+ "repairReinstalled": "\u5df2\u91cd\u65b0\u5b89\u88c5\u5e76\u6210\u529f\u542f\u52a8 Show Runtime\u3002",+ "repairInstallStartFailed": "Show Runtime \u5df2\u5b89\u88c5\uff0c\u4f46\u65e0\u6cd5\u542f\u52a8\uff1a{reason}",+ "repairReinstallStartFailed": "Show Runtime \u5df2\u91cd\u65b0\u5b89\u88c5\uff0c\u4f46\u4ecd\u65e0\u6cd5\u542f\u52a8\uff1a{reason}",+ "repairVerificationFailed": "\u65e0\u6cd5\u9a8c\u8bc1 Show Runtime \u662f\u5426\u53ef\u542f\u52a8\uff0c\u56e0\u6b64\u672a\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5\uff1a{detail}",+ "repairPostVerificationFailed": "Show Runtime \u51c6\u5907\u5df2\u5b8c\u6210\uff0c\u4f46\u65e0\u6cd5\u9a8c\u8bc1\u662f\u5426\u53ef\u542f\u52a8\uff1a{detail}","repairPrepareFailed": "Show Runtime \u51c6\u5907\u5931\u8d25\uff1a{detail}","repairLegacyArchiveUnavailable": "\u6253\u5305\u7684 Show Runtime \u6e05\u5355\u4e0d\u53ef\u7528\uff0c\u65e7\u7248\u4e0a\u6e38\u5f52\u6863\u5730\u5740\u4e5f\u6ca1\u6709\u53d1\u5e03\u8d44\u4ea7\u3002\u8bf7\u5347\u7ea7\u6216\u91cd\u65b0\u5b89\u88c5\u5b98\u65b9 Avibe \u8f6f\u4ef6\u5305\uff0c\u6216\u79fb\u9664\u8fc7\u671f\u7684 runtime \u6765\u6e90\u8986\u76d6\u914d\u7f6e\u3002"}