Skip to content

message: a chat message kind, tool rows and text that streams, in every renderer (#296) - #305

Merged
jirathip-k merged 9 commits into
stagingfrom
issue-296
Nov 21, 2026
Merged

jirathip-k merged 9 commits into
stagingfrom
issue-296

Conversation

@jirathip-k

@jirathip-k jirathip-k commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #296

For humans

Apps can now show a chat as blocks: who said each message, its text as it streams in with a blinking caret, the agent's tool calls (running, done or failed, with output that folds open) and attached files and images.
A reply that is still being written grows where it stands on the web page, the iPhone and Mac app and the desktop app, so a long answer no longer sends or redraws the whole message on every word.
A message can carry the time it was sent, shown quietly beside the speaker's name.
It looks the same in every renderer and on the static site, light and dark.

For apps: two new core kinds, message (Message::new(Role::Agent, "Scout").id(..).avatar(..).time("14:32").blocks(..).files(vec![Attachment { name, tap, src }])) and tool (Tool::new("Read", ToolState::Done).id(..).summary(..).body(..)), and prose gains an optional streaming. Prose::read(markdown) turns markdown into prose parts on the server. A new op, append, grows a prose block at its end; only diff (so Shelf::put) writes it, so an app keeps putting whole screens. A client built before this asks for the whole screen on each such frame: ship clients first, then stream. wire::old turns append into a merge of parts. In TS, apply moved from the shell's patch module to the core (@jirathip-dev/blocks exports it; the shell still re-exports it). SCHEMA_VERSION is unchanged (additive); the guard version goes to 3 for three new rules.

What changed (built to docs/architecture/message/ and docs/design/message/)

  • Crate: message, tool, Attachment, Role, ToolState; prose.streaming; Prose::read (kind/read.rs, prefix-stable, unknown markdown stays text); Prose::grow; Op::Append in wire, patch (message is a host of blocks), diff (text-only when only the last text grew, else keep + parts; other fields in a merge first) and wire::old. linkable moved from built into kind so the reader uses the one link rule.
  • Guard: new lint/stream-no-id, lint/summary-long, lint/tap-empty (each with a failing fixture); label-long, label-empty, empty-state widened to messages, tools and attachments (a test each).
  • HTML: render/kind/message.ts, tool.ts; the prose view's grow draws an append in place (earlier parts are the same nodes); the patcher hands append to it and skips one whose block a merge/replace already redrew in the same batch. apply moved to web/src/core/apply.ts (ADR decision 10) with the growth rule in core/kind/prose.ts; the ADR's structuredClone ban on patch.ts is in .drover/arch.toml (the two fetch( bans on patch.ts and render/** were merged to keep the file under its baseline).
  • React: kinds/message.ts, kinds/tool.ts, prose aria-busy; same markup as HTML (markup test, incl. the thread screen and a continuation pair).
  • Static page: site/kind/message.rs, tool.rs (a <details> inside the tool so it opens with no script), prose aria-busy.
  • SwiftUI: Kind/Message.swift, Kind/Tool.swift, the caret in the prose view, append in Apply.swift, tool open state kept by id in BlocksView.
  • egui: native draw/prose.rs (was TODO(#45)), draw/message.rs, draw/tool.rs.
  • A second message by the same speaker draws no head (the design's choice), in every renderer.
  • Amendment (2026-11-21, q2779): message.time, optional, drawn after the role word in the role word's muted face (<time class="mt"> in HTML, React and the static page; a muted meta Text in SwiftUI, also on a system line; a small muted label in egui, whose name truncation now leaves room for it). Omitted when unset; a repeat speaker's hidden head hides it too. The sample and fixtures carry 14:32; tests in crates/blocks/tests/site_message.rs and web/test/kind/prose.test.ts check drawn, omitted and the repeat case.
  • Showcase: both kinds on the site gallery with their Rust tabs; the egui demo and Swift draw them from the samples.
  • Docs: docs/schema/stream.md (the op), docs/schema/blocks.md (the kinds).
  • fixtures/append/*.json (the op's cases, read by Rust, TS and Swift), fixtures/append/thread.{screen,steps}.json (the script played by blocks-shot, blocks-snap and the desk harness), fixtures/read/*.json.

Decisions taken here:

  • A tool's state collides with a screen's root state map only when a tool is a fixture's root; codegen's tree writer now reads the root state only when it is an object.
  • The time goes after the role word (name, role, time), so the name keeps its place and the time reads as metadata; a system line shows it beside its name.
  • The role word under a name is the role itself (agent, owner, system), as drawn in the design; an unknown role reads agent.

src/ net +1504 (budget ~+1,300 in the ADR): two kinds in five renderers, the op in three languages, plus the reader and the amended time; just cap: 42815 / 43000.

Evidence (at 4d825b8)

The head adds one test-only commit after fedcb31: the pages test now expects 45 showcase pages. The rows below ran at fedcb31, plus the pages row at 4d825b8.

Command Exit
just fmt 0
just clippy 0
just test 0
just web (211 pass, 0 fail, incl. the new time test) 0
npm --prefix web run test:react (32 pass) 0
just swift (96 tests, 1 skipped as before) 0
just desktop 0
just arch / just cap (42815 / 43000) / just guard 0 / 0 / 0
(cd site && cargo test) 0
cargo run --locked -p blocks-site -- site then node --test test/pages/showcase.test.ts (pages.yml's step; 9 pass, 45 pages) at 4d825b8 0 / 0

Earlier at c84cf2b, before the time field: just check 0, just perf / just soak 0 / 0, the blocks-shot thread script at 390 and 1440 light and dark 0, blocks check --all --render with no findings on the samples.

Not verified here: the look against the design was compared by eye on the harness PNGs (HTML light/dark at 390 and 1440; SwiftUI and egui shots by their slices), not pixel-diffed; the time's look was not compared against a design image, since the design has none. Known gaps, all small: egui has no bold face and no image thumbnails (as the ADR says for egui); the SwiftUI running glyph does not spin.

…treams (#296)

The ADR for #296 in docs/architecture/message/: a message is who is speaking around ordinary blocks (a prose
block for text, a new tool kind per tool call, attachments as a field); one new op, append, grows a prose block
at its end and is written by diff. Measured on a long reply: the wire, the crate and the HTML drawing.
No product code.
…nd grown in place; apply moved to the core; showcase and docs (#296)
@jirathip-k
jirathip-k merged commit 3fe5208 into staging Nov 21, 2026
17 checks passed
@jirathip-k
jirathip-k deleted the issue-296 branch November 21, 2026 08:28
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