Skip to content

fix(query): make openkb query safe for non-TTY stdout (closes #34)#45

Open
Litash wants to merge 1 commit intoVectifyAI:mainfrom
Litash:fix/issue-34-fmt-non-tty
Open

fix(query): make openkb query safe for non-TTY stdout (closes #34)#45
Litash wants to merge 1 commit intoVectifyAI:mainfrom
Litash:fix/issue-34-fmt-non-tty

Conversation

@Litash
Copy link
Copy Markdown

@Litash Litash commented May 11, 2026

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.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant