web: gated access, anchored viewers, mobile tabs and chat colour

- serve.mjs requires a signed session cookie for every page, artifact and the
  WebSocket, with a password file, 30-day sessions, login throttling and public
  brand assets for the sign-in page.
- The diff viewer is a fixed-height top-anchored panel whose toolbar (modes,
  copy, previous, next, close as icons) is its first row; the artifact viewer is
  likewise a fixed frame so its navigation never moves.
- The audit's selected tab uses the app's normal selected surface and bottom
  accent. Sessions that were not recorded say so plainly.
- Chat code blocks are syntax-coloured; graph pinch-zoom works with two fingers
  while a single pointer still pans and clicks nodes.
- Phones always keep the destination bar (pane collapse is wide-only), with the
  destinations spread evenly and Search on the right; the list default width is
  narrower; the theme colour matches the app.
- Code-format and layout tests, plus the full browser suite, pass.
This commit is contained in:
2026-10-20 02:21:51 +01:00
parent d7763ec466
commit ebf02c3bed
17 changed files with 558 additions and 42 deletions
+16 -3
View File
@@ -603,7 +603,9 @@ const dock = h(
"nav",
{ id: "destinationDock", class: "destination-dock", "aria-label": "Destinations" },
h("div", { class: "dock-status-row" }, dockStatus, dockSettings),
h("div", { class: "dock-row" }, dockSearch, dockDestinations),
// The destinations come first and Search sits on the right; every item takes
// an equal share of the bar on a phone.
h("div", { class: "dock-row" }, dockDestinations, dockSearch),
);
// The attention sheet lives in its own layer so it can overlay any view without
// being torn down by a content re-render; renderAttentionSheet rebuilds it.
@@ -618,6 +620,15 @@ document.body.append(h("div", { class: "app-root" }, appRail, workspace, dock));
appRail.querySelector("#railCollapse")?.addEventListener("click", () => {
state.railCollapsed = !state.railCollapsed;
applyLayoutState();
if (typeof window.matchMedia === "function") {
const wideQuery = window.matchMedia("(min-width: 600px)");
const onWideChange = () => {
applyLayoutState();
renderContent();
};
if (typeof wideQuery.addEventListener === "function") wideQuery.addEventListener("change", onWideChange);
else if (typeof wideQuery.addListener === "function") wideQuery.addListener(onWideChange);
}
});
document.addEventListener("click", (event) => {
const button = event.target instanceof Element ? event.target.closest("#listCollapse") : null;
@@ -938,7 +949,7 @@ function listCollapseButton() {
}
function applyLayoutState() {
appRail.classList.toggle("collapsed", state.railCollapsed === true);
appRail.classList.toggle("collapsed", state.railCollapsed === true && isWideLayout());
const railButton = document.getElementById("railCollapse");
if (railButton) {
const label = state.railCollapsed ? "Expand navigation" : "Collapse navigation";
@@ -1129,7 +1140,9 @@ function renderContent() {
const activePane = detailOpen ? "detail" : "list";
const model = detailSections();
const layout = h("div", {
class: `pane-layout${state.listCollapsed ? " list-collapsed" : ""}`,
// Collapsing a pane is a wide-screen affordance; a phone always keeps the
// list and the bottom destination bar available.
class: `pane-layout${state.listCollapsed && isWideLayout() ? " list-collapsed" : ""}`,
"data-active-pane": activePane,
});
+71
View File
@@ -1357,9 +1357,33 @@ export function mount(container, graph, options = {}) {
let pointerId = null;
let dragOrigin = null;
let lastPoint = null;
const pointers = new Map();
let pinch = null;
function onPointerDown(event) {
if (event.button !== 0) return;
// No pointer capture: capturing retargeted the following click to the
// viewport and swallowed node taps. A pinch that leaves the canvas simply
// stops updating until the fingers return.
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const rect = viewport.getBoundingClientRect();
pinch = {
distance: Math.hypot(a.x - b.x, a.y - b.y),
scale: state.scale,
lastCentroid: {
x: (a.x + b.x) / 2 - rect.left,
y: (a.y + b.y) / 2 - rect.top,
},
};
dragged = true;
pointerId = null;
dragOrigin = null;
lastPoint = null;
return;
}
if (pointers.size > 2) return;
dragged = false;
pointerId = event.pointerId;
dragOrigin = { x: event.clientX, y: event.clientY };
@@ -1367,6 +1391,44 @@ export function mount(container, graph, options = {}) {
}
function onPointerMove(event) {
if (pointers.has(event.pointerId)) {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
}
if (pointers.size >= 2 && pinch) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinch.distance <= 0 || distance <= 0) return;
const rect = viewport.getBoundingClientRect();
const centroid = {
x: (a.x + b.x) / 2 - rect.left,
y: (a.y + b.y) / 2 - rect.top,
};
const target = Math.min(
Math.max(pinch.scale * (distance / pinch.distance), MIN_SCALE),
MAX_SCALE,
);
const zoomed = zoomAbout(
state.offset,
state.scale,
centroid,
target / state.scale,
MIN_SCALE,
MAX_SCALE,
);
const dx = centroid.x - pinch.lastCentroid.x;
const dy = centroid.y - pinch.lastCentroid.y;
state.scale = zoomed.scale;
state.offset = clampOffset(
{ x: zoomed.offset.x + dx, y: zoomed.offset.y + dy },
scaledContent(),
viewportSize(),
MIN_VISIBLE,
);
pinch.lastCentroid = centroid;
state.userAdjusted = true;
applyTransform();
return;
}
if (pointerId === null || event.pointerId !== pointerId || !lastPoint) return;
if (!dragged) {
const moved =
@@ -1388,10 +1450,19 @@ export function mount(container, graph, options = {}) {
}
function onPointerUp(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinch = null;
if (pointerId !== null && event.pointerId !== pointerId) return;
pointerId = null;
dragOrigin = null;
lastPoint = null;
// After a pinch, continue with the finger still down as a pan.
if (pointers.size === 1) {
const [id, point] = [...pointers.entries()][0];
pointerId = id;
dragOrigin = { ...point };
lastPoint = { ...point };
}
}
function onWheel(event) {
+75
View File
@@ -0,0 +1,75 @@
// A small, dependency-free syntax colourer for fenced code in chat. It returns
// tokens, never HTML: the renderer appends spans with text nodes, so no model
// output can inject markup. Unknown languages still get strings, comments and
// numbers highlighted with the generic keyword set.
const KEYWORDS = {
go: "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var true false nil iota",
javascript:
"async await break case catch class const continue debugger default delete do else export extends finally for from function get if import in instanceof let new of return set static super switch this throw try typeof var void while with yield true false null undefined",
typescript:
"abstract any as asserts async await boolean break case catch class const constructor continue declare default delete do else enum export extends false finally for from function get if implements import in infer instanceof interface is keyof let module namespace never new null number object of package private protected public readonly require return set static string super switch symbol this throw true try type typeof undefined unique unknown var void while with yield",
kotlin:
"as break class continue do else false for fun if in interface is null object package return super this throw true try typealias typeof val var when while by catch constructor delegate dynamic field file finally get import init param property receiver set setparam where actual abstract annotation companion const crossinline data enum expect external final infix inline inner internal lateinit noinline open operator out override private protected public reified sealed suspend tailrec vararg",
java: "abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while true false null",
shell:
"if then else elif fi for while until do done case esac function in select time coproc break continue return exit export readonly local declare typeset unset shift source alias echo cd pwd set true false",
bash:
"if then else elif fi for while until do done case esac function in select time coproc break continue return exit export readonly local declare typeset unset shift source alias echo cd pwd set true false",
python:
"and as assert async await break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield match case",
rust:
"as async await break const continue crate dyn else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while",
sql: "select from where insert into values update set delete create table alter drop index join left right inner outer group by order having limit offset as and or not null true false distinct union all",
json: "true false null",
};
const HASH_COMMENT = new Set(["shell", "bash", "python", "ruby", "yaml", "toml"]);
function languageKey(language) {
const key = String(language ?? "").trim().toLowerCase().split(/[\s:]/)[0];
if (key === "js" || key === "jsx") return "javascript";
if (key === "ts" || key === "tsx") return "typescript";
if (key === "sh" || key === "zsh") return "shell";
if (key === "py") return "python";
if (key === "kt") return "kotlin";
if (key === "rs") return "rust";
return key;
}
/**
* Tokenize one code block into `{text, kind}` with kind plain|comment|string|
* number|keyword|literal. Total and deterministic.
*/
export function highlight(code, language = "") {
const key = languageKey(language);
const keywords = new Set((KEYWORDS[key] ?? KEYWORDS.javascript).split(/\s+/).filter(Boolean));
const commentPattern = HASH_COMMENT.has(key) ? "#[^\\n]*" : key === "sql" ? "--[^\\n]*" : "\\/\\/[^\\n]*";
const pattern = new RegExp(
`(\\/\\*[\\s\\S]*?\\*\\/|${commentPattern}|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\b\\d+(?:\\.\\d+)?\\b|[A-Za-z_$][\\w$]*)`,
"g",
);
const text = String(code ?? "");
const tokens = [];
let last = 0;
for (const match of text.matchAll(pattern)) {
if (match.index > last) tokens.push({ text: text.slice(last, match.index), kind: "plain" });
const value = match[0];
let kind = "plain";
if (value.startsWith("//") || value.startsWith("#") || value.startsWith("--") || value.startsWith("/*")) {
kind = "comment";
} else if (/^["'`]/.test(value)) {
kind = "string";
} else if (/^\d/.test(value)) {
kind = "number";
} else if (keywords.has(value)) {
kind = value === "true" || value === "false" || value === "null" || value === "None" ||
value === "nil" || value === "True" || value === "False"
? "literal"
: "keyword";
}
tokens.push({ text: value, kind });
last = match.index + value.length;
}
if (last < text.length) tokens.push({ text: text.slice(last), kind: "plain" });
return tokens;
}
+9 -1
View File
@@ -8,6 +8,7 @@ import { writeChatStars } from "../chatStars.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
import { highlight } from "../highlight.js";
import { formatDuration } from "../runs.js";
import { humanBytes } from "../artifacts.js";
import { changeStat, diffLineClass, diffLineSymbol } from "../changes.js";
@@ -2710,7 +2711,14 @@ function renderMarkdownBlock(block) {
if (block.kind === "code") {
const code = h("div", { class: "md-code-block" });
code.append(h("div", { class: "md-code-label", text: codeBlockLabel(block.language) }));
code.append(h("pre", { class: "md-pre" }, h("code", { text: block.code })));
const pre = h("pre", { class: "md-pre" });
const body = h("code");
for (const token of highlight(block.code, block.language)) {
if (token.kind === "plain") body.append(document.createTextNode(token.text));
else body.append(h("span", { class: `tok-${token.kind}`, text: token.text }));
}
pre.append(body);
code.append(pre);
return code;
}
if (block.kind === "rule") return h("hr", { class: "md-rule" });
+31 -23
View File
@@ -114,24 +114,7 @@ function openChangeViewer(files, startIndex, trigger = null) {
text: `${changePositionLabel(index, files.length)} · changed by ${(entry.steps ?? []).join(" → ")}`,
}),
);
const head = h(
"div",
{ class: "change-viewer-head" },
titles,
h("button", {
class: "change-viewer-copy",
type: "button",
text: "Copy raw patch",
disabled: !hasPatch,
onclick: () => copyText(entry.patch ?? ""),
}),
h("button", {
class: "change-viewer-close",
type: "button",
text: "Close diff",
onclick: closeChangeViewer,
}),
);
const head = h("div", { class: "change-viewer-head" }, titles);
const controls = h(
"div",
@@ -160,10 +143,22 @@ function openChangeViewer(files, startIndex, trigger = null) {
}),
h("div", { class: "change-viewer-spacer" }),
h("button", {
class: "change-page",
class: "change-icon",
type: "button",
"data-action": "copy",
title: "Copy raw patch",
"aria-label": "Copy raw patch",
text: "\u29c9",
disabled: !hasPatch,
onclick: () => copyText(entry.patch ?? ""),
}),
h("button", {
class: "change-icon",
type: "button",
"data-page": "prev",
text: "Previous file",
title: "Previous file",
"aria-label": "Previous file",
text: "\u2039",
disabled: index === 0,
onclick: () => {
index = Math.max(index - 1, 0);
@@ -172,10 +167,12 @@ function openChangeViewer(files, startIndex, trigger = null) {
},
}),
h("button", {
class: "change-page",
class: "change-icon",
type: "button",
"data-page": "next",
text: "Next file",
title: "Next file",
"aria-label": "Next file",
text: "\u203a",
disabled: index === files.length - 1,
onclick: () => {
index = Math.min(index + 1, files.length - 1);
@@ -183,6 +180,15 @@ function openChangeViewer(files, startIndex, trigger = null) {
renderViewer();
},
}),
h("button", {
class: "change-icon",
type: "button",
"data-action": "close",
title: "Close diff",
"aria-label": "Close diff",
text: "\u00d7",
onclick: closeChangeViewer,
}),
);
const body = h("div", { class: "change-viewer-body" });
@@ -199,7 +205,9 @@ function openChangeViewer(files, startIndex, trigger = null) {
body.append(renderRenderedDiff(entry));
}
panel.replaceChildren(head, controls, body);
// The toolbar is the first row: paging/copy/close never move when the
// path or the diff length changes.
panel.replaceChildren(controls, head, body);
};
renderViewer();
+6 -1
View File
@@ -305,7 +305,12 @@ function auditArtifact(step, name, emptyMessage) {
/** The exported session, rendered in place, with the raw file one click away. */
function auditSession(step) {
const artifact = systemArtifacts(step).find((entry) => entry.name === "session.html");
if (!artifact) return renderSessionExport(step);
if (!artifact) {
return h("div", {
class: "muted",
text: "Session not recorded for this visit. Sessions are exported by model stages.",
});
}
const resolved = resolvedArtifactUrl(artifact, state.url);
const wrap = h("div", { class: "audit-session" });
if (!resolved) {