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
16 changes: 16 additions & 0 deletions .github/workflows/package-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:
paths:
- ".github/workflows/package-smoke.yml"
- "packages/**"
- "apps/presentation/dashboard/**"
- "scripts/chat_bundle.py"
- "tests/test_core_distribution.py"
- "tests/test_core_workspace_distribution.py"
- "tests/test_core_recall_distribution.py"
- "tests/test_core_pr_review_distribution.py"
- "tests/test_core_issue_fix_distribution.py"
Expand All @@ -20,8 +23,11 @@ on:
paths:
- ".github/workflows/package-smoke.yml"
- "packages/**"
- "apps/presentation/dashboard/**"
- "scripts/chat_bundle.py"
- "loopx/**"
- "tests/test_core_distribution.py"
- "tests/test_core_workspace_distribution.py"
- "tests/test_core_recall_distribution.py"
- "tests/test_core_pr_review_distribution.py"
- "tests/test_core_issue_fix_distribution.py"
Expand Down Expand Up @@ -119,6 +125,16 @@ jobs:
LOOPX_STANDARD_TEST_WHEELHOUSE="$RUNNER_TEMP/core-dist" uv run --extra test python -m pytest -q \
tests/test_core_standard_distribution.py

- name: Build the matching Workspace wheel
run: |
uv run --extra test python scripts/chat_bundle.py build --install
uv run --extra test python packages/loopx-core/prepare.py --distribution loopx-workspace --output "$RUNNER_TEMP/workspace-source"
uv build --wheel "$RUNNER_TEMP/workspace-source" --out-dir "$RUNNER_TEMP/workspace-dist"
printf 'LOOPX_CORE_TEST_WHEEL=%s\n' "$RUNNER_TEMP"/core-dist/loopx_core-*.whl >> "$GITHUB_ENV"
printf 'LOOPX_WORKSPACE_TEST_WHEEL=%s\n' "$RUNNER_TEMP"/workspace-dist/loopx_workspace-*.whl >> "$GITHUB_ENV"
- name: Qualify Workspace readback and removal on File and SQLite
run: uv run --extra test python -m pytest -q tests/test_core_workspace_distribution.py

codex-provider-routing:
name: loopx-codex-provider-routing
runs-on: ubuntu-latest
Expand Down
19 changes: 19 additions & 0 deletions docs/architecture/rfcs/monorepo-distribution-split-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ This is an installation layout. CLI handlers and host facilities inside
provider distributions keep the existing `packages/<package-id>/` convention;
the capability-package row does not require one capability per provider.

The local [Workspace wheel](../../../packages/loopx-workspace/README.md) adds
Chat, Dashboard and the existing endpoint manager to the same release of
`loopx-core`. It carries the verified browser bundle and opens the registry and
runtime used by Core. Launch is explicit. Core help and task execution leave
Workspace unloaded, and the Workspace loads the assessment executor on a
research analysis request. Package smoke exercises a checked Core task,
readback after installing and restarting Workspace, and Core replay after
removal on File and SQLite. The native App, IM and split public release still
have their own R2/M3 acceptance.

Workspace carries the native Steward session, monitor and report adapters
and the managed Session calendar because they use its original conversation
store. These adapters reuse the Core command parsers and execution owners.
Standalone Core observes pending requests and results at Turn start
through the shared Inbox owner. Peers can request, adopt and return work
through that owner. Only returns to an original Workspace conversation use its
session store. Inbox read routes and receipts retain their scoped identities
when Workspace is added or removed.

Authority does not move: the kernel remains the only writer of Goal/Todo/claim/
lease/quota/effect state. A capability package may only register providers,
capability contracts and CLI subcommands through `CapabilityRegistry`; it never
Expand Down
13 changes: 13 additions & 0 deletions docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ Host 承担记账;必要的权限、预算、不确定性与恢复决策仍在
可选 provider 发行物继续遵守 `packages/<package-id>/` 惯例;capability 包这一行不要求每个 provider
都创建一个 capability。

