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
19 changes: 15 additions & 4 deletions loopx/capabilities/agent_turn_recall/catalog_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@

from typing import Any

from ...python_install_owner import builtin_capability_installed
from ...python_install_owner import inspect_builtin_capability_distribution


AGENT_TURN_RECALL_SCHEMA_VERSION = "agent_turn_recall_v0"
AGENT_TURN_RECALL_SURFACE_ID = "agent_workflow.turn_admission"
RECALL_DISTRIBUTION = "loopx-capability-agent-turn-recall"
RECALL_INSTALL_HINT = f"Install the matching {RECALL_DISTRIBUTION} wheel in this Core environment."
RECALL_MODULES = (f"{__package__}.cli", f"{__package__}.core")


def agent_turn_recall_installed(*, builtin_cli_present: bool | None = None) -> bool:
return builtin_capability_installed(
RECALL_DISTRIBUTION, (f"{__package__}.cli", f"{__package__}.core"),
def inspect_agent_turn_recall_distribution(
*, builtin_cli_present: bool | None = None,
) -> dict[str, Any]:
"""Inspect whether the optional agent-turn-recall wheel is installed and matches Core."""
return inspect_builtin_capability_distribution(
RECALL_DISTRIBUTION,
RECALL_MODULES,
builtin_cli_present=builtin_cli_present,
)


def agent_turn_recall_installed(*, builtin_cli_present: bool | None = None) -> bool:
return bool(
inspect_agent_turn_recall_distribution(builtin_cli_present=builtin_cli_present)["ready"]
)


AGENT_TURN_RECALL_CATALOG_ENTRY: dict[str, Any] = {
"id": "agent-turn-recall",
"origin": "builtin",
Expand Down
15 changes: 12 additions & 3 deletions loopx/capabilities/benchmark_toolkit/catalog_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any

from ...python_install_owner import BENCHMARK_TOOLKIT_DISTRIBUTION, builtin_capability_installed
from ...python_install_owner import BENCHMARK_TOOLKIT_DISTRIBUTION, inspect_builtin_capability_distribution
from .four_arm_contract import (
BENCHMARK_FOUR_ARM_ATTESTATIONS,
BENCHMARK_FOUR_ARM_RUNNER_OBLIGATIONS,
Expand All @@ -28,14 +28,23 @@
)


def benchmark_toolkit_installed(*, builtin_cli_present: bool | None = None) -> bool:
return builtin_capability_installed(
def inspect_benchmark_toolkit_distribution(
*, builtin_cli_present: bool | None = None,
) -> dict[str, Any]:
"""Inspect whether the optional benchmark-toolkit wheel is installed and matches Core."""
return inspect_builtin_capability_distribution(
BENCHMARK_TOOLKIT_DISTRIBUTION,
BENCHMARK_TOOLKIT_STARTUP_MODULES,
builtin_cli_present=builtin_cli_present,
)


def benchmark_toolkit_installed(*, builtin_cli_present: bool | None = None) -> bool:
return bool(
inspect_benchmark_toolkit_distribution(builtin_cli_present=builtin_cli_present)["ready"]
)


BENCHMARK_TOOLKIT_CATALOG_ENTRY: dict[str, Any] = {
"id": "benchmark-toolkit",
"origin": "builtin",
Expand Down
20 changes: 16 additions & 4 deletions loopx/capabilities/issue_fix/catalog_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@

from typing import Any

from ...python_install_owner import builtin_capability_installed
from ...python_install_owner import inspect_builtin_capability_distribution
from .command_templates import build_issue_fix_pr_lifecycle_command


ISSUE_FIX_DISTRIBUTION = "loopx-capability-issue-fix"
ISSUE_FIX_INSTALL_HINT = f"Install the matching {ISSUE_FIX_DISTRIBUTION} wheel in this Core environment."
ISSUE_FIX_MODULES = tuple(
f"{__package__}.{name}" for name in ("cli", "candidate_preflight", "workflow_plan", "acceptance_loop")
)


def issue_fix_workflow_installed(*, builtin_cli_present: bool | None = None) -> bool:
return builtin_capability_installed(
def inspect_issue_fix_workflow_distribution(
*, builtin_cli_present: bool | None = None,
) -> dict[str, Any]:
"""Inspect whether the optional issue-fix wheel is installed and matches Core."""
return inspect_builtin_capability_distribution(
ISSUE_FIX_DISTRIBUTION,
tuple(f"{__package__}.{name}" for name in ("cli", "candidate_preflight", "workflow_plan", "acceptance_loop")),
ISSUE_FIX_MODULES,
builtin_cli_present=builtin_cli_present,
)


def issue_fix_workflow_installed(*, builtin_cli_present: bool | None = None) -> bool:
return bool(
inspect_issue_fix_workflow_distribution(builtin_cli_present=builtin_cli_present)["ready"]
)


# The ordinary CLI continues to expose these compatibility command groups.
_COMPATIBILITY_COMMANDS = [
{
Expand Down
23 changes: 19 additions & 4 deletions loopx/capabilities/pr_review_queue/catalog_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

from typing import Any

from ...python_install_owner import builtin_capability_installed
from ...python_install_owner import inspect_builtin_capability_distribution

PR_REVIEW_DISTRIBUTION = "loopx-capability-pull-request-review"
PR_REVIEW_INSTALL_HINT = f"Install the matching {PR_REVIEW_DISTRIBUTION} wheel in this Core environment."
PR_REVIEW_MODULES = (
"loopx.cli_commands.pr_review",
"loopx.pr_review",
"loopx.pr_review_merge_readiness",
f"{__package__}.core",
)


def pull_request_review_installed(*, builtin_cli_present: bool | None = None) -> bool:
return builtin_capability_installed(
def inspect_pull_request_review_distribution(
*, builtin_cli_present: bool | None = None,
) -> dict[str, Any]:
"""Inspect whether the optional PR-review wheel is installed and matches Core."""
return inspect_builtin_capability_distribution(
PR_REVIEW_DISTRIBUTION,
("loopx.cli_commands.pr_review", "loopx.pr_review", "loopx.pr_review_merge_readiness", f"{__package__}.core"),
PR_REVIEW_MODULES,
builtin_cli_present=builtin_cli_present,
)


def pull_request_review_installed(*, builtin_cli_present: bool | None = None) -> bool:
return bool(
inspect_pull_request_review_distribution(builtin_cli_present=builtin_cli_present)["ready"]
)


PR_REVIEW_CATALOG_ENTRY: dict[str, Any] = {
"id": "pull-request-review",
"origin": "builtin",
Expand Down
16 changes: 12 additions & 4 deletions loopx/cli_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,14 @@ def _standalone_core() -> bool:
return False


def _workspace_installed() -> bool:
from .python_install_owner import WORKSPACE_DISTRIBUTION, builtin_capability_installed
def inspect_workspace_distribution(*, builtin_cli_present: bool | None = None) -> dict[str, Any]:
"""Inspect whether the optional Workspace wheel is installed and matches Core."""
from .python_install_owner import (
WORKSPACE_DISTRIBUTION,
inspect_builtin_capability_distribution,
)

return builtin_capability_installed(
return inspect_builtin_capability_distribution(
WORKSPACE_DISTRIBUTION,
(
"loopx.chat",
Expand All @@ -1122,7 +1126,7 @@ def _workspace_installed() -> bool:
"loopx.presentation.research_analysis_api",
"loopx.presentation.runtime_workspace",
),
builtin_cli_present=False,
builtin_cli_present=builtin_cli_present,
resources=(
"loopx/chat/endpoints.py",
"loopx/chat/lark_api.py",
Expand All @@ -1131,6 +1135,10 @@ def _workspace_installed() -> bool:
)


def _workspace_installed() -> bool:
return bool(inspect_workspace_distribution(builtin_cli_present=False)["ready"])


def _run_full_cli(raw_argv: list[str]) -> int:
try:
from .cli import main as cli_main
Expand Down
35 changes: 33 additions & 2 deletions loopx/python_install_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ def distribution_recorded_files(installed: Distribution) -> list[tuple[str, Path
return entries


def read_editable_direct_url(installed: Distribution) -> bool | None:
"""Inspect ``direct_url.json`` for editable metadata, returning ``None`` when malformed."""
try:
raw_direct_url = installed.read_text("direct_url.json")
if raw_direct_url is None:
dist_path = getattr(installed, "_path", None)
if isinstance(dist_path, (str, os.PathLike)):
direct_url_path = Path(dist_path) / "direct_url.json"
try:
direct_url_path.lstat()
except FileNotFoundError:
raw_direct_url = None
else:
# PathDistribution.read_text swallows PermissionError and IsADirectoryError as None.
raw_direct_url = direct_url_path.read_text(encoding="utf-8")
direct_url = json.loads(raw_direct_url) if raw_direct_url is not None else {}
except (OSError, ValueError):
return None
if not isinstance(direct_url, dict):
return None
if "dir_info" in direct_url:
dir_info = direct_url["dir_info"]
if not isinstance(dir_info, dict):
return None
return bool(dir_info.get("editable"))
return False


def inspect_builtin_capability_distribution(
distribution_name: str,
modules: tuple[str, ...],
Expand Down Expand Up @@ -133,8 +161,9 @@ def inspect_builtin_capability_distribution(
"unowned_resources": [],
}

direct_url = json.loads(implementation.read_text("direct_url.json") or "{}")
editable = bool(direct_url.get("dir_info", {}).get("editable"))
editable_flag = read_editable_direct_url(implementation)
invalid_metadata = editable_flag is None
editable = bool(editable_flag)
entries = distribution_recorded_files(implementation)
package_parent = Path(__file__).resolve().parent.parent
recorded = {path.resolve() for _name, path in entries or ()}
Expand Down Expand Up @@ -177,6 +206,8 @@ def inspect_builtin_capability_distribution(
reasons.append("core_distribution_missing")
elif implementation.version != core_version:
reasons.append("version_mismatch")
if invalid_metadata:
reasons.append("invalid_companion_metadata")
if editable:
reasons.append("editable_companion_unsupported")
if missing_modules or missing_resources:
Expand Down
44 changes: 34 additions & 10 deletions loopx/release_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .command_invocation import command_argv
from .python_install_owner import (
RESEARCH_DISTRIBUTION,
distribution_record_path,
installed_loopx_distribution,
verified_distribution_console,
Expand Down Expand Up @@ -311,7 +310,6 @@ def collect_companion_distribution_diagnostics(
) -> tuple[list[dict[str, Any]], list[dict[str, Any]], str | None]:
"""Inspect installed optional companion wheels for standalone loopx-core."""
from importlib.util import find_spec
from .capabilities.deep_research.catalog_entry import inspect_research_workflow_distribution

if find_spec("loopx.cli") is not None:
return [], [], None
Expand All @@ -321,9 +319,24 @@ def collect_companion_distribution_diagnostics(
return [], [], None
if getattr(installed, "name", None) != "loopx-core":
return [], [], None
from .capabilities.agent_turn_recall.catalog_entry import inspect_agent_turn_recall_distribution
from .capabilities.benchmark_toolkit.catalog_entry import inspect_benchmark_toolkit_distribution
from .capabilities.deep_research.catalog_entry import inspect_research_workflow_distribution
from .capabilities.issue_fix.catalog_entry import inspect_issue_fix_workflow_distribution
from .capabilities.pr_review_queue.catalog_entry import inspect_pull_request_review_distribution
from .cli_runtime import inspect_workspace_distribution

inspectors = (
inspect_workspace_distribution,
inspect_benchmark_toolkit_distribution,
inspect_agent_turn_recall_distribution,
inspect_pull_request_review_distribution,
inspect_issue_fix_workflow_distribution,
inspect_research_workflow_distribution,
)
companions = [
item
for item in (inspect_research_workflow_distribution(builtin_cli_present=False),)
for item in (inspect_fn(builtin_cli_present=False) for inspect_fn in inspectors)
if item["installed"]
]
checks: list[dict[str, Any]] = []
Expand All @@ -346,10 +359,15 @@ def collect_companion_distribution_diagnostics(
if missing:
summary += f" [{', '.join(missing)}]"
details.append(summary)
fix_parts.append(
f"Reinstall matching `{item['distribution']}=={item['core_version']}` "
f"or uninstall `{item['distribution']}`."
)
if item["core_version"]:
fix_parts.append(
f"Reinstall matching `{item['distribution']}=={item['core_version']}` "
f"or uninstall `{item['distribution']}`."
)
else:
fix_parts.append(
f"Reinstall matching `{item['distribution']}` or uninstall `{item['distribution']}`."
)
checks.append(
{
"id": "companion_distributions_compatible",
Expand Down Expand Up @@ -396,9 +414,15 @@ def collect_companion_distribution_diagnostics(
}
)
if not fingerprint_ok and not fix_parts:
fix_parts.append(
f"Repair or reinstall `loopx-core` and any `{RESEARCH_DISTRIBUTION}` companion at the exact Core version."
)
companion_names = ", ".join(f"`{item['distribution']}`" for item in companions)
if companion_names:
fix_parts.append(
f"Repair or reinstall `loopx-core` and installed companions ({companion_names}) at the exact Core version."
)
else:
fix_parts.append(
"Repair or reinstall `loopx-core` and any optional companion wheel at the exact Core version."
)
return companions, checks, " ".join(fix_parts) if fix_parts else None


Expand Down
5 changes: 3 additions & 2 deletions loopx/release_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
distribution_recorded_files,
installed_loopx_distribution,
is_distribution_artifact,
read_editable_direct_url,
)


Expand Down Expand Up @@ -324,8 +325,8 @@ def release_runtime_identity(release_root: Path | None = None) -> dict[str, str


def _owned_runtime_files(installed: Distribution) -> dict[str, Path]:
direct_url = json.loads(installed.read_text("direct_url.json") or "{}")
if direct_url.get("dir_info", {}).get("editable") or installed.version != __version__:
editable_flag = read_editable_direct_url(installed)
if editable_flag is None or editable_flag or installed.version != __version__:
return {}
entries = distribution_recorded_files(installed)
if entries is None:
Expand Down
Loading
Loading