Tooling

Studio

lttr serve and the studio library. A live grid of every sample, a workbench with its problems, data, golden diff and test sends, the components page, the size budget, keyboard shortcuts, editor links, unsaved editor buffers and the security model.

The studio is the day-to-day way to see a kit's samples while you edit them. It opens with a grid of every sample. Each sample opens in a workbench that shows the email at 600 and 375 px, in light and dark, next to its problems as file:line:col lines. A save re-renders only what it changed, and the page updates in place within half a second.

From the workbench you can also try other data on a sample, review its render against the golden files and accept it, and send it to your own inbox. The components page shows every component of the kit with its schema and a rendered example.

There are two ways to run it:

  • lttr serve runs it for the built-in kits and for any kit directory on disk.
  • The studio library runs it for an app whose templates bind its own Go types, which the lttr binary cannot know.

Either can also run inside your editor's language server, as lttr lsp -studio or emaildev lsp -studio, so the preview follows what you type before you save. See Follow your editor's unsaved text.

Run lttr serve

Terminal
$ go run ./cmd/lttr serve -kit ./kit
lttr studio: serving kit (2 samples) on http://localhost:7070

Open the address in a browser. make serve runs the same command with the Makefile's KIT (default quiet). Stop it with Ctrl-C.

Terminal
$ go run ./cmd/lttr serve -h
usage: lttr serve [-kit kit] [-dir dir] [-addr host:port] [-golden dir] [-editor name] [-send-to addr,…]

Runs the lttr studio, a live preview of the kit's samples, until interrupted:
a grid of every sample and a workbench for one, with its problems as
file:line:col lines. A save reloads what it changed: for quiet the example
templates in -dir (default examples/quiet/templates); for plain, the samples
in -dir (its embedded samples, which do not change, without it); for a kit
directory, the whole kit (kit.yaml, templates, styles, samples/, or the
samples in -dir). A kit that fails to load shows its problems until it loads.

Golden status compares each render with <Name>.html and <Name>.txt in
-golden: by default testdata/golden for quiet, <dir>/testdata/golden for a
kit directory, when it exists; -golden "" turns it off.

Test sends go only to the addresses in -send-to (else LTTR_STUDIO_SEND_TO),
at most 10 a minute, marked with a "[test] " subject prefix and an
X-Lttr-Test: 1 header, through the SMTP server in LTTR_SMTP_ADDR (host:port),
with PLAIN auth when LTTR_SMTP_USER and LTTR_SMTP_PASS are set, and from
LTTR_SMTP_FROM when set. Without a list or a server, sending is off.

flags:
  -addr address
        listen address (default "localhost:7070")
  -dir dir
        template or sample source dir (see above)
  -editor editor
        editor that problem links open: vscode, cursor, zed, idea or none (default "vscode")
  -golden dir
        golden dir (see above)
  -kit kit
        kit: quiet (the examples), plain, or a kit directory (./plain for a directory called plain) (default "quiet")
  -send-to addresses
        addresses test sends may go to, comma-separated (else LTTR_STUDIO_SEND_TO); SMTP from LTTR_SMTP_ADDR, _USER, _PASS and _FROM

What a save reloads depends on -kit:

  • A kit directory (-kit ./kit) reloads the whole kit: kit.yaml, the layouts, styles.css, every component and samples/. A token, a component's html.tmpl or a sample edit all show up, and so does a sample that names a new profile:, since the studio makes up a profile for every name the samples use. With -dir, the samples come from that directory instead of samples/.
  • quiet (the default) reads each example's .md source from -dir (default examples/quiet/templates, so run it from a checkout). The Go data types and profiles stay the example package's own.
  • plain serves its two embedded samples, which do not change, or the samples in -dir.

The studio watches the files by polling them every 200 ms and rebuilds 100 ms after the last change, so a burst of saves gives one rebuild. It ignores dot-files and editors' save temporaries: names ending in ~, .swp or .tmp, Emacs's #name#, JetBrains's ___jb_tmp___ and ___jb_old___ files, and Vim's 4913. A change to Go code needs a restart: lttr serve is a compiled program.

Read the grid

The grid shows one tile per sample: a thumbnail of the render, the sample's number and name, and one status badge. When a sample has more than one status, the badge shows the first that applies, in this order:

