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
15 changes: 15 additions & 0 deletions docs/architecture/rfcs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ Paired diffs do not certify translation accuracy.
governed commit policy/verifier, lease-impact handling and Stage 3+
qualification remain unshipped. Manager handoff consumes these boundaries;
it does not provide another amendment writer.
- [Goal-Oriented Multi-Agent Peer Coordination v0](goal-oriented-multi-agent-coordination-v0.md)
([中文版](goal-oriented-multi-agent-coordination-v0.zh-CN.md))
- **Delivery on `main`:** M0 read-only peer frontier and collaboration
opportunity projection (`peer_coordination.ts`) and M1 conditional
default-on `<=300 B` Turn-envelope digest (`peer_coordination_digest.ts`)
implemented; M2–M3 remain unshipped.
- **Current boundary:** Projects bounded `peer_frontiers` and deterministic
`collaboration_opportunities` (`shared_target_collision_risk`,
`peer_verification_needed`, `peer_unleased_lane_attention`,
`shared_domain_synergy`, all with `grants_authority: false`) onto
`shared_goal_alignment_v0`, and automatically injects cursor-deduplicated
`peer_coordination_digest` (`<=300 B` including field key; omitted at `0 B`
when single-agent, unchanged, or opted out) into `TurnEnvelope` on
`loopx quota should-run`. Cooldown-gated bilateral `manager-inbox`
handshakes (M2) and host-neutral live route observers (M3) remain open.
- [Goal contract evolution and bounded working context v0](goal-contract-evolution-v0.md)
([中文版](goal-contract-evolution-v0.zh-CN.md))
- **Delivery on `main`:** Proposal only; existing objective revision and additive
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/rfcs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ appendix may keep dated history, but no dated log heading may precede it.

[中文版](STATUS.zh-CN.md) is the semantic mirror of this file.

## Accepted (54)
## Accepted (55)

| RFC | Header status | Supersedes / closes | Ledger |
| --- | --- | --- | --- |
Expand All @@ -42,6 +42,7 @@ appendix may keep dated history, but no dated log heading may precede it.
| [RFC: Goal Direction Baseline (v0)](goal-direction-baseline-v0.md) | Accepted | none | — |
| [Design follow-up: Goal continuity across restart and replacement](goal-immutability-coherence-defense-v0.md) | Accepted | none | — |
| [Goal Instance Identity and Orphan Recovery (v0)](goal-instance-identity-and-orphan-recovery-v0.md) | Accepted | none | — |
| [RFC: Goal-Oriented Multi-Agent Peer Coordination (v0)](goal-oriented-multi-agent-coordination-v0.md) | Accepted | none | — |
| [RFC: Persistent Goal outcome refinement (v0)](goal-outcome-refinement-v0.md) | Accepted | none | — |
| [RFC: Goal-scoped Capability Portfolio and Connector Lifecycle (v0)](goal-scoped-capability-portfolio-v0.md) | Accepted | none | — |
| [RFC: Per-Goal Usage, Token, and Cost Surfacing v0](goal-usage-token-cost-v0.md) | Accepted | none | — |
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/rfcs/STATUS.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

[English](STATUS.md) 与本文互为语义镜像。

## 已接受 (54)
## 已接受 (55)

| RFC | 头部状态 | 替代 / 关闭 | Ledger |
| --- | --- | --- | --- |
Expand All @@ -39,6 +39,7 @@
| [RFC:Goal Direction Baseline(目标方向基线)v0](goal-direction-baseline-v0.zh-CN.md) | 已接受 | 无 | — |
| [后续设计:重启与实例替换中的 Goal 连续性](goal-immutability-coherence-defense-v0.zh-CN.md) | 已接受 | none | — |
| [Goal 实例身份与孤儿状态恢复(v0)](goal-instance-identity-and-orphan-recovery-v0.zh-CN.md) | 已接受 | 无 | — |
| [RFC:面向目标的多 Agent 自主协同协议(v0)](goal-oriented-multi-agent-coordination-v0.zh-CN.md) | 已接受 | 无 | — |
| [RFC:持久化 Goal 成果细化(v0)](goal-outcome-refinement-v0.zh-CN.md) | 已接受 | 无 | — |
| [RFC:Goal 级能力组合与 Connector 生命周期(v0)](goal-scoped-capability-portfolio-v0.zh-CN.md) | 已接受 | 无 | — |
| [RFC: Per-Goal Usage, Token, and Cost Surfacing v0](goal-usage-token-cost-v0.md) | 已接受 | none | — |
Expand Down
178 changes: 178 additions & 0 deletions docs/architecture/rfcs/goal-oriented-multi-agent-coordination-v0.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions loopx/cli_commands/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,40 @@ def _prepare_quota_result_context(
)


