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
+3
View File
@@ -176,6 +176,9 @@ const state = {
pipelineGraph: null,
// Expanded by default; a collapse is remembered (graphPrefs.js).
pipelineGraphExpanded: readGraphExpanded(),
// The Run pipeline dialog: pipeline/version, prompt, working directory,
// notification mode and its loading/error state.
runStart: null,
// Gallery or list for run artifacts; a per-operator choice (artifactViewPrefs.js).
artifactView: readArtifactView(),
// Starred chat sessions: filled from chat_sessions (server-shared).
+1
View File
@@ -46,6 +46,7 @@ export const Protocol = Object.freeze({
// The run-level operator actions (R11–R14). Each replies with a `run` (or
// `run_started` for retry) envelope carrying the updated run detail; mirrors
// internal/protocol/runs.go and Message.kt.
RUN_PIPELINE: "run_pipeline",
CANCEL_RUN: "cancel_run",
RETRY_RUN: "retry_run",
DECIDE_RUN: "decide_run",
+23
View File
@@ -181,6 +181,29 @@ export class PipelinesRepository {
}
/** Cancels a run; mirrors PipelinesRepository.cancelRun (exactly run_id). */
/**
* Starts a fresh run of one pipeline version. `notifyMode` is auto, on or off;
* auto omits the field so the pipeline definition applies.
*/
async runPipeline({ pipelineId, version, prompt, workspace, notifyMode = "auto", title = "" } = {}) {
const request = {
type: Protocol.RUN_PIPELINE,
pipeline_id: Number(pipelineId),
version: Number(version),
request_key: newChatOperationId(),
workspace: String(workspace ?? "").trim(),
input: { prompt: String(prompt ?? "") },
};
if (String(title ?? "").trim() !== "") request.title = String(title).trim();
const mode = String(notifyMode ?? "auto").trim().toLowerCase();
if (mode === "on" || mode === "off") request.notify_mode = mode;
const response = await this.#client.call(request);
if (!response.run_detail) {
throw new ProtocolError("The server returned no run detail.");
}
return response.run_detail;
}
async cancelRun(id) {
const response = await this.#client.call({ type: Protocol.CANCEL_RUN, run_id: id });
if (!response.run_detail) {
+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 {
+178 -1
View File
@@ -29,10 +29,11 @@ import { statusIcon } from "../statusIcon.js";
import { writeGraphExpanded } from "../graphPrefs.js";
export function createPipelinesView(rt) {
const { state, repo } = rt;
const { state, repo, modal } = rt;
const renderContent = (...args) => rt.renderContent(...args);
const selectPipeline = (...args) => rt.selectPipeline(...args);
const pushRoute = (...args) => rt.pushRoute(...args);
const applyRoute = (...args) => rt.applyRoute(...args);
function renderPipelineList() {
@@ -374,6 +375,171 @@ function pipelineGlyph() {
return svg;
}
/** Open the Run pipeline dialog for [pipeline]. */
async function openRunDialog(pipeline) {
const pipelineId = Number(pipeline?.id) || 0;
if (pipelineId <= 0) return;
const start = {
pipelineId,
version: Number(pipeline?.version) || Number(pipeline?.latest_version) || 0,
name: String(pipeline?.name ?? ""),
prompt: "",
workspace: String(state.workspace ?? "").startsWith("/") ? state.workspace : "",
notifyMode: "auto",
directories: [],
loading: true,
sending: false,
error: "",
};
state.runStart = start;
renderContent();
try {
const directories = await repo.chatDirectories();
start.directories = Array.isArray(directories)
? directories.filter((entry) => typeof entry === "string" && entry.startsWith("/"))
: [];
} catch (error) {
start.directories = [];
start.error = describeError(error);
}
if (!start.workspace && start.directories.length) start.workspace = start.directories[0];
start.loading = false;
if (state.runStart === start) renderContent();
}
function closeRunDialog() {
state.runStart = null;
renderContent();
}
async function startRun() {
const start = state.runStart;
if (!start || start.sending) return;
const prompt = start.prompt.trim();
if (prompt === "") {
start.error = "Enter a prompt for this run.";
renderContent();
return;
}
if (!start.workspace.startsWith("/")) {
start.error = "Choose an absolute working directory on the server.";
renderContent();
return;
}
start.sending = true;
start.error = "";
renderContent();
try {
const run = await repo.runPipeline({
pipelineId: start.pipelineId,
version: start.version,
prompt,
workspace: start.workspace,
notifyMode: start.notifyMode,
title: "",
});
state.runStart = null;
await applyRoute({ kind: "run", id: run.id });
} catch (error) {
if (state.runStart !== start) return;
start.sending = false;
start.error = describeError(error);
renderContent();
}
}
function renderRunStartDialog() {
const start = state.runStart;
const overlay = h("div", {
class: "confirm-dialog run-start-dialog",
role: "dialog",
"aria-modal": "true",
"aria-label": `Run ${start.name || "pipeline"}`,
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeRunDialog();
});
const panel = h("div", { class: "confirm-panel" });
panel.append(h("h2", { class: "confirm-title", text: `Run ${start.name || "pipeline"}` }));
const promptField = h("label", { class: "run-start-field", for: "runPrompt" });
promptField.append(h("span", { class: "run-start-label", text: "Prompt" }));
const prompt = h("textarea", {
id: "runPrompt",
class: "run-start-prompt",
rows: "5",
placeholder: "What should this run do?",
spellcheck: "false",
oninput: (event) => { start.prompt = event.target.value; },
});
prompt.value = start.prompt;
promptField.append(prompt);
panel.append(promptField);
const listId = "runWorkspaceChoices";
const datalist = h("datalist", { id: listId });
for (const directory of start.directories) datalist.append(h("option", { value: directory }));
const workField = h("label", { class: "run-start-field", for: "runWorkspace" });
workField.append(h("span", { class: "run-start-label", text: "Working directory (on the server)" }));
const work = h("input", {
id: "runWorkspace",
type: "text",
list: listId,
value: start.workspace,
spellcheck: "false",
autocomplete: "off",
placeholder: "/absolute/path/on/the/server",
oninput: (event) => { start.workspace = event.target.value; },
});
workField.append(work, datalist);
workField.append(h("span", { class: "run-start-helper muted", text: "Choose a recent directory or type an absolute path." }));
panel.append(workField);
const notifyField = h("label", { class: "run-start-field", for: "runNotify" });
notifyField.append(h("span", { class: "run-start-label", text: "Notifications for this run" }));
const notify = h("select", { id: "runNotify", onchange: (event) => { start.notifyMode = event.target.value; } });
for (const [value, label] of [
["auto", "Pipeline default"],
["on", "Notify me"],
["off", "Silent"],
]) {
const option = h("option", { value, text: label });
option.selected = start.notifyMode === value;
notify.append(option);
}
notifyField.append(notify);
panel.append(notifyField);
if (start.loading) panel.append(h("div", { class: "run-start-helper muted", text: "Loading directories…" }));
if (start.error) panel.append(h("div", { class: "run-start-error", role: "alert", text: start.error }));
const actions = h("div", { class: "confirm-actions" });
actions.append(
h("button", {
class: "ghost run-start-cancel",
type: "button",
text: "Cancel",
disabled: start.sending,
onclick: closeRunDialog,
}),
h("button", {
class: "primary run-start-confirm",
type: "button",
text: start.sending ? "Starting…" : "Run",
disabled: start.sending,
onclick: startRun,
}),
);
panel.append(actions);
overlay.append(panel);
modal.stage("run-start", overlay, {
onClose: closeRunDialog,
triggerSelector: ".run-pipeline",
fallbackSelectors: ["#detailTitle", "#pane-main"],
});
return overlay;
}
function renderPipelineDetail() {
const d = state.pipelineDetail;
const pane = h("div", { class: "detail" });
@@ -382,6 +548,16 @@ function renderPipelineDetail() {
return pane;
}
pane.append(h("h1", { class: "detail-title", id: "detailTitle", tabindex: "-1", text: d.name || `pipeline ${d.id}` }));
pane.append(
h("div", { class: "pipeline-actions" },
h("button", {
class: "primary run-pipeline",
type: "button",
text: "Run",
onclick: () => openRunDialog(d),
}),
),
);
if (state.pipelineTab === "graph") {
pane.append(h("p", { class: "graph-note muted", text: graphNote() }));
const stages = d.graph?.stages ?? [];
@@ -466,6 +642,7 @@ function renderPipelineDetail() {
}
pane.append(body);
}
if (state.runStart) pane.append(renderRunStartDialog());
return pane;
}