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
30 changes: 27 additions & 3 deletions src/toad/arrivals.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def land(self) -> None:
if target is not None and owner.follows_tail:
with owner.layout_scroll():
target.land(owner)
owner.request_preparation()
owner.refresh_visible_notifications()
if self.keys:
owner.repaint_arrival_keys(self.keys)

Expand Down Expand Up @@ -264,8 +264,32 @@ def follow_end(self) -> None:
"""Place the window at its followed tail (toolkits with a specialized jump override)."""
self.scroll_y = self.tail_scroll_y

def request_preparation(self) -> None:
"""Prepare the viewport after an arrival scroll lands; paging windows override."""
histories: Iterable[object] = ()

def refresh_visible_notifications(self) -> None:
"""Refresh delivery/read receipts for histories now visible in this window without
re-arming source page reads (`history_pager.py` finish_source_work invariant)."""
for history in tuple(self.histories):
history.check_visible_notifications()

def toolkit_animated_travel(self) -> float:
"""Remaining distance of any toolkit-owned scroll animation or fling."""
return 0.0

@property
def animated_travel(self) -> float:
"""Remaining distance of a head reveal, else any toolkit-owned scroll travel."""
if (travel := self.head_reveal_travel()) is not None:
return travel
return self.toolkit_animated_travel()

def shift_toolkit_travel(self, rows: float, destination: float) -> None:
"""Shift any toolkit-owned scroll animation or fling by `rows` after layout moves."""

def shift_travel(self, rows: float, destination: float) -> None:
"""Keep a head reveal and any toolkit-owned scroll travel aimed at the same rows."""
self.shift_arrival_motion(rows)
self.shift_toolkit_travel(rows, destination)

# ---- Shared semantic operations ----

Expand Down
11 changes: 11 additions & 0 deletions src/toad/client/bus_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ def delivery_unknown(self, description: str, draft: SubmittedText) -> None:
self.submission_composer.restore(draft)
self.show_send_failure(self.unknown_notice(description))

def can_refresh_composer(self) -> bool:
"""Whether this view is attached and ready to draw compose access."""
return True

@abstractmethod
def apply_compose_access(self, composer, access: ComposeAccess) -> None:
"""Apply Core's compose access (read-only hold and file attachments) onto `composer`."""

async def refresh_composer(self, access: ComposeAccess) -> None:
"""Draw compose from the caller's Core answer: held or open, and whether it offers
files."""
if not self.can_refresh_composer():
return
self.composer_block = access.block_reason
self.on_composer("access", lambda composer: self.apply_compose_access(composer, access))

@abstractmethod
def draws_user_message(self, reference: MessageReference) -> bool: ...
Expand Down
11 changes: 11 additions & 0 deletions src/toad/client/composer_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,19 @@ def capture_composer_draft(self) -> ComposerDraft:
def reset_editor_draft(self, host: ComposerPoolHost, text: str) -> None:
"""Initialize this composer's editor for a fresh `host` with no captured state."""

def rebind_toolkit_conversation(self, host: ComposerPoolHost, draft: ComposerDraft) -> None:
"""Toolkit-specific state rebinding before queue and prompt refresh."""

def after_rebind_conversation(self) -> None:
"""Optional toolkit-specific post-rebind layout fit."""

def rebind_conversation(self, host: ComposerPoolHost, draft: ComposerDraft) -> None:
"""Rebind this existing composer widget to `host` and restore `draft`."""
self.kept_delivery_preview = None
self.rebind_toolkit_conversation(host, draft)
self.sync_queue()
self.update_prompt()
self.after_rebind_conversation()


class ComposerPoolHost:
Expand Down
3 changes: 3 additions & 0 deletions src/toad/client/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ def in_flow_collapse_link(self) -> FragmentCollapse | None:
"""Collapse link when this row itself draws the message's leading header divider."""
return None

def retain_painted(self, owner) -> None:
"""Non-message fragments carry no read-receipt evidence; `EvidencedFragment` overrides."""

