Files
xscapes/main.go
T
donlucasandClaude Opus 5 d02530bb54 The cat becomes a companion, and three fixes measured worse than their bugs
Two days of his design round: I drew, he ruled from rendered options.

THE CAT. It asks with its ears ("Pricked ears"), finishes with its chin up,
and walks up its own ladder -- 12x7 -> 16x9 -> 24x14, the middle rung the
Faithful Scale-Up with its nose removed, the top rung "Ruffed sit", drawn.
Before this the ask and the finish were the WORKING body: measured over 1,200
frames a pose, bodies only, 97% of a still of either was also a still of the
cat simply working. Now 0%, asserted, with Worried as the positive control.

The crab finishes "settled on the sand" with one pincer shutting every 7 s.
crabDone was DEAD ART -- it raised a claw by a single source row and the row
OR ate it, so all six half-rows were crabWork's. The finish cue has been the
eye glyph alone since it was written.

Its near eye rotates through four faces, picked on the RISING EDGE of an ask
and held. Random carries no information, which is the only reason a second
mark on that channel is legal at all.

THE OR-TRAP, which he caught from both sides. CatBody row 11 is a muzzle gap
row 10 covers, so the cat has never had a mouth on screen. A 16x9 draft grew a
nose; doubling for the top rung grew a mouth. Two general fixes were measured
and rejected -- half-row doubling flattens nine tapered rows, and filling every
covered interior gap also eats the notch between the ears.

FIXED: the cat's mid-stride drew a 16-cell side view inside the 12-cell box and
put the eyes 6 and 10 cells off the head, 4,037 times across 31 sessions ·
hyFloor ignored the horizon and allowed water above it in 81 configurations ·
the unmirrored layout paced the companion toward the frame edge · emit accepted
any word as a kind and confirmed delivery of nothing · XSCAPES_COMPANION was
double-prefixed and had never worked · the cat's parent body had no cleared rim ·
the tail could not scale, so a doubled cat arrived bald · DrawnHeadCol ignored
the mirror, which the crab's symmetric eye cells had hidden.

NOT FIXED, and both put back after measuring worse than the bug: a fractional
tide depth churns 53.62% every frame against ~64% on crossings alone; making
the star separation strict took touching pairs from 10 to 12. Carded with the
numbers. An average that passes is not a ceiling that holds.

Studies, none of them shipping behaviour: -starfall (the star arriving, 1,805
swept arrivals), -catalts (the design round), -decisions (what is still open).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P7YSpTVSL4ws8rgG1X4mtt
2026-09-12 21:19:55 -07:00

458 lines
15 KiB
Go

