Skip to content
Open
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
29 changes: 24 additions & 5 deletions loopx/agent_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from typing import Any

from .agent_registry import registered_agent_ids_from_registry
from .bootstrap_command_pack import inspect_bootstrap_connection
from .bootstrap_command_pack import (
resolve_bootstrap_activation_registry,
resolve_bootstrap_project_route,
)
from .capabilities.change_quality.policy import change_quality_goal_policy
from .host_loop_activation import (
agent_type_uses_host_managed_skills,
Expand All @@ -29,6 +32,7 @@
host_command,
render_available_capability_args,
render_codex_cli_install_preflight,
render_optional_cli_arg,
render_quota_guard_command,
shell_arg,
shell_arg_for_host,
Expand Down Expand Up @@ -284,6 +288,7 @@ def _bootstrap_pack_command(
cli_bin: str,
task_text: str | None,
available_capabilities: list[str] | None,
runtime_root: str | None,
) -> str:
surface_by_type = {
"codex-app": "codex-app",
Expand All @@ -308,7 +313,7 @@ def _bootstrap_pack_command(
"other-agent": "other-agent",
}
parts = [
host_command(cli_bin),
host_command(cli_bin) + render_optional_cli_arg("--runtime-root", runtime_root),
"bootstrap-command-pack",
"--project",
shell_arg_for_host(project),
Expand Down Expand Up @@ -437,9 +442,14 @@ def build_agent_onboarding_packet(
cli_bin: str = "loopx",
task_text: str | None = None,
available_capabilities: list[str] | None = None,
runtime_root_arg: str | None = None,
explicit_project_registry: Path | None = None,
) -> dict[str, Any]:
canonical_agent_type = normalize_agent_type(agent_type)
inspection = inspect_bootstrap_connection(project, goal_id=goal_id)
runtime_root_override, (inspection, _) = resolve_bootstrap_project_route(
project, goal_id=goal_id, runtime_root_arg=runtime_root_arg,
explicit_project_registry=explicit_project_registry if canonical_agent_type == "codex-app" else None,
)
resolved_project = str(inspection["project"])
resolved_goal_id = str(inspection["goal_id"])
registry_path = Path(str(inspection["registry"]))
Expand All @@ -460,6 +470,7 @@ def build_agent_onboarding_packet(

runtime_root = resolve_runtime_root(
registry,
override=runtime_root_override,
registry_path=registry_path,
)
goal = project_goal_with_builtin_machine_configuration(
Expand All @@ -482,12 +493,17 @@ def build_agent_onboarding_packet(
registry_path,
resolved_goal_id,
)
activation_registry = str(registry_path) if canonical_agent_type == "antigravity-app" else None
activation_registry = resolve_bootstrap_activation_registry(
canonical_agent_type, registry_path,
connected=inspection.get("connection_state") == "connected",
runtime_root_override=runtime_root_override,
)
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,
runtime_root=runtime_root_override,
agent_id=agent_id,
registered_agents=registered_agents,
available_capabilities=available_capabilities,
Expand All @@ -507,6 +523,7 @@ def build_agent_onboarding_packet(
cli_bin=cli_bin,
task_text=task_text,
available_capabilities=normalized_available_capabilities,
runtime_root=runtime_root_override,
)
commands: dict[str, Any] = {
"doctor_or_install": render_codex_cli_install_preflight(
Expand All @@ -519,6 +536,7 @@ def build_agent_onboarding_packet(
resolved_goal_id,
cli_bin=cli_bin,
registry_path=activation_registry,
runtime_root=runtime_root_override,
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 All @@ -527,7 +545,8 @@ def build_agent_onboarding_packet(
else None
),
"agent_onboard_recheck": (
f"{host_command(cli_bin)} agent-onboard "
f"{host_command(cli_bin)}{render_optional_cli_arg('--runtime-root', runtime_root_override)}"
" agent-onboard "
f"--agent-type {shell_arg_for_host(canonical_agent_type)} "
f"--project {shell_arg_for_host(resolved_project)} "
f"--goal-id {shell_arg_for_host(resolved_goal_id)}"
Expand Down
100 changes: 89 additions & 11 deletions loopx/bootstrap_command_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
render_refresh_state_command,
shell_arg_for_host,
)
from .paths import resolve_runtime_root
from .paths import global_registry_path, resolve_runtime_root
from .registry import registry_goals, resolve_state_file
from .slash_commands import build_slash_command_catalog
from .thread_agent_binding import normalize_thread_id, resolve_thread_agent_binding
Expand Down Expand Up @@ -563,6 +563,17 @@ def _read_registry(path: Path) -> tuple[dict[str, Any] | None, str | None]:
return payload, None


def resolve_bootstrap_activation_registry(
agent_type: str, registry_path: Path, *, connected: bool, runtime_root_override: str | None,
) -> str | None:
"""Carry the selected project into activation from an explicit App runtime."""
if agent_type == "antigravity-app" or (
agent_type == "codex-app" and connected and runtime_root_override is not None
):
return str(registry_path)
return None


def _runtime_roots(
registry: dict[str, Any] | None,
*,
Expand Down Expand Up @@ -598,21 +609,82 @@ def _select_goal(goals: list[dict[str, Any]], goal_id: str | None) -> tuple[str,
_BootstrapConnectionSnapshot = tuple[dict[str, object], dict[str, object] | None]


def _declared_project_runtime(registry_path: Path) -> str | None:
if (registry_path.parent.name, registry_path.name) != (".loopx", "registry.json"):
return None
registry, _ = _read_registry(registry_path)
if registry and registry.get("common_runtime_root"):
return str(resolve_runtime_root(registry, registry_path=registry_path))
return None


def resolve_bootstrap_project_route(
project: Path,
*,
goal_id: str | None,
runtime_root_arg: str | None,
explicit_project_registry: Path | None = None,
resolve_linked_worktree_alias: bool = True,
connection_snapshot: _BootstrapConnectionSnapshot | None = None,
) -> tuple[str | None, _BootstrapConnectionSnapshot]:
"""Resolve the connection and the runtime carried into emitted host commands."""
runtime_root = None
if runtime_root_arg:
registry_path = _resolve_project(project) / ".loopx" / "registry.json"
runtime_root = str(resolve_runtime_root({}, runtime_root_arg, registry_path=registry_path))
if connection_snapshot is not None:
return runtime_root, connection_snapshot

if runtime_root is None and explicit_project_registry is not None:
registry_path = explicit_project_registry.resolve()
declared_runtime = _declared_project_runtime(registry_path)
if declared_runtime is not None:
snapshot = _inspect_bootstrap_connection(
project, goal_id=goal_id, runtime_root=declared_runtime,
resolve_linked_worktree_alias=resolve_linked_worktree_alias,
)
connection, _ = snapshot
if (
connection["connection_state"] == "connected"
and Path(str(connection["registry"])).resolve() == registry_path
):
return declared_runtime, snapshot

return runtime_root, _inspect_bootstrap_connection(
project, goal_id=goal_id, runtime_root=runtime_root,
resolve_linked_worktree_alias=resolve_linked_worktree_alias,
)


def inspect_bootstrap_connection(
project: Path, *, goal_id: str | None = None, resolve_linked_worktree_alias: bool = True,
project: Path,
*,
goal_id: str | None = None,
resolve_linked_worktree_alias: bool = True,
runtime_root: str | None = None,
) -> dict[str, Any]:
"""Inspect either the canonical project route or the caller's exact route."""
return _inspect_bootstrap_connection(project, goal_id=goal_id,
resolve_linked_worktree_alias=resolve_linked_worktree_alias)[0]
return _inspect_bootstrap_connection(
project, goal_id=goal_id, resolve_linked_worktree_alias=resolve_linked_worktree_alias,
runtime_root=runtime_root,
)[0]


def _inspect_bootstrap_connection(
project: Path, *, goal_id: str | None, resolve_linked_worktree_alias: bool,
project: Path,
*,
goal_id: str | None,
resolve_linked_worktree_alias: bool,
runtime_root: str | None = None,
) -> _BootstrapConnectionSnapshot:
"""Capture the connection and the registry used to build it together."""
input_project = _resolve_project(project)
alias = (
resolve_canonical_project_alias(input_project, goal_id=goal_id)
resolve_canonical_project_alias(
input_project,
goal_id=goal_id,
global_registry=global_registry_path(Path(runtime_root)) if runtime_root else None,
)
if resolve_linked_worktree_alias
else {
"applied": False,
Expand Down Expand Up @@ -814,10 +886,15 @@ def build_loopx_bootstrap_command_pack(
resolve_linked_worktree_alias: bool = True,
display_name: str | None = None,
runtime_root_arg: str | None = None,
explicit_project_registry: Path | None = None,
_connection_snapshot: _BootstrapConnectionSnapshot | None = None,
) -> dict[str, Any]:
inspection, registry_payload = _connection_snapshot or _inspect_bootstrap_connection(
project, goal_id=goal_id, resolve_linked_worktree_alias=resolve_linked_worktree_alias,
agent_type = agent_type_for_host_surface(host_surface)
runtime_root_override, (inspection, registry_payload) = resolve_bootstrap_project_route(
project, goal_id=goal_id, runtime_root_arg=runtime_root_arg,
explicit_project_registry=explicit_project_registry if agent_type == "codex-app" else None,
resolve_linked_worktree_alias=resolve_linked_worktree_alias,
connection_snapshot=_connection_snapshot,
)
resolved_project = str(inspection["project"])
resolved_goal_id = str(inspection["goal_id"])
Expand All @@ -830,7 +907,6 @@ def build_loopx_bootstrap_command_pack(
cli_bin=cli_bin,
goal_id="<goal-id>",
)
agent_type = agent_type_for_host_surface(host_surface)
registry_path = Path(str(inspection["registry"]))
registry_goal = next(
(
Expand All @@ -844,9 +920,11 @@ def build_loopx_bootstrap_command_pack(
command_runtime_root, identity_runtime_root = _runtime_roots(
registry_payload,
registry_path=registry_path,
runtime_root_arg=runtime_root_arg,
runtime_root_arg=runtime_root_override,
)
activation_registry = resolve_bootstrap_activation_registry(
agent_type, registry_path, connected=connected, runtime_root_override=runtime_root_override,
)
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
9 changes: 9 additions & 0 deletions loopx/cli_commands/starter_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def handle_new_project_prompt_command(
def handle_agent_onboard_command(
args: argparse.Namespace,
print_payload: PrintPayload,
*,
runtime_root_arg: str | None = None,
explicit_project_registry: Path | None = None,
) -> int:
if bool(getattr(args, "list_agent_types", False)):
print_payload(build_agent_type_catalog(), args.format, render_agent_type_catalog_markdown)
Expand All @@ -78,6 +81,8 @@ def handle_agent_onboard_command(
cli_bin=args.cli_bin,
task_text=args.task_text,
available_capabilities=args.available_capabilities,
runtime_root_arg=runtime_root_arg,
explicit_project_registry=explicit_project_registry,
)
except AgentTypeError as exc:
print_payload(exc.to_payload(), args.format, render_agent_onboarding_markdown)
Expand All @@ -91,6 +96,7 @@ def handle_loopx_bootstrap_command_pack_command(
print_payload: PrintPayload,
*,
runtime_root_arg: str | None = None,
explicit_project_registry: Path | None = None,
) -> int:
payload = build_loopx_bootstrap_command_pack(
project=Path(args.project),
Expand All @@ -105,6 +111,7 @@ def handle_loopx_bootstrap_command_pack_command(
capability_route=args.capability_route,
fine_grained=bool(args.fine_grained),
runtime_root_arg=runtime_root_arg,
explicit_project_registry=explicit_project_registry,
)
if bool(getattr(args, "message_only", False)):
print(str(payload.get("message") or ""))
Expand Down Expand Up @@ -148,4 +155,6 @@ def handle_starter_bootstrap_command(
return handler(args, print_payload, runtime_root_arg=args.runtime_root)
if handler is handle_loopx_bootstrap_command_pack_command:
return handler(args, print_payload, runtime_root_arg=args.runtime_root)
if handler is handle_agent_onboard_command:
return handler(args, print_payload, runtime_root_arg=args.runtime_root)
return handler(args, print_payload)
28 changes: 24 additions & 4 deletions loopx/cli_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,32 @@ def _dispatch_common_command(
return handle_start_goal_command(
args, print_payload, runtime_root_arg=args.runtime_root,
)
if args.command == "bootstrap-command-pack":
from .cli_commands.starter_bootstrap import handle_loopx_bootstrap_command_pack_command
if args.command in {"bootstrap-command-pack", "agent-onboard"}:
from .cli_commands.starter_bootstrap import (
handle_agent_onboard_command, handle_loopx_bootstrap_command_pack_command,
)

return handle_loopx_bootstrap_command_pack_command(
args, print_payload, runtime_root_arg=args.runtime_root,
runtime_root_arg = args.runtime_root
# Project commands use a registry anchor only when it was supplied on the CLI.
if runtime_root_arg and not allow_missing_registry:
from .paths import resolve_runtime_root

runtime_root_arg = (
str(registry_path.parent.absolute())
if str(args.registry) == HOST_GLOBAL_REGISTRY_SELECTOR
else str(resolve_runtime_root({}, runtime_root_arg, registry_path=registry_path))
)
handler = (
handle_agent_onboard_command if args.command == "agent-onboard"
else handle_loopx_bootstrap_command_pack_command
)
explicit_project_registry = (
registry_path
if not allow_missing_registry and str(args.registry) != HOST_GLOBAL_REGISTRY_SELECTOR
else None
)
return handler(args, print_payload, runtime_root_arg=runtime_root_arg,
explicit_project_registry=explicit_project_registry)
if args.command in {"bootstrap", "connect"}:
from .cli_commands.bootstrap_connect import handle_bootstrap_connect_command

Expand Down
2 changes: 2 additions & 0 deletions loopx/host_loop_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@ def build_host_loop_activation_packet(
cadence_args = [cli_bin, "--format", "json"]
if runtime_root:
cadence_args.extend(["--runtime-root", runtime_root])
if registry:
cadence_args.extend(["--registry", registry])
cadence_args.extend(["automation-cadence", "--goal-id", goal_id])
if selected_agent_id:
cadence_args.extend(["--agent-id", str(selected_agent_id)])
Expand Down
Loading
Loading