Skip to content

Commit d293089

Browse files
committed
Remove unused and test-only functions
- tui/mouse: drop parse_events (split covers SGR parsing; tests use split) - entry/server: drop ServerView.reset_for_run and ServerView.take_pending (fresh view per run; tests inspect _pending directly) - core/token_estimator: drop is_cjk_char (superseded by _CJK_RE)
1 parent 0134a8b commit d293089

6 files changed

Lines changed: 7 additions & 77 deletions

File tree

‎python_agent_harness/core/token_estimator.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@
1414
from ..session import config
1515
from .models import extract_reasoning
1616

17-
18-
def is_cjk_char(c: str) -> bool:
19-
"""Return True if C is a CJK or full-width character."""
20-
cp = ord(c)
21-
return (
22-
0x3000 <= cp <= 0x9FFF # CJK + kana + punctuation
23-
or 0xF900 <= cp <= 0xFAFF # CJK compat ideographs
24-
or 0xFF00 <= cp <= 0xFFEF # full-width forms
25-
or 0x20000 <= cp <= 0x2FA1F # CJK extensions B-F
26-
)
27-
28-
29-
# The same ranges as `is_cjk_char`, as a single compiled character class.
17+
# The CJK/full-width ranges, as a single compiled character class.
3018
# Scanning for CJK runs in C (the regex engine) instead of a per-character
3119
# Python loop, so large payloads count CJK chars much faster.
3220
_CJK_RE = re.compile(r"[\u3000-\u9fff\uf900-\ufaff\uff00-\uffef\U00020000-\U0002fa1f]")

‎python_agent_harness/entry/server.py‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,6 @@ def cancel_pending(self) -> None:
409409
if state is not None:
410410
state.event.set()
411411

412-
def reset_for_run(self, run_id: str | None) -> None:
413-
"""Re-arm the view for a new run: fresh seq counter, new run_id."""
414-
with self._lock:
415-
self._buffer = []
416-
self._seq = 0
417-
self._sealed = False
418-
self._cancelled.clear()
419-
self.run_id = run_id
420-
self._deltas.reset()
421-
with self._pending_lock:
422-
self._abandoned = False
423-
424412
# -- HeadlessView overrides -------------------------------------------------
425413

426414
def confirm(self, prompt: str) -> bool:
@@ -450,15 +438,6 @@ def ask(self, questions: list[dict]) -> str:
450438
)
451439
return self._wait_answer(state)
452440

453-
# -- test seam ------------------------------------------------------------
454-
455-
def take_pending(self) -> _AskState | None:
456-
"""Detach the pending ask state (test inspection hook)."""
457-
with self._pending_lock:
458-
state = self._pending
459-
self._pending = None
460-
return state
461-
462441

463442
class AgentServer:
464443
"""Request loop over stdin/stdout driving a resident Controller.

‎python_agent_harness/tui/mouse.py‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,6 @@
7070
LEFT_BUTTON = 0
7171

7272

73-
def parse_events(data: bytes) -> list[tuple[int, int, int, str]]:
74-
"""Complete mouse reports in DATA as ``(button, column, row, kind)``.
75-
76-
``kind`` is ``"press"`` for the terminal's ``M`` suffix and
77-
``"release"`` for ``m``. Coordinates are 1-based, exactly as the
78-
terminal sent them.
79-
"""
80-
events = []
81-
for m in _SGR.finditer(data):
82-
events.append(
83-
(
84-
int(m.group(1)),
85-
int(m.group(2)),
86-
int(m.group(3)),
87-
"press" if m.group(4) == b"M" else "release",
88-
)
89-
)
90-
return events
91-
92-
9373
def is_left_click(button: int) -> bool:
9474
"""True for a plain left-button press.
9575

‎tests/core/test_token_estimator.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
context_window_for,
1313
estimate_payload_tokens,
1414
estimate_tokens,
15-
is_cjk_char,
1615
payload_text,
1716
)
1817

