The composer decides what a chat is, and the topbar stops trying

The mode select in the topbar posted with hx-post against a route that only
answers PATCH, so every change returned 405 and the mode never moved. htmx
shows nothing when a request fails, so the control looked like it worked: the
select stayed where you put it and the server ignored you. It has never worked.

Two more of the same kind. A mode could not be chosen at all until the chat
existed, so reaching Plan meant sending something in Manual first and letting
the model answer under the wrong rules. And the project directory box was real
and submitted, but unlabelled and squeezed to a few characters by the select
beside it, so it read as broken -- which is how it was reported.

So the kind, the connection, the directory and the mode move out of the strip
above the text and into one toolbar row beneath it, where attach and send
already are. The directory becomes a button that opens a browser over SFTP,
because a path is something you would rather find than spell. `scan_dir` is new
beside `list_dir`: a picker has to tell a directory from a file before it can
draw the row, and `list_dir` backs a tool whose contract is a list of names and
must not change under a model mid-conversation.

Browsing is a person clicking, not a model calling, so it does not pass through
policy.py -- the same argument the terminal panel rests on. It does mean Manual
mode has a second exception now.

Also: .chip was two components with one name, and the attachment card won, so
the Chat/Agent pills silently wore its padding. --radius-md was used twice and
declared nowhere, so both fell back to 0. .btn.is-active has been set by
syncToggles since the terminal landed and styled by nothing. Enter-to-send
ignored isComposing, so committing an IME candidate sent the message. The
terminal had five colours of a sixteen-colour palette, with fallbacks from a
palette that no longer exists.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-08-02 16:44:57 +02:00
parent cab8025346
commit a7e59a00f8
22 changed files with 1449 additions and 276 deletions
+176 -111
View File
@@ -13,6 +13,13 @@
file_ids input, and being inside the form is what gets them serialised with
the message. Keeping them outside and reaching for hx-include does not work:
that attribute only has an effect on the element issuing the request.
Layout: chips, then the text, then one toolbar row underneath carrying
everything that acts on the message. The kind selector and the connection
used to sit in a strip *above* the text, inside the same bordered card, where
they read as debris floating in the input rather than as controls. Below the
text they are in the same place as attach and send, which is where the hand
already is.
#}
<div class="composer" {% if can.get("files.upload") %}data-dropzone{% endif %}>
{% if can.get("files.upload") %}
@@ -54,128 +61,186 @@
<input type="hidden" name="temporary" value="true">
{% endif %}
{# Chat or Agent, chosen once. There is no switching afterwards: the
tools offered, the harness and the approval loop all differ, so a
conversation whose earlier turns ran somewhere else is not one
conversation. Only shown when picking Agent would lead anywhere. #}
{% if not chat and agent_profiles %}
<input type="hidden" name="kind" value="chat" id="chat-kind">
<div class="composer__kind" data-agent-picker>
<label class="chip">
<input type="radio" name="kind_choice" value="chat" checked>
<span>{{ icon("chat", "icon--sm") }} Chat</span>
</label>
<label class="chip">
<input type="radio" name="kind_choice" value="agent">
<span>{{ icon("server", "icon--sm") }} Agent</span>
</label>
<textarea class="composer__input" name="content" rows="1"
data-autosize data-max-height="320" data-composer-input
placeholder="{% if chat %}Send a message…{% else %}Ask anything…{% endif %}"
aria-label="Message" {{ 'autofocus' if not chat }}></textarea>
<span class="composer__kind-agent" hidden>
<select class="select select--sm" name="ssh_profile_id" aria-label="Connection">
{% for profile in agent_profiles %}
<option value="{{ profile.id }}" data-dir="{{ profile.default_dir }}"
{{ 'disabled' if not profile.verified }}>
{{ profile.name }}{{ ' — not checked' if not profile.verified }}
</option>
<div class="composer__toolbar">
<div class="composer__tools">
{% if can.get("files.upload") %}
{# A menu rather than the file picker straight away: there are four ways
to attach something now, and only one of them is a file on disk.
Uses the same picker machinery as the model chooser -- see ui.js. #}
<div class="picker picker--up" data-picker>
<button class="btn btn--icon composer__btn" type="button" data-picker-toggle
aria-haspopup="menu" aria-expanded="false"
aria-label="Attach" title="Attach">
{{ icon("attach") }}
</button>
<div class="picker__menu picker__menu--compact" data-picker-menu role="menu"
hidden aria-label="Attach">
<button class="picker__option" type="button" role="menuitem"
data-attach="file">
{{ icon("attach", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">File</span>
<span class="picker__option-note">PDF, text, code</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="image">
{{ icon("image", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Image</span>
<span class="picker__option-note">Sent only to vision models</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="link">
{{ icon("link", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Link</span>
<span class="picker__option-note">Fetch a page and attach its text</span>
</span>
</button>
{% if can.get("library.use") %}
<button class="picker__option" type="button" role="menuitem"
data-attach="knowledge">
{{ icon("archive", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Knowledge</span>
<span class="picker__option-note">From your library</span>
</span>
</button>
{% endif %}
</div>
</div>
{% endif %}
</div>
{#
What this conversation is and where it runs.
On a new chat all of it is editable. On an existing one the kind, the
connection and the directory are fixed -- update_chat refuses them
with a 409, because a transcript whose earlier turns ran somewhere
else is not one conversation -- so they render as a read-only chip and
only the mode stays live. The mode is the exception on purpose: it
decides what gets asked about, not what the conversation is.
#}
{% if not chat and agent_profiles %}
<div class="composer__context" data-agent-picker>
<input type="hidden" name="kind" value="chat" id="chat-kind">
<div class="segmented" role="group" aria-label="Kind of chat">
<label class="segmented__option">
<input type="radio" name="kind_choice" value="chat" checked>
<span>{{ icon("chat", "icon--sm") }} Chat</span>
</label>
<label class="segmented__option">
<input type="radio" name="kind_choice" value="agent">
<span>{{ icon("bolt", "icon--sm") }} Agent</span>
</label>
</div>
<span class="composer__agent" data-agent-extra hidden>
<select class="select select--sm" name="ssh_profile_id" aria-label="Connection">
{% for profile in agent_profiles %}
<option value="{{ profile.id }}" data-dir="{{ profile.default_dir }}"
{{ 'disabled' if not profile.verified }}>
{{ profile.name }}{{ ' — not checked' if not profile.verified }}
</option>
{% endfor %}
</select>
{# A button and a hidden field, not a text box. The text box was
real and submitted, but unlabelled and squeezed to a few
characters by the select beside it, so it read as broken. A path
is also something you would rather find than spell. #}
<input type="hidden" name="project_dir" value="" data-dir-value>
<button class="btn btn--sm composer__dir" type="button" data-dir-browse
aria-label="Project directory"
title="Choose the directory this chat works in">
{{ icon("folder", "icon--sm") }}
<span class="composer__dir-path" data-dir-label>/</span>
</button>
{% if agent_modes %}
<select class="select select--sm" name="agent_mode" aria-label="Approval mode">
{% for value, label, hint in agent_modes %}
<option value="{{ value }}" title="{{ hint }}">{{ label }}</option>
{% endfor %}
</select>
{% endif %}
</span>
</div>
{% elif chat and chat.kind == "agent" %}
<div class="composer__context">
<span class="composer__where" title="{{ chat.project_dir }}">
{{ icon("bolt", "icon--sm") }}
<span>{{ agent_profile.name if agent_profile else "connection missing" }}</span>
<span class="composer__where-dir">{{ chat.project_dir }}</span>
</span>
{# Its own form: nesting one inside the composer's form is invalid
HTML, and the browser drops the inner one. #}
<select class="select select--sm" name="agent_mode" aria-label="Approval mode"
form="agent-mode-form">
{% for value, label, hint in agent_modes %}
<option value="{{ value }}" title="{{ hint }}"
{{ 'selected' if value == chat.agent_mode }}>{{ label }}</option>
{% endfor %}
</select>
<input class="input input--sm input--mono" name="project_dir"
value="{{ agent_profiles[0].default_dir }}"
aria-label="Project directory" placeholder="/project">
</span>
</div>
{% endif %}
<div class="composer__row">
{% if can.get("files.upload") %}
{# A menu rather than the file picker straight away: there are four ways
to attach something now, and only one of them is a file on disk.
Uses the same picker machinery as the model chooser -- see ui.js. #}
<div class="picker picker--up" data-picker>
<button class="btn btn--icon composer__btn" type="button" data-picker-toggle
aria-haspopup="menu" aria-expanded="false"
aria-label="Attach" title="Attach">
{{ icon("attach") }}
</button>
<div class="picker__menu picker__menu--compact" data-picker-menu role="menu"
hidden aria-label="Attach">
<button class="picker__option" type="button" role="menuitem"
data-attach="file">
{{ icon("attach", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">File</span>
<span class="picker__option-note">PDF, text, code</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="image">
{{ icon("image", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Image</span>
<span class="picker__option-note">Sent only to vision models</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="link">
{{ icon("link", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Link</span>
<span class="picker__option-note">Fetch a page and attach its text</span>
</span>
</button>
{% if can.get("library.use") %}
<button class="picker__option" type="button" role="menuitem"
data-attach="knowledge">
{{ icon("archive", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Knowledge</span>
<span class="picker__option-note">From your library</span>
</span>
</button>
{% endif %}
</div>
</div>
{% endif %}
<textarea class="composer__input" name="content" rows="1"
data-autosize data-max-height="320" data-composer-input
placeholder="{% if chat %}Send a message…{% else %}Ask anything…{% endif %}"
aria-label="Message" {{ 'autofocus' if not chat }}></textarea>
<div class="composer__actions">
{% if can_dictate %}
{# Recording is started and stopped by the same button; audio.js swaps
data-mic-state and the icon with it. #}
<button class="btn btn--icon composer__btn composer__mic" type="button"
data-mic data-mic-state="idle"
aria-label="Dictate a message" title="Dictate a message">
<span class="composer__icon composer__icon--mic">{{ icon("mic") }}</span>
<span class="composer__icon composer__icon--recording" aria-hidden="true">
{{ icon("stop-circle") }}
</span>
</button>
{% endif %}
{% if can_dictate %}
{# Recording is started and stopped by the same button; audio.js swaps
data-mic-state and the icon with it. #}
<button class="btn btn--icon composer__btn composer__mic" type="button"
data-mic data-mic-state="idle"
aria-label="Dictate a message" title="Dictate a message">
<span class="composer__icon composer__icon--mic">{{ icon("mic") }}</span>
<span class="composer__icon composer__icon--recording" aria-hidden="true">
{{ icon("stop-circle") }}
</span>
</button>
{% endif %}
{#
One button, two jobs. While a reply is being written it becomes Stop,
because that is where the hand already is and a second button sitting
permanently beside Send is clutter that is wrong most of the time.
{#
One button, two jobs. While a reply is being written it becomes Stop,
because that is where the hand already is and a second button sitting
permanently beside Send is clutter that is wrong most of the time.
ui.js flips data-composer-action, and the type with it: as `submit`
the form's own handler sends, as `button` the click handler stops.
Both icons are rendered here and chosen in CSS, so the swap costs no
layout and cannot flash an empty button.
#}
<button class="btn btn--primary btn--icon composer__btn" type="submit"
data-composer-action="send" aria-label="Send">
<span class="composer__icon composer__icon--send">{{ icon("send") }}</span>
<span class="composer__icon composer__icon--stop" aria-hidden="true">
<span class="composer__stop-square"></span>
</span>
</button>
ui.js flips data-composer-action, and the type with it: as `submit`
the form's own handler sends, as `button` the click handler stops.
Both icons are rendered here and chosen in CSS, so the swap costs no
layout and cannot flash an empty button.
#}
<button class="btn btn--primary btn--icon composer__btn" type="submit"
data-composer-action="send" aria-label="Send">
<span class="composer__icon composer__icon--send">{{ icon("send") }}</span>
<span class="composer__icon composer__icon--stop" aria-hidden="true">
<span class="composer__stop-square"></span>
</span>
</button>
</div>
</div>
</form>
{# Outside the composer's form, and referenced by the mode select's `form`
attribute above. hx-patch and not hx-post: there is no POST for a chat,
only PATCH, and htmx shows nothing when a request 405s -- which is how
this control spent its whole life doing nothing. #}
{% if chat and chat.kind == "agent" %}
<form id="agent-mode-form" hx-patch="/api/chats/{{ chat.id }}" hx-swap="none"
hx-trigger="change"></form>
{% endif %}
<p class="composer__hint">
Enter to send, Shift+Enter for a new line.
{% if can.get("files.upload") %}