Files
donlucasandClaude Fable 5.1 44d8d1f532 The page cannot change with the terminal it is built from: sitePage pins the split-cell switches
A rebuild of the committed page from a Claude Code shell inside Terminal.app
came out 34 KB smaller, and every shore clip had a flat-capped sun: main()
sets term.NoSplitCells from TERM_PROGRAM, the canvas HTML writers save and
restore it around their own output, but the shore decides its disc's caps
when it PAINTS (FlatCaps), before any writer runs. Measured by resolving
every clip's palette classes to colours: 139 frames differed, all on the
shore; without TERM_PROGRAM the rebuild matched the committed page byte
for byte. sitePage now pins both switches to the no-terminal values for the
whole render, and TestThePageDoesNotChangeWithTheTerminal builds the page
under both settings and requires the same bytes (fails without the fix).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 20:33:10 -07:00

185 lines
7.9 KiB
Go

package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/donlucasx/xscapes/internal/notify"
"html"
"os"
"path/filepath"
"strings"
"github.com/donlucasx/xscapes/internal/canvas"
"github.com/donlucasx/xscapes/internal/event"
"github.com/donlucasx/xscapes/internal/scape"
"github.com/donlucasx/xscapes/internal/term"
)
// turnBeat is one moment of the demo turn: seconds from the prompt, a note,
// and the events that land then.
type turnBeat struct {
at float64
note string
evs []event.Event
}
// demoTurn is the one simulated Claude Code turn every rendered study shares:
// a prompt, some reading, edits, a fan-out of five subagents, a failing
// command, a question, the finish, and half a minute of quiet. The payload
// shapes are the ones verified out of the Claude Code binary.
//
// It lives in one place so the wired study and the submission page cannot
// drift apart: a beat changed here changes in both.
func demoTurn() []turnBeat {
sub := func(id, kind string, k event.Kind) event.Event {
return event.Event{Kind: k, Agent: id, AgentType: kind, Op: event.OpSub}
}
tool := func(k event.Kind, id string, op event.Op, name, target, detail string, ms int64) event.Event {
return event.Event{Kind: k, ID: id, Op: op, Tool: name, Target: target, Detail: detail, MS: ms}
}
todo := func(n, of int) event.Event {
return event.Event{Kind: event.Todo, Op: event.OpTodo, N: n, Of: of}
}
ctx := func(used float64) event.Event {
return event.Event{Kind: event.Context, Frac: &used}
}
return []turnBeat{
{0, "the prompt lands — thinking, no tool yet", []event.Event{
{Kind: event.Prompt, Text: "add rate limiting to the auth endpoint"},
todo(0, 5),
}},
{6, "reading around", []event.Event{
tool(event.ToolStart, "t1", event.OpRead, "Read", "internal/auth/handler.go", "", 0),
tool(event.ToolEnd, "t1", event.OpRead, "Read", "internal/auth/handler.go", "142 lines", 412),
tool(event.ToolStart, "t2", event.OpSearch, "Grep", "rate.Limiter", "", 0),
tool(event.ToolEnd, "t2", event.OpSearch, "Grep", "rate.Limiter", "3 files", 88),
todo(1, 5),
}},
{11, "working hard — edits landing", []event.Event{
tool(event.ToolStart, "t3", event.OpEdit, "Edit", "internal/auth/handler.go", "", 0),
tool(event.ToolEnd, "t3", event.OpEdit, "Edit", "internal/auth/handler.go", "+18 -2", 120),
tool(event.ToolStart, "t4", event.OpWrite, "Write", "internal/auth/limiter.go", "", 0),
tool(event.ToolEnd, "t4", event.OpWrite, "Write", "internal/auth/limiter.go", "64 lines", 95),
tool(event.ToolStart, "t5", event.OpShell, "Bash", "go", "", 0),
todo(2, 5),
}},
{14, "a fan-out — five subagents", []event.Event{
sub("a1", "code-reviewer", event.SubStart),
sub("a2", "general-purpose", event.SubStart),
sub("a3", "general-purpose", event.SubStart),
sub("a4", "Explore", event.SubStart),
sub("a5", "Explore", event.SubStart),
}},
{22, "a test fails — the companion carries it, not the weather", []event.Event{
sub("a4", "Explore", event.SubEnd),
sub("a5", "Explore", event.SubEnd),
tool(event.Error, "t5", event.OpShell, "Bash", "go", "exit 1", 4100),
todo(3, 5),
// The session is past 40% of its context here, so the readout
// under the moon is on from this beat (his ruling, 2026-09-05).
ctx(0.46),
}},
{30, "the user is asked for something", []event.Event{
{Kind: event.NeedsInput, Text: "allow Bash?"},
}},
{44, "done — the sea settles, the sand still holds the record", []event.Event{
sub("a1", "code-reviewer", event.SubEnd),
sub("a2", "general-purpose", event.SubEnd),
sub("a3", "general-purpose", event.SubEnd),
{Kind: event.Prompt, Text: "yes"},
todo(5, 5),
{Kind: event.Done, Text: "Rate limiting is in. 100 req/min per IP."},
}},
{72, "half a minute later — flat, the writing receding", nil},
}
}
// sitePage writes the submission page: the template as it is, with the
// animated clips rendered beside it into <dir>/anim by gifPages. The clips
// are the demo turn folded through the real reducer, as a 256-colour
// terminal shows it; site/make-gifs.py then captures and encodes them.
// The page used to carry five stills lifted from the same fold; his
// direction of 2026-09-05: animated clips, no still screens.
func sitePage(seed int64, dir string) (string, error) {
// The page must not change with the terminal it is built from. The HTML
// writers save and restore term.NoSplitCells around their own output,
// but the shore decides its disc's flat caps when it PAINTS (FlatCaps in
// shore.go), before any writer runs: built from a shell inside
// Terminal.app, every shore clip came out with a flat-capped sun
// (2026-09-17). Both switches are pinned to the no-terminal values for
// the whole render; TestThePageDoesNotChangeWithTheTerminal holds it.
wasN, wasL := term.NoSplitCells, term.LowerHalf
term.NoSplitCells, term.LowerHalf = false, false
defer func() { term.NoSplitCells, term.LowerHalf = wasN, wasL }()
tmpl, err := os.ReadFile(filepath.Join(dir, "template.html"))
if err != nil {
return "", err
}
page := string(tmpl)
cover := coverLayers(seed)
page = strings.Replace(page, "{{cover}}", cover, 1)
page = strings.Replace(page, "{{covermobile}}", coverLayersMobile(seed), 1)
// The animations are embedded as text, not screenshotted into GIFs. See
// siteframes.go for why, and for what it costs.
fxjs, fxcss, err := renderFX(seed)
if err != nil {
return "", err
}
page = strings.Replace(page, "{{fxjs}}", fxjs, 1)
// The three cues as data URIs, so a reader can press and hear them
// (65 KB of WAV, the product's own bytes; the s38 judge's J4).
ask, done, worried := notify.Cues()
uri := func(b []byte) string { return "data:audio/wav;base64," + base64.StdEncoding.EncodeToString(b) }
cues, _ := json.Marshal(map[string]string{"ask": uri(ask), "done": uri(done), "worried": uri(worried)})
page = strings.Replace(page, "{{cues}}", "window.CUES="+string(cues)+";", 1)
page = strings.Replace(page, "{{fxcss}}", fxcss, 1)
// Each section's quiet moving field, his idea of 2026-09-14. See backdrops.go.
for key, frames := range renderBackdrops(seed) {
page = strings.Replace(page, "{{bg:"+key+"}}", frames, 1)
}
if err := os.WriteFile(filepath.Join(dir, "anim", "cover.html"), []byte(cover), 0o644); err != nil {
return "", err
}
if i := strings.Index(page, "{{"); i >= 0 {
end := min(i+40, len(page))
return "", fmt.Errorf("template marker not filled: %q", page[i:end])
}
if err := gifPages(seed, filepath.Join(dir, "anim")); err != nil {
return "", err
}
return page, nil
}
// coverLayers is the cover's background: six frames of the real shore at
// night, glyphs only, stacked as <pre> layers a CSS step animation cycles.
// The mark sits over its own sea. Written to <dir>/anim/cover.html too, so
// the deck's title slide can carry the same.
func coverLayers(seed int64) string { return coverLayersAt(seed, 168, 44) }
// coverLayersMobile is the same sea at a width a phone can actually show.
//
// His note, 2026-09-14: the splash reads on desktop and does not on mobile,
// and the reason is that the cover frame is a FIXED 168 columns at a fixed
// 14px. On a 390px screen that is a 1400px picture behind a 390px window, so
// a phone sees a crop of the middle of the sea rather than a sea. A narrower
// render is the only honest fix: scaling 168 columns down to fit would put the
// cell under 2px, which is not an animation, it is noise.
func coverLayersMobile(seed int64) string { return coverLayersAt(seed, 60, 30) }
func coverLayersAt(seed int64, w, h int) string {
var b strings.Builder
sh := scape.NewShore(seed, false)
sh.MoonX = 0.28
act := scape.Activity{Working: true, Level: 0.55, TimeOfDay: 0.93}
c := canvas.New(w, h, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
for i := 0; i < 30; i++ {
sh.Update(c, float64(i)/20, act)
}
for i := 0; i < 6; i++ {
sh.Update(c, 2+float64(i)*0.7, act)
fmt.Fprintf(&b, `<pre style="animation-delay:-%.1fs">%s</pre>`, float64(i)*0.7, html.EscapeString(c.RenderPlain()))
}
return b.String()
}