Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

redact: Insights › Masking shows how masking works, with Little Magpie, folded until opened

yetonecad7bbbdb77d
diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html
index c6ea695b1..054402c06 100644
--- a/internal/gui/assets/index.html
+++ b/internal/gui/assets/index.html
@@ -514,6 +514,7 @@
<script src="context.js"></script>
<script src="plugins/usage/page.js"></script>
<script src="plugins/redact/page.js"></script>
+<script src="plugins/redact/demo.js"></script>
<script src="plugins/otel/page.js"></script>
<script src="plugins/gateway/settings.js"></script>
<script src="start.js"></script>
diff --git a/internal/gui/assets/plugins/redact/client.js b/internal/gui/assets/plugins/redact/client.js
index 80422515d..9c05e3a5c 100644
--- a/internal/gui/assets/plugins/redact/client.js
+++ b/internal/gui/assets/plugins/redact/client.js
@@ -4,7 +4,8 @@
// i18n.js beside this file. This file registers the page and its markup,
// before app.js; page.js, after app.js, is the page's code. The card on
// top says how much was masked over 7 or 30 days and where it went, the
-// list under it each request (or each value) masking changed, and a
+// list under it each request (or each value) masking changed (between
+// them, folded, demo.js's 小鹊 shows how masking works), and a
// request opened says what it carried, what the vendor got instead, and
// how each value was found and put back. The hooks are what the shell
// asks of it: open, refresh (the window came back), reload (Refresh in
@@ -15,6 +16,15 @@ magpie.plugin("redact", (ctx) => {
title: "Masking",
html: `
<section class="msk-card" id="maskCard"></section>
+ <section class="msk-demo" id="maskDemo">
+ <button type="button" class="md-row" id="mdRow" aria-expanded="false" aria-controls="mdBody">
+ <span class="md-thumb" aria-hidden="true"></span>
+ <span class="md-words"><span class="md-name" data-t>How masking works</span><span class="md-sub" data-t>Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer</span></span>
+ <span class="md-len">0:27</span>
+ <svg class="md-chev" viewBox="0 0 16 16" width="12" height="12" aria-hidden="true"><path d="m6 3.5 4.5 4.5L6 12.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
+ </button>
+ <div class="md-body" id="mdBody" hidden></div>
+ </section>
<section class="msk-list" id="maskList"></section>
<section class="msk-one" id="maskOne" hidden></section>
`,
diff --git a/internal/gui/assets/plugins/redact/demo.js b/internal/gui/assets/plugins/redact/demo.js
new file mode 100644
index 000000000..ff7a968cd
--- /dev/null
+++ b/internal/gui/assets/plugins/redact/demo.js
@@ -0,0 +1,442 @@
+// Insights › Masking's demo (client.js has its row): 小鹊 takes one request
+// through masking. The letter comes to her before it leaves this computer,
+// she tears the password and the email out into her notebook and sticks
+// placeholders in their place, the provider answers with placeholders, and
+// she puts the values back before the browser on this computer signs in.
+//
+// She is a video, one take per theme, drawn on the card's own colour; the
+// sheets, the notebook and the boxes are the page's, moved over her. The
+// video is fetched when the row is first opened, never before. It plays
+// while the row is open and on screen, once through, and rests on its last
+// step; with reduced motion it starts there.
+
+const XQD_END = 27.5;
+const XQD_STEPS = [
+ [0, "You send a request", "You ask the agent to sign in to github.com with a password. The letter goes to Little Magpie first and hasn't left your computer yet."],
+ [5.4, "She reads it through", "Little Magpie opens the letter and reads it line by line for what shouldn't be sent: emails, passwords."],
+ [7.8, "Tearing out what's private", "The real values are torn out and written in her notebook. The notebook stays on your computer."],
+ [10.6, "Sticking on placeholders", "Placeholders fill the gaps. A value always gets the same one, so the model still understands."],
+ [12.8, "Off to the provider", "The letter is sealed and sent. The provider gets only placeholders."],
+ [15.6, "The answer calls the browser", "The model decides to call browser.login, and its arguments are placeholders too."],
+ [18.8, "Putting the values back", "When the answer comes, Little Magpie opens her notebook and turns each placeholder back into its value."],
+ [22.2, "Signing in on your computer", "The tool signs in with the real password on your computer. The password never left it."],
+];
+const XQD_MAIL = "[email protected]", XQD_PASS = "hunter2-prod";
+const XQD_PM = "{{EMAIL_r3tvb2ce}}", XQD_PP = "{{PASSWORD_k7q2m4xa}}";
+
+let xqd = null; // the demo, once its row has been opened
+
+document.addEventListener("click", (e) => {
+ if (e.target.closest?.("#mdRow")) maskDemoToggle();
+});
+
+function maskDemoToggle() {
+ const row = $("#mdRow"), body = $("#mdBody");
+ if (!row || !body) return;
+ const open = row.getAttribute("aria-expanded") !== "true";
+ row.setAttribute("aria-expanded", String(open));
+ body.hidden = !open;
+ // the kernel can draw the page again, and an old demo goes with it
+ if (open && !xqd?.root.isConnected) xqd = maskDemoBuild(body);
+ xqd?.wake();
+}
+
+// What a label says: data-t, so a change of language says it again.
+const xqdSay = (cls, text) => { const s = el("span", cls, t(text)); s.dataset.t = ""; s.dataset.en = text; return s; };
+const xqdIcon = {
+ you: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><circle cx="12" cy="8" r="4"/><path d="M4 21c1.5-4 4.5-6 8-6s6.5 2 8 6"/></svg>',
+ book: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 4h11a3 3 0 0 1 3 3v13H8a3 3 0 0 1-3-3z"/><path d="M5 17a3 3 0 0 1 3-3h11"/></svg>',
+ lock: '<svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>',
+ check: (n) => `<svg width="${n}" height="${n}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>`,
+ server: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="7" rx="2"/><rect x="4" y="13" width="16" height="7" rx="2"/><path d="M8 7.5h.01M8 16.5h.01"/></svg>',
+ env: (seal) => `<svg class="xq-env xq-mv" viewBox="-2 -1 82 58" aria-hidden="true"><rect x="1.5" y="4" width="76" height="50" rx="6" fill="var(--xq-env-shadow)"/><rect x="1" y="1" width="76" height="50" rx="5" fill="var(--xq-paper)" stroke="var(--faint)" stroke-width="1.2"/><path d="M2 3l37 26L76 3" fill="none" stroke="var(--faint)" stroke-width="1.2"/><circle cx="39" cy="28" r="8" fill="${seal}"/><circle cx="39" cy="28" r="4.5" fill="none" stroke="#fff" stroke-opacity=".5" stroke-width="1.3"/></svg>`,
+ pause: '<svg width="12" height="12" viewBox="0 0 12 12"><rect x="2" y="1.5" width="2.6" height="9" rx="1" fill="currentColor"/><rect x="7.4" y="1.5" width="2.6" height="9" rx="1" fill="currentColor"/></svg>',
+ play: '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 1.8v8.4a.6.6 0 0 0 .9.5l7-4.2a.6.6 0 0 0 0-1L3.9 1.3a.6.6 0 0 0-.9.5z" fill="currentColor"/></svg>',
+};
+
+// The stage is drawn at 1000×420 and scaled to the card's width.
+function maskDemoStage() {
+ const stage = el("div", "xq-stage");
+ const at = (node, k) => { node.dataset.k = k; return node; };
+ const box = (k, icon, title, sub) => {
+ const b = at(el("div", "xq-box"), k), h = el("div", "xq-bh"), ic = el("div", "xq-ic" + (icon === "book" ? " acc" : ""));
+ ic.innerHTML = xqdIcon[icon];
+ const words = el("div");
+ words.append(xqdSay("xq-h", title));
+ if (sub) words.append(xqdSay("xq-sub", sub));
+ h.append(ic, words);
+ b.append(h);
+ return b;
+ };
+ const lane = (x, far, text) => { const l = el("div", "xq-lane"); l.style.left = x + "px"; l.append(el("span", "xq-dot" + (far ? " far" : "")), xqdSay("", text)); return l; };
+ const divider = el("div", "xq-divider");
+ divider.append(xqdSay("", "Over the network"));
+
+ const req = box("req", "you", "You tell the agent");
+ req.append(at(el("div", "xq-msg"), "reqmsg"));
+
+ const ledger = box("ledger", "book", "Little Magpie's notebook", "Kept on your computer only");
+ ledger.append(at(xqdSay("xq-lempty", "Nothing in it yet"), "lempty"));
+ [[XQD_PM, XQD_MAIL, 40], [XQD_PP, XQD_PASS, 81]].forEach(([code, real, top], i) => {
+ const r = at(el("div", "xq-lrow xq-mv"), "row" + i);
+ r.style.top = top + "px";
+ r.append(el("span", "xq-lc xq-pillc", code), el("span", "xq-lv", real));
+ ledger.append(r);
+ });
+
+ const browser = at(el("div", "xq-box"), "browser"), bar = el("div", "xq-bbar");
+ bar.innerHTML = `<i></i><i></i><i></i><div class="xq-url">${xqdIcon.lock}github.com/login</div>`;
+ const form = el("div", "xq-bform"), fu = at(el("div", "xq-field"), "fu"), fp = at(el("div", "xq-field"), "fp"), btn = el("div", "xq-bbtn");
+ btn.append(xqdSay("", "Sign in"));
+ form.append(fu, fp, btn);
+ const ok = at(el("div", "xq-bok xq-mv"), "bok"), chk = el("div", "xq-chk");
+ chk.innerHTML = xqdIcon.check(16);
+ ok.append(chk, xqdSay("", "Signed in to github.com"), xqdSay("xq-sub", "The tool runs on your computer"));
+ browser.append(bar, form, ok);
+
+ const xq = at(el("div", "xq-her"), "her");
+ xq.setAttribute("aria-hidden", "true");
+ const vid = el("video");
+ vid.muted = true; vid.playsInline = true; vid.preload = "auto";
+ vid.setAttribute("muted", ""); vid.setAttribute("playsinline", "");
+ xq.append(vid);
+
+ const slot = (k, real, code, hole, ok) => {
+ const s = at(el("span", "xq-slot"), k);
+ if (hole) s.append(el("span", "xq-hole"));
+ s.append(el("span", "xq-real xq-mv" + (ok ? " ok" : ""), real), el("span", "xq-code xq-mv", code));
+ return s;
+ };
+ const line = (label, ...rest) => { const l = el("div", "xq-ln"); if (label) l.append(xqdSay("xq-k", label)); l.append(...rest); return l; };
+ const paper = (k, head, side) => { const p = at(el("div", "xq-paper xq-mv"), k), ph = el("div", "xq-ph"); ph.append(xqdSay("", head), xqdSay("", side)); p.append(ph); return p; };
+ const letter = paper("letter", "Letter to the provider", "Agent → model");
+ letter.append(line("The job", xqdSay("", "Sign in to github.com")), line("Account", slot("s0", XQD_MAIL, XQD_PM, true)), line("Password", slot("s1", XQD_PASS, XQD_PP, true)));
+ const reply = paper("reply", "The provider's answer", "Calls a tool"), fn = el("div", "xq-ln");
+ fn.append(el("span", "xq-fn", "browser.login"), el("span", "xq-arg", "url: github.com"));
+ reply.append(fn, line("", el("span", "xq-k", "username"), slot("r0", XQD_MAIL, XQD_PM, false, true)), line("", el("span", "xq-k", "password"), slot("r1", XQD_PASS, XQD_PP, false, true)));
+
+ const prov = box("prov", "server", "Model service", "Remote, not on your computer");
+ const pin = at(el("div", "xq-psec xq-mv"), "pin");
+ const pline = (...n) => { const p = el("div", "xq-pline"); p.append(...n); return p; };
+ pin.append(xqdSay("xq-cap", "Letter it got"), pline(xqdSay("", "Sign in to github.com")), pline(xqdSay("", "Account"), el("span", "xq-pillc", XQD_PM)), pline(xqdSay("", "Password"), el("span", "xq-pillc", XQD_PP)));
+ const pout = at(el("div", "xq-psec xq-mv"), "pout"), think = at(el("div", "xq-think"), "think");
+ think.append(el("i", "xq-mv"), el("i", "xq-mv"), el("i", "xq-mv"));
+ const pcode = at(el("div", "xq-pcode xq-mv"), "pcode");
+ pcode.append("browser.login(", el("div", "xq-ind", "username:"), el("span", "xq-pillc", XQD_PM), el("div", "xq-ind", "password:"), el("span", "xq-pillc", XQD_PP), el("div", "", ")"));
+ pout.append(xqdSay("xq-cap", "Reply it wrote"), think, pcode);
+ const pnote = at(el("div", "xq-pnote xq-mv"), "pnote");
+ pnote.innerHTML = xqdIcon.check(12);
+ pnote.append(xqdSay("", "It saw only placeholders, never your password or email."));
+ prov.append(pin, pout, pnote);
+
+ stage.append(lane(18, false, "Your computer"), lane(802, true, "Provider"), divider, req, ledger, browser, xq, letter, reply, prov);
+ stage.insertAdjacentHTML("beforeend", xqdIcon.env("#3c63d8") + xqdIcon.env("#d6a03c"));
+ const [envA, envB] = stage.querySelectorAll(".xq-env");
+ at(envA, "envA"); at(envB, "envB");
+ const fly = (k, cls, text) => { const f = at(el("span", "xq-flyer xq-mv"), k); f.append(el("span", "xq-code " + cls, text)); return f; };
+ stage.append(fly("f0", "torn", XQD_MAIL), fly("f1", "torn", XQD_PASS), fly("g0", "back", XQD_MAIL), fly("g1", "back", XQD_PASS));
+ for (let i = 0; i < 6; i++) stage.append(at(el("i", "xq-trail xq-mv"), "t" + i));
+ return stage;
+}
+
+function maskDemoBuild(body) {
+ const root = el("div", "xqd"), vp = el("div", "xq-vp"), stage = maskDemoStage();
+ vp.append(stage);
+ const foot = el("div", "xq-foot"), capT = el("div", "xq-cap-t"), capB = el("div", "xq-cap-b");
+ foot.append(capT, capB);
+ const ctrl = el("div", "xq-ctrl"), play = el("button", "xq-play"), scrub = el("input", "xq-scrub");
+ play.type = "button";
+ scrub.type = "range"; scrub.min = "0"; scrub.max = "1000"; scrub.value = "0";
+ ctrl.append(play, scrub);
+ const steps = el("div", "xq-steps");
+ root.append(vp, foot, ctrl, steps);
+ body.append(root);
+
+ const q = (k) => stage.querySelector(`[data-k="${k}"]`);
+ const clamp = (v, a = 0, b = 1) => Math.min(b, Math.max(a, v));
+ const seg = (t, a, b) => clamp((t - a) / (b - a));
+ const lerp = (a, b, k) => a + (b - a) * k;
+ const eo = (k) => 1 - Math.pow(1 - k, 3);
+ const eio = (k) => k < .5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2;
+ const f2 = (v) => Math.round(v * 100) / 100;
+ // style writes are skipped when the value is the same, so a frame
+ // touches only what moved, and nothing per frame reads layout
+ const css = (e, prop, v) => { const c = e._c || (e._c = {}); if (c[prop] === v) return; c[prop] = v; e.style[prop] = v; };
+ const cls = (e, name, on) => { const c = e._c || (e._c = {}), k = "c:" + name; if (c[k] === on) return; c[k] = on; e.classList.toggle(name, on); };
+ const op = (e, v) => css(e, "opacity", String(f2(v)));
+
+ // her hands rest on the desk here in the video: sheets are handed to and
+ // taken from these points
+ const DESK = { L: [478, 262], R: [542, 262] };
+ const held = (side, tilt) => [DESK[side][0], DESK[side][1], tilt];
+ const ENV = .82, REQ = [126, 96], PROV = [893, 110], PROV_OUT = [860, 250], BROWSER = [126, 340], LC = [510, 333];
+ const OPEN = [510, 256, 0], SEND = held("R", -14), CATCH2 = held("R", -16);
+
+ const slots = {};
+ for (const k of ["s0", "s1", "r0", "r1"]) {
+ const s = q(k);
+ slots[k] = { el: s, real: s.querySelector(".xq-real"), code: s.querySelector(".xq-code"), hole: s.querySelector(".xq-hole") };
+ }
+ const flyers = ["f0", "f1", "g0", "g1"].map(q), rows = [q("row0"), q("row1")], rowCodes = rows.map((r) => r.querySelector(".xq-lc"));
+ const trails = [0, 1, 2, 3, 4, 5].map((i) => q("t" + i)), thinkDots = [...q("think").children];
+ const e = {};
+ for (const k of ["envA", "envB", "letter", "reply", "reqmsg", "lempty", "pin", "pout", "think", "pcode", "pnote", "fu", "fp", "bok"]) e[k] = q(k);
+
+ // stage-space box from offsets, which ignore transforms, so a sheet is
+ // measured where it lies on the desk whatever frame it is drawn in
+ const at = (n0) => { let x = 0, y = 0, n = n0; while (n && n !== stage) { x += n.offsetLeft; y += n.offsetTop; n = n.offsetParent; } return { x, y, w: n0.offsetWidth, h: n0.offsetHeight }; };
+ const LV = [];
+ const measure = () => {
+ for (const s of Object.values(slots)) {
+ s.rw = s.real.offsetWidth; s.cw = s.code.offsetWidth;
+ const b = at(s.el); s.x = b.x; s.y = b.y + b.h / 2;
+ if (s.el._c) delete s.el._c.width;
+ }
+ flyers.forEach((f) => { f._w = f.offsetWidth; f._h = f.offsetHeight; if (f._c) delete f._c.transform; });
+ rows.forEach((r, i) => { const b = at(r.querySelector(".xq-lv")); LV[i] = [b.x + Math.min(b.w, 130) / 2 + 6, b.y + b.h / 2]; });
+ };
+
+ const bez = (p0, p1, lift, k) => {
+ const c = [(p0[0] + p1[0]) / 2, Math.min(p0[1], p1[1]) - lift], u = 1 - k;
+ return [u * u * p0[0] + 2 * u * k * c[0] + k * k * p1[0], u * u * p0[1] + 2 * u * k * c[1] + k * k * p1[1]];
+ };
+ const place = (n, x, y, rot, sc, o) => { css(n, "transform", `translate(${f2(x)}px,${f2(y)}px) rotate(${f2(rot)}deg) scale(${f2(sc)})`); op(n, o); };
+ const placeC = (n, x, y, o) => { css(n, "transform", `translate(${f2(x - n._w / 2)}px,${f2(y - n._h / 2)}px)`); op(n, o); };
+ const drawTrail = (path, colour) => trails.forEach((d, i) => {
+ const kk = path ? path[3] - (i + 1) * .045 : 0;
+ if (!path || kk <= 0 || path[3] >= 1) return op(d, 0);
+ const [x, y] = bez(path[0], path[1], path[2], kk);
+ css(d, "transform", `translate(${f2(x)}px,${f2(y)}px)`);
+ css(d, "background", colour);
+ op(d, (1 - i / 6) * .45);
+ });
+ // a sheet between a hand (k = 0) and its place on the desk (k = 1)
+ const onDesk = (n, from, k, o) => place(n, lerp(from[0] - LC[0], 0, k), lerp(from[1] - LC[1], 0, k), lerp(from[2], 0, k), lerp(.22, 1, k), o);
+ const slotW = (s, w) => css(s.el, "width", Math.round(w) + "px");
+
+ // the request types itself, in the reader's language
+ let said = "", lastN = -1, lastSi = -1;
+ const reqText = () => t("Sign in to github.com for me with the password {pw}, the account is {email}.", { pw: XQD_PASS, email: XQD_MAIL });
+ const typed = (n) => {
+ const text = reqText(), shown = text.slice(0, n);
+ const frag = document.createDocumentFragment();
+ let i = 0;
+ for (const m of shown.matchAll(new RegExp(`${XQD_PASS}|${XQD_MAIL.replace(".", "\\.")}`, "g"))) {
+ frag.append(shown.slice(i, m.index), el("b", "", m[0]));
+ i = m.index + m[0].length;
+ }
+ frag.append(shown.slice(i));
+ return frag;
+ };
+
+ const stepBtns = XQD_STEPS.map(([at0, title]) => {
+ const b = el("button", "", t(title));
+ b.type = "button"; b.dataset.t = ""; b.dataset.en = title;
+ b.onclick = () => { seek(at0 + .01); render(T); sync(); };
+ steps.append(b);
+ return b;
+ });
+
+ function render(t0) {
+ const lang = document.documentElement.lang;
+ const len = reqText().length;
+ const n = Math.round(seg(t0, .2, 1.4) * len) * 2 + (t0 < 1.8 ? 1 : 0);
+ if (n !== lastN || lang !== said) {
+ lastN = n;
+ e.reqmsg.replaceChildren(typed(n >> 1));
+ if (n & 1) e.reqmsg.append(el("span", "xq-caret"));
+ }
+
+ // the envelope flies into her left hand, she brings it to her chest and
+ // opens it; later the sealed letter goes from her right hand to the provider
+ let path = null, colour = "#3c63d8";
+ if (t0 >= 1.6 && t0 < 3.0) {
+ const k = eio(seg(t0, 1.75, 3.0)), to = held("L", 18), [x, y] = bez(REQ, to, 60, k);
+ place(e.envA, x, y, lerp(-6, to[2], k), lerp(.5, ENV, eo(seg(t0, 1.6, 1.9))), seg(t0, 1.6, 1.75));
+ path = [REQ, to, 60, k];
+ } else if (t0 >= 3.0 && t0 < 4.95) {
+ const k = eio(seg(t0, 3.3, 3.9)), a = held("L", 18), b = OPEN;
+ place(e.envA, lerp(a[0], b[0], k), lerp(a[1], b[1], k), lerp(a[2], 0, k), ENV * (1 - .25 * seg(t0, 4.6, 4.95)), 1 - seg(t0, 4.7, 4.95));
+ } else if (t0 >= 12.9 && t0 < 13.65) {
+ const h = held("R", -14);
+ place(e.envA, h[0], h[1], h[2], ENV, seg(t0, 12.9, 13.05));
+ } else if (t0 >= 13.65 && t0 < 15.0) {
+ const k = eio(seg(t0, 13.65, 14.75)), [x, y] = bez(SEND, PROV, 50, k);
+ place(e.envA, x, y, lerp(SEND[2], 0, k), ENV * (1 - .4 * seg(t0, 14.75, 14.95)), 1 - seg(t0, 14.75, 14.95));
+ path = [SEND, PROV, 50, k];
+ } else op(e.envA, 0);
+
+ if (t0 >= 17.0 && t0 < 18.3) {
+ const k = eio(seg(t0, 17.1, 18.3)), to = held("R", -16), [x, y] = bez(PROV_OUT, to, 45, k);
+ place(e.envB, x, y, lerp(0, to[2], k), lerp(.5, ENV, eo(seg(t0, 17, 17.3))), seg(t0, 17, 17.15));
+ path = [PROV_OUT, to, 45, k]; colour = "#d6a03c";
+ } else if (t0 >= 18.3 && t0 < 18.9) {
+ const h = held("R", -16);
+ place(e.envB, h[0], h[1], h[2], ENV * (1 - .25 * seg(t0, 18.6, 18.9)), 1 - seg(t0, 18.65, 18.9));
+ } else op(e.envB, 0);
+ drawTrail(path, colour);
+
+ // the letter comes out of the envelope at her chest and lies on the desk
+ let lvis = false;
+ if (t0 >= 4.6 && t0 < 12.6) { lvis = true; onDesk(e.letter, OPEN, eo(seg(t0, 4.6, 5.4)), seg(t0, 4.6, 4.8)); }
+ else if (t0 >= 12.6 && t0 < 13.15) { lvis = true; onDesk(e.letter, SEND, 1 - eio(seg(t0, 12.6, 13.05)), 1 - seg(t0, 12.95, 13.15)); }
+ css(e.letter, "visibility", lvis ? "visible" : "hidden");
+
+ // read, tear into the notebook, stick the placeholders on
+ const READ = [6.0, 6.8], TEAR = [8.2, 9.2], STICK = [11.0, 11.7];
+ ["s0", "s1"].forEach((k, i) => {
+ const s = slots[k], torn = seg(t0, TEAR[i], TEAR[i] + .25), stuck = eo(seg(t0, STICK[i], STICK[i] + .35));
+ cls(s.real, "hl", t0 >= READ[i]);
+ op(s.real, 1 - torn);
+ css(s.real, "transform", `translateY(${f2(-6 * torn)}px)`);
+ op(s.hole, torn * (1 - stuck));
+ op(s.code, stuck);
+ css(s.code, "transform", `scale(${f2(lerp(1.25, 1, stuck))})`);
+ slotW(s, lerp(s.rw, s.cw, eio(seg(t0, STICK[i], STICK[i] + .35))));
+ const fk = seg(t0, TEAR[i] + .05, TEAR[i] + .95);
+ if (fk > 0 && fk < 1 && lvis) {
+ const [x, y] = bez([s.x + s.rw / 2, s.y], LV[i], 50, eio(fk));
+ placeC(flyers[i], x, y, seg(fk, 0, .1) * (1 - seg(fk, .92, 1)));
+ } else op(flyers[i], 0);
+ op(rows[i], seg(t0, TEAR[i] + .9, TEAR[i] + 1.05));
+ op(rowCodes[i], seg(t0, STICK[i], STICK[i] + .3));
+ });
+ op(e.lempty, 1 - seg(t0, TEAR[0] + .7, TEAR[0] + .9));
+
+ // the provider reads placeholders and answers with placeholders
+ op(e.pin, seg(t0, 14.8, 15.2));
+ op(e.pout, seg(t0, 15.6, 15.9));
+ css(e.think, "display", t0 < 16.4 ? "flex" : "none");
+ if (t0 < 16.4 && t0 > 15.5) thinkDots.forEach((d, i) => op(d, .35 + .65 * Math.max(0, Math.sin(t0 * 7 - i * .9))));
+ op(e.pcode, seg(t0, 16.4, 16.9));
+ op(e.pnote, seg(t0, 17.6, 18.0));
+
+ // the answer comes out of her hands onto the desk, placeholders turn
+ // back, then it goes to the browser
+ let rvis = false;
+ if (t0 >= 18.6 && t0 < 22.4) { rvis = true; onDesk(e.reply, CATCH2, eo(seg(t0, 18.6, 19.4)), seg(t0, 18.6, 18.8)); }
+ else if (t0 >= 22.4 && t0 < 23.25) {
+ rvis = true; const k = eio(seg(t0, 22.4, 23.2));
+ place(e.reply, lerp(0, BROWSER[0] - LC[0], k), lerp(0, BROWSER[1] - LC[1], k), 0, lerp(1, .3, k), 1 - seg(t0, 23.0, 23.25));
+ }
+ css(e.reply, "visibility", rvis ? "visible" : "hidden");
+ const RESTORE = [20.2, 21.1];
+ ["r0", "r1"].forEach((k, i) => {
+ const s = slots[k], back = eo(seg(t0, RESTORE[i] + .55, RESTORE[i] + .85));
+ op(s.code, 1 - back);
+ css(s.code, "transform", `translateY(${f2(-5 * back)}px)`);
+ op(s.real, back);
+ slotW(s, lerp(s.cw, s.rw, back));
+ cls(rows[i], "hot", t0 >= RESTORE[i] - .3 && t0 < RESTORE[i] + 1.2);
+ const gk = seg(t0, RESTORE[i], RESTORE[i] + .65);
+ if (gk > 0 && gk < 1 && rvis) {
+ const [x, y] = bez(LV[i], [s.x + s.rw / 2, s.y], 40, eio(gk));
+ placeC(flyers[2 + i], x, y, seg(gk, 0, .1) * (1 - seg(gk, .85, 1)));
+ } else op(flyers[2 + i], 0);
+ });
+
+ // the browser on this computer fills in and signs in
+ const tu = XQD_MAIL.slice(0, Math.round(seg(t0, 23.4, 24.1) * XQD_MAIL.length)), tp = "•".repeat(Math.round(seg(t0, 24.1, 24.6) * 12));
+ if (e.fu._t !== tu) e.fu.textContent = e.fu._t = tu;
+ if (e.fp._t !== tp) e.fp.textContent = e.fp._t = tp;
+ cls(e.fu, "on", t0 >= 23.4 && t0 < 24.1);
+ cls(e.fp, "on", t0 >= 24.1 && t0 < 24.7);
+ const ok = eo(seg(t0, 25.0, 25.4));
+ op(e.bok, ok);
+ css(e.bok, "transform", `scale(${f2(lerp(.97, 1, ok))})`);
+
+ let si = 0;
+ XQD_STEPS.forEach(([s], i) => { if (t0 >= s) si = i; });
+ if (si !== lastSi || lang !== said) {
+ lastSi = si;
+ const n = el("span", "n", `${si + 1}/${XQD_STEPS.length}`);
+ capT.replaceChildren(n, t(XQD_STEPS[si][1]));
+ capB.textContent = t(XQD_STEPS[si][2]);
+ stepBtns.forEach((b, i) => { b.classList.toggle("on", i === si); b.classList.toggle("done", i < si); });
+ }
+ said = lang;
+ }
+
+ // T, the frame clock, moves the sheets every display frame; while the
+ // video plays T leans toward its time, so she and the sheets keep step.
+ // Without the video (it can't load or play) the frame clock alone runs.
+ const vid = stage.querySelector("video");
+ let T = 0, playing = !calm(), open = false, seen = false, raf = 0, last = 0, fixed = 0, theme = "";
+ const dark = matchMedia("(prefers-color-scheme: dark)");
+ const pickVid = () => {
+ const th = document.documentElement.dataset.theme || (dark.matches ? "dark" : "light");
+ if (th === theme) return;
+ theme = th;
+ vid.poster = `plugins/redact/xq_${th}.jpg`;
+ vid.src = `plugins/redact/xq_${th}.webm`;
+ // a new source starts paused: it goes on where the old one was
+ seek(T);
+ wake();
+ };
+ const seek = (t0) => { T = t0; if (vid.readyState >= 1) vid.currentTime = Math.min(t0, vid.duration - .02); };
+ vid.addEventListener("loadedmetadata", () => seek(T));
+ let lastScrub = -1;
+ const sync = () => { const v = Math.round(T / XQD_END * 200) * 5; if (v !== lastScrub) { lastScrub = v; scrub.value = v; } };
+ const live = () => open && seen && !document.hidden && root.isConnected && !$("#maskDemo")?.hidden;
+ const setPlaying = (p) => {
+ playing = p;
+ play.innerHTML = p ? xqdIcon.pause : xqdIcon.play;
+ words();
+ if (p && T >= XQD_END - .05) seek(0);
+ wake();
+ };
+ // the controls' names, said again when the language changes
+ const words = () => {
+ play.title = t(playing ? "Pause the demo" : "Play the demo");
+ play.setAttribute("aria-label", play.title);
+ scrub.setAttribute("aria-label", t("Where the demo is"));
+ };
+ play.onclick = () => setPlaying(!playing);
+ scrub.oninput = () => { setPlaying(false); seek(scrub.value / 1000 * XQD_END); render(T); };
+
+ function frame(now) {
+ raf = 0;
+ if (!live() || !playing) return;
+ T += Math.min(.05, (now - (last || now)) / 1000);
+ last = now;
+ if (!vid.paused && !vid.seeking && vid.readyState >= 2) {
+ // a video that went elsewhere (a seek it couldn't make, a stall) is
+ // sent back to T, at most once a second; T never jumps to it
+ const err = vid.currentTime - T;
+ if (Math.abs(err) <= .25) T += err * .1;
+ else if (now - fixed > 1000) { fixed = now; vid.currentTime = Math.min(T, vid.duration - .02); }
+ }
+ // once through, then it rests on the last step
+ if (T >= XQD_END || vid.ended) { T = XQD_END; render(T); sync(); return setPlaying(false); }
+ render(T); sync();
+ raf = requestAnimationFrame(frame);
+ }
+ // wake starts or stops it as the row, the page and the window say
+ function wake() {
+ open = $("#mdRow")?.getAttribute("aria-expanded") === "true";
+ if (live() && playing) {
+ seek(T);
+ vid.play().catch(() => {});
+ if (!raf) { last = 0; raf = requestAnimationFrame(frame); }
+ } else {
+ vid.pause();
+ if (raf) cancelAnimationFrame(raf), (raf = 0);
+ }
+ }
+ new IntersectionObserver((es) => { seen = es[es.length - 1].isIntersecting; wake(); }).observe(vp);
+ document.addEventListener("visibilitychange", wake);
+ new ResizeObserver(() => { stage.style.transform = `scale(${vp.clientWidth / 1000})`; }).observe(vp);
+ new MutationObserver(pickVid).observe(document.documentElement, { attributeFilter: ["data-theme"] });
+ dark.addEventListener("change", pickVid);
+ // a change of language redraws the words the frame writes itself
+ new MutationObserver(() => { render(T); words(); }).observe(document.documentElement, { attributeFilter: ["lang"] });
+
+ pickVid();
+ measure();
+ document.fonts?.ready.then(() => { measure(); render(T); });
+ if (!playing) seek(25.6);
+ render(T); sync();
+ setPlaying(playing);
+ root.__state = () => ({ T, ct: vid.currentTime, paused: vid.paused, rs: vid.readyState, src: vid.currentSrc.split("/").pop(), playing, raf: !!raf });
+ return { wake, root };
+}
diff --git a/internal/gui/assets/plugins/redact/i18n.js b/internal/gui/assets/plugins/redact/i18n.js
index 07de53c79..258fea842 100644
--- a/internal/gui/assets/plugins/redact/i18n.js
+++ b/internal/gui/assets/plugins/redact/i18n.js
@@ -50,6 +50,47 @@ magpie.strings({
"Clear masking records?": "清空脱敏记录?",
"Every request's record of what was masked is deleted from this computer. Masking stays as it is, and requests from now on are recorded again.": "这台电脑上每条请求的脱敏记录都会删除。脱敏设置不变,之后的请求照常记录。",
"Masking records cleared": "脱敏记录已清空",
+ "How masking works": "脱敏原理演示",
+ "Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer": "小鹊带你走一遍一条请求:密码在离开前换成编码,回信到了再在你的电脑上换回来",
+ "You send a request": "你发出请求",
+ "You ask the agent to sign in to github.com with a password. The letter goes to Little Magpie first and hasn't left your computer yet.": "你让 Agent 用密码登录 github.com。这封信先交到小鹊手里,还没离开你的电脑。",
+ "She reads it through": "仔细检查",
+ "Little Magpie opens the letter and reads it line by line for what shouldn't be sent: emails, passwords.": "小鹊拆开信,一行一行地找:邮箱、密码这些不该寄出去的东西。",
+ "Tearing out what's private": "撕下敏感信息",
+ "The real values are torn out and written in her notebook. The notebook stays on your computer.": "真实的值撕下来,记进小本本。小本本只放在你的电脑上。",
+ "Sticking on placeholders": "贴上编码",
+ "Placeholders fill the gaps. A value always gets the same one, so the model still understands.": "空出来的地方贴上编码。同一个值每次都是同一个编码,模型照样读得懂。",
+ "Off to the provider": "寄给供应商",
+ "The letter is sealed and sent. The provider gets only placeholders.": "信封好寄出。供应商收到的只有编码。",
+ "The answer calls the browser": "回信:调用浏览器工具",
+ "The model decides to call browser.login, and its arguments are placeholders too.": "模型决定调用 browser.login,参数里写的也是编码。",
+ "Putting the values back": "对照还原",
+ "When the answer comes, Little Magpie opens her notebook and turns each placeholder back into its value.": "回信到了,小鹊翻开小本本,把编码换回真实的值。",
+ "Signing in on your computer": "在你的电脑上登录",
+ "The tool signs in with the real password on your computer. The password never left it.": "工具在你的电脑上用真实密码登录成功。密码从头到尾没离开过你的电脑。",
+ "Over the network": "网络",
+ "You tell the agent": "你对 Agent 说",
+ "Little Magpie's notebook": "小鹊的小本本",
+ "Kept on your computer only": "只放在你的电脑上",
+ "Nothing in it yet": "还是空的",
+ "Signed in to github.com": "已登录 github.com",
+ "The tool runs on your computer": "工具在你的电脑上执行",
+ "Letter to the provider": "寄往供应商的信",
+ "Agent → model": "Agent → 模型",
+ "The job": "任务",
+ "Sign in to github.com": "登录 github.com",
+ "The provider's answer": "供应商的回信",
+ "Calls a tool": "调用工具",
+ "Model service": "模型服务",
+ "Remote, not on your computer": "远程,不在你的电脑上",
+ "Letter it got": "收到的信",
+ "Reply it wrote": "回信",
+ "It saw only placeholders, never your password or email.": "它只见过编码,没见过你的密码和邮箱。",
+ "Your computer": "你的电脑",
+ "Pause the demo": "暂停",
+ "Play the demo": "播放",
+ "Where the demo is": "进度",
+ "Sign in to github.com for me with the password {pw}, the account is {email}.": "用密码 {pw} 帮我登录 github.com,账号是 {email}。",
},
"zh-TW": {
"Turn on masking": "開啟脫敏",
@@ -100,6 +141,47 @@ magpie.strings({
"Clear masking records?": "清空脫敏記錄?",
"Every request's record of what was masked is deleted from this computer. Masking stays as it is, and requests from now on are recorded again.": "這台電腦上每條請求的脫敏記錄都會刪除。脫敏設定不變,之後的請求照常記錄。",
"Masking records cleared": "脫敏記錄已清空",
+ "How masking works": "脫敏原理示範",
+ "Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer": "小鵲帶你走一遍一條請求:密碼在離開前換成編碼,回信到了再在你的電腦上換回來",
+ "You send a request": "你發出請求",
+ "You ask the agent to sign in to github.com with a password. The letter goes to Little Magpie first and hasn't left your computer yet.": "你讓 Agent 用密碼登入 github.com。這封信先交到小鵲手裡,還沒離開你的電腦。",
+ "She reads it through": "仔細檢查",
+ "Little Magpie opens the letter and reads it line by line for what shouldn't be sent: emails, passwords.": "小鵲拆開信,一行一行地找:電子郵件、密碼這些不該寄出去的東西。",
+ "Tearing out what's private": "撕下敏感資訊",
+ "The real values are torn out and written in her notebook. The notebook stays on your computer.": "真實的值撕下來,記進小本本。小本本只放在你的電腦上。",
+ "Sticking on placeholders": "貼上編碼",
+ "Placeholders fill the gaps. A value always gets the same one, so the model still understands.": "空出來的地方貼上編碼。同一個值每次都是同一個編碼,模型照樣讀得懂。",
+ "Off to the provider": "寄給供應商",
+ "The letter is sealed and sent. The provider gets only placeholders.": "信封好寄出。供應商收到的只有編碼。",
+ "The answer calls the browser": "回信:呼叫瀏覽器工具",
+ "The model decides to call browser.login, and its arguments are placeholders too.": "模型決定呼叫 browser.login,參數裡寫的也是編碼。",
+ "Putting the values back": "對照還原",
+ "When the answer comes, Little Magpie opens her notebook and turns each placeholder back into its value.": "回信到了,小鵲翻開小本本,把編碼換回真實的值。",
+ "Signing in on your computer": "在你的電腦上登入",
+ "The tool signs in with the real password on your computer. The password never left it.": "工具在你的電腦上用真實密碼登入成功。密碼從頭到尾沒離開過你的電腦。",
+ "Over the network": "網路",
+ "You tell the agent": "你對 Agent 說",
+ "Little Magpie's notebook": "小鵲的小本本",
+ "Kept on your computer only": "只放在你的電腦上",
+ "Nothing in it yet": "還是空的",
+ "Signed in to github.com": "已登入 github.com",
+ "The tool runs on your computer": "工具在你的電腦上執行",
+ "Letter to the provider": "寄往供應商的信",
+ "Agent → model": "Agent → 模型",
+ "The job": "任務",
+ "Sign in to github.com": "登入 github.com",
+ "The provider's answer": "供應商的回信",
+ "Calls a tool": "呼叫工具",
+ "Model service": "模型服務",
+ "Remote, not on your computer": "遠端,不在你的電腦上",
+ "Letter it got": "收到的信",
+ "Reply it wrote": "回信",
+ "It saw only placeholders, never your password or email.": "它只見過編碼,沒見過你的密碼和電子郵件。",
+ "Your computer": "你的電腦",
+ "Pause the demo": "暫停",
+ "Play the demo": "播放",
+ "Where the demo is": "進度",
+ "Sign in to github.com for me with the password {pw}, the account is {email}.": "用密碼 {pw} 幫我登入 github.com,帳號是 {email}。",
},
ja: {
"Turn on masking": "マスクをオンにする",
@@ -150,6 +232,47 @@ magpie.strings({
"Clear masking records?": "マスクの記録を消去しますか?",
"Every request's record of what was masked is deleted from this computer. Masking stays as it is, and requests from now on are recorded again.": "このコンピュータにある各リクエストのマスク記録がすべて削除されます。マスクの設定はそのままで、これからのリクエストはまた記録されます。",
"Masking records cleared": "マスクの記録を消去しました",
+ "How masking works": "マスキングのしくみ",
+ "Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer": "小鵲がひとつのリクエストを案内します。パスワードは送られる前にプレースホルダーになり、返事が届くとこのコンピュータで元に戻ります",
+ "You send a request": "リクエストを送る",
+ "You ask the agent to sign in to github.com with a password. The letter goes to Little Magpie first and hasn't left your computer yet.": "Agent に、パスワードで github.com へサインインするよう頼みます。この手紙はまず小鵲に届き、まだこのコンピュータを出ていません。",
+ "She reads it through": "よく読む",
+ "Little Magpie opens the letter and reads it line by line for what shouldn't be sent: emails, passwords.": "小鵲は手紙を開き、メールアドレスやパスワードなど、送ってはいけないものを一行ずつ探します。",
+ "Tearing out what's private": "秘密を切り取る",
+ "The real values are torn out and written in her notebook. The notebook stays on your computer.": "本当の値を切り取って、メモ帳に書き留めます。メモ帳はこのコンピュータにだけあります。",
+ "Sticking on placeholders": "プレースホルダーを貼る",
+ "Placeholders fill the gaps. A value always gets the same one, so the model still understands.": "空いたところにプレースホルダーを貼ります。同じ値はいつも同じプレースホルダーなので、モデルはそのまま理解できます。",
+ "Off to the provider": "プロバイダへ送る",
+ "The letter is sealed and sent. The provider gets only placeholders.": "手紙に封をして送ります。プロバイダに届くのはプレースホルダーだけです。",
+ "The answer calls the browser": "返事:ブラウザのツールを呼ぶ",
+ "The model decides to call browser.login, and its arguments are placeholders too.": "モデルは browser.login を呼ぶことにします。引数に書かれているのもプレースホルダーです。",
+ "Putting the values back": "照らし合わせて戻す",
+ "When the answer comes, Little Magpie opens her notebook and turns each placeholder back into its value.": "返事が届くと、小鵲はメモ帳を開き、プレースホルダーを本当の値に戻します。",
+ "Signing in on your computer": "このコンピュータでサインイン",
+ "The tool signs in with the real password on your computer. The password never left it.": "ツールはこのコンピュータで本当のパスワードを使ってサインインします。パスワードは一度もこのコンピュータを出ていません。",
+ "Over the network": "ネットワーク",
+ "You tell the agent": "Agent への依頼",
+ "Little Magpie's notebook": "小鵲のメモ帳",
+ "Kept on your computer only": "このコンピュータにだけ保管",
+ "Nothing in it yet": "まだ空です",
+ "Signed in to github.com": "github.com にサインインしました",
+ "The tool runs on your computer": "ツールはこのコンピュータで動きます",
+ "Letter to the provider": "プロバイダへの手紙",
+ "Agent → model": "Agent → モデル",
+ "The job": "依頼",
+ "Sign in to github.com": "github.com にサインイン",
+ "The provider's answer": "プロバイダからの返事",
+ "Calls a tool": "ツールを呼ぶ",
+ "Model service": "モデルサービス",
+ "Remote, not on your computer": "リモート。このコンピュータにはありません",
+ "Letter it got": "届いた手紙",
+ "Reply it wrote": "返事",
+ "It saw only placeholders, never your password or email.": "見たのはプレースホルダーだけで、パスワードもメールアドレスも見ていません。",
+ "Your computer": "このコンピュータ",
+ "Pause the demo": "一時停止",
+ "Play the demo": "再生",
+ "Where the demo is": "再生位置",
+ "Sign in to github.com for me with the password {pw}, the account is {email}.": "パスワード {pw} で github.com にサインインして。アカウントは {email}。",
},
de: {
"Turn on masking": "Maskierung einschalten",
@@ -200,5 +323,46 @@ magpie.strings({
"Clear masking records?": "Maskierungseinträge löschen?",
"Every request's record of what was masked is deleted from this computer. Masking stays as it is, and requests from now on are recorded again.": "Der Eintrag jeder Anfrage dazu, was maskiert wurde, wird von diesem Computer gelöscht. Die Maskierung bleibt, wie sie ist, und Anfragen ab jetzt werden wieder erfasst.",
"Masking records cleared": "Maskierungseinträge gelöscht",
+ "How masking works": "So funktioniert die Maskierung",
+ "Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer": "Die kleine Elster begleitet eine Anfrage: Passwörter werden zu Platzhaltern, bevor sie hinausgeht, und kommen mit der Antwort auf Ihrem Computer zurück",
+ "You send a request": "Sie senden eine Anfrage",
+ "You ask the agent to sign in to github.com with a password. The letter goes to Little Magpie first and hasn't left your computer yet.": "Sie bitten den Agenten, sich mit einem Passwort bei github.com anzumelden. Der Brief geht zuerst an die kleine Elster und hat Ihren Computer noch nicht verlassen.",
+ "She reads it through": "Sie liest genau",
+ "Little Magpie opens the letter and reads it line by line for what shouldn't be sent: emails, passwords.": "Die kleine Elster öffnet den Brief und sucht Zeile für Zeile, was nicht hinausgehen soll: E-Mails, Passwörter.",
+ "Tearing out what's private": "Das Private herausreißen",
+ "The real values are torn out and written in her notebook. The notebook stays on your computer.": "Die echten Werte werden herausgerissen und ins Notizbuch geschrieben. Das Notizbuch bleibt auf Ihrem Computer.",
+ "Sticking on placeholders": "Platzhalter aufkleben",
+ "Placeholders fill the gaps. A value always gets the same one, so the model still understands.": "In die Lücken kommen Platzhalter. Ein Wert bekommt immer denselben, also versteht das Modell den Brief trotzdem.",
+ "Off to the provider": "Ab zum Anbieter",
+ "The letter is sealed and sent. The provider gets only placeholders.": "Der Brief wird verschlossen und verschickt. Der Anbieter bekommt nur Platzhalter.",
+ "The answer calls the browser": "Die Antwort ruft den Browser auf",
+ "The model decides to call browser.login, and its arguments are placeholders too.": "Das Modell ruft browser.login auf, und auch seine Argumente sind Platzhalter.",
+ "Putting the values back": "Die Werte zurücksetzen",
+ "When the answer comes, Little Magpie opens her notebook and turns each placeholder back into its value.": "Kommt die Antwort, schlägt die kleine Elster ihr Notizbuch auf und setzt für jeden Platzhalter wieder den echten Wert ein.",
+ "Signing in on your computer": "Anmelden auf Ihrem Computer",
+ "The tool signs in with the real password on your computer. The password never left it.": "Das Tool meldet sich auf Ihrem Computer mit dem echten Passwort an. Das Passwort hat ihn nie verlassen.",
+ "Over the network": "Netzwerk",
+ "You tell the agent": "Sie sagen dem Agenten",
+ "Little Magpie's notebook": "Notizbuch der kleinen Elster",
+ "Kept on your computer only": "Nur auf Ihrem Computer",
+ "Nothing in it yet": "Noch leer",
+ "Signed in to github.com": "Bei github.com angemeldet",
+ "The tool runs on your computer": "Das Tool läuft auf Ihrem Computer",
+ "Letter to the provider": "Brief an den Anbieter",
+ "Agent → model": "Agent → Modell",
+ "The job": "Aufgabe",
+ "Sign in to github.com": "Bei github.com anmelden",
+ "The provider's answer": "Antwort des Anbieters",
+ "Calls a tool": "Ruft ein Tool auf",
+ "Model service": "Modelldienst",
+ "Remote, not on your computer": "Entfernt, nicht auf Ihrem Computer",
+ "Letter it got": "Erhaltener Brief",
+ "Reply it wrote": "Seine Antwort",
+ "It saw only placeholders, never your password or email.": "Er sah nur Platzhalter, nie Ihr Passwort oder Ihre E-Mail.",
+ "Your computer": "Ihr Computer",
+ "Pause the demo": "Anhalten",
+ "Play the demo": "Abspielen",
+ "Where the demo is": "Fortschritt",
+ "Sign in to github.com for me with the password {pw}, the account is {email}.": "Melden Sie mich mit dem Passwort {pw} bei github.com an, das Konto ist {email}.",
},
});
diff --git a/internal/gui/assets/plugins/redact/page.js b/internal/gui/assets/plugins/redact/page.js
index 7ab9e43f3..82992efe3 100644
--- a/internal/gui/assets/plugins/redact/page.js
+++ b/internal/gui/assets/plugins/redact/page.js
@@ -595,7 +595,8 @@ function maskOneOpen(key, r) {
if (!key) return;
maskTipOff();
const o = maskO = { key, r: r || maskL.records.find((x) => x.key === key) || null, sent: undefined, leaves: null, vals: new Map(), view: "both", pick: "", open: new Set(), whole: new Set() };
- $("#maskCard").hidden = $("#maskList").hidden = true;
+ $("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = true;
+ xqd?.wake();
$("#maskOne").hidden = false;
drawMaskOne();
(o.r ? Promise.resolve(o.r) : api("masking/record?key=" + key))
@@ -623,7 +624,8 @@ function maskOneClose() {
maskO = null;
$("#maskOne").hidden = true;
$("#maskOne").replaceChildren();
- $("#maskCard").hidden = $("#maskList").hidden = false;
+ $("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = false;
+ xqd?.wake();
drawMaskList();
}
diff --git a/internal/gui/assets/plugins/redact/redact.css b/internal/gui/assets/plugins/redact/redact.css
index 51b6464c7..2e7120ffb 100644
--- a/internal/gui/assets/plugins/redact/redact.css
+++ b/internal/gui/assets/plugins/redact/redact.css
@@ -251,3 +251,112 @@ body.window .msk-onebar::before { inset: -6px -16px; }
.msk-vrow .by, .msk-vrow .bar { display: none; }
}
@media (prefers-reduced-motion: reduce) { .mo-scan, .msk-live i { animation: none; } }
+
+/* How masking works (demo.js): a row that opens onto 小鹊 taking one request
+ through. Her video is drawn on the card's colour, one take per theme; the
+ stage is laid out at 1000×420 and scaled to the card */
+.msk-demo { flex: none; border-radius: 14px; border: 1px solid var(--line); background: var(--card); overflow: hidden; }
+.msk-demo[hidden], .md-body[hidden] { display: none; }
+.md-row { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 9px 16px 9px 12px; cursor: pointer; }
+.md-row:hover { background: var(--pill-hover); }
+.md-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 14px; }
+.md-thumb { flex: none; width: 32px; height: 32px; border-radius: 9px; background: url(xq_light.jpg) -33px -5px / 98px auto no-repeat var(--card); box-shadow: inset 0 0 0 1px var(--line-2); }
+.md-words { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
+.md-name { font-size: 13px; font-weight: 600; color: var(--fg); }
+.md-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+.md-len { flex: none; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
+.md-chev { flex: none; color: var(--faint); transition: transform .2s; }
+.md-row[aria-expanded="true"] .md-chev { transform: rotate(90deg); }
+.md-body { border-top: 1px solid var(--line-2); padding: 10px 12px 12px; }
+@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .md-thumb { background-image: url(xq_dark.jpg); } }
+:root[data-theme="dark"] .md-thumb { background-image: url(xq_dark.jpg); }
+
+.xqd { --xq-paper: #fffdf8; --xq-shadow: 0 6px 18px rgba(20, 22, 30, .10), 0 1px 3px rgba(20, 22, 30, .06), 0 0 0 .5px rgba(20, 22, 30, .08); --xq-env-shadow: rgba(20, 22, 30, .10); font-size: 13px; line-height: 1.45; color: var(--fg); }
+@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .xqd { --xq-paper: #2a2a2f; --xq-shadow: 0 6px 18px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3), 0 0 0 .5px rgba(255, 255, 255, .07); --xq-env-shadow: rgba(0, 0, 0, .35); } }
+:root[data-theme="dark"] .xqd { --xq-paper: #2a2a2f; --xq-shadow: 0 6px 18px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3), 0 0 0 .5px rgba(255, 255, 255, .07); --xq-env-shadow: rgba(0, 0, 0, .35); }
+.xqd * { box-sizing: border-box; }
+.xq-vp { position: relative; width: 100%; aspect-ratio: 1000 / 420; overflow: hidden; }
+.xq-stage { position: absolute; left: 0; top: 0; width: 1000px; height: 420px; transform-origin: 0 0; contain: layout; }
+.xq-mv { will-change: transform, opacity; }
+.xq-lane { position: absolute; top: 6px; display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
+.xq-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
+.xq-dot.far { background: var(--faint); }
+.xq-divider { position: absolute; left: 784px; top: 6px; bottom: 6px; width: 0; border-left: 1px dashed var(--line); }
+.xq-divider span { position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%) rotate(-90deg); padding: 2px 8px; border-radius: 6px; background: var(--card); font-size: 10.5px; white-space: nowrap; color: var(--faint); }
+.xq-box { position: absolute; overflow: hidden; border-radius: 12px; border: 1px solid var(--line); background: var(--card); box-shadow: 0 1px 2px rgba(20, 22, 30, .04); }
+.xq-h { display: block; font-size: 12px; font-weight: 600; }
+.xq-sub { display: block; font-size: 10.5px; font-weight: 400; color: var(--muted); }
+.xq-bh { display: flex; align-items: center; gap: 8px; padding: 9px 11px 0; }
+.xq-bh > div:last-child { min-width: 0; }
+.xq-ic { flex: none; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--pill); color: var(--fg-2); }
+.xq-ic.acc { background: var(--accent-soft); color: var(--accent); }
+.xq-stage [data-k="req"] { left: 16px; top: 28px; width: 220px; height: 112px; }
+.xq-msg { margin: 5px 11px 0; font-size: 12px; line-height: 1.4; color: var(--fg-2); overflow-wrap: anywhere; }
+.xq-msg b { font-weight: 600; color: var(--fg); }
+.xq-caret { display: inline-block; width: 1.5px; height: 12px; margin-left: 1px; vertical-align: -2px; background: var(--accent); }
+.xq-stage [data-k="ledger"] { left: 16px; top: 148px; width: 220px; height: 126px; }
+.xq-lrow { position: absolute; left: 7px; right: 7px; height: 40px; padding: 0 6px; display: flex; flex-direction: column; justify-content: center; gap: 2px; border-radius: 8px; opacity: 0; transition: background-color .2s; }
+.xq-lv { padding-left: 1px; font-family: var(--code); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--fg); }
+.xq-lc { align-self: flex-start; }
+.xq-lrow.hot { background: var(--accent-soft); }
+.xq-lempty { position: absolute; left: 11px; right: 11px; top: 68px; text-align: center; font-size: 11px; color: var(--faint); }
+.xq-stage [data-k="browser"] { left: 16px; top: 282px; width: 220px; height: 130px; }
+.xq-bbar { display: flex; align-items: center; gap: 5px; padding: 7px 10px; border-bottom: 1px solid var(--line-2); }
+.xq-bbar i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
+.xq-url { flex: 1; height: 18px; margin-left: 6px; padding: 0 7px; display: flex; align-items: center; gap: 5px; border-radius: 6px; background: var(--pill); font-size: 10.5px; color: var(--muted); }
+.xq-bform { padding: 7px 12px; }
+.xq-field { height: 22px; margin-bottom: 5px; padding: 0 7px; display: flex; align-items: center; overflow: hidden; white-space: nowrap; border: 1px solid var(--line); border-radius: 7px; background: var(--card-2); font-family: var(--code); font-size: 11px; color: var(--fg); }
+.xq-field.on { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
+.xq-bbtn { height: 22px; margin-top: 4px; display: grid; place-items: center; border-radius: 7px; background: var(--accent); font-size: 11px; font-weight: 600; color: var(--accent-fg); }
+.xq-bok { position: absolute; inset: 32px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; background: var(--card); font-size: 12px; font-weight: 600; text-align: center; opacity: 0; }
+.xq-chk { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--green-soft); color: var(--green); }
+.xq-her { position: absolute; left: 290px; top: 16px; width: 440px; height: 293.33px; pointer-events: none; }
+.xq-her video { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: fill; -webkit-mask-image: linear-gradient(90deg, transparent, #000 1.6%, #000 98.4%, transparent), linear-gradient(transparent, #000 4%, #000 98.4%, transparent); -webkit-mask-composite: source-in; mask-composite: intersect; }
+.xq-paper { position: absolute; left: 360px; top: 274px; width: 300px; height: 118px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--xq-paper); box-shadow: var(--xq-shadow); transform-origin: 50% 50%; visibility: hidden; }
+.xq-ph { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 10.5px; white-space: nowrap; color: var(--muted); }
+.xq-ln { display: flex; align-items: center; gap: 8px; height: 26px; font-size: 12px; white-space: nowrap; color: var(--fg-2); }
+.xq-k { flex: none; width: 60px; overflow: hidden; text-overflow: ellipsis; font-size: 11px; color: var(--muted); }
+.xq-fn { font-family: var(--code); font-size: 11.5px; font-weight: 600; color: var(--fg); }
+.xq-arg { font-family: var(--code); font-size: 11px; color: var(--muted); }
+.xq-slot { position: relative; flex: none; display: inline-block; height: 22px; vertical-align: middle; }
+.xq-slot > span { position: absolute; left: 0; top: 0; height: 22px; padding: 0 7px; display: flex; align-items: center; border-radius: 7px; white-space: nowrap; font-family: var(--code); font-size: 11px; }
+.xq-real { color: var(--fg); }
+.xq-real.hl { background: var(--amber-soft); color: var(--amber); }
+.xq-real.ok { background: var(--green-soft); color: var(--green); }
+.xq-slot > .xq-hole { inset: 0; width: 100%; border: 1px dashed var(--faint); opacity: 0; }
+.xq-code, .xq-pillc { display: inline-flex; align-items: center; height: 22px; padding: 0 7px; border-radius: 7px; white-space: nowrap; background: var(--accent-soft); font-family: var(--code); font-size: 11px; font-weight: 600; color: var(--accent); }
+.xq-pillc { height: 19px; padding: 0 6px; border-radius: 6px; font-size: 10.5px; }
+.xq-code.torn { background: var(--amber-soft); color: var(--amber); }
+.xq-code.back { background: var(--green-soft); color: var(--green); }
+.xq-stage [data-k="prov"] { left: 800px; top: 28px; width: 186px; height: 384px; }
+.xq-psec { margin: 8px 11px 0; padding-top: 8px; border-top: 1px solid var(--line-2); opacity: 0; }
+.xq-cap { display: block; margin-bottom: 3px; font-size: 10.5px; color: var(--muted); }
+.xq-pline { display: flex; flex-direction: column; gap: 1px; margin-bottom: 3px; font-size: 11.5px; color: var(--fg-2); }
+.xq-pline .xq-pillc { align-self: flex-start; }
+.xq-pcode { font-family: var(--code); font-size: 10.5px; line-height: 1.45; color: var(--fg); }
+.xq-ind { padding-left: 8px; }
+.xq-pcode .xq-pillc { margin: 0 0 0 8px; }
+.xq-think { display: flex; gap: 4px; padding: 4px 0; }
+.xq-think i { width: 5px; height: 5px; border-radius: 50%; background: var(--faint); }
+.xq-pnote { margin: 8px 11px 0; display: flex; align-items: flex-start; gap: 6px; font-size: 10.5px; line-height: 1.4; color: var(--muted); opacity: 0; }
+.xq-pnote svg { flex: none; margin-top: 1px; color: var(--green); }
+/* the shadow is drawn in the svg: a filter on a moving layer is redrawn every frame */
+.xq-env { position: absolute; left: 0; top: 0; width: 82px; height: 58px; margin: -27px 0 0 -41px; overflow: visible; opacity: 0; }
+.xq-flyer { position: absolute; left: 0; top: 0; opacity: 0; }
+.xq-flyer .xq-code { box-shadow: var(--xq-shadow); }
+.xq-trail { position: absolute; left: 0; top: 0; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; opacity: 0; }
+.xq-foot { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-2); }
+.xq-cap-t { font-size: 13px; font-weight: 600; }
+.xq-cap-t .n { margin-right: 6px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
+.xq-cap-b { min-height: 18px; margin-top: 1px; font-size: 12px; color: var(--fg-2); }
+.xq-ctrl { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
+.xq-play { all: unset; flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--pill); color: var(--fg); cursor: pointer; }
+.xq-play:hover { background: var(--pill-hover); }
+.xq-play:focus-visible, .xq-steps button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
+.xq-scrub { flex: 1; min-width: 60px; accent-color: var(--accent); }
+.xq-steps { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
+.xq-steps button { all: unset; padding: 3px 8px; border-radius: 6px; font-size: 11px; color: var(--muted); cursor: pointer; }
+.xq-steps button:hover { background: var(--pill); }
+.xq-steps button.on { background: var(--accent-soft); font-weight: 600; color: var(--accent); }
+.xq-steps button.done { color: var(--fg-2); }
+@container (max-width: 560px) { .xq-steps { display: none; } .md-len { display: none; } }
diff --git a/internal/gui/assets/plugins/redact/xq_dark.jpg b/internal/gui/assets/plugins/redact/xq_dark.jpg
new file mode 100644
index 000000000..db54f0643
Binary files /dev/null and b/internal/gui/assets/plugins/redact/xq_dark.jpg differ
diff --git a/internal/gui/assets/plugins/redact/xq_dark.webm b/internal/gui/assets/plugins/redact/xq_dark.webm
new file mode 100644
index 000000000..6da09cca2
Binary files /dev/null and b/internal/gui/assets/plugins/redact/xq_dark.webm differ
diff --git a/internal/gui/assets/plugins/redact/xq_light.jpg b/internal/gui/assets/plugins/redact/xq_light.jpg
new file mode 100644
index 000000000..5f996f02d
Binary files /dev/null and b/internal/gui/assets/plugins/redact/xq_light.jpg differ
diff --git a/internal/gui/assets/plugins/redact/xq_light.webm b/internal/gui/assets/plugins/redact/xq_light.webm
new file mode 100644
index 000000000..93c4ded00
Binary files /dev/null and b/internal/gui/assets/plugins/redact/xq_light.webm differ
diff --git a/internal/gui/tests/masking-demo.test.cjs b/internal/gui/tests/masking-demo.test.cjs
new file mode 100644
index 000000000..5ea82a9e7
--- /dev/null
+++ b/internal/gui/tests/masking-demo.test.cjs
@@ -0,0 +1,229 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// Insights › Masking's demo (plugins/redact/demo.js): a folded row between
+// the card and the requests. Folded, it fetches no video. Opened, it fetches
+// the take for the theme in use (and the other one when the theme changes),
+// plays while open and on screen, rests at the end, and stops when folded
+// or when a request is opened over it. With reduced motion it starts on the
+// last step and doesn't play. Her video is drawn on the card's own colour.
+// Nothing is left in English, nothing is wider than the window.
+// Every language, Chromium and WebKit, 1100 and 640px; the API is faked.
+const assert = require("node:assert/strict");
+const fs = require("node:fs/promises");
+const path = require("node:path");
+const { test } = require("node:test");
+const { chromium, webkit } = require("playwright");
+
+const assets = path.resolve(__dirname, "../assets");
+const K = "1792987654321000001";
+const record = { key: K, t: new Date(Date.now() - 60e3).toISOString(), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 1,
+ values: [{ p: "{{PERSON_bbbb2222}}", k: "PERSON", b: "model", h: "", l: 3, n: 1 }], snips: { "{{PERSON_bbbb2222}}": "ask {{PERSON_bbbb2222}} about it" } };
+
+function serve(lang, theme, fetched) {
+ const settings = { theme, lang, tray: "panel", currency: "usd", redact: true, redactPersonal: true };
+ return async (route) => {
+ const req = route.request(), url = new URL(req.url());
+ const json = (data) => route.fulfill({ json: data });
+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"${theme}",web:true};` });
+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
+ if (url.pathname === "/api/state") return json({ agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", fields: [] }], profiles: [], settings });
+ if (url.pathname === "/api/settings") return json(settings);
+ if (url.pathname === "/api/providers") return json({ providers: [{ id: "anthropic", name: "Anthropic", icon: "anthropic", agents: [], models: [] }], presets: [], excluded: [], gateway: { running: true, window: true, mine: true, url: "http://127.0.0.1:3999", models: 0, groups: [], calls: [] } });
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname === "/api/masking/summary") return json({ days: [], requests: 1, n: 1, distinct: 1, blocked: 0, hours: [], kinds: [{ name: "PERSON", n: 1, distinct: 1 }], by: { model: 1 }, agents: [{ name: "claude", n: 1, distinct: 1 }], providers: [{ name: "anthropic", n: 1, distinct: 1 }], values: [] });
+ if (url.pathname === "/api/masking/records") return json({ records: [record], more: false });
+ if (url.pathname === "/api/masking/record") return json(record);
+ if (url.pathname.startsWith("/api/")) return json({});
+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname), ext = path.extname(file);
+ if (ext === ".webm" || ext === ".jpg") fetched.push(path.basename(file));
+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png", ".jpg": "image/jpeg", ".webm": "video/webm" }[ext];
+ let body;
+ try { body = await fs.readFile(file); } catch { return route.fulfill({ status: 404, body: "" }); }
+ // a video is served in ranges, as the gateway's file server does, or
+ // Chromium can't seek in it
+ const range = ext === ".webm" && /bytes=(\d+)-(\d*)/.exec(req.headers().range || "");
+ if (range) {
+ const from = +range[1], to = range[2] ? Math.min(+range[2], body.length - 1) : body.length - 1;
+ return route.fulfill({ status: 206, body: body.subarray(from, to + 1), contentType, headers: { "Accept-Ranges": "bytes", "Content-Range": `bytes ${from}-${to}/${body.length}` } });
+ }
+ await route.fulfill({ body, contentType, headers: ext === ".webm" ? { "Accept-Ranges": "bytes" } : {} });
+ };
+}
+
+async function open(engine, lang, width, opts = {}) {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ const page = await (await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: opts.motion ? "no-preference" : "reduce" })).newPage();
+ page.setDefaultTimeout(8000);
+ const errors = [], fetched = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve(lang, opts.theme || "light", fetched));
+ await page.goto("http://magpie.test/?view=masking");
+ await page.locator("#mdRow").waitFor();
+ return { browser, page, errors, fetched };
+}
+const state = (page) => page.evaluate(() => document.querySelector(".xqd").__state());
+// page, when given, adds the demo's state to the failure
+async function until(ok, ms = 8000, page) {
+ for (const end = Date.now() + ms; !(await ok());) {
+ if (Date.now() > end) throw new Error("never happened: " + ok + (page ? " " + JSON.stringify(await state(page).catch(() => null)) : ""));
+ await new Promise((r) => setTimeout(r, 50));
+ }
+}
+
+const english = ["How masking works", "Little Magpie", "Over the network", "notebook", "Model service", "Letter to the provider", "Your computer",
+ "Sign in to github.com", "Signed in to github.com", "Nothing in it yet", "Signing in on your computer", "on your computer", "placeholders"];
+const wide = (page) => page.evaluate(() => {
+ const over = [...document.querySelectorAll("#view-masking *")].filter((n) => n.getClientRects().length && n.getBoundingClientRect().right > innerWidth + 1).map((n) => n.className?.baseVal ?? n.className);
+ return { page: document.documentElement.scrollWidth > document.documentElement.clientWidth, over };
+});
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
+ for (const width of [1100, 640]) {
+ test(`${engine} ${lang} ${width}px: the demo is folded, and opens on its last step`, async (t) => {
+ const { browser, page, errors, fetched } = await open(engine, lang, width);
+ t.after(() => browser.close());
+ const row = page.locator("#mdRow");
+ assert.equal(await row.getAttribute("aria-expanded"), "false");
+ assert(await page.locator("#mdBody").isHidden(), "folded at first");
+ // it sits between the card and the requests
+ assert.deepEqual(await page.evaluate(() => [document.querySelector("#maskDemo").previousElementSibling?.id, document.querySelector("#maskDemo").nextElementSibling?.id]), ["maskCard", "maskList"]);
+ await page.waitForTimeout(300);
+ assert(!fetched.some((f) => f.endsWith(".webm")), "a video fetched while folded: " + fetched);
+
+ await row.click();
+ assert.equal(await row.getAttribute("aria-expanded"), "true");
+ await page.locator(".xqd .xq-stage").waitFor();
+ await until(() => fetched.includes("xq_light.webm"));
+ assert(!fetched.includes("xq_dark.webm"), "only the theme's take");
+ // reduced motion: on the last step, not playing
+ const s = await state(page);
+ assert.equal(s.playing, false);
+ assert.equal(s.raf, false);
+ assert(Math.abs(s.T - 25.6) < .01, "T " + s.T);
+ assert.match(await page.locator(".xq-cap-t").innerText(), /^8\/8/);
+ await page.waitForTimeout(300);
+ assert(Math.abs((await state(page)).T - 25.6) < .01, "it moved under reduced motion");
+ // the stage fits the card
+ const fit = await page.evaluate(() => { const vp = document.querySelector(".xq-vp").getBoundingClientRect(), st = document.querySelector(".xq-stage").getBoundingClientRect(); return [vp.width, st.width, vp.height, st.height]; });
+ assert(Math.abs(fit[0] - fit[1]) < 1 && Math.abs(fit[2] - fit[3]) < 1, "stage " + fit);
+
+ if (lang !== "en") {
+ const said = await page.locator("#maskDemo").innerText();
+ for (const w of english) assert(!said.includes(w), `${w} left in English: ${said}`);
+ assert(!(await page.locator(".xq-play").getAttribute("title")).includes("demo"), "the play button's name");
+ }
+ assert.deepEqual(await wide(page), { page: false, over: [] });
+ // every box's text ends inside it; the two whose text flows keep room for a font a
+ // little taller than this one (WebKitGTK's Noto ran the provider's note 16px past its box)
+ assert.deepEqual(await page.evaluate(() => {
+ const k = document.querySelector(".xq-stage").getBoundingClientRect().width / 1000;
+ return [...document.querySelectorAll(".xq-stage .xq-box")].flatMap((b) => {
+ const end = b.getBoundingClientRect().bottom - k;
+ const low = Math.max(...[...b.querySelectorAll("*")].filter((n) => n.getClientRects().length).map((n) => n.getBoundingClientRect().bottom));
+ return (end - low) / k < ({ req: 4, prov: 4 }[b.dataset.k] ?? 0) - .5 ? [`${b.dataset.k} ${Math.round((end - low) / k)}px to spare`] : [];
+ });
+ }), []);
+ if (process.env.MASK_SHOTS) await page.screenshot({ path: path.join(process.env.MASK_SHOTS, `demo_${engine}_${lang}_${width}.png`), fullPage: true });
+
+ await row.click();
+ assert(await page.locator("#mdBody").isHidden(), "folded again");
+ assert.deepEqual(errors, []);
+ });
+ }
+ }
+
+ test(`${engine}: the demo plays while open, stops when folded or covered, and rests at the end`, async (t) => {
+ const { browser, page, errors } = await open(engine, "en", 1100, { motion: true });
+ t.after(() => browser.close());
+ await page.locator("#mdRow").click();
+ await page.locator(".xqd .xq-stage").waitFor();
+ await until(async () => (await state(page)).T > .8);
+ const playing = await state(page);
+ assert.equal(playing.playing, true);
+ if (engine === "chromium") {
+ // Chromium plays VP9: the video is the clock
+ await until(async () => { const s = await state(page); return s.rs >= 2 && !s.paused; });
+ await until(async () => { const s = await state(page); return Math.abs(s.ct - s.T) < .3; });
+ }
+
+ // folded: no frames, the video paused, T held
+ await page.locator("#mdRow").click();
+ await until(async () => !(await state(page)).raf);
+ const held = await state(page);
+ assert.equal(held.paused, true);
+ await page.waitForTimeout(400);
+ assert.equal((await state(page)).T, held.T, "T moved while folded");
+
+ // opened again it goes on from there
+ await page.locator("#mdRow").click();
+ await until(async () => (await state(page)).T > held.T + .3);
+
+ // a request opened over it: hidden and stopped; back, it plays again
+ await page.evaluate((k) => maskOneOpen(k), K);
+ await until(async () => page.locator("#maskDemo").isHidden());
+ await until(async () => !(await state(page)).raf);
+ assert.equal((await state(page)).paused, true);
+ await page.evaluate(() => maskOneClose());
+ await until(async () => page.locator("#maskDemo").isVisible());
+ await until(async () => (await state(page)).raf);
+
+ // the last step plays to the end and stops there: the page comes to rest
+ await page.locator(".xq-steps button").last().click();
+ await until(async () => { const s = await state(page); return !s.playing && !s.raf; }, 12000, page);
+ const end = await state(page);
+ assert(end.T >= 27.4, "rests at the end, T " + end.T);
+ const endless = await page.evaluate(() => document.getAnimations().filter((a) => a.effect?.getComputedTiming().endTime === Infinity).length);
+ assert.equal(endless, 0, "an animation that never ends");
+ // play from the end starts it over
+ await page.locator(".xq-play").click();
+ await until(async () => { const s = await state(page); return s.playing && s.T < 5; });
+ assert.deepEqual(errors, []);
+ });
+
+ test(`${engine}: the dark theme gets the dark take, on the card's colour`, async (t) => {
+ const { browser, page, errors, fetched } = await open(engine, "en", 1100, { theme: "dark" });
+ t.after(() => browser.close());
+ await page.locator("#mdRow").click();
+ await until(() => fetched.includes("xq_dark.webm"));
+ assert(!fetched.includes("xq_light.webm"), "only the theme's take");
+ if (engine === "chromium") {
+ await until(async () => (await state(page)).rs >= 2);
+ await onCard(page);
+ }
+ // the theme changed: the other take, on the light card
+ await page.evaluate(() => { document.documentElement.dataset.theme = "light"; });
+ await until(async () => (await state(page)).src === "xq_light.webm");
+ if (engine === "chromium") {
+ await until(async () => (await state(page)).rs >= 2);
+ await onCard(page);
+ }
+ assert.deepEqual(errors, []);
+ });
+ test(`${engine}: a theme changed while it plays goes on playing, in the new take`, async (t) => {
+ const { browser, page, errors } = await open(engine, "en", 1100, { motion: true });
+ t.after(() => browser.close());
+ await page.locator("#mdRow").click();
+ await until(async () => { const s = await state(page); return !s.paused && s.ct > 1; }, 8000, page);
+ await page.evaluate(() => { document.documentElement.dataset.theme = "dark"; });
+ await until(async () => (await state(page)).src === "xq_dark.webm", 8000, page);
+ const a = await state(page);
+ // the new take plays on from where the old one was, in step with the sheets
+ await until(async () => { const s = await state(page); return !s.paused && s.ct > a.T + .5 && Math.abs(s.ct - s.T) < .3; }, 8000, page);
+ assert.deepEqual(errors, []);
+ });
+}
+
+// her background is the card's: the video's own corners, against the card
+async function onCard(page) {
+ const [card, px] = await page.evaluate(() => {
+ const v = document.querySelector(".xqd video"), c = document.createElement("canvas");
+ c.width = v.videoWidth; c.height = v.videoHeight;
+ const g = c.getContext("2d");
+ g.drawImage(v, 0, 0);
+ const at = [[4, 4], [c.width - 5, 4], [4, c.height / 2]].map(([x, y]) => [...g.getImageData(x, y, 1, 1).data.slice(0, 3)]);
+ const bg = getComputedStyle(document.querySelector("#maskDemo")).backgroundColor.match(/\d+/g).slice(0, 3).map(Number);
+ return [bg, at];
+ });
+ for (const p of px) assert(p.every((v, i) => Math.abs(v - card[i]) <= 6), `video ${p} on card ${card}`);
+}