Merge branch 'main' into web-layout

Take main's newer smoke behaviour where they met: the binary capture is run 449
(opened through openRunDetail), and a running run must show no aggregate Changes
section. Keep the layout's shell-aware checks and its L2-L4 rows; L7 stays todo
with the view-level fixes recorded.
This commit is contained in:
2026-10-19 20:06:25 +01:00
14 changed files with 709 additions and 150 deletions
+53 -37
View File
@@ -1,6 +1,6 @@
// Pure, DOM-free logic for the run summary's Changes section and its diff
// viewer, ported from the Android client so the browser says and shows exactly
// the same things:
// Pure, DOM-free logic for the run summary's final-state Changes section and its
// diff viewer, ported from the Android client so the browser says and shows
// exactly the same things (the aggregate is last-visit-wins rather than a sum):
// ui/changes/RunChanges.kt changeKind, changeKindLabel, parseUnifiedPatch,
// runChanges, runChangesHeader, runChangesNote,
// changesListSummary, noChangeDetail,
@@ -249,14 +249,27 @@ export function gutterText(value, width) {
// ---------------------------------------------------------------------------
/**
* Aggregates a run's stage steps into its Changes state. Pure and total over its
* input: a null `file_changes` on a step is a historical (or non-capturing) step
* and contributes nothing (it is never "no changes"); a present capture with no
* files is a real, observed no-change. Files are keyed by path and keep
* Whether the Summary tab may present the run-wide aggregated Changes section.
* The operator decision is final-state-only: a failed run has no settled final
* workspace, so its evidence stays in each visit's own recorded capture. The
* Android client shows the aggregate for failed runs too; this is a deliberate
* browser divergence, recorded in PARITY.md R4. Pure.
*/
export function showRunChangesSummary(status) {
return str(status).trim().toLowerCase() === "succeeded";
}
/**
* Aggregates a run's stage steps into its final-state Changes view. Pure and
* total over its input: a null `file_changes` on a step is a historical (or
* non-capturing) step and contributes nothing (it is never "no changes"); a
* present capture with no files is a real, observed no-change. Steps are read in
* numeric sequence order (stable for ties), and files are keyed by path and keep
* first-seen order, so a path several steps changed is one entry naming all of
* them. Later steps win the kind unless they only say "other", added/removed
* line counts sum, binary/truncated are OR'd, before_mode is first-seen and
* after_mode last-seen.
* them. The last recorded step for a path supplies its kind, patch, added/removed
* counts, binary/truncated flags and modes: the summary describes the state the
* run left, never a sum of intermediate visits. Run-wide capture counters and
* caveats still describe every contributing step.
*/
export function runChanges(steps) {
const entries = new Map();
@@ -267,9 +280,14 @@ export function runChanges(steps) {
let missingCaptures = 0;
let skipped = 0;
let omitted = 0;
let truncatedSeen = false;
const diagnostics = new Set();
const orderedSteps = (steps ?? [])
.map((step, index) => ({ step, index }))
.sort((a, b) => sequenceOf(a.step) - sequenceOf(b.step) || a.index - b.index)
.map((entry) => entry.step);
for (const step of steps ?? []) {
for (const step of orderedSteps) {
const changes = step?.file_changes;
if (changes == null) {
if (step?.status === "running" || step?.status === "waiting") stepsPending++;
@@ -287,47 +305,39 @@ export function runChanges(steps) {
for (const file of changes.files ?? []) {
const path = str(file?.path);
if (path.trim() === "") continue;
if (file?.truncated === true) truncatedSeen = true;
const kind = changeKind(file?.kind);
const parsed = parseUnifiedPatch(file?.patch);
const existing = entries.get(path);
const mergedSteps = existing ? [...existing.steps] : [];
if (!mergedSteps.includes(stage)) mergedSteps.push(stage);
const patchParts = [];
if (existing && existing.patch != null) patchParts.push(existing.patch);
if (typeof file?.patch === "string" && file.patch.trim() !== "") patchParts.push(file.patch);
const joinedPatch = patchParts.join("\n");
// The last recorded step wins every per-file fact: the summary is the
// final state, not an accumulation of the visits on the way there.
entries.set(path, {
path,
// A later step wins the kind: it is the observed state the run left.
kind: existing == null || kind !== ChangeKind.Other ? kind : existing.kind,
added: (existing?.added ?? 0) + parsed.added,
removed: (existing?.removed ?? 0) + parsed.removed,
binary: existing?.binary === true || file?.binary === true,
truncated: existing?.truncated === true || file?.truncated === true,
// Keep the first-seen before-mode and the last-seen after-mode, so the
// pair describes the run's net effect on the file.
beforeMode: existing && existing.beforeMode != null ? existing.beforeMode : nullable(file?.before_mode),
afterMode: file?.after_mode != null ? file.after_mode : existing?.afterMode ?? null,
kind,
added: parsed.added,
removed: parsed.removed,
binary: file?.binary === true,
truncated: file?.truncated === true,
beforeMode: nullable(file?.before_mode),
afterMode: nullable(file?.after_mode),
otherModeChange:
existing?.otherModeChange === true ||
(file?.before_mode != null &&
file?.after_mode != null &&
file.before_mode !== file.after_mode &&
!file.binary &&
parsed.added === 0 &&
parsed.removed === 0),
file?.before_mode != null &&
file?.after_mode != null &&
file.before_mode !== file.after_mode &&
!file.binary &&
parsed.added === 0 &&
parsed.removed === 0,
steps: mergedSteps,
// Preserve every recorded textual patch for a path. A file may be
// changed by several stages, and retaining only the first one would
// make the displayed hunks disagree with the aggregate stat.
patch: joinedPatch.trim() !== "" ? joinedPatch : null,
patch: typeof file?.patch === "string" && file.patch.trim() !== "" ? file.patch : null,
});
}
}
const files = [...entries.values()];
const pending = stepsWithChanges === 0 && stepsPending > 0;
const totalPartial = partial || files.some((file) => file.truncated) || omitted > 0;
const totalPartial = partial || truncatedSeen || omitted > 0;
return {
files,
stepsWithChanges,
@@ -538,6 +548,12 @@ export function diffLineClass(kind) {
// Internals
// ---------------------------------------------------------------------------
/** A step's numeric sequence for ordering, with a missing/invalid value as 0. */
function sequenceOf(step) {
const value = Number(step?.sequence);
return Number.isFinite(value) ? value : 0;
}
/** An integer parsed from a strictly-numeric string, or null. */
function intOrNull(text) {
return /^[+-]?\d+$/.test(text) ? Number.parseInt(text, 10) : null;
+31 -6
View File
@@ -28,6 +28,7 @@ import {
runStateOf,
} from "./runs.js";
import { presentedArtifacts, sessionExportArtifact, displayVisit } from "./artifacts.js";
import { changeStat, parseUnifiedPatch } from "./changes.js";
import { effectiveStageType } from "./templates.js";
// ---------------------------------------------------------------------------
@@ -696,14 +697,25 @@ export function artifactBaseName(name) {
// ---------------------------------------------------------------------------
/**
* One changed-file line, e.g. `modified src/a.kt (binary) (truncated)`. Mirrors
* Format.kt fileChangeLine.
* One changed-file line, e.g. `modified src/a.kt +3 -2 (truncated)`. The kind,
* path and binary/truncated markers are Format.kt's exact spelling; the `+N -M`
* stat is added when the recorded patch is readable (not binary) and parses to
* at least one hunk, so a line never claims a line count it could not read. A
* binary file keeps its marker and never gets a text stat.
*/
export function fileChangeLine(file) {
const base = `${str(file?.kind)} ${str(file?.path)}`;
const binary = file?.binary ? " (binary)" : "";
const truncated = file?.truncated ? " (truncated)" : "";
return base + binary + truncated;
let stat = "";
if (!file?.binary) {
const patch = str(file?.patch);
if (patch.trim() !== "") {
const parsed = parseUnifiedPatch(patch);
if (parsed.hunks.length > 0) stat = changeStat(parsed.added, parsed.removed);
}
}
return base + (stat !== "" ? ` ${stat}` : "") + binary + truncated;
}
/** One notification receipt, e.g. `delivered → ntfy · ok`, skipping a blank diagnostic. */
@@ -714,12 +726,16 @@ export function notificationLine(receipt) {
}
/**
* A compact file-change summary, e.g. `partial (2 files), 1 skipped`. Blank
* parts are omitted; an entirely blank change set renders as "".
* A compact file-change summary, e.g.
* `partial (2 files), 1 skipped, 3 omitted · Excluded protected files.`.
* The status word, file count, skipped and omitted counts are the capture's own
* honest facts; the trimmed diagnostic follows after ` · ` when present. Blank
* parts are omitted, and an entirely blank change set renders as "".
*/
export function fileChangesSummary(changes) {
let text = "";
if (str(changes?.status).trim() !== "") text += str(changes.status);
const status = str(changes?.status).trim();
if (status !== "") text += status;
const files = changes?.files ?? [];
if (files.length > 0) {
if (text !== "") text += " ";
@@ -729,6 +745,15 @@ export function fileChangesSummary(changes) {
if (text !== "") text += ", ";
text += `${changes.skipped} skipped`;
}
if (Number(changes?.omitted) > 0) {
if (text !== "") text += ", ";
text += `${changes.omitted} omitted`;
}
const diagnostic = str(changes?.diagnostic).trim();
if (diagnostic !== "") {
if (text !== "") text += " · ";
text += diagnostic;
}
return text;
}
+14 -4
View File
@@ -152,6 +152,12 @@ function renderAttentionSheet() {
);
const body = h("div", { class: "attention-sheet-body" });
// One count for the whole open sheet: only repeated labels need the run id
// appended, so dismissing stays unambiguous without noisy names elsewhere.
const labelCounts = new Map();
for (const entry of entries) {
labelCounts.set(entry.label, (labelCounts.get(entry.label) ?? 0) + 1);
}
if (entries.length === 0) {
body.append(h("p", { class: "attention-empty", text: "Nothing needs you right now." }));
} else {
@@ -163,7 +169,7 @@ function renderAttentionSheet() {
onclick: clearAttentionSheet,
}),
);
for (const entry of entries) body.append(renderAttentionRow(entry));
for (const entry of entries) body.append(renderAttentionRow(entry, labelCounts));
}
const sheet = h("div", { class: "attention-sheet-panel", tabindex: "-1" }, head, body);
@@ -172,8 +178,12 @@ function renderAttentionSheet() {
}
/** One attention row: status icon, the two text lines, and a trailing Dismiss. */
function renderAttentionRow(entry) {
function renderAttentionRow(entry, labelCounts = null) {
const glyphState = entry.kind === AttentionKind.Decision ? "waiting" : "failed";
const repeated = (labelCounts?.get(entry.label) ?? 0) > 1;
const dismissLabel = repeated
? `Dismiss ${entry.label} (run ${entry.runId})`
: `Dismiss ${entry.label}`;
const open = h(
"button",
{
@@ -198,8 +208,8 @@ function renderAttentionRow(entry) {
const dismiss = h("button", {
class: "attention-dismiss",
type: "button",
"aria-label": "Dismiss",
title: "Dismiss",
"aria-label": dismissLabel,
title: dismissLabel,
onclick: (event) => {
// The trailing control must never activate the row it sits in.
event.stopPropagation();
+46 -22
View File
@@ -1504,24 +1504,39 @@ function fillChatRows(rows) {
const active = filtered.filter((session) => !session.closed);
const closed = filtered.filter((session) => session.closed);
// Titles are often repeated ("New chat"); compute the duplicates once so the
// per-row actions name can include the session id only when it is needed.
const duplicateTitles = duplicateChatTitles(filtered);
const groups = groupSessionsByDirectory(active);
if (groups.length > 1) {
for (const group of groups) {
rows.append(h("div", { class: "chat-group-header", text: directoryLabel(group.directory) }));
for (const session of group.sessions) rows.append(renderChatRow(session));
for (const session of group.sessions) rows.append(renderChatRow(session, duplicateTitles));
}
} else {
for (const session of active) rows.append(renderChatRow(session));
for (const session of active) rows.append(renderChatRow(session, duplicateTitles));
}
if (closed.length > 0) {
rows.append(h("div", { class: "chat-group-header", text: CLOSED_SECTION_LABEL }));
for (const session of closed) rows.append(renderChatRow(session));
for (const session of closed) rows.append(renderChatRow(session, duplicateTitles));
}
if (state.chatError) {
rows.append(h("div", { class: "chat-error muted", text: state.chatError }));
}
}
/** The titles shared by more than one rendered session, for unique action names. */
function duplicateChatTitles(sessions) {
const counts = new Map();
for (const session of sessions) {
const title = sessionTitle(session);
counts.set(title, (counts.get(title) ?? 0) + 1);
}
return new Set(
[...counts.entries()].filter(([, count]) => count > 1).map(([title]) => title),
);
}
function chatEmpty(message) {
return h("div", { class: "empty" }, h("span", { class: "muted", text: message }));
}
@@ -1531,7 +1546,7 @@ function chatEmpty(message) {
* activity badge word, the work-label meta line and the close/reopen action.
* Every server string is set with textContent.
*/
function renderChatRow(session) {
function renderChatRow(session, duplicateTitles = new Set()) {
const open = state.chatActiveId === session.id;
const thread = state.chatThreads.get(session.id) ?? null;
const unseen =
@@ -1543,23 +1558,28 @@ function renderChatRow(session) {
});
const activity = sessionActivity(thread?.running === true, unseen);
const badge = sessionActivityBadge(activity, open);
// The row is a plain container (M6): the session title/meta area is the native
// button and the Chat actions control is its sibling, not a child.
const row = h("div", {
class: `row chat-row${open ? " selected" : ""}`,
role: "button",
tabindex: "0",
"data-session": session.id,
onclick: () => openChatSession(session.id),
onkeydown: (event) => {
// Only the row itself opens on Enter/Space; the Chat actions menu handles
// its own keyboard activation (and must not double-fire).
if (event.target !== event.currentTarget) return;
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
openChatSession(session.id);
}
});
// Keep background and programmatic clicks opening the session, but never
// double-fire when a real control (session button or actions) was clicked.
row.addEventListener("click", (event) => {
const target = event.target;
if (target instanceof Element && target.closest("button, a")) return;
openChatSession(session.id);
});
const sessionButton = h("button", {
class: "chat-session-button",
type: "button",
onclick: (event) => {
event.stopPropagation();
openChatSession(session.id);
},
});
const head = h("div", { class: "row-head" });
const head = h("span", { class: "row-head" });
head.append(h("span", { class: "row-title chat-row-title", text: sessionTitle(session) }));
const chip = sessionChipLabel(session);
if (chip) head.append(h("span", { class: "chip chat-kind-chip", text: chip }));
@@ -1572,14 +1592,14 @@ function renderChatRow(session) {
),
);
}
row.append(head);
row.append(
sessionButton.append(head);
sessionButton.append(
h("span", {
class: "row-meta chat-row-meta",
text: sessionMeta(session, sessionWorkLabel(session.busy === true, thread)),
}),
);
row.append(renderChatActionsMenu(session));
row.append(sessionButton, renderChatActionsMenu(session, duplicateTitles));
return row;
}
@@ -1707,18 +1727,22 @@ function renderChatCreate() {
* Close chat… (open) or Reopen (closed), then Hide on this device. Closing is the
* shared, server-side finish; hiding only affects this device and says so.
*/
function renderChatActionsMenu(session) {
function renderChatActionsMenu(session, duplicateTitles = new Set()) {
const wrap = h("div", { class: "chat-row-actions chat-menu-wrap" });
const expanded = state.chatMenu === session.id;
const title = sessionTitle(session);
const actionLabel = duplicateTitles.has(title)
? `${CHAT_ACTIONS_LABEL} for ${title} (${session.id})`
: `${CHAT_ACTIONS_LABEL} for ${title}`;
wrap.append(
h("button", {
class: "ghost chat-menu-button",
type: "button",
text: "⋯",
"aria-label": CHAT_ACTIONS_LABEL,
"aria-label": actionLabel,
"aria-haspopup": "menu",
"aria-expanded": expanded ? "true" : "false",
title: CHAT_ACTIONS_LABEL,
title: actionLabel,
onclick: (event) => {
event.stopPropagation();
openChatMenu(session.id);
+27 -10
View File
@@ -71,6 +71,7 @@ import {
runChanges,
runChangesHeader,
runChangesNote,
showRunChangesSummary,
} from "../changes.js";
import {
DECISION_ACTION,
@@ -217,12 +218,15 @@ function renderRunSummaryTab(d, now) {
);
// The run-level Changes (parity R4), collapsed by default like the Android
// summary: the observed workspace diff. Its header alone states the file count
// and aggregate stat until expanded, and every file row opens the diff viewer.
const changes = runChanges(d.steps ?? []);
wrap.append(
renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)),
);
// summary: the observed final-state workspace diff. Only a succeeded run has a
// settled final state to present; a failed run keeps its evidence in each
// visit's own capture (a deliberate divergence from Android, see PARITY R4).
if (showRunChangesSummary(d.status)) {
const changes = runChanges(d.steps ?? []);
wrap.append(
renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)),
);
}
return wrap;
}
@@ -841,7 +845,14 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
const kind = artifactKind(artifact.content_type, artifact.name);
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
const name = artifact.name || "(unnamed artifact)";
const tile = h("div", { class: "artifact-tile clickable" });
// The tile is the native control (M5): Enter/Space activate it for free, and
// the Copy link / Share buttons are siblings in the wrapper, never children.
const wrap = h("div", { class: "artifact-tile-wrap" });
const tile = h("button", {
class: "artifact-tile clickable",
type: "button",
"aria-label": `Open ${name}`,
});
const openViewer = () => {
const at = viewerIndexOf.get(artifact.url);
if (at != null) openArtifactViewer(viewable, at);
@@ -855,7 +866,13 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
tile.append(img);
tile.addEventListener("click", openViewer);
} else if (kind === ArtifactKind.Video) {
tile.append(h("div", { class: "artifact-poster" }, h("span", { class: "artifact-play", text: "▶" })));
tile.append(
h(
"div",
{ class: "artifact-poster" },
h("span", { class: "artifact-play", "aria-hidden": "true", text: "▶" }),
),
);
tile.append(h("div", { class: "artifact-name", text: name }));
tile.addEventListener("click", openViewer);
} else {
@@ -866,8 +883,8 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
);
tile.addEventListener("click", openTab);
}
tile.append(renderTileActions(resolved, media));
return tile;
wrap.append(tile, renderTileActions(resolved, media));
return wrap;
}
/** The compact per-tile actions: copy-link (non-media tiles) and share. */