BadgeMeaning
◌ staleThe template no longer compiles or renders. The tile keeps the last good render, dimmed.
⚠ N problemsThe render is current, with N errors and warnings.
✕ not renderedThe sample has never rendered, with no problem of its own: the kit broke before it could. A broken render config shows ⚠ 1 problem instead, with the problem not rendered: the render config is invalid for this kit; see the kit problems.
Δ changedThe render differs from its golden files.
golden ✓The HTML and text equal the golden files byte for byte.
○ golden offGolden status is off (-golden "", or no golden directory).
○ no goldenThere is no golden file to compare with yet.

A second badge shows the HTML size when it is over 90 KB (see the size budget). The summary line above the grid counts the samples by status, for example 2 match golden ✓ or 1 Δ changed · 1 ◌ stale, and the filter box narrows the tiles by name. The Samples | Components switch next to the kit's name opens the components page.

When a save re-renders a sample, its tile shows ● updated for a moment and a screen reader hears one short announcement, such as welcome re-rendered, differs from golden.

The pill at the top right says what the studio is doing:

PillMeaning
Live · watching ./kitWatching that directory; a save reloads.
Live · unsaved bufferThe page shows a render of text you haven't saved yet, from the language server. On the workbench, it is that sample's text; on the grid, any sample's.
Live · kit has problemsWatching, and the kit's own files have problems.
Kit failed to load · watchingThe kit has never loaded; the page lists why.
Serving embedded filesNot live: nothing on disk is watched.
Reconnecting…The page lost its connection to the server.

Know the states

  • The kit didn't load. When the kit fails to load at startup, there is nothing to render yet. The page lists every problem with its location, such as kit/kit.yaml:8, and a suggestion when there is one. Fix the files and the page switches to the grid by itself, within a second of the save, with every sample's profile in place. There is no need to restart or reload.
  • The kit has problems. When a loaded kit breaks later, a callout names the first problem and lists the rest. If the kit no longer loads at all, every sample keeps its last good render, marked ◌ stale. A problem that leaves the kit loading, such as a typo in samples/samples.yaml, stales only the samples that can no longer render (here, the one whose data the typo lost), and the others keep their badges.
  • Not live. When nothing is watched (lttr serve -kit plain without -dir, or the library without KitDir and TemplateDir), a notice says so, with the way to make it live. You can dismiss the notice for the session.
  • Connection lost. When the server stops, the page retries after 1, 2, 4 and 8 seconds, then every 8 seconds. Retry now tries at once. When it reconnects, to the same server or to one restarted meanwhile, the page catches up on every change it missed.
  • No samples. An empty kit shows how to add a sample to samples/samples.yaml.

Use the workbench

Open a tile, or press Enter on it, to open its workbench:

  • The top bar has the sample list toggle, previous and next buttons, a switcher listing every sample, and Send test, which opens the Send tab.
  • The sample list on the left shows each sample's status glyph. It has its own filter. Below it, // COMPONENTS lists the components the sample uses, each a link to its page on the components page.
  • The toolbar above the preview sets:
    • Width: 600, 375, or Both side by side. Frames that do not fit are scaled down, and the zoom note says by how much (600 + 375 · 73%).
    • Email: Light or Dark. This switches the email's own prefers-color-scheme rules inside the frame, as a dark-mode mail client would. It is not the studio's theme.
    • View: HTML, Text (the plain-text part) or Source (the template source, with line numbers).
  • The stale callout appears above the preview when the render is stale: Showing the last good render: this sample has problems.
  • The inspector on the right has four tabs:
    • Problems lists each error and warning: its severity, its location (a link to your editor), the message, and a did you mean X? copy chip when lttr has a suggestion. The chip copies the suggestion. A problem in a kit file is tagged kit file.
    • Data shows the sample's data as JSON, to try other values.
    • Diff compares the render with its golden files, to review and accept it.
    • Send sends the render to an allowed inbox.
  • The status line at the bottom shows the problem count, the golden status and the size, and reminds you that changes to Go data or types need a restart.

The studio opens in its light theme. The moon button switches it to dark, and the choice is remembered. The studio does not follow the system's dark mode. The Light and Dark email toggle is separate.

Keyboard shortcuts

