This commit was merged in pull request #846.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Trusted latest-assistant-message observer boundary for receipt promotion.
|
||||
|
||||
Runtime adapters must implement ``observe_latest_assistant_message`` directly:
|
||||
Claude selects the exact latest assistant entry and Pi selects ``message_end``.
|
||||
The broker accepts no observed message through its request protocol.
|
||||
Production adapters deliver finalized assistant content over the daemon-owned
|
||||
observer socket after the daemon authenticates their peer against the broker's
|
||||
kernel-anchored session identity. The broker request protocol never accepts
|
||||
assistant-message content. Claude supplies its latest assistant entry; Pi
|
||||
supplies finalized assistant content at ``message_end``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -26,7 +28,7 @@ class ReceiptObserver(Protocol):
|
||||
|
||||
|
||||
class UnavailableReceiptObserver:
|
||||
"""Production-safe default until a runtime adapter injects an observer."""
|
||||
"""Fail-closed only for direct unit construction without daemon transport."""
|
||||
|
||||
def observe_latest_assistant_message(
|
||||
self,
|
||||
@@ -38,6 +40,31 @@ class UnavailableReceiptObserver:
|
||||
return None
|
||||
|
||||
|
||||
class RuntimeReceiptObserver:
|
||||
"""Daemon-owned production observer populated only by authenticated adapters."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._messages: dict[tuple[str, str, int], str] = {}
|
||||
|
||||
def record_latest_assistant_message(
|
||||
self,
|
||||
session_id: str,
|
||||
runtime: str,
|
||||
runtime_generation: int,
|
||||
message: str,
|
||||
) -> None:
|
||||
self._messages[(session_id, runtime, runtime_generation)] = message
|
||||
|
||||
def observe_latest_assistant_message(
|
||||
self,
|
||||
session_id: str,
|
||||
runtime: str,
|
||||
runtime_generation: int,
|
||||
_binding: dict[str, object],
|
||||
) -> str | None:
|
||||
return self._messages.get((session_id, runtime, runtime_generation))
|
||||
|
||||
|
||||
class TestReceiptObserver:
|
||||
"""Deterministic controlled observer used only by byte-build tests."""
|
||||
|
||||
@@ -60,7 +87,7 @@ class TestReceiptObserver:
|
||||
|
||||
|
||||
class FileTestReceiptObserver:
|
||||
"""Private fixture-file observer for isolated out-of-process test drivers."""
|
||||
"""Private fixture-file observer for isolated out-of-process test drivers only."""
|
||||
|
||||
def __init__(self, path: Path) -> None:
|
||||
self.path = path
|
||||
|
||||
Reference in New Issue
Block a user