def _turn_peer_digest_delivery_callback(
payload: Mapping[str, object],
args: argparse.Namespace,
*,
preview: bool,
preflight_failed: bool,
closeout_unavailable: bool,
context: QuotaCommandContext | None,
registry_path: Path,
heartbeat_turn_id: str | None,
) -> Callable[[Mapping[str, object]], None]:
"""Create post-delivery cursor commit callback bound to the emitted channel view."""
from ..control_plane.goals.peer_coordination_digest_source import (
maybe_commit_turn_peer_coordination_cursor,
)

turn_id = heartbeat_turn_id or getattr(args, "turn_instance_id", None)
return lambda delivered: maybe_commit_turn_peer_coordination_cursor(
payload,
quota_command=args.quota_command,
preview=preview,
scheduler_observation=bool(getattr(args, "scheduler_observation", False)),
preflight_failed=preflight_failed,
closeout_unavailable=closeout_unavailable,
status_payload=context.status_payload if context is not None else None,
registry_path=registry_path,
runtime_root=context.runtime_root if context is not None else None,
goal_id=args.goal_id,
agent_id=args.agent_id,
delivered_payload=delivered,
turn_instance_id=turn_id,
)


def _emit_quota_result(
payload: dict[str, object],
args: argparse.Namespace,
Expand All @@ -286,6 +320,7 @@ def _emit_quota_result(
capture_directory: Path | None,
detail_sections: frozenset[str],
print_payload: PrintPayload,
on_delivered: Callable[[Mapping[str, object]], None] | None = None,
) -> int:
from .quota_result_delivery import emit_quota_result

Expand All @@ -300,6 +335,7 @@ def _emit_quota_result(
capture_directory=capture_directory,
detail_sections=detail_sections,
print_payload=print_payload,
on_delivered=on_delivered,
)


Expand Down Expand Up @@ -738,4 +774,14 @@ def _execute_quota_command(
capture_directory=capture_directory,
detail_sections=detail_sections,
print_payload=print_payload,
on_delivered=_turn_peer_digest_delivery_callback(
payload,
args,
preview=preview,
preflight_failed=action_selection_preflight_failed,
closeout_unavailable=closeout_query_unavailable,
context=context,
registry_path=registry_path,
heartbeat_turn_id=heartbeat_turn_id,
),
)
54 changes: 47 additions & 7 deletions loopx/cli_commands/quota_context_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def _validate_pinned_selection(selection: dict[str, Any]) -> None:
def read_context_capture(args: argparse.Namespace, *, presentation: dict[str, Any] | None = None,
next_page_bytes: int | None = None,
next_page_output_bytes: int | None = None,
reader_argv: list[str] | None = None) -> dict[str, Any]:
reader_argv: list[str] | None = None,
delivery_proof: dict[str, Any] | None = None) -> dict[str, Any]:
"""Bounded local IO over immutable JSON.

Verify the complete byte digest on every page. The cursor addresses bytes
Expand Down Expand Up @@ -453,12 +454,29 @@ def read_context_capture(args: argparse.Namespace, *, presentation: dict[str, An
reference_file, bound_route = None, None
if offset > len(raw) or (offset < len(raw) and raw[offset] & 0xC0 == 0x80):
raise ValueError("capture offset is outside the file or not a UTF-8 boundary; use the returned next offset")
return _capture_page(path, raw, digest, offset=offset, size=size,
page = _capture_page(path, raw, digest, offset=offset, size=size,
output_limit=output_limit, instruction=bool(context_dir),
presentation=presentation, next_page_bytes=next_page_bytes,
next_page_output_bytes=next_page_output_bytes, select=selectors, selection_sha256=selection_digest,
list_fields=list_fields, list_depth=list_depth, initial_read=initial_read, reference_file=reference_file,
reader_argv=reader_argv, compact_reader=bound_route is not None)
if delivery_proof is not None and page.get("ok") is True:
from ..control_plane.goals.peer_coordination_digest_source import (
prove_page_delivered_peer_digest,
)

delivered_digest = prove_page_delivered_peer_digest(
payload,
raw=raw,
content=str(page.get("content") or ""),
offset=int(page["offset"]),
list_fields=list_fields,
is_selection=selectors is not None or initial_read,
)
if delivered_digest is not None:
delivery_proof["delivered_digest"] = delivered_digest
delivery_proof["captured_payload"] = payload
return page
except (OSError, ValueError, RecursionError, EffectRuntimeRemoteError, EffectRuntimeStartupError) as exc:
# Recovery is presentation-only: keep failures separate from quota's
# collection error path and retain the existing receipt/capture.
Expand Down Expand Up @@ -721,7 +739,8 @@ def budgeted_ready_opening(navigation: dict[str, Any], plan: dict[str, Any],
def _bounded_initial_read(navigation: dict[str, Any], plan: dict[str, Any], *,
page_bytes: int, output_bytes: int, reader_argv: list[str] | None,
attach_page: bool = True, remaining_reference: Path | None = None,
ordinary_page: dict[str, Any] | None = None) -> dict[str, Any] | None:
ordinary_page: dict[str, Any] | None = None,
delivery_proof: dict[str, Any] | None = None) -> dict[str, Any] | None:
"""Try the typed opening and keep the remainder pinned to the same capture."""
if "opening" not in plan or "first_read_command" not in navigation:
return None
Expand Down Expand Up @@ -763,14 +782,33 @@ def command(reference: Path) -> str:
"and its next_command cursor through the remaining initial context. Both views pin the same capture. "
"EOF does not establish retention, authority or freshness.")
page["navigation"] = navigation
return page if len(_native_output_bytes(page)) <= output_bytes else None
if len(_native_output_bytes(page)) > output_bytes:
return None
if delivery_proof is not None:
from ..control_plane.goals.peer_coordination_digest_source import (
prove_page_delivered_peer_digest,
)

delivered_digest = prove_page_delivered_peer_digest(
document,
raw=content,
content=str(page.get("content") or ""),
offset=int(page["offset"]),
list_fields=False,
is_selection=True,
)
if delivered_digest is not None:
delivery_proof["delivered_digest"] = delivered_digest
delivery_proof["captured_payload"] = document
return page
except (OSError, ValueError):
return None # The same-capture ordinary reader is already available.


def _saved_context_read_page(args: argparse.Namespace, navigation: dict[str, Any], *,
initial_reference: str | None, initial_read_plan: dict[str, Any] | None,
output_limit: int | None, reader_argv: list[str]) -> dict[str, Any]:
output_limit: int | None, reader_argv: list[str],
delivery_proof: dict[str, Any] | None = None) -> dict[str, Any]:
"""Use the ordinary verified reader; the first page and navigation share its output budget."""
recovery = navigation["recovery"]
pinned = initial_reference if args.initial_read else None
Expand All @@ -780,13 +818,15 @@ def _saved_context_read_page(args: argparse.Namespace, navigation: dict[str, Any
"capture_sha256": None if reference else recovery["sha256"],
"max_page_output_bytes": output_limit,
"codex_context_dir": None, "codex_context_root": None, "initial_read": bool(args.initial_read and not pinned)})
page = read_context_capture(read_args, presentation={"navigation": navigation}, reader_argv=reader_argv)
page = read_context_capture(read_args, presentation={"navigation": navigation}, reader_argv=reader_argv,
delivery_proof=delivery_proof)
if page["ok"]:
if (pinned and initial_read_plan and output_limit is not None and not page["eof"]
and "previously_delivered_fields" not in page
and (opening := _bounded_initial_read(navigation, initial_read_plan,
page_bytes=args.page_bytes if args.page_bytes is not None else output_limit,
output_bytes=output_limit, reader_argv=reader_argv, ordinary_page=page)) is not None):
output_bytes=output_limit, reader_argv=reader_argv, ordinary_page=page,
delivery_proof=delivery_proof)) is not None):
return opening
# Keep the already-budgeted page and cursor ahead of recovery metadata.
page["navigation"] = page.pop("navigation")
Expand Down
58 changes: 54 additions & 4 deletions loopx/cli_commands/quota_native_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import stat
import subprocess
import sys
import tempfile
from collections.abc import Callable
from contextlib import AbstractContextManager, nullcontext
Expand Down Expand Up @@ -91,6 +92,7 @@ def _saved_context_transport_failure(
def project_saved_context_capture(
args: argparse.Namespace, *, hook_session: str | None = None,
registry_path: Path | None = None, runtime_root_arg: str | None = None,
delivery_proof: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""Present an immutable already-decided quota capture.

Expand Down Expand Up @@ -217,7 +219,10 @@ def authority_refusal(error: Exception) -> dict[str, Any]:
with publication_guard():
if saved_page:
return _saved_context_read_page(args, navigation, initial_reference=None,
initial_read_plan=None, output_limit=output_limit, reader_argv=reader_argv)
initial_read_plan=None, output_limit=output_limit, reader_argv=reader_argv,
delivery_proof=delivery_proof)
if delivery_proof is not None and isinstance(navigation, dict):
delivery_proof["captured_payload"] = payload
return navigation
except NativeRecoveryLeaseUnavailable as exc:
return authority_refusal(exc)
Expand Down Expand Up @@ -339,7 +344,10 @@ def authority_refusal(error: Exception) -> dict[str, Any]:
with nullcontext() if native_prepared else publication_guard():
if saved_page:
return _saved_context_read_page(args, navigation, initial_reference=initial_reference,
initial_read_plan=initial_read_plan, output_limit=output_limit, reader_argv=reader_argv)
initial_read_plan=initial_read_plan, output_limit=output_limit, reader_argv=reader_argv,
delivery_proof=delivery_proof)
if delivery_proof is not None and isinstance(navigation, dict):
delivery_proof["captured_payload"] = payload
return navigation
except NativeRecoveryLeaseUnavailable as exc:
return authority_refusal(exc)
Expand Down Expand Up @@ -613,16 +621,58 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
)
return _handle_context_hook(args, activation=activation)
if args.quota_command == "context-project":
payload = project_saved_context_capture(args, registry_path=registry_path, runtime_root_arg=runtime_root_arg)
from ..control_plane.goals.peer_coordination_digest_source import (
maybe_commit_captured_peer_coordination_cursor,
)

delivery_proof: dict[str, Any] = {}
payload = project_saved_context_capture(
args,
registry_path=registry_path,
runtime_root_arg=runtime_root_arg,
delivery_proof=delivery_proof,
)
print_payload(payload, args.format, lambda value: str(value.get("command", value.get("reason", ""))))
sys.stdout.flush()
if payload.get("ok") is True:
try:
maybe_commit_captured_peer_coordination_cursor(
args,
emitted_payload=payload,
delivery_proof=delivery_proof,
registry_path=registry_path,
runtime_root_arg=runtime_root_arg,
)
except Exception: # noqa: BLE001 - best-effort cursor commit never blocks delivered projection.
pass
return 0 if payload["ok"] else 1
if args.quota_command == "context-read":
from ..command_invocation import current_loopx_cli_argv
from ..control_plane.goals.peer_coordination_digest_source import (
maybe_commit_captured_peer_coordination_cursor,
)

# Presentation recovery reads the original capture, never current Goal
# state. In particular it must not evaluate a guard or append a receipt.
payload = quota_capture.read_context_capture(args, reader_argv=current_loopx_cli_argv())
delivery_proof = {}
payload = quota_capture.read_context_capture(
args,
reader_argv=current_loopx_cli_argv(),
delivery_proof=delivery_proof,
)
print_payload(payload, args.format, lambda value: str(value.get("content", value.get("reason", ""))))
sys.stdout.flush()
if payload.get("ok") is True:
try:
maybe_commit_captured_peer_coordination_cursor(
args,
emitted_payload=payload,
delivery_proof=delivery_proof,
registry_path=registry_path,
runtime_root_arg=runtime_root_arg,
)
except Exception: # noqa: BLE001 - best-effort cursor commit never blocks delivered readback.
pass
return 0 if payload["ok"] else 1
if args.quota_command == "replan-view":
return handle_replan_view(args, print_payload)
Expand Down
Loading
Loading