jChat

jChat is the chat window of Joshu on its desktop, and this page explains how it shows each step, stops a request, and talks to the Hermes gateway.

Updated

Purpose

jChat is the chat window of the companion on the Joshu desktop. It shows each step of the companion as a card while the companion works, and it lets the owner stop a request, edit a message, add files, open long answers in a side panel, answer questions with one click, and find old chats. The window talks to the Hermes gateway of the box through a relay in the Joshu server.

Motivation

The first jChat used the OpenAI-style chat endpoint of Hermes (/v1/chat/completions). That endpoint streams text and a short label for each tool call, but not the inputs or the result of the call, and it has no stop, edit, or question controls. Owners know richer AI chat apps, and the old window looked thin next to them.

Hermes v0.23 has a gateway socket (/api/ws, protocol hermes-gateway-v1) that Hermes Desktop and the Hermes Webapp use. It streams each tool call with its inputs and result, reasoning, questions with choices, and usage, and it has methods for stop, edit, rename, delete, and replay after a reconnect. jChat uses this socket.

Three constraints shaped the design:

  • The gateway socket accepts a connection only from the same machine and checks the Origin header, so a browser page cannot open it directly. Its credential must also stay on the box.
  • The socket has about 265 methods, and many of them change the box (terminal, config, plugins, vault). The browser must reach only what jChat needs.
  • Joshu adds context to each jChat turn (the time of the owner, the shared browser state, the setup mention), and the transcript must keep only the words of the owner.

Architecture

Architecture of jChat. The owner uses the jChat window in the desktop browser. The window opens a WebSocket to the jChat relay in the Joshu server, with the desktop session cookie. The relay gets a ticket from the Hermes control socket for each connection, opens the Hermes gateway socket, and adds the Joshu turn context to api_text. The relay keeps an index of jChat sessions and the uploaded files. Hermes keeps the chats in its SessionDB. The voice brain writes voice turns to the same sessions through the old stream route.

Source of the diagram: diagrams/jchat.json.

  • jChat window (apps/hermes-chat): React 18 with assistant-ui (external store runtime) for the thread, composer, edit, and copy, and Streamdown for markdown, code, math, and diagrams. The look comes from the box UI design language: Tailwind 4 on the tokens in packages/design-system/box-ui/, shadcn/ui parts in src/components/ui/, Lucide icons, and Inter and JetBrains Mono served from the box. src/theme.ts sets data-theme on the root element from the dark mode setting of the computer. The event store (chatStore.ts) turns relay events into ordered message parts: text, reasoning, steps, and questions.
  • jChat relay (src/jchat/): one browser WebSocket (/joshu/api/jchat/ws) gets one gateway connection. The browser sends a small set of operations, and the relay maps each to the gateway methods it needs. It also stages uploads (POST /joshu/api/jchat/uploads) and keeps the index of jChat sessions.
  • Gateway client (packages/hermes-gateway-client): MIT source copied from Hermes apps/shared at the pinned commit. The relay uses its JSON-RPC channel, which keeps request ids, timeouts, error mapping, event decoding, and the heartbeat.
  • Hermes gateway: the socket of the box, bound to loopback on a private port that only the control socket names.
  • jChat state (<joshu state>/jchat/): sessions.json (the index) and uploads/<id>/ (the files and the text of each PDF).

Theory of operation

A new chat:

  1. The owner opens jChat. The window opens the relay socket. The Joshu server checks the desktop session on the upgrade, resolves the gateway through the control socket in the Hermes home, gets a ticket, and opens the gateway socket from loopback with no Origin header. The relay sends relay.ready.
  2. The window asks for the chat list. The relay merges three lists: session.list scope live (a chat that Hermes has not stored yet is only there), session.list scope stored with hidden sessions, filtered to the ids in the index, and the legacy jChat chats from the Hermes SessionDB (hermes-chat-*, source api_server), which the socket does not list.
  3. The owner types a request. The relay creates a session (session.create, source gui, client joshu-jchat), adds its id to the index, and sends session.created to the window before any other event of the session. Then it sends prompt.submit with text (the words of the owner) and api_text (the Joshu context, then the file lines, then the words of the owner).
  4. Hermes streams events: message.start, message.delta, reasoning.delta, tool.start (with the inputs), tool.complete (with the result and the time), clarify.request, and message.complete. The relay forwards the events of the sessions that the window follows and drops the approval events. When desktop_open completes, the relay sends the queued desktop actions to the window.
  5. When the turn ends, the window reloads the chat from session.transcript. The saved rows give each owner message the row_id that edit needs. Saved tool rows have the inputs but not always the result, so the window keeps the results that it saw live.

