Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions loopx/agent_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
38 changes: 13 additions & 25 deletions loopx/agy_goal_mode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -111,38 +113,21 @@ def build_antigravity_sidecar_template(
goal_id: str = "<goal-id>",
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 = (
Expand Down Expand Up @@ -364,20 +349,23 @@ def antigravity_app_activation_extras(
goal_id: str = "<goal-id>",
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."""
sidecar_template = build_antigravity_sidecar_template(
goal_id=goal_id,
agent_id=agent_id,
runtime_root=runtime_root,
registry=registry,
cli_bin=cli_bin,
)
hooks_template = build_antigravity_hooks_template(
cli_bin=cli_bin,
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"]
Expand Down
3 changes: 2 additions & 1 deletion loopx/agy_goal_mode/host_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions loopx/bootstrap_command_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions loopx/host_loop_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)
Expand Down
2 changes: 2 additions & 0 deletions loopx/hosts/skill_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def antigravity_app_activation(
goal_id: str = "<goal-id>",
agent_id: str | None = None,
runtime_root: str | None = None,
registry: str | None = None,
) -> dict[str, Any]:
return skill_facade_cli_activation(
commands,
Expand All @@ -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,
),
)
Expand Down
12 changes: 10 additions & 2 deletions loopx/project_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 "")
Expand All @@ -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",
Expand All @@ -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 "")
Expand Down
59 changes: 59 additions & 0 deletions tests/test_agy_host_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"]
Expand Down
Loading