Press ? for this list in the studio. Shortcuts pause while a text field has focus.

KeyWhereDoes
j / kGridFocus the next or previous tile
j / kWorkbenchOpen the next or previous sample
gWorkbench, components pageBack to the grid (on the grid: to the top)
1 / 2 / 3WorkbenchWidth 600, 375, or both
dWorkbenchEmail dark mode on or off (not the studio theme)
?AnywhereShow the shortcuts
EscDialog, switcherClose it

Each toolbar group and the inspector's tab row is one Tab stop. Inside it, the arrow keys move the selection, and Home and End jump to the ends. Every control shows a focus ring.

Open problems in your editor

A problem's location links to the file in your editor, at its line and column. -editor (or Options.Editor) picks the editor. The link is built from the file's absolute path:

-editorLink
vscode (default)vscode://file/<path>:<line>:<col>
cursorcursor://file/<path>:<line>:<col>
zedzed://file/<path>:<line>:<col>
ideaidea://open?file=<path>&line=<line>&column=<col>
noneno link

Only files on disk get a link. A location inside an embedded file (a built-in kit, or an app's go:embed without KitDir) shows as plain text.

Compare with goldens

Golden status compares each render with <Name>.html and <Name>.txt in the golden directory, byte for byte. Name is the template's name, which is the convention lint.Golden uses. By default lttr serve reads testdata/golden for quiet and <dir>/testdata/golden for a kit directory, when it exists. -golden dir picks another, and -golden "" turns it off.

The status line says golden ✓ match, Δ differs from golden, ○ no golden yet or, with golden status off, ○ golden off. A stale sample is ◌ stale · not compared. To update a golden, accept the render in the Diff tab, or run your golden test with -update (make golden for Quiet), and review the diff.

The studio renders with the sample set's own Config, so it compares exactly what lint.Golden sees, with real asset URLs. Only the preview it serves differs. The asset base (Config.AssetBase, or the kit's asset_base var) is rewritten to the studio's /assets/, so images load from the kit's own files.

Try other data

The Data tab shows the data the sample renders with, as JSON. Edit it to see how the email copes with a long name, an empty list or a missing field:

  • The JSON is checked as you type. An error shows where it is, such as ✕ Line 4, column 3: expected ',' or '}' after property value, and Apply stays off until the JSON parses. The preview keeps the last data you applied.
  • Apply re-renders the sample with your JSON, in memory. Nothing is written. The data is decoded as the sample's own type, so for Go-typed data an unknown field or a wrong type is refused with its line:col. The tab then says ● applied in memory at 10:46:46 AM · not saved. The applied data stays through template and kit edits, until you press Reset or Save.
  • Reset drops the applied data, and the sample renders with its own data again.
  • Save to samples.yaml writes the data into the sample's entry in samples.yaml, then drops the applied data, so the sample renders from the file. It saves what the editor shows, applied or not.

Save is offered only when the studio reads the sample's data from a samples.yaml on disk: a kit directory's samples/samples.yaml (lttr serve -kit ./kit), or the samples.yaml in -dir. It is never offered for an embedded kit (lttr serve -kit plain without -dir) or in the studio library. There, Copy JSON copies the data instead. For Go-typed data the tab says: This sample's data is a Go value. Copy the JSON into your Go source to keep it.

What Save changes

Save rewrites only the sample's own entry. In the usual samples.yaml, a mapping with each file name at the start of its line, every other entry, and every comment and blank line outside the entry, stay byte for byte. Inside the entry, keys you kept stay in place with their comments, and values you did not change keep how they were written. New keys come after them, in sorted order.

A few files can't be edited that precisely, and Save falls back to writing the whole file again: a flow or indented mapping, a file with unusual line breaks (a lone CR, or U+2028), or an entry whose last line can't be told apart from a comment after it. The data and the comments are kept, but blank lines and layout may change. Comments at the end of a nested block inside the edited entry may be dropped.

Save refuses when the sample's entry in samples.yaml changed on disk since the studio loaded it (even while applied data is in use), or when the file changes during the save. Edits to other entries are kept.

