Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Convert JPEG and WebP to the size of their space in the transcript
razorback16259034ec2d8c
diff --git a/README.md b/README.mdindex 401fff0..d0e2d11 100644--- a/README.md+++ b/README.md@@ -20,7 +20,7 @@ Only the drawing changes. The saved answer stays Markdown.A `theme` dictionary (`theme.fg`, `theme.muted`, `theme.blue`, `theme.palette`, `theme.width`, …) is in scope, so drawings match the terminal's colours. The mod tells Claude about this in a short part of the system prompt.- Files that Claude sends to you (the SendUserFile tool). The mod draws each file under the row that shows the files, in the same order:- - PNG, JPEG and WebP images. Typst changes a JPEG or WebP image into a PNG image in the cache folder. It does this one time for each version of the file. The long side of that PNG image is 4096 pixels or less.+ - PNG, JPEG and WebP images. Typst changes a JPEG or WebP image into a PNG image in the cache folder. The PNG image is the size of the space for the picture in the transcript, or smaller. Typst does this one time for each version of the file and each size of the space. When the space changes, the mod shows the old PNG image until Typst makes the new one.- Markdown files (`.md` or `.markdown`, 256 KiB or less). The mod draws the file as rendered pictures, the same as an answer. A relative image path in the file starts from the folder of the file.Other files stay as the normal row. JPEG images, WebP images and Markdown files need Typst.diff --git a/hooks/lib/images.ts b/hooks/lib/images.tsindex 36b053f..82e08e5 100644--- a/hooks/lib/images.ts+++ b/hooks/lib/images.ts@@ -3,7 +3,7 @@// images, and the cells a picture takes. The drawing on the host is in// pictures.tsx.import type { Cell } from './state'-import { MAX_IMAGE_ROWS, PICTURE_MAX_ROWS, PICTURE_MIN_ROWS } from './settings'+import { CONVERT_MAX_SIDE, MAX_IMAGE_ROWS, PICTURE_MAX_ROWS, PICTURE_MIN_ROWS } from './settings'import { hashOf } from './draw'// The most rows a picture under a row takes: half the viewport, within@@ -66,10 +66,19 @@ export const sentImages = (output: unknown) => sentFiles(output).filter(f => f.k// The folder of a file, for the relative images of a Markdown file.export const folderOf = (path: string) => path.replace(/\/+[^/]*$/, '') || '/'+// The box in pixels a JPEG or WebP is made to fit: the space a picture+// takes (as pictureCells), each side at most CONVERT_MAX_SIDE.+export type PixelBox = { width: number; height: number }+export function convertBox(columns: number, rows: number, px: Cell): PixelBox {+ const side = (n: number) => Math.max(1, Math.min(CONVERT_MAX_SIDE, Math.round(n)))+ return { width: side(columns * px.width), height: side(rows * px.height) }+}+// The PNG Typst makes of a JPEG or WebP: in a key folder of the cache (as a-// compile's, dropped after 2 days), by the file and its stat stamp, so a-// changed file is made again.-export const convertedPath = (cache: string, file: string, stamp: string) => `${cache}/${hashOf(['convert', file, stamp])}/image.png`+// compile's, dropped after 2 days), by the file, its stat stamp and the box,+// so a changed file or a new box is made again.+export const convertedPath = (cache: string, file: string, stamp: string, box: PixelBox) =>+ `${cache}/${hashOf(['convert', file, stamp, box.width, box.height])}/image.png`// The numbers of the `[Image #N]` marks in a prompt, each once, in order.export function pastedNumbers(text: string): number[] {diff --git a/hooks/lib/pictures.tsx b/hooks/lib/pictures.tsxindex cd8afb8..6321253 100644--- a/hooks/lib/pictures.tsx+++ b/hooks/lib/pictures.tsx@@ -5,9 +5,9 @@import type { EngineInterface, ImageSource, RenderElement, RenderInput } from 'claude-code'import { COMPILE_TIMEOUT_MS, DEFAULT_CELL, GUTTER, PICTURES_KEPT, SENT_TEXT_MAX_BYTES } from './settings'-import { converted, converting, INLINE_KEPT, inlined, pasteDirs, pictures, S, sentTexts, type Env } from './state'+import { converted, converting, INLINE_KEPT, inlined, lastConverted, pasteDirs, pictures, refresh, S, sentTexts, type Env } from './state'import { columnsFor, fitsInline, INLINE_MAX_BYTES } from './terminal'-import { convertedPath, folderOf, pasteDirOf, pictureCells, pictureRowsFor, type SentFile } from './images'+import { convertBox, convertedPath, folderOf, pasteDirOf, pictureCells, pictureRowsFor, type PixelBox, type SentFile } from './images'import { imagePathOf } from './markdown'import { drawPages, hashOf } from './draw'import { convertCall, logDebug, parseOd, pngSize } from './typst'@@ -86,27 +86,34 @@ export async function shownOne($: EngineInterface, e: RowInput, ready: Env, fileconst nameOf = (file: string) => file.split('/').pop() || 'image'// A JPEG or WebP as a PNG that Typst makes (render/convert.typ) in the-// cache: once per stat stamp, and one run at a time per file. Null with no-// Typst, or when it fails (the row stays as is).-export async function convertedOf($: EngineInterface, ready: Env, file: string): Promise<string | null> {+// cache, to fit `box`: once per stat stamp and box, one run at a time per+// key. The first PNG of a file is waited for; for a new box, the last PNG+// of the file draws at once while the new one is made, then a refresh+// draws it. Null with no Typst, or when it fails (the row stays as is).+export async function convertedOf($: EngineInterface, ready: Env, file: string, box: PixelBox): Promise<string | null> {if (!ready.typst) return nullconst st = await $.fs.stat(file).catch(() => null)if (!st || st.kind !== 'file') return nullconst stamp = `${st.mtimeMs}:${st.size}`- const kept = converted.get(file)- if (kept?.stamp === stamp) return kept.png- const key = `${file}@${stamp}`+ const last = lastConverted.get(file)+ const before = last?.stamp === stamp ? last.png : null+ const key = `${file}@${stamp}@${box.width}x${box.height}`+ if (converted.has(key)) return converted.get(key) ?? beforelet run = converting.get(key)if (!run) {- run = convertOnce($, ready, file, stamp).finally(() => converting.delete(key))+ // A new box while another box of this file is made: wait for that run+ // (its refresh draws the row again, with the box of that time).+ if (before && [...converting.keys()].some(k => k.startsWith(`${file}@${stamp}@`))) return before+ run = convertOnce($, ready, file, stamp, box, key).finally(() => converting.delete(key))converting.set(key, run)+ if (before) void run.then(() => refresh($), () => undefined)}- return run+ return before ?? run}-async function convertOnce($: EngineInterface, ready: Env, file: string, stamp: string): Promise<string | null> {- const out = convertedPath(ready.cache, file, stamp)- // Made before (an earlier load): the same file at the same stamp.+async function convertOnce($: EngineInterface, ready: Env, file: string, stamp: string, box: PixelBox, key: string): Promise<string | null> {+ const out = convertedPath(ready.cache, file, stamp, box)+ // Made before (an earlier load): the same file, stamp and box.const made = await $.fs.stat(out).catch(() => null)let png: string | null = outif (made?.kind !== 'file' || !made.size) {@@ -117,7 +124,7 @@ async function convertOnce($: EngineInterface, ready: Env, file: string, stamp:// Typst writes a part file, moved to image.png only once it is whole, so// a run that is killed or fails leaves no image.png for a later load.const part = `${dir}/image.part.png`- const { argv, env } = convertCall({ typst: ready.typst!, root: ready.root, cache: ready.cache, file, out: part })+ const { argv, env } = convertCall({ typst: ready.typst!, root: ready.root, cache: ready.cache, file, box, out: part })const failed = (err: unknown) => ({ exitCode: 1, stdout: '', stderr: `did not run: ${String(err)}` })const ran = await $.process.run(argv, { timeoutMs: COMPILE_TIMEOUT_MS, env }).catch(failed)const moved = ran.exitCode === 0 ? await $.process.run(['mv', '-f', part, out]).catch(failed) : null@@ -129,15 +136,21 @@ async function convertOnce($: EngineInterface, ready: Env, file: string, stamp:png = null}}- converted.delete(file)- converted.set(file, { stamp, png })- for (const old of converted.keys()) {- if (converted.size <= PICTURES_KEPT) break- converted.delete(old)- }+ keep(converted, key, png)+ if (png) keep(lastConverted, file, { stamp, png })return png}+// Sets a cache entry as the newest; the oldest go past PICTURES_KEPT.+function keep<T>(cache: Map<string, T>, key: string, value: T) {+ cache.delete(key)+ cache.set(key, value)+ for (const old of cache.keys()) {+ if (cache.size <= PICTURES_KEPT) break+ cache.delete(old)+ }+}+// A Markdown file's text, read again only when its stat changes; null when// it is gone, over SENT_TEXT_MAX_BYTES, not read, or empty.export async function sentTextOf($: EngineInterface, file: string): Promise<string | null> {@@ -148,12 +161,7 @@ export async function sentTextOf($: EngineInterface, file: string): Promise<striif (kept?.stamp === stamp) return kept.textconst got = st.size <= SENT_TEXT_MAX_BYTES ? await $.fs.read(file).catch(() => null) : nullconst text = got?.trim() ? got : null- sentTexts.delete(file)- sentTexts.set(file, { stamp, text })- for (const old of sentTexts.keys()) {- if (sentTexts.size <= PICTURES_KEPT) break- sentTexts.delete(old)- }+ keep(sentTexts, file, { stamp, text })return text}@@ -165,6 +173,8 @@ export async function sentOf($: EngineInterface, e: RowInput, o: { ready: Env; markdown: Env | null; files: readonly SentFile[]; id: string },): Promise<Under[]> {const columns = columnsFor(e.viewport?.columns)+ // The space a picture takes (as in shownOne), which a JPEG or WebP is made to fit.+ const box = convertBox(columns, pictureRowsFor(e.viewport?.rows), S.cell ?? DEFAULT_CELL)const under: Under[] = []for (const f of o.files) {const full = imagePathOf(f.path, o.ready.cwd)@@ -175,7 +185,7 @@ export async function sentOf(if (drawing.kind !== 'text') under.push({ drawing, columns })continue}- const png = f.kind === 'png' ? full : await convertedOf($, o.ready, full)+ const png = f.kind === 'png' ? full : await convertedOf($, o.ready, full, box)const shown = png ? await shownOne($, e, o.ready, png, nameOf(full)) : nullif (shown) under.push(shown)}diff --git a/hooks/lib/settings.ts b/hooks/lib/settings.tsindex 7c73a33..0c81e15 100644--- a/hooks/lib/settings.ts+++ b/hooks/lib/settings.ts@@ -65,8 +65,8 @@ export const PICTURES_KEPT = 64// A Markdown file Claude sends (SendUserFile) draws when it is at most this// many bytes.export const SENT_TEXT_MAX_BYTES = 256 * 1024-// The PNG Typst makes of a JPEG or WebP: its long side at most this many-// pixels (never made larger).+// The PNG Typst makes of a JPEG or WebP fits the space of the picture, and+// each side is at most this many pixels (never made larger).export const CONVERT_MAX_SIDE = 4096// What Claude is told while the mod draws its answers (a system promptdiff --git a/hooks/lib/state.ts b/hooks/lib/state.tsindex b126b99..1801576 100644--- a/hooks/lib/state.ts+++ b/hooks/lib/state.ts@@ -137,11 +137,14 @@ export const INLINE_KEPT = 64// PNG), and the pasted-images folder of each session once found.export const pictures = new Map<string, { stamp: string; size: { width: number; height: number } | null }>()export const pasteDirs = new Map<string, string>()-// SendUserFile: the PNG Typst made of each JPEG or WebP by its stat stamp-// (null: it failed), the ones Typst makes now, and the text of each Markdown-// file by its stat stamp (null: it does not draw).-export const converted = new Map<string, { stamp: string; png: string | null }>()+// SendUserFile: the PNG Typst made of each JPEG or WebP by its file, stat+// stamp and box (null: it failed), the ones Typst makes now (same keys), the+// last PNG made of each file (any box: it draws while a new box is made),+// and the text of each Markdown file by its stat stamp (null: it does not+// draw).+export const converted = new Map<string, string | null>()export const converting = new Map<string, Promise<string | null>>()+export const lastConverted = new Map<string, { stamp: string; png: string }>()export const sentTexts = new Map<string, { stamp: string; text: string | null }>()// The plan: the text edited in md-preview's flow, by the call's tool_use_id// (its rows draw it), and the ExitPlanMode calls of subagents (drawn as thediff --git a/hooks/lib/typst.ts b/hooks/lib/typst.tsindex 584e1a9..6471023 100644--- a/hooks/lib/typst.ts+++ b/hooks/lib/typst.ts@@ -2,7 +2,7 @@// answer's segments to PNG pages (with a retry in safe mode).import type { EngineInterface } from 'claude-code'-import { COMPILE_TIMEOUT_MS, CONVERT_MAX_SIDE, NO_NETWORK, SEGMENT_ROWS, TYPST_FALLBACKS } from './settings'+import { COMPILE_TIMEOUT_MS, NO_NETWORK, SEGMENT_ROWS, TYPST_FALLBACKS } from './settings'import { DEFAULT_METRICS, type FontMetrics, type Job, type Metrics, type Result } from './state'import { firstLine, imagePathOf, localImages, plainOf, splitSegments } from './markdown'import { inlineBudget } from './terminal'@@ -34,9 +34,16 @@ export function typstCall(o: {}// The typst command that makes a PNG of a JPEG or WebP (render/convert.typ)-// at its own pixel size, its long side at most CONVERT_MAX_SIDE: at 72 ppi,-// 1 pt is 1 pixel.-export function convertCall(o: { typst: string; root: string; cache: string; file: string; out: string }): { argv: string[]; env: Record<string, string> } {+// that fits `box` (in pixels), never larger than its own pixel size: at 72+// ppi, 1 pt is 1 pixel.+export function convertCall(o: {+ typst: string+ root: string+ cache: string+ file: string+ box: { width: number; height: number }+ out: string+}): { argv: string[]; env: Record<string, string> } {const argv = [o.typst, 'compile','--root', '/',@@ -44,7 +51,8 @@ export function convertCall(o: { typst: string; root: string; cache: string; fil'--diagnostic-format', 'short','--ppi', '72','--input', `f=${o.file}`,- '--input', `max=${CONVERT_MAX_SIDE}`,+ '--input', `maxw=${o.box.width}`,+ '--input', `maxh=${o.box.height}`,`${o.root}/render/convert.typ`,o.out,]diff --git a/render/convert.typ b/render/convert.typindex 01d9cc7..7633cb1 100644--- a/render/convert.typ+++ b/render/convert.typ@@ -1,8 +1,8 @@// md-preview: makes a PNG of a JPEG or WebP (the engine's Image draws PNG// only). Compiled at 72 ppi, where 1 pt is 1 pixel.//-// Inputs: f = the image's absolute path (with --root /); max = the most-// pixels of the long side (0 or absent: no cap).+// Inputs: f = the image's absolute path (with --root /); maxw, maxh = the+// box in pixels the PNG must fit (0 or absent: no limit on that side).//// Typst sizes an image by its own DPI (a 300 dpi JPEG is drawn at a quarter// of its pixels), so the pixel size is read from the file and set as the@@ -43,14 +43,15 @@#let size = if has-tag(0, "RIFF") and has-tag(8, "WEBP") { webp-size() } else if at(0) == 0xff and at(1) == 0xd8 { jpeg-size() }// The sides as drawn: the pixel size, swapped when Typst turns the image by-// its EXIF orientation; else Typst's own size. The long side is at most-// `max` pixels (0: no cap); an image is never made larger.+// its EXIF orientation; else Typst's own size. Then it fits the box, the+// aspect kept; an image is never made larger.#context {let natural = measure(image(data))let (w, h) = if size == none or size.at(0) == 0 or size.at(1) == 0 { (natural.width / 1pt, natural.height / 1pt) } else { size }let turned = w != h and (natural.width > natural.height) != (w > h)let (dw, dh) = if turned { (h, w) } else { (w, h) }- let max = int(sys.inputs.at("max", default: "0"))- let scale = if max > 0 { calc.min(1, max / calc.max(dw, dh)) } else { 1 }+ let side(key) = int(sys.inputs.at(key, default: "0"))+ let (maxw, maxh) = (side("maxw"), side("maxh"))+ let scale = calc.min(1, if maxw > 0 { maxw / dw } else { 1 }, if maxh > 0 { maxh / dh } else { 1 })image(data, width: dw * scale * 1pt)}diff --git a/tests/images.test.ts b/tests/images.test.tsindex c353e60..5b89681 100644--- a/tests/images.test.ts+++ b/tests/images.test.ts@@ -1,7 +1,7 @@import { expect, mock, test } from 'claude-code/testing'import {- claudeTmpOf, convertCall, convertedPath, DEFAULT_CELL, folderOf, imageKindOf, isMarkdownPath, pasteDirOf, pastedImagePath, pastedNumbers,+ claudeTmpOf, convertBox, convertCall, convertedPath, DEFAULT_CELL, folderOf, imageKindOf, isMarkdownPath, pasteDirOf, pastedImagePath, pastedNumbers,PICTURE_MAX_ROWS, pictureCells, pictureRowsFor, projectSlug, renderKey, sentFiles, sentImages,} from '../hooks/register'@@ -91,19 +91,31 @@ test('the folder of a file, for the relative images of a Markdown file', () => {expect(folderOf('/t//notes.md')).toBe('/t')})-test('a converted PNG is named by the file and its stat stamp, in a key folder of the cache', () => {- const one = convertedPath('/c', '/t/a.jpg', '1:1000')+// The box of a 100 x 40 viewport at 16 x 32 px cells: 98 columns, 20 rows.+const BOX = { width: 1568, height: 640 }++test('a JPEG or WebP is made to fit the space of the picture, each side at most 4096 px', () => {+ expect(convertBox(98, 20, DEFAULT_CELL)).toEqual(BOX)+ expect(convertBox(58, 24, { width: 8, height: 17 })).toEqual({ width: 464, height: 408 })+ expect(convertBox(120, 24, { width: 40, height: 200 })).toEqual({ width: 4096, height: 4096 })+ expect(convertBox(0, 0, DEFAULT_CELL)).toEqual({ width: 1, height: 1 })+})++test('a converted PNG is named by the file, its stat stamp and the box, in a key folder of the cache', () => {+ const one = convertedPath('/c', '/t/a.jpg', '1:1000', BOX)expect(one).toMatch(/^\/c\/[0-9a-f]{16}\/image\.png$/)- expect(convertedPath('/c', '/t/a.jpg', '1:1000')).toBe(one)- expect(convertedPath('/c', '/t/a.jpg', '2:1000')).not.toBe(one)- expect(convertedPath('/c', '/t/b.jpg', '1:1000')).not.toBe(one)+ expect(convertedPath('/c', '/t/a.jpg', '1:1000', { ...BOX })).toBe(one)+ expect(convertedPath('/c', '/t/a.jpg', '2:1000', BOX)).not.toBe(one)+ expect(convertedPath('/c', '/t/b.jpg', '1:1000', BOX)).not.toBe(one)+ expect(convertedPath('/c', '/t/a.jpg', '1:1000', { width: 928, height: 640 })).not.toBe(one)+ expect(convertedPath('/c', '/t/a.jpg', '1:1000', { width: 1568, height: 768 })).not.toBe(one)})-test('the conversion call: render/convert.typ at 72 ppi, the file and the 4096 px cap as inputs, no network', () => {- const { argv, env } = convertCall({ typst: '/usr/bin/typst', root: '/r', cache: '/c', file: '/t/a b.webp', out: '/c/k/image.png' })+test('the conversion call: render/convert.typ at 72 ppi, the file and the box as inputs, no network', () => {+ const { argv, env } = convertCall({ typst: '/usr/bin/typst', root: '/r', cache: '/c', file: '/t/a b.webp', box: BOX, out: '/c/k/image.png' })expect(argv).toEqual(['/usr/bin/typst', 'compile', '--root', '/', '--format', 'png', '--diagnostic-format', 'short', '--ppi', '72',- '--input', 'f=/t/a b.webp', '--input', 'max=4096', '/r/render/convert.typ', '/c/k/image.png',+ '--input', 'f=/t/a b.webp', '--input', 'maxw=1568', '--input', 'maxh=640', '/r/render/convert.typ', '/c/k/image.png',])expect(env.TYPST_PACKAGE_CACHE_PATH).toBe('/c/pkg-cache')expect(env.HTTPS_PROXY).toBe('http://127.0.0.1:9')@@ -152,10 +164,12 @@ const PASTED = '/private/tmp/claude-501/-w-app/sid-1/images'// are the files that exist, by path: their first bytes as od prints them.// `texts` are text files (a Markdown file Claude sends), `mtimes` the files'// mtimes (1 when not set). `typst`: Typst is found; it makes a PNG of a JPEG-// or WebP (unless `failConvert`; `mv` moves it, unless `failMove`), and+// or WebP (unless `failConvert`, or from run number `failConvertFrom`; `mv`+// moves it, unless `failMove`), and// compiles Markdown to one page.// `holdConvert`: a conversion ends only once its file had that many stats-// (other rows reached it while it runs). `holdCompile`: a Markdown compile+// (other rows reached it while it runs). `holdRun`: conversion number `at`+// (from 1) ends only when `until` settles. `holdCompile`: a Markdown compile// ends only when this settles.function world(on: any, o: {vars?: Record<string, string>@@ -166,8 +180,10 @@ function world(on: any, o: {projects?: string[]typst?: booleanfailConvert?: boolean+ failConvertFrom?: numberfailMove?: booleanholdConvert?: number+ holdRun?: { at: number; until: Promise<void> }holdCompile?: Promise<void>} = {}) {mock.store(on)@@ -211,7 +227,8 @@ function world(on: any, o: {converts.push(argv)const file = argv.find(a => a.startsWith('f='))!.slice(2)if ((stats.get(file) ?? 0) < (o.holdConvert ?? 0)) await new Promise<void>(done => waits.push({ path: file, done }))- if (o.failConvert) return ok('', 1)+ if (o.holdRun?.at === converts.length) await o.holdRun.until+ if (o.failConvert || converts.length >= (o.failConvertFrom ?? Infinity)) return ok('', 1)files[argv.at(-1)!] = HEADreturn ok('')}@@ -334,6 +351,9 @@ test('a JPEG and a WebP Claude sends are made PNGs by Typst once, and draw underexpect(shown[0].props.source.file).toMatch(/^\/c\/[0-9a-f]{16}\/image\.png$/)expect(shown[0].props.source.file).not.toBe(shown[1].props.source.file)expect(converts.map(argv => argv.find(a => a.startsWith('f=')))).toEqual(['f=/t/photo.jpg', 'f=/t/shot.webp'])+ // Made to fit the space of the picture: 98 x 20 cells of 16 x 32 px.+ expect(converts[0]).toContain('maxw=1568')+ expect(converts[0]).toContain('maxh=640')// Typst writes a part file; only a whole one is moved to image.png.const out = shown[0].props.source.fileexpect(converts[0]!.at(-1)).toBe(out.replace(/image\.png$/, 'image.part.png'))@@ -359,6 +379,47 @@ test('a JPEG by its name; two rows at once convert it once; a changed file conveexpect(converts.length).toBe(2)})+test('a new box: the last PNG draws at once, a run for the box starts, and its refresh draws the new PNG', async ($, on) => {+ let release = () => {}+ const until = new Promise<void>(done => (release = done))+ const { clock, converts } = world(on, { typst: true, holdRun: { at: 2, until }, files: { '/t/photo.jpg': JPEG } })+ await ready($)+ const wide = await $.ui.mount(sent(attachAll('/t/photo.jpg'), false, 'tu-1'))+ const first = images(await wide.drawn())[0].props.source.file+ // The same file in a narrower row: 58 columns, so another box.+ const narrow = await $.ui.mount({ ...sent(attachAll('/t/photo.jpg'), false, 'tu-2'), viewport: { columns: 60, rows: 40 } })+ expect(images(await narrow.drawn())[0].props.source.file).toBe(first)+ expect(converts.length).toBe(2)+ expect(converts[1]).toContain('maxw=928')+ // While it runs, the narrow row and a third box do not wait or run again.+ await narrow.redraw(sent(attachAll('/t/photo.jpg'), false, 'tu-2').props)+ const other = await $.ui.mount({ ...sent(attachAll('/t/photo.jpg'), false, 'tu-3'), viewport: { columns: 80, rows: 40 } })+ expect(images(await other.drawn())[0].props.source.file).toBe(first)+ expect(converts.length).toBe(2)+ release()+ await clock.settle()+ // The refresh drew the rows again: the narrow row has its own PNG now.+ const now = images(await narrow.drawn())[0].props.source.file+ expect(now).not.toBe(first)+ expect(now).toBe(convertedPath('/c', '/t/photo.jpg', '1:1000', { width: 928, height: 640 }))+ expect(images(await wide.drawn())[0].props.source.file).toBe(first)+})++test('a failed run for a new box keeps the last PNG', async ($, on) => {+ // The second run (the new box) fails.+ const { clock, converts, logs } = world(on, { typst: true, failConvertFrom: 2, files: { '/t/photo.jpg': JPEG } })+ await ready($)+ const wide = await $.ui.mount(sent(attachAll('/t/photo.jpg'), false, 'tu-1'))+ const first = images(await wide.drawn())[0].props.source.file+ const narrow = await $.ui.mount({ ...sent(attachAll('/t/photo.jpg'), false, 'tu-2'), viewport: { columns: 60, rows: 40 } })+ expect(images(await narrow.drawn())[0].props.source.file).toBe(first)+ await clock.settle()+ await narrow.redraw(sent(attachAll('/t/photo.jpg'), false, 'tu-2').props)+ expect(images(await narrow.drawn())[0].props.source.file).toBe(first)+ expect(converts.length).toBe(2)+ expect(logs.join('')).toContain('convert /t/photo.jpg failed')+})+test('over ssh, a converted JPEG goes as bytes', async ($, on) => {const { reads } = world(on, { typst: true, vars: { SSH_CONNECTION: '10.0.0.2 50000 10.0.0.1 22' }, files: { '/t/photo.jpg': JPEG } })await ready($)@@ -392,9 +453,9 @@ test('a part file that can not be moved draws no picture; an image.png made befoexpect(logs.join('')).toContain('convert /t/photo.jpg: could not move')expect(Object.keys(files).filter(f => f.endsWith('/image.png'))).toEqual([])// An earlier load made the PNG of old.jpg (same stamp): no run, it draws.- files[convertedPath('/c', '/t/old.jpg', '1:1000')] = HEAD+ files[convertedPath('/c', '/t/old.jpg', '1:1000', BOX)] = HEADconst old = await $.ui.mount(sent(attachAll('/t/old.jpg'), false, 'tu-2'))- expect(images(await old.drawn())[0].props.source.file).toBe(convertedPath('/c', '/t/old.jpg', '1:1000'))+ expect(images(await old.drawn())[0].props.source.file).toBe(convertedPath('/c', '/t/old.jpg', '1:1000', BOX))expect(converts.length).toBe(1)})