[本地 Workspace wheel](../../../packages/loopx-workspace/README.md) 为同版本的
`loopx-core` 加装 Chat、Dashboard 和已有的端点管理命令。它附带经过验证的浏览器资源,
并打开 Core 原先使用的 registry 和运行时状态。服务由用户显式启动。Core 帮助和任务执行
不会加载 Workspace,工作区在收到研究分析请求时才加载评估执行器。打包验收覆盖 File
和 SQLite 上由 Core 完成并独立验收的任务、安装和重启 Workspace 后的读回,以及卸载后
从 Core 重放原结果。原生 App、IM 和公开拆包发布仍需各自完成 R2/M3 验收。

管家的原生会话、监控和报告适配器,以及托管会话的日历,使用 Workspace 的原会话存储,
随 Workspace 发行,复用 Core 的命令解析和执行入口。独立 Core 在 Turn 开始时通过共用收件箱
发现待处理的请求和结果。
普通 Agent 通过同一实现提交、接受协作请求并回传结果。回传到 Workspace 原会话时才使用
对应的会话存储。加装或卸载 Workspace 时,收件箱读取入口及回执继续沿用原有作用域和身份。

权威不移动:内核仍是 Goal/Todo/claim/lease/quota/effect 状态的唯一写者。capability 包只能通过 `CapabilityRegistry` 注册 provider、capability 契约和 CLI 子命令,绝不 import 内核私有模块。

### 治理与运行时所有权
Expand Down
93 changes: 2 additions & 91 deletions loopx/capabilities/manager_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from pathlib import Path
import re

from ...command_invocation import loopx_cli_argv
from ...file_lock import exclusive_file_lock
from ...install_contract import render_host_cli_command
from ...control_plane.collaboration import conversation_scope
from ...control_plane.collaboration.source_grant_observation import (
POLICY_SCHEMA as POLICY_SCHEMA,
Expand Down Expand Up @@ -41,6 +39,8 @@
pending as pending,
)

from ...control_plane.collaboration.inbox_turn_start import turn_start_hook as turn_start_hook

INSTRUCTION = (
"Read this owner-supplied context before choosing work. Assess it against the current "
"Goal, evidence, commitments and costs; honor explicit owner constraints and decide the plan. "
Expand Down Expand Up @@ -227,95 +227,6 @@ def publication_plan():
}


def turn_start_hook(
runtime_root: Path, registry_path: Path, goal_id: str, agent_id: str, *, model_read: bool = False
):
from ...control_plane.capability_hooks import (
TurnStartHookRegistration,
TURN_START_HOOK_RESULT_SCHEMA_VERSION,
)

snapshot = None

def produce():
nonlocal snapshot
try:
from ...control_plane.collaboration.inbox import read_inbox_transaction
from ...control_plane.collaboration.inbox import _pending_result

with collaboration_goal_scope(
registry_path, goal_id=goal_id, agents=(agent_id,),
) as goal_scope:
observed = read_inbox_transaction(runtime_root, {
"operation": "turn_start", "goal_id": goal_id, "agent_id": agent_id,
"read_command": command,
}, scope=goal_scope)
observed.update(goal_id=goal_id, agent_id=agent_id)
inbox = _pending_result(runtime_root, observed, goal_scope, None)
snapshot = observed["context"]
agenda = snapshot["unfinished_delegations"]
count = (
max(len(inbox["items"]), agenda["incoming_count"])
+ max(len(inbox.get("peer_returns", {}).get("items", [])), agenda["outgoing_count"])
+ len(inbox.get("native_child_results", {}).get("items", []))
+ int(inbox.get("native_child_results", {}).get("unavailable_count", 0))
+ int(inbox.get("native_child_results", {}).get("scan_complete") is False)
+ len(inbox.get("operation_handoffs", []))
)
incomplete = not agenda["scan_complete"]
count += int(incomplete)
status, error = ("observed" if count else "empty"), None
except (OSError, ValueError):
count, status, error = 0, "unavailable", "manager_context_unreadable"
return {
"schema_version": TURN_START_HOOK_RESULT_SCHEMA_VERSION,
"hook_id": "manager.context_inbox",
"capability_id": "manager-context",
"phase": "turn_start",
"status": status,
"observation_count": count,
"agent_read_required": count > 0,
"external_reads_performed": False,
"external_writes_performed": False,
"local_private_state_mutated": False,
"private_content_returned": False,
"provider_payload_returned": False,
"error_code": error,
}