@@ -38,7 +37,6 @@ def test_latin_estimate(self):
3837
self.assertEqual(estimate_tokens("abcdefgh"), 2)
3938

4039
def test_cjk_estimate(self):
41-
self.assertTrue(is_cjk_char("中"))
4240
self.assertEqual(estimate_tokens("中文"), 1)
4341
# mixed: 8 latin (2 tok) + 2 cjk (1 tok)
4442
self.assertEqual(estimate_tokens("abcdefgh中文"), 3)

‎tests/entry/test_server.py‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,8 @@ def test_usage_snapshot_shape(self):
897897
def test_confirm_true_and_false(self):
898898
out = io.StringIO()
899899
view = ServerView(out=out, err=io.StringIO(), run_id="r1")
900-
self.assertIsNone(view.take_pending())
900+
with view._pending_lock:
901+
self.assertIsNone(view._pending)
901902
result: dict = {}
902903

903904
def _confirm() -> None:
@@ -992,22 +993,6 @@ def test_ask_timeout_falls_back_unanswered(self):
992993
view = ServerView(out=out, err=io.StringIO(), run_id="r1", answer_timeout=0.2)
993994
self.assertEqual(view.ask([{"question": "q?"}]), "Unanswered")
994995

995-
def test_reset_for_run_renumbers(self):
996-
out = io.StringIO()
997-
view = ServerView(out=out, err=io.StringIO(), run_id="r1")
998-
view.emit_start("p1", [])
999-
view.on_delta("x")
1000-
view.reset_for_run("r2")
1001-
# events before the next emit_start are buffered (pre-start
1002-
# contract), so arm run 2 before emitting again
1003-
view.emit_start("p2", [])
1004-
view.on_delta("y")
1005-
lines = [json.loads(line) for line in out.getvalue().splitlines() if line]
1006-
self.assertEqual([line["seq"] for line in lines], [1, 2, 1, 2])
1007-
self.assertEqual([line.get("run_id") for line in lines], ["r1", "r1", "r2", "r2"])
1008-
self.assertEqual(lines[0]["prompt"], "p1")
1009-
self.assertEqual(lines[2]["prompt"], "p2")
1010-
1011996
def test_answer_without_pending_is_noop(self):
1012997
out = io.StringIO()
1013998
view = ServerView(out=out, err=io.StringIO(), run_id="r1")

‎tests/tui/test_tui_mouse.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def _tool_call_message(tool_id="1", name="Bash", command="ls -la"):
4040
class TestMouseParsing(unittest.TestCase):
4141
def test_parse_sgr_press_and_release(self):
4242
data = b"\x1b[<0;12;7M\x1b[<0;12;7m"
43-
events = mouse_mod.parse_events(data)
43+
events, _, _ = mouse_mod.split(data)
4444
self.assertEqual(events, [(0, 12, 7, "press"), (0, 12, 7, "release")])
4545

4646
def test_parse_ignores_non_mouse_input(self):
4747
"""Typed text and other escapes never look like a click."""
48-
self.assertEqual(mouse_mod.parse_events(b"hello"), [])
49-
self.assertEqual(mouse_mod.parse_events(b"\x1b[A"), [])
48+
self.assertEqual(mouse_mod.split(b"hello")[0], [])
49+
self.assertEqual(mouse_mod.split(b"\x1b[A")[0], [])
5050

5151
def test_parse_large_coordinates(self):
5252
"""SGR (1006) reports columns/rows beyond the X10 limit."""
53-
events = mouse_mod.parse_events(b"\x1b[<0;300;120M")
53+
events, _, _ = mouse_mod.split(b"\x1b[<0;300;120M")
5454
self.assertEqual(events, [(0, 300, 120, "press")])
5555

5656
def test_is_left_click_excludes_wheel_and_drag(self):

0 commit comments

Comments
 (0)