← Back to Pull requests

fix(cli): migrate to bubbletea v2 to drop the init-time terminal probe #254

Closed
unknown closed this pull request without merging on Sep 21, 2026 02:07 UTC
View on GitHub
unknown unknown commented on Sep 20, 2026 06:07 UTC
Author

Fixes #250.

Every openapi invocation, including --version and spec lint, stalls for about five seconds and leaks ESC ] 11 ; ? ESC \ ESC [ 6 n into stdout when stdout is a terminal but stdin is not (CI log capture, script, expect, editors that shell out). The cause is bubbletea v1's tea_init.go, whose init() calls lipgloss.HasDarkBackground() eagerly so the terminal answers the background-colour query (OSC 11) before any Program takes over stdin. That runs before main, so it fires for every subcommand even though only spec explore and spec snip ever draw a TUI, and when no answer comes back termenv waits out its five-second OSCTimeout. The comment on that init() says the workaround would be removed in v2.

It was. Bubble Tea v2 has no init-time probe, lipgloss v2 has no package-level renderer and no background detection, and muesli/termenv (which sent the query) drops out of the dependency graph entirely. This PR moves cmd/openapi to charm.land/bubbletea/v2, charm.land/lipgloss/v2 and charm.land/bubbles/v2. Only the cmd/openapi module depends on charm, so the root module is untouched.

API changes applied

  • Import paths: github.com/charmbracelet/{bubbletea,lipgloss,bubbles} become charm.land/{bubbletea,lipgloss,bubbles}/v2 (the v2 modules declare the charm.land vanity path; the github.com/.../v2 form does not resolve).

  • Model.View() string becomes Model.View() tea.View, wrapping the rendered string with tea.NewView.

  • tea.WithAltScreen() program option is gone; the explore and snip views now set AltScreen = true on the returned tea.View. The file-path input prompt never used the alt screen and still does not.

  • tea.KeyMsg is now an interface; the models match tea.KeyPressMsg and switch on msg.String() ("enter", "esc", "ctrl+c") instead of msg.Type constants.

  • lipgloss.Color is now a function returning color.Color, so the method colour map and GetMethodColor use color.Color and call lipgloss.Color(...) per entry.

  • bubbles textinput: ti.Width = 60 becomes ti.SetWidth(60).
  • Space key

    In v1, KeyMsg.String() for the space bar returned " ". In v2 it returns "space", so the fold/select toggle in model.go now matches case "space":. Every other key the explorer handles (q, ?, esc, j/k, arrows, ctrl+d/ctrl+u, g/G, enter, a/A) keeps its v1 string. The only configured selection action key is w, so no ActionKey config needed changing, but any future ActionKey{Key: " "} would have to be written as "space". New tests in model_keys_test.go drive Update with tea.KeyPressMsg{Code: tea.KeySpace} and cover the fold toggle, the selection toggle, cursor movement, the action key, and the quit keys.

    Compatibility

  • Colour output: lipgloss v2 emits truecolor and leaves downsampling to Bubble Tea's renderer, whereas v1 downsampled itself based on the detected profile. On 256-colour or 16-colour terminals the TUI palette may render slightly differently. Non-TUI commands are unaffected.

  • The TUI still emits its own terminal queries (synchronised output, kitty keyboard protocol, modifyOtherKeys) when spec explore or spec snip actually runs. Those are scoped to the interactive session and no longer happen at process start.

  • .github/dependabot.yml lists only / and jsonschema/oas3/tests under gomod, so the charm dependencies in cmd/openapi will not be bumped automatically. Adding cmd/openapi to that directories list is a possible follow-up.

  • golangci-lint's exhaustive finding on the old tea.KeyType switch in input.go goes away because the switch is now on strings. No new lint findings are introduced; the remaining hits in the touched files are pre-existing on main.
  • Testing

    Run from cmd/openapi (the root ./... pattern does not descend into this nested module, so mise test at the root does not exercise it):

    cd cmd/openapi
    go build ./...
    go vet ./...
    go test -race -count=1 ./...
    go mod tidy && git diff --exit-code go.mod go.sum   # tidy is a no-op
    gofmt -l .                                          # only commands/overlay/validate.go, pre-existing on main
    cd ../.. && golangci-lint run ./cmd/openapi/...     # 48 findings, all pre-existing on main (main has 49)
    

    Cross-compiles cleanly for windows/amd64, linux/amd64, linux/arm64 and darwin/amd64.

    Reproduction of the issue, stdout on a pty and stdin closed, before (main at e70ae27) and after this branch:

    $ printf 'openapi: 3.1.0\ninfo:\n  title: t\n  version: "1"\npaths: {}\n' > /tmp/spec.yaml
    $ /usr/bin/time -p script -q /dev/null ./openapi spec lint /tmp/spec.yaml < /dev/null | cat -v | head -1
    

    Before:

    ^D^H^H^[]11;?^[\^[[6nLinting OpenAPI document: /tmp/spec.yaml^M
    real 5.06
    

    After:

    ^D^H^HLinting OpenAPI document: /tmp/spec.yaml^M
    real 0.57
    

    $ /usr/bin/time -p script -q /dev/null ./openapi --version < /dev/null | cat -v | head -1
    

    Before:

    ^D^H^H^[]11;?^[\^[[6nv0.0.0-20260920052111-e70ae27ae5d7^M
    real 5.02
    

    After:

    ^D^H^Hv0.0.0-20260920060402-72adb6c288cd^M
    real 0.03
    

    The leading ^D^H^H in both is macOS script echoing the EOF from /dev/null and is not produced by the binary. The ^[]11;?^[\ (OSC 11 background query) and ^[[6n (cursor position report) are gone in the after output, and the five-second stall with them.

    $ strings ./openapi | grep -c HasDarkBackground
    

    Before: 9. After: 0.

    TUI smoke test on a three-operation spec, driven through a pty with a 100x30 window: spec explore enters the alt screen (ESC[?1049h), draws the header and the operation list, j moves the highlight to the second row, space unfolds that row (shows Summary: List users and Operation ID: listUsers), a second space folds it again, and q leaves the alt screen (ESC[?1049l) and exits 0. The main build behaves identically in the same harness.

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Fixes #250 by migrating cmd/openapi to Bubble Tea v2. Bubble Tea v1 ran a terminal background-color probe during init(), so every openapi command (even --version and spec lint) stalled about five seconds and leaked escape sequences when stdout was a terminal but stdin was not. v2 has no init-time probe; the TUI only queries the terminal when spec explore or spec snip runs.

    What changed

  • Moves cmd/openapi to charm.land/bubbletea/v2, charm.land/lipgloss/v2, and charm.land/bubbles/v2; only this module depends on charm, so the root module is untouched.

  • Views return tea.View with AltScreen = true instead of using tea.WithAltScreen(), and key handling matches tea.KeyPressMsg strings where space is "space".

  • Adds tests that drive every explorer key handler through Update, including cursor viewport-bounds assertions.
  • Compatibility

  • lipgloss v2 leaves color downsampling to Bubble Tea's renderer, so the TUI palette may render slightly differently on 256- or 16-color terminals.

  • Action keys configured as " " must be written as "space".
  • <sup>Written for commit 8f742783ba5aeab5ac90f914eedc6d7dda51b15d. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/speakeasy-api/openapi/pull/254?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: david-long1 Review duration: 1199m
    All Vouch review confidence checks passed
    Residual risk 0.32 = Change Risk (0.75) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #254"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.6% · Safe to merge
    31.6%