Skip to content

Attach files to bus messages: Android picker, desktop dialog or path search, TUI pickers, history chips - #2123

Closed
trissim wants to merge 19 commits into
mainfrom
fork-android-file-picker-2
Closed

trissim wants to merge 19 commits into
mainfrom
fork-android-file-picker-2

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown

What

A file picker for bus messages that works over remote connections. On the phone, Attach opens Android's own file picker. On the desktop it opens the file dialog or the project path search (setting ui.input.file_picker). In the TUI it opens a terminal file browser or the path search. History rows show each message's files as chips, and opening a chip fetches its bytes. Needs the agent-comms change (OpenHCSDev/agent-comms#4889) on the bus first.

Shape

  • One owner, both frontends. toad.client.message_files.MessagePromptComposer is the shared message composer the Qt and Textual message composers inherit. It holds the attached files and the attach action; the FilePicker setting family names the picker; file_picked attaches or refuses a file. Each frontend answers only pick_in_window, pick_by_path_search and show_attached. The agent (ACP) composer does not inherit it, so it never offers Attach.
  • Files ride the submission. UserInputSubmitted, InputSubmission and TypedText carry files, and BusSubmissionExecution hands them to comms_user_send. A send that does not land returns its whole draft. SubmissionView.delivery_refused and delivery_unknown now restore text and files once, replacing the two frontends' copied bodies; each frontend says only where a failure shows.
  • Android. QFileDialog with native dialogs on. Qt answers it with the Storage Access Framework, and the returned content:// URL is read through QFile, never more than one byte past what the message can still carry (read_limit). No Java hook was needed.
  • Path search. toad.client.project_paths.ProjectPathSearch is the listing and ranking without a toolkit. Textual's PathSearch and Qt's QtPathSearch both inherit it.
  • Chips. AttachedFileChip is the shared caption and take-off action that both frontends' chip widgets inherit.
  • History chips. toad.client.message_file_links makes one comms_message_files read per page (per conversation on the page, never per message). A row draws one linked Span per file under its text, so neither frontend has chip-drawing code. OpensLineLinks gains one handler: it fetches the bytes through the message, verifies the SHA-256, keeps the file under data/message-files/<sha[:16]>/<name>, and previews or opens it the way each frontend opens a project file. The module imports nothing of the composer: before it was split out, the transcript reader reached sidebar_panels through the composer, and a function-local import hid that cycle.
  • The attach key. AttachFileAction (ctrl+t) belongs to the MessageAction family, which only MessageTextArea binds. On Qt, action_methods is per composer class and only QtMessageComposer adds it.
  • Older bus. Toad needs the agent-comms change on the bus first: a bus without comms_message_files refuses the page's files read, and that refusal fails loudly with no fallback.

Evidence

All of the following ran on this head (854365a) against the agent-comms branch of OpenHCSDev/agent-comms#4889.

  • Desktop proof (Qt offscreen, a scratch bus served by agent-comms b0026f92b5). qt_drive.py attach writes a 300,029-byte file, picks it the way a person does (path typed into the QFileDialog, then Enter), shows its chip, types a body and sends it to scratch-live-pipeline. The recipient thread then lists and fetches the file through comms_message_files and comms_message_file:

    1-attached: page=QtMailboxView ... chips=['attached.bin · 293.0 KB  ✕'] sha256='56fc8286e3b96bcb4907f7d2185fd0a9ee57c9f6b4f6eb7420b10fb53e66d32c'
    2-sent: page=QtMailboxView ... chips=[] failure=''
    {"from": "user", "body": "a file from the Qt composer", "reference": "3-2fe151066061", "files": [["attached.bin", "application/octet-stream", 300029, "56fc8286…d32c"]], "fetched_sha256": "56fc8286e3b96bcb4907f7d2185fd0a9ee57c9f6b4f6eb7420b10fb53e66d32c", "fetched_bytes": 300029}
    picked sha256 56fc8286e3b96bcb4907f7d2185fd0a9ee57c9f6b4f6eb7420b10fb53e66d32c bytes 300029
    
  • TUI chip. tests/textual/test_message_file_attach.py::test_a_sent_file_draws_as_a_chip_under_its_message_in_the_terminal passes: a sent file draws as [shot.png · 2.0 KB] under its message.

  • tools/android/check.sh (scratch APP folder, a copy of the toadcomms profile, a runtime carrying agent-comms b80128bbd0, the final head). The shipped run now presses Attach in a channel and in a thread, requires exactly one file dialog, closes it unanswered, and requires no attached file:

    shipped app imports toad.qt.main; every application action has a summary
    function-local imports reaching an unshipped package or Textual UI: 15 (baseline 15)
    shipped app ran every view kind and bound key on a scratch bus
    
  • tools/qt_inherit_ratchet.py: exit 0.

    toad.qt modules importing toad.widgets/screens: 0 (ratchet baseline 0)
    bare Qt classes: 21 (ratchet baseline 21); Qt-only: 22
    parallel copies: 0 (ratchet baseline 0)
    
  • tools/shadow_check.py: empty methods shadowing real ones: 0 (baseline 0), exit 0.

  • Tests: 33 test files naming each changed declaration, run once against agent-comms 94c2fead44: 96 passed, 37 failed, 1 collection error, 3 skipped. The agent-comms commits after 94c2fead44 change its bridges, wake segments and typing, which toad does not import, and split the file-name check into two.

    • Every failure but one also fails on main at the merge base (11eb3b8), run in a separate worktree, with the same error (39 failed + 1 error there). Examples: LocalCoreAccess.__init__() missing 'reads', model_selection_available, HistoryWindow.jump_bar, test_prompt_enter_insert needing a live editor child, and the link_opening.py vs widgets/linked_rows.py guard.
    • Only on this branch: test_existing_thread_link.py::test_name_clicked_in_a_narrow_direct_chat_reuses_the_open_thread_tab. Rerun serially: pass. It is load-timed and does not touch files.
    • The new tests (tests/model/test_message_files.py, tests/model/test_message_file_reader.py, tests/textual/test_message_file_chips.py, tests/textual/test_message_file_attach.py) all pass.
  • NRA (python -m nominal_refactor_advisor src/toad --json --json-payload loop --no-cache: uncached and with no scan budget, so the scan runs to completion; this NRA version reports a scan_status only for a partial cached scan): 495 findings on this head and 495 on the merge base, with every detector's count equal. Two findings this branch had added were fixed:

    • the hidden_import_cycle through sidebar_panels (the message_file_links split above);
    • the 0-or-1 chip tuple (now one chip line per file).

    A string_kind_dispatch the full payload had listed in message_files.py went with the name check that moved into agent-comms' MessageFile.

Rollout

  1. Merge Messages carry files: upload with a send, read back through the message agent-comms#4889.
  2. Install the bus.
  3. Merge this PR.
  4. Build the APK.

A toad from this branch against an older bus fails the page-files read loudly.

Not covered here

  • Opening a fetched file on Android goes through Qt's own file provider (QDesktopServices.openUrl). The desktop path is tested. The phone path has not been run, because this change builds no APK.
  • A remote watch frame names no files (see the agent-comms PR). Agents on a local bridge or the native runtime are told about each file.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

trissim and others added 19 commits November 18, 2026 02:25
MessagePromptComposer, the shared message composer both frontends inherit, now
holds the files it will send with the text. Attach opens the picker that
ui.input.file_picker names (the file dialog, or the project path search); a
picked file becomes the FileUpload Core checks again. Each frontend answers only
its pickers and how attached files are drawn.

The files ride the submission: UserInputSubmitted, InputSubmission and TypedText
carry them, and the bus send hands them to comms_user_send. A send that does not
land returns its whole draft: SubmissionView restores text and files once,
replacing the two frontends' copied restore bodies, and each frontend says only
where a failure is shown.

ProjectPaths is the project's path listing and ranking without a toolkit, for
the path search pickers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… editor, two pickers

QtMessageComposer is the shared message composer with Qt's answers; the
channel, direct-message and mailbox composers inherit it, and the agent
composer does not, so its keys and buttons never offer Attach. Each composer
kind declares the actions it binds (action_methods) instead of one module list.

Attach opens QFileDialog, which on Android Qt answers with the system document
picker: its content:// URL is read through QFile, never more than one byte past
what the message can still carry. On a desktop the setting may choose the
project path search instead; QtPathSearch inherits ProjectPathSearch, the
listing and ranking the TUI's path search shares. A chip is a
QtAttachedFileChip over the shared AttachedFileChip.

The shipped run opens Attach on the channel and the thread and closes it
without picking; the attach scenario picks a file through the dialog and sends it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
Textual's Button renders its label reactive and Widget.remove leaves the DOM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
…h, and chips

Textual's MessagePrompt answers the shared composer's pickers. The file browser
opens at the project and can leave it (backspace goes up); the path search
ranks the project's paths. Either reads the chosen file through the shared
attach_path, bounded at read_limit, and Escape attaches nothing. Attached
files show as chips above the text (AttachedFileChip); pressing one takes
it off, and a send that does not land returns them.

ctrl+t (AttachFileAction) belongs to a MessageAction family that only
MessageTextArea declares, so an agent prompt binds no attach key.

PathSearch now inherits ProjectPathSearch: its scan, spelling and ranking
copies are deleted, so the @ completion and the pickers list one way.
Textual's Prompt answers show_failure where its conversation shows a send
failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… and opens it

A message's files are rows beside the bus, read once per page: WireSource.read for a
wire page and, for a thread transcript, the page's TranscriptPages source (the view's
TranscriptPresentation, through CoordinationTranscriptReader off the UI thread) before
the page goes to the render workers. Each read is one comms_message_files call per
conversation the page holds, never one per message.

