Public: anyone can read this; the crew can change it.
Talk's frame reloads on a fresh grant, so a landing deploy no longer leaves it white #16352
Check · Review · Land · Live done — Landed and live in production.
talk/frame-landing → main 0 commits 2 threads · 2 unresolved
6 files
changed +116
−39
docs/design/size-budget.json +1 −1
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | "css": 48640 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 39680, | |
| 71 | "js": 39936, | |
| 72 | 72 | "css": 55808 |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
docs/features/talk.md +5 −1
| @@ -136,7 +136,7 @@ A reply is drawn by the README renderer and then, for Talk alone, by `linkTalk` | ||
| 136 | 136 | |
| 137 | 137 | An agent reply is Markdown, drawn on the server by the same renderer as a README: fenced code is highlighted, tables and links render, and everything else is escaped (a `<script>` in a reply shows as text). A table wider than the column scrolls inside it; the page does not. The reply sits in the column like a person's turn, with none of the README's padding or line measure. |
| 138 | 138 | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 18,100 B, the script under 49,100 B, and a page with a code reply under 53,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 18,100 B, the script under 50,400 B, and a page with a code reply under 53,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 140 | 140 | |
| 141 | 141 | ## Following |
| 142 | 142 | |
| @@ -183,6 +183,10 @@ After you confirm a held action, the thread shows a receipt: the verb, the objec | ||
| 183 | 183 | |
| 184 | 184 | The terminal's Talk screen reads the same file: `d` on the list, or `d` or `x` in an open chat, shows the conversation as the Markdown `/talk/:id/download` serves (`conversationMarkdown`), its owner's alone. Each turn's words sit in a fenced block, so no message can forge a turn heading; past a million characters the earliest turns are left out and the file says so. The MCP `say` tool's `download` with no `conversation` takes the latest one. |
| 185 | 185 | |
| 186 | ## When the preview times out | |
| 187 | ||
| 188 | The preview frame opens with a sign-in link that lasts a few minutes, and every reload asks the forge for a fresh one. If the frame ever loads an old link, it says "The preview opened here has timed out." Press Reload above the preview to open it again. | |
| 189 | ||
| 186 | 190 | ## Display (#15734) |
| 187 | 191 | |
| 188 | 192 | Four preferences of the person's own, at the end of the conversation menu (⋯ → Display), one plain form that works without the script (`POST /talk/display`, signed in, same origin): spacing (comfortable or compact: the spacing scale only, never the type size), motion (as the system says, or reduced: Talk's arrivals, the head's slide and the shimmer stop whatever the system says), what Enter does (sends, or adds a line with Ctrl or Cmd+Enter sending) and whether a reply's steps start folded or open. They are the person's `user_setting` rows (`talk.density`, `talk.motion`, `talk.enter`, `talk.steps`, read by `talkDisplay` in `src/core/settings.ts`), applied by the server so the first paint is right; a value that is not one of a preference's own choices is never kept. No theme builder, no colours. The terminal honours the same steps choice: a conversation opened in `forge talk` shows a run of steps as one line ("3 steps") or each step, and `v` there flips the choice for both places, while `D` opens Talk display to set all four (docs/features/talk-display.md); spacing, motion and Enter are the page's own (the terminal has its own rows, no animation, and its `s` prompt always sends on Enter). |
src/apps/proxy.ts +49 −27
| @@ -925,11 +925,7 @@ function toSignIn(runtime: AppsRuntime, request: Request, to?: string): Response | ||
| 925 | 925 | |
| 926 | 926 | /** What a frame is told instead of a sign-in redirect it cannot follow: one sentence and a link out. */ |
| 927 | 927 | function needsSignIn(href: string): Response { |
| 928 | const html = `<!doctype html> | |
| 929 | <meta charset="utf-8"> | |
| 930 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 931 | <title>Sign in to see this</title> | |
| 932 | <style>:root{color-scheme:light dark;font:16px/1.5 system-ui,sans-serif}body{max-width:30rem;margin:18vh auto;padding:0 1.5rem}</style> | |
| 928 | const html = `${sentenceHead("Sign in to see this")} | |
| 933 | 929 | <p>This preview is private, and this frame cannot show who you are. <a href="${escape(href)}" target="_blank" rel="noopener">Open it on its own</a>.</p> |
| 934 | 930 | `; |
| 935 | 931 | return securityFloor( |
| @@ -1883,6 +1879,11 @@ function grant( | ||
| 1883 | 1879 | const token = url.searchParams.get("t") ?? ""; |
| 1884 | 1880 | const vouched = readGrant(runtime.app.config.dataDir, token, target); |
| 1885 | 1881 | if (vouched === undefined) { |
| 1882 | // A grant this forge signed for this app that has run out, opened in the Talk pane's frame: a | |
| 1883 | // bare not-found under the floor draws nothing there (a white frame), so the frame is told in a | |
| 1884 | // sentence. Only a genuine grant gets it, so it says nothing to someone who never held one. | |
| 1885 | if (request.headers.get("sec-fetch-dest") === "iframe" && readGrant(runtime.app.config.dataDir, token, target, 0) !== undefined) | |
| 1886 | return ranOutPage(runtime); | |
| 1886 | 1887 | return new Response("not found", { status: 404 }); |
| 1887 | 1888 | } |
| 1888 | 1889 | // The pane's frame. On another site than the app's host (a custom domain, a forge on its own |
| @@ -2027,18 +2028,7 @@ export function unavailable( | ||
| 2027 | 2028 | ) |
| 2028 | 2029 | exits.push(`<a href="${escape(runtime.urlFor(target.app, "production"))}">Production</a>`); |
| 2029 | 2030 | exits.push(`<a href="${escape(new URL("/", forge).href)}">Forge home</a>`); |
| 2030 | const html = `<!doctype html> | |
| 2031 | <meta charset="utf-8"> | |
| 2032 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 2033 | ${deploying ? '<meta http-equiv="refresh" content="3">' : ""} | |
| 2034 | <title>${escape(name)} — ${deploying ? doing : gone ? "gone" : "not running"}</title> | |
| 2035 | <style> | |
| 2036 | :root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; } | |
| 2037 | body { max-width: 34rem; margin: 20vh auto; padding: 0 1.5rem; } | |
| 2038 | h1 { font-size: 1.25rem; margin: 0 0 .5rem; } | |
| 2039 | p { margin: .5rem 0; opacity: .85; } | |
| 2040 | code { font-size: .9em; } | |
| 2041 | </style> | |
| 2031 | const html = `${sentenceHead(`${escape(name)} — ${deploying ? doing : gone ? "gone" : "not running"}`, deploying ? '<meta http-equiv="refresh" content="3">' : "")} | |
| 2042 | 2032 | <h1>${escape(name)} ${deploying ? `is ${doing}` : gone ? "is gone" : "is not running"}</h1> |
| 2043 | 2033 | <p>This is ${escape(where)}. ${escape(message)}</p> |
| 2044 | 2034 | ${deploying ? "<p>This page refreshes on its own.</p>" : ""} |
| @@ -2066,6 +2056,47 @@ ${report ? '<p><a href="/__forge/report">Report a problem</a> to the people who | ||
| 2066 | 2056 | ); |
| 2067 | 2057 | } |
| 2068 | 2058 | |
| 2059 | /** | |
| 2060 | * The pane's frame when the grant that opened it has run out: the forge's sentence in its | |
| 2061 | * sentence-page look, framed by the forge's own origin only, with nothing that runs. The pane's | |
| 2062 | * Reload, above it, reads a fresh grant. | |
| 2063 | */ | |
| 2064 | function ranOutPage(runtime: AppsRuntime): Response { | |
| 2065 | const forge = new URL(runtime.options.forgeUrl).origin; | |
| 2066 | const html = `${sentenceHead("Timed out")} | |
| 2067 | <p>The preview opened here has timed out. Press Reload above the preview.</p> | |
| 2068 | `; | |
| 2069 | return securityFloor( | |
| 2070 | new Response(html, { | |
| 2071 | status: 410, | |
| 2072 | headers: { | |
| 2073 | "content-type": "text/html; charset=utf-8", | |
| 2074 | "cache-control": "no-store", | |
| 2075 | "content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; frame-ancestors ${forge}; base-uri 'none'; form-action 'none'`, | |
| 2076 | }, | |
| 2077 | }), | |
| 2078 | ); | |
| 2079 | } | |
| 2080 | ||
| 2081 | /** | |
| 2082 | * The head of every sentence-page the forge answers on an app's host (not running, archived, timed | |
| 2083 | * out): one look for all of them, plain system type in the reader's light or dark, nothing that runs. | |
| 2084 | * `title` is already escaped; `extra` is the forge's own markup (a refresh). | |
| 2085 | */ | |
| 2086 | function sentenceHead(title: string, extra = ""): string { | |
| 2087 | return `<!doctype html> | |
| 2088 | <meta charset="utf-8"> | |
| 2089 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 2090 | ${extra}<title>${title}</title> | |
| 2091 | <style> | |
| 2092 | :root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; } | |
| 2093 | body { max-width: 34rem; margin: 20vh auto; padding: 0 1.5rem; } | |
| 2094 | h1 { font-size: 1.25rem; margin: 0 0 .5rem; } | |
| 2095 | p { margin: .5rem 0; opacity: .85; } | |
| 2096 | code { font-size: .9em; } | |
| 2097 | </style>`; | |
| 2098 | } | |
| 2099 | ||
| 2069 | 2100 | /** Set on the forge's own sentence-pages so the proxy can tell them from an app's answer; never sent. */ |
| 2070 | 2101 | const HOLDING_MARK = "x-forge-holding"; |
| 2071 | 2102 | |
| @@ -2077,16 +2108,7 @@ const HOLDING_POLICY = | ||
| 2077 | 2108 | /** The short page an archived repository's app answers with: 503, not a 502. */ |
| 2078 | 2109 | function archivedPage(target: AppTarget): Response { |
| 2079 | 2110 | const name = escape(target.app.slug); |
| 2080 | const html = `<!doctype html> | |
| 2081 | <meta charset="utf-8"> | |
| 2082 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 2083 | <title>${name} — archived</title> | |
| 2084 | <style> | |
| 2085 | :root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; } | |
| 2086 | body { max-width: 34rem; margin: 20vh auto; padding: 0 1.5rem; } | |
| 2087 | h1 { font-size: 1.25rem; margin: 0 0 .5rem; } | |
| 2088 | p { margin: .5rem 0; opacity: .85; } | |
| 2089 | </style> | |
| 2111 | const html = `${sentenceHead(`${name} — archived`)} | |
| 2090 | 2112 | <h1>${name} is archived</h1> |
| 2091 | 2113 | <p>Its people have put it away. It is not running, and its data is kept.</p> |
| 2092 | 2114 | `; |
src/web/pages/talk_client.ts +22 −6
| @@ -988,12 +988,28 @@ ${dictateJs} | ||
| 988 | 988 | const f = e.target.querySelector("[data-frame]"), shell = document.querySelector("[data-shell]"); |
| 989 | 989 | if (f && shell && shell.dataset.frameOrigin !== new URL(f.src).origin && !answering) window.location.reload(); |
| 990 | 990 | }); |
| 991 | const reframe = () => document.querySelectorAll("[data-frame]").forEach((f) => { | |
| 992 | const s = f.closest("[data-stage]"), n = s && s.querySelector("[data-stage-note]"); | |
| 993 | if (n) { s.setAttribute("data-busy", ""); n.hidden = false; } | |
| 994 | f.addEventListener("load", () => { if (n) { s.removeAttribute("data-busy"); n.hidden = true; } }, { once: true }); | |
| 995 | f.src = f.src; | |
| 996 | }); | |
| 991 | // A frame's address carries a grant the forge signed for two minutes, so it is never loaded twice: | |
| 992 | // the pane is read again and the frame loads the fresh address it names, on the same origin. A pane | |
| 993 | // that frames nothing now (the app not serving) leaves the frame as it was, under no note. | |
| 994 | const reframe = () => { | |
| 995 | const frames = [...document.querySelectorAll("[data-frame]")]; | |
| 996 | if (frames.length === 0) return; | |
| 997 | const notes = frames.map((f) => { | |
| 998 | const s = f.closest("[data-stage]"), n = s && s.querySelector("[data-stage-note]"); | |
| 999 | if (n) { s.setAttribute("data-busy", ""); n.hidden = false; } | |
| 1000 | return () => { if (n) { s.removeAttribute("data-busy"); n.hidden = true; } }; | |
| 1001 | }); | |
| 1002 | fetch("?pane=preview&fragment=pane", { headers: { accept: "text/html" } }).then((r) => (r.ok ? r.text() : "")).catch(() => "").then((text) => { | |
| 1003 | const t = document.createElement("template"); | |
| 1004 | t.innerHTML = text; | |
| 1005 | const fresh = t.content.querySelector("[data-frame]"), src = fresh && fresh.getAttribute("src"); | |
| 1006 | frames.forEach((f, i) => { | |
| 1007 | if (!src || new URL(src, window.location.href).origin !== new URL(f.src, window.location.href).origin) { notes[i](); return; } | |
| 1008 | f.addEventListener("load", notes[i], { once: true }); | |
| 1009 | f.src = src; | |
| 1010 | }); | |
| 1011 | }); | |
| 1012 | }; | |
| 997 | 1013 | // The build panel is a live region of its own (?fragment=build), swapped as its runs and pull |
| 998 | 1014 | // move, and read again when a turn lands: a new version settles in and the frame reloads; a |
| 999 | 1015 | // preview that has just become ready loads the page once, since its origin joins frame-src. |
test/talk-page.test.ts +20 −3
| @@ -454,7 +454,7 @@ describe("the page", () => { | ||
| 454 | 454 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 455 | 455 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 456 | 456 | expect(Buffer.byteLength(talkCss)).toBeLessThan(18_100); |
| 457 | expect(Buffer.byteLength(talkJs)).toBeLessThan(49_400); | |
| 457 | expect(Buffer.byteLength(talkJs)).toBeLessThan(50_400); | |
| 458 | 458 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. |
| 459 | 459 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); |
| 460 | 460 | if (!sizer.ok) throw new Error(sizer.error); |
| @@ -644,8 +644,11 @@ describe("the page", () => { | ||
| 644 | 644 | t.doc.body.appendChild(frame); |
| 645 | 645 | t.sources.at(-1)!.on["running"]!({ data: "{}" }); |
| 646 | 646 | expect(loads).toEqual([]); |
| 647 | // Never the address it was opened with: its grant has run out by now. The pane names a fresh one. | |
| 648 | t.page.html = '<aside class="talk-pane"><div data-stage><iframe data-frame src="https://x.example/__forge/grant?t=fresh"></iframe></div></aside>'; | |
| 647 | 649 | t.sources.at(-1)!.on["done"]!({ data: "{}" }); |
| 648 | expect(loads).toEqual(["https://x.example/"]); | |
| 650 | await pollUntil(() => loads.length > 0, "the frame loaded again"); | |
| 651 | expect(loads).toEqual(["https://x.example/__forge/grant?t=fresh"]); | |
| 649 | 652 | }); |
| 650 | 653 | |
| 651 | 654 | test("a head that slid away comes back when focus enters it, so a keyboard user never loses the conversation menu", async () => { |
| @@ -666,7 +669,7 @@ describe("the page", () => { | ||
| 666 | 669 | work.innerHTML = '<section class="talk-build" id="talk-build" data-versions="1" data-preview="ready" data-live-src="/talk/c1?fragment=build"><a>v1</a></section><aside class="talk-pane"><div class="talk-stage" data-stage><iframe data-frame src="https://app--2.example/"></iframe><p data-stage-note hidden>Updating the preview…</p></div></aside>'; |
| 667 | 670 | t.doc.body.appendChild(work); |
| 668 | 671 | const frame = work.querySelector("[data-frame]"); |
| 669 | t.page.html = '<section class="talk-build" id="talk-build" data-versions="2" data-preview="ready" data-live-src="/talk/c1?fragment=build"><a>v1</a><a>v2</a></section>'; | |
| 672 | t.page.html = '<section class="talk-build" id="talk-build" data-versions="2" data-preview="ready" data-live-src="/talk/c1?fragment=build"><a>v1</a><a>v2</a></section><aside class="talk-pane"><div class="talk-stage" data-stage><iframe data-frame src="https://app--2.example/__forge/grant?t=v2"></iframe></div></aside>'; | |
| 670 | 673 | t.emit("2", '<li class="talk-turn talk-tool talk-step" id="t-2" data-step><details><summary>Edited server.ts</summary></details></li>'); |
| 671 | 674 | await tick(); |
| 672 | 675 | expect(t.urls).toContain("/talk/c1?fragment=build"); |
| @@ -674,6 +677,7 @@ describe("the page", () => { | ||
| 674 | 677 | expect(t.doc.querySelector(".talk-build").dataset.versions).toBe("2"); |
| 675 | 678 | const stage = work.querySelector("[data-stage]"); |
| 676 | 679 | expect([stage.hasAttribute("data-busy"), stage.querySelector("[data-stage-note]").hidden]).toEqual([true, false]); |
| 680 | await pollUntil(() => frame.getAttribute("src") === "https://app--2.example/__forge/grant?t=v2", "the frame on the pane's fresh address"); | |
| 677 | 681 | frame.dispatchEvent(new t.window.Event("load")); |
| 678 | 682 | expect([stage.hasAttribute("data-busy"), stage.querySelector("[data-stage-note]").hidden]).toEqual([false, true]); |
| 679 | 683 | // The same count again moves nothing. |
| @@ -1235,10 +1239,23 @@ describe("the page", () => { | ||
| 1235 | 1239 | const deploy = (env: string, repo = "alice/x") => t.doc.dispatchEvent(new t.window.CustomEvent("forge:event", { detail: { kind: "run.finished", repo, payload: { kind: "deploy", state: "ok", env } } })); |
| 1236 | 1240 | deploy("production", "bob/other"); |
| 1237 | 1241 | expect(t.doc.querySelector("[data-stage]").hasAttribute("data-busy")).toBe(false); |
| 1242 | // The frame's address holds a grant signed for two minutes: the reload asks the pane again and | |
| 1243 | // loads the fresh address it names, never the one it was opened with (0.7.648's white frame). | |
| 1244 | const frame = t.doc.querySelector("[data-frame]"); | |
| 1245 | t.page.html = '<aside class="talk-pane"><div class="talk-stage" data-stage data-env="production"><iframe data-frame src="http://app.test/__forge/grant?t=fresh"></iframe></div></aside>'; | |
| 1238 | 1246 | deploy("production"); |
| 1239 | 1247 | expect([t.doc.querySelector("[data-stage]").hasAttribute("data-busy"), reloads]).toEqual([true, 0]); |
| 1248 | await pollUntil(() => frame.getAttribute("src") === "http://app.test/__forge/grant?t=fresh", "the frame on a fresh grant"); | |
| 1249 | frame.dispatchEvent(new t.window.Event("load")); | |
| 1250 | expect(t.doc.querySelector("[data-stage]").hasAttribute("data-busy")).toBe(false); | |
| 1251 | // The pane framing nothing now (the app not serving), the frame is left as it was, under no note. | |
| 1252 | t.page.html = '<aside class="talk-pane"><div class="talk-stage talk-stage-wait" data-stage></div></aside>'; | |
| 1253 | deploy("production"); | |
| 1254 | await pollUntil(() => !t.doc.querySelector("[data-stage]").hasAttribute("data-busy"), "the note taken down"); | |
| 1255 | expect(frame.getAttribute("src")).toBe("http://app.test/__forge/grant?t=fresh"); | |
| 1240 | 1256 | deploy("pull-2"); |
| 1241 | 1257 | expect(reloads).toBe(1); |
| 1258 | t.urls.length = 0; | |
| 1242 | 1259 | // A pull's preview framed when production deploys: the pane is asked what it frames now. The |
| 1243 | 1260 | // pull still open, it frames the pull and nothing moves; the pull landed, production is framed |
| 1244 | 1261 | // and the page draws once for its origin. |
test/talk-preview-frame.test.ts +19 −1
| @@ -143,9 +143,27 @@ describe("the grant in the frame's address", () => { | ||
| 143 | 143 | |
| 144 | 144 | test("an expired grant, and one signed for another app, are refused", async () => { |
| 145 | 145 | const expired = signGrant(app.config.dataDir, targetOf("priv"), -1_000, Date.now(), who()); |
| 146 | expect((await grantAt("priv", expired)).status).toBe(404); | |
| 146 | expect((await grantAt("priv", expired, "document")).status).toBe(404); | |
| 147 | 147 | const other = signGrant(app.config.dataDir, targetOf("pub"), 60_000, Date.now(), who()); |
| 148 | 148 | expect((await grantAt("priv", other)).status).toBe(404); |
| 149 | // A token nobody signed, in a frame, is the bare not-found a stranger gets. | |
| 150 | const forged = `${expired.slice(0, expired.lastIndexOf("."))}.AAAA`; | |
| 151 | const bare = await grantAt("priv", forged); | |
| 152 | expect([bare.status, await bare.text()]).toEqual([404, "not found"]); | |
| 153 | }); | |
| 154 | ||
| 155 | test("a genuine grant that ran out, reloaded in the pane's frame, says so in a page the forge may frame (#16347's white frame)", async () => { | |
| 156 | // The pane reloaded the address its frame was opened with, after the two minutes its grant lives. | |
| 157 | const spent = signGrant(app.config.dataDir, targetOf("priv"), -1_000, Date.now(), who()); | |
| 158 | const answer = await grantAt("priv", spent); | |
| 159 | expect(answer.status).toBe(410); | |
| 160 | expect(await answer.text()).toContain("The preview opened here has timed out. Press Reload above the preview."); | |
| 161 | expect(answer.headers.get("set-cookie")).toBeNull(); | |
| 162 | expect(answer.headers.get("location")).toBeNull(); | |
| 163 | const csp = answer.headers.get("content-security-policy") ?? ""; | |
| 164 | expect(csp).toContain(`frame-ancestors ${origin};`); | |
| 165 | expect(csp).toContain("default-src 'none'"); | |
| 166 | expect(csp).not.toContain("script-src"); | |
| 149 | 167 | }); |
| 150 | 168 | |
| 151 | 169 | test("in a frame its cookie is kept per embedding site; opened on its own it stays Lax", async () => { |
new above
offline