Skip to content

feat(web): add newest-first chat order - #327

Merged
Rinat S (rsolmano) merged 12 commits into
mainfrom
inverted-chat-display
Aug 30, 2026
Merged

feat(web): add newest-first chat order#327
Rinat S (rsolmano) merged 12 commits into
mainfrom
inverted-chat-display

Conversation

@danyaberezun

@danyaberezun danyaberezun commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an opt-in newest-first presentation for agent chats while keeping the existing oldest-first order as the compatibility default.

Newest-first keeps each request/answer exchange contiguous, reverses the temporal rows inside it, and leaves the message box at the bottom. It extends the smooth reading-band controller so latest-following, reader detachment, reduced motion, history jumps, touch momentum, keyboard return, and the upward Latest action remain coherent in either direction.

Changes

  • add Settings → Chat → Message order with Oldest first / Newest first choices
  • keep the preference client-local: host-qualified localStorage in browsers and a stable backend-profile/window adapter in desktop; it never enters AppConfig or synchronizes to other clients
  • strip retired host-side chatMessageOrder values from stale config rather than persisting or broadcasting them
  • project canonical chronological rows as 6,5,4 | 3,2,1 in newest-first mode without changing Pi transcripts or row identities
  • make initial positioning, streaming follow, manual-scroll detachment, touch/keyboard intent, and return-to-latest direction-aware
  • preserve detached history through projected prefix changes, dynamic stream-header height, and cumulative runway growth
  • preserve forward-readable content inside individual Markdown, tool, Activity, and review rows
  • add unit and browser coverage for ordering, persistence/isolation, latest-edge positioning, detached history, touch return, and interactive-keyboard behavior

Testing

  • bun run e2e — 305 passed across all 8 shards
  • bun run e2e -- e2e/chat-order.spec.ts — 2 passed
  • bun run test — all 14 workspace test tasks passed
  • bun run typecheck — all 14 workspace typecheck tasks passed
  • bun run check:deps — passed
  • bun run check:boundaries — passed
  • bun run check:seams — passed
  • bun run lint — passed (six pre-existing unused-suppression warnings)

Screenshots

Oldest first (default) Newest first
Oldest-first chat Newest-first chat

ThinkRail-Todo: 01a042c1-dc8d-7035-a256-21dec8a36c07/t_daf0f2326236
ThinkRail-Todo: 01a042c1-dc8d-7035-a256-21dec8a36c07/t_f5e3d7c06afb
ThinkRail-Todo: 01a042c1-dc8d-7035-a256-21dec8a36c07/t_f8352e3e142e
ThinkRail-Todo: 01a042c1-dc8d-7035-a256-21dec8a36c07/t_4ac0030afe08
ThinkRail-Todo: 01a042c1-dc8d-7035-a256-21dec8a36c07/t_15673164aba4

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

jetbrains-air[bot]
jetbrains-air Bot previously approved these changes Aug 27, 2026

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

# Conflicts:
#	apps/web/src/chat/SPEC.md
#	apps/web/src/chat/rows.ts
#	apps/web/src/store/SPEC.md
#	apps/web/src/store/appStore.ts
#	e2e/SPEC.md
#	packages/contracts/SPEC.md
#	packages/contracts/src/domain.ts
#	packages/server/src/persistence/SPEC.md
#	packages/server/src/settings/SPEC.md
#	packages/server/src/settings/settings.test.ts
ThinkRail-Todo: 01a05321-f558-705c-810e-7fd1e94bd5f1/t_4d7d16ec4ed6
ThinkRail-Todo: 01a05321-f558-705c-810e-7fd1e94bd5f1/t_4cdbc452875e
ThinkRail-Todo: 01a05321-f558-705c-810e-7fd1e94bd5f1/t_9609676d4bd2
ThinkRail-Todo: 01a05321-f558-705c-810e-7fd1e94bd5f1/t_d0d06ff6c361

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@rsolmano
Rinat S (rsolmano) merged commit e72dccd into main Aug 30, 2026
6 checks passed
@rsolmano
Rinat S (rsolmano) deleted the inverted-chat-display branch August 30, 2026 18:29
Iaroslav (Rick) Postovalov (CommanderTvis) added a commit to CommanderTvis/thinkrail that referenced this pull request Aug 31, 2026
The engine stops being pi-in-process and becomes any ACP agent the host
launches as a child and speaks JSON-RPC to over stdio. A fatal agent or
provider fault now kills one supervised child, not the host.

