diff --git a/web/claw/README.md b/web/claw/README.md index 1df4f7e..321ac45 100644 --- a/web/claw/README.md +++ b/web/claw/README.md @@ -128,11 +128,13 @@ Two consequences worth knowing before changing this code: - **Sessions are created in place.** The sidebar's `+` form posts `POST /v1/sessions` with a client-validated name (`[A-Za-z0-9._-]{1,64}`), switches the chat to the new key, and - lets 400/409 land in the error banner. The inventory lists only the - resident prefixes (`interactive:`, `task:`, `calendar:`) — the ones the - message, event and history routes answer for. The phone's status keys - (`phone:…`), the coding jobs' `job:#` keys and forge keys - stay out, and the full list stays on the wire. + 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 + (`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. - **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 @@ -141,6 +143,16 @@ Two consequences worth knowing before changing this code: error banner like every other refusal, and the chat moves to the first remaining session, the stream's watcher following the key so nothing keeps streaming a session that no longer exists. +- **Every row is controllable.** Beside the delete button, on hover: + `hold` posts `POST /v1/sessions/{key}/pause` and the row badges + `held` — queued work accumulates and nothing dispatches until `run` + posts the resume, both answered by the inventory's `paused` flag. + `stop` posts `POST /v1/sessions/{key}/abort`: a live turn is cut + (the stream closes on its `aborted` marker, in the warn tone, since + nothing failed), and an idle key's queued work is dropped instead — + the notice says which, from the answer's `cut`/`dropped`. A key with + neither running nor queued work has `stop` disabled rather than + sending a no-op. ## Layout diff --git a/web/claw/app/app.vue b/web/claw/app/app.vue index 9527db2..88c9346 100644 --- a/web/claw/app/app.vue +++ b/web/claw/app/app.vue @@ -377,6 +377,49 @@ async function confirmDeleteSession(): Promise { } } +/** The pause gate: hold a key's dispatch, lift the hold. The inventory + * refresh carries the `paused` flag back to the sidebar. */ +async function pauseSession(key: string): Promise { + try { + await claw.pauseSession(key) + pushNotice(`${key} held`) + apiError.value = null + } catch (err) { + noteApiError(err) + } + void refreshSessions() +} + +async function resumeSession(key: string): Promise { + try { + await claw.resumeSession(key) + pushNotice(`${key} resumed`) + apiError.value = null + } catch (err) { + noteApiError(err) + } + void refreshSessions() +} + +/** Abort: cut a live turn, or drop the key's queued work. The answer + * says which happened; the inventory refresh settles the row. */ +async function abortSession(key: string): Promise { + try { + const result = await claw.abortSession(key) + pushNotice( + result.cut + ? `turn on ${key} stopped` + : result.dropped > 0 + ? `${result.dropped} queued item(s) dropped on ${key}` + : `nothing running on ${key}`, + ) + apiError.value = null + } catch (err) { + noteApiError(err) + } + void refreshSessions() +} + async function refreshProviders(): Promise { try { providersState.value = await claw.providers() @@ -770,6 +813,9 @@ onUnmounted(() => { @refresh="refreshSessions" @create="createSession" @delete="askDeleteSession" + @pause="pauseSession" + @resume="resumeSession" + @abort="abortSession" /> {{ item.turn.outcome }} @@ -759,6 +763,13 @@ function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' { color: var(--accent-text); } +/* An aborted turn: stopped from the controls, and nothing replaced + it. Not a failure either — the same warn tone the held badge + carries, which is what an operator's stop is. */ +.outcome.aborted { + color: var(--warn); +} + /* While the turn runs but no reply text has landed yet. Tool rows and the thinking trace never render on this surface, so this line is the turn's only pulse between its first event and its first delta — the diff --git a/web/claw/app/components/SessionsSidebar.vue b/web/claw/app/components/SessionsSidebar.vue index 780f70e..7232076 100644 --- a/web/claw/app/components/SessionsSidebar.vue +++ b/web/claw/app/components/SessionsSidebar.vue @@ -10,7 +10,16 @@ // // The non-interactive keys fold under *others*: folded (the default), // the group shows only how many of them hold a lease, plus the -// more/less toggle; unfolded it lists every row. +// more/less toggle; unfolded it lists every row — all of them, the +// whole inventory, not only the keys a transcript can open. A row the +// chat cannot open (a forge thread, a coding job, a phone topic) is a +// control row: pause/resume and abort act on its dispatch, and there +// is no transcript to click into. +// +// 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 +// live turn, or drops the key's queued work when none runs. Nothing +// here is destructive beyond the delete, which keeps its own dialog. import { SESSION_NAME_PATTERN, isResidentKey } from '~/composables/useClaw' import type { ClawSession } from '~/composables/useClaw' @@ -27,11 +36,24 @@ const emit = defineEmits<{ refresh: [] create: [name: string] delete: [key: string] + pause: [key: string] + resume: [key: string] + abort: [key: string] }>() interface Group { label: string - rows: { key: string; name: string; session: ClawSession }[] + rows: { + key: string + name: string + 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 + * work to drop. */ + abortable: boolean + }[] /** How many rows hold a lease; the others' header shows the count. */ working: number /** Whether the rows fold away until the toggle says otherwise. */ @@ -42,23 +64,25 @@ const groups = computed(() => { const byKey = (a: ClawSession, b: ClawSession) => a.key.localeCompare(b.key) // Only the resident prefixes are chat sessions: `interactive:` is the // live chat surface, `task:` a scheduled task's own turn, `calendar:` a - // reminder's. The rest of the inventory has no transcript to open — - // `phone::` is status reporting, `job:#` - // is the coding jobs' bookkeeping, a forge key is a thread the handler - // reports on — and the daemon's message, event and history routes - // refuse those prefixes, so a row for one is a dead end. The inventory - // hides them rather than the API narrowing. + // reminder's. The rest of the inventory — `phone::` + // status reporting, `job:#` bookkeeping, a forge thread — + // has no transcript to open: the daemon's message, event and history + // routes refuse those prefixes, so a row for one is a dead end. The + // others group still lists them all: the inventory shows every key, + // 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:')) .sort(byKey) - const others = conversable + const others = props.sessions .filter((session) => !session.key.startsWith('interactive:')) .sort(byKey) const row = (session: ClawSession) => ({ key: session.key, name: session.key.replace(/^interactive:/, ''), session, + selectable: isResidentKey(session.key), + abortable: session.state === 'leased' || session.inbox_depth > 0, }) const working = (sessions: ClawSession[]) => sessions.filter((session) => session.state === 'leased').length @@ -205,13 +229,48 @@ watch( :class="{ active: row.key === activeKey }" :title="row.key" > - + + +