MessageRow.file_reader derives whose read a message's files are, once: a channel message
in its channel, a direct message in the DM with the participant that is not the reader.
BusMessageRow names the row every transcript event draws, so the fragment consumer and
the file read share it.

MessageLines is the one parent of both message fragment bases: leading blocks, text, the
file chips (only the part carrying the status draws them), then what trails. It replaces
the two identical blocks() copies. A chip is a Span linked by MessageFileLink, so both
frontends draw it as the spans they already draw.

OpensLineLinks opens the link: it fetches the bytes through the view's coordination
access, refuses bytes whose SHA-256 differs from the listed one, keeps them under the
data folder by digest, and hands the path to the frontend's show_file (Textual previews
it as a project file; Qt opens it with the system's handler). A refusal or a lost
connection reaches warn_link.

SavedTranscript's loader is now a TranscriptPages source that answers a page and its
files; LoadedTranscriptPages wraps a load function with no file store (an attached
history). Test callers move to the render task's signature, which repairs five tests that
already failed on main for want of the fragment classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… Android

PySide's QUrl.toString takes no UrlFormattingOption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
…og, then Enter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… the composer

transcript_reader reached sidebar_panels through the composer half of
message_files (prompt_composer, settings, view settings), and sidebar_panels'
function-local import hid the cycle. message_file_links holds the links, page
files and chips; message_files keeps the composer.

One chip line per file, so a message's chips are its files, not a 0-or-1 tuple.
The name a kept file is saved under is MessageFile's own: the record refuses any
other as it decodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
@trissim

trissim commented Nov 18, 2026

Copy link
Copy Markdown
Author

Merged as part of #2130: this branch was rebased onto main and gated together with the other UI branches, since they edit the same lines.

@trissim trissim closed this Nov 18, 2026
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