That refusal reads samples.yaml changed on disk; reload. Nothing is written, and your edit stays in the editor. Under the language server, Save also refuses while samples.yaml is open in your editor with unsaved changes, since writing would put that unsaved text on disk: samples.yaml has unsaved changes in your editor; save it first. It refuses too, writing nothing, when the edit would change another entry, for example an alias of this entry's anchor, or a keep-chomped block such as >+ whose value ends in a blank line: samples.yaml: the edit would change other entries (an alias of this entry's anchor?); edit the file by hand.

Review and accept a golden

The Diff tab compares the current render with the golden files, and writes them when the change is what you meant.

  • The tab's name says the state: Diff, 2 changes (the hunks in the HTML and the text together), Diff, matches golden or Diff, no golden. With golden status off, the tab is disabled, and the reason shows beside it: Golden files are off: no golden directory is set.
  • Golden and current renders sit side by side. The captions say when each was made: the golden file's modification time, and when the studio rendered the current one.
  • The HTML | Text toggle shows a unified diff of either part, with @@ -60,7 +60,7 @@ hunk headers and a stat line such as 1 hunk · +1 −1. A line whose only change is its line ending is tagged line endings differ.

Accept as golden asks before it writes anything. The confirm reads Accept this render as golden? and This overwrites 2 files. Commit them to make the change stick., and lists the two files. Accept and write files writes them, and Cancel or Esc closes it. With no golden yet, the button is Accept as first golden.

Accept writes <golden dir>/<Name>.html and <Name>.txt, the files lint.Golden compares, with the render as lint.Golden sees it: real asset URLs, not the preview's. It creates the golden directory when it is missing. Commit the files, and your golden test checks against them from then on.

Accept writes the render you reviewed, not a newer one. The page sends the hash of the render the diff showed. If a save re-rendered the sample since, the studio answers render changed; review the diff again, writes nothing, and shows the new diff. A render that is stale, has errors or doesn't exist can't be accepted either, and the tab says why: Fix the errors first: a render with errors can’t be golden.

Accept is off while applied data is in use, since a golden is of the data on disk: the tab says This render uses applied data; save or reset it first. Save or reset the data first. For the same reason, Accept is off while the render uses unsaved editor text: This render uses unsaved editor text; save it first.

Send a test

Previews are close to what a mail client shows, but not the same. Send test sends the current render to a real inbox, so you can check it in Gmail, Outlook or Apple Mail.

Sending is off until you give the studio two things, then restart it:

  • An allow-list. -send-to qa@example.com,dev@example.com, or LTTR_STUDIO_SEND_TO with the same form. The flag wins over the variable. Write bare addresses, separated by commas. A display name is not needed, and a quoted one containing a comma doesn't parse.
  • An SMTP server. LTTR_SMTP_ADDR is its host:port, for example localhost:1025 for a local catcher such as Mailpit. LTTR_SMTP_USER and LTTR_SMTP_PASS turn on PLAIN auth. LTTR_SMTP_FROM replaces the From of every test; without it, each test is from its template's profile.
Terminal
$ LTTR_SMTP_ADDR=localhost:1025 go run ./cmd/lttr serve -kit ./kit -send-to qa@example.com,dev@example.com
lttr studio: serving kit (2 samples) on http://localhost:7070

A bad address or SMTP setting stops lttr serve before it listens: it prints the problem, then the usage, and exits 2. The problem reads like one of these:

Output
lttr serve: -send-to: bad address "nope": mail: missing '@' or angle-addr
lttr serve: LTTR_SMTP_ADDR: want host:port, such as localhost:1025
lttr serve: LTTR_SMTP_PASS is set but LTTR_SMTP_USER is not

The Send tab picks the recipient from the allow-list; there is no free-text address. Above the button, the envelope shows the From, the subject with its [test] tag, the X-Lttr-Test: 1 header and the server, as smtp://localhost:1025. After a send, the tab says ✓ Sent to qa@example.com at 10:46:51 AM and gives the Message-ID.

  • Every test is marked. The subject starts with [test] and the message carries the header X-Lttr-Test: 1. The marking lets a mail filter, or the person who gets it, tell a test from a real message, and lets you route tests to their own folder.
  • Only the allow-list. The studio refuses any other recipient with not on the allow-list, even from a request that passes the write checks.
  • At most 10 a minute. Each studio process sends at most 10 tests in any 60 seconds, failed deliveries included. The 11th shows Rate limit reached: 10 per minute. You can send again in 59 s., and the button counts down.
  • Only a good render. A sample that is stale, has errors or has no render is not sent, and neither is any sample while the kit has problems.
  • Credentials stay out. The user and password never appear in the page, the studio's answers or its log. When the server refuses the login, the studio shows only its reply code, such as authentication failed (535).

