ImaGen #5: tmux-window preview for generated images (--preview flag + /imagine integration) #5
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
When a user (m or any interactive agent) runs
imagen generate, automatically preview the resulting image in a new tmux window usingtmux-img. Programmatic callers (otto, lex workers, batch scripts) keep the current behaviour — no UI side effects unless they ask.m's framing (2026-05-08)
After the first FLUX render landed, m saw the image rendered inline via
tmux-imgin head's pane and said:The goal is a frictionless
/imagine "..."flow: the image generates and the preview just appears in a side window — noxdg-open, no nvim-on-binary-PNG.Scope
1.
imagen generate --previewflagcmd/imagen/generate:--preview/--no-preview.auto— preview iff stdout is a TTY and$TMUXis set (i.e. running inside a tmux session). Otherwise off.tmux-img --hold <output-path>. Window name:img:<slug>(slug from prompt, mirroring the output naming).--no-previewforces off (for batch scripts / CI).--previewforces on even outside tmux (errors clearly with "requires $TMUX, are you in a tmux session?").IMAGEN_PREVIEW=auto|on|offenv var as the precedence floor (config -> env -> flag).2. Config knob
~/.config/imagen.yaml:imagen config initwritespreview: auto.imagen config validateaccepts the new field.3. tmux integration helper
internal/preview/tmux.go: small package that wrapstmux new-window -t "$TMUX_SESSION" -n "img:<slug>" 'tmux-img --hold <path>'. Usesos/exec. Returns a typed error when:tmuxbinary is missing on PATHtmux-imgbinary is missing on PATH$TMUXis unset and--previewwas forced onAll three error messages name the missing binary and where to install it (e.g.
tmux-imgis~/.local/bin/tmux-img).4.
/imagineskill updateUpdate
mai/.mai/skills/imagine/SKILL.md(lives in m/dotfiles):imagen generate ...without--preview; the auto behaviour does the right thing inside any tmux pane.m pwa reply --attach-imageonce m/mAi#213 lands).--no-previewto suppress the window-storm.5. Tests
internal/preview/tmux_test.go: mockedos/exec(ort.Setenv+ a faketmux/tmux-imgon PATH via temp dir) to verify the spawned command. No real tmux session needed in tests.cmd/imagen/generate_test.go: assert flag parsing + the auto/on/off resolution table.Acceptance criteria
imagen generate "a cat in a fishbowl"from inside any tmux pane spawns a siblingimg:cat-...window showing the PNG viatmux-img. The original pane keeps its terminal output (image path, latency).imagen generate ... --no-previewproduces no new window.imagen generate ...from outside tmux (e.g. a plain ssh shell) emits the path on stdout and does NOT crash trying to open a window.IMAGEN_PREVIEW=off imagen generate ...overrides auto-preview even inside tmux./imagine "<prompt>"from m's terminal pane behaves identically to (1).go build ./... && go test ./...clean.Out of scope
icat,feh,xdg-open) — can be added later under the same--previewumbrella with apreview_backend:config key. Not needed for v0.Refs
imagen generate, file overlap)/imagineskill body; coordinate so #4's live-demo and #5's skill update don't conflicttmux-imglives at~/.local/bin/tmux-img(signature:tmux-img [--hold] <image> [WxH])Workflow
Blocked on #2 (Go adapter) merging. After that, coder role; standard branch + worktree pattern. End shift with the live demo from acceptance #1 + a screenshot of the spawned tmux window in the Gitea comment.
Shift-1 done — Go side landed on
mai/hermes/issue-5-imagen-5-tmuxCommit:
2a8bd4313bWhat's in
internal/preview(new):Mode(auto|on|off),ParseMode,Resolve, and aSpawnerthat invokestmux new-window -d -n img:<slug> '<tmux-img --hold path>'. Typed errors:ErrTmuxMissing—tmuxnot on$PATHErrTmuxImgMissing—tmux-imgnot on$PATH(names~/.local/bin/tmux-imgin the message)ErrNoTmuxForced—--previewwas forced on but$TMUXis unsetcmd/imagen/generate—--preview/--no-previewflags;IMAGEN_PREVIEW=auto|on|off. Resolution: config -> env -> flag (later wins). Preview failures are warnings on stderr — the image is already on disk.internal/config—output.previewfield, validated toauto|on|off|<empty>. Sample (imagen config init) writespreview: autowith a 3-line comment.docs/usage.mdgets a Preview section + flags row;docs/architecture.mdlists the new package.Acceptance walk-through
imagen generate ...from inside tmux spawnsimg:<slug>windowtmux list-windowsshowed4: img:demo-cat-fishbowl--no-preview-> no new windowenv -u TMUX ...) -> path on stdout, no crashIMAGEN_PREVIEW=offoverrides auto/imagine "..."from m's panego build ./... && go test ./...cleanOut-of-band:
/imagineSKILL.mdPer head's brief: the
/imagineskill lives inm/dotfilesandathenais currently shipping #4 there. Skill update (5.4) deferred to coordinate — head will signal when #4 is in. ImaGen-side work is complete.Live demo notes for m
From any tmux pane:
Force-on inside tmux:
--preview. Suppress for batch:--no-previeworIMAGEN_PREVIEW=off. Forced-on outside tmux gives a clear error and does not crash.Setting
needs-review.Merged into main
Branch
mai/hermes/issue-5-imagen-5-tmuxmerged via--no-ffata1d0165. Pushed to origin/main.2a8bd43a1d0165Acceptance criteria
imagen generate "..."from inside tmux spawns siblingimg:<slug>window--no-previewproduces no new window$TMUXenvIMAGEN_PREVIEW=offoverrides auto-preview/imagine "<prompt>"from m's terminal pane behaves like (1)go build ./... && go test ./...cleanFiles
internal/preview/tmux.go(119 lines) - typed errors (ErrTmuxMissing,ErrTmuxImgMissing,ErrNoTmuxForced),Resolve(mode, inTmux, stdoutTTY)decision matrix,Spawnerwith injectableLookPath+Runhooks for testsinternal/preview/tmux_test.go(170 lines) - covers all three modes and all error paths via fakes; no real tmux dependencycmd/imagen/generate.go(+84/-10) - flag wiring (--preview/--no-preview), env override, mode-resolution table,maybePreviewis non-fatal (image always writes; preview failure printsimagen: preview: ...to stderr but does not exit non-zero)cmd/imagen/generate_test.go(50 lines) - flag parsing + resolution testsinternal/config/config.go+ tests - newoutput.previewknob (auto|on|off, defaultauto),imagen config initwrites it,imagen config validateaccepts itdocs/architecture.md,docs/usage.md- preview mechanism documentedBehaviour reference
$TMUX--previewflagos/exec--no-preview--preview$TMUXIMAGEN_PREVIEW=offFollow-up: when m's dotfiles working tree is clean, head merges
mai/athena/issue-4-imagine-skillinto dotfiles main (closes #4), then unblocks the small/imagineSKILL.md edit for acceptance #5 of this issue.