@cached_property
def revision(self):
"""What makes the same fragment draw differently, derived once from its events as its
Expand Down
14 changes: 11 additions & 3 deletions src/toad/client/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from agent_comms.ui_model.observation import ReadNotifications
from metaclass_registry.mro_dispatch import handles

from toad.client.composer_pool import ComposerPoolHost
from toad.client.connection import CoordinationAccess, Observation
from toad.client.conversation import ConversationKind
from toad.client.resource_release import ResourceRelease
Expand All @@ -47,7 +48,7 @@
ConversationSource,
)

from toad.client.fragments import EvidencedFragment, FragmentKey, MessageShown
from toad.client.fragments import EvidencedFragment, FragmentKey, HistoryFragment, MessageShown
from toad.client.history_preparation import HistorySourceSnapshot, PageRequest
from toad.client.history_reads import NothingToRead, PaintedRead, ReadMarking, ReadWork
from toad.client.message_file_links import PageFiles
Expand Down Expand Up @@ -198,7 +199,7 @@ async def refresh_source(self) -> None:
"""Read the conversation again, as the view reads it now."""
await self.view._refresh()

def retain_painted(self, fragment: EvidencedFragment) -> None:
def retain_painted(self, fragment: HistoryFragment) -> None:
"""Keep actual painted evidence until its original page is acknowledged."""
fragment.retain_painted(self)

Expand Down Expand Up @@ -262,7 +263,7 @@ async def reload_notification_source(self) -> None:
await self.refresh_source()


class WireView(ConversationActivity):
class WireView(ConversationActivity, ComposerPoolHost):
"""A frontend's view of one wire conversation, as its page source, its sends and its
commands address it. A plain parent: each toolkit's widget metaclass would conflict
with ABCMeta.
Expand All @@ -274,6 +275,13 @@ class WireView(ConversationActivity):
conversation: ConversationKind
message_history: ReadMarkedHistory

@property
def composer_placeholder(self) -> str:
return self.conversation.initial_placeholder

def show_mention_candidates(self, mentions) -> None:
self.on_composer("mentions", lambda composer: composer.set_mention_candidates(mentions))

def begin_submission(self, owner, submission):
"""A channel or inbox message goes where this view's page source says."""
return self.message_history.page_source.begin_submission(self, owner, submission)
Expand Down
5 changes: 4 additions & 1 deletion src/toad/client/history_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ def check_follow(self, window: HistoryWindow) -> bool:
previous = window.scroll_y
with window.layout_scroll():
window.scroll_y = window.tail_scroll_y
return previous != window.scroll_y
moved = previous != window.scroll_y
if moved:
window.refresh_visible_notifications()
return moved

def finish_layout(self, answered: int) -> None:
"""No change waits on a layout."""
Expand Down
3 changes: 3 additions & 0 deletions src/toad/client/history_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def prepare_viewport(self) -> None:
super().prepare_viewport()
self.notification_view.check_notifications()

def check_visible_notifications(self) -> None:
self.notification_view.check_notifications_after_refresh()