When sending is off, Send test is disabled with the reason beside it, such as Sending is off: no allow-list, and the Send tab says how to turn it on: Pass -send-to, or set LTTR_STUDIO_SEND_TO, then restart.

The studio delivers through lttr.SMTP: STARTTLS when the server offers it, verified against the host of LTTR_SMTP_ADDR.

Browse the components

The Samples | Components switch on the grid opens /components, a reference of every component in the kit. /components/<name> opens one by its name or an alias.

  • The list on the left shows each component with its class and how many samples use it, or ○ unused. Its filter matches names, aliases and attribute names.
  • The component shows its class, its aliases and a components/<name>/ link, which opens its component.yaml in your editor when the kit is on disk. A badge says used in 2 samples or ○ not used in any sample.
  • Tables give its schema: Attributes (Name, Type, Default, Required, Values), Bindings · Go, Children (Component, Min, Max), Content (the rules in words, such as blocks: paragraph · list) and Must follow.
  • The example is the component rendered from the first sample that uses it, in a sandboxed frame, with its source and a link to that sample's workbench. It re-renders when the sample does. A component no sample uses shows No rendered example: add a sample that uses it to see one here. A component that must follow another has no standalone example, and says why.

The usage counts count the samples that name the component, and for the kit's default component, such as Plain's section, the samples with loose Markdown it wraps. A default component used only that way has no block of its own to cut an example from, so it has no example. The counts refresh when the kit changes.

Watch the size budget

The status line shows the HTML size against Gmail's clip point, for example 18 KB of 102 KB, with a small meter. Gmail clips a message whose HTML is over 102 KB, which hides the end of the email behind a link.

  • Over 90 KB, the size turns amber (⚠ 94 KB of 102 KB), and the tile gets a size badge.
  • At 100 KB, lttr refuses to render (the same limit as lttr lint). The sample shows the error and keeps its last good render as stale.

Run it for your own Go types

An app that binds its own Go types in its templates cannot use lttr serve, because the lttr binary does not have those types. It runs the studio as a small dev-only program instead, with the studio package. Build your own kit's tutorial is the worked example:

tutorial/cmd/emaildev/main.go
// Command emaildev runs the lttr studio on the tutorial's samples, reloading
// the kit and templates from disk. Run it from the repository root:
//
//  go run ./examples/tutorial/cmd/emaildev
package main

import (
    "os"

    "github.com/sulv-io/lttr/examples/tutorial"
    "github.com/sulv-io/lttr/studio"
)

func main() {
    os.Exit(studio.Options{
        KitDir:      "examples/tutorial/kit",
        LoadKit:     tutorial.LoadKit,
        TemplateDir: "examples/tutorial/templates",
        GoldenDir:   "examples/tutorial/testdata",
    }.Main(tutorial.Set(), os.Args[1:]))
}
Terminal
$ go run ./examples/tutorial/cmd/emaildev
lttr studio: serving tutorial (1 sample) on http://localhost:7070

The program serves the app's lttr.SampleSet: the kit, the Config, and each template with typed sample data. The same set feeds lint.Check and lint.Golden, so write it once. See Describe samples once.

Make it live

An app usually embeds its kit and templates with go:embed. The binary then holds a copy that the studio cannot watch. Options says where the files live on disk:

FieldWhat it does
KitDirThe kit's directory. A change there loads the kit again with LoadKit.
LoadKitfunc(fs.FS) (*kit.Kit, error): loads the kit from os.DirFS(KitDir) with the app's kit.Types and kit.Funcs. Required with KitDir; without it, serving fails with studio: KitDir needs LoadKit.
TemplateDirEach sample's source is read again from <TemplateDir>/<sample.File()>.
GoldenDirThe golden directory for golden status; "" turns it off.
AddrThe listen address, localhost:7070 by default.
Editorvscode (default), cursor, zed, idea or none.
SendToThe allow-list for test sends; empty reads LTTR_STUDIO_SEND_TO. SMTP comes from the LTTR_SMTP_* variables.
Stdout, StderrThe serving line, and warnings and errors. Default os.Stdout and os.Stderr.