packages/acp — the ACP client, and the only client-side package allowed to
name an ACP type. connection/ spawns and negotiates (tolerating an agent
that writes a banner before its first message), client/ implements what we
offer agents (fs, terminals, permissions, elicitation, MCP over the ACP
channel), translate/ is the single seam where protocol shapes become
ThinkRail shapes, registry/ resolves the published agent registry, and
testing/ validates a committed frame corpus against the SDK's own schema
so an SDK bump fails here rather than in production.

packages/contracts — chatProtocol.ts replaces piProtocol.ts: ThinkRail's own
transcript model, a delta event union with three write modes, and a
ChatCapabilities record carrying one field per UI-visible affordance, so
panels read a negotiated record instead of probing the agent. The package
now imports nothing at all.

packages/pi-agent — the bundled first-party agent wrapping pi, launched as
`thinkrail acp-pi`. It is the only package permitted to import pi, and it
carries the four signals ACP has no words for (retry, compaction, queue,
steering) in a namespaced _meta.

packages/server — the host: an ACP session manager over its own append-only
transcript store, so history, search, jump-to-message and reopen work with
every agent rather than only those implementing ACP's optional session/load.
Credentials belong to the agent now; auth is the policy layer over the six
ACP credential operations plus the Central lifecycle the host must own.

apps/web — renders the ThinkRail transcript model, never an ACP shape, and
gates every control on the negotiated capability record.

scripts/check-architecture.ts makes the module boundaries a gate rather than
a convention: the ACP SDK stops at five sub-modules of packages/acp plus
packages/pi-agent, and pi stops at packages/pi-agent.

Rebased onto main. Carried through unchanged: the bottom workbench panel,
terminal reservations, Pino host logging, browser history navigation, the
subprocess budget, the Remix icon pack, the numeric spacing scale, the
gh-CLI Open PR module and the Cloudflare website.

Re-landed on the ACP wire, where the shapes differ:

- Mid-stream queue editing. The host owns the steering queue, so
  session.clearQueue and session.removeQueued need none of the
  drain-and-re-queue emulation pi's all-or-nothing clearQueue forced.
  queue_changed carries the queued texts beside the depths, and
  session.abort restores them; SessionQueueContent holds PromptContent so an
  image-bearing queue restores losslessly.
- The native /compact command moves to the agent side. ACP already carries a
  command list, so packages/pi-agent advertises compact and intercepts it in
  session/prompt — no session.compact wire method, and any agent that
  advertises its own compact command gets the same affordance for free.
- Plan review (reviewer + reflector sessions, the verdict gate, the auto-fix
  cycle) runs on AgentSessionManager: sessions are created through it and
  configured by config-option value, sends are synchronous so the rollback
  keys off a throw rather than an acceptance window, settlement is observed
  as turn_settled, and notices land as durable notice markers. The reviewer
  policy is agent-neutral on the wire — reviewModel/reviewEffort are opaque
  config-option values, not a pi Model.
