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
17 changes: 9 additions & 8 deletions src/agent_comms/acp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,22 @@ def input_identity(self, acquire_scope: Callable[[], LiveAttachmentScope]) -> Cl
return acquire_scope().claimed_identity


class SessionScopedUpdate(AgentCommsUpdate, declared_name=None):
"""An agent-comms update scoped to a session."""

def for_session(self, session_id: AcpSessionId) -> Self:
return replace(self, scope=self.scope.for_session(session_id))


@dataclass(frozen=True)
class QueueChangedUpdate(AgentCommsUpdate):
class QueueChangedUpdate(SessionScopedUpdate):
scope: QueueScope
revision: int
projection: QueueProjection

def __post_init__(self):
self.scope.validate_scope(self.projection)

def for_session(self, session_id: AcpSessionId) -> QueueChangedUpdate:
return replace(self, scope=self.scope.for_session(session_id))

@property
def status(self) -> str | None:
return self.projection.status
Expand All @@ -382,7 +386,7 @@ def digest(self) -> str:


@dataclass(frozen=True)
class InputStartedUpdate(AgentCommsUpdate, declared_name=None):
class InputStartedUpdate(SessionScopedUpdate, declared_name=None):
text: str | None
scope: QueueScope
revision: int | None
Expand All @@ -404,9 +408,6 @@ def started_request(self, input_id: InputId) -> bool:
def when_unidentified(self, action: Callable[[], None]) -> None:
pass

def for_session(self, session_id: AcpSessionId) -> InputStartedUpdate:
return replace(self, scope=self.scope.for_session(session_id))


@dataclass(frozen=True)
class IdentifiedInputStarted(InputStartedUpdate):
Expand Down
7 changes: 2 additions & 5 deletions src/agent_comms/cli_bridges/harness_delivery_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from agent_comms.execution.turn_item import NativeItemId, NativeTurnId
from agent_comms.messaging.message_reference import MessageReference
from agent_comms.messaging.notification_progress import (
ConsumptionEvidence,
ConsumingProgress,
DeliveryProgress,
HarnessConsumedProgress,
PassthroughConsumptionEvidence,
)
from agent_comms.nominal.declared_family import DeclaredFamily
from agent_comms.nominal.field_codec import TranscriptRecordId
Expand All @@ -40,7 +40,7 @@


@dataclass(frozen=True)
class MonitorEvidence(ConsumptionEvidence, DeclaredFamily):
class MonitorEvidence(PassthroughConsumptionEvidence, DeclaredFamily):
"""Unsent and terminal observations cannot accept another delivery."""

