web: run pipelines from the browser and quiet background chat

Add the Run pipeline dialog with prompt, server directory and a per-run
notification choice; add --notify auto/on/off to run and retry; move the live
tool call onto the tool-count line and tick the reasoning duration; stop chat
frames from repainting a different screen.
This commit is contained in:
2026-10-20 12:56:47 +01:00
parent f7a3a49f94
commit 0d7e81362f
17 changed files with 428 additions and 80 deletions
+46 -49
View File
@@ -685,6 +685,10 @@ let chatRenderMode = null;
* scroller and leave the composer DOM untouched.
*/
function scheduleChatRender(mode = "full") {
// A background chat must never repaint the screen the operator is using.
// Folding its frames into state is enough; the chat list/detail paint when the
// operator returns to Chat.
if (state.view !== "chat") return;
if (mode === "full" || chatRenderMode == null) chatRenderMode = mode === "full" ? "full" : chatRenderMode ?? "transcript";
if (chatRenderScheduled) return;
chatRenderScheduled = true;
@@ -692,6 +696,7 @@ function scheduleChatRender(mode = "full") {
chatRenderScheduled = false;
const chosen = chatRenderMode;
chatRenderMode = null;
if (state.view !== "chat") return;
if (chosen === "transcript" && refreshChatTranscript(state.chatActiveId)) return;
renderContent();
};
@@ -768,7 +773,7 @@ function onChatEvent(frame) {
const historySyncTimers = new Map();
const historySyncedFor = new Map();
function scheduleHistorySync(sessionId, messageId) {
if (!messageId || sessionId !== state.chatActiveId) return;
if (!messageId || state.view !== "chat" || sessionId !== state.chatActiveId) return;
if (historySyncedFor.get(sessionId) === messageId) return;
historySyncedFor.set(sessionId, messageId);
if (historySyncTimers.has(sessionId)) return;
@@ -812,7 +817,7 @@ function onChatPermission(frame) {
next.permissionError = "";
}
state.chatThreads.set(sessionId, next);
if (sessionId === state.chatActiveId) scheduleChatRender();
if (state.view === "chat" && sessionId === state.chatActiveId) scheduleChatRender();
}
/**
@@ -1331,7 +1336,7 @@ function onChatFrame(message) {
const running = runningAfterFrame(thread.running, frame);
if (queued === thread.queued && running === thread.running) return;
setThread(sessionId, { queued, running });
if (sessionId === state.chatActiveId) {
if (state.view === "chat" && sessionId === state.chatActiveId) {
refreshChatComposerState(sessionId);
scheduleChatRender("transcript");
}
@@ -2539,13 +2544,15 @@ function renderChatTranscript(
else {
const streaming = running && index === lastAgent;
const elapsed = (part) => threadToolElapsedMillis(thread, part, now);
transcript.append(renderChatAgentTurn(row.turn, streaming, elapsed));
transcript.append(renderChatAgentTurn(row.turn, streaming, elapsed, thread));
}
});
// The running indicator sits under the transcript, after the last agent turn:
// a spinner, the phase headline, the turn's elapsed, then one line per running
// tool (a call over 60 s is tinted and marked `· long`).
if (running && thread) transcript.append(renderChatRunningIndicator(thread, now));
if (running && thread && threadRunningTools(thread.messages).length === 0) {
transcript.append(renderChatRunningIndicator(thread, now));
}
// The conversation's local command lines sit after the turns, full width and
// deliberately unlike a message bubble (see ChatCommandNoticeItem).
for (const notice of notices) transcript.append(renderChatCommandNotice(sessionId, notice));
@@ -2823,26 +2830,6 @@ function renderChatRunningIndicator(thread, now) {
}),
);
wrap.append(head);
// One stable detail line for the whole turn. Rendering one line per in-flight
// tool made the transcript grow and shrink for every call, which bounced the
// text (and the composer) while a turn streamed. The line updates in place to
// the longest-running call; the tool chip in the turn still lists every call.
const running = threadRunningTools(thread.messages);
const chosen =
running.find((part) => toolLongRunning(threadToolElapsedMillis(thread, part, now))) ??
running[0] ??
null;
if (chosen) {
wrap.append(renderChatRunningTool(thread, chosen, now));
} else {
wrap.append(
h(
"div",
{ class: "chat-running-tool" },
h("span", { class: "chat-running-tool-text", text: "Preparing the next step…" }),
),
);
}
return wrap;
}
@@ -2885,14 +2872,14 @@ function renderChatUserMessage(message) {
}
/** One folded agent reply, left-aligned: reasoning, tool-call chip, answer. */
function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0) {
function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0, thread = null) {
const wrap = h("div", { class: "chat-turn chat-turn-agent" });
const bubble = h("div", { class: "chat-bubble agent-bubble" });
const steps = turn.reasoningSteps;
// Thinking is evidence about the turn, not part of the answer bubble. Keep it
// outside and above the message, the way the tool summary sits outside and
// below it.
if (steps.length > 0) wrap.append(renderChatReasoning(turn, streaming));
if (steps.length > 0) wrap.append(renderChatReasoning(turn, streaming, thread));
if (turn.answer.trim() !== "") bubble.append(renderMarkdown(turn.answer));
if (bubble.childElementCount > 0) wrap.append(bubble);
// The tool summary is a quiet line beside the message, not a highlighted chip
@@ -2913,9 +2900,9 @@ function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0) {
* `Reasoning · N steps`), a live one `Thinking…`/`Thinking · N steps`. Live
* elapsed time is C5's; this renders the parts' own timing.
*/
function renderChatReasoning(turn, streaming = false) {
function renderChatReasoning(turn, streaming = false, thread = null) {
const expanded = state.chatReasoning.has(turn.key);
const block = h("div", { class: "chat-reasoning" });
const block = h("div", { class: `chat-reasoning${streaming ? " chat-reasoning-live" : ""}` });
const toggle = h("button", {
class: "chat-reasoning-toggle",
type: "button",
@@ -2930,11 +2917,16 @@ function renderChatReasoning(turn, streaming = false) {
}),
);
const label = reasoningLabel(turn.reasoningSteps.length, streaming);
const elapsedMillis = turnElapsedMillis(turn.parts);
// A live turn has no completed timing envelope yet, so measure from the
// thread's running clock; the one-second clock refreshes this label in place.
const elapsedMillis = streaming
? threadElapsedMillis(thread, Date.now())
: turnElapsedMillis(turn.parts);
const duration = elapsedMillis == null ? null : formatDuration(Math.trunc(elapsedMillis / 1000));
toggle.append(
h("span", {
class: "chat-reasoning-label",
"data-live-steps": streaming ? String(turn.reasoningSteps.length) : null,
text: duration == null ? label : `${label} · ${duration}`,
}),
);
@@ -2986,6 +2978,7 @@ function renderChatToolCalls(turn, { streaming = false, elapsedMillis = () => 0
"aria-expanded": "false",
"aria-haspopup": "dialog",
});
const currentTool = running ? parts.filter((part) => toolRunning(part)).at(-1) ?? null : null;
if (running) {
chip.append(h("span", { class: "spinner chat-tool-spinner", "aria-hidden": "true" }));
} else {
@@ -2998,6 +2991,19 @@ function renderChatToolCalls(turn, { streaming = false, elapsedMillis = () => 0
);
}
chip.append(h("span", { class: "chat-tool-label", text: toolCallsLabel(count) }));
// The live call lives on the same line as the count instead of in a second
// status line below the transcript. The chip therefore updates in place while
// the count and the rest of the row remain stable.
if (currentTool) {
const detail = toolDetail(currentTool);
const name = toolLabel(currentTool);
chip.append(
h("span", {
class: "chat-tool-current",
text: detail == null ? name : `${name} ${detail}`,
}),
);
}
if (long) chip.append(h("span", { class: "chat-tool-long", text: "\u00b7 long" }));
chip.append(
h("span", {
@@ -3754,30 +3760,21 @@ function stopChatClock() {
/** Refresh the running indicator in place from the thread's own state at [now]. */
function updateChatIndicator(now) {
const thread = state.chatActiveId ? state.chatThreads.get(state.chatActiveId) : null;
if (!thread?.running) return;
// The live reasoning label is a second continuous clock: "Thinking · N steps ·
// 1m 2s" must keep counting even when no frame arrives.
const liveReasoning = document.querySelector("#chatTranscript .chat-reasoning-live .chat-reasoning-label");
if (liveReasoning) {
const steps = Number(liveReasoning.dataset.liveSteps) || 0;
const duration = formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000));
liveReasoning.textContent = `${reasoningLabel(steps, true)} · ${duration}`;
}
const el = document.getElementById("chatRunning");
if (!thread?.running || !el) return;
if (!el) return;
const label = el.querySelector(".chat-running-label");
if (label) label.textContent = turnPhaseLabel(threadPhase(thread, now) ?? TURN_PHASE_WAITING);
const elapsed = el.querySelector(".chat-running-elapsed");
if (elapsed) elapsed.textContent = `\u00b7 ${formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000))}`;
const running = threadRunningTools(thread.messages);
const chosen =
running.find((part) => toolLongRunning(threadToolElapsedMillis(thread, part, now))) ??
running[0] ??
null;
const line = el.querySelector(".chat-running-tool");
if (line) {
const text = line.querySelector(".chat-running-tool-text");
if (text && chosen) text.textContent = runningToolText(chosen);
const age = chosen ? threadToolElapsedMillis(thread, chosen, now) : 0;
const toolElapsed = line.querySelector(".chat-running-tool-elapsed");
if (toolElapsed) toolElapsed.textContent = chosen ? formatToolDuration(age) : "";
const mark = line.querySelector(".chat-tool-long");
if (chosen && toolLongRunning(age) && !mark) {
line.classList.add("chat-running-tool-long");
line.append(h("span", { class: "chat-tool-long", text: "\u00b7 long" }));
}
}
}
return {