From fb4b8852d654443ea20193fdff8e2abdcf97796c Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Sat, 28 Nov 2026 01:19:46 -0500 Subject: [PATCH] Apply 10 clean NRA codemod recipes (5 cycle cuts, 3 empty subclasses, 1 retype, 1 promote) Applied mechanically via nominal-refactor-advisor --codemod-apply src against core-1c20b52e3 (carrying NRA #644): - cut_hidden_cycle (5): toad.acp.session_binding, toad.client.block_claim, toad.core.link_context_changed, toad.cursor_movement, toad.publication_work - redirect_empty_subclass (3): LoginNotReady, ApplicationNotRunningError, ApplicationStartupObserverAlreadyInstalled - retype_type_only_reads (1): toad.widgets.terminal_tool (AttachedSurfaceBinding -> ViewSurfaceBinding) - promote_hidden_imports (1): toad.render_processes Updated 9 test files for symbols moved by cut_hidden_cycle. --- src/toad/acp/agent.py | 3 +- src/toad/acp/agent_controller.py | 33 +------- src/toad/acp/agent_session.py | 9 +- src/toad/acp/client_session.py | 2 +- src/toad/acp/session_agent.py | 3 +- src/toad/acp/session_binding.py | 34 ++++++++ src/toad/agent.py | 3 +- src/toad/agent_binding.py | 3 +- src/toad/agent_surface.py | 2 +- src/toad/agent_turn_events.py | 11 +-- src/toad/app.py | 6 +- src/toad/application_lifetime.py | 6 +- src/toad/client/application.py | 4 +- src/toad/client/block_claim.py | 43 ++++++++++ src/toad/client/committed_presentation.py | 33 +------- src/toad/client/connection.py | 3 +- src/toad/client/history.py | 2 +- src/toad/client/session_tracker.py | 3 +- src/toad/client/subscribers.py | 3 +- src/toad/client/tab_order.py | 3 +- src/toad/client/transfers.py | 3 +- src/toad/client/view_binding_protocols.py | 5 +- src/toad/comms_host.py | 2 +- src/toad/conversation_comms_handlers.py | 2 +- src/toad/conversation_turn.py | 2 +- src/toad/core/configuration_events.py | 2 +- src/toad/core/events.py | 83 ++----------------- src/toad/core/input_events.py | 2 +- src/toad/core/link_context_changed.py | 76 +++++++++++++++++ src/toad/core/preference_events.py | 2 +- src/toad/core/session_requests.py | 2 +- src/toad/core/source_events.py | 2 +- src/toad/core_event_carrier.py | 2 +- src/toad/cursor_movement.py | 25 ++++++ src/toad/launch_binding.py | 2 +- src/toad/navigation_target.py | 2 +- src/toad/preferences.py | 2 +- src/toad/project_path_owner.py | 2 +- src/toad/prompt_cursor.py | 22 +---- src/toad/publication_work.py | 25 ++++++ src/toad/qt/agent_surface.py | 2 +- src/toad/qt/core_events.py | 2 +- src/toad/qt/history.py | 2 +- src/toad/render_processes.py | 6 +- src/toad/session_navigation.py | 2 +- src/toad/shell_source.py | 2 +- src/toad/transcript_publication.py | 27 +----- src/toad/widgets/comms_chat.py | 5 +- src/toad/widgets/conversation.py | 5 +- src/toad/widgets/linked_rows.py | 2 +- src/toad/widgets/message_divider.py | 2 +- src/toad/widgets/message_row_owner.py | 6 +- src/toad/widgets/path_search.py | 2 +- src/toad/widgets/prompt_popup.py | 2 +- src/toad/widgets/session_tabs.py | 5 +- src/toad/widgets/shell_result.py | 2 +- src/toad/widgets/terminal_tool.py | 9 +- tests/app/test_transcript_recipient.py | 2 +- ...core_event_handlers_receive_their_event.py | 2 +- tests/guards/test_shared_hook_sequences.py | 6 +- .../test_android_resync_lazy_load_catchup.py | 3 +- ...st_session_updates_after_binding_change.py | 3 +- tests/support/agents.py | 2 +- tests/textual/test_initial_session_title.py | 3 +- tests/textual/test_live_output_streams.py | 3 +- tests/textual/test_pooled_composer_neovim.py | 2 +- 66 files changed, 308 insertions(+), 275 deletions(-) create mode 100644 src/toad/acp/session_binding.py create mode 100644 src/toad/client/block_claim.py create mode 100644 src/toad/core/link_context_changed.py create mode 100644 src/toad/cursor_movement.py create mode 100644 src/toad/publication_work.py diff --git a/src/toad/acp/agent.py b/src/toad/acp/agent.py index f1aa8a00ec..f3abf1d63e 100644 --- a/src/toad/acp/agent.py +++ b/src/toad/acp/agent.py @@ -34,6 +34,7 @@ from toad.core import events as core_events from toad.client.platform import host from toad.core.events import UpdateStatusLine +from toad.core.link_context_changed import CoreEventStream @rich.repr.auto @@ -53,7 +54,7 @@ def __init__( session_id: AcpSessionId | NoAcpSessionId, session_pk: int | None = None, *, - app_events: core_events.CoreEventStream, + app_events: CoreEventStream, transcripts: CoordinationTranscriptReader, ) -> None: """ diff --git a/src/toad/acp/agent_controller.py b/src/toad/acp/agent_controller.py index ab2400ca4e..7d71b38830 100644 --- a/src/toad/acp/agent_controller.py +++ b/src/toad/acp/agent_controller.py @@ -4,7 +4,6 @@ import asyncio from abc import ABC, abstractmethod -from dataclasses import dataclass, field from functools import partial from typing import TYPE_CHECKING @@ -20,14 +19,12 @@ ) from agent_comms.acp_extension import InputFailedUpdate from agent_comms.execution.acp_failure import ACPFailure, RequestFailure -from agent_comms.nominal.field_codec import AcpSessionId, FieldCodec, NoAcpSessionId -from agent_comms.registry.thread_identity import ThreadIncarnation -from agent_comms.transcript.transcripts import TranscriptReadIdentity +from agent_comms.nominal.field_codec import NoAcpSessionId from toad.acp.client_session import ClientSessionRequest, QueueSessionRequest from toad.acp.prompt import build as build_prompt from toad.acp.queue_attachment import QueueActionRefused -from toad.acp.session_output import SessionOutput +from toad.acp.session_binding import SessionBinding from toad.acp.status import StopReason from toad.acp.terminal_owner import OperationalTerminalOwner from toad.client.transcript_reader import CoordinationTranscriptReader @@ -53,32 +50,6 @@ from toad.acp.agent import Agent -class SourceIdentity: - def matches_source(self, root: str, thread: ThreadIncarnation) -> bool: - return False - - -@dataclass(frozen=True) -class SessionBinding: - """Actual ACP binding identity, preserved only until session replacement.""" - - session_id: AcpSessionId | NoAcpSessionId - output: SessionOutput = field(default_factory=SessionOutput, compare=False) - - @property - def bound(self) -> bool: - return self.session_id.bound - - def accepts_notification(self, session_id: AcpSessionId): - return self.session_id == session_id - - def accepts_snapshot( - self, identity: TranscriptReadIdentity, owner: SourceIdentity - ) -> bool: - return (self.accepts_notification(FieldCodec.decode(AcpSessionId, identity.requested_name)) - and owner.matches_source(identity.root, identity.thread.incarnation)) - - class TaskRunner(ABC): @abstractmethod async def run[Result](self, task: RenderTask[Result]) -> Result: ... diff --git a/src/toad/acp/agent_session.py b/src/toad/acp/agent_session.py index 8eeebd1e43..4b12354ffd 100644 --- a/src/toad/acp/agent_session.py +++ b/src/toad/acp/agent_session.py @@ -37,6 +37,7 @@ UnsupportedResumeAgentFail, ) from toad.client.db import DB, SessionMeta +from toad.core.link_context_changed import CoreEventStream PROTOCOL_VERSION = 1 @@ -136,16 +137,12 @@ class RefusedSessionDisposition(UnheldSessionDisposition, FailedSessionDispositi """The agent process answered the handshake with an error; it holds no session.""" -class LoginNotReady(ValueError): - """A terminal login finished, but the session it restarted did not become ready.""" - - class AgentSession: """Own readiness and durable session effects; binding identity stays on the controller.""" reconnect_timeout_seconds = 30 - def __init__(self, agent, pk, app_events: core_events.CoreEventStream) -> None: + def __init__(self, agent, pk, app_events: CoreEventStream) -> None: self.agent = agent # The app's stream: its thread rows show this session's state, attached to a view or not. self.app_events = app_events @@ -365,7 +362,7 @@ async def reconnect_after_login(self) -> None: """Only a session that is ready after its restart counts as a finished login.""" await self.reconnect() if not self.ready: - raise LoginNotReady(self.disposition.refusal_notice) + raise ValueError(self.disposition.refusal_notice) async def authenticate(self, method_id: str) -> None: authority = ClientSessionRequest(self.agent, self.agent.session_id) diff --git a/src/toad/acp/client_session.py b/src/toad/acp/client_session.py index a7e6fe9d3a..aeb042fa16 100644 --- a/src/toad/acp/client_session.py +++ b/src/toad/acp/client_session.py @@ -5,11 +5,11 @@ from agent_comms.acp_extension import CoordinationChangedUpdate from toad.acp.queue_attachment import QueueActionRefused +from toad.acp.session_binding import SessionBinding from toad.acp.status import StopReason, UnreportedStopReason if TYPE_CHECKING: from toad.acp.agent import Agent - from toad.acp.agent_controller import SessionBinding from toad.acp.agent_session import SessionDisposition from acp.exceptions import RequestError from agent_comms.nominal.field_codec import AcpSessionId, FieldCodec, NoAcpSessionId diff --git a/src/toad/acp/session_agent.py b/src/toad/acp/session_agent.py index a288b6d2ac..180693f08e 100644 --- a/src/toad/acp/session_agent.py +++ b/src/toad/acp/session_agent.py @@ -45,10 +45,11 @@ from agent_comms.ui_model.observation import ReadOwnerOperation from pydantic import JsonValue -from toad.acp.agent_controller import AgentController, SourceIdentity +from toad.acp.agent_controller import AgentController from toad.acp.client_session import ClientSessionRequest, OwnerRequest from toad.acp.comms_updates import PendingThreadRead from toad.acp.goal_control import ClientGoalControls +from toad.acp.session_binding import SourceIdentity from toad.agent import AgentBase from toad.core import events as core_events diff --git a/src/toad/acp/session_binding.py b/src/toad/acp/session_binding.py new file mode 100644 index 0000000000..31fa4afb72 --- /dev/null +++ b/src/toad/acp/session_binding.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from dataclasses import dataclass, field + +from agent_comms.nominal.field_codec import AcpSessionId, FieldCodec, NoAcpSessionId +from agent_comms.registry.thread_identity import ThreadIncarnation +from agent_comms.transcript.transcripts import TranscriptReadIdentity +from toad.acp.session_output import SessionOutput + + +class SourceIdentity: + def matches_source(self, root: str, thread: ThreadIncarnation) -> bool: + return False + + +@dataclass(frozen=True) +class SessionBinding: + """Actual ACP binding identity, preserved only until session replacement.""" + + session_id: AcpSessionId | NoAcpSessionId + output: SessionOutput = field(default_factory=SessionOutput, compare=False) + + @property + def bound(self) -> bool: + return self.session_id.bound + + def accepts_notification(self, session_id: AcpSessionId): + return self.session_id == session_id + + def accepts_snapshot( + self, identity: TranscriptReadIdentity, owner: SourceIdentity + ) -> bool: + return (self.accepts_notification(FieldCodec.decode(AcpSessionId, identity.requested_name)) + and owner.matches_source(identity.root, identity.thread.incarnation)) diff --git a/src/toad/agent.py b/src/toad/agent.py index d2dcf9d95d..ffdbddc560 100644 --- a/src/toad/agent.py +++ b/src/toad/agent.py @@ -12,7 +12,8 @@ from toad.agent_presentation import LocalAgentPresentation from toad.client.db import DB from toad.conversation_turn import NoTurn, TurnOwner -from toad.core.events import CoreEventStream, SessionAgentAttached +from toad.core.events import SessionAgentAttached +from toad.core.link_context_changed import CoreEventStream from toad.session_observation import SessionObservation from toad.submission_queue import QueueSource from toad.surface_binding import SurfaceBinding diff --git a/src/toad/agent_binding.py b/src/toad/agent_binding.py index c6f8a8007c..44bad3edc3 100644 --- a/src/toad/agent_binding.py +++ b/src/toad/agent_binding.py @@ -17,13 +17,12 @@ from toad.acp.agent_controller import AgentController from toad.acp.agent_session import SessionDisposition, UnopenedSessionDisposition from toad.client.submission import SubmissionStart +from toad.core.link_context_changed import CoreEventStream, Publication from toad.goal_controls import GoalSource from toad.agent_presentation import AgentPresentation, LocalAgentPresentation -from toad.core.events import CoreEventStream from toad.client.input_decision import InputAccepted, InputDecision, NoLiveAgent from toad.commit_claims import CommitSource from toad.conversation_turn import TurnOwner -from toad.core.events import Publication from toad.acp.comms_updates import ThreadRead from agent_comms.nominal.field_codec import AcpSessionId diff --git a/src/toad/agent_surface.py b/src/toad/agent_surface.py index 979fd542b9..1b367ecd6c 100644 --- a/src/toad/agent_surface.py +++ b/src/toad/agent_surface.py @@ -25,7 +25,7 @@ from toad.acp.terminal_owner import OperationalTerminalOwner from toad.ansi import TerminalState from toad.answer import Answer - from toad.core.events import CoreEventStream + from toad.core.link_context_changed import CoreEventStream from toad.core_event_carrier import CoreEventMessage from toad.shell_output import ShellOutput from toad.terminal_execution import TerminalExecution diff --git a/src/toad/agent_turn_events.py b/src/toad/agent_turn_events.py index 0273f2b87f..acf2170820 100644 --- a/src/toad/agent_turn_events.py +++ b/src/toad/agent_turn_events.py @@ -16,6 +16,7 @@ from metaclass_registry.mro_dispatch import MroDispatch, handles from toad.core import events as core_events +from toad.core.link_context_changed import Publication class AgentTurnEvents(MroDispatch): @@ -33,7 +34,7 @@ def update_slash_commands(self) -> object: """Offer the agent's current commands in the composer.""" @handles(core_events.Update) - async def on_acp_agent_message(self, event: core_events.Update, message: core_events.Publication) -> None: + async def on_acp_agent_message(self, event: core_events.Update, message: Publication) -> None: self.consumed(message) if not self.agent_binding.matches_agent(message.publisher): return @@ -42,22 +43,22 @@ async def on_acp_agent_message(self, event: core_events.Update, message: core_ev await self.output.append(event.stream, event.text) @handles(core_events.Thinking) - async def on_acp_agent_thinking(self, event: core_events.Thinking, message: core_events.Publication) -> None: + async def on_acp_agent_thinking(self, event: core_events.Thinking, message: Publication) -> None: self.turns.describe("Thinking…") await self.output.append(event.stream, event.text) @handles(core_events.RequestPermission) - async def on_acp_request_permission(self, event: core_events.RequestPermission, message: core_events.Publication) -> None: + async def on_acp_request_permission(self, event: core_events.RequestPermission, message: Publication) -> None: for request in message.publisher.permissions.pending: self.request_permissions(request) self.output.boundary() @handles(core_events.ToolCall) - async def on_acp_tool_call_update(self, event: core_events.ToolCall, message: core_events.Publication) -> None: + async def on_acp_tool_call_update(self, event: core_events.ToolCall, message: Publication) -> None: await message.publisher.controller.surface.present_tool(message, self) @handles(core_events.AvailableCommandsUpdate) async def on_acp_available_commands_update( - self, event: core_events.AvailableCommandsUpdate, message: core_events.Publication + self, event: core_events.AvailableCommandsUpdate, message: Publication ) -> None: self.update_slash_commands() diff --git a/src/toad/app.py b/src/toad/app.py index 6a37aceac0..741aca5efc 100644 --- a/src/toad/app.py +++ b/src/toad/app.py @@ -89,10 +89,6 @@ class ToadLoadingIndicator(TransparentBackground, LoadingIndicator): -class ApplicationNotRunningError(RuntimeError): - """The application has no event loop to accept cross-thread work.""" - - class ToadApp(DeclaredWidgetActions, WorkspaceSessionShutdown, WorkspaceHost, ClientApplication, CorePrewarm, Transfers, HostsNeovim, actions=(ApplicationAction,), inherit_bindings=False): """The top level app.""" @@ -456,7 +452,7 @@ def selected_mode(self): def running_loop(self) -> asyncio.AbstractEventLoop: loop = self._loop if loop is None: - raise ApplicationNotRunningError("App is not running") + raise RuntimeError("App is not running") return loop def schedule_from_thread(self, callback: Callable[[], object]) -> None: diff --git a/src/toad/application_lifetime.py b/src/toad/application_lifetime.py index 6050da62ed..0bd57617da 100644 --- a/src/toad/application_lifetime.py +++ b/src/toad/application_lifetime.py @@ -91,10 +91,6 @@ async def deliver(self, event_name: str, properties: dict[str, object]) -> None: return -class ApplicationStartupObserverAlreadyInstalled(RuntimeError): - """Only one external observer may await the next application startup.""" - - class ApplicationStartupHook: """One-shot startup observation state owned by the application lifetime.""" @@ -110,7 +106,7 @@ class PendingApplicationStartupHook(ApplicationStartupHook): observer: Callable[[ApplicationLifetime], None] def install(self, observer: Callable[[ApplicationLifetime], None]) -> ApplicationStartupHook: - raise ApplicationStartupObserverAlreadyInstalled( + raise RuntimeError( "An application startup observer is already installed") def notify(self, lifetime: ApplicationLifetime) -> ApplicationStartupHook: diff --git a/src/toad/client/application.py b/src/toad/client/application.py index f16c6f222e..1b2e0c125d 100644 --- a/src/toad/client/application.py +++ b/src/toad/client/application.py @@ -27,6 +27,7 @@ from toad.client.pending import BusConnecting, awaited from toad.application_lifetime import ApplicationLifetime, ApplicationStart +from toad.core.link_context_changed import CoreEventStream from toad.heap import HEAP from toad.client import bus_connect from toad.client.bus_selection import ( @@ -46,7 +47,6 @@ from toad.client.tab_order import TabOrder from toad.client.view_settings import ApplicationSettings from toad.constants import WELCOME -from toad.core import events as core_events from toad.core import session_requests from toad.launch_binding import AgentBinding from toad.launch_opening import LaunchOpening, NoLaunchOpening @@ -262,7 +262,7 @@ def initialize_client( constructor runs before a terminal captures stderr, which spawn bookkeeping needs.""" self.preparation.renderer.start() self.render_processes = self._make_render_processes() - self.events = core_events.CoreEventStream(self) + self.events = CoreEventStream(self) self.navigation_reader = NavigationReader() self.agent_binding = agent_binding self.application = self.lifetime_kind(self, agent_session_id, opening) diff --git a/src/toad/client/block_claim.py b/src/toad/client/block_claim.py new file mode 100644 index 0000000000..f87656395a --- /dev/null +++ b/src/toad/client/block_claim.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from metaclass_registry.mro_dispatch import handles +from toad.commit_claims import ( + CommitBarrierClaim, + CommitClaim, + CommitParticipant, + RetainedBlockClaim, +) +from toad.core.projection import MroProjection + +if TYPE_CHECKING: + from textual.widget import Widget + + +class CommitBarrier: + """A local interactive session whose ordering cannot be replaced by a snapshot.""" + + +class BlockClaims(MroProjection[CommitClaim]): + """Every block a conversation's contents hold has one commit claim; this is where it is read.""" + + # object, not Widget: a history's MRO reaches Widget before its CommitParticipant base. + @handles(object) + def retained(self, widget: Widget) -> CommitClaim: + return RetainedBlockClaim() + + @handles(CommitParticipant) + def participant(self, widget: CommitParticipant) -> CommitClaim: + return widget.commit_claim + + @handles(CommitBarrier) + def barrier(self, widget: CommitBarrier) -> CommitClaim: + return CommitBarrierClaim() + + +BLOCK_CLAIMS = BlockClaims() + + +def block_claim(widget: object) -> CommitClaim: + return BLOCK_CLAIMS.project_value(widget) diff --git a/src/toad/client/committed_presentation.py b/src/toad/client/committed_presentation.py index 6d1a5c16ab..1d4aca731d 100644 --- a/src/toad/client/committed_presentation.py +++ b/src/toad/client/committed_presentation.py @@ -19,23 +19,20 @@ from metaclass_registry.mro_dispatch import handles from textual.await_complete import AwaitComplete +from toad.client.block_claim import block_claim from toad.client.history_preparation import NEWER_END from toad.client.history_state import PreparedReplacementViewportRequest, TranscriptState, WorkingTranscript from toad.client.prepared_pages import PreparedPageSource, SavedHistory from toad.client.reader_position import LatestPosition from toad.commit_claims import ( - CommitBarrierClaim, CommitClaim, CommitEvidence, - CommitParticipant, LiveResponsePresentation, - RetainedBlockClaim, ) from toad.core.projection import MroProjection from toad.transcript_preparation import TranscriptPageRenderTask if TYPE_CHECKING: - from textual.widget import Widget from toad.client.prepared_pages import PreparedTranscriptPage from toad.widgets.conversation import Conversation @@ -43,34 +40,6 @@ from toad.widgets.transcript_history import CommittedHistory, TranscriptHistory -class CommitBarrier: - """A local interactive session whose ordering cannot be replaced by a snapshot.""" - - -class BlockClaims(MroProjection[CommitClaim]): - """Every block a conversation's contents hold has one commit claim; this is where it is read.""" - - # object, not Widget: a history's MRO reaches Widget before its CommitParticipant base. - @handles(object) - def retained(self, widget: Widget) -> CommitClaim: - return RetainedBlockClaim() - - @handles(CommitParticipant) - def participant(self, widget: CommitParticipant) -> CommitClaim: - return widget.commit_claim - - @handles(CommitBarrier) - def barrier(self, widget: CommitBarrier) -> CommitClaim: - return CommitBarrierClaim() - - -BLOCK_CLAIMS = BlockClaims() - - -def block_claim(widget: object) -> CommitClaim: - return BLOCK_CLAIMS.project_value(widget) - - class DraftCoverage(MroProjection[bool]): """Whether a live block already draws the in-progress assistant reply.""" diff --git a/src/toad/client/connection.py b/src/toad/client/connection.py index c33426e510..cfc4b1a20d 100644 --- a/src/toad/client/connection.py +++ b/src/toad/client/connection.py @@ -105,9 +105,7 @@ from toad.client.context_reads import ContextReads from toad.core.events import ( CoordinationObserved, - CoreEventStream, ExternalTranscriptChanged, - LinkContextChanged, ObservedServiceChanged, OpenTabsChanged, SidebarPresented, @@ -126,6 +124,7 @@ from toad.client.resource_release import AsyncResourceRelease, ResourceRelease from toad.client.session_projection import SessionCollection, SessionProjection from toad.client.thread_comms_source import RelationshipReads +from toad.core.link_context_changed import CoreEventStream, LinkContextChanged T = TypeVar("T") diff --git a/src/toad/client/history.py b/src/toad/client/history.py index 31efe223c9..f1567826ea 100644 --- a/src/toad/client/history.py +++ b/src/toad/client/history.py @@ -41,7 +41,7 @@ from toad.client.connection import CoordinationAccess, Observation from toad.client.conversation import ConversationKind from toad.client.resource_release import ResourceRelease -from toad.core.events import Publication +from toad.core.link_context_changed import Publication from toad.core.source_events import TranscriptSourceWorkFinished from toad.client.conversation_capabilities import ( ConversationActivity, diff --git a/src/toad/client/session_tracker.py b/src/toad/client/session_tracker.py index 6b400540bf..480bde626d 100644 --- a/src/toad/client/session_tracker.py +++ b/src/toad/client/session_tracker.py @@ -9,9 +9,10 @@ from agent_comms.ui_model.unread import ExactUnread, UnreadPresentation from toad.client.conversation import ConversationKind -from toad.core.events import CoreEventStream, SessionChangedEvent, SessionClosedEvent +from toad.core.events import SessionChangedEvent, SessionClosedEvent from toad.client.tab_identity import SessionTabIdentity, TabIdentity from toad.client.tab_order import TabOrder +from toad.core.link_context_changed import CoreEventStream @dataclass(frozen=True) diff --git a/src/toad/client/subscribers.py b/src/toad/client/subscribers.py index 7c0d987ce1..2c34e4d822 100644 --- a/src/toad/client/subscribers.py +++ b/src/toad/client/subscribers.py @@ -11,7 +11,8 @@ from metaclass_registry.mro_dispatch import MroDispatch -from toad.core.events import CoreEvent, CoreEventStream, ThreadChangeSubscription +from toad.core.events import ThreadChangeSubscription +from toad.core.link_context_changed import CoreEvent, CoreEventStream @dataclass(eq=False) diff --git a/src/toad/client/tab_order.py b/src/toad/client/tab_order.py index 6bfd627c24..881b5aed09 100644 --- a/src/toad/client/tab_order.py +++ b/src/toad/client/tab_order.py @@ -6,9 +6,10 @@ from agent_comms.execution.child_process import join_retirement -from toad.core.events import CoreEventStream, TabHistoryChanged +from toad.core.events import TabHistoryChanged from toad.client.db import DB, TabScope from toad.client.tab_identity import TabIdentity +from toad.core.link_context_changed import CoreEventStream class TabOrder: diff --git a/src/toad/client/transfers.py b/src/toad/client/transfers.py index 5f9b427b0e..3afc97237d 100644 --- a/src/toad/client/transfers.py +++ b/src/toad/client/transfers.py @@ -31,6 +31,7 @@ from toad.client.connection import CapturedSource, CoordinationAccess from toad.client.host import CommsHost from toad.core import events as core_events +from toad.core.link_context_changed import CoreEventStream from toad.work_preparation import PreparationRuntime class TransferProgress: @@ -109,7 +110,7 @@ class TransferHost(CommsHost): coordination_access: CoordinationAccess preparation: PreparationRuntime - events: core_events.CoreEventStream + events: CoreEventStream @asynccontextmanager async def export_progress(self) -> AsyncIterator[CancellableExportProgress]: diff --git a/src/toad/client/view_binding_protocols.py b/src/toad/client/view_binding_protocols.py index 30490c67ce..36e4661207 100644 --- a/src/toad/client/view_binding_protocols.py +++ b/src/toad/client/view_binding_protocols.py @@ -20,15 +20,16 @@ from toad.client.prepared_pages import PreparedPageSource, PreparedTranscriptPage from toad.client.session_scope import SessionScope from toad.client.transcript_history_contract import TranscriptHistoryContract -from toad.core.events import Publication, ThreadRowsChanged +from toad.core.events import ThreadRowsChanged +from toad.core.link_context_changed import Publication from toad.core.source_events import TranscriptCoverage, TranscriptSourceWorkFinished +from toad.publication_work import PublicationWork if TYPE_CHECKING: from agent_comms.execution.transcript_sources import TranscriptCursor from agent_comms.transcript.transcript_drafts import NoDraft from agent_comms.transcript.transcripts import TranscriptReadIdentity - from toad.transcript_publication import PublicationWork class BoundViewHost: diff --git a/src/toad/comms_host.py b/src/toad/comms_host.py index ba92629c21..7e77a38937 100644 --- a/src/toad/comms_host.py +++ b/src/toad/comms_host.py @@ -18,7 +18,7 @@ from toad.application_outcome import ApplicationOutcome from toad.client.bus_selection import BusPickerHost from toad.client.host import NavigatingHost -from toad.core.events import CoreEventStream +from toad.core.link_context_changed import CoreEventStream from toad.core_event_carrier import CoreEventReceiver from toad.textual_colours import ThemedApp from toad.work_preparation import PreparationRuntime diff --git a/src/toad/conversation_comms_handlers.py b/src/toad/conversation_comms_handlers.py index 47de4e3d40..5393c59e80 100644 --- a/src/toad/conversation_comms_handlers.py +++ b/src/toad/conversation_comms_handlers.py @@ -26,7 +26,7 @@ from toad.client.subscribers import CoreObserverDispatch from toad.core import events as core_events from toad.core.configuration_events import ChangeConfiguration, ChangeModel -from toad.core.events import Publication +from toad.core.link_context_changed import Publication class ConversationCommsHandlers(CoreObserverDispatch): diff --git a/src/toad/conversation_turn.py b/src/toad/conversation_turn.py index d38f96aa73..13032dc4da 100644 --- a/src/toad/conversation_turn.py +++ b/src/toad/conversation_turn.py @@ -12,6 +12,7 @@ from agent_comms.nominal.declared_family import DeclaredFamily from agent_comms.registry.activity import ActivityState from agent_comms.ui_model.status import ThreadStatusModel +from toad.client.block_claim import block_claim from toad.core_event_carrier import CoreEventMessage from toad.turn_presentation import TurnPresentation @@ -61,7 +62,6 @@ def accepts_update(self, update) -> bool: def captured_snapshot(self, widgets: tuple[Widget, ...]): """Each original claim owns capture while this source is active.""" - from toad.client.committed_presentation import block_claim return frozenset(widget for widget in widgets if block_claim(widget).capture(not self.busy)) diff --git a/src/toad/core/configuration_events.py b/src/toad/core/configuration_events.py index 0be153f7dd..64e84bcb9d 100644 --- a/src/toad/core/configuration_events.py +++ b/src/toad/core/configuration_events.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent @dataclass(frozen=True) diff --git a/src/toad/core/events.py b/src/toad/core/events.py index f478952ed4..2033d5a1e6 100644 --- a/src/toad/core/events.py +++ b/src/toad/core/events.py @@ -7,12 +7,9 @@ from functools import cached_property from pathlib import Path from typing import Annotated, ClassVar -from weakref import WeakSet, WeakValueDictionary +from weakref import WeakSet -from formbridge.publications import ( - PublicationStream, - Subscription, -) +from formbridge.publications import Subscription from agent_comms.acp_extension import ( NoQueueScope, @@ -21,7 +18,6 @@ from agent_comms.acp_extension import AgentCommsUpdate from agent_comms.acp_extension import RequestFailedUpdate from agent_comms.messaging.sent_message import AssignedSourceIdentity -from agent_comms.nominal.declared_family import DeclaredFamily from agent_comms.nominal.field_codec import AcpSessionId, NoAcpSessionId, PathText from agent_comms.presentation import ReadState from agent_comms.team.team_hud import TeamBoardCut, TeamHud @@ -29,6 +25,12 @@ from toad.acp.attachment_presentation import CursorPresentation, QueuePresentation from toad.acp.sdk_boundary import ToolCallWire from toad.acp.status import ToolCallStatus +from toad.core.link_context_changed import ( + CoreEvent, + CoreEventStream, + LinkContextChanged, + Publication, +) from toad.live_output import OutputStream, ThoughtStream from toad.plan import PlanItem from toad.client.tab_identity import TabIdentity @@ -40,35 +42,6 @@ class ThreadInterestUpdate(OperationKind, ExclusiveKind): """Tells Core which threads the open views are interested in; a newer update supersedes one running.""" -class CoreEvent(DeclaredFamily, affix="Event"): - """An application publication; its wire shape belongs to FieldCodec.""" - - def accepted_by(self, handler: object, message: Publication) -> bool: - """Whether a conversation comms handler accepts this publication.""" - return True - - def refreshes(self, screen: object) -> bool: - """Whether this publication is the given screen's to act on. - - A publication owns what it means for the views that receive it, so a screen asks this - question instead of classifying events by type. Every event is news to every screen - unless its member says otherwise. - """ - return True - - def subscribers(self, stream: CoreEventStream): - for event_type in type(self).__mro__: - yield from stream.subscriptions.get(event_type, ()) - - def replaces(self, queued: CoreEvent) -> bool: - """Only a CoalescingEvent replaces a queued publication.""" - return False - - def keyed_as(self, key: object) -> bool: - """Only a queued CoalescingEvent carries a coalescing key.""" - return False - - class CoalescingEvent(CoreEvent, declared_name=None): """A newer publication supersedes a queued one with an equal coalescing key. @@ -285,11 +258,6 @@ def subscribers(self, stream: CoreEventStream): yield from super().subscribers(stream) -@dataclass(frozen=True) -class LinkContextChanged(CoreEvent): - """The original project or reference observation changed; redraw from its owner.""" - - @dataclass(frozen=True) class ObservedServiceChanged(LinkContextChanged): """The access owner attached a replacement service, not just new references.""" @@ -440,18 +408,6 @@ async def present(self, view) -> None: # Session inspection keeps ACP log access independent of delivery notices. -class Publication: - """One delivered Core event and the subscription it arrived on. Each frontend's carrier - is one; who published it follows from the subscription's stream.""" - - event: CoreEvent - subscription: Subscription - - @property - def publisher(self) -> object: - return self.subscription.stream.publisher - - @dataclass(eq=False) class ThreadChangeSubscription(Subscription): """One live thread scope owns both delivery and observation interest.""" @@ -469,26 +425,3 @@ def bucket_opened(self) -> None: def bucket_emptied(self) -> None: self.bucket_opened() - - -class CoreEventStream(PublicationStream): - """Core-specific publication stream with thread-scoped subscriptions.""" - - def __init__(self, publisher: object) -> None: - super().__init__(publisher) - self.thread_subscriptions: WeakValueDictionary[tuple[str, str], WeakSet[Subscription]] = WeakValueDictionary() - - def close_threads(self) -> None: - for bucket in tuple(self.thread_subscriptions.values()): - for subscription in tuple(bucket): - subscription.close() - - def observed_threads(self, root: str) -> frozenset[str]: - return frozenset(thread for (source, thread), bucket in self.thread_subscriptions.items() - if source == root and bucket) - - def publish(self, event: CoreEvent) -> None: # type: ignore[override] - subscriptions = tuple(event.subscribers(self)) - for subscription in subscriptions: - for listener in subscription.listeners(): - listener(event, subscription) diff --git a/src/toad/core/input_events.py b/src/toad/core/input_events.py index aa0e912f6a..0002608443 100644 --- a/src/toad/core/input_events.py +++ b/src/toad/core/input_events.py @@ -5,7 +5,7 @@ from agent_comms.messaging.message_files import FileUpload -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent from toad.goal_controls import GoalInteraction from toad.input_history import InputHistory, PromptInputHistory, ShellInputHistory diff --git a/src/toad/core/link_context_changed.py b/src/toad/core/link_context_changed.py new file mode 100644 index 0000000000..beb7e3ffcf --- /dev/null +++ b/src/toad/core/link_context_changed.py @@ -0,0 +1,76 @@ +from __future__ import annotations + +from dataclasses import dataclass +from weakref import WeakSet, WeakValueDictionary + +from agent_comms.nominal.declared_family import DeclaredFamily +from formbridge.publications import PublicationStream, Subscription + + +class CoreEvent(DeclaredFamily, affix="Event"): + """An application publication; its wire shape belongs to FieldCodec.""" + + def accepted_by(self, handler: object, message: Publication) -> bool: + """Whether a conversation comms handler accepts this publication.""" + return True + + def refreshes(self, screen: object) -> bool: + """Whether this publication is the given screen's to act on. + + A publication owns what it means for the views that receive it, so a screen asks this + question instead of classifying events by type. Every event is news to every screen + unless its member says otherwise. + """ + return True + + def subscribers(self, stream: CoreEventStream): + for event_type in type(self).__mro__: + yield from stream.subscriptions.get(event_type, ()) + + def replaces(self, queued: CoreEvent) -> bool: + """Only a CoalescingEvent replaces a queued publication.""" + return False + + def keyed_as(self, key: object) -> bool: + """Only a queued CoalescingEvent carries a coalescing key.""" + return False + + +@dataclass(frozen=True) +class LinkContextChanged(CoreEvent): + """The original project or reference observation changed; redraw from its owner.""" + + +class Publication: + """One delivered Core event and the subscription it arrived on. Each frontend's carrier + is one; who published it follows from the subscription's stream.""" + + event: CoreEvent + subscription: Subscription + + @property + def publisher(self) -> object: + return self.subscription.stream.publisher + + +class CoreEventStream(PublicationStream): + """Core-specific publication stream with thread-scoped subscriptions.""" + + def __init__(self, publisher: object) -> None: + super().__init__(publisher) + self.thread_subscriptions: WeakValueDictionary[tuple[str, str], WeakSet[Subscription]] = WeakValueDictionary() + + def close_threads(self) -> None: + for bucket in tuple(self.thread_subscriptions.values()): + for subscription in tuple(bucket): + subscription.close() + + def observed_threads(self, root: str) -> frozenset[str]: + return frozenset(thread for (source, thread), bucket in self.thread_subscriptions.items() + if source == root and bucket) + + def publish(self, event: CoreEvent) -> None: # type: ignore[override] + subscriptions = tuple(event.subscribers(self)) + for subscription in subscriptions: + for listener in subscription.listeners(): + listener(event, subscription) diff --git a/src/toad/core/preference_events.py b/src/toad/core/preference_events.py index edbdb959ec..61b7a66d2a 100644 --- a/src/toad/core/preference_events.py +++ b/src/toad/core/preference_events.py @@ -4,7 +4,7 @@ from formbridge.forms.declared_fields import DeclaredField -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent @dataclass(frozen=True) diff --git a/src/toad/core/session_requests.py b/src/toad/core/session_requests.py index 7b8289dcd8..d7003147e1 100644 --- a/src/toad/core/session_requests.py +++ b/src/toad/core/session_requests.py @@ -12,7 +12,7 @@ from agent_comms.projects.checkouts import Checkout from toad.constants import WELCOME -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent from toad.navigation_context import NavigationContext from toad.navigation_target import NavigationTarget diff --git a/src/toad/core/source_events.py b/src/toad/core/source_events.py index 296767bf9e..70f8df9026 100644 --- a/src/toad/core/source_events.py +++ b/src/toad/core/source_events.py @@ -4,7 +4,7 @@ import agent_comms.transcript.transcript_events as transcript_events -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent @dataclass(frozen=True) diff --git a/src/toad/core_event_carrier.py b/src/toad/core_event_carrier.py index 002594a628..34d0c22cb2 100644 --- a/src/toad/core_event_carrier.py +++ b/src/toad/core_event_carrier.py @@ -9,7 +9,7 @@ from toad.client.subscribers import CallbackSubscription, CoreObserverDispatch from formbridge.publications import Subscription -from toad.core.events import CoreEvent, CoreEventStream, Publication +from toad.core.link_context_changed import CoreEvent, CoreEventStream, Publication async def dispatch_publication(receiver, message) -> None: diff --git a/src/toad/cursor_movement.py b/src/toad/cursor_movement.py new file mode 100644 index 0000000000..f0da24c254 --- /dev/null +++ b/src/toad/cursor_movement.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from dataclasses import dataclass + +from textual.widgets.text_area import Selection + + +@dataclass(frozen=True) +class CursorMovement: + previous: Selection + current: Selection + + @property + def moved_cursor(self) -> bool: + return self.previous != self.current and self.current.is_empty + + @property + def entered_slash(self) -> bool: + return (self.previous.end, self.current.end) == ((0, 0), (0, 1)) + + @property + def retreating_first_line(self) -> bool: + if (self.previous.end[0], self.current.end[0]) != (0, 0): + return False + return self.current.end[1] < self.previous.end[1] diff --git a/src/toad/launch_binding.py b/src/toad/launch_binding.py index af8f618b1e..3c463096de 100644 --- a/src/toad/launch_binding.py +++ b/src/toad/launch_binding.py @@ -18,7 +18,7 @@ from toad.client.agents import read_agents from toad.client.db import DB from toad.core import session_requests -from toad.core.events import CoreEventStream +from toad.core.link_context_changed import CoreEventStream from toad.surface_binding import SurfaceBinding from toad.thread_identity import SessionIdentity from toad.transcript_scope import TranscriptScope diff --git a/src/toad/navigation_target.py b/src/toad/navigation_target.py index b920056cc8..acd5b916ea 100644 --- a/src/toad/navigation_target.py +++ b/src/toad/navigation_target.py @@ -21,7 +21,7 @@ DmConversation, IrcConversation, ) -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent from toad.navigation_context import ( NavigationContext, NavigationDestination, diff --git a/src/toad/preferences.py b/src/toad/preferences.py index 7f25348688..8fdb4af08f 100644 --- a/src/toad/preferences.py +++ b/src/toad/preferences.py @@ -28,7 +28,7 @@ from toad import atomic, paths from toad import setting_effects as effects from formbridge.forms.declared_fields import DeclaredField, FieldPath, FormPage, Multiline -from toad.core.events import CoreEventStream +from toad.core.link_context_changed import CoreEventStream from toad.core.preference_events import PreferenceChanged from toad.hint_labels import HintLabels, NextLetterHintLabels from toad.key_modes import KeyMode, Standard diff --git a/src/toad/project_path_owner.py b/src/toad/project_path_owner.py index 54b9d3ca5a..992fe2116b 100644 --- a/src/toad/project_path_owner.py +++ b/src/toad/project_path_owner.py @@ -7,6 +7,7 @@ from typing import TYPE_CHECKING from agent_comms.projects.checkouts import Checkout +from toad.core.link_context_changed import LinkContextChanged if TYPE_CHECKING: from textual.widget import Widget @@ -35,7 +36,6 @@ def link_context_events(self): return self.core_publications def link_context_changed(self): - from toad.core.events import LinkContextChanged self.publish_core(LinkContextChanged()) diff --git a/src/toad/prompt_cursor.py b/src/toad/prompt_cursor.py index 0b9d563a26..4980949490 100644 --- a/src/toad/prompt_cursor.py +++ b/src/toad/prompt_cursor.py @@ -2,7 +2,6 @@ from __future__ import annotations from abc import abstractmethod -from dataclasses import dataclass from types import FunctionType from typing import TYPE_CHECKING, ClassVar from weakref import ref @@ -14,6 +13,7 @@ from toad.client.line_blocks import Span from toad.core.input_events import HistoryMove +from toad.cursor_movement import CursorMovement from toad.slash_command import SlashCommand from toad.widgets.prompt_popup import CompletionPopup @@ -21,26 +21,6 @@ from toad.widgets.prompt import PromptTextArea -@dataclass(frozen=True) -class CursorMovement: - previous: Selection - current: Selection - - @property - def moved_cursor(self) -> bool: - return self.previous != self.current and self.current.is_empty - - @property - def entered_slash(self) -> bool: - return (self.previous.end, self.current.end) == ((0, 0), (0, 1)) - - @property - def retreating_first_line(self) -> bool: - if (self.previous.end[0], self.current.end[0]) != (0, 0): - return False - return self.current.end[1] < self.previous.end[1] - - class CommandText(DeclaredFamily, affix="Text"): """One decode joins actual text to its existing command declaration.""" diff --git a/src/toad/publication_work.py b/src/toad/publication_work.py new file mode 100644 index 0000000000..1c63fb2f2d --- /dev/null +++ b/src/toad/publication_work.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from agent_comms.coordination.errors import TranscriptChanged +from textual.worker import Worker + + +class PublicationWork: + """No publication is running: nothing to cancel or join, and a commit has nothing to settle.""" + + @property + def is_finished(self) -> bool: + return True + + def runs(self, worker: Worker) -> bool: + return False + + def cancel(self) -> None: + pass + + async def joined(self) -> None: + """Cancel this work and wait until it has stopped.""" + + async def settled(self) -> None: + """Wait for the commit this work publishes; with none running, the transcript moved on.""" + raise TranscriptChanged() diff --git a/src/toad/qt/agent_surface.py b/src/toad/qt/agent_surface.py index 1a6c950057..7431d44330 100644 --- a/src/toad/qt/agent_surface.py +++ b/src/toad/qt/agent_surface.py @@ -23,7 +23,7 @@ from toad.client.fragments import GrowsInPlace, Shown from toad.client.subscribers import CallbackSubscription from toad.commit_claims import CAPTURED_CLAIM, CapturedClaim, SnapshotPresentation -from toad.core.events import CoreEvent, CoreEventStream +from toad.core.link_context_changed import CoreEvent, CoreEventStream from toad.permission_presentation import ( DialogPermissionPresentation, DiffPermissionPresentation, diff --git a/src/toad/qt/core_events.py b/src/toad/qt/core_events.py index ede74ca68c..07166d0314 100644 --- a/src/toad/qt/core_events.py +++ b/src/toad/qt/core_events.py @@ -12,7 +12,7 @@ from toad.app_node import AppScoped from toad.client.connection import CoordinationAccess from toad.client.subscribers import CallbackSubscription, CoreObserverDispatch -from toad.core.events import CoreEvent, Publication +from toad.core.link_context_changed import CoreEvent, Publication @dataclass(frozen=True) diff --git a/src/toad/qt/history.py b/src/toad/qt/history.py index a395167358..26af640a5f 100644 --- a/src/toad/qt/history.py +++ b/src/toad/qt/history.py @@ -30,6 +30,7 @@ from PySide6.QtGui import QAbstractTextDocumentLayout, QColor, QDesktopServices, QFont, QFontMetrics, QFontMetricsF, QImage, QPainter, QPalette, QPen, QPixmap, QRegion, QScrollEvent, QTextDocument from PySide6.QtWidgets import QApplication, QPushButton, QScroller, QScrollerProperties, QWidget from pyqt_reactive.widgets.virtual_rows import HtmlRow, RowFormatting, RowPreparer +from toad.core.link_context_changed import CoreEventStream from toad.qt.virtual_scroll import ( FragmentRowList, NO_TAP_HIGHLIGHT, @@ -46,7 +47,6 @@ from toad.client.view_settings import SettingsReading from toad.qt.finger_press import FingerPress, Press from toad.client.fragments import BusMessageHistoryFragment, FragmentCollapse, HistoryFragment, Shown -from toad.core.events import CoreEventStream from toad.core.projection import MroProjection from toad.link_opening import TogglesFragmentShown from toad.navigation_target import NavigationTarget diff --git a/src/toad/render_processes.py b/src/toad/render_processes.py index db6d3d05ea..568791952d 100644 --- a/src/toad/render_processes.py +++ b/src/toad/render_processes.py @@ -20,6 +20,8 @@ from agent_comms.execution.helper_workers import HelperWorkers from agent_comms.execution.thread_launch import ThreadLaunch +from toad import render_tasks +from toad.acp import sdk_boundary from toad.render_backend import Renderer, RenderTask, capture_submitted from toad.work_preparation import PreparedValue @@ -38,10 +40,6 @@ def _initialize_worker() -> None: """ RENDER_WORKER_PROCESS.publish() ThreadLaunch.strip(os.environ) - from toad import render_tasks # noqa: F401 -- declare worker rendering capabilities - from toad.acp import ( - sdk_boundary, # noqa: F401 -- declare worker ingress capabilities - ) launch_root.started() diff --git a/src/toad/session_navigation.py b/src/toad/session_navigation.py index d71b4b7642..260c1ff9da 100644 --- a/src/toad/session_navigation.py +++ b/src/toad/session_navigation.py @@ -31,8 +31,8 @@ from toad.client.agents import AgentNotFound, read_agents from toad.core import events as core_events from toad.core import session_requests -from toad.core.events import CoreEventStream from toad.client.db import SessionMeta +from toad.core.link_context_changed import CoreEventStream from toad.launch_binding import ( AgentAttached, AgentBinding, diff --git a/src/toad/shell_source.py b/src/toad/shell_source.py index de705b30c9..ada5d31158 100644 --- a/src/toad/shell_source.py +++ b/src/toad/shell_source.py @@ -1,8 +1,8 @@ """Shared shell process ownership, independent of how commands start.""" from abc import ABC, abstractmethod import asyncio +from toad.core.link_context_changed import CoreEventStream from toad.surface_binding import SurfaceBinding, DetachedSurfaceBinding -from toad.core.events import CoreEventStream from toad.shell_output import ShellOutput, ShellTerminalOutput from toad.terminal_execution import TerminalOperation, NewTerminalOperation diff --git a/src/toad/transcript_publication.py b/src/toad/transcript_publication.py index 8b709fed12..77d1d4a547 100644 --- a/src/toad/transcript_publication.py +++ b/src/toad/transcript_publication.py @@ -51,21 +51,23 @@ from textual.await_complete import AwaitComplete from textual.worker import Worker, WorkerCancelled +from toad.client.block_claim import block_claim from toad.client.committed_presentation import ( - block_claim, commit_plan, covers_live_draft, retirement_candidates, ) from toad.client.history_coverage import NO_COVERAGE, HistoryCoverage from toad.commit_claims import CommitEvidence, NativeCommitEvidence -from toad.core.events import CoordinationObserved, CoreEventStream, ThreadRowsChanged +from toad.core.events import CoordinationObserved, ThreadRowsChanged +from toad.core.link_context_changed import CoreEventStream from toad.core.projection import MroProjection from toad.core.source_events import TranscriptCoverage as CoverageEvent from toad.history_jump import ReaderWindow from toad.live_output import LiveOutput from toad.client.resource_release import AsyncResourceRelease, ResourceRelease from toad.client.session_scope import SessionOrigin, SessionScope +from toad.publication_work import PublicationWork from toad.transcript_scope import NoTranscript, TranscriptScope from toad.entry_placement import ChronologicalEntry, EntryPlacement from toad.client.message_file_links import PageFiles @@ -363,27 +365,6 @@ def submit_to(self, requests: SourcePublicationRequests) -> None: UNCAPTURED = Uncaptured() -class PublicationWork: - """No publication is running: nothing to cancel or join, and a commit has nothing to settle.""" - - @property - def is_finished(self) -> bool: - return True - - def runs(self, worker: Worker) -> bool: - return False - - def cancel(self) -> None: - pass - - async def joined(self) -> None: - """Cancel this work and wait until it has stopped.""" - - async def settled(self) -> None: - """Wait for the commit this work publishes; with none running, the transcript moved on.""" - raise TranscriptChanged() - - NO_PUBLICATION_WORK = PublicationWork() diff --git a/src/toad/widgets/comms_chat.py b/src/toad/widgets/comms_chat.py index 0ba7d9c0a5..7eb4c3fd80 100644 --- a/src/toad/widgets/comms_chat.py +++ b/src/toad/widgets/comms_chat.py @@ -24,6 +24,7 @@ from toad.conversation_submission import AgentInputSubmission, ConversationSubmissions from toad.core import events as core_events from toad.client.referenced_core import ReferencedCore +from toad.core.link_context_changed import LinkContextChanged from toad.session_scope import SessionScope from toad.status_thread import StatusThread from toad.submission_queue import NoQueueSource, QueueSource @@ -150,8 +151,8 @@ async def _selected_source_changed(self, event: core_events.SessionSelected) -> self.refresh_identity() await self._refresh() - @handles(core_events.LinkContextChanged) - async def _command_source_changed(self, event: core_events.LinkContextChanged) -> None: + @handles(LinkContextChanged) + async def _command_source_changed(self, event: LinkContextChanged) -> None: """The sidebar's references changed: the label and commands follow them.""" await super()._command_source_changed(event) self.refresh_identity() diff --git a/src/toad/widgets/conversation.py b/src/toad/widgets/conversation.py index 53d4601b85..cc3d3a8024 100644 --- a/src/toad/widgets/conversation.py +++ b/src/toad/widgets/conversation.py @@ -43,6 +43,7 @@ from toad.client.view_binding_protocols import BoundViewHost from toad.client.session_sources import SourcedConversation from toad.client.thread_binding_dispatch import ThreadBindingDispatch +from toad.core.link_context_changed import LinkContextChanged from toad.flash_host import FlashHost from rich.console import Console from rich.segment import Segment @@ -1726,8 +1727,8 @@ async def update_slash_commands(self) -> None: def command_navigation(self): return self.query_ancestor(NavigationScope).navigation_owner.navigation_context - @handles(core_events.LinkContextChanged) - async def _command_source_changed(self, event: core_events.LinkContextChanged) -> None: + @handles(LinkContextChanged) + async def _command_source_changed(self, event: LinkContextChanged) -> None: self.on_composer("refresh_commands", lambda prompt: prompt.slash_complete.refresh_commands()) @handles(core_events.SessionSelected, core_events.OpenTabsChanged) diff --git a/src/toad/widgets/linked_rows.py b/src/toad/widgets/linked_rows.py index 274eaf62cc..db2a579d7b 100644 --- a/src/toad/widgets/linked_rows.py +++ b/src/toad/widgets/linked_rows.py @@ -25,8 +25,8 @@ from toad.app_node import FollowsTheme from toad.arrivals import AnimatesArrivals from toad.block_navigation import ConversationEntry -from toad.core.events import LinkContextChanged from toad.core.input_events import SelectHistoricalIdentity +from toad.core.link_context_changed import LinkContextChanged from toad.core_event_carrier import CoreEventReceiver from toad.frame_presentation import RowRun from toad.client.line_blocks import LineLink diff --git a/src/toad/widgets/message_divider.py b/src/toad/widgets/message_divider.py index 5b56dc5789..56b374cc8f 100644 --- a/src/toad/widgets/message_divider.py +++ b/src/toad/widgets/message_divider.py @@ -12,6 +12,7 @@ from textual.selection import Selection from textual.strip import Strip from textual.widget import Widget +from toad.client.block_claim import block_claim from ui_theme.effects import NEW_MESSAGE, Mix from toad.block_content import BlockContent @@ -26,7 +27,6 @@ StartsHidden, ) from toad.message_rows import LiveMessageClock, MessageClock, MessageRow -from toad.client.committed_presentation import block_claim from toad.commit_claims import CommitParticipant from toad.widgets.linked_rows import LinkedRows, MessageRowBlock from toad.widgets.transcript_lines import ( diff --git a/src/toad/widgets/message_row_owner.py b/src/toad/widgets/message_row_owner.py index d08e0a3937..5d0212fbce 100644 --- a/src/toad/widgets/message_row_owner.py +++ b/src/toad/widgets/message_row_owner.py @@ -2,15 +2,11 @@ from __future__ import annotations -from typing import TYPE_CHECKING from textual.widget import Widget from toad.client.line_blocks import Divider - -if TYPE_CHECKING: - from toad.widgets.message_divider import MessageDivider - +from toad.widgets.message_divider import MessageDivider class MessageRowOwner(Widget): """A complete live message, not a divider or another message-menu surface.""" diff --git a/src/toad/widgets/path_search.py b/src/toad/widgets/path_search.py index 69d05561a3..0aa6e8c503 100644 --- a/src/toad/widgets/path_search.py +++ b/src/toad/widgets/path_search.py @@ -17,6 +17,7 @@ from textual.app import ComposeResult from textual.navigation import MovesCursor +from toad.core.link_context_changed import LinkContextChanged from toad.widget_actions import ForwardsCursor, WidgetAction, PriorityActions, HiddenActions, Submits, DismissAction, SubmitAction, VisibleActions from textual import work from textual import getters @@ -43,7 +44,6 @@ from metaclass_registry.mro_dispatch import handles -from toad.core.events import LinkContextChanged from toad.core_event_carrier import CoreEventReceiver from toad.project_path_owner import ProjectPathOwner from toad.client.project_paths import ProjectPathSearch diff --git a/src/toad/widgets/prompt_popup.py b/src/toad/widgets/prompt_popup.py index e773002281..ade86ea7d0 100644 --- a/src/toad/widgets/prompt_popup.py +++ b/src/toad/widgets/prompt_popup.py @@ -15,6 +15,7 @@ from textual.widgets import Input from textual.widgets.option_list import OptionListComponent +from toad.cursor_movement import CursorMovement from toad.declared_widget import DeclaredWidget from toad.messages import Dismiss from toad.native_style import ( @@ -32,7 +33,6 @@ from toad.widgets.selection import SelectionOptionList if TYPE_CHECKING: - from toad.prompt_cursor import CursorMovement from toad.widgets.prompt import Prompt diff --git a/src/toad/widgets/session_tabs.py b/src/toad/widgets/session_tabs.py index 1edf679beb..c282dd3425 100644 --- a/src/toad/widgets/session_tabs.py +++ b/src/toad/widgets/session_tabs.py @@ -11,6 +11,7 @@ FILL, WidgetView, ) +from toad.core.link_context_changed import LinkContextChanged from toad.native_style import KeepsFocusOnClick from toad.widget_actions import ActivationKeys from toad.widgets.comms_menu import ActionMenu @@ -386,8 +387,8 @@ async def _sidebar_presented(self, event: core_events.SidebarPresented) -> None: if geometry_changed: self.call_after_refresh(self.show_selected_tab) - @handles(core_events.OpenTabsChanged, core_events.LinkContextChanged) - async def _tabs_changed(self, event: core_events.OpenTabsChanged | core_events.LinkContextChanged) -> None: + @handles(core_events.OpenTabsChanged, LinkContextChanged) + async def _tabs_changed(self, event: core_events.OpenTabsChanged | LinkContextChanged) -> None: """A thread tab is a thread row: it repaints when an open session's state changes too.""" if self.screen.is_active: await self._sync_tabs() diff --git a/src/toad/widgets/shell_result.py b/src/toad/widgets/shell_result.py index cf61f4cc7d..5fce13f9c5 100644 --- a/src/toad/widgets/shell_result.py +++ b/src/toad/widgets/shell_result.py @@ -7,12 +7,12 @@ from textual.css.styles import Styles from textual.highlight import highlight from textual.widgets import Static +from toad.client.block_claim import CommitBarrier from ui_theme.scheme import ForegroundColour, PrimaryColour from toad.native_style import PrimaryText, RightMargin from toad.widgets.non_selectable_label import NonSelectableLabel -from toad.client.committed_presentation import CommitBarrier from toad.shell_output import ShellCommandOutput diff --git a/src/toad/widgets/terminal_tool.py b/src/toad/widgets/terminal_tool.py index 450bcbc1c2..ccab0268ec 100644 --- a/src/toad/widgets/terminal_tool.py +++ b/src/toad/widgets/terminal_tool.py @@ -2,12 +2,13 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING, ClassVar +from typing import ClassVar from rich.style import Style from textual.content import Content from textual.css.native import ThemeState, DeclaresTheme, Keyword, NativeDeclaration, Percent, TextVariable, Variable from textual.css.styles import Styles from textual.message import Message +from toad.surface_binding import ViewSurfaceBinding from ui_theme.scheme import ErrorColour, PrimaryColour, SuccessColour, ThemeColour from metaclass_registry.mro_dispatch import MroDispatch, handles @@ -22,10 +23,6 @@ from textual import on from textual.events import Unmount -if TYPE_CHECKING: - from toad.agent_surface import AttachedSurfaceBinding - - class TerminalLook(DeclaresTheme): """The panel of a command that has not finished.""" @@ -75,7 +72,7 @@ class TerminalTool( class Projection(Message): """A native render request borrows its original acquired resources.""" - binding: AttachedSurfaceBinding + binding: ViewSurfaceBinding controller: TerminalController terminal_id: str execution: TerminalExecution diff --git a/tests/app/test_transcript_recipient.py b/tests/app/test_transcript_recipient.py index 96b23015db..0bcb33ca59 100644 --- a/tests/app/test_transcript_recipient.py +++ b/tests/app/test_transcript_recipient.py @@ -11,7 +11,7 @@ from support.coordination import carrying, coordination_fact from support.journals import assistant_entry, write_journal -from toad.acp.agent_controller import SessionBinding +from toad.acp.session_binding import SessionBinding async def test_unbound_tab_refuses_another_threads_snapshot(workspace): diff --git a/tests/guards/test_core_event_handlers_receive_their_event.py b/tests/guards/test_core_event_handlers_receive_their_event.py index 685f6e5194..ede133b725 100644 --- a/tests/guards/test_core_event_handlers_receive_their_event.py +++ b/tests/guards/test_core_event_handlers_receive_their_event.py @@ -9,7 +9,7 @@ from pathlib import Path import toad -from toad.core.events import CoreEvent, Publication +from toad.core.link_context_changed import CoreEvent, Publication from toad.core_event_carrier import CoreEventReceiver PACKAGE = Path(toad.__file__).parent diff --git a/tests/guards/test_shared_hook_sequences.py b/tests/guards/test_shared_hook_sequences.py index 3b5117fe7c..bbfdea6105 100644 --- a/tests/guards/test_shared_hook_sequences.py +++ b/tests/guards/test_shared_hook_sequences.py @@ -895,7 +895,8 @@ def test_qt_live_blocks_survive_page_range_changes_and_retire_only_by_commit_cov from toad.qt.live_turn import QtLiveBlock, QtResponseBlock, QtThoughtBlock, QtUserInputBlock from toad.qt.thread_view import QtThreadView from toad.transcript_publication import BoundView - from toad.client.committed_presentation import CommitTranscript, block_claim + from toad.client.block_claim import block_claim + from toad.client.committed_presentation import CommitTranscript from toad.client.history_state import LiveTranscript from toad.arrivals import AnimatesArrivals @@ -1008,7 +1009,8 @@ def test_conversation_comms_handlers_are_shared_across_frontends_and_filter_publ from agent_comms.execution.transcript_sources import UnreadTranscriptCursor from toad.conversation_comms_handlers import ConversationCommsHandlers - from toad.core.events import CommsUpdated, CoreEventStream + from toad.core.events import CommsUpdated + from toad.core.link_context_changed import CoreEventStream from toad.qt.agent_surface import subscribe_agent from toad.qt.conversation import QtConversation from toad.qt.core_events import QtCoreObserver, QtPublication diff --git a/tests/model/test_android_resync_lazy_load_catchup.py b/tests/model/test_android_resync_lazy_load_catchup.py index 38c20c467b..02e5109d40 100644 --- a/tests/model/test_android_resync_lazy_load_catchup.py +++ b/tests/model/test_android_resync_lazy_load_catchup.py @@ -80,7 +80,8 @@ ) from toad.client.prepared_pages import PreparedPageSource, SavedHistory from toad.client.resource_release import ResourceRelease -from toad.core.events import CoordinationObserved, CoreEventStream +from toad.core.events import CoordinationObserved +from toad.core.link_context_changed import CoreEventStream from toad.history_jump import FollowsTail from toad.transcript_publication import SourcePublicationRequests, TranscriptPublication diff --git a/tests/model/test_session_updates_after_binding_change.py b/tests/model/test_session_updates_after_binding_change.py index 76f87c8faa..975e2333db 100644 --- a/tests/model/test_session_updates_after_binding_change.py +++ b/tests/model/test_session_updates_after_binding_change.py @@ -13,7 +13,8 @@ ValidateSessionUpdateTask, ) from toad.client.connection import CoreConnection -from toad.core.events import CoreEvent, Update +from toad.core.events import Update +from toad.core.link_context_changed import CoreEvent from toad.render_processes import RenderProcessPool diff --git a/tests/support/agents.py b/tests/support/agents.py index 1104f30667..8642c59c23 100644 --- a/tests/support/agents.py +++ b/tests/support/agents.py @@ -11,7 +11,7 @@ from agent_comms.nominal.field_codec import AcpSessionId, FieldCodec, NoAcpSessionId from agent_comms.projects.checkouts import Checkout -from toad.core.events import CoreEvent +from toad.core.link_context_changed import CoreEvent from toad.launch_binding import NoAgent if TYPE_CHECKING: diff --git a/tests/textual/test_initial_session_title.py b/tests/textual/test_initial_session_title.py index a5674adc25..22317c938b 100644 --- a/tests/textual/test_initial_session_title.py +++ b/tests/textual/test_initial_session_title.py @@ -10,7 +10,8 @@ from support.agents import command from support.coordination import coordination_fact from toad.acp.agent import Agent -from toad.core.events import CoreEvent, SessionInfoUpdate +from toad.core.events import SessionInfoUpdate +from toad.core.link_context_changed import CoreEvent from toad.client.db import DB from agent_comms.nominal.field_codec import AcpSessionId, NoAcpSessionId diff --git a/tests/textual/test_live_output_streams.py b/tests/textual/test_live_output_streams.py index c5dad89818..5aef3cd04f 100644 --- a/tests/textual/test_live_output_streams.py +++ b/tests/textual/test_live_output_streams.py @@ -5,7 +5,8 @@ from toad.acp.comms_updates import CommsUpdateConsumer from toad.commit_claims import CapturedClaim -from toad.core.events import CoreEvent, Update +from toad.core.events import Update +from toad.core.link_context_changed import CoreEvent from toad.core_event_carrier import CoreEventMessage from toad.live_output import ( CompleteResponseStream, diff --git a/tests/textual/test_pooled_composer_neovim.py b/tests/textual/test_pooled_composer_neovim.py index d8bb8f9378..057ed2db54 100644 --- a/tests/textual/test_pooled_composer_neovim.py +++ b/tests/textual/test_pooled_composer_neovim.py @@ -22,7 +22,7 @@ from toad.client.bus_submission import BusSubmissions, SubmissionView from toad.client.composer_pool import ComposerPoolHost, WorkspaceComposerPool from toad.client.input_attention import InputAttention -from toad.core.events import CoreEventStream +from toad.core.link_context_changed import CoreEventStream from toad.key_modes import KeyMode, VimNormal from toad.neovim_editing import HostsNeovim, NeovimEditing from toad.project_path_owner import ProjectPathOwner