diff --git a/pyproject.toml b/pyproject.toml index 08b8dbf3e9..cea0933461 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -202,3 +202,7 @@ keyword-binders = [ derived-spellings = [ { family = "agent_comms.nominal.declared_family:DeclaredFamily", rule = "agent_comms.nominal.declared_family:declared_words", affix = "affix", spelling = "declared_name" }, ] +# Stdlib-only fast-path hook: importing agent_comms at module top level runs Core on every tool call. +forbidden-imports = [ + { from = "agent_comms_hooks.antigravity", to = ["agent_comms"] }, +] diff --git a/src/agent_comms/cli_bridges/antigravity_protocol.py b/src/agent_comms/cli_bridges/antigravity_protocol.py index 4d221bb7a1..eca863b9da 100644 --- a/src/agent_comms/cli_bridges/antigravity_protocol.py +++ b/src/agent_comms/cli_bridges/antigravity_protocol.py @@ -15,8 +15,10 @@ from agent_comms.cli_bridges.cli_protocol import HistoryRecord, TaggedWire from agent_comms.cli_bridges.runtime_updates import ( ActiveItem, + CatchUpReadingPhase, FinishedItem, FinishedTurn, + LiveReadingPhase, ReadingPhase, RuntimeInfoObserved, RuntimeUpdate, @@ -96,14 +98,10 @@ def window_ended(self, session: AntigravitySession) -> tuple[RuntimeUpdate, ...] @dataclass -class AntigravityCatchUp(AntigravityReaderPhase): +class AntigravityCatchUp(CatchUpReadingPhase, AntigravityReaderPhase): pending: tuple[StatusUpdate, ...] = () latest_info: tuple[RuntimeInfoObserved, ...] = () - def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...]: - self.latest_info = (update,) - return () - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: self.pending = (update,) return () @@ -113,10 +111,7 @@ def window_ended(self, session: AntigravitySession) -> tuple[RuntimeUpdate, ...] return (*self.latest_info, *self.pending) -class AntigravityLive(AntigravityReaderPhase): - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: - return (update,) - +class AntigravityLive(LiveReadingPhase, AntigravityReaderPhase): def window_ended(self, session: AntigravitySession) -> tuple[RuntimeUpdate, ...]: return () diff --git a/src/agent_comms/cli_bridges/claude_protocol.py b/src/agent_comms/cli_bridges/claude_protocol.py index 8ef2324ced..0d17d58ac9 100644 --- a/src/agent_comms/cli_bridges/claude_protocol.py +++ b/src/agent_comms/cli_bridges/claude_protocol.py @@ -34,9 +34,11 @@ ActiveItem, AllTurnsCancelled, AllTurnsEnded, + CatchUpReadingPhase, FinishedItem, HiddenItem, HistoryNotice, + LiveReadingPhase, OfferedToolsObserved, ReadingPhase, RuntimeInfoObserved, @@ -364,7 +366,7 @@ def unturned_finish(self) -> tuple[RuntimeUpdate, ...]: ... @dataclass -class CatchUp(ClaudeReaderPhase): +class CatchUp(CatchUpReadingPhase, ClaudeReaderPhase): pending: tuple[StatusUpdate, ...] = () latest_tools: tuple[OfferedToolsObserved, ...] = () latest_info: tuple[RuntimeInfoObserved, ...] = () @@ -373,10 +375,6 @@ def offered(self, update: OfferedToolsObserved) -> tuple[RuntimeUpdate, ...]: self.latest_tools = (update,) return () - def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...]: - self.latest_info = (update,) - return () - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: self.pending = (update,) return () @@ -393,10 +391,7 @@ def unturned_finish(self) -> tuple[RuntimeUpdate, ...]: return () -class Live(ClaudeReaderPhase): - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: - return (update,) - +class Live(LiveReadingPhase, ClaudeReaderPhase): def window_ended(self, session: ClaudeSession) -> tuple[RuntimeUpdate, ...]: return () diff --git a/src/agent_comms/cli_bridges/runtime_updates.py b/src/agent_comms/cli_bridges/runtime_updates.py index 3c853c6995..323cde1893 100644 --- a/src/agent_comms/cli_bridges/runtime_updates.py +++ b/src/agent_comms/cli_bridges/runtime_updates.py @@ -362,6 +362,21 @@ def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...] return (update,) +class CatchUpReadingPhase(ReadingPhase): + """A transcript reading phase that buffers catch-up updates before going live.""" + + def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...]: + self.latest_info = (update,) + return () + + +class LiveReadingPhase(ReadingPhase): + """A live transcript reading phase that emits status updates immediately.""" + + def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: + return (update,) + + @dataclass(frozen=True) class RuntimeUpdate(ABC): """One change a runtime reports about its thread.""" @@ -477,8 +492,15 @@ def accumulate(self, output: ThreadOutput) -> tuple[RuntimeUpdate, ...]: return output.active_item(self) +class EventRecordingRuntimeUpdate(RuntimeUpdate): + """A runtime update that adds its events directly to an import buffer.""" + + def add_to(self, history: ImportBuffer) -> None: + history.add(self.events) + + @dataclass(frozen=True) -class FinishedItem(TurnItem, RuntimeUpdate): +class FinishedItem(TurnItem, EventRecordingRuntimeUpdate): """One CLI item's complete presentation, identified by its producer.""" events: tuple[TranscriptEvent, ...] @@ -500,9 +522,6 @@ def retain_before(self, later: set[TurnItem]) -> bool: def page_record(self, turn_id: NativeTurnId, item_id: NativeItemId) -> FinishedItem: return self - def add_to(self, history: ImportBuffer) -> None: - history.add(self.events) - @dataclass(frozen=True) class PageItem(TurnItem): @@ -553,15 +572,12 @@ def write(self, transcript: ExternalTranscript, records: tuple[FinishedItem, ... @dataclass(frozen=True) -class HiddenItem(UnpublishedRuntimeUpdate): +class HiddenItem(EventRecordingRuntimeUpdate, UnpublishedRuntimeUpdate): """Conversation the live view does not show, because the thread shows it another way (a bus delivery) or because only the person's own prompts are shown; history keeps it.""" events: tuple[TranscriptEvent, ...] - def add_to(self, history: ImportBuffer) -> None: - history.add(self.events) - @dataclass(frozen=True) class Summarized(UnpublishedRuntimeUpdate): diff --git a/src/agent_comms/execution/cli_inbox_backend.py b/src/agent_comms/execution/cli_inbox_backend.py index 73e8197507..5dfb45a8f1 100644 --- a/src/agent_comms/execution/cli_inbox_backend.py +++ b/src/agent_comms/execution/cli_inbox_backend.py @@ -40,9 +40,6 @@ class CliInboxRuntime(UnwrittenRuntimeLocation): path: str = "" - def is_resumable(self) -> bool: - return False - def require_forkable(self) -> None: pass diff --git a/src/agent_comms/execution/unstarted_runtime.py b/src/agent_comms/execution/unstarted_runtime.py index a44227f688..40e6c9e981 100644 --- a/src/agent_comms/execution/unstarted_runtime.py +++ b/src/agent_comms/execution/unstarted_runtime.py @@ -59,6 +59,9 @@ def history_source(self, root, incarnation): class UnwrittenRuntimeLocation(ExternalTranscriptLocation, declared_name=None): """A runtime location with no recorded transcript write timestamp.""" + def is_resumable(self) -> bool: + return False + def last_written(self) -> float: return 0.0 @@ -66,8 +69,6 @@ def last_written(self) -> float: @dataclass(frozen=True) class UnstartedRuntime(UnwrittenRuntimeLocation): owner: type[AgentBackend] - def is_resumable(self) -> bool: - return False @property def backend(self): diff --git a/src/agent_comms/messaging/channel_targets.py b/src/agent_comms/messaging/channel_targets.py index d83fd46e45..b92177c64d 100644 --- a/src/agent_comms/messaging/channel_targets.py +++ b/src/agent_comms/messaging/channel_targets.py @@ -247,22 +247,23 @@ class ReplyRoute(ABC): @abstractmethod def target(self, target_name: str, sender: str) -> str: ... + def sql(self, column: str, sender: str, names: tuple[str, ...]) -> tuple[str, tuple[str, ...]]: + target = self.target(column, sender) + return self._sql_step(column, sender, names, target) + @abstractmethod - def sql( - self, column: str, sender: str, names: tuple[str, ...], - ) -> tuple[str, tuple[str, ...]]: ... + def _sql_step(self, column: str, sender: str, names: tuple[str, ...], target) -> tuple[str, tuple[str, ...]]: + ... class SenderReply(ReplyRoute): def target(self, target_name: str, sender: str) -> str: return sender - def sql( - self, column: str, sender: str, names: tuple[str, ...], - ) -> tuple[str, tuple[str, ...]]: + def _sql_step(self, column: str, sender: str, names: tuple[str, ...], target) -> tuple[str, tuple[str, ...]]: marks = ",".join("?" for _ in names) return ( - f"{self.target(column, sender)} IN ({marks}) AND NOT ({ChannelReply.channel_sql(column)})", + f"{target} IN ({marks}) AND NOT ({ChannelReply.channel_sql(column)})", names, ) @@ -271,10 +272,8 @@ class ChannelReply(ReplyRoute): def target(self, target_name: str, sender: str) -> str: return target_name - def sql( - self, column: str, sender: str, names: tuple[str, ...], - ) -> tuple[str, tuple[str, ...]]: - return f"{self.target(column, sender)}=?", names + def _sql_step(self, column: str, sender: str, names: tuple[str, ...], target) -> tuple[str, tuple[str, ...]]: + return f"{target}=?", names @staticmethod def channel_sql(column: str) -> str: diff --git a/src/agent_comms/messaging/read_basis.py b/src/agent_comms/messaging/read_basis.py index 3019a862f1..d05a87f9b1 100644 --- a/src/agent_comms/messaging/read_basis.py +++ b/src/agent_comms/messaging/read_basis.py @@ -601,13 +601,17 @@ def recorded_keys(self, snapshot: RegistryProvenance) -> Iterable[Conversation]: def in_targets(self, targets: Collection[str], snapshot: RegistryProvenance) -> bool: ... -@dataclass(frozen=True, slots=True) -class AllConversation(Conversation): - """An explicit whole-bus read applies to every conversation in this source.""" +class NamedConversation(Conversation, declared_name=None): + """A conversation whose identity does not depend on per-incarnation DM resolution.""" - def resolved(self, snapshot: RegistryProvenance): + def resolved(self, snapshot: RegistryProvenance) -> Self: return self + +@dataclass(frozen=True, slots=True) +class AllConversation(NamedConversation): + """An explicit whole-bus read applies to every conversation in this source.""" + def scope(self, snapshot: RegistryProvenance) -> AllChannelDisplayScope: return AllChannelDisplayScope(AnyChannel.address()) @@ -623,12 +627,9 @@ def in_targets(self, targets: Collection[str], snapshot: RegistryProvenance) -> @dataclass(frozen=True, slots=True) -class ChannelConversation(Conversation): +class ChannelConversation(NamedConversation): target: str - def resolved(self, snapshot: RegistryProvenance) -> ChannelConversation: - return self - def scope(self, snapshot: RegistryProvenance) -> ChannelDisplayScope: return ChannelDisplayScope(self.target, frozenset((self.target,))) diff --git a/src/agent_comms/planning/goal_actions.py b/src/agent_comms/planning/goal_actions.py index 5c61704dad..4b06c47bdd 100644 --- a/src/agent_comms/planning/goal_actions.py +++ b/src/agent_comms/planning/goal_actions.py @@ -337,8 +337,16 @@ def before_transition(self, goal: Goal, ctx: GoalActionContext) -> None: ) +class WaitCompletingGoalAction(GoalAction, declared_name=None): + """A goal action sharing wait-completion handling.""" + + def complete_wait(self, ctx: GoalActionContext) -> None: + pass + + @dataclass(frozen=True, kw_only=True) class StandbyGoalAction( + WaitCompletingGoalAction, ActivatingGoalAction, GoalReportAction, ModelInvocable, @@ -346,8 +354,6 @@ class StandbyGoalAction( ): wait_for: tuple[str, ...] = () reviewed_inputs: tuple[Annotated[InputKey, InputKeyText], ...] = () - def complete_wait(self, ctx: GoalActionContext) -> None: - pass def prepare(self, goals: GoalActionStore, name: str, actor: type) -> GoalAction[Goal]: @@ -488,10 +494,14 @@ def create(self, ctx: GoalActionContext) -> NoGoal: @dataclass(frozen=True, kw_only=True) -class EditGoalAction(GoalAction[Goal], OwnerInvocable, RuntimeInvocable, PeerInvocable): +class EditGoalAction( + WaitCompletingGoalAction, + GoalAction[Goal], + OwnerInvocable, + RuntimeInvocable, + PeerInvocable, +): text: str - def complete_wait(self, ctx: GoalActionContext) -> None: - pass def change(self, goal: Goal, ctx: GoalActionContext) -> Goal: diff --git a/src/agent_comms/registry/thread_status.py b/src/agent_comms/registry/thread_status.py index 09ebed6f46..3a592480d7 100644 --- a/src/agent_comms/registry/thread_status.py +++ b/src/agent_comms/registry/thread_status.py @@ -511,12 +511,16 @@ def presentation( return replace(super().presentation(title, activity, idle), summary="CLI inbox ยท no bridge") -class ServiceThreadStatus(PublishingPresence, ThreadStatus): - """A service can publish, but has no executable roster row or owner controls.""" +class HiddenThreadStatus(ThreadStatus, declared_name=None): + """A thread status excluded from user roster views.""" def in_view(self, visibility: RosterVisibility) -> bool: return False + +class ServiceThreadStatus(PublishingPresence, HiddenThreadStatus): + """A service can publish, but has no executable roster row or owner controls.""" + def external_registered(self, thread: PresenceThread, now: float) -> ThreadStatus: return self @@ -545,10 +549,7 @@ def active_checkout_matches(self, thread): return () -class DeletingThreadStatus(ThreadStatus): - def in_view(self, visibility: RosterVisibility) -> bool: - return False - +class DeletingThreadStatus(HiddenThreadStatus): def require_deleting(self) -> None: pass diff --git a/src/agent_comms/storage/private_path.py b/src/agent_comms/storage/private_path.py index fc015c814e..e5b0c0f53d 100644 --- a/src/agent_comms/storage/private_path.py +++ b/src/agent_comms/storage/private_path.py @@ -213,7 +213,15 @@ def accepts_links(cls, nlink: int) -> bool: return nlink == 1 -class PrivateDirectoryRole(PrivateRole): +class DirectoryFilesystemRole(FilesystemRole, declared_name=None): + """A filesystem role that requires and opens a directory.""" + + @classmethod + def accepts_kind(cls, mode: int) -> bool: + return stat.S_ISDIR(mode) + + +class PrivateDirectoryRole(DirectoryFilesystemRole, PrivateRole): permissions = 0o700 @classmethod @@ -240,10 +248,6 @@ def require_private_tree( def kind_flags(cls) -> int: return os.O_DIRECTORY - @classmethod - def accepts_kind(cls, mode: int) -> bool: - return stat.S_ISDIR(mode) - class PrivateSocketRole(NonBlockingFilesystemRole): @classmethod @@ -269,21 +273,17 @@ def address(cls, path: Path) -> Iterator[Path]: yield address -class OwnedDirectoryRole(FilesystemRole): +class OwnedDirectoryRole(DirectoryFilesystemRole): @classmethod def kind_flags(cls) -> int: return os.O_DIRECTORY - @classmethod - def accepts_kind(cls, mode: int) -> bool: - return stat.S_ISDIR(mode) - @classmethod def accepts_permissions(cls, observed: os.stat_result) -> bool: return True -class TrustedAncestorRole(FilesystemRole): +class TrustedAncestorRole(DirectoryFilesystemRole): @classmethod def kind_flags(cls) -> int: return os.O_DIRECTORY @@ -293,10 +293,6 @@ def require_path(cls, directory: Path, refusal: Exception) -> None: for ancestor in (directory, *directory.parents): cls.require(ancestor.lstat(), refusal) - @classmethod - def accepts_kind(cls, mode: int) -> bool: - return stat.S_ISDIR(mode) - @classmethod def accepts_owner(cls, uid: int) -> bool: return HostPlatform.current().trusted_ancestor_owner(uid)