From 1a1ace014a4bd2072bb367fd515c69d2986b7b5b Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 24 Nov 2026 20:58:02 +0100 Subject: [PATCH] feat(web/claw): open every key, read-only when it has no stream 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. --- web/claw/README.md | 16 ++++-- web/claw/app/app.vue | 57 +++++++++++++++++++++ web/claw/app/components/ChatPanel.vue | 55 +++++++++++++++----- web/claw/app/components/SessionsSidebar.vue | 49 +++++++++--------- web/claw/app/composables/useClaw.ts | 25 ++++++--- 5 files changed, 153 insertions(+), 49 deletions(-) diff --git a/web/claw/README.md b/web/claw/README.md index 321ac45..7a53caa 100644 --- a/web/claw/README.md +++ b/web/claw/README.md @@ -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 lets 400/409 land in the error banner. The interactive prefixes (`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:#` keys and forge - keys. Only the resident prefixes have a transcript, so a row in - *others* for anything else is a control row: no click-through, but - the same pause/resume/abort and delete as every other row. + keys. +- **Every row opens, and some open read-only.** A resident key + (`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 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 diff --git a/web/claw/app/app.vue b/web/claw/app/app.vue index 88c9346..f7c03b9 100644 --- a/web/claw/app/app.vue +++ b/web/claw/app/app.vue @@ -310,6 +310,13 @@ async function refreshSessions(): Promise { try { sessions.value = await claw.sessions() 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) { noteApiError(err) } finally { @@ -672,6 +679,16 @@ function saveToken(): void { // --- the one live subscription --------------------------------------- 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 { stream?.close() @@ -681,9 +698,19 @@ function resubscribe(): void { attemptedAttachments.clear() notices.value = [] 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 // stream: subscribing to one would retry a 404 forever. 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, { onEvent: (event, seq) => transcript.applyEvent(event, seq), // 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 { + 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 * it above. Whole turns only, so the page never duplicates or skips: * the daemon ends it exactly where the mirror begins. */ @@ -822,6 +878,7 @@ onUnmounted(() => { :live="liveTurn" :active-key="activeKey" :can-send="isInteractive(activeKey)" + :read-only="threadReadOnly" :busy="busy" :session="activeSession" :active-backend="providersState?.active ?? null" diff --git a/web/claw/app/components/ChatPanel.vue b/web/claw/app/components/ChatPanel.vue index bec457f..9794801 100644 --- a/web/claw/app/components/ChatPanel.vue +++ b/web/claw/app/components/ChatPanel.vue @@ -26,6 +26,8 @@ const props = defineProps<{ activeKey: string /** Only `interactive:*` keys accept messages (the claw 400s the rest). */ canSend: boolean + /** The daemon answers this key with a snapshot, not a stream. */ + readOnly: boolean busy: boolean session: ClawSession | null activeBackend: { provider: string; model: string } | null @@ -43,6 +45,27 @@ const props = defineProps<{ 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 * the staged images, previews included for the optimistic row. */ interface SendPayload { @@ -428,10 +451,13 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {

{{ displayName }}

- + {{ streamLabel }} + + snapshot + @@ -446,7 +472,9 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {

- 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' }}

loading earlier turns

@@ -455,7 +483,7 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
-
you
+
{{ userLabel }}

-
-