command = render_host_cli_command(
[
*loopx_cli_argv(),
"--registry",
str(registry_path),
"--runtime-root",
str(runtime_root),
"manager-inbox",
"read",
"--attention-only",
*(["--format", "markdown"] if model_read else []),
"--goal-id",
goal_id,
"--agent-id",
agent_id,
]
)
return TurnStartHookRegistration(
hook_id="manager.context_inbox",
capability_id="manager-context",
requested_read_scope=("owner_private_context_inbox",),
requested_write_scope=(),
producer=produce,
context_reader=lambda: snapshot,
required_read={
"kind": "operator_inbox",
"command": command,
"reason": "Review owner context and decide whether the current plan should change; no priority is imposed.",
"ordering": "before_work",
},
)


def evidence_scope_readback(runtime_root: Path, channel: str, *, registry_path: Path | None = None) -> dict:
"""Observe this audience's typed read grant, separately from delivery.

Expand Down
6 changes: 4 additions & 2 deletions loopx/capabilities/manager_context/roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
from ...control_plane.content_digest import BARE_SHA256_PATTERN
from ...control_plane.collaboration.source_chat_observation import original_delivery_facts
from ..native_chat.file_discovery import file_change_fingerprint
from ...chat import ChatMessagePayloadConflictError
from ...chat_store import TERMINAL_TURN_STATES

class ReturnResolutionBlocked(ValueError, RuntimeError):
"""A return cannot be resolved; ``reason`` is the provider-neutral code.
Expand Down Expand Up @@ -477,6 +475,8 @@ def project_chat_session_snapshot(root, store, session_id, *, registry,
snapshot["report_message_id"] = report_message_id
snapshot["active_turn"] = None
elif turn is not None:
from ...chat_store import TERMINAL_TURN_STATES

status = turn["status"]
snapshot["selected_turn"] = {"turn_id": turn_id, "status": status, "terminal": status in TERMINAL_TURN_STATES}
error = turn.get("error")
Expand Down Expand Up @@ -758,6 +758,8 @@ def __call__(self, attempt):


def _deliver_return(host, path, sender, frozen_route):
from ...chat import ChatMessagePayloadConflictError

store, cancelled = host["store"], host["cancelled"]
with _return_source(host, path, frozen_route) as facts:
plan = _return_transaction(host, path, "prepare", {"facts": facts})
Expand Down
11 changes: 6 additions & 5 deletions loopx/capabilities/native_chat/steward_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ def native_command(controller: Any, argv: list[str]) -> dict[str, Any]:
{"ok": False, "error_code": error_code, "error": str(exc)}
) from exc

from ...cli import build_parser
if not argv or argv[0] not in {"quota", "todo", "task-lease"}:
raise ValueError("unsupported native steward operation")

from ...cli_runtime import _build_selected_parser
from ...cli_rollout import append_cli_rollout_event
from ...cli_commands.quota import handle_quota_command
from ...cli_commands.todo import handle_todo_command
from ...cli_commands.task_lease import handle_task_lease_command

