Skip to content

Add shared structured context/thinking presentation and fix Qt ContextExplorer native reads - #2273

Merged
trissim merged 1 commit into
mainfrom
feat/structured-context-and-thinking
Nov 24, 2026
Merged

trissim merged 1 commit into
mainfrom
feat/structured-context-and-thinking

Conversation

@trissim

@trissim trissim commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Puts structured <think>, <ctx>, <tool_call>, Certainty: (DEDUCED/ASSUMED/UNKNOWN/REFUTED/OBSERVED + Basis + Confidence), and [[CTX_TURN]] / === SECTION === presentation at the top UI-backend layer (toad.client / toad.core) so Textual, Qt desktop, Android APK, and Web (toad serve) all inherit it from one owner with zero per-frontend forks.

Changes

  • src/toad/client/structured_context.py: Nominal StructuredPart family (ThinkingPart, ContextSectionPart, LiveContextPart, ToolCallPart, AnswerPart) and StructuredTag(DeclaredFamily, affix='Tag') (ThinkTag, CtxTag, ToolCallTag), linear-time parser handling both closed and streaming unclosed tags, plus compact 50-col mobile-friendly labels.
  • src/toad/client/agent_activity.py: AgentActivityPresentation.thinking() delegates to ThinkingPart.from_text().line_blocks() (live Textual AgentThought, live Qt QtThoughtBlock, and saved ThinkingTranscript).
  • src/toad/client/transcript_fragments.py & src/toad/message_rows.py: Split inline structured tags via parse_structured_text when present so neither transcripts nor bridged wire messages leak raw XML tags.
  • src/toad/core/context_inspection.py: Added StructuredSectionNode and PiMessageParts(MroProjection); NativeMessageNode and NativeSegmentNode / RecordedSegmentNode expand thinking, certainty claims, <ctx> sections, and tool calls as collapsible tree nodes while preserving public_text() search exclusion of private thinking.
  • src/toad/qt/context_panel.py: Fixed QtContextExplorer never calling prepare_native() (leaving live threads stuck on Reading native context… on Qt desktop & Android), wired shared holding.find() search, added lazy child expansion matching Textual's ContextTree._expand, and added compact Older/Newer/Refresh/Copy toolbar + word wrap.
  • Tests: Added tests/model/test_structured_context.py and updated tests/support/context_reads.py (DirectCoreAccess) + tests/support/overlapping_annotations.py (keyword-only ModelLabel) for Core core-03b277691.

Verification

  • Focused pytest: 27 passed in 7.33s (test_structured_context.py, test_context_inspection_source.py, test_context_reader_session_revision.py, test_fragment_source_occurrence.py, test_wire_message_lines.py, test_shared_frontend_members.py).
  • Live session smoke on real CLM-tristan (879 msgs -> 458 expanded nodes) and clm-live (4 msgs -> 4 certainty claims, 0 raw tag leaks).
  • Cold start: PRE-SPLASH 253 / POST-LOAD 1758 (comms=False, pkg=False).
  • Guards: qt_inherit_ratchet.py = 0, shadow_check.py = 0, guarded_imports.py = 0, rel_imports = 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant