Skip to content

Latest commit

 

History

History
537 lines (507 loc) · 34.5 KB

AGENTS.md

File metadata and controls

537 lines (507 loc) · 34.5 KB

AGENTS.md

ft is a terminal file-tree explorer (a JetBrains-style project pane for a tmux split) written in Go with Bubble Tea v2. macOS is the supported OS; the code is structured for Linux to be added behind build tags.

Build, test, verify

Use go-task (Taskfile.yml; there is no default task):

task vet       # go vet ./...
task test      # go test ./...
task build     # builds ./ft (gitignored)
task install   # go install ./cmd/ft  -> ~/go/bin/ft

All code must be gofmt-clean and go vet-clean, and tests must pass before any change is considered done.

Releasing

Every push to main runs .github/workflows/release.yml. A pull request's title becomes its merge commit's subject, and .github/scripts/next-version.sh reads those subjects on main's first-parent line since the last tag: feat bumps the minor version, fix and perf bump the patch, and type!: or a BREAKING CHANGE: line is major (minor while the version is 0.x). Anything else releases nothing. So a pull request title must be a conventional-commit subject, and its type is a release decision. To release without one, run the workflow by hand from the Actions tab and pick the bump.

GoReleaser (.goreleaser.yaml) uploads the archives to the GitHub release itself. Do not add an actions/upload-artifact step: release assets are free, and Actions artifact storage counts against the account's quota.

Every archive carries LICENSE and THIRD_PARTY_NOTICES.txt, because the MIT and BSD licences of what is compiled in, Go's standard library included, ask for their notices to travel with the binary. GoReleaser's before hook runs .github/scripts/third-party-notices.sh, which reads the import graph at release time, so the file is never committed and never stale. The hook names the operating systems to read it for; keep them in step with goos.

Critical gotcha: charm.land import paths

The Charm v2 modules use vanity import paths. go get github.com/charmbracelet/bubbletea/v2 FAILS with a module-path mismatch. Use:

  • charm.land/bubbletea/v2
  • charm.land/lipgloss/v2
  • charm.land/bubbles/v2

Verify v2 APIs with go doc charm.land/bubbletea/v2 <Symbol> rather than assuming v1 shapes: View() returns tea.View (AltScreen/MouseMode are set on it per render), mouse events are typed messages (tea.MouseClickMsg, tea.MouseWheelMsg), and Key.String() returns text for printable keys ("Y") and names otherwise ("ctrl+c", "up").

Package map

cmd/ft/             entrypoint, flag parsing
internal/app/       Bubble Tea model — the heart of the tool
  app.go            model, Update dispatch, keybinding table (buildBindings)
  actions.go        navigation, toggles, clipboard, file ops, command exec
  view.go           rendering: header (clickable toggles), tree, status bar
  mouse.go          wheel/click/double-click, header hit-testing
  fuzzy.go          candidate walk (BFS, streamed) + screen-aware ranking
  grep.go           content-search mode: debounce, hit list, Find narrowing
  git.go            per-repo status cache plumbing
internal/tree/      pure tree model: lazy nodes, expand/collapse, flatten
internal/fsops/     directory listing + fsnotify watcher (debounced batches)
internal/gitx/      repo discovery, `git status --porcelain -z --ignored` parsing
internal/search/    finder file-type filter (pure) + the ripgrep integration
internal/config/    TOML config, command templates + shell quoting, starter
internal/state/     per-root JSON persistence (expansion, selection, toggles)
internal/icons/     Nerd Font glyphs; table.go is GENERATED — see below
internal/platform/  OS interface; darwin impl (pbcopy, open -R, Finder trash),
                    linux impl (wl-copy/xclip/xsel, xdg-open, gio/trash-put)
internal/tmux/      every tmux invocation: the self-relaunch decision, the
                    session names (grammar, list parsing, kill), and the
                    server-wide pane list that jump routing needs
internal/ipc/       the "ft jump <file>" socket: one listener per instance,
                    plus the pure routing that picks which instance answers
internal/herdr/     every herdr call: the socket client, and the pure rule
                    picking which open pane belongs to a checkout
internal/agenthook/ what an agent's lifecycle hook means: event + payload in,
                    state / bell / notification out (pure; "ft agent-hook")