Relative directories are relative to the working directory, which is also the root of the paths the studio shows. Run the program from the module root.

With KitDir and TemplateDir set, kit and template edits reload live. A change to Go code needs a restart: the data types, the sample data, LoadKit, or anything else compiled into the program. The workbench's status line says so. Without them, the studio serves the embedded files and shows the not-live notice, with the hint Set KitDir and TemplateDir (studio.Options) to reload edits live.

Main, Options.Main and Serve

  • studio.Main(set, args) is studio.Options{}.Main(set, args): the embedded files, not live, on localhost:7070.
  • Options.Main(set, args) parses -addr, -golden, -editor and -send-to from args over the options, so the fields are the defaults and flags override them. It serves until SIGINT or SIGTERM and returns the exit code: 0, 1 on error, 2 on a usage error. -h prints the flags and what reloads:
    Terminal
    $ go run ./examples/tutorial/cmd/emaildev -h
    usage: emaildev [-addr host:port] [-golden dir] [-editor name] [-send-to addr,…]
           emaildev schema [-o file]
           emaildev lsp [-studio host:port] [-golden dir] [-editor name] [-send-to addr,…]
    
    Runs the lttr studio, a live preview of this program's samples, until
    interrupted. A change to Go data or Go types needs a restart.
    
    Reloads on a change to:
      the kit        examples/tutorial/kit
      the templates  examples/tutorial/templates
    
    subcommands:
      schema    write .lttr/schema.json, the kit and data description editors read
      lsp       the language server for editors, on stdin and stdout
    
    flags:
      -addr address
            listen address (default "localhost:7070")
      -editor editor
            editor that problem links open: vscode, cursor, zed, idea or none (default "vscode")
      -golden dir
            golden dir (<Name>.html and <Name>.txt) for golden status; empty for none (default "examples/tutorial/testdata")
      -send-to addresses
            addresses test sends may go to, comma-separated (else LTTR_STUDIO_SEND_TO); SMTP from LTTR_SMTP_ADDR, _USER, _PASS and _FROM
    
  • Two subcommands come with Main and Options.Main, so the same program serves your editor too:
    • schema [-o file] writes .lttr/schema.json at the module root (the nearest directory up holding go.mod), or to -o's file. It describes the kit and each template's data paths, so lttr lsp can offer completion, hover and definition for your templates. Commit it, and run it again after changing the kit or the Go data types.
    • lsp [-studio host:port] [-golden dir] [-editor name] [-send-to addr,…] runs the language server on stdin and stdout, with the program's own kit loader, Go types and samples, so its problems are exact. -studio also serves the studio, following your unsaved buffers.

    See Editor setup for both.
  • studio.Serve(ctx, set, opts) is the embeddable form. It serves until ctx is done, then shuts down and returns nil. It parses no flags and handles no signals:
cmd/emailstudio/main.go
package main

import (
    "context"
    "log"
    "os"
    "os/signal"

    "github.com/sulv-io/lttr/examples/tutorial"
    "github.com/sulv-io/lttr/studio"
)

func main() {
    ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
    defer stop()
    err := studio.Serve(ctx, tutorial.Set(), studio.Options{
        Addr:        "localhost:7071",
        KitDir:      "examples/tutorial/kit",
        LoadKit:     tutorial.LoadKit,
        TemplateDir: "examples/tutorial/templates",
    })
    if err != nil {
        log.Fatal(err)
    }
}

Keep the program out of production builds: put it in its own cmd/ directory that nothing else imports.

Follow your editor's unsaved text