// Command xscapes renders the thinking scene.
//
// Without flags it prints one frame, which is what you want in a pipe. The
// live TUI is a thin wrapper over exactly this renderer.
package main
import (
"flag"
"fmt"
"io"
"os"
"path/filepath"
"github.com/donlucasx/xscapes/internal/canvas"
"github.com/donlucasx/xscapes/internal/envx"
"github.com/donlucasx/xscapes/internal/notify"
"github.com/donlucasx/xscapes/internal/scape"
"github.com/donlucasx/xscapes/internal/term"
)
// wantsHelp is the bare help gesture and nothing else: `xscapes -h`, `-help`,
// `--help` or `help` with no other argument. `-h 30` is still the canvas
// height, which every study command and the whole test suite passes.
func wantsHelp(args []string) bool {
if len(args) != 1 {
return false
}
switch args[0] {
case "-h", "-help", "--help", "help":
return true
}
return false
}
// helpText is what someone sees one second after installing: the subcommands
// first, because `xscapes claude` is the product and the renderer's twenty
// flags are for the studies. It runs after the flags are registered so
// PrintDefaults has something to print.
func helpText(w io.Writer) {
usage(w)
fmt.Fprintln(w, "The renderer's flags:")
flag.CommandLine.SetOutput(w)
flag.PrintDefaults()
}
func main() {
warnLegacyEnv(os.Args[1:])
// Before dispatch: the host paints too, and Terminal.app draws U+2580
// with a gap above it (see term.LowerHalf).
term.LowerHalf = term.DetectSplit(os.Getenv("TERM_PROGRAM"))
// And Terminal.app's half block leaves a 1px rule at the cell's bottom
// edge whichever way up it is drawn, so the ramp is painted one tone a
// cell there. Every HTML writer saves and restores this: the published
// page must not change with the terminal it was built from.
term.NoSplitCells = term.DetectNoSplit(os.Getenv("TERM_PROGRAM"))
// Subcommands are checked before the flag set is parsed. The renderer has
// twenty demo flags and the adapters have their own; keeping them in
// separate flag sets is what stops `emit -tool` from colliding with a
// future `-t` on the renderer.
if dispatch(os.Args[1:]) {
return
}
var (
width = flag.Int("w", 80, "canvas width")
height = flag.Int("h", 24, "canvas height")
frames = flag.Int("frames", 1, "how many frames to render")
plain = flag.Bool("plain", false, "glyphs only, no colour")
working = flag.Bool("working", false, "render the working state")
level = flag.Float64("level", -1, "activity level 0..1 (default: 0 resting, 0.7 working)")
seed = flag.Int64("seed", 7, "scene seed")
asciiG = flag.Bool("ascii", false, "ASCII glyphs only, no Unicode")
fps = flag.Float64("fps", 20, "time step between rendered frames")
info = flag.Bool("info", false, "print the detected colour profile and exit")
html = flag.String("html", "", "write the frame to an HTML file instead (for looking at colour)")
sheet = flag.String("sheet", "", "write the companion contact sheet to an HTML file")
compare = flag.String("compare", "", "write the rendering comparison to an HTML file")
anim = flag.String("anim", "", "write an animated companion preview to an HTML file")
strip = flag.String("strip", "", "write a frame strip (for GIF assembly) to an HTML file")
layout = flag.String("layout", "", "write the layout mockups to an HTML file")
ctxdemo = flag.String("context", "", "write the context-moon demo to an HTML file")
dayHTML = flag.String("day", "", "write the day cycle, truecolor vs 256, to an HTML file")
busy = flag.String("busy", "", "write the activity-level sweep to an HTML file")
kits = flag.String("kittens", "", "write the subagent-kitten demo to an HTML file")
wired = flag.String("wired", "", "write a simulated session, folded by the real reducer, to an HTML file")
reel = flag.String("reel", "", "write a frame strip of one simulated turn (for GIF assembly)")
colors = flag.String("colors", "", "write the 256-vs-truecolor study to an HTML file")
facesHT = flag.String("faces", "", "write the companion face/coat study to an HTML file")
eyesHT = flag.String("eyes", "", "write the companion eye-fill study to an HTML file")
ctxHT = flag.String("ctxcycle", "", "write the context cycle study (moon phase, altitude, readout) to an HTML file")
moonHT = flag.String("moon", "", "write the moon-edge study (quad edge, sun shadow, halo, rim) to an HTML file")
reelAt = flag.Int("reel-from", 0, "first frame of the reel strip")
reelN = flag.Int("reel-count", 40, "how many frames of the reel strip")
tod = flag.Float64("tod", 0, "time of day: 0 midnight, .25 dawn, .5 noon, .75 dusk")
todo = flag.String("todo", "", "checklist as done/total, e.g. -todo 3/5 (lights the constellation)")
live = flag.Bool("live", false, "paint the scape in THIS terminal until Ctrl-C")
ctxUsed = flag.Float64("ctx", 0, "context used, 0..1 (moon phase and altitude)")
mode = flag.String("mode", "working", "strip mode: resting|working|needsyou|walk")
session = flag.String("session", "", "session to follow in -live (default: $CLAUDE_CODE_SESSION_ID, else the newest)")
await = flag.Bool("await", false, "in -live, keep looking for a session instead of settling for the demo")
mirror = flag.Bool("mirror", true, "companion on the right, litter growing leftward (-mirror=false for the old left-anchored layout)")
mockup = flag.String("mockup", "", "write the left-vs-mirrored composition study to an HTML file")
overlay = flag.String("overlay", "", "mock the agent INSIDE the scape: composite a captured pane (text file) over the scene")
sandfd = flag.String("sandfade", "", "tuner: how far the lower beach falls away to black")
starfl = flag.String("starfall", "", "the star-arriving study: write the mockup to an HTML file")
catalt = flag.String("catalts", "", "the cat design round: write the alternatives to an HTML file")
decide = flag.String("decisions", "", "every art decision still open, in one page")
site = flag.String("site", "", "write the submission page: reads <dir>/template.html, writes <dir>/index.html")
gifsDir = flag.String("gifs", "", "write the animated clips of the demo turn as frame pages into <dir> (then site/make-gifs.py encodes them)")
)
// `-h` is the canvas HEIGHT, so the one gesture everybody tries first --
// `xscapes -h` -- printed "flag needs an argument: -h" and then the usage
// block, which reads as a crash one second after installing. dispatch()
// has a `case "-h", "--help"` but it can never run: dispatch returns early
// on any argument starting with "-", so only the bare word `help` ever
// reached it. The height flag keeps its name -- every study command and the
// test suite pass -h N -- and a BARE -h is the help nobody was serving.
if wantsHelp(os.Args[1:]) {
helpText(os.Stdout)
return
}
flag.Parse()
// The half-block that smooths a gradient is Unicode, so ASCII-only output
// cannot have it. Nothing else in the renderer is glyph-set dependent.
if *asciiG {
term.Shading = false
}
if *info {
tw, th := termSize()
split := "upper"
if term.LowerHalf {
split = "lower"
}
fmt.Printf("profile=%s size=%dx%d glyph-chroma=%.1fx split=%s sound=%s TERM=%q COLORTERM=%q TERM_PROGRAM=%q\n",
term.DetectProfile(), tw, th, term.GlyphBoost, split, notify.New().Describe(),
os.Getenv("TERM"), os.Getenv("COLORTERM"), os.Getenv("TERM_PROGRAM"))
return
}
act := scape.Activity{Working: *working, TimeOfDay: *tod, ContextUsed: *ctxUsed}
if *todo != "" {
if _, err := fmt.Sscanf(*todo, "%d/%d", &act.TodoDone, &act.TodoTotal); err != nil {
fmt.Fprintln(os.Stderr, "xscapes: -todo wants done/total, e.g. 3/5")
os.Exit(2)
}
}
switch {
case *level >= 0:
act.Level = *level
case *working:
act.Level = 0.7
}
c := canvas.New(*width, *height, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
sc := scape.NewShore(*seed, *asciiG)
profile := term.DetectProfile()
if *live {
wl, hl := 0, 0
if isSet("w") {
wl = *width
}
if isSet("h") {
hl = *height
}
runLive(*seed, *fps, wl, hl, *ctxUsed, *tod, *asciiG, *session, *mirror, *await)
return
}
if *decide != "" {
if err := os.WriteFile(*decide, []byte(decisionsPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*decide)
return
}
if *catalt != "" {
if err := os.WriteFile(*catalt, []byte(catAltsPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
for _, ln := range catAltsReport() {
fmt.Fprintln(os.Stderr, " ", ln)
}
fmt.Println(*catalt)
return
}
if *starfl != "" {
if err := os.WriteFile(*starfl, []byte(starfallPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
for _, ln := range starfallSweep(*seed) {
fmt.Fprintln(os.Stderr, " ", ln)
}
fmt.Println(*starfl)
return
}
if *sandfd != "" {
if err := os.WriteFile(*sandfd, []byte(sandFadePage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
for _, ln := range sandFadeContrast(*seed, *tod) {
fmt.Fprintln(os.Stderr, " ", ln)
}
fmt.Println(*sandfd)
return
}
if *overlay != "" {
if flag.NArg() < 1 {
fmt.Fprintln(os.Stderr, "xscapes: -overlay needs a captured pane file, e.g. -overlay out.html pane.txt")
os.Exit(2)
}
if err := os.WriteFile(*overlay, []byte(overlayPage(*seed, flag.Arg(0))), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*overlay)
return
}
if *mockup != "" {
if err := os.WriteFile(*mockup, []byte(mockupPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*mockup)
return
}
if *facesHT != "" {
if err := os.WriteFile(*facesHT, []byte(facePage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*facesHT)
return
}
if *eyesHT != "" {
if err := os.WriteFile(*eyesHT, []byte(eyesPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*eyesHT)
return
}
if *gifsDir != "" {
if err := gifPages(*seed, *gifsDir); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*gifsDir)
return
}
if *ctxHT != "" {
if err := os.WriteFile(*ctxHT, []byte(ctxCyclePage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*ctxHT)
return
}
if *moonHT != "" {
if err := os.WriteFile(*moonHT, []byte(moonPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*moonHT)
return
}
if *colors != "" {
if err := os.WriteFile(*colors, []byte(colorPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*colors)
return
}
if *reel != "" {
if err := os.WriteFile(*reel, []byte(reelPage(*seed, *reelAt, *reelN, *fps)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*reel)
return
}
if *site != "" {
page, err := sitePage(*seed, *site)
if err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
out := filepath.Join(*site, "index.html")
if err := os.WriteFile(out, []byte(page), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(out)
return
}
if *wired != "" {
if err := os.WriteFile(*wired, []byte(wiredPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*wired)
return
}
if *kits != "" {
if err := os.WriteFile(*kits, []byte(kittenPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*kits)
return
}
if *busy != "" {
if err := os.WriteFile(*busy, []byte(busyPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*busy)
return
}
if *dayHTML != "" {
if err := os.WriteFile(*dayHTML, []byte(dayPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*dayHTML)
return
}
if *ctxdemo != "" {
if err := os.WriteFile(*ctxdemo, []byte(contextPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*ctxdemo)
return
}
if *layout != "" {
if err := os.WriteFile(*layout, []byte(layoutPage(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*layout)
return
}
if *strip != "" {
if err := os.WriteFile(*strip, []byte(stripPage(*seed, *frames, *fps, *mode)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*strip)
return
}
if *anim != "" {
if err := os.WriteFile(*anim, []byte(animPage(*seed, 36, 12)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*anim)
return
}
if *compare != "" {
if err := os.WriteFile(*compare, []byte(compareSheet(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*compare)
return
}
if *sheet != "" {
if err := os.WriteFile(*sheet, []byte(contactSheet(*seed)), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*sheet)
return
}
if *html != "" {
sc.Update(c, float64(*frames-1)/(*fps), act)
if err := os.WriteFile(*html, []byte(c.RenderHTML("xscapes — "+sc.Name())), 0o644); err != nil {
fmt.Fprintln(os.Stderr, "xscapes:", err)
os.Exit(1)
}
fmt.Println(*html)
return
}
for i := 0; i < *frames; i++ {
sc.Update(c, float64(i)/(*fps), act)
if *plain {
fmt.Println(c.RenderPlain())
} else {
fmt.Println(c.Render(profile))
}
if i < *frames-1 {
fmt.Println()
}
}
}
// isSet reports whether a flag was given explicitly, so -live can size itself
// to the real terminal unless told otherwise.
func isSet(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}
// warnLegacyEnv names any pre-rename ASCIISCAPES_* variable still in the
// environment. They keep working -- see internal/envx -- but a setting whose
// name has moved is the easiest way there is to end up measuring nothing, so
// the program says which ones it saw rather than letting them pass.
//
// Here, at the top of main, because this is the last moment that is certainly
// safe to write to the terminal: `-live`, `claude` and `inside` take the
// alternate screen shortly after, and a stray line then lands in the middle of
// a painted frame. The two adapters are exempt -- `hook` runs on every tool
// call with its output already sent to /dev/null, and `statusline` owns a line
// of the agent's chrome that is not ours to scribble on.
func warnLegacyEnv(args []string) {
if len(args) > 0 {
switch args[0] {
case "hook", "statusline":
return
}
}
envx.WarnLegacy(os.Stderr)
}