Repository navigation
Conversation
e70fa46 to
93defd8
Compare
✅ Integration test reportCommit: 973ece0
Top 6 slowest tests (at least 2 minutes):
|
|
/review |
93defd8 to
60a6b63
Compare
60a6b63 to
4b39c09
Compare
4b39c09 to
2c519b9
Compare
|
/review |
There was a problem hiding this comment.
Automated review at 2c519b9. Each finding was verified against the code.
Not ready yet: part of the automated review did not complete.
This PR migrates the TUI stack from charmbracelet v1 to charm.land v2 (bubbletea, bubbles, lipgloss, huh) and addresses three regressions the swap would otherwise introduce: leftover terminal replies, Shift+Enter handling, and huh form plumbing. The migration is thorough, with extensive test updates, golden file changes, and a new reply guard mechanism. Two minor improvements survived verification.
2c519b9 to
c84e2ff
Compare
c84e2ff to
dfd06f0
Compare
dfd06f0 to
ac1e69e
Compare
|
/review |
There was a problem hiding this comment.
Automated review at ac1e69e. Each finding was verified against the code.
Not ready yet: part of the automated review did not complete.
This PR moves the TUI stack to the charm.land v2 modules. It routes huh forms through cmdio.RunHuhField/RunHuhForm, adds a reply guard to NewTeaProgram so terminal answers don't leak to the shell, and maps Shift+Enter to Enter. The port looks careful and the pins back it up. One real behavior gap remains: the guard keeps delivering non-key messages after quit, so a draining pager keeps fetching and printing. Smaller items: two dead cmdIO fallbacks that break the no-speculative-fallback rule, a mismatched background probe in the selftest, and a changelog entry that lists too few TUIs.
…atabricks#7884) ## Changes Halve the agent rules: 66 KB → 33 KB of AGENTS.md + `.agents/rules/`. The rules that are always loaded or loaded on every Go edit shrink the most: | Context loaded | Before | After | |---|---|---| | Always (AGENTS.md) | 12.2 KB | 6.1 KB | | Editing a `.go` file (+ style-guide-go, comments) | 23.5 KB | 9.7 KB | | Editing a `_test.go` file (+ testing) | 45.8 KB | 17.5 KB | | Editing acceptance outputs (+ testing, auto-generated-files) | 38.5 KB | 16.4 KB | Skills are unchanged: they load only when invoked. What was removed, and why: - **Already enforced by `./task lint`** (the agent gets the same message from the linter): - integer `range`, builtin `min`/`max` (modernize) - loop-variable capture (copyloopvar) - `os.Getenv`, `sync.Once` (forbidigo) - `context.Background()` (gorules) - `t.Context()` in tests (usetesting) - stdlib `log` (depguard) - `%w` wrapping (errorlint) - error-string punctuation (staticcheck ST1005) - copying `config.Config` (govet copylocks) - **Wrong or stale:** - `errors.As` was recommended, but forbidigo bans it (the tree has 0 `errors.As` calls vs 231 `errors.AsType`). - `isResourceGone` doesn't exist. - `libs/structpath` has moved to `libs/structs/structpath`. - "consult the Makefile": there is no Makefile. - The `out.test.toml` old-format migration rule is dead: 0 files are left in that format. - "Use Python 3.11" also applied to `python/`, which supports `>=3.10`. - The `databricks_template_schema.json` "reference" was an outdated copy of dbt-sql's schema. It described a description convention the real file no longer uses, and it had a typo. It is replaced by pointers to the real templates and to `libs/jsonschema/extension.go`. - template-versions.md hardcoded how many pins each template has. The counts were wrong; the grep in the same rule is what the agent should rely on. - **Rules that produced wrong review feedback:** - "Each source file should have a corresponding test file": 38% of source files have none, and the rule contradicts acceptance-tests-first. The reviewer bot used it to request tests for cobra wiring, and those requests were ignored: databricks#7688 (comment), databricks#7742 (comment) - "Place tests in the same package but with a `_test` suffix": 1050 test files use the internal package and 231 use `_test`. The rule led to an invented `_internal_test.go` convention that the author rejected: databricks#7847 (comment) - "Add `.databricks` to `Ignore`": `acceptance/script.cleanup` already removes it. This produced a wrong `[blocking]` comment: databricks#7846 (comment) - "Define magic strings as named constants, even if short": reviewers push back on single-use constants (databricks#5844 (comment), databricks#6204 (comment), databricks#6149 (comment)). - **Generic guidance current models already follow:** - return early - `switch` vs `if/else` - empty-struct context keys - table-driven tests - shared test constants - Go doc comment format - constructor parameter structs - "don't explain each test case in your responses" - debug prints (pr-checklist already covers them) - the GOOD/BAD preamble - **Repetition:** - `Cloud = true` runs locally too: this was explained 5 times and is now explained once in AGENTS.md and once in testing.md. - `integration/` is deprecated: stated 4 times. - "Don't edit generated outputs": stated 4 times across testing.md and auto-generated-files.md. - The `print_requests.py`/`jq` guidance was 3 overlapping rules and is now 1. - The long GOOD/BAD examples were dropped where the rule sentence already says it. Clarified: - `os.Exit`: the rule now says how `TestMain` should exit. The bot had suggested `os.Exit(m.Run())`, against this same rule: databricks#7595 (comment) - Comments: existing comments may be updated when your change makes them wrong. ## Why The rules were mostly mined from review history in databricks#5078. That PR's follow-up promised a slim-down that never came (databricks#4882), and token cost had already come up in review (databricks#6584). Every byte of AGENTS.md and the Go/test rules is paid on most turns, and rules that are wrong or that the linter already enforces either crowd out the useful ones or become review noise. I checked the 98 comments from review-oss-bot and the human pushback since 2026: the rules that went wrong are the ones removed above. The acceptance-test rules that came from real agent failures (`Cloud`, `EnvMatrix`, TOML dotted keys, `musterr`/`errcode`, `print_requests.py`, testserver over `[[Server]]`, GET-response projection) are kept, just shorter. ## Tests `./task check-agents-setup` and `./task checks` pass. Every path, helper, task and identifier still mentioned was checked against the tree. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
pardis-beikzadeh-db
left a comment
There was a problem hiding this comment.
Review limited to cmd/air/.
ac1e69e to
5c488ec
Compare
bb98437 to
0220739
Compare
0220739 to
66e7ddf
Compare
…huh) Moves the CLI's TUI code to charm.land/bubbletea/v2, bubbles/v2, lipgloss/v2 and huh/v2, with the behaviour that v1 gave callers kept or deliberately changed and pinned. Swap - Models handle key events through teainput; tea.HideCursor is gone (Bubble Tea hides the cursor while a program runs), so the select modes golden loses one "?25 reset". - Color: the program's profile comes from the stream's cmdio.Renderer (WithColorProfile), floored at ANSI for template helpers, so TERM unset, CI and CLICOLOR=0 keep v1's depth. - tableview.RunWithOptions sends its window size with tea.WithWindowSize, so the first frame is drawn at that size. - cmd/selftest/tui ports to v2: keys prints the message and the decoded event side by side; profile and huh read the background through lipgloss.HasDarkBackground. Quit guard - cmdio.NewTeaProgram defers quitting, on a terminal, until the terminal answers the cursor position request sent at quit time. Terminals answer in order, so the answers to the startup queries are read before the program exits, and nothing is left at the shell prompt. The wait is bounded at 2 s. Shift+Enter - teainput.KeyName reports shift+enter as enter, for terminals that enable the kitty keyboard protocol. huh - Forms go through cmdio.RunHuhField or RunHuhForm, which run with the context's input, stderr, and the stderr color profile. huh's WithProgramOptions replaces its defaults, so the input and output are passed explicitly. The reply guard is not installed for huh: it needs to inject a message when the terminal does not answer, and a huh program does not expose Send. Golden changes are listed in the stack PR body, one per behaviour. Pins that need a terminal have a TTY variant (TestQueriesPin_PromptQuitBeforeRepliesTTY, termtest StdinTTY), and TestNewTeaProgramGuardsTerminalInput covers the constructor with a faked terminal. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The timeout no longer outlives a program that got its cursor report. The timeout test drives the guard the way the event loop does instead of calling filter from the timer goroutine. Co-authored-by: Isaac <no-reply@databricks.com>
v2's Renderer.Writer always downsamples, so with CI or CLICOLOR=0 on a terminal it stripped the basic ANSI colors cmdio's helpers emit, which v1 passed through. The selftest swatches now go through the renderer's writer too, so NO_COLOR and CLICOLOR=0 apply to them. Also narrow the kitty keyboard and terminal reply changelog entries to what the change does. Co-authored-by: Isaac <no-reply@databricks.com>
The pager's quit waits for the terminal's answer, so a fetch in flight could still print its page and start another fetch; it now drops what lands after quit, as v1 did when Quit ended the program at once. The selftest huh and profile probes query the background on the stream they report on. The huh and paged template options use fromContext: SupportsColor already needs a cmdIO there. The reply guard tests that read the program's input back skip Windows, where bubbletea's reader can take those bytes first. Co-authored-by: Isaac <no-reply@databricks.com>
bubbletea v2 draws nothing at width 0 and can't detect a pipe's size, so SetupTest sets the size NewTestIO already does. v2 also redraws only the cells that change, so a validation message that shares its start with the previous one never appears whole in the byte stream; the cmd/auth tests wait for those messages on the screen instead. Co-authored-by: Isaac <no-reply@databricks.com>
bubbletea v2 redraws only the cells that change, so typed "ab" can arrive as "a" and then "b" inserted before the cursor, and never appear whole in the byte stream. TestPrompt_ShiftEnterSubmits timed out that way on Linux and macOS CI. WaitFor now also succeeds once the text is on the screen. Co-authored-by: Isaac <no-reply@databricks.com>
The selftest probe now runs its field through RunHuhField, as the prompts do, which leaves RunHuhForm with one caller. Co-authored-by: Isaac <no-reply@databricks.com>
66e7ddf to
973ece0
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
Reviewed 9671839d2590…973ece08d8cf with all five review sources completed. I reproduced two blockers in the migrated runtime:
-
[blocking] The quit barrier can precede the keyboard query (
teaprogram.go:74–77). With a quit key buffered before the first render tick, the actual output order isDECRQM 2026,DECRQM 2027, CPR, kitty query. Bubble Tea flushes its query buffer before its renderer, so an ordered CPR reply releases the guard while the later kitty reply is still pending. My publicNewTeaProgramprobe answers every query in order and leaves"\x1b[?0u"unread after guarded exit. Queue the barrier after the startup renderer queries have been flushed, and add an early-quit test with the kitty answer delayed separately. The current golden waits for the prompt's first frame before typing, so it misses this ordering. -
[blocking] The spinner has no dimensions on the supported MSYS2 pipe path (
spinner.go:169–174). Without ConPTY, stderr is a named pipe: cmdio enables interactive spinner output, but Bubble Tea has nottyOutputto resize from. Production has noteaWindowSize, so v2 renders at width zero and loses the spinner/progress text. Running the same productionNewIO→NewSpinnerprobe against a non-console output marked withFakeTTYprintsUploadingon base and no suffix on this head. The Windows initialization path likewise leavesttyOutputunset for named pipes. Supply usable dimensions for this path and cover it with the existing Windows pipe test machinery. Native Windows execution was not available here.
Non-blocking findings:
- [nice to have] Color parity: the ANSI floor in
stderrWriterrevives v2 lipgloss colors as well as preserving raw helper colors. With processCLICOLOR=0and no force, the same exportedprompt.PrintAnswered(ctx, "Name", "hello")probe is plain on base and emits SGR 37/91 here. Huh also uses this floor although its view has no cmdio template helpers. Render library styles at their original unfloored profile before mixing them with helper SGR. Raised by three sources. - [nice to have] Windows environment lookup:
termenvEnviron.Getenvusesk == key; the previous processos.Getenvlookup is case-insensitive on Windows. A variable stored asclicolor=0orci=1is now missed. Preserve native lookup semantics (or keep the real process environment for production). Raised by two sources; source-verified, without a Windows runtime. - [nice to have] Huh input paths: with
TERM=dumb, huh bypasses Bubble Tea, so the program options do not set the form's accessible input/output. The newTestRunHuhFieldUsesContextIOreads process stdin and fails with an empty value instead ofhello. Set the form's own input/output too. Separately, a kitty Shift+Enter sent throughRunHuhFielddoes not submit; a delayed!+ plain Enter returnshello!, while plain Enter returnshello. The normalization inKeyNamenever reaches these fields. - [nice to have] Isolate the query-test environment: inherited
SSH_TTYwithTERM=xterm-256colormakes Bubble Tea omit both DECRQM queries and fails these goldens. An explicit test program environment fixes the mismatch; setting only cmdio's context environment does not control Bubble Tea. Raised by two sources. - [nit] Test helpers:
Press("alt+ctrl+h")andPress("f1")worked on base and now panic; parse modifier prefixes independently of order and retain the named-key coverage. Also, the localsentMsgsclosure inteaprogram_test.go:25conflicts with the explicit Go rule requiring a regular function for a repeated operation.
Required CI checks pass. The optional regression jobs were cancelled without running steps. The affected cmdio race suite passes with a deterministic terminal environment; the broader cmd/air race failure at list_index_test.go:51 also reproduces on base.
I accepted the explicitly documented spinner/log interleaving, huh background, and picker/form reply-guard limitations rather than repeating them. The two blockers above are additional failures outside those documented tradeoffs.
Changes
Moves the TUI stack to
charm.land/bubbletea/v2,bubbles/v2,lipgloss/v2andhuh/v2, and fixes three things the swap would otherwise regress. The last commit of the stack; the earlier PRs carry the rest of the work.The swap
teainput;tea.HideCursoris gone (bubbletea hides the cursor while a program runs), so the select modes golden loses one?25 reset.WithColorProfile, floored at ANSI for template helpers).colorDepthstill uses termenv, soTERMunset,CI,CLICOLOR=0,TERM=screenand tmux+truecolor keep v1's depth.LogStringgets the same floor. v2'sRenderer.Writeralways downsamples, so withCIorCLICOLOR=0on a terminal it would strip the basic colors cmdio's helpers emit, which v1 passed through (cmdio: strip styles from LogString output on a color-less stderr #7738 promises to keep them).selftest tui colors --lipgloss --stream stdout|stderrwrites its swatches through the renderer's writer. v2 styles render full color by themselves, so without itNO_COLORandCLICOLOR=0did not apply to them.tableview.RunWithOptionssends its window size withtea.WithWindowSize, so the first frame is drawn at that size (v2 renders before a sent message lands).huh.ThemeFunc; huh passes it the background it knows. Open: huh never learns it on v2, see Known issues.cmd/selftest/tuiports to v2 (keysprints the raw v2 key next to the decoded event;huhwraps the theme to report the background huh handed it, with no query of its own;profile --query-backgroundqueries each stream's terminal throughlipgloss.HasDarkBackground).Fix 1: leftover terminal replies
bubbletea v2 sends queries at startup (DECRQM 2026 and 2027, kitty keyboard flags). A program that quits before the terminal answers left those answers for the shell prompt.
cmdio.NewTeaProgramnow defers the quit, on a terminal only, until the terminal answers a cursor position request sent at quit time. Terminals answer in order, so the earlier answers have been read by then.This applies to every quit of a guarded program (prompts, selection lists, the pager, the table viewer and
databricks air's list), not only when replies are missing. Each quit costs one terminal round trip: milliseconds locally, one RTT over SSH. If the terminal never answers, the quit goes ahead after 2 s. Keys typed or pasted during the wait are discarded, because the model has already quit.Fix 2: Shift+Enter
v2 enables the kitty keyboard protocol, so terminals that report Shift+Enter separately (Ghostty, kitty, WezTerm) send it as its own key.
teainput.KeyNamemapsshift+entertoenter, so prompts and selection lists submit on it.Fix 3: huh forms
Forms go through
cmdio.RunHuhField(19 call sites inlibs/apps/prompt,cmd/apps,cmd/aitools, and the selftest probe). They run with the context's input, stderr and the stderr colour profile. huh'sWithProgramOptionsreplaces its defaults, so input and output are passed explicitly. Not covered: the reply guard. It has to inject a message if the terminal never answers, and a huh program does not exposeSend, so a missed answer would hang the quit. A huh form can still leave a late reply on the shell prompt after a quick quit; that is open.Rebase onto main: the aitools pickers
mainadded pickers that run a huh form in their own bubbletea program so that Esc cancels (cmd/aitools/install.gopickerModel, used byaitools installandaitools mcp add/removeinmcp_pickers.go). They are ported as they are:pickerModelmatchestea.KeyPressMsgEsc, returns atea.Viewthat reports focus (huh v2'sRundoes the same), andrunPickerstill draws on stderr without the context. So, like the huh forms above, they skip the reply guard, and their colour depth comes from bubbletea's own detection rather than cmdio's. Their tests useteainput.PressandView().Content.Pager quit while a page loads
The pager's quit waits for the terminal's answer like every guarded quit. A fetch still in flight (for example after Enter to drain, then
q) could print its page and start another fetch, which is another API call, in that wait. The pager now drops whatever lands after quit, as v1 did when Quit ended the program at once (TestPagerModelDropsBatchAfterQuit).Changelog:
.nextchanges/cli/kitty-keyboard.md,shift-enter.mdandterminal-replies.md.terminal-replies.mdalso states the huh limitation.Why
v2 changes the key, cursor, colour and program APIs; the swap has to keep v1's visible behaviour except where a change is deliberate and pinned. The three fixes address regressions that the swap would otherwise ship.
Tests
go build ./..., golangci-lint (0 issues), gofmt clean.TERM=xterm-256color go test -race -count=3 ./libs/cmdio/...passes.libs/tableview,libs/apps/...,cmd/air,cmd/apps,cmd/fs,cmd/aitools,cmd/selftest/...,internal/buildpass.go test ./acceptance/...) passes.TestLogStringKeepsHelperColorsWhenProfileIsAscii(CIandCLICOLOR=0),TestRunHuhFieldUsesContextIO, and the reply guard tests (the timeout is stopped once the cursor report arrives).GOOS=windows go vet ./libs/cmdio/...andGOOS=darwin go vet ./libs/cmdio/...pass.keys,profile,colors --lipgloss,pager,table,huh,prompt,select,spinner): all exit 0 with the expected output.Golden changes (pins), against the previous branch
Fourteen pin groups change, all intended:
TestModesPin_{Prompt,Select,Pager}/{enter,ctrl-c},TestModesPin_Spinner: v2 sets modifyOtherKeys 2 and kitty push 1 and undoes both on exit; the mouse-mode resets are gone (v2 never sets those modes); select no longer toggles?25twice.TestKeysPin_{Prompt,Select}ShiftEnter/{kitty,modifyOtherKeys}: Shift+Enter submits (Value: xy,zleft unread; the select clears its screen).TestKeysPin_PromptBracketedPasteWithNewline: the screen keeps✔ Value: aaboveb█.TestQueriesPin_PromptQuitBeforeRepliesandTestQueriesPin_SelectQuitBeforeReplies: pipes never install the guard, so these pins now record v2's queries and the unguarded leftover.TestQueriesPin_PromptTerminalAnswersAtOnce: v2's three startup queries are in the golden.TestQueriesPin_PromptUnsolicitedBackgroundReply: the late OSC 11 reply is consumed; the value isab, notab11;rgb:….TestQueriesPin_PromptQuitBeforeRepliesTTY(stdin poses as a terminal through the new termtestStdinTTYoption). The guard holds the quit for the cursor report; leftover is(none).Unchanged and passing: the pager's first-page spinner pins (
TestPagerPin_SpinnerDuringFirstPageandTestPagerPin_EnterDrainsRemainingPagesstill show several frames), the colour pins, and the Alt pins from #7741. The colour pins cover cmdio's color decisions on a pipe, not a real terminal's depth; see the manual colour check.Test-only changes
libs/cmdio/teaprogram_test.go:TestNewTeaProgramGuardsTerminalInputrunsNewTeaProgramwith a faked terminal. It finishes in about 100 ms.abcan arrive asa, thenbinserted before the cursor). termtest'sWaitFornow also succeeds once the text is on the emulated screen, and thecmd/authtests wait for validation messages withWaitForScreen.cmdio.SetupTestsets the same window size asNewTestIO: v2 draws nothing at width 0 and can't detect a pipe's size. Thecmd/rootprompt tests need it.TestGuardedProgramConsumesLateReplies,TestNewTeaProgramGuardsTerminalInput) skip Windows: bubbletea's input reader can outlive the program there and take those bytes first, the same reason the leftover pins skip Windows.Known issues
LogStringinterleave on v2.LogStringwrites to the terminal while a spinner's renderer is drawing, so the first frame can land before the log line (*spinner started, or* Workingspinner started). Under eight parallel-racecopies ofTestColorPin_Spinnerwith-count=25, v2 failed 13 times across 6 of 8 copies; v1 failed zero times. Fixing it means routingLogStringthrough the active program, which has a message-loss window at teardown. Not in this PR.tea.RequestBackgroundColor(itsInitrequests only the window size) and bubbletea v2 queries the background only on request, so the appkitThemeFuncis always called withisDark=false. Checked with a form run throughRunHuhFieldunder a pipe: the theme was called 21 times, all light, and no OSC 11 was written; a model that requests the colour under the same I/O does write it. On v1 termenv queried the background for the theme'sAdaptiveColor. The only colour that depends on it is the blurred button:#a1a1aainstead of#52525bon a dark terminal.selftest tui huhshows this asdark_background=false. Possible fixes: run forms under cmdio's own program with anInitthat requests the background (which would also let the reply guard cover forms), or query once before the form starts. Open.databricks appsordatabricks aitoolscan still leave a terminal answer such as^[[?2026;2$yat the shell prompt. This is a known limitation of this PR, documented oncmdio.RunHuhFieldand in the changelog.Manual checks on real terminals
Run each with the v1 build (
main, or #7688 for theselftest tuicommands) and with this build.databricks selftest tui prompt, typexy, Shift+Enter,z, Enter. v2:Entered: xy(Shift+Enter submits). Record what v1 prints: without the kitty keyboard protocol these terminals usually send a plain Enter.databricks selftest tui prompt, typeaband Enter at once, then look at the shell prompt. Both: nothing left over, such as^[[?2026;2$y. v1 sends no such queries; v2 waits for the answers before it exits.databricks selftest tui prompt &,kill -TERM %1, thenstty -ain the shell. Open issue: v2 leaves kitty keyboard and modifyOtherKeys on untilreset, as v1 leaves raw mode.databricks selftest tui profileanddatabricks selftest tui colors --lipgloss, withTERMunset,CI=1,CLICOLOR=0,TERM=screen, and tmux withCOLORTERM=truecolor. The depth must match v1's. With both stdout and stderr on a terminal,CI=1 databricks selftest tui colorsmust show the helper colors, as on v1.databricks selftest tui promptunder a terminal that does not answer OSC 11 (for examplescript): the prompt should appear at once, and typed keys are kept.databricks selftest tui pager --items 30 --delay-first 4s: the spinner animates during the first fetch, then the first page and the prompt.databricks selftest tui table --rows 50,/, type text, Alt+F, paste, Enter,q: noalt+for pasted[text]in the search.databricks selftest tui huh --field confirm, on a dark and a light background. v1:dark_backgroundand the blurred-button colour match the background. v2, until the known issue is fixed:dark_background=falseon both, blurred button#a1a1aa.profile --query-backgroundshows what the terminal answers.This pull request and its description were written by Isaac.