From 0c0d34f7267829f71cf770f77a89d9ab0b7dd8f2 Mon Sep 17 00:00:00 2001 From: huangruiteng Date: Thu, 19 Nov 2026 16:10:02 +0800 Subject: [PATCH 1/2] Keep explicit Codex App activation on the selected project Signed-off-by: huangruiteng --- loopx/agent_onboarding.py | 27 +++- loopx/bootstrap_command_pack.py | 53 ++++++-- loopx/cli_commands/starter_bootstrap.py | 5 + loopx/cli_runtime.py | 22 +++- loopx/host_loop_activation.py | 2 + tests/test_bootstrap_command_pack_platform.py | 120 ++++++++++++++++++ 6 files changed, 212 insertions(+), 17 deletions(-) diff --git a/loopx/agent_onboarding.py b/loopx/agent_onboarding.py index bee609f34b..4cc6f79d24 100644 --- a/loopx/agent_onboarding.py +++ b/loopx/agent_onboarding.py @@ -5,7 +5,11 @@ 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 ( + inspect_bootstrap_connection, + resolve_bootstrap_activation_registry, + resolve_bootstrap_runtime_override, +) from .capabilities.change_quality.policy import change_quality_goal_policy from .host_loop_activation import ( agent_type_uses_host_managed_skills, @@ -29,6 +33,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, @@ -284,6 +289,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", @@ -308,7 +314,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), @@ -437,9 +443,11 @@ 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, ) -> dict[str, Any]: canonical_agent_type = normalize_agent_type(agent_type) - inspection = inspect_bootstrap_connection(project, goal_id=goal_id) + runtime_root_override = resolve_bootstrap_runtime_override(project, runtime_root_arg) + inspection = inspect_bootstrap_connection(project, goal_id=goal_id, runtime_root=runtime_root_override) resolved_project = str(inspection["project"]) resolved_goal_id = str(inspection["goal_id"]) registry_path = Path(str(inspection["registry"])) @@ -460,6 +468,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( @@ -482,12 +491,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, @@ -507,6 +521,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( @@ -519,6 +534,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), @@ -527,7 +543,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)}" diff --git a/loopx/bootstrap_command_pack.py b/loopx/bootstrap_command_pack.py index 8451873ba5..d994815c48 100644 --- a/loopx/bootstrap_command_pack.py +++ b/loopx/bootstrap_command_pack.py @@ -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 @@ -563,6 +563,25 @@ 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 resolve_bootstrap_runtime_override(project: Path, override: str | None) -> str | None: + """Anchor an explicit route to the requested project before looking for aliases.""" + if not override: + return None + registry_path = _resolve_project(project) / ".loopx" / "registry.json" + return str(resolve_runtime_root({}, override, registry_path=registry_path)) + + def _runtime_roots( registry: dict[str, Any] | None, *, @@ -599,20 +618,34 @@ def _select_goal(goals: list[dict[str, Any]], goal_id: str | None) -> tuple[str, 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, @@ -816,8 +849,10 @@ def build_loopx_bootstrap_command_pack( runtime_root_arg: str | None = None, _connection_snapshot: _BootstrapConnectionSnapshot | None = None, ) -> dict[str, Any]: + runtime_root_override = resolve_bootstrap_runtime_override(project, runtime_root_arg) inspection, registry_payload = _connection_snapshot or _inspect_bootstrap_connection( project, goal_id=goal_id, resolve_linked_worktree_alias=resolve_linked_worktree_alias, + runtime_root=runtime_root_override, ) resolved_project = str(inspection["project"]) resolved_goal_id = str(inspection["goal_id"]) @@ -844,9 +879,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, diff --git a/loopx/cli_commands/starter_bootstrap.py b/loopx/cli_commands/starter_bootstrap.py index 3d21efbca3..2e92b68cbf 100644 --- a/loopx/cli_commands/starter_bootstrap.py +++ b/loopx/cli_commands/starter_bootstrap.py @@ -57,6 +57,8 @@ def handle_new_project_prompt_command( def handle_agent_onboard_command( args: argparse.Namespace, print_payload: PrintPayload, + *, + runtime_root_arg: str | None = None, ) -> int: if bool(getattr(args, "list_agent_types", False)): print_payload(build_agent_type_catalog(), args.format, render_agent_type_catalog_markdown) @@ -78,6 +80,7 @@ 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, ) except AgentTypeError as exc: print_payload(exc.to_payload(), args.format, render_agent_onboarding_markdown) @@ -148,4 +151,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) diff --git a/loopx/cli_runtime.py b/loopx/cli_runtime.py index bc674449aa..213ab29a32 100644 --- a/loopx/cli_runtime.py +++ b/loopx/cli_runtime.py @@ -568,12 +568,26 @@ 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 ) + return handler(args, print_payload, runtime_root_arg=runtime_root_arg) if args.command in {"bootstrap", "connect"}: from .cli_commands.bootstrap_connect import handle_bootstrap_connect_command diff --git a/loopx/host_loop_activation.py b/loopx/host_loop_activation.py index 9943c049ee..2c00da83cd 100644 --- a/loopx/host_loop_activation.py +++ b/loopx/host_loop_activation.py @@ -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)]) diff --git a/tests/test_bootstrap_command_pack_platform.py b/tests/test_bootstrap_command_pack_platform.py index d717a6834b..5f9842a895 100644 --- a/tests/test_bootstrap_command_pack_platform.py +++ b/tests/test_bootstrap_command_pack_platform.py @@ -2,6 +2,7 @@ from __future__ import annotations +import json import os import shlex import shutil @@ -13,6 +14,7 @@ import loopx.project_prompt as project_prompt from loopx.bootstrap_command_pack import build_start_goal_guided_packet +from host_surface_cli_probes import connected_project, run_cli PWSH = shutil.which("pwsh") @@ -20,6 +22,124 @@ GOAL_TEXT = "Verify native PowerShell guided connection" +@pytest.mark.parametrize("surface", ["antigravity-app", "codex-app"]) +@pytest.mark.parametrize("entry, surface_option", [ + ("bootstrap-command-pack", "--host-surface"), + ("agent-onboard", "--agent-type"), +]) +def test_activation_uses_explicit_runtime_for_linked_project_discovery( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, entry: str, surface_option: str, surface: str, +) -> None: + from loopx import paths + from loopx.capabilities.change_quality.machine_defaults import ( + CHANGE_QUALITY_MACHINE_DEFAULTS_SCHEMA, + ) + from loopx.capabilities.machine_configuration.contract import MACHINE_CONFIGURATION_SCHEMA + from loopx.capabilities.machine_configuration.store import machine_configuration_store_path + + monkeypatch.delenv("LOOPX_RUNTIME_ROOT", raising=False) + monkeypatch.delenv("LOOPX_REGISTRY", raising=False) + markers = {} + for root in (paths.DEFAULT_RUNTIME_ROOT, paths.LEGACY_RUNTIME_ROOT): + marker = root / "owned-state" / "marker.json" + marker.parent.mkdir(parents=True) + marker.write_text('{"preserved":true}\n', encoding="utf-8") + markers[marker] = marker.read_bytes() + assert paths.default_runtime_route()["status"] == "conflict" + + primary = connected_project(tmp_path / "canonical") + registry = primary / ".loopx" / "registry.json" + state = primary / "ACTIVE_GOAL_STATE.md" + state.write_text("# Goal\n\nVerify the selected activation route.\n", encoding="utf-8") + document = json.loads(registry.read_text(encoding="utf-8")) + document["common_runtime_root"] = str(tmp_path / "other runtime") + goal = document["goals"][0] + goal["state_file"] = state.name + goal["coordination"] = {"registered_agents": ["probe-agent"], "agent_model": "peer_v1"} + registry.write_text(json.dumps(document), encoding="utf-8") + for argv in ( + ["init"], + ["-c", "user.name=LoopX Test", "-c", "user.email=loopx@example.invalid", + "commit", "--allow-empty", "-m", "test fixture"], + ): + subprocess.run(["git", *argv], cwd=primary, check=True, capture_output=True) + linked = tmp_path / "linked project" + subprocess.run(["git", "worktree", "add", "--detach", str(linked)], cwd=primary, + check=True, capture_output=True) + selected = primary / "selected runtime" + linked_runtime = linked / selected.name + foreign_project = connected_project(tmp_path / "foreign") + foreign_registry = foreign_project / ".loopx" / "registry.json" + foreign_runtime = foreign_project / selected.name + for runtime in (selected, linked_runtime, foreign_runtime): + runtime.mkdir() + global_registry = paths.global_registry_path(runtime) + global_registry.write_text(json.dumps({ + "goals": [{**goal, "source_registry": str(registry)}], + }), encoding="utf-8") + markers[global_registry] = global_registry.read_bytes() + foreign_configuration = machine_configuration_store_path(foreign_runtime) + foreign_configuration.parent.mkdir() + foreign_configuration.write_text(json.dumps({ + "schema_version": MACHINE_CONFIGURATION_SCHEMA, + "namespaces": {"change_quality_qualification": { + "schema_version": CHANGE_QUALITY_MACHINE_DEFAULTS_SCHEMA, + "enabled": True, "safe_fix": False, "strict_receipt": False, + }}, + }), encoding="utf-8") + markers[foreign_configuration] = foreign_configuration.read_bytes() + monkeypatch.setenv("LOOPX_REGISTRY", str(foreign_registry)) + + markers.update({path: path.read_bytes() for path in (registry, foreign_registry, state)}) + args = ( + "--registry", str(registry), entry, surface_option, surface, "--project", str(linked), + "--goal-id", "surface-goal", "--agent-id", "probe-agent", + ) + for route, registry_args, expected_runtime in ( + (selected.name, args, selected), + (str(selected), args[2:], selected), + (str(selected), ("--registry", "@host-global", *args[2:]), selected), + (linked_runtime.name, args[2:], linked_runtime), + ): + explicit = run_cli("--runtime-root", route, *registry_args, cwd=tmp_path) + assert explicit.returncode == 0, explicit.stdout + explicit.stderr + packet = json.loads(explicit.stdout) + alias = packet["project_connection"]["canonical_project_alias"] + assert alias["applied"] + assert Path(alias["global_registry"]) == paths.global_registry_path(expected_runtime) + assert Path(packet["project_connection"]["registry"]) == registry + activation = packet["host_loop_activation"] + assert activation["activation_allowed"] + commands = [activation["activation_input_command"]] + activation_args = shlex.split(commands[0], posix=os.name != "nt") + if os.name != "nt": + assert activation_args[0] == "loopx" + launched = run_cli(*activation_args[1:], cwd=tmp_path) + assert launched.returncode == 0, launched.stdout + launched.stderr + launched_packet = json.loads(launched.stdout) + assert launched_packet["ok"] and launched_packet["goal_id"] == "surface-goal" + assert launched_packet["agent_id"] == "probe-agent" + assert Path(activation_args[activation_args.index("--registry") + 1].strip("'")) == registry + if surface == "codex-app": + for command in (packet["commands"]["quota_guard"], activation["commands"]["automation_cadence_json"]): + argv = shlex.split(command, posix=os.name != "nt") + assert Path(argv[argv.index("--registry") + 1].strip("'")) == registry + assert Path(argv[argv.index("--runtime-root") + 1].strip("'")) == expected_runtime + if entry == "agent-onboard": + assert "loopx-change-quality" not in packet["skill_delivery"]["active_project_skill_ids"] + commands += [packet["commands"][key] for key in ( + "bootstrap_command_pack", "agent_onboard_recheck", "quota_guard", + )] + for command in commands: + argv = shlex.split(command, posix=os.name != "nt") + assert Path(argv[argv.index("--runtime-root") + 1].strip("'")) == expected_runtime + + implicit = run_cli(*args, cwd=tmp_path) + assert implicit.returncode != 0 + assert "Both default LoopX runtime roots contain state" in implicit.stdout + implicit.stderr + assert all(path.read_bytes() == data for path, data in markers.items()) + + def guided_packet( project: Path, *, From 97e997b71ba0d350de94511138fb4b9f1c6ca339 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:06:42 +0800 Subject: [PATCH 2/2] Keep declared project registries through Codex App activation Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/agent_onboarding.py | 10 +-- loopx/bootstrap_command_pack.py | 67 +++++++++++++++---- loopx/cli_commands/starter_bootstrap.py | 4 ++ loopx/cli_runtime.py | 8 ++- tests/test_bootstrap_command_pack_platform.py | 33 +++++++++ 5 files changed, 104 insertions(+), 18 deletions(-) diff --git a/loopx/agent_onboarding.py b/loopx/agent_onboarding.py index 4cc6f79d24..bb4c8fe38c 100644 --- a/loopx/agent_onboarding.py +++ b/loopx/agent_onboarding.py @@ -6,9 +6,8 @@ from .agent_registry import registered_agent_ids_from_registry from .bootstrap_command_pack import ( - inspect_bootstrap_connection, resolve_bootstrap_activation_registry, - resolve_bootstrap_runtime_override, + resolve_bootstrap_project_route, ) from .capabilities.change_quality.policy import change_quality_goal_policy from .host_loop_activation import ( @@ -444,10 +443,13 @@ def build_agent_onboarding_packet( 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) - runtime_root_override = resolve_bootstrap_runtime_override(project, runtime_root_arg) - inspection = inspect_bootstrap_connection(project, goal_id=goal_id, runtime_root=runtime_root_override) + 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"])) diff --git a/loopx/bootstrap_command_pack.py b/loopx/bootstrap_command_pack.py index d994815c48..03806ebf73 100644 --- a/loopx/bootstrap_command_pack.py +++ b/loopx/bootstrap_command_pack.py @@ -574,14 +574,6 @@ def resolve_bootstrap_activation_registry( return None -def resolve_bootstrap_runtime_override(project: Path, override: str | None) -> str | None: - """Anchor an explicit route to the requested project before looking for aliases.""" - if not override: - return None - registry_path = _resolve_project(project) / ".loopx" / "registry.json" - return str(resolve_runtime_root({}, override, registry_path=registry_path)) - - def _runtime_roots( registry: dict[str, Any] | None, *, @@ -617,6 +609,53 @@ 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, *, @@ -847,12 +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]: - runtime_root_override = resolve_bootstrap_runtime_override(project, runtime_root_arg) - inspection, registry_payload = _connection_snapshot or _inspect_bootstrap_connection( - project, goal_id=goal_id, resolve_linked_worktree_alias=resolve_linked_worktree_alias, - runtime_root=runtime_root_override, + 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"]) @@ -865,7 +907,6 @@ def build_loopx_bootstrap_command_pack( cli_bin=cli_bin, goal_id="", ) - agent_type = agent_type_for_host_surface(host_surface) registry_path = Path(str(inspection["registry"])) registry_goal = next( ( diff --git a/loopx/cli_commands/starter_bootstrap.py b/loopx/cli_commands/starter_bootstrap.py index 2e92b68cbf..f94993221b 100644 --- a/loopx/cli_commands/starter_bootstrap.py +++ b/loopx/cli_commands/starter_bootstrap.py @@ -59,6 +59,7 @@ def handle_agent_onboard_command( 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) @@ -81,6 +82,7 @@ def handle_agent_onboard_command( 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) @@ -94,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), @@ -108,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 "")) diff --git a/loopx/cli_runtime.py b/loopx/cli_runtime.py index ef8c776404..dd605032e1 100644 --- a/loopx/cli_runtime.py +++ b/loopx/cli_runtime.py @@ -587,7 +587,13 @@ def _dispatch_common_command( handle_agent_onboard_command if args.command == "agent-onboard" else handle_loopx_bootstrap_command_pack_command ) - return handler(args, print_payload, runtime_root_arg=runtime_root_arg) + 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 diff --git a/tests/test_bootstrap_command_pack_platform.py b/tests/test_bootstrap_command_pack_platform.py index 5f9842a895..afddfa5941 100644 --- a/tests/test_bootstrap_command_pack_platform.py +++ b/tests/test_bootstrap_command_pack_platform.py @@ -139,6 +139,39 @@ def test_activation_uses_explicit_runtime_for_linked_project_discovery( assert "Both default LoopX runtime roots contain state" in implicit.stdout + implicit.stderr assert all(path.read_bytes() == data for path, data in markers.items()) + if surface == "codex-app": + # A concrete project registry can name the runtime itself. The generated + # commands must keep that route even when the next shell has a foreign registry. + document["common_runtime_root"] = selected.name + registry.write_text(json.dumps(document), encoding="utf-8") + markers[registry] = registry.read_bytes() + for project in (primary, linked): + request = ( + "--registry", str(registry), entry, surface_option, surface, + "--project", str(project), "--goal-id", "surface-goal", "--agent-id", "probe-agent", + ) + declared = run_cli(*request, cwd=tmp_path) + assert declared.returncode == 0, declared.stdout + declared.stderr + packet = json.loads(declared.stdout) + connection = packet["project_connection"] + assert Path(connection["registry"]) == registry + if project == linked: + assert connection["canonical_project_alias"]["applied"] + activation = packet["host_loop_activation"] + assert activation["activation_allowed"] + for command in ( + activation["activation_input_command"], + activation["commands"]["automation_cadence_json"], + packet["commands"]["quota_guard"], + ): + argv = shlex.split(command, posix=os.name != "nt") + assert Path(argv[argv.index("--registry") + 1].strip("'")) == registry + assert Path(argv[argv.index("--runtime-root") + 1].strip("'")) == selected + implicit = run_cli(*args[2:], cwd=tmp_path) + assert implicit.returncode != 0 + assert "Both default LoopX runtime roots contain state" in implicit.stdout + implicit.stderr + assert all(path.read_bytes() == data for path, data in markers.items()) + def guided_packet( project: Path,