The language server can serve the studio too: lttr lsp -studio localhost:7070, or your own program's emaildev lsp -studio localhost:7070. Its preview then follows the text in your editor as you type, before you save, on the same engine that checks it. See Editor setup for the editors, and Preview as you type for which kit it serves.

  • The pill says so. While the page shows a render of unsaved text, the pill reads Live · unsaved buffer, and a render that differs from its golden says Δ differs from golden · unsaved.
  • Save or close. Save the file, and the pill returns to Live · watching …. Close it without saving, and the preview returns to the text on disk.
  • New files wait for a save. A file that exists only in your editor can be read by the kit, but it isn't listed as a new sample until you save it.
  • Writes use the files on disk. Accept refuses a render built from unsaved text, and Save to samples.yaml refuses while samples.yaml has unsaved changes in your editor. A golden never holds text you haven't saved.
  • No "Rendering…" cue. The buffer rebuilds 150 ms after you stop typing, and a build takes about 40 ms, so a cue would flicker on every keystroke. The pill and the ● updated cue already say that the preview follows your typing.

Keep it local

The studio serves your templates and sample data, so by default only your own machine can reach it.

  • It listens on localhost. The default address is localhost:7070.
  • It checks the Host header. Every request, reads included, must name localhost, 127.0.0.1 or [::1] with the studio's port. Any other Host gets 421 Misdirected Request. A web page that rebinds its own domain to your machine cannot read the studio through the browser.
  • It serves no remote resources. The studio's pages load no fonts or scripts from elsewhere. Their Content-Security-Policy allows only the studio's own files, and every response carries Cross-Origin-Resource-Policy: same-origin, X-Content-Type-Options: nosniff and Cache-Control: no-store.
  • Previews are sandboxed. Each email renders in an <iframe sandbox="allow-same-origin"> with scripts off, and the rendered HTML is served with Content-Security-Policy: script-src 'none'. Nothing in an email runs. Same-origin access lets the studio measure the frame and switch its colour scheme.
  • Writes come only from the studio's own page. Apply, Reset, Save, Accept and Send are POST, PUT or DELETE requests, and each must carry two things a page on another site can't supply: the X-Lttr-Token header, holding a random token the studio makes at each start (32 bytes from crypto/rand) and puts in its own pages, and an Origin header equal to the studio's own address. The body must be JSON (Content-Type: application/json) of at most 1 MiB. The studio checks, in order, and answers:
    CheckAnswer
    The request's Content-Type isn't application/json415
    The token or the Origin is missing or wrong, or Origin is null403 with {"error":"forbidden"}
    The body is over 1 MiB413
    The body takes over 10 seconds to arrive408

    Nothing is written or sent before these pass. A form on another site can't send JSON, and a fetch from another site that sends JSON or the token must ask the studio first, which it never allows. The Host check keeps other sites from reading the token.
  • It writes two kinds of file. Save writes the sample set's samples.yaml and Accept writes <Name>.html and <Name>.txt in the golden directory. The paths come from the sample and its template name, never from the request. A file that is a symbolic link is refused, and every write goes to a temporary file in the same directory first, then replaces the file in one step.

To open the studio from another device on your network, such as a phone, listen on your machine's LAN address. The Host check then allows that address too:

Terminal
go run ./cmd/lttr serve -addr 192.168.1.20:7070

Anyone who can reach that address can read your templates and data, save sample data, accept goldens and send test emails to the allow-list, and the studio warns you. 0.0.0.0 listens everywhere but still accepts only localhost Host headers:

Terminal
$ go run ./cmd/lttr serve -addr 0.0.0.0:7070
lttr serve: listening on a non-loopback address; anyone who can reach it can read your templates and data, save sample data, accept goldens and send test emails to the allow-list
lttr serve: -addr 0.0.0.0:7070 and [::]:7070 still accept only localhost Host headers; for LAN access use -addr <lan-ip>:7070
lttr studio: serving quiet (9 samples) on http://localhost:7070

Share a one-shot preview

lttr preview writes every sample to a directory, with an index.html to open in a browser. There is no server and no reload, so it is the form to hand someone for a review, or to feed to make shoot:

Terminal
make preview
# KIT=plain make preview

See The lttr CLI for everything it writes. Its index lists the samples and shows the selected one:

ControlKeyboardDoes
Email colour scheme: Light, DarkdSwitches the email's prefers-color-scheme rules inside each frame
Preview width: Both, 600, 375wShows one or both frames
Part: HTML, Plain texttThe HTML frames or the text part
Page themeThe page's own light or dark chrome

j/k (or the arrow keys) move between samples, and every choice is remembered. The frames embed each email with srcdoc, so the page works when opened as a file:// document.

Next steps

Copyright © 2026