Design rules that keep this maintainable:

  • internal/tree stays free of filesystem and UI dependencies; directory listing is injected via tree.Lister.

  • All git information comes from one parsed git status per repo, cached in the app model and refreshed via async tea.Cmds. Never shell out to git per file. That status runs as git --no-optional-locks status: ft re-reads it after every watched file change, and a plain git status takes .git/index.lock on every run (measured), so a lazygit commit or any other index write landing in that window fails with "index.lock: File exists". TestReadStatusLeavesTheIndexAlone is the guard.

  • OS-specific behaviour goes behind platform.Platform in platform_<goos>.go files with build tags — never inline exec.Command for OS integrations elsewhere.

  • Each external tool gets one package that owns every invocation of it: internal/gitx for git, internal/search for rg. Argument building and output parsing stay pure and table-tested (search/args.go, search/parse.go); the process spawn lives alone (search/exec.go). The app only sequences git and rg in async tea.Cmds, because their cost grows with the repository. A tmux call made in answer to a key press may run inline (ctrl+w, X, the T kill, the quit check all do): it takes a few milliseconds, and ft's own input arrives through that same server, so a tmux too stuck to answer has already stopped ft's keys. Only a read on a timer, like the agent poll, goes off the loop.

  • The finder's file-type filter is compiled once, in internal/search, and used by both the walk (Filter.Match) and ripgrep (Filter.Globs becomes -g args) — so a filtered file list and a filtered content search can never disagree about which files are in scope.

  • Web links (u/U): internal/gitx/link.go owns remote-URL normalisation and URL building (pure, table-tested); platform.OpenURL owns the browser.

  • Commands ship in internal/config/catalogue.go, never in the starter. starterTOML is written to ~/.filetree/config.toml on first run and never again, and Load merges the file over the catalogue rather than replacing it — so a command added to the starter reaches nobody who has already run ft once. That is a real bug that shipped once already; TestStarterDefinesNoCommands guards it. [keys] covers commands as well as actions, resolved together by resolveActionKeys, and the commented [keys] reference in the starter is generated from both tables so it cannot go stale.

  • internal/tmux owns every tmux call, the way gitx owns git: the pure half (session.go — name building, list-sessions parsing) is table-tested, and the process spawns live alone in run.go and exec.go. The self-relaunch keeps its decision pure the same way: tmux.ShouldWrap takes an Env struct so it is table-tested, and the syscall.Exec lives alone in internal/tmux/exec.go. It runs in main after root validation and config load, so startup errors print in the user's terminal instead of dying with the session they would have created.

  • internal/herdr owns every herdr call, the way gitx owns git: the pure half (pick.go — which of the open shells answers for a checkout) is table-tested, and the socket work lives alone in herdr.go. It speaks the socket directly rather than shelling out to the herdr CLI, and that is not a preference: focusing a named pane has no CLI form at all (herdr pane focus takes a direction, and herdr api offers only snapshot and schema), while the socket exposes pane.focus taking a pane id. Going straight to the socket also costs no process spawn, which matters because one key press makes several calls. Note prutil/internal/herdr shells out instead — fine there, because every agent method it needs does have a CLI form.

  • A new herdr key is a program value, not a new command. cmd/ft/herdrprogram.go holds the body all of them share: find the place, find the program in it, reuse or create, name the tab, report. A key says only what to look for (Argv0), what to run (Command), what to say to one already running (Reuse, nil when there is nothing to say) and whether it needs a checkout. herdredit.go and herdrlazygit.go are what that looks like. Resist adding a fifth by copying the body.

  • Two keys sharing a binary must each claim only their own panes. alt+g runs lazygit and ctrl+g runs lazygit -f <file>; to Runs they are the same program, so each would answer for the other. program.Match is the hook, and RunsWith/RunsWithout are what it is built from — matching the arguments a pane was started with, which is also what gives blame one tab per file. Give such a key a Label too, or its tabs all carry the binary's name.

  • Never label a workspace ft creates. herdr derives a workspace's name from its shell's directory and keeps it current, but a label passed to workspace.create is stored as the workspace's custom_name in ~/.config/herdr/session.json, and a custom name is never replaced. J once labelled new workspaces with the directory's basename, which read correctly until the first cd and then stuck. herdr's own name for a fresh workspace is that same basename, so there is nothing to add. Tabs are the opposite case: hx, lazygit and blame <file> say what a tab runs, and should stick.

  • The multi-step herdr work is a subcommand, not a template. J runs ft herdr-shell {dir}, the same shape as ft jump. Choosing between the open shells takes a pane list, a process check per candidate and a ranking; in a [commands] template that would mean a jq dependency and no tests. Adding more herdr keys should follow this: one line in the catalogue, the logic in Go. Note the template passes {dir} alone and works the checkout out from it: config.NeedsRepo refuses any template mentioning {gitroot} outside a repository, and this key has to work in a loose directory too.

  • Two herdr send methods, and picking the wrong one corrupts a file. pane.send_input honours the pane's bracketed-paste mode and arrives as a paste; pane.send_text arrives as typing. A program that tells them apart does completely different things with them. Sending :open file to helix via send_input pastes the literal text into the buffer and leaves the file modified, and nothing opens; via send_text the leading colon reaches helix's command line. Verified against a real helix, not reasoned about. So: send_text to drive a program's key handling, send_input to hand a command to a shell. TestOpenInTypesRatherThanPastes is the guard — do not "simplify" those three calls into one atomic send.

  • Process identity comes from argv0, and the whole foreground list. Name is what a process calls itself now, and programs rename themselves: a Claude pane reports Name 2.1.268 with Argv0 claude. The foreground group can also hold more than one process, and the wrapper may be listed first — a pane running Claude under caffeinate lists caffeinate ahead of it. Matching the first entry by Name finds the wrapper and misses the program. See herdr.ProcessInfo.Runs.

  • herdr.Scope is the boundary, and it has two shapes. Inside a checkout it is the checkout root, which is the whole of the worktree-awareness. Outside one it is the selection's own directory, and membership runs both ways — a shell above the selection or below it. The upward direction is load-bearing: without it, stepping one directory deeper puts the shell you just opened out of scope and earns a second workspace for the same place. A repository spanning the whole home directory is ignored as a boundary (checkoutFor in cmd/ft/herdrshell.go), because dotfiles-in-~ would otherwise make every loose directory one enormous checkout.

  • ft jump <file> (internal/ipc) is the one way into a running ft from outside the process, and the only IPC there is. Each instance listens on ~/.filetree/run/<pid>.sock; the jump command dials all of them, asks each which root it is on, picks one, and sends the path, which main turns into an app.RevealMsg through Program.Send. Four rules hold it together:

    • Routing filters on containment, then scores locality (ipc.Pick, pure and table-tested). An instance whose root does not cover the path cannot show it, so scoring "same tmux window" additively would let the pane beside the editor win every time and then fail, while an instance that could have shown the file was never reached. Filter first; among the survivors, the caller's window beats its session beats neither, and the deepest root wins. Terms are compared in order rather than summed so no amount of path depth outranks being in the right window.
    • Status is answered off the Bubble Tea event loop, from an atomic.Pointer the model publishes to through SetRootObserver (hooked into loadRoot, the single funnel every re-root passes through). An ft suspended in an interactive command has a blocked Update, and an instance that cannot answer cannot be routed around either — it would time out and stall the editor's keystroke.
    • Program.Send blocks when the loop is suspended, so revealVia (cmd/ft/main.go) sends from a goroutine: the deadline has to cover getting the message in, not just getting an answer back. Measured, not reasoned about — waiting on the reply alone hung for the client's full timeout. The reply channel is buffered for the mirror case, a client that has already given up.
    • A reveal reports whether it actually happened. selectPath no-ops on a path with no row and ExpandRel gives up at a missing segment, so revealRequest re-checks the selection afterwards and blames the ancestor the row filter is hiding (Flatten skips a filtered directory's whole subtree, so an ordinary file inside a dot-directory has no row either). It never flips show_hidden/show_ignored itself — those are persisted per root. It also refuses outright during modePrompt: commitPrompt and createTargetDir resolve their target from m.selected() when the prompt is committed, so a jump landing in between would rename or create against a file the user never chose. Sockets are 0600 in a 0700 directory, and are swept by the next jump rather than on a timer — a killed instance leaves a file, and a file nothing answers on is unlinked when it refuses a connect. macOS caps a socket path at 104 bytes, which Serve checks so the failure is a sentence rather than the kernel's "invalid argument".
  • treeHeight() is the body; treeVisibleRows() is the tree. The sticky parents (sticky_parents) pin the ancestor chain of m.rows[m.scroll] above the tree and are paid for out of the body, so anything counting selectable rows — ensureVisible, clampScroll, half-page paging, the finder's centring jump — must use treeVisibleRows(), while the help and finder screens keep filling all of treeHeight(). Two consequences are easy to get wrong. The count is Depth-1, not Depth: Flatten puts the root's children at depth 1, and the root is left to the header line. And the window height and the scroll offset now decide each other, so ensureVisible and clampScroll both settle by iteration rather than clamping once — they are compatible at rest (at an ensureVisible fixed point clampScroll is a no-op), which is what stops G on a deep tree oscillating. Clicks go through rowAtY, which returns the real row index for a pinned line, so selection, double-click and the chevron hit test need no case of their own. A confirmation too long for the status line is the one thing that takes rows from the body without going through treeHeight(): fitConfirm wraps it and View drops that many lines off the bottom of the body (borrowLines). It is short-lived and covers rows no click reaches while it is up, so scrolling and paging never need to know.

  • New keybindings are wired in buildBindings (internal/app/app.go); make

    them remappable via the [keys] action map and list them in the ? help overlay (view.go) and README.

  • A key with a space in it is a chord ("n right"), and it is an ordinary entry in m.bindings keyed by the whole sequence — so [keys], the conflict report and the help page need nothing special. What chords add is in internal/app/chord.go: m.chordPrefixes (every proper prefix of a bound sequence, computed by settleChords after all claims), and m.chord, the prefix typed so far, consulted at the bottom of handleKey in modeNormal only. A prefix displaces a single-key binding on the same key unless that key is navigation, in which case the chord is refused. hjkl are tried as arrows inside a chord only when the letter itself completes nothing. The n shells are actions rather than templates because tmux.PlanShell has to read the layout to pick the pane; n space (the popup) is still a catalogue command, which is why a chord can mix the two.

  • ctrl+c is the only guaranteed way out, and handleKey rewrites it to "esc" before the mode switch whenever the mode is not modeNormal. So a new mode gets "the first press backs out, the next one quits" for free by handling esc, and needs no ctrl+c case of its own. quit itself ships unbound (like reload, which F5 covers) — the action is still in DefaultActionKeys so [keys] can give it a letter, but nothing does by default, which is what keeps q free for a command.

Generated code

internal/icons/table.go is generated from nvim-web-devicons' lua tables — do not hand-edit. Glyphs are written as \uXXXX/\UXXXXXXXX escapes because literal PUA glyphs do not survive copy/paste reliably. Devops entries missing upstream (hcl, terragrunt, helm, …) are added in icons.go's init by reusing generated glyphs.

Runtime files

  • Config: ~/.filetree/config.toml (TOML; commented starter written on first run from internal/config/starter.go — keep starter and README in sync with behaviour changes).

  • State: ~/.filetree/state/<basename>-<hash8>.json, one per tree root.

  • Recent roots (<): ~/.filetree/state/<basename>-<hash8>.roots.json, keyed by the launch root (launchRoot: homeRoot, else the current root) so every root reached from one project shares one list. recordRoot is called from loadRoot, the same funnel the root observer uses, and skips the scratch and worktrees view dirs. Picking the launch root must go through leaveView, not enterView, or homeRoot ends up naming the root you are standing on.

  • Jump sockets: ~/.filetree/run/<pid>.sock, one per running instance.

  • Command templates: {path} {relpath} {dir} {root} {name} plus mark vars {marked} {marked1} {marked2} are substituted shell-quoted; unknown {tokens} pass through untouched (tmux formats like "{last}" depend on this; also why {marked1} must be replaced before {marked} — the Replacer tries patterns in argument order). Commands run via /bin/sh -c with mode "interactive" (tea.ExecProcess suspends the TUI) or "background".

  • The scratch view (s/S) is plain re-rooting: loadRoot (internal/app) swaps tree+state; per-root state files make each root remember its own expansion. homeRoot (session-only) powers the Esc/toggle-key return; Esc is layered — marks clear first, then the view returns.

  • Every re-root goes through switchRoot (internal/app/actions.go): saveState on the way out, loadRoot on the way in. Saving first is why the return trip needs no work — each root's expansion lives in its own state file, keyed by that root, so the two sides of a switch cannot overwrite each other. enterView remembers the project root once; a second view does not overwrite it. That rule is what makes > (root-here) replace the root rather than stack, so one Esc comes home from any depth — and it is why homeRoot is a slot and not a stack. > carries the open dirs in via tree.RebaseRels, which renames them for the new root (expansion is stored root-relative, so "sub/a/b" up here is "a/b" down there); the seed applies only to a root with no expansion of its own, so a subtree you have been in before opens the way you left it. shift+enter is bound to the same action in the fixed navigation set, but only arrives where the terminal reports modified keys — inside tmux that needs set -s extended-keys on, a server option that is off by default, so never rely on it in a test. Bubble Tea already requests Kitty level 1 and modifyOtherKeys=2 unconditionally; there is no program option to add.

  • Worktrees (w/W) reuse the same re-rooting: <[worktrees] dir>/<repo basename>/<branch or pr-N>. internal/gitx/worktree.go owns every git invocation (add/remove/fetch, linked-worktree detection, input parsing); the app only sequences them in async tea.Cmds. d on a worktree root becomes git worktree remove (pendingOp kind opWorktree, with an f force re-prompt when git refuses a dirty tree).

  • Every session ft creates is named <[sessions] prefix><kind>/<rest>, kind first. agent is <repo>/<branch>/<tool> from tmux.SessionName and m.repoIdentFor (internal/app/sessions.go) — the main repo of a linked worktree, so every worktree files under one name. Every other kind (tree, shell, lazygit, blame, diff) is tmux.PlaceName: one path, rendered by tmux.Slug as storekey.Name does it, basename plus a hash. Kind first is what lets ParseName read a name without counting its slashes, and what makes a query in T narrow to one kind. The prefix is the only filter, so a name from before this convention still lists — unparsed, name only. "." and ":" are rewritten to "_" in a name because tmux does that silently otherwise, which would stop new-session -A finding what it created.

    • The popups build their own names in the catalogue out of {prefix} and a key (-s {prefix}shell/{dirkey}), which composes because the value is quoted and the literal between them is not — the same trick as {session}/claude. {repokey} is in repoTokens and the other two are not: a shell popup must keep working outside a repository.
    • -A on every one of them. A named session that already exists makes a bare new-session fail with "duplicate session", inside a popup that closes too fast to read it. The tree is the exception and cannot use -A (that would attach this terminal to the other tree), so main picks a free name with tmux.UniqueName before Wrap execs — after the exec there is no process left to recover in.
    • The picker is a fourth finderSource (srcTmux), not a new mode — see the bookmark view for the pattern; its ctrl+w/ctrl+s/ctrl+x are hardcoded in the modeFuzzy switch and listed in finderReservedKeys (ctrl+s is shared with the bookmark view, which the switch tells apart by finderSrc), and the status bar lists them from sessionHints while the view is open. It lists this tree too, from tmux.SelfSession($TMUX_PANE): attachSession, paneSession and killSession all refuse that row, because attaching shows the tree inside its own popup and killing it kills ft, and sortTmuxSessions puts it last so the row nothing acts on does not lead a list ordered by activity.
  • A session shown in a pane is a nested client, and that costs two things. ctrl+w splits the window and runs tmux attach-session in the new pane (tmux.SplitAttach); X (detach-pane) sends it away again. tmux has no primitive for putting a session in a pane, and the two alternatives are worse: join-pane moves the agent's only pane, which destroys its window and therefore its session, so it stops being listable by T exactly while you are using it; link-window gives you a whole window, which is what the popup already does. Nesting keeps the name, which is the identity everything else routes on. Two rules hold it together:

    • Unsetting $TMUX is required and insufficient. tmux refuses to nest ("sessions should be nested with care"), and unsetting $TMUX alone sends the nested tmux to the default socket, where the session does not exist ("set $TMUX to force"). AttachCommand therefore passes the socket back with -S, recovered from $TMUX by tmux.SocketPath — $TMUX is <socket>,<pid>,<session index>. This is the same hazard AttachPopup avoids by never unsetting $TMUX at all, so the two must not be merged.
    • Which pane is showing what is read from tmux, never remembered. A session attached in a pane is a client on that pane's tty, so tmux.PaneShowing matches list-clients against list-panes in ft's own window ($TMUX_PANE, captured once into Model.selfPane). Nothing is stored, so it is still right after an ft restart, or for a pane opened by hand. It is also what makes ctrl+w focus an already-open pane instead of attaching a second client to it. ctrl+s is the same nested client in a different place: the bottom half of the pane to ft's right (tmux.PaneRightOf: last-active, then largest), split with -vd and no -f, so ft's column is untouched and needs no width restore; with nothing to the right it falls back to ctrl+w's split. Because that stacks sessions, tmux.PaneShowing returns the newest matching pane (highest id, compared numerically), which is what makes X detach the one you opened last. The split is -fdh, like the pane commands in the catalogue: -d leaves the focus in ft, since opening an agent is not the same as wanting to type at it, and a second ctrl+w on a session already on screen is what moves you into its pane. A full-width split (-f) takes its columns from every pane in the window,

    so a 40-column ft beside an editor comes back at 18 and the tree stops being readable. Both ctrl+w and X therefore read ft's width immediately before the disruptive call and re-apply it after — reading rather than remembering, so a user resize is honoured. It is skipped when ft filled more than half the window, where there was no sidebar to preserve and restoring the old width would squeeze the pane just opened down to a single column.

  • An agent's state lives on its tmux session, written only by its own hooks. ft agent-hook <prompt|tool|notify|stop|end> (cmd/ft/agenthook.go) sets the session option @ft_agent to "<state> <unix>" from $TMUX_PANE, and List reads it back as one more list-sessions field — so the tree, T and the status bar never keep state of their own, and an ft restart loses nothing. internal/agenthook.Decide is the whole event table; the command only sequences tmux and platform.Notify around it (hookEnv, tested with fakes). Four decisions hold it together:

    • "Unseen" is tmux's bell flag, not ft's bookkeeping. The hook writes BEL to the pane's tty; tmux raises session_alerts only for a session nobody is viewing and clears it on attach. Session.NeedsYou is waiting, or that flag — except while working, because the flag outlives an answer given without attaching. Note session_alerts is <window index><flags> (0!), never words: the first version matched "bell" and never fired.
    • Passthrough is not the mechanism. allow-passthrough only reaches a terminal from a pane that is on screen; a detached session has none. The desktop banner therefore comes from the hook (osascript, text passed as argv so a payload cannot become script), and only when session_attached is 0.
    • A state outlives its agent, so it is ignored at a shell. AgentNow drops the state when the foreground command is a shell — the agent keys run <tool>; exec $SHELL, so that means the agent has exited, whether or not its end hook ran.
    • The poll is one chain. pollSessions reads off the event loop and each result schedules the next tick (agentPollInterval, 2s), so a slow tmux never stacks reads. A failed read keeps the last count rather than showing "all clear", and an open T re-sorts with the cursor following the session by name.
  • Quit ends the session only when ft made it, and the kill is main's last act. tmux.Wrap starts the inner ft with -owns-session (tmux.OwnerFlag, hidden from the usage text), and main turns that into the session's id, read at startup (SetOwnedSession). The session name cannot be the test: a second ft run from a split inside a tree session reads the same tree kind, and would end its parent. The id is kept rather than re-read at quit because the pane can be moved (join-pane) into a session of yours, and tmux.CheckQuit (pure, table-tested) refuses when it has. CheckQuit also calls a pane busy unless it is at a shell, dead, or a nested tmux client — a ctrl+w pane only detaches, so its agent survives — and counts the session's other attached clients. Either one stages an opQuitSession confirmation, the one mode where handleKey does not rewrite ctrl+c to esc, and where the quit action's own key also answers: the second press is the answer. quit_closes_session is read at quit time (closesOnQuit), not at startup, so a config reload counts. The model only records the verdict (ClosesSession); main kills by id after the program has stopped, the IPC socket has closed and state is saved, because kill-session hangs up ft along with every other pane. Agent and popup sessions are separate sessions and are never touched.

  • The tab title reaches the terminal through tmux, not around it. tea.View.WindowTitle alone stops at tmux: it becomes the pane's pane_title, and set-titles is off by default. So tmux.Wrap chains set-option set-titles on and a set-titles-string of tmux.TitleFormat onto the new-session (session options, so nothing else changes), and the model publishes the same string to the session option @ft_title (publishTitle, internal/app/title.go). The option rather than #{pane_title} because the string is evaluated against the active pane — focusing the editor split would hand the tab to helix. Writes are one chain, like the session poll: the title changes twice in quick succession at startup (name, then branch), and two concurrent set-options can land out of order. main unsets the option on exit, since the session can outlive ft.

  • Not every tmux subcommand takes the = exact-match prefix target() adds. attach-session, kill-session, detach-client, join-pane and resize-pane do; set-option, display-message and capture-pane resolve -t differently and fail with no such session: =.... PaneWidths passes a bare pane id for exactly this reason.

  • The status-bar branch (⎇ …) is cached per repo in m.branches, filled by the same async cmds that read git status — so it refreshes wherever status does, and nowhere else.

  • Marks (space bar) live only in the app model (marked/markOrder, path-keyed, session-only). Copy/move of marked items goes through internal/fsops/transfer.go — destructive steps (overwrite, cross-device move source) always go via the injected Trash, never unlink. Delete (d) is mark-aware (falls back to the selection) and ancestor-dedupes the list first so a marked dir plus its marked children can't race.

Testing a TUI change for real

Unit tests cover tree/gitx/config/state/search/fuzzy logic. Tests that need ripgrep skip when it is absent (search.Available). For end-to-end checks, drive the real binary:

  • Plain pty: script -q /tmp/out sh -c 'stty rows 30 cols 90; ./ft <dir>' with keystrokes piped on stdin. A script pty starts 0x0 — without the stty the app renders nothing.
  • tmux integration (hand-off commands, splits): create a detached session (tmux new-session -d -s t -x 200 -y 50 './ft <dir>'), drive with tmux send-keys, assert with tmux list-panes / tmux capture-pane -p.
  • Jump routing needs two sessions plus a shell pane to call from, and the assertion is which tree moved. capture-pane -p drops colour, so the cursor is invisible in it — use capture-pane -p -e and look for the selection background (^[[48;5;24m) on the row you expected. The two cases worth the setup are an instance in the caller's window losing to one elsewhere that actually contains the path, and a jump aimed at an instance suspended in hx (which must not stall the caller, and must land when the instance comes back).
  • When asserting "file opened in helix", grep the statusline (NOR + filename), not just the filename — pasted-garbage bugs also contain the filename in the buffer.
  • A disposable fixture repo with modified/untracked/ignored files is the standard way to exercise git colouring; create it under /tmp, not in this repo.

Known input gotcha (documented in the starter config): keys sent to helix via tmux send-keys must deliver Escape in its own send, then sleep ~150ms, or ESC coalesces with the next byte and parses as an Alt-chord.

Anything that builds a shell string for tmux has to be exercised on macOS. tmux runs display-popup and send-keys commands through default-shell, which is /bin/zsh on a stock macOS and /bin/sh or bash in a Linux container — so a whole class of bug is invisible off the supported OS. The one that shipped: ShellQuote treated = as safe, the session picker's = exact-match target reached zsh bare, zsh applied equals expansion (a word starting with = becomes the path of the command it names), and attach-session failed with the popup closing too fast to read the error. Every other shell leaves =foo alone. Prefer passing tmux targets as direct argv (exec.Command("tmux", "kill-session", "-t", target)) where there is no template to honour — that path was never affected.

Two things worth measuring rather than reasoning about, both of which were guessed wrong first: display-popup blocks its caller until the popup closes (display-popup -E "sleep 4" takes four seconds), and a popup is not a pane, so attaching from inside one passes tmux's nested-session check even though $TMUX is set.