async def confirm(self, bridge: TranscriptConfirmsDelivery, delivery: HarnessDelivery,
Expand All @@ -52,9 +52,6 @@ def evidence(self, recorded: type[Outcome]) -> tuple[type[Outcome], MonitorEvide
proves nothing leaves the recorded outcome."""
return recorded, self

def consumed_progress(self, progress: DeliveryProgress) -> DeliveryProgress:
return progress

def claim_handoff(self, state: AssignmentState) -> tuple[type[AssignmentState], ...]:
return state.harness_handoff()

Expand Down
9 changes: 8 additions & 1 deletion src/agent_comms/cli_verbs/cli_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pydantic import JsonValue

from agent_comms.nominal.field_codec import SubclassUnion
from agent_comms.nominal.field_codec import FieldCodec, PresenceExclude, SubclassUnion
from agent_comms.transport.tool_result import DeclaredReply, ToolResult


Expand Down Expand Up @@ -47,6 +47,13 @@ def write(self, output: TextIO) -> int:
return self.exit_code()


class PresenceExcludedReply(CliResult):
"""A declared reply whose wire projection excludes presence-only fields."""

def to_wire(self) -> object:
return FieldCodec.project(self, PresenceExclude)


@dataclass(frozen=True)
class RegisteredResult(CliResult):
registered: str
Expand Down
29 changes: 19 additions & 10 deletions src/agent_comms/coordination/assignment_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,19 @@ def notification(
)


class TriagePendingAssignment(PreengagementTarget, PendingNotification, AssignmentState):
class BoundedTriageAssignment(AssignmentState, declared_name=None):
"""An assignment state whose wake mode is BoundedTriageWake."""

@property
def mode(self):
return BoundedTriageWake()


class TriagePendingAssignment(
PreengagementTarget,
PendingNotification,
BoundedTriageAssignment,
):
def wake_frame(self, source: Delivered, obligation: ResponseObligation | None) -> tuple[str, str]:
if obligation is not None:
raise IdentityConflict("bounded triage cannot inherit a response obligation")
Expand All @@ -354,10 +366,6 @@ def requires_selected_triage(self) -> bool:
def harness_ignore(self) -> tuple[type[AssignmentState], ...]:
return (IgnoredAssignment,)

@property
def mode(self):
return BoundedTriageWake()

@classmethod
def successors(cls):
return IgnoredAssignment, EngagedAssignment, DeferredAssignment, FailedAssignment
Expand All @@ -376,13 +384,14 @@ def successors(cls):
return EngagedAssignment, DeferredAssignment, FailedAssignment


class IgnoredAssignment(ChangedNotification, PreengagementTarget, Terminal, AssignmentState):
class IgnoredAssignment(
ChangedNotification,
PreengagementTarget,
Terminal,
BoundedTriageAssignment,
):
notification_state = IgnoredProgress

@property
def mode(self):
return BoundedTriageWake()

@property
def verdict(self):
return "ignore"
Expand Down
17 changes: 9 additions & 8 deletions src/agent_comms/coordination/attempt_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ def successors(cls):
)


class AbortingAttempt(LiveAttempt):
class RetryableFailureAttempt(LiveAttempt, declared_name=None):
"""An attempt state that transitions to either retry or unsuccessful terminal."""

@classmethod
def successors(cls):
return (
Expand All @@ -290,6 +292,10 @@ def successors(cls):
)


class AbortingAttempt(RetryableFailureAttempt):
pass


class RetryingAttempt(LiveAttempt):
@classmethod
def successors(cls):
Expand All @@ -302,13 +308,8 @@ def successors(cls):
)


class ProviderUnavailableAttempt(LiveAttempt):
@classmethod
def successors(cls):
return (
UnsuccessfulTerminal,
RetryingAttempt,
)
class ProviderUnavailableAttempt(RetryableFailureAttempt):
pass


class SucceededAttempt(TerminalAttempt):
Expand Down
7 changes: 2 additions & 5 deletions src/agent_comms/execution/cli_inbox_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
RuntimeLocation,
)
from agent_comms.execution.launch_runtime import LaunchRuntime
from agent_comms.execution.unstarted_runtime import ExternalTranscriptLocation
from agent_comms.execution.unstarted_runtime import UnwrittenRuntimeLocation
from agent_comms.nominal.field_codec import AcpSessionId


@dataclass(frozen=True)
class CliInboxRuntime(ExternalTranscriptLocation):
class CliInboxRuntime(UnwrittenRuntimeLocation):
"""Runtime location for a CLI-inbox thread.

``path`` is empty for a pure CLI inbox, or holds a preserved native Pi session
Expand All @@ -46,9 +46,6 @@ def is_resumable(self) -> bool:
def require_forkable(self) -> None:
pass

def last_written(self) -> float:
return 0.0

async def compact(self, operation):
return FailedCompaction("A CLI-inbox thread compacts in its own CLI session.")

Expand Down
14 changes: 7 additions & 7 deletions src/agent_comms/execution/native_input_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
ImmutableRows,
Index,
IntegerStorage,
ReconciledFile,
TableSchema,
SelfSchemaReconciledFile,
TypedTable,
WithoutRowid,
)
Expand Down Expand Up @@ -223,16 +222,17 @@ def corroborate(
return self.at(session_file, session_entry_start=location.session_entry_start)


class NativeInputProof(DurableFile, ReconciledFile, PatternFile, DurableTables):
class NativeInputProof(
DurableFile,
SelfSchemaReconciledFile,
PatternFile,
DurableTables,
):
"""The retained proof file names its journal without joining their two families."""

__slots__ = ()
filename = "input-proofs/{lookup}/{name}.sqlite"

@classmethod
def table_schema(cls) -> type[TableSchema]:
return cls

@classmethod
def schema_rows(cls) -> tuple[type[TypedTable], ...]:
return (NativeContextJournal,)
Expand Down
8 changes: 2 additions & 6 deletions src/agent_comms/execution/native_input_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from agent_comms.storage.typed_table import (
LOCAL_TABLE_SOURCE,
SqlStorage,
ExplicitSqlStorage,
TableSource,
TextStorage,
sql_literal,
Expand Down Expand Up @@ -80,15 +80,11 @@ def offset(self) -> int:
return self.value


class NativeStageStorage(SqlStorage):
class NativeStageStorage(ExplicitSqlStorage):
"""A nullable stage column keeps the execution family's generated name CHECK."""

sql_type = "TEXT"

@classmethod
def accepts(cls, annotation: object) -> bool:
return False # Declared on the column; a NativeColumn names no family itself.

@classmethod
def constraints(cls, column: str, annotation: object = None) -> tuple[str, ...]:
return (NativeInputExecution.sql_constraint(column),)
Expand Down
38 changes: 23 additions & 15 deletions src/agent_comms/execution/transcript_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@
from agent_comms.transport.tool_declaration import ToolDeclaration


class WireFrontier(DeclaredFamily, ResolvesSentReports, affix="WireFrontier"):
class UnassignedSentReportResolver(ResolvesSentReports):
"""A sent-report resolver for sources without sender assignment qualification."""

def resolve_sent(
self, messages: tuple[SentTranscript, ...],
) -> tuple[SentTranscript | PublishedSentMessage, ...]:
return tuple(messages)


class WireFrontier(DeclaredFamily, UnassignedSentReportResolver, affix="WireFrontier"):
"""The wire coordinate owns cursor construction, bounds and source authority."""

sequence: int
Expand All @@ -122,11 +131,6 @@ def require_source(self, identity: AssignedSourceIdentity) -> None:
def require_native(self) -> None:
"""An unassigned position carries only the native coordinate."""

def resolve_sent(
self, messages: tuple[SentTranscript, ...],
) -> tuple[SentTranscript | PublishedSentMessage, ...]:
return tuple(messages)


@dataclass(frozen=True)
class NoWireFrontier(WireFrontier):
Expand Down Expand Up @@ -398,7 +402,11 @@ class CapturedTranscriptAppend:
events: tuple[TranscriptEvent, ...]


class TranscriptSource(TranscriptHistorySource, ReadsPublishedMessages, ResolvesSentReports):
class TranscriptSource(
TranscriptHistorySource,
ReadsPublishedMessages,
UnassignedSentReportResolver,
):
"""Recorded items alone carry no assigned-wire or publication authority.

Native and external stores supply their original records. An assigned
Expand Down Expand Up @@ -516,10 +524,6 @@ def project(records, *, max_records: int, max_bytes: int):
def sent_messages(self, references: Iterable[MessageReference]) -> dict[MessageReference, Message]:
return {}

def resolve_sent(self, messages: tuple[SentTranscript, ...]):
"""Records without a sender assignment cannot qualify Send reports."""
return tuple(messages)

frontier = NoWireFrontier()

def window(self, *, limit: int = 1, sent_limit: int = 0) -> AssignedSourceWindow:
Expand Down Expand Up @@ -656,8 +660,15 @@ def with_prefix(self, prefix: TranscriptCursor) -> TranscriptCursor:
return self.at_offset(prefix.offset)


class NoOpReadTranscriptCursor(TranscriptCursor, declared_name=None):
"""A transcript cursor with no displayed messages to mark read."""

def mark_read(self, reads: MarksSourceRead[RecordsCut], viewer: str, runtime: TranscriptRuntime) -> None:
...


@dataclass(frozen=True, slots=True)
class UnreadTranscriptCursor(TranscriptCursor):
class UnreadTranscriptCursor(NoOpReadTranscriptCursor, TranscriptCursor):
"""No source has been read; this is not a source position or a read mark."""

def contains(self, other: TranscriptCursor) -> bool:
Expand Down Expand Up @@ -697,9 +708,6 @@ def at_offset(self, offset: int) -> TranscriptCursor:
def with_frontier(self, frontier: WireFrontier) -> TranscriptCursor:
return self

def mark_read(self, reads: MarksSourceRead[RecordsCut], viewer: str, runtime: TranscriptRuntime) -> None:
"""Nothing has been drawn, so there is nothing to acknowledge."""


class FileTranscriptCursor(TranscriptCursor, declared_name=None):
"""A position in a file's bytes: a session rewritten through os.replace is another file,
Expand Down
13 changes: 8 additions & 5 deletions src/agent_comms/execution/unstarted_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ def history_source(self, root, incarnation):
return ExternalTranscript(root, incarnation)


class UnwrittenRuntimeLocation(ExternalTranscriptLocation, declared_name=None):
"""A runtime location with no recorded transcript write timestamp."""

def last_written(self) -> float:
return 0.0


@dataclass(frozen=True)
class UnstartedRuntime(ExternalTranscriptLocation):
class UnstartedRuntime(UnwrittenRuntimeLocation):
owner: type[AgentBackend]
def is_resumable(self) -> bool:
return False
Expand All @@ -73,10 +80,6 @@ def path(self) -> str:
def require_forkable(self):
raise ValueError("Canonical saved session required")

def last_written(self) -> float:
"""No saved session exists to have grown."""
return 0.0

async def compact(self, operation):
return FailedCompaction("This thread has no saved session to compact.")

Expand Down
Loading
Loading