Controls:

  • Stop sends session.interrupt with the current generation. Tool calls in flight finish, no new step starts, and the turn ends with status interrupted. Hermes saves a note for the model ("Operation interrupted …"), which the window shows as "Stopped."
  • Edit sends session.mutate with operation rewind on the row_id of the edited message, then a new prompt.submit. Everything after the edited message is gone.
  • A question arrives as event clarify.request with its choices. A click or a typed answer sends clarify.respond.
  • Files go to the upload route first. When the message is sent, each file is named in api_text with its path. A PDF also gets its text next to it (pdftotext), and an image is named with a hint to use the vision tool.
  • Reconnect: when the gateway socket drops, the relay dials again with a new ticket, resumes each followed session, and replays the missed events with session.events.since.
  • Goal notices: the result of an earlier request that the companion finished in the background arrives on the surface-event queue (/api/realtime-goals/surface-events, key joshu-hermes-chat:<session id>). Hermes does not save it in the session, so the window keeps it in the browser, confirms it to the box only after it is saved, and shows it again after a reload. The window passes each new notice once with the next message, and the relay names it in api_text, so the companion knows what the owner saw.
  • Voice in jChat still runs through the voice brain and the old stream route on the same session id. When a voice turn ends, the window reloads the chat.

Design decisions

2026-11-28. jChat uses the gateway socket through a relay in the Joshu server. Alternatives: the /v1/runs API of Hermes, which sends only a 500-character preview of each tool call and no questions; serving the Hermes Webapp, which is a workspace for power users with a terminal and a file tree and its own sign-in; and a direct browser connection, which the Origin check refuses and which would expose the credential. The relay keeps the credential and the desktop sign-in check on the box and gives the window the full event stream.

2026-11-28. The relay socket checks Origin, not Sec-Fetch-Site. The HTTP routes of the box check the desktop session with Host, Sec-Fetch-Site, and the ArozOS cookie. A browser does not reliably send Sec-Fetch-Site on a WebSocket handshake, so that check refused the relay socket of a signed-in owner. The socket check takes the box hostname as Host, an Origin of the same host (which a browser always sends, and which stops a cross-site WebSocket), and a cookie that ArozOS accepts.

2026-11-28. The browser sends operations, not gateway methods. The relay knows a short list of operations (list, open, create, send, stop, edit, clarify, rename, delete, transcript) and refuses any session that is not a jChat session. Forwarding methods with an allowlist was the first plan, but the socket also has shell.exec and other methods that change the box, and a list of operations is smaller and easier to review.

2026-11-28. The relay connects with the public control-socket contract of Hermes. resolve-profile names the socket URL and session-ticket mints a ticket that lasts 30 seconds and works once. The relay dials with a new ticket each time. A fixed token in the environment was the fallback, but it was not needed: the control socket accepts the Joshu server, which runs as the same user as the gateway.

2026-11-28. jChat keeps its own index of sessions. The socket creates sessions only with fixed policy sources (gui, cli, and others), and Hermes stores each socket session with source local, the same as other socket clients. A title prefix was rejected, because the owner can rename a chat. An id in the index older than a day leaves the index when Hermes no longer lists it (a session prune can delete it).

2026-11-28. The Joshu turn context goes in api_text. prompt.submit takes text, which Hermes saves and shows, and api_text, the text for the model. A pre_llm_call hook in a Joshu plugin would also work, but it needs a file handoff between two processes. A hidden submit would run a model turn of its own.

2026-11-28. Every file is named in api_text, with no native attachment. With a native attachment, Hermes saves the whole model text, with the context and the file lines, as the owner's message, so the chat would show it after a reload. Hermes itself turns a native image into a line with its path for the model, so naming the file gives the model the same input. The limits are 10 files and 25 MB per file.

2026-11-28. The window is built on assistant-ui and Streamdown, on React 18. Forking the Hermes Desktop renderer was rejected: its chat imports hundreds of files of Desktop state. assistant-ui primitives have no styles, so the window can give them any look. Both libraries support React 18, so the other desktop apps did not have to move to React 19. The first window used one plain stylesheet on the older tokens; the next decision replaced it.