args = build_parser().parse_args(["--format", "json", *argv])
args = _build_selected_parser(argv[0]).parse_args(["--format", "json", *argv])
code: int | None
result: dict[str, Any] = {}
kwargs: dict[str, Any] = {"registry_path": controller.registry_path,
Expand All @@ -116,10 +119,8 @@ def native_command(controller: Any, argv: list[str]) -> dict[str, Any]:
elif args.command == "quota":
code = handle_quota_command(args, **kwargs,
append_cli_rollout_event=append_cli_rollout_event)
elif args.command == "task-lease":
code = handle_task_lease_command(args, **kwargs, output_format=lambda *_a, **_kw: "json")
else:
raise ValueError("unsupported native steward operation")
code = handle_task_lease_command(args, **kwargs, output_format=lambda *_a, **_kw: "json")
if code or result.get("ok") is not True:
raise NativeStewardCommandError(result)
return result
Expand Down
4 changes: 2 additions & 2 deletions loopx/capabilities/native_chat/steward_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def _commit_poll(

def _native_poll(self, argv: Sequence[str]) -> dict[str, object]:
"""Use the native poll owner; a Chat observation is no heartbeat task."""
from ...cli import build_parser
from ...cli_runtime import _build_selected_parser
from ...cli_commands.lark_inbox import (
build_lark_operator_inbox_urgency_projector,
)
Expand All @@ -285,7 +285,7 @@ def _native_poll(self, argv: Sequence[str]) -> dict[str, object]:
from ...quota import record_quota_monitor_poll
from ..explore.composition_frontier import project_live_explore_composition_frontier

args = build_parser().parse_args(["--format", "json", *argv])
args = _build_selected_parser("quota").parse_args(["--format", "json", *argv])
admission = prepare_quota_command_context(
args,
registry_path=self.controller.registry_path,
Expand Down
16 changes: 8 additions & 8 deletions loopx/capabilities/native_chat/steward_turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def _settle_stopped_report_candidate(
stopped_proof: dict[str, Any],
raw_candidate: dict[str, Any],
) -> dict[str, Any]:
from ...cli import build_parser
from ...cli_runtime import _build_selected_parser
from ...cli_commands.turn import handle_turn_command
from ...control_plane.turn_driver import inspect_loopx_turn_journal
from ..periodic_report.private_generation import validate_private_generation
Expand All @@ -957,7 +957,7 @@ def _settle_stopped_report_candidate(
"--turn-instance-id", saved_instance_id, "--todo-id", todo["todo_id"], "--execute"]
if request.get("validation_command") is not None:
argv += ["--validation-command-json", json.dumps(request["validation_command"])]
args = build_parser().parse_args(argv)
args = _build_selected_parser("turn").parse_args(argv)
args.host, args.session_scope = "codex-app-server", "agent"
result: dict[str, Any] = {}
host_runner = self._build_replay_runner(_normalize_report_kernel_candidate(raw_candidate))
Expand All @@ -982,7 +982,7 @@ def recover_report_settlement(self, actor: dict[str, Any], window: dict[str, Any
journal owner must authorize a no-host continuation; its existing
effect readbacks reconcile ambiguous writeback/debit outcomes.
"""
from ...cli import build_parser
from ...cli_runtime import _build_selected_parser
from ...cli_commands.turn import handle_turn_command
from ...control_plane.turn_driver import inspect_loopx_turn_journal
from ...control_plane.turn_driver.journal_store import find_loopx_turn_key_by_settlement_identity
Expand Down Expand Up @@ -1049,7 +1049,7 @@ def no_model(*_args):
if contract_recovery is not None
else no_model
)
args = build_parser().parse_args(["turn", "run-once", "--goal-id", actor["goal_id"],
args = _build_selected_parser("turn").parse_args(["turn", "run-once", "--goal-id", actor["goal_id"],
"--agent-id", actor["agent_id"], "--project", admitted["workspace_path"],
"--host", "generic-cli", "--resume-turn-key", key, "--retry-failed-turn", "--execute"])
args.host, args.session_scope = "codex-app-server", "agent"
Expand Down Expand Up @@ -1318,7 +1318,7 @@ def _steward_followup_context(self, actor: Mapping[str, Any], session_id: str,

def _governance_replan_context(self, actor: Mapping[str, Any], authority: Mapping[str, Any]) -> dict[str, Any]:
"""Project public-safe review/writeback/vision context for text-only Steward replanning."""
from ...cli import build_parser
from ...cli_runtime import _build_selected_parser
from ...cli_commands.quota_native_context import read_replan_view
from ...control_plane.goals.goal_frontier import latest_agent_vision_from_status_payload
from ...control_plane.todos.list_readback import list_goal_todos
Expand All @@ -1340,7 +1340,7 @@ def _read_stage(cmd_str: Any) -> dict[str, Any] | None:
try:
tokens = shlex.split(cmd_str)
q_idx = tokens.index("quota")
parsed = build_parser().parse_args(tokens[q_idx:])
parsed = _build_selected_parser("quota").parse_args(tokens[q_idx:])
view = read_replan_view(parsed)
if isinstance(view, Mapping) and view.get("ok") is True:
return dict(view)
Expand Down Expand Up @@ -1502,7 +1502,7 @@ def _apply_steward_user_actions(self, actor: Mapping[str, Any], actions: Sequenc
def execute(self, *, session_id: str, turn_id: str, adapter: Any,
event_sink: Any, context: dict[str, Any]) -> dict[str, Any]:
"""Run in the original Chat worker, through all native settlement owners."""
from ...cli import build_parser
from ...cli_runtime import _build_selected_parser
from ...cli_commands.turn import handle_turn_command
from ...control_plane.turn_driver.host_candidate import extract_turn_authority, render_prompt, parse_model_json, build_result
from .antigravity_adapter import AntigravityAdapter
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def launch():
argv += ["--todo-id", request["todo_id"]]
if request["validation_command"] is not None:
argv += ["--validation-command-json", json.dumps(request["validation_command"])]
args = build_parser().parse_args(argv)
args = _build_selected_parser("turn").parse_args(argv)
# This connection is host-owned, not a command path supplied by a model.
# The kernel records the actual app-server host and independent profile.
args.host, args.session_scope = "codex-app-server", "agent"
Expand Down
2 changes: 1 addition & 1 deletion loopx/chat/action_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, Mapping

from ..agent_registry import registered_agent_ids_for_goal
from ..capabilities.issue_fix.repository_snapshot import _REPO_PATTERN
from ..capabilities.issue_fix.github_public import _REPO_PATTERN
from ..control_plane.content_digest import BARE_SHA256_PATTERN
from ..control_plane.runtime.time import now_utc, parse_timestamp, utc_isoformat
from ..control_plane.todos.contract import require_supported_todo_resume_when
Expand Down
2 changes: 1 addition & 1 deletion loopx/chat/todo_action_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import NoReturn, Protocol, runtime_checkable

from ..chat_store import TERMINAL_TURN_STATES
from .action_store_common import is_str_dict, require_str_dict
from ..control_plane.collaboration.action_store_common import is_str_dict, require_str_dict

CANONICAL_UPDATE_BASIS_SCHEMA_VERSION = "loopx_chat_canonical_update_basis_v0"
CANONICAL_TERMINAL_BASIS_SCHEMA_VERSION = "loopx_chat_canonical_terminal_basis_v0"
Expand Down
2 changes: 1 addition & 1 deletion loopx/chat/todo_action_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
read_canonical_todos_if_promoted,
)
from ..control_plane.todos.mutation_api import update_goal_todo
from .action_store_common import _opaque_id, is_str_dict, require_str_dict
from ..control_plane.collaboration.action_store_common import _opaque_id, is_str_dict, require_str_dict
from .todo_action_contracts import (
ChatTodoActionHost,
as_optional_str,
Expand Down
2 changes: 1 addition & 1 deletion loopx/chat/todo_action_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..control_plane.todos.mutation_api import update_goal_todo
from ..control_plane.work_items.task_lease import lease_is_active
from ..file_lock import exclusive_cross_runtime_file_lock
from .action_store_common import _opaque_id, is_str_dict, require_str_dict
from ..control_plane.collaboration.action_store_common import _opaque_id, is_str_dict, require_str_dict
from .todo_action_contracts import (
ChatTodoActionHost,
GoalCommitSubmitController,
Expand Down
Loading
Loading