From 47fbd432ecc6255579d89407f094c1de13121b4c Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:23:09 +0800 Subject: [PATCH] fix(antigravity): keep the project registry in generated wakes Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/agent_onboarding.py | 3 ++ loopx/agy_goal_mode/__init__.py | 38 +++++++------------ loopx/agy_goal_mode/host_runtime.py | 3 +- loopx/bootstrap_command_pack.py | 3 ++ loopx/host_loop_activation.py | 7 ++++ loopx/hosts/skill_facade.py | 2 + loopx/project_prompt.py | 12 +++++- tests/test_agy_host_surface.py | 59 +++++++++++++++++++++++++++++ 8 files changed, 99 insertions(+), 28 deletions(-) diff --git a/loopx/agent_onboarding.py b/loopx/agent_onboarding.py index 7bacb923ab..bee609f34b 100644 --- a/loopx/agent_onboarding.py +++ b/loopx/agent_onboarding.py @@ -482,10 +482,12 @@ def build_agent_onboarding_packet( registry_path, resolved_goal_id, ) + activation_registry = str(registry_path) if canonical_agent_type == "antigravity-app" else None host_loop_activation = build_host_loop_activation_packet( agent_type=canonical_agent_type, goal_id=resolved_goal_id, cli_bin=cli_bin, + registry=activation_registry, agent_id=agent_id, registered_agents=registered_agents, available_capabilities=available_capabilities, @@ -516,6 +518,7 @@ def build_agent_onboarding_packet( render_quota_guard_command( resolved_goal_id, cli_bin=cli_bin, + registry_path=activation_registry, agent_id=str(selected_agent_id) if selected_agent_id else None, available_capabilities=normalized_available_capabilities, **scheduler_command_binding_for_agent_type(canonical_agent_type), diff --git a/loopx/agy_goal_mode/__init__.py b/loopx/agy_goal_mode/__init__.py index bb2c73536d..da60243cca 100644 --- a/loopx/agy_goal_mode/__init__.py +++ b/loopx/agy_goal_mode/__init__.py @@ -14,6 +14,8 @@ from pathlib import Path from typing import Any +from ..command_invocation import loopx_cli_argv + AGY_INSTALL_SURFACE = "agy" ANTIGRAVITY_APP_INSTALL_SURFACE = "antigravity-app" ANTIGRAVITY_APP_AGENT_TYPE = "antigravity-app" @@ -111,38 +113,21 @@ def build_antigravity_sidecar_template( goal_id: str = "", agent_id: str | None = None, runtime_root: str | None = None, + registry: str | None = None, cli_bin: str = "loopx", interval_seconds: int = 180, ) -> dict[str, Any]: """Build a public-safe Antigravity 2.0 ``sidecar.json`` periodic heartbeat template.""" - quota_args = [cli_bin, "--format", "json"] + cli_args = [*loopx_cli_argv(cli_bin), "--format", "json"] if runtime_root: - quota_args.extend(["--runtime-root", runtime_root]) - quota_args.extend( - [ - "quota", - "should-run", - "--goal-id", - goal_id, - "--runtime-profile", - "antigravity_app", - ] - ) + cli_args.extend(["--runtime-root", runtime_root]) + if registry: + cli_args.extend(["--registry", registry]) + profile_args = ["--goal-id", goal_id, "--runtime-profile", "antigravity_app"] + quota_args = [*cli_args, "quota", "should-run", *profile_args] if agent_id: quota_args.extend(["--agent-id", agent_id]) - heartbeat_args = [cli_bin, "--format", "json"] - if runtime_root: - heartbeat_args.extend(["--runtime-root", runtime_root]) - heartbeat_args.extend( - [ - "heartbeat-prompt", - "--thin", - "--goal-id", - goal_id, - "--runtime-profile", - "antigravity_app", - ] - ) + heartbeat_args = [*cli_args, "heartbeat-prompt", "--thin", *profile_args] if agent_id: heartbeat_args.extend(["--agent-id", agent_id]) bootstrap_prompt = ( @@ -364,6 +349,7 @@ def antigravity_app_activation_extras( goal_id: str = "", agent_id: str | None = None, runtime_root: str | None = None, + registry: str | None = None, cli_bin: str = "loopx", ) -> dict[str, Any]: """Keyword overrides for ``antigravity_app_activation``'s facade call.""" @@ -371,6 +357,7 @@ def antigravity_app_activation_extras( goal_id=goal_id, agent_id=agent_id, runtime_root=runtime_root, + registry=registry, cli_bin=cli_bin, ) hooks_template = build_antigravity_hooks_template( @@ -378,6 +365,7 @@ def antigravity_app_activation_extras( goal_id=goal_id, agent_id=agent_id, runtime_root=runtime_root, + registry=registry, resolve_local_executable=False, ) wake_prompt = sidecar_template["sidecar"]["loopx-heartbeat"]["bootstrap_prompt"] diff --git a/loopx/agy_goal_mode/host_runtime.py b/loopx/agy_goal_mode/host_runtime.py index 6cd4f5b265..96e207b865 100644 --- a/loopx/agy_goal_mode/host_runtime.py +++ b/loopx/agy_goal_mode/host_runtime.py @@ -17,6 +17,7 @@ import time from typing import Any +from ..command_invocation import loopx_cli_argv from ..entrypoint import pin_utf8_stdio from ..file_lock import exclusive_file_lock @@ -41,7 +42,7 @@ def retryable_native_error(error: Any) -> bool: def _core_args(args: argparse.Namespace, command: list[str]) -> list[str]: - result = [args.cli_bin, "--format", "json"] + result = [*loopx_cli_argv(args.cli_bin), "--format", "json"] for flag, value in ( ("--registry", args.registry), ("--runtime-root", args.runtime_root), diff --git a/loopx/bootstrap_command_pack.py b/loopx/bootstrap_command_pack.py index 1c92b1409a..8451873ba5 100644 --- a/loopx/bootstrap_command_pack.py +++ b/loopx/bootstrap_command_pack.py @@ -846,6 +846,7 @@ def build_loopx_bootstrap_command_pack( registry_path=registry_path, runtime_root_arg=runtime_root_arg, ) + activation_registry = str(registry_path) if agent_type == "antigravity-app" else None thread_binding = resolve_thread_agent_binding( registry_goal, host_surface=host_surface, @@ -890,6 +891,7 @@ def build_loopx_bootstrap_command_pack( goal_id=resolved_goal_id, cli_bin=cli_bin, runtime_root=command_runtime_root, + registry=activation_registry, identity_runtime_root=identity_runtime_root, agent_id=effective_agent_id, registered_agents=registered_agents, @@ -923,6 +925,7 @@ def build_loopx_bootstrap_command_pack( resolved_goal_id, cli_bin=cli_bin, runtime_root=command_runtime_root, + registry_path=activation_registry, agent_id=str(selected_agent_id) if selected_agent_id else None, available_capabilities=available_capabilities, begin_turn=guided_start_begins_turn, diff --git a/loopx/host_loop_activation.py b/loopx/host_loop_activation.py index 20558dcc73..9943c049ee 100644 --- a/loopx/host_loop_activation.py +++ b/loopx/host_loop_activation.py @@ -524,6 +524,7 @@ def _heartbeat_commands( agent_type: str, cli_bin: str, runtime_root: str | None = None, + registry: str | None = None, agent_id: str | None, available_capabilities: list[str] | None = None, ) -> dict[str, str]: @@ -558,6 +559,7 @@ def _heartbeat_commands( goal_id, cli_bin=cli_bin, runtime_root=runtime_root, + registry_path=registry, agent_id=agent_id, agent_scope=agent_scope, available_capabilities=available_capabilities, @@ -568,6 +570,7 @@ def _heartbeat_commands( goal_id, cli_bin=cli_bin, runtime_root=runtime_root, + registry_path=registry, agent_id=agent_id, agent_scope=agent_scope, available_capabilities=available_capabilities, @@ -1241,6 +1244,7 @@ def build_host_loop_activation_packet( goal_id: str, cli_bin: str = "loopx", runtime_root: str | None = None, + registry: str | None = None, identity_runtime_root: str | None = None, agent_id: str | None = None, registered_agents: list[str] | None = None, @@ -1266,6 +1270,7 @@ def build_host_loop_activation_packet( agent_type=canonical, cli_bin=cli_bin, runtime_root=runtime_root, + registry=registry, agent_id=str(selected_agent_id) if selected_agent_id else None, available_capabilities=normalized_available_capabilities, ) @@ -1328,6 +1333,7 @@ def build_host_loop_activation_packet( goal_id=goal_id, agent_id=str(selected_agent_id) if selected_agent_id else None, runtime_root=runtime_root, + registry=registry, ) elif canonical == "kiro-cli": surface = kiro_cli_activation(commands, cli_bin) @@ -1349,6 +1355,7 @@ def build_host_loop_activation_packet( agent_type=canonical, cli_bin=cli_bin, runtime_root=runtime_root, + registry=registry, agent_id=candidate, available_capabilities=normalized_available_capabilities, ) diff --git a/loopx/hosts/skill_facade.py b/loopx/hosts/skill_facade.py index ef32d65f9e..bef38874b3 100644 --- a/loopx/hosts/skill_facade.py +++ b/loopx/hosts/skill_facade.py @@ -171,6 +171,7 @@ def antigravity_app_activation( goal_id: str = "", agent_id: str | None = None, runtime_root: str | None = None, + registry: str | None = None, ) -> dict[str, Any]: return skill_facade_cli_activation( commands, @@ -183,6 +184,7 @@ def antigravity_app_activation( goal_id=goal_id, agent_id=agent_id, runtime_root=runtime_root, + registry=registry, cli_bin=cli_bin, ), ) diff --git a/loopx/project_prompt.py b/loopx/project_prompt.py index de407238af..a76933bbaf 100644 --- a/loopx/project_prompt.py +++ b/loopx/project_prompt.py @@ -316,6 +316,7 @@ def render_heartbeat_prompt_command( *, cli_bin: str = "loopx", runtime_root: str | Path | None = None, + registry_path: str | Path | None = None, agent_id: str | None = None, agent_scope: str = "Codex CLI /goal visible TUI loop", body: str = "thin", @@ -337,8 +338,11 @@ def render_heartbeat_prompt_command( if visible_goal_host else "" ) + prefix = render_cli_command_prefix( + cli_bin=cli_bin, runtime_root=runtime_root, registry_path=registry_path + ) return ( - f"{render_cli_command_prefix(cli_bin=cli_bin, runtime_root=runtime_root)} " + f"{prefix} " f"heartbeat-prompt --{shell_arg(body)} " f"--goal-id {shell_arg(goal_id)}{agent_arg}{scope_arg}{capability_args}" f"{scheduler_args}{visible_goal_arg}" + (" --bootstrap" if bootstrap else "") @@ -350,6 +354,7 @@ def render_heartbeat_prompt_json_command( *, cli_bin: str = "loopx", runtime_root: str | Path | None = None, + registry_path: str | Path | None = None, agent_id: str | None = None, agent_scope: str = "Codex CLI /goal visible TUI loop", body: str = "thin", @@ -371,8 +376,11 @@ def render_heartbeat_prompt_json_command( if visible_goal_host else "" ) + prefix = render_cli_command_prefix( + cli_bin=cli_bin, runtime_root=runtime_root, registry_path=registry_path + ) return ( - f"{render_cli_command_prefix(cli_bin=cli_bin, runtime_root=runtime_root)} " + f"{prefix} " f"--format json heartbeat-prompt --{shell_arg(body)} " f"--goal-id {shell_arg(goal_id)}{agent_arg}{scope_arg}{capability_args}" f"{scheduler_args}{visible_goal_arg}" + (" --bootstrap" if bootstrap else "") diff --git a/tests/test_agy_host_surface.py b/tests/test_agy_host_surface.py index 54599097c7..e7e2a1e44a 100644 --- a/tests/test_agy_host_surface.py +++ b/tests/test_agy_host_surface.py @@ -9,12 +9,16 @@ from __future__ import annotations +import json import os from pathlib import Path +import shlex import pytest from host_surface_cli_probes import ( + connected_project, onboarding_setup_command_installs, + run_cli, selection_gate_offers_surface, start_goal_accepts_surface, ) @@ -52,6 +56,61 @@ HOST_SURFACE = "agy" +@pytest.mark.parametrize( + "entry", [ + ("bootstrap-command-pack", "--host-surface", "antigravity-app"), + ("agent-onboard", "--agent-type", "antigravity-app"), + ], +) +def test_antigravity_generated_commands_read_the_project_registry_from_another_directory( + tmp_path: Path, entry: tuple[str, ...], +) -> None: + project = connected_project(tmp_path / "project with spaces") + registry = project / ".loopx" / "registry.json" + runtime = tmp_path / "isolated-runtime" + state = project / "ACTIVE_GOAL_STATE.md" + state.write_text("# Goal\n\nUse the registered project state.\n", encoding="utf-8") + data = json.loads(registry.read_text()) + data["common_runtime_root"] = str(runtime) + data["goals"][0].update( + state_file=state.name, + coordination={"registered_agents": ["probe-agent"], "agent_model": "peer_v1"}, + ) + registry.write_text(json.dumps(data), encoding="utf-8") + foreign = tmp_path / "other" + foreign.mkdir() + # The host may be in another project which happens to use the same Goal id. + other = connected_project(foreign) + foreign_registry = other / ".loopx" / "registry.json" + foreign_registry.write_text(json.dumps({ + "goals": [{**data["goals"][0], "repo": str(other)}], + }), encoding="utf-8") + env = {**os.environ, "LOOPX_RUNTIME_ROOT": str(runtime), "LOOPX_USAGE_PING": "0"} + env.pop("LOOPX_REGISTRY", None) + result = run_cli( + *entry, "--project", str(project), "--goal-id", "surface-goal", + "--agent-id", "probe-agent", cwd=other, env=env, + ) + assert result.returncode == 0, result.stderr + activation = json.loads(result.stdout)["host_loop_activation"] + assert activation["activation_allowed"] + mutation = activation["host_mutation"] + sidecar = mutation["sidecar_template"] + prompt = sidecar["sidecar_json"]["args"][-1] + bootstrap, = [line for line in prompt.splitlines() if " heartbeat-prompt " in line] + for command in (bootstrap, activation["activation_input_command"]): + argv = shlex.split(command) + result = run_cli(*argv[1:], cwd=other, env=env) + assert result.returncode == 0, result.stdout + result.stderr + payload = json.loads(result.stdout) + assert payload["ok"] + guard = next(line for line in payload["task_body"].splitlines() if " quota should-run " in line) + guard_argv = shlex.split(guard) + assert Path(guard_argv[guard_argv.index("--registry") + 1]) == registry + hook = shlex.split(mutation["hooks_template"]["loopx"]["Stop"][0]["command"]) + assert hook[hook.index("--registry") + 1] == str(registry) + + def test_start_goal_accepts_the_agy_host_surface(tmp_path: Path) -> None: payload = start_goal_accepts_surface(HOST_SURFACE, tmp_path) activation = payload["command_pack"]["host_loop_activation"]