feat(web/claw): open every key, read-only when it has no stream
android / debug (push) Successful in 2m29s
ci / test (push) Successful in 42s
ci / docker (push) Successful in 2m0s
ci / web (push) Successful in 12s
android / release (push) Successful in 2m17s
ci / checks (push) Successful in 1m13s
ci / chart (push) Successful in 6s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 2m0s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 13s
ci / publish-edge-chart (push) Successful in 3s

Every row in the sidebar was disabled unless its key started with a
resident prefix, so a forge thread or a finished job could only be
paused or aborted, never read.

Now every row opens. A resident key subscribes as before. Any other key
loads the snapshot its history route serves, which carries `read_only`;
the header says `snapshot` instead of claiming a live stream, and the
composer becomes a line saying why there is none. The mirror is the same
one the stream feeds, so paging, outcomes, and the turn renderer come
for free.

That view has no stream to tell it a dispatch ran, so the inventory's
revision drives reloads: a poll that sees it move fetches the newest
page again, and nothing else does, so the pages a reader walked back to
survive polling.

`phone:` joins the client's resident prefixes, which the daemon already
carried: those rows were dead ends that refused the message the phone
client sends every day.

The user label follows the key: a chat or phone key's rows are the
human's, any other key's are the prompt its dispatch started with.
This commit is contained in:
vhaudiquet committed 2026-11-24 20:58:02 +01:00
1 parent 8d7dc7c4c7
commit 1a1ace014a
5 files changed
+153 -49

No files matched your search