- Extensions get a real theme (JetBrains#316): plainTextTheme moves into
  packages/pi-agent beside the bridge it serves, replacing an empty object
  cast, and an extension failure is named to the client before the session
  registers.

Rebased again onto the Electrobun desktop packaging (JetBrains#317). The desktop app
drives the same host, so `createServer` now answers `{ port, stop, shutdown }`
with the ACP teardown behind `shutdown()`, `bootHost` runs under upstream's
host-ownership lease, and `apps/cli` takes the shared build-support and
artifact-probe modules. `artifactProbes.ts` is ported to the ACP wire — the
model catalog is read from a session's config options, Central status from
`agent.providers`, the trash probe seeds a host transcript, and the retired
`provider.loginStart` OAuth leg becomes an `agent.authMethods` probe that the
CLI smoke runs beside its own `acp-pi` initialize legs. Upstream's
`check:boundaries` table learns the ACP layout (`packages/acp`,
`packages/pi-agent`, and the server/cli edges into them); it runs alongside
`check:arch`, which keeps policing the pi and ACP-SDK import invariants.

Rebased again onto the subagent layer (JetBrains#302/JetBrains#303/JetBrains#304), frontend-local
workbench layouts (JetBrains#338), newest-first chat order (JetBrains#327) and Try-again
recovery (JetBrains#345).

- pi-delegation and pi-subagents are pi packages, so the delegation host
  moves from packages/server into packages/pi-agent and scopes child
  sessions by an encoding of the worktree cwd — the agent has no workspace
  ids. The Agent card registers through the existing tool-renderer seam
  unchanged; the pi-only subagent-completion custom message drops, because
  under ACP the child's result already arrives on the Agent tool call.
- subagent.getTranscript becomes the first ThinkRail _ext round-trip: the
  host asks the agent over dev.thinkrail.v1/subagent/transcript and the
  agent answers with ChatMessages, so the child transcript reaches the UI
  without the host owning sessions it never created.
- Layouts leave the wire with upstream: layout.get/layout.replace, the
  layout module and the layout.changed channel are gone, and the workbench
  frame is the web's own state.
- The desktop's generated entry registers only the trash helpers now; the
  bundled pi runtime belongs to the agent process, which registers its own.
- Try-again attaches to an error notice, since notices replace the pi-era
  error turn.

Deliberately not carried: the reviewer model/effort pickers in Settings (ACP
has no session-less config read to source the options from — the auto-fix
toggle stays), and useTranscriptSync's revision fence (this transcript model
is one fold over one event log, so a reloaded transcript is the live object
graph by construction).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BFWLfHUiKpPbiAHxiD75BJ
Iaroslav (Rick) Postovalov (CommanderTvis) added a commit to CommanderTvis/thinkrail that referenced this pull request Aug 31, 2026
The engine stops being pi-in-process and becomes any ACP agent the host
launches as a child and speaks JSON-RPC to over stdio. A fatal agent or
provider fault now kills one supervised child, not the host.

packages/acp — the ACP client, and the only client-side package allowed to
name an ACP type. connection/ spawns and negotiates (tolerating an agent
that writes a banner before its first message), client/ implements what we
offer agents (fs, terminals, permissions, elicitation, MCP over the ACP
channel), translate/ is the single seam where protocol shapes become
ThinkRail shapes, registry/ resolves the published agent registry, and
testing/ validates a committed frame corpus against the SDK's own schema
so an SDK bump fails here rather than in production.

packages/contracts — chatProtocol.ts replaces piProtocol.ts: ThinkRail's own
transcript model, a delta event union with three write modes, and a
ChatCapabilities record carrying one field per UI-visible affordance, so
panels read a negotiated record instead of probing the agent. The package
now imports nothing at all.

packages/pi-agent — the bundled first-party agent wrapping pi, launched as
`thinkrail acp-pi`. It is the only package permitted to import pi, and it
carries the four signals ACP has no words for (retry, compaction, queue,
steering) in a namespaced _meta.

packages/server — the host: an ACP session manager over its own append-only
transcript store, so history, search, jump-to-message and reopen work with
every agent rather than only those implementing ACP's optional session/load.
Credentials belong to the agent now; auth is the policy layer over the six
ACP credential operations plus the Central lifecycle the host must own.

apps/web — renders the ThinkRail transcript model, never an ACP shape, and
gates every control on the negotiated capability record.

scripts/check-architecture.ts makes the module boundaries a gate rather than
a convention: the ACP SDK stops at five sub-modules of packages/acp plus
packages/pi-agent, and pi stops at packages/pi-agent.

Rebased onto main. Carried through unchanged: the bottom workbench panel,
terminal reservations, Pino host logging, browser history navigation, the
subprocess budget, the Remix icon pack, the numeric spacing scale, the
gh-CLI Open PR module and the Cloudflare website.

Re-landed on the ACP wire, where the shapes differ:

- Mid-stream queue editing. The host owns the steering queue, so
  session.clearQueue and session.removeQueued need none of the
  drain-and-re-queue emulation pi's all-or-nothing clearQueue forced.
  queue_changed carries the queued texts beside the depths, and
  session.abort restores them; SessionQueueContent holds PromptContent so an
  image-bearing queue restores losslessly.
- The native /compact command moves to the agent side. ACP already carries a
  command list, so packages/pi-agent advertises compact and intercepts it in
  session/prompt — no session.compact wire method, and any agent that
  advertises its own compact command gets the same affordance for free.
- Plan review (reviewer + reflector sessions, the verdict gate, the auto-fix
  cycle) runs on AgentSessionManager: sessions are created through it and
  configured by config-option value, sends are synchronous so the rollback
  keys off a throw rather than an acceptance window, settlement is observed
  as turn_settled, and notices land as durable notice markers. The reviewer
  policy is agent-neutral on the wire — reviewModel/reviewEffort are opaque
  config-option values, not a pi Model.
- Extensions get a real theme (JetBrains#316): plainTextTheme moves into
  packages/pi-agent beside the bridge it serves, replacing an empty object
  cast, and an extension failure is named to the client before the session
  registers.

Rebased again onto the Electrobun desktop packaging (JetBrains#317). The desktop app
drives the same host, so `createServer` now answers `{ port, stop, shutdown }`
with the ACP teardown behind `shutdown()`, `bootHost` runs under upstream's
host-ownership lease, and `apps/cli` takes the shared build-support and
artifact-probe modules. `artifactProbes.ts` is ported to the ACP wire — the
model catalog is read from a session's config options, Central status from
`agent.providers`, the trash probe seeds a host transcript, and the retired
`provider.loginStart` OAuth leg becomes an `agent.authMethods` probe that the
CLI smoke runs beside its own `acp-pi` initialize legs. Upstream's
`check:boundaries` table learns the ACP layout (`packages/acp`,
`packages/pi-agent`, and the server/cli edges into them); it runs alongside
`check:arch`, which keeps policing the pi and ACP-SDK import invariants.

Rebased again onto the subagent layer (JetBrains#302/JetBrains#303/JetBrains#304), frontend-local
workbench layouts (JetBrains#338), newest-first chat order (JetBrains#327) and Try-again
recovery (JetBrains#345).

- pi-delegation and pi-subagents are pi packages, so the delegation host
  moves from packages/server into packages/pi-agent and scopes child
  sessions by an encoding of the worktree cwd — the agent has no workspace
  ids. The Agent card registers through the existing tool-renderer seam
  unchanged; the pi-only subagent-completion custom message drops, because
  under ACP the child's result already arrives on the Agent tool call.
- subagent.getTranscript becomes the first ThinkRail _ext round-trip: the
  host asks the agent over dev.thinkrail.v1/subagent/transcript and the
  agent answers with ChatMessages, so the child transcript reaches the UI
  without the host owning sessions it never created.
- Layouts leave the wire with upstream: layout.get/layout.replace, the
  layout module and the layout.changed channel are gone, and the workbench
  frame is the web's own state.
- The desktop's generated entry registers only the trash helpers now; the
  bundled pi runtime belongs to the agent process, which registers its own.
- Try-again attaches to an error notice, since notices replace the pi-era
  error turn.

Rebased again onto the off-the-event-loop git reads (JetBrains#265). The review and
todo read paths are async now, so the host's review send, todo fix request
and review snapshot await them; the plan-fix flow keeps upstream's per-item
latch (claim on entry, release in a finally) around our synchronous ACP
send, and firstOpenWorkspace follows listWorkspaces into a promise.

Deliberately not carried: the reviewer model/effort pickers in Settings (ACP
has no session-less config read to source the options from — the auto-fix
toggle stays), and useTranscriptSync's revision fence (this transcript model
is one fold over one event log, so a reloaded transcript is the live object
graph by construction).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BFWLfHUiKpPbiAHxiD75BJ
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.

2 participants