Skip to content

Commit 8ddebac

Browse files
committed
fix(tui): address CodeRabbit review findings
- app.py: detect AGENTS.md/CLAUDE.md in the session work_dir (awaiting the async HostPath.exists) instead of process cwd, so the /init tip is correct when cwd differs from the session path. - color_utils.py: replace EN DASH with ASCII hyphen in the luma docstring. - slash.py: clarify the recaps config-flag guidance (--config vs --config-file). - terminal_background.py: debug-log swallowed OSC11 probe failures instead of silently degrading, per the exception-handling rule. - tests: annotate the autouse fixture return type; tighten the thinking-status metadata assertion to validate the token-count block, not just any paren.
1 parent 33a2f8a commit 8ddebac

6 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/pythinker_code/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,9 @@ async def run_shell(
874874
# Repos without agent guidance benefit most from /init — surface the
875875
# tip emphasized (WARN renders bold) only when neither file exists.
876876
try:
877-
work_dir = Path.cwd()
878-
has_agent_docs = (work_dir / "AGENTS.md").exists() or (work_dir / "CLAUDE.md").exists()
877+
has_agent_docs = (
878+
await (work_dir / "AGENTS.md").exists() or await (work_dir / "CLAUDE.md").exists()
879+
)
879880
except OSError:
880881
has_agent_docs = True
881882
if not has_agent_docs:

src/pythinker_code/ui/color_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def blend(fg: RGB, bg: RGB, alpha: float) -> RGB:
3939

4040

4141
def luma(rgb: RGB) -> float:
42-
"""ITU-R BT.601 perceived brightness in the 0255 range."""
42+
"""ITU-R BT.601 perceived brightness in the 0-255 range."""
4343
return 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]
4444

4545

src/pythinker_code/ui/shell/slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def print_settings_table() -> None:
12931293
if config_file is None:
12941294
console.print(
12951295
f"[{_t_set.warning}]Toggling recaps requires a config file; "
1296-
f"restart without --config text to persist settings.[/]"
1296+
f"restart without --config (or use --config-file) to persist settings.[/]"
12971297
)
12981298
return
12991299
try:

src/pythinker_code/ui/terminal_background.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from __future__ import annotations
1212

13-
import contextlib
13+
import logging
1414
import os
1515
import re
1616
import select
@@ -24,6 +24,8 @@
2424
if TYPE_CHECKING:
2525
from pythinker_code.ui.theme import ThemeName
2626

27+
_log = logging.getLogger(__name__)
28+
2729
_OSC11_QUERY = "\x1b]11;?\x1b\\"
2830
# Reply shape: ``ESC ] 11 ; rgb:RRRR/GGGG/BBBB`` terminated by BEL or ST.
2931
# Components are 1-4 hex digits each (XParseColor scaling).
@@ -81,7 +83,8 @@ def _probe_uncached(timeout: float) -> RGB | None:
8183

8284
try:
8385
old_attrs = termios.tcgetattr(fd)
84-
except (termios.error, OSError):
86+
except (termios.error, OSError) as exc:
87+
_log.debug("OSC11 probe failed while reading terminal attrs", exc_info=exc)
8588
return None
8689
try:
8790
tty.setcbreak(fd)
@@ -102,13 +105,16 @@ def _probe_uncached(timeout: float) -> RGB | None:
102105
if "\x07" in buf or "\x1b\\" in buf:
103106
break
104107
return parse_osc11_response(buf)
105-
except (OSError, ValueError):
108+
except (OSError, ValueError) as exc:
109+
_log.debug("OSC11 probe failed during probe I/O", exc_info=exc)
106110
return None
107111
finally:
108112
# Never let restore failure escape — a raised tcsetattr here would
109113
# both crash startup and leave the terminal in cbreak mode anyway.
110-
with contextlib.suppress(termios.error, OSError):
114+
try:
111115
termios.tcsetattr(fd, termios.TCSADRAIN, old_attrs)
116+
except (termios.error, OSError) as exc:
117+
_log.debug("OSC11 probe failed to restore terminal mode", exc_info=exc)
112118

113119

114120
def probe_terminal_background(timeout: float = _PROBE_TIMEOUT_S) -> RGB | None:

tests/ui_and_conv/test_output_guards.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
from collections.abc import Iterator
6+
57
import pytest
68

79
from pythinker_code.ui.shell.components import (
@@ -18,7 +20,7 @@
1820

1921

2022
@pytest.fixture(autouse=True)
21-
def _isolated_registry():
23+
def _isolated_registry() -> Iterator[None]:
2224
clear_tool_renderers()
2325
yield
2426
clear_tool_renderers()

tests/ui_and_conv/test_streaming_content_block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ def test_thinking_status_line_uses_compact_activity_metadata():
261261
console = Console(record=True, width=120, color_system=None)
262262
console.print(block.compose())
263263
output = console.export_text()
264-
assert "Thinking…" in output
265-
assert "(" in output and ")" in output
264+
assert "Thinking… (" in output
265+
assert "tokens" in output
266266
assert "esc to interrupt" not in output
267267

268268

0 commit comments

Comments
 (0)