2026-11-29. The window uses the box UI design language, with Tailwind 4 and shadcn/ui. jChat is the first box app on the newer tokens (packages/design-system/box-ui/tokens.css), because it shows most of the moments when the companion works. Tailwind 4 runs only in the Vite build of jChat (@tailwindcss/vite), and src/app.css imports Tailwind, the tokens, and the Tailwind theme that maps the tokens to utility classes and to the color names of shadcn/ui. Plain CSS on the new tokens was rejected, because shadcn/ui parts and Streamdown both expect Tailwind: Streamdown already renders markdown with shadcn/ui color names, so it takes the tokens with no extra code, and an @source line lets Tailwind see its classes. The rules in app.css that size the markdown sit outside the Tailwind layers, so they win over the classes of Streamdown.

The parts come from the shadcn/ui registry (MIT) and change on arrival: sizes on the tokens, no dark: classes (the tokens switch), no menu animation and no hover transition (menus and hovers change at once, as the UX principles ask), one focus ring for every control from a base rule, and forwardRef on Button and Input, because Radix needs the ref of a trigger button and React 18 does not pass a ref as a prop. A shared package of parts was rejected until a second app moves. The step card is a small card of one row, 32 pixels high, that follows the tool call rows of the Beautiful UI component Tool Chips (MIT); the Beautiful UI Prompt Bar was not used, because it needs a shader library and has controls that jChat doesn't have.

Light and dark mode: the tokens put the dark values under [data-theme="dark"], so src/theme.ts sets the attribute from the media query prefers-color-scheme and again when the setting changes. A copy of the dark values under a media query was rejected, because the values would live in two places, and the box desktop has no light or dark setting of its own to read.

Fonts: the Fontsource variable packages of Inter and JetBrains Mono are bundled, so the box serves the files and the browser downloads only the subsets that a page uses. Google Fonts was rejected because it sends the address of the owner to Google. The packages name the fonts "Inter Variable" and "JetBrains Mono Variable", so the font tokens list those names after the plain names.

Motion: only the spinner of a running step or turn and the words of a streamed answer move, with the duration tokens, which reduced motion sets to zero. The spinner is a loop, so the class motion-reduce:animate-none stops it.

The cost is about 110 kB more in the entry script before compression (about 33 kB after gzip), mostly the Radix menu with its positioning code and tailwind-merge, and about 30 kB more CSS. Google Fonts requests are gone.

2026-11-28. Long content opens in a side panel, found in the text. A finished code block of more than 40 lines, or an answer of more than 60 lines with headings, shows as a card and opens in the side panel when the answer ends. The gateway sends no artifact event, so the rule runs in the window, as Hermes Desktop does.

2026-11-28. Approvals are not in jChat yet. The relay drops approval events and cannot send an approval answer, so a request that needs the owner's approval for a command waits for the Hermes approval timeout and goes on without the command, as the old window did. Approvals in jChat belong to a later change on approvals and security.

2026-11-28. The old stream route stays for voice. The voice brain calls Hermes directly with the chat session id. Moving voice to the gateway socket would change the voice brain, so the window reloads the chat after each voice turn instead.

Limits and failure modes

  • A chat from before this jChat shows its messages, but its steps have no saved results.
  • Saved tool rows of new chats have inputs but not always results, so a step opened after a reload can say that the chat did not keep the result.
  • The list reads the stored sessions of every channel, newest first, and stops when it has found every chat of the jChat index (usually on the first page of 200). A jChat chat older than the newest 5,000 sessions of the box does not show in the list until the session prune of Hermes makes room.
  • Images in old messages show only in the window that sent them; after a reload, the message shows the file names.
  • Goal notices live in the browser that received them. Another browser does not show them, and after a reload they show at the end of the chat, not at the time they arrived.
  • The chat panels of jMail, jNotes, and jWhiteboard still use the AG-UI panel and its older look, so jChat and the app chats look different until those apps move to the box UI design language.
  • A request that needs an approval for a command waits up to the Hermes approval timeout (5 minutes by default).
  • If the gateway is down, the relay retries with a growing delay and the window shows "Reconnecting…". A request sent while the relay is down fails with a message, and the owner sends it again.
  • A Hermes upgrade can change the socket contract. The copied client has the pinned commit in its README; after an upgrade, copy it again and replay the recorded fixtures in test/fixtures/jchat-gateway/.

This page comes from docs/technical-reference/jchat.md in the open-source Joshu repo.