Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176<script lang="ts"> import type { SessionRuntimeInfo } from "@/contracts/session-runtime"; import type { LifecycleNotice, OperationPending, WebConnectionState } from "../connection"; import { createEventDispatcher } from "svelte"; import { towerLabel, severityDotClass } from "../severity"; import ContextMeter from "./ContextMeter.svelte";
export let runtime: SessionRuntimeInfo | null = null; export let phase: WebConnectionState["phase"] = "connected"; export let operationPending: OperationPending = {}; export let notice: LifecycleNotice | null = null; export let statusMessage = ""; /** Active model's context window (tokens), from the runtime model catalog. Absent when the * runtime exposes no model catalog or the active model omits a window. Together with * `usage.context_tokens` it drives the context-size display. */ export let contextWindow: number | undefined = undefined; /** Active server-authored reasoning effort, when the model supports selection. */ export let reasoningEffort: string | undefined = undefined;
const dispatcher = createEventDispatcher<{ stop: { sessionId: string; cwd: string }; kill: { sessionId: string; cwd: string; force: boolean }; refresh: { sessionId: string; cwd: string }; /** Resume a stopped/failed runtime by activating the session (saga vr7kgx.2 §5). */ resume: { sessionId: string; cwd: string }; dismissNotice: null; }>();
let forceConfirming = false; let forceDispatching = false; let forceObservedPending = false; let forceTrigger: HTMLButtonElement | undefined; let lastSessionId: string | null = null;
$: sessionId = runtime?.session_id ?? null; $: if (sessionId !== lastSessionId) { forceConfirming = false; forceDispatching = false; forceObservedPending = false; lastSessionId = sessionId; } $: label = runtime?.title ?? (sessionId ? `Session ${sessionId.slice(0, 8)}` : "Session"); $: connected = phase === "connected"; $: canStop = runtime?.runtime_state === "running" || runtime?.runtime_state === "starting"; $: canResume = runtime?.runtime_state === "stopped" || runtime?.runtime_state === "failed"; // The header badge surfaces what the AGENT is doing (idle/streaming/permission hold/…), not // the runtime lifecycle (running/stopped/…). A runtime can be "running" (process alive) while // the agent sits idle — the badge must read "idle" in that case, never "running". Stopped/ // failed runtimes fall back to lifecycle labels since there is no live agent activity. $: stopped = runtime?.runtime_state === "stopped"; $: failed = runtime?.runtime_state === "failed"; $: activityLabel = stopped ? "history available" : failed ? "runtime failed" : towerLabel(runtime?.status); $: activityDot = stopped ? "sev-dot" : severityDotClass(runtime?.status); $: stopPending = sessionId !== null && operationPending[`session.terminate:${sessionId}`] === true; $: killPending = sessionId !== null && operationPending[`session.kill:${sessionId}`] === true; $: refreshPending = sessionId !== null && operationPending[`session.status:${sessionId}`] === true; $: activatePending = sessionId !== null && operationPending[`session.activate:${sessionId}`] === true; $: mutationPending = stopPending || killPending; $: liveMessage = statusMessage || notice?.message || ""; $: if (forceDispatching && killPending) forceObservedPending = true; $: if (forceDispatching && forceObservedPending && !killPending) { forceConfirming = false; forceDispatching = false; forceObservedPending = false; }
// Context-size display (current / total / percentage). `context_tokens` is the tokens the // last provider call placed in-window; `contextWindow` is the active model's capacity from // the runtime model catalog. Either may be absent — render only what is known. The meter // itself (bar + pct + edge color) lives in the shared `ContextMeter` component. $: contextCurrent = runtime?.usage?.context_tokens; $: contextTotal = contextWindow; $: showContext = contextCurrent !== undefined || contextTotal !== undefined;
function target(): { sessionId: string; cwd: string } | null { return runtime ? { sessionId: runtime.session_id, cwd: runtime.cwd } : null; } function refresh() { const value = target(); if (value && connected && !refreshPending) dispatcher("refresh", value); } function stop() { const value = target(); if (value && connected && canStop && !mutationPending) dispatcher("stop", value); } function kill(force: boolean) { const value = target(); if (value && connected && canStop && !mutationPending) dispatcher("kill", { ...value, force }); } function resume() { const value = target(); if (value && connected && canResume && !activatePending) dispatcher("resume", value); } function cancelForce() { forceConfirming = false; forceDispatching = false; forceObservedPending = false; forceTrigger?.focus(); } function confirmForce() { if (forceDispatching || mutationPending) return; forceDispatching = true; kill(true); } function createdLabel(value: number): string { return new Date(value).toLocaleString(); } function shortNum(value: number | undefined): string { if (value === undefined || !Number.isFinite(value)) return "–"; if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`; if (value >= 1_000) return `${(value / 1_000).toFixed(value >= 10_000 ? 0 : 1)}k`; return String(value); }</script>
<aside class="runtime-panel" aria-label="Session runtime controls"> <header class="panel-head"> <div> <span class="tracked">Session details</span> <h2 id="session-runtime-heading" class="session-title" tabindex="-1">{label}</h2> </div> {#if runtime}<span class="runtime-state mono"><span class={activityDot} aria-hidden="true"></span>{activityLabel}</span>{/if} </header>
{#if runtime} <dl class="fields"> <div class="field"><dt>Session ID</dt><dd class="mono" data-field="session-id">{runtime.session_id}</dd></div> <div class="field"><dt>Working directory</dt><dd class="mono" title={runtime.cwd}>{runtime.cwd}</dd></div> {#if runtime.model}<div class="field"><dt>Model</dt><dd class="mono">{runtime.model}</dd></div>{/if} {#if runtime.provider}<div class="field"><dt>Provider</dt><dd class="mono">{runtime.provider}</dd></div>{/if} {#if runtime.mode}<div class="field"><dt>Mode</dt><dd class="mono">{runtime.mode}</dd></div>{/if} {#if reasoningEffort}<div class="field"><dt>Reasoning</dt><dd class="mono">{reasoningEffort}</dd></div>{/if} <div class="field"><dt>Activity</dt><dd class="mono">{stopped || failed ? "—" : runtime.status}</dd></div> <div class="field"><dt>Runtime</dt><dd class="mono">{runtime.runtime_state}</dd></div> <div class="field"><dt>Created</dt><dd class="mono">{createdLabel(runtime.created_at)}</dd></div> {#if runtime.usage} <div class="field usage"><dt>Usage</dt><dd class="mono"> <span>in {shortNum(runtime.usage.input)}</span><span>out {shortNum(runtime.usage.output)}</span> {#if runtime.usage.cache_read !== undefined}<span>cache read {shortNum(runtime.usage.cache_read)}</span>{/if} {#if runtime.usage.cache_write !== undefined}<span>cache write {shortNum(runtime.usage.cache_write)}</span>{/if} </dd></div> {/if} {#if showContext} <div class="field context" data-field="context"> <dt>Context</dt> <dd class="mono"> <ContextMeter contextCurrent={contextCurrent} contextTotal={contextTotal} variant="panel" /> </dd> </div> {/if} </dl>
<div class="status" role="status" aria-live="polite"> {#if liveMessage}<span class="status-msg mono">{liveMessage}</span>{/if} {#if notice}<button class="btn btn--ghost dismiss" type="button" on:click={() => dispatcher("dismissNotice", null)} aria-label="Dismiss notice">✕</button>{/if} </div>
{#if forceConfirming} <div class="force-confirm" role="alertdialog" aria-label="Force kill runtime for {label}"> <p>Force kill the runtime for <strong>{label}</strong>? Durable session history is retained.</p> <div class="force-actions"> <button class="btn btn--ghost" type="button" data-action="forceCancel" on:click={cancelForce}>Cancel</button> <button class="btn btn--danger" type="button" data-action="forceConfirm" on:click={confirmForce} disabled={forceDispatching || killPending}>Force kill runtime</button> </div> </div> {/if}
<div class="actions" role="group" aria-label="Session runtime lifecycle"> <button class="btn" type="button" data-action="refresh" on:click={refresh} disabled={!connected || refreshPending}>Refresh status</button> {#if canResume} <button class="btn btn--primary" type="button" data-action="resume" on:click={resume} disabled={!connected || activatePending}>{activatePending ? "Resuming" : "Resume runtime"}</button> {/if} <button class="btn" type="button" data-action="stop" on:click={stop} disabled={!connected || !canStop || mutationPending}>{stopPending ? "Stopping" : "Stop runtime"}</button> <button class="btn btn--danger" type="button" data-action="kill" on:click={() => kill(false)} disabled={!connected || !canStop || mutationPending}>{killPending ? "Killing" : "Kill runtime"}</button> <button class="btn btn--ghost" type="button" data-action="forceKill" bind:this={forceTrigger} on:click={() => (forceConfirming = true)} disabled={!connected || !canStop || mutationPending} aria-expanded={forceConfirming}>Force kill runtime</button> </div> {:else} <div class="empty"><span class="tracked">Session runtime unavailable</span></div> {/if}</aside>
<style> .runtime-panel { display: flex; flex-direction: column; min-width: 0; height: 100%; background: var(--surface); border-left: 1px solid var(--hairline); box-shadow: var(--shadow-lift); } .panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--hairline); } .session-title { margin: 3px 0 0; font-size: 16px; color: var(--ink); } #session-runtime-heading:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--r-xs); } .runtime-state { font-size: 11px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 5px; } .runtime-state .sev-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--sev-success); flex: none; } .runtime-state .sev-dot.is-streaming { background: var(--sev-info); } .runtime-state .sev-dot.is-permission { background: var(--sev-warn); } .runtime-state .sev-dot.is-error { background: var(--sev-error); } .runtime-state .sev-dot.is-compact { background: var(--sev-info); opacity: 0.7; } .fields { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 12px 14px; overflow-y: auto; min-height: 0; } .field { display: grid; grid-template-columns: minmax(78px, 38%) 1fr; gap: 8px; align-items: baseline; } .field dt { font-size: 11px; color: var(--ink-3); } .field dd { margin: 0; font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .field.usage dd { display: flex; flex-wrap: wrap; gap: 8px; white-space: normal; } .field.context dd { display: flex; align-items: center; white-space: normal; overflow: visible; } .status { display: flex; align-items: flex-start; gap: 8px; padding: 6px 14px; min-height: 24px; border-top: 1px solid var(--hairline-faint); } .status-msg { font-size: 11.5px; color: var(--ink-2); word-break: break-word; flex: 1; } .dismiss { padding: 0 6px; } .force-confirm { padding: 10px 14px; border-top: 1px solid var(--hairline-faint); background: var(--sev-error-bg); } .force-confirm p { margin: 0 0 8px; font-size: 12px; color: var(--sev-error-ink); } .force-actions { display: flex; gap: 8px; justify-content: flex-end; } .actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--hairline); } .empty { padding: 24px 14px; color: var(--ink-3); }</style>