fix(query): make openkb query safe for non-TTY stdout (closes #34)#45
Open
Litash wants to merge 1 commit intoVectifyAI:mainfrom
Open
fix(query): make openkb query safe for non-TTY stdout (closes #34)#45Litash wants to merge 1 commit intoVectifyAI:mainfrom
Litash wants to merge 1 commit intoVectifyAI:mainfrom
Conversation
…AI#34) prompt_toolkit's print_formatted_text constructs a Win32Output on Windows that demands a real console handle, crashing run_query (stream=True) with NoConsoleScreenBufferError when stdout is a pipe, file, or captured subprocess stream (MCP stdio, redirected output, CI captures). Two complementary changes: 1. Defensive: push the existing _use_color() gate into the _fmt helper in openkb/agent/chat.py so every prompt_toolkit call site -- chat REPL, query streaming, slash-command output -- falls back to plain sys.stdout.write when the output isn't a usable console. 2. UX: auto-disable stream=True in openkb query for non-TTY stdout via a small _stream_to_tty() helper in openkb/cli.py. Non-interactive callers now reach the clean stream=False branch in run_query and get the final answer string instead of an interleave of tool-call lines and answer tokens. The non-stream branch echoes the answer so output is preserved. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
prompt_toolkit's print_formatted_text constructs a Win32Output on Windows that demands a real console handle, crashing run_query (stream=True) with NoConsoleScreenBufferError when stdout is a pipe, file, or captured subprocess stream (MCP stdio, redirected output, CI captures).
Two complementary changes:
Defensive: push the existing _use_color() gate into the _fmt helper in openkb/agent/chat.py so every prompt_toolkit call site -- chat REPL, query streaming, slash-command output -- falls back to plain sys.stdout.write when the output isn't a usable console.
UX: auto-disable stream=True in openkb query for non-TTY stdout via a small _stream_to_tty() helper in openkb/cli.py. Non-interactive callers now reach the clean stream=False branch in run_query and get the final answer string instead of an interleave of tool-call lines and answer tokens. The non-stream branch echoes the answer so output is preserved.