@property
def notification_references(self):
return tuple(dict.fromkeys(reference for fragment in self.visible_fragments()
Expand Down
5 changes: 3 additions & 2 deletions src/toad/client/history_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ def layout_scroll(self):
if not restoring:
if rows := self.scroll_y - previous:
self.shift_travel(rows, destination)
if not self.gliding_to_end():
self.request_preparation()
self.lookahead.relocated(rows)
finally:
self._restoring = restoring
Expand Down Expand Up @@ -842,6 +840,9 @@ def prepare_viewport(self) -> None:
self.prepare_visible_pages()
self.state.check_edges(self)

def check_visible_notifications(self) -> None:
"""Refresh visible delivery/read receipts; histories carrying notifications override."""

def invalidate_projection(self) -> None:
self._generation += 1

Expand Down
34 changes: 33 additions & 1 deletion src/toad/client/model_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,39 @@ def select_model(self, model_id: str) -> None: ...
def connect_provider(self) -> None: ...

@abstractmethod
def filter_models(self, placement: HighlightPlacement) -> None: ...
def search_query(self) -> str: ...

@abstractmethod
def highlighted_model_id(self) -> str | None: ...

@abstractmethod
def present_filtered_models(
self,
ranked: list[RankedModel],
highlighted_index: int | None,
summary: str,
) -> None: ...

def filter_models(self, placement: HighlightPlacement) -> None:
previous_id = self.highlighted_model_id()
ranked, summary = self.rank_models(self.search_query())
highlighted = (
placement.index([entry.choice.value for entry in ranked], previous_id)
if ranked
else None
)
self.present_filtered_models(ranked, highlighted, summary)

def search_changed(self) -> None:
self.filter_models(ResetsHighlight())
self.refilter = KeepsHighlight()

def note_highlight_moved(self) -> None:
self.refilter = KeepsHighlight()

def submit(self) -> None:
if (model_id := self.highlighted_model_id()) is not None:
self.select_model(model_id)

async def recent_choices(self, scope: str) -> list[str]:
return await ModelConfigurationSetting().recent_choices(scope)
Expand Down
44 changes: 24 additions & 20 deletions src/toad/client/structured_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ def wire_blocks(self, row, body_type) -> tuple[LineBlock, ...]:
return self.line_blocks()


class RawTextPart(StructuredPart):
"""A structured part whose searchable text is its `raw_text` field."""

raw_text: str

@property
def text(self) -> str:
return self.raw_text


class BodyTextPart(StructuredPart):
"""A structured part whose searchable text is its `body_text` field."""

body_text: str

@property
def text(self) -> str:
return self.body_text


@dataclass(frozen=True)
class CertaintyClaim(StructuredPart):
"""One grounded or assumed epistemic claim from a `Certainty:` audit block."""
Expand Down Expand Up @@ -121,7 +141,7 @@ def line_blocks(self) -> tuple[LineBlock, ...]:


@dataclass(frozen=True)
class ThinkingPart(StructuredPart):
class ThinkingPart(RawTextPart):
"""Visible reasoning (`<think>` or Pi `ThinkingContent`), with parsed Certainty/Confidence."""

kind_title = "Thinking"
Expand All @@ -132,10 +152,6 @@ class ThinkingPart(StructuredPart):
confidence: str = ""
streaming: bool = False

@property
def text(self) -> str:
return self.raw_text

@classmethod
def from_text(cls, text: str, *, streaming: bool = False) -> ThinkingPart:
cleaned = text.strip()
Expand Down Expand Up @@ -202,7 +218,7 @@ def line_blocks(self) -> tuple[LineBlock, ...]:


@dataclass(frozen=True)
class ContextSectionPart(StructuredPart):
class ContextSectionPart(BodyTextPart):
"""One named section inside a compact `<ctx>` / `.live_ctx` document."""

kind_title = "Section"
Expand All @@ -211,10 +227,6 @@ class ContextSectionPart(StructuredPart):
heading: str
body_text: str

@property
def text(self) -> str:
return self.body_text

@property
def label(self) -> str:
preview = compact_preview(self.body_text, 48)
Expand All @@ -231,7 +243,7 @@ def line_blocks(self) -> tuple[LineBlock, ...]:


@dataclass(frozen=True)
class LiveContextPart(StructuredPart):
class LiveContextPart(RawTextPart):
"""A compact structured `<ctx>` or `.live_ctx` context block decomposed into sections."""

kind_title = "Context"
Expand All @@ -243,10 +255,6 @@ class LiveContextPart(StructuredPart):
sections: tuple[ContextSectionPart, ...] = ()
streaming: bool = False

@property
def text(self) -> str:
return self.raw_text

@classmethod
def from_text(cls, text: str, *, title: str = "Context", streaming: bool = False) -> LiveContextPart:
cleaned = text.strip()
Expand Down Expand Up @@ -369,18 +377,14 @@ def line_blocks(self) -> tuple[LineBlock, ...]:


@dataclass(frozen=True)
class AnswerPart(StructuredPart):
class AnswerPart(BodyTextPart):
"""Plain assistant answer text outside `<think>`, `<ctx>`, and `<tool_call>` blocks."""

kind_title = "Answer"
expands_in_tree = False

body_text: str

@property
def text(self) -> str:
return self.body_text

@property
def label(self) -> str:
preview = compact_preview(self.body_text, 56)
Expand Down
25 changes: 10 additions & 15 deletions src/toad/delivery_failure_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,17 @@ def release_pooled_composer(self, composer: Prompt) -> ComposerDraft:
composer.reparent(park)
return draft

async def refresh_composer(self, access: ComposeAccess) -> None:
"""Draw compose from the caller's Core answer."""
if not self.is_attached:
return
reason = access.block_reason
self.composer_block = reason

def apply(prompt: Prompt) -> None:
prompt.offer_files(access.takes_files)
area = prompt.prompt_text_area
area.disabled = bool(reason)
area.tooltip = reason or None
if not area.disabled and self.screen.focused is None:
self.screen.set_focus(area)
def can_refresh_composer(self) -> bool:
return self.is_attached

self.on_composer("access", apply)
def apply_compose_access(self, prompt: Prompt, access: ComposeAccess) -> None:
reason = access.block_reason
prompt.offer_files(access.takes_files)
area = prompt.prompt_text_area
area.disabled = bool(reason)
area.tooltip = reason or None
if not area.disabled and self.screen.focused is None:
self.screen.set_focus(area)

@property
def submission_composer(self):
Expand Down
7 changes: 3 additions & 4 deletions src/toad/qt/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,10 @@ def capture_composer_draft(self) -> ComposerDraft:
dismissed_text=self.dismissed_text,
)

def rebind_conversation(self, host: ComposerPoolHost, draft: ComposerDraft) -> None:
def rebind_toolkit_conversation(self, host: ComposerPoolHost, draft: ComposerDraft) -> None:
self.host = host
self.info_bar.configuration_scope = host
self.info_bar.status.configuration_scope = host
self.kept_delivery_preview = None
self._last_queue_state = None
self.given_placeholder = draft.placeholder or host.composer_placeholder
self.mention_candidates = draft.mention_candidates
Expand All @@ -849,9 +848,9 @@ def rebind_conversation(self, host: ComposerPoolHost, draft: ComposerDraft) -> N
self.failure.setText("")
self.failure.hide()
self.place_input_box()
self.update_prompt()

def after_rebind_conversation(self) -> None:
self.fit_height()
self.sync_queue()


Composer.action_methods = (
Expand Down
Loading
Loading