+12 -4
View File
@@ -130,11 +130,19 @@ Two consequences worth knowing before changing this code:
(`[A-Za-z0-9._-]{1,64}`), switches the chat to the new key, and (`[A-Za-z0-9._-]{1,64}`), switches the chat to the new key, and
lets 400/409 land in the error banner. The interactive prefixes lets 400/409 land in the error banner. The interactive prefixes
(`interactive:`) list above the fold; *others* holds the whole rest (`interactive:`) list above the fold; *others* holds the whole rest
of the inventory — `task:`, `calendar:`, the phone's status keys of the inventory — `task:`, `calendar:`, the phone's keys
(`phone:…`), the coding jobs' `job:<instance>#<id>` keys and forge (`phone:…`), the coding jobs' `job:<instance>#<id>` keys and forge
keys. Only the resident prefixes have a transcript, so a row in keys.
*others* for anything else is a control row: no click-through, but - **Every row opens, and some open read-only.** A resident key
the same pause/resume/abort and delete as every other row. (`interactive:`, `task:`, `phone:`, `calendar:`) has a live stream,
and the chat resets its mirror whenever that stream reopens. A key
outside them has none: its dispatch runs outside the hub. The panel
fetches `GET /v1/sessions/{key}/history` instead, which serves the
session the engine checkpointed, and shows the turns with a
`snapshot` status and the composer replaced by a line saying why.
The inventory's `revision` is that view's only reload signal: a poll
that sees it move fetches the newest page again, so an older page
the reader walked back to survives polling until a turn runs.
- **Deleting a session is a decision, not a click.** The row's delete - **Deleting a session is a decision, not a click.** The row's delete
button only names the key; the shell's dialog spells out that the button only names the key; the shell's dialog spells out that the
turn history goes with it, and `DELETE /v1/sessions/{key}` runs on turn history goes with it, and `DELETE /v1/sessions/{key}` runs on
+57
View File
@@ -310,6 +310,13 @@ async function refreshSessions(): Promise<void> {
try { try {
sessions.value = await claw.sessions() sessions.value = await claw.sessions()
apiError.value = null apiError.value = null
// A read-only thread has no stream to tell it a dispatch ran; the
// inventory's revision does. Reload the snapshot when it moved, and
// only then — a reload drops the pages the reader walked back to.
if (activeKey.value !== '' && !isResidentKey(activeKey.value) && !threadLoading) {
const revision = sessions.value.find((s) => s.key === activeKey.value)?.revision ?? null
if (revision !== threadRevision) void loadThread()
}
} catch (err) { } catch (err) {
noteApiError(err) noteApiError(err)
} finally { } finally {
@@ -672,6 +679,16 @@ function saveToken(): void {
// --- the one live subscription --------------------------------------- // --- the one live subscription ---------------------------------------
let stream: { close: () => void } | null = null let stream: { close: () => void } | null = null
/** The revision the read-only thread on screen was loaded at; a poll
* that sees a newer one reloads it, since no stream will. */
let threadRevision: number | null = null
/** A load is in flight: a poll landing mid-load must not start a second
* one and append the same page twice. */
let threadLoading = false
/** Whether the key on screen answers a snapshot. The key's prefix says
* so before the fetch lands; the page's own `read_only` has the last
* word. */
const threadReadOnly = ref(false)
function resubscribe(): void { function resubscribe(): void {
stream?.close() stream?.close()
@@ -681,9 +698,19 @@ function resubscribe(): void {
attemptedAttachments.clear() attemptedAttachments.clear()
notices.value = [] notices.value = []
streamStatus.value = 'connecting' streamStatus.value = 'connecting'
threadRevision = null
threadReadOnly.value = activeKey.value !== '' && !isResidentKey(activeKey.value)
// Deleting the last session clears the key, and an empty key is not a // Deleting the last session clears the key, and an empty key is not a
// stream: subscribing to one would retry a 404 forever. // stream: subscribing to one would retry a 404 forever.
if (activeKey.value === '') return if (activeKey.value === '') return
// A key outside the resident context has no turn record: its handler
// never streams, and the events route answers 400. What the daemon
// does hold is the session stash, which the history route serves as a
// read-only snapshot. The panel shows it with the composer closed.
if (!isResidentKey(activeKey.value)) {
void loadThread()
return
}
stream = claw.subscribeEvents(activeKey.value, { stream = claw.subscribeEvents(activeKey.value, {
onEvent: (event, seq) => transcript.applyEvent(event, seq), onEvent: (event, seq) => transcript.applyEvent(event, seq),
// The record lost what this mirror holds (a wiped or reset // The record lost what this mirror holds (a wiped or reset
@@ -710,6 +737,35 @@ function resubscribe(): void {
}) })
} }
/** Loads the newest page of a read-only thread: a snapshot of the
* engine's own history, rendered by the same mirror the stream feeds.
* Pagination is the walk back, unchanged — a page lands, the scroller
* asks for the next one. */
async function loadThread(): Promise<void> {
const key = activeKey.value
threadLoading = true
streamStatus.value = 'open'
// A reload (a finished dispatch moved the revision) rebuilds from the
// newest page: the mirror holds the previous snapshot, and stacking
// the new one under it would duplicate every turn.
transcript.reset()
olderAvailable.value = true
attemptedAttachments.clear()
try {
const page = await claw.history(key)
if (key !== activeKey.value) return
for (const { seq, event } of page.events) transcript.applyEvent(event, seq)
olderAvailable.value = page.more
threadReadOnly.value = page.readOnly
threadRevision = sessions.value.find((session) => session.key === key)?.revision ?? null
apiError.value = null
} catch (err) {
noteApiError(err)
} finally {
threadLoading = false
}
}
/** Fetches one page of turns older than the mirror's first and stacks /** Fetches one page of turns older than the mirror's first and stacks
* it above. Whole turns only, so the page never duplicates or skips: * it above. Whole turns only, so the page never duplicates or skips:
* the daemon ends it exactly where the mirror begins. */ * the daemon ends it exactly where the mirror begins. */
@@ -822,6 +878,7 @@ onUnmounted(() => {
:live="liveTurn" :live="liveTurn"
:active-key="activeKey" :active-key="activeKey"
:can-send="isInteractive(activeKey)" :can-send="isInteractive(activeKey)"
:read-only="threadReadOnly"
:busy="busy" :busy="busy"
:session="activeSession" :session="activeSession"
:active-backend="providersState?.active ?? null" :active-backend="providersState?.active ?? null"
+43 -12
View File
@@ -26,6 +26,8 @@ const props = defineProps<{
activeKey: string activeKey: string
/** Only `interactive:*` keys accept messages (the claw 400s the rest). */ /** Only `interactive:*` keys accept messages (the claw 400s the rest). */
canSend: boolean canSend: boolean
/** The daemon answers this key with a snapshot, not a stream. */
readOnly: boolean
busy: boolean busy: boolean
session: ClawSession | null session: ClawSession | null
activeBackend: { provider: string; model: string } | null activeBackend: { provider: string; model: string } | null
@@ -43,6 +45,27 @@ const props = defineProps<{
const agentName = computed(() => props.identity?.name?.trim() || 'rhema') const agentName = computed(() => props.identity?.name?.trim() || 'rhema')
/** Why the composer is closed. A resident key that is not `interactive:`
* runs on its own trigger; anything else is a snapshot of a stash the
* engine checkpointed, whose answer went out through its dispatch. */
const readOnlyNote = computed(() =>
!props.readOnly
? 'Only interactive: keys take messages. This key runs on its own trigger and the transcript is read-only.'
: 'Read-only snapshot of the turns this key ran. The dispatch takes its input and posts its answer outside the chat.',
)
/** Whose words a user row holds. A chat key's are the human's, on the
* web surface or on the phone; every other key's are the prompt its
* dispatch was started with. */
const userLabel = computed(() =>
/^(interactive|phone):/.test(props.activeKey) ? 'you' : 'dispatch',
)
/** Whether the key has a stream at all. A snapshot answers a page once
* and follows nothing, so the header says so instead of claiming to be
* live. */
const streaming = computed(() => !props.readOnly)
/** One send as the panel hands it up: the text (pastes embedded) and /** One send as the panel hands it up: the text (pastes embedded) and
* the staged images, previews included for the optimistic row. */ * the staged images, previews included for the optimistic row. */
interface SendPayload { interface SendPayload {
@@ -428,10 +451,13 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
<div class="text"> <div class="text">
<h2>{{ displayName }}</h2> <h2>{{ displayName }}</h2>
</div> </div>
<span class="stream-status" :title="`event stream: ${streamStatus}`"> <span v-if="streaming" class="stream-status" :title="`event stream: ${streamStatus}`">
<StatusDot :tone="streamTone(streamStatus)" /> <StatusDot :tone="streamTone(streamStatus)" />
{{ streamLabel }} {{ streamLabel }}
</span> </span>
<span v-else class="stream-status" title="a snapshot of the stored session; no stream follows this key">
snapshot
</span>
<button class="ghost info" title="session info" @click="infoOpen = true">ⓘ</button> <button class="ghost info" title="session info" @click="infoOpen = true">ⓘ</button>
</header> </header>
@@ -446,7 +472,9 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
<div ref="scroller" class="stream-area" @scroll.passive="onScroll"> <div ref="scroller" class="stream-area" @scroll.passive="onScroll">
<p v-if="items.length === 0 && !live" class="empty"> <p v-if="items.length === 0 && !live" class="empty">
nothing streamed yet; messages post to the claw and replies arrive here live {{ streaming
? 'nothing streamed yet; messages post to the claw and replies arrive here live'
: 'nothing recorded for this key yet' }}
</p> </p>
<p v-if="loadingOlder" class="older-hint">loading earlier turns</p> <p v-if="loadingOlder" class="older-hint">loading earlier turns</p>
@@ -455,7 +483,7 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
<div v-if="item.kind === 'sent'" class="msg"> <div v-if="item.kind === 'sent'" class="msg">
<div class="avatar user" aria-hidden="true">·</div> <div class="avatar user" aria-hidden="true">·</div>
<div class="msg-body"> <div class="msg-body">
<div class="who">you</div> <div class="who">{{ userLabel }}</div>
<div v-if="item.images.length > 0" class="sent-images"> <div v-if="item.images.length > 0" class="sent-images">
<button <button
v-for="(image, index) in item.images" v-for="(image, index) in item.images"
@@ -563,8 +591,9 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
{{ imageError }} {{ imageError }}
<button class="chip-x" title="dismiss" @click="imageError = null">×</button> <button class="chip-x" title="dismiss" @click="imageError = null">×</button>
</p> </p>
<div class="input-row"> <p v-if="!canSend" class="read-only">{{ readOnlyNote }}</p>
<button class="ghost attach" title="attach images" :disabled="!canSend" @click="pickImages"> <div v-else class="input-row">
<button class="ghost attach" title="attach images" @click="pickImages">
+ +
</button> </button>
<textarea <textarea
@@ -572,20 +601,15 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
v-model="draft" v-model="draft"
rows="1" rows="1"
:placeholder=" :placeholder="
canSend live ? `Message ${agentName}… sending steers the running turn` : `Message ${agentName}…`
? live
? `Message ${agentName}… sending steers the running turn`
: `Message ${agentName}…`
: 'only interactive:* sessions accept messages'
" "
:disabled="!canSend"
@keydown="onPromptKeydown" @keydown="onPromptKeydown"
@paste="onPaste" @paste="onPaste"
@input="resizePrompt" @input="resizePrompt"
/> />
<button <button
class="primary send" class="primary send"
:disabled="!canSend || busy || draft.trim() === ''" :disabled="busy || draft.trim() === ''"
:title="live ? 'send — interrupts the running turn' : 'send'" :title="live ? 'send — interrupts the running turn' : 'send'"
@click="submit" @click="submit"
> >
@@ -988,6 +1012,13 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
gap: 8px; gap: 8px;
} }
.read-only {
margin: 0;
padding: 2px 0;
color: var(--text3);
font-size: 12.5px;
}
.attach { .attach {
width: 38px; width: 38px;
padding: 0; padding: 0;
+24 -25
View File
@@ -10,11 +10,11 @@
// //
// The non-interactive keys fold under *others*: folded (the default), // The non-interactive keys fold under *others*: folded (the default),
// the group shows only how many of them hold a lease, plus the // the group shows only how many of them hold a lease, plus the
// more/less toggle; unfolded it lists every row — all of them, the // more/less toggle; unfolded it lists every row, the whole inventory.
// whole inventory, not only the keys a transcript can open. A row the // Every row opens: a resident key streams, and any other key (a forge
// chat cannot open (a forge thread, a coding job, a phone topic) is a // thread, a coding job, a phone topic) opens the read-only snapshot its
// control row: pause/resume and abort act on its dispatch, and there // history route serves. The controls beside it act on its dispatch from
// is no transcript to click into. // either view.
// //
// The controls sit beside the delete button, on hover, one word each: // The controls sit beside the delete button, on hover, one word each:
// hold/run pauses and resumes the key's dispatch, stop aborts — cuts a // hold/run pauses and resumes the key's dispatch, stop aborts — cuts a
@@ -47,9 +47,6 @@ interface Group {
key: string key: string
name: string name: string
session: ClawSession session: ClawSession
/** Whether the chat can open this key — the resident prefixes only.
* A non-selectable row is a control row: it has no transcript. */
selectable: boolean
/** Whether abort has anything to act on: a live turn, or queued /** Whether abort has anything to act on: a live turn, or queued
* work to drop. */ * work to drop. */
abortable: boolean abortable: boolean
@@ -62,16 +59,13 @@ interface Group {
const groups = computed<Group[]>(() => { const groups = computed<Group[]>(() => {
const byKey = (a: ClawSession, b: ClawSession) => a.key.localeCompare(b.key) const byKey = (a: ClawSession, b: ClawSession) => a.key.localeCompare(b.key)
// Only the resident prefixes are chat sessions: `interactive:` is the // The resident prefixes are the chat sessions: `interactive:` is the
// live chat surface, `task:` a scheduled task's own turn, `calendar:` a // live chat surface, `task:` a scheduled task's own turn, `phone:` the
// reminder's. The rest of the inventory — `phone:<device>:<topic>` // phone client's, `calendar:` a reminder's. The rest of the inventory —
// status reporting, `job:<instance>#<id>` bookkeeping, a forge thread — // `job:<instance>#<id>`, a forge thread — holds no turn record: its
// has no transcript to open: the daemon's message, event and history // handler never streams. Its history route serves the session stash
// routes refuse those prefixes, so a row for one is a dead end. The // instead, so the row still opens, read-only.
// others group still lists them all: the inventory shows every key, const interactive = props.sessions
// and a dead-end row is a control row, not a hidden one.
const conversable = props.sessions.filter((session) => isResidentKey(session.key))
const interactive = conversable
.filter((session) => session.key.startsWith('interactive:')) .filter((session) => session.key.startsWith('interactive:'))
.sort(byKey) .sort(byKey)
const others = props.sessions const others = props.sessions
@@ -81,7 +75,6 @@ const groups = computed<Group[]>(() => {
key: session.key, key: session.key,
name: session.key.replace(/^interactive:/, ''), name: session.key.replace(/^interactive:/, ''),
session, session,
selectable: isResidentKey(session.key),
abortable: session.state === 'leased' || session.inbox_depth > 0, abortable: session.state === 'leased' || session.inbox_depth > 0,
}) })
const working = (sessions: ClawSession[]) => const working = (sessions: ClawSession[]) =>
@@ -104,9 +97,19 @@ const groups = computed<Group[]>(() => {
return groups return groups
}) })
/** Whether the others group is folded out; it starts folded. */ /** Whether the others group is folded out; it starts folded, and opens
* when the chat opens a row that lives in it — otherwise the selection
* would be invisible. */
const othersOpen = ref(false) const othersOpen = ref(false)
watch(
() => props.activeKey,
(key) => {
if (key !== '' && !isResidentKey(key)) othersOpen.value = true
},
{ immediate: true },
)
const shownCount = computed(() => const shownCount = computed(() =>
groups.value.reduce((total, group) => total + group.rows.length, 0), groups.value.reduce((total, group) => total + group.rows.length, 0),
) )
@@ -229,11 +232,7 @@ watch(
:class="{ active: row.key === activeKey }" :class="{ active: row.key === activeKey }"
:title="row.key" :title="row.key"
> >
<button <button class="entry" @click="$emit('select', row.key)">
class="entry"
:disabled="!row.selectable"
@click="$emit('select', row.key)"
>
<StatusDot :tone="stateTone(row.session.state)" /> <StatusDot :tone="stateTone(row.session.state)" />
<span class="name">{{ row.name }}</span> <span class="name">{{ row.name }}</span>
<span <span
+17 -8
View File
@@ -319,12 +319,13 @@ export function isInteractive(key: string): boolean {
return key.startsWith(INTERACTIVE_PREFIX) return key.startsWith(INTERACTIVE_PREFIX)
} }
/** The prefixes the chat surface answers for: the daemon's /** The prefixes the daemon's resident context owns: its
* `is_resident_key` (`crates/rhema-claw/src/interactive.rs`). Every other * `is_resident_key` (`crates/rhema-claw/src/interactive.rs`). A resident
* key in the inventory — `phone:` status reporting, `job:<instance>#<id>`, * key has a live turn record the event stream follows. Every other key
* a forge thread — has no transcript: the message, event and history * in the inventory — a forge thread, a coding job — answers no stream
* routes 400 on it. */ * and takes no message: its history route serves the snapshot the
const RESIDENT_PREFIXES = ['interactive:', 'task:', 'calendar:'] * engine checkpointed, and the panel renders it read-only. */
const RESIDENT_PREFIXES = ['interactive:', 'task:', 'phone:', 'calendar:']
/** Whether `key` is one the transcript surface can open. */ /** Whether `key` is one the transcript surface can open. */
export function isResidentKey(key: string): boolean { export function isResidentKey(key: string): boolean {
@@ -414,6 +415,9 @@ export interface StreamHandlers {
export interface HistoryPage { export interface HistoryPage {
events: { seq: number; event: TurnEvent }[] events: { seq: number; event: TurnEvent }[]
more: boolean more: boolean
/** The page is a snapshot of a key the daemon cannot take messages
* for: the chat surface renders it and hides the composer. */
readOnly: boolean
} }
export interface ClawApi { export interface ClawApi {
@@ -511,6 +515,7 @@ export interface ClawApi {
* `GET /v1/sessions/{key}/history` — one page of whole turns ending * `GET /v1/sessions/{key}/history` — one page of whole turns ending
* at `before` (absent: the newest). Pages stack: the next call passes * at `before` (absent: the newest). Pages stack: the next call passes
* the seq of the oldest event held, and stops when `more` is false. * the seq of the oldest event held, and stops when `more` is false.
* A non-resident key answers a read-only snapshot here.
*/ */
history(key: string, before?: number | null, limit?: number): Promise<HistoryPage> history(key: string, before?: number | null, limit?: number): Promise<HistoryPage>
} }
@@ -631,7 +636,11 @@ export function useClaw(token: Ref<string | null>): ClawApi {
const body = (await get( const body = (await get(
`/v1/sessions/${encodeURIComponent(key)}/history${query}`, `/v1/sessions/${encodeURIComponent(key)}/history${query}`,
token.value, token.value,
)) as { events?: { seq?: unknown; event?: unknown }[]; more?: unknown } )) as {
events?: { seq?: unknown; event?: unknown }[]
more?: unknown
read_only?: unknown
}
// The wire shape is trusted only as far as it parses: an event the // The wire shape is trusted only as far as it parses: an event the
// parser does not know is dropped, and its seq with it — the page // parser does not know is dropped, and its seq with it — the page
// still renders what it could read. // still renders what it could read.
@@ -639,7 +648,7 @@ export function useClaw(token: Ref<string | null>): ClawApi {
const event = parseTurnEvent(JSON.stringify(entry.event)) const event = parseTurnEvent(JSON.stringify(entry.event))
return event && typeof entry.seq === 'number' ? [{ seq: entry.seq, event }] : [] return event && typeof entry.seq === 'number' ? [{ seq: entry.seq, event }] : []
}) })
return { events, more: body.more === true } return { events, more: body.more === true, readOnly: body.read_only === true }
} }
async function providers(): Promise<ProvidersState> { async function providers(): Promise<ProvidersState> {