Private
Public Access
0
0
This commit is contained in:
2026-06-06 00:40:07 -04:00
parent 053f5d867a
commit e670fc1c3e
6 changed files with 60 additions and 102 deletions
-29
View File
@@ -1,29 +0,0 @@
"""Minimal reproducer for the auto_switch_sim GUI crash."""
import sys
import time
import os
sys.path.insert(0, 'C:/projects/manual_slop')
sys.path.insert(0, 'C:/projects/manual_slop/src')
from src.api_hook_client import ApiHookClient
client = ApiHookClient()
if not client.wait_for_server(timeout=15):
print('FAIL: server not up')
sys.exit(1)
print('OK: server up')
print('Step 1: click btn_reset')
client.click('btn_reset')
time.sleep(1.0)
print('Step 1 done, status=', client.get_value('ai_status'))
print('Step 2: set_value current_provider gemini_cli')
client.set_value('current_provider', 'gemini_cli')
time.sleep(1.0)
print('Step 2 done')
print('Step 3: set_value gcli_path')
mock_path = os.path.abspath('tests/mock_concurrent_mma.py')
client.set_value('gcli_path', '"' + sys.executable + '" "' + mock_path + '"')
time.sleep(1.0)
print('Step 3 done')
+27 -33
View File
@@ -1,3 +1,4 @@
import difflib
import shutil import shutil
import os import os
@@ -8,8 +9,8 @@ from typing import List, Dict, Optional, Tuple
@dataclass @dataclass
class DiffHunk: class DiffHunk:
header: str header: str
lines: List[str] lines: List[str]
old_start: int old_start: int
old_count: int old_count: int
new_start: int new_start: int
@@ -19,18 +20,16 @@ class DiffHunk:
class DiffFile: class DiffFile:
old_path: str old_path: str
new_path: str new_path: str
hunks: List[DiffHunk] hunks: List[DiffHunk]
def parse_hunk_header(line: str) -> Optional[tuple[int, int, int, int]]: def parse_hunk_header(line: str) -> Optional[tuple[int, int, int, int]]:
""" """
[C: tests/test_diff_viewer.py:test_parse_hunk_header] [C: tests/test_diff_viewer.py:test_parse_hunk_header]
""" """
if not line.startswith("@@"): if not line.startswith("@@"): return None
return None
parts = line.split() parts = line.split()
if len(parts) < 2: if len(parts) < 2: return None
return None
old_part = parts[1][1:] old_part = parts[1][1:]
new_part = parts[2][1:] new_part = parts[2][1:]
@@ -52,7 +51,7 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
if not diff_text or not diff_text.strip(): if not diff_text or not diff_text.strip():
return [] return []
files: List[DiffFile] = [] files: List[DiffFile] = []
current_file: Optional[DiffFile] = None current_file: Optional[DiffFile] = None
current_hunk: Optional[DiffHunk] = None current_hunk: Optional[DiffHunk] = None
@@ -83,21 +82,21 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
if hunk_info: if hunk_info:
old_start, old_count, new_start, new_count = hunk_info old_start, old_count, new_start, new_count = hunk_info
current_hunk = DiffHunk( current_hunk = DiffHunk(
header=line, header = line,
lines=[], lines = [],
old_start=old_start, old_start = old_start,
old_count=old_count, old_count = old_count,
new_start=new_start, new_start = new_start,
new_count=new_count new_count = new_count
) )
else: else:
current_hunk = DiffHunk( current_hunk = DiffHunk(
header=line, header = line,
lines=[], lines = [],
old_start=0, old_start = 0,
old_count=0, old_count = 0,
new_start=0, new_start = 0,
new_count=0 new_count = 0
) )
elif current_hunk is not None: elif current_hunk is not None:
@@ -115,22 +114,17 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
def get_line_color(line: str) -> Optional[str]: def get_line_color(line: str) -> Optional[str]:
""" """
[C: tests/test_diff_viewer.py:test_get_line_color] [C: tests/test_diff_viewer.py:test_get_line_color]
""" """
if line.startswith("+"): if line.startswith("+"): return "green"
return "green" elif line.startswith("-"): return "red"
elif line.startswith("-"): elif line.startswith("@@"): return "cyan"
return "red"
elif line.startswith("@@"):
return "cyan"
return None return None
def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str]: def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str]:
""" """
[C: src/gui_2.py:App._apply_pending_patch, tests/test_diff_viewer.py:test_apply_patch_simple, tests/test_diff_viewer.py:test_apply_patch_with_context] [C: src/gui_2.py:App._apply_pending_patch, tests/test_diff_viewer.py:test_apply_patch_simple, tests/test_diff_viewer.py:test_apply_patch_with_context]
""" """
import difflib
diff_files = parse_diff(patch_text) diff_files = parse_diff(patch_text)
if not diff_files: if not diff_files:
return False, "No valid diff found" return False, "No valid diff found"
@@ -147,7 +141,7 @@ def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str
original_lines = f.read().splitlines(keepends=True) original_lines = f.read().splitlines(keepends=True)
new_lines = original_lines.copy() new_lines = original_lines.copy()
offset = 0 offset = 0
for hunk in df.hunks: for hunk in df.hunks:
hunk_old_start = hunk.old_start - 1 hunk_old_start = hunk.old_start - 1
@@ -164,7 +158,7 @@ def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str
hunk_new_content.append(line + "\n") hunk_new_content.append(line + "\n")
new_lines = new_lines[:replace_start] + hunk_new_content + new_lines[replace_start + replace_count:] new_lines = new_lines[:replace_start] + hunk_new_content + new_lines[replace_start + replace_count:]
offset += len(hunk_new_content) - replace_count offset += len(hunk_new_content) - replace_count
with open(file_path, "w", encoding="utf-8", newline="") as f: with open(file_path, "w", encoding="utf-8", newline="") as f:
f.writelines(new_lines) f.writelines(new_lines)
+23 -28
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -20,7 +20,7 @@ class FuzzyAnchor:
def create_slice(cls, text: str, start_line: int, end_line: int) -> dict: def create_slice(cls, text: str, start_line: int, end_line: int) -> dict:
""" """
start_line and end_line are 1-based. start_line and end_line are 1-based.
[C: src/gui_2.py:App._populate_auto_slices, src/gui_2.py:App._render_text_viewer_window, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_create_slice_basic, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_anchor_mismatch_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_exact_match, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_deleted_before_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_inserted_before, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_multiple_lines_changed, tests/test_slice_editor_behavior.py:test_add_slice_with_annotations] [C: src/gui_2.py:App._populate_auto_slices, src/gui_2.py:App._render_text_viewer_window, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_create_slice_basic, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_anchor_mismatch_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_exact_match, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_deleted_before_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_inserted_before, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_multiple_lines_changed, tests/test_slice_editor_behavior.py:test_add_slice_with_annotations]
""" """
lines = text.splitlines() lines = text.splitlines()
s_idx = max(0, start_line - 1) s_idx = max(0, start_line - 1)
+5 -7
View File
@@ -189,18 +189,16 @@ class GeminiCliAdapter:
self.last_latency = current_latency self.last_latency = current_latency
return { return {
"text": accumulated_text, "text": accumulated_text,
"tool_calls": tool_calls, "tool_calls": tool_calls,
"stderr": stderr_final "stderr": stderr_final
} }
def count_tokens(self, contents: list[str]) -> int: def count_tokens(self, contents: list[str]) -> int:
""" """
Provides a character-based token estimation for the Gemini CLI.
Uses 4 chars/token as a conservative average.
Provides a character-based token estimation for the Gemini CLI. [C: tests/test_gemini_cli_adapter_parity.py:TestGeminiCliAdapterParity.test_count_tokens_fallback]
Uses 4 chars/token as a conservative average.
[C: tests/test_gemini_cli_adapter_parity.py:TestGeminiCliAdapterParity.test_count_tokens_fallback]
""" """
total_chars = len("\n".join(contents)) total_chars = len("\n".join(contents))
return total_chars // 4 return total_chars // 4