fix: readable CLI output and graceful context-overflow errors in non-TTY runs#51
Merged
Conversation
…TTY runs Two fixes for running `nib --cli` in CI (e.g. GitHub Actions), where stdout is not a TTY: - Spinner: the animated spinner redraws one line with a carriage return every 80ms. Off a TTY the `\r` does nothing, so every frame becomes its own log line and the log fills with hundreds of "thinking" entries. Make the spinner TTY-aware: on a non-TTY it prints each distinct status once (deduplicated), reprinting after tool-call boundaries so progress stays visible. - Errors: a context-window overflow surfaced as a triple-wrapped, opaque "failed to select tool: ... failed to make a decision after 3 attempts: rpc error: ... exceeds the available context size" line. Add humanizeError, which rewrites known backend context-overflow errors (llama.cpp/LocalAI, OpenAI, vLLM phrasings) into a short, actionable message with the token counts, while preserving the original via Unwrap. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
nib --cliin CI (e.g. GitHub Actions) produced unreadable output. Two issues, both stemming from stdout not being a TTY:Spinner flood. The CLI spinner redraws a single line with a carriage return (
\r) every 80 ms. Off a TTY the\rdoes nothing, so every frame lands on its own line — the log fills with hundreds of⠋ thinkingentries.Opaque context-overflow error. When the request exceeded the model's context window, the failure surfaced as a triple-wrapped, cryptic line:
Changes
TTY-aware spinner (
cmd/cli.go): on a TTY, unchanged animated spinner. Off a TTY, it prints each distinct status once (deduplicated), reprinting after tool-call boundaries so progress stays visible. A steady "thinking" state collapses to one line instead of hundreds.humanizeError(chat/errors.go): rewrites known backend context-overflow errors (llama.cpp/LocalAI, OpenAI, and vLLM phrasings) into a short, actionable message with the token counts, e.g.:The original error is preserved via
Unwrapsoerrors.Is/Asstill work. Unrecognized errors pass through unchanged. Applied at the single error surface inSendMessage, so both the CLI and TUI benefit.Tests
cmd/cli_spinner_test.go: non-TTY output contains no\rand deduplicates a repeated status to one line; status reprints across a stop/start boundary.chat/errors_test.go: both backend phrasings (including OpenAI's reversed count order) yield correct request/limit numbers; unwrap chain intact; nil and unrelated errors pass through.🤖 Generated with Claude Code