refactor(stage-1): eliminate dead parse_text, simplify task progress SQL, remove prompt hacks

This commit is contained in:
Antigravity committed 2026-10-07 14:39:53 +03:00
1 parent 6c2d94773c
commit 20eef2c684
3 files changed
+19 -95

No files matched your search

+1 -9
View File
@@ -74,10 +74,6 @@ def get_sentence_dictionary_hints(sentence: str, target_word: str = "") -> str:
return "" return ""
hints = [] hints = []
special_guidance = {
"owl": "owl — это сова/неясыть (ни в коем случае НЕ орёл!)",
"tawny owl": "tawny owl — это сова/неясыть (птица семейства совиных, ни в коем случае НЕ орёл!)",
}
try: try:
with get_db() as conn: with get_db() as conn:
@@ -98,11 +94,7 @@ def get_sentence_dictionary_hints(sentence: str, target_word: str = "") -> str:
continue continue
seen_terms.add(cand) seen_terms.add(cand)
trans = matched_dict[cand] trans = matched_dict[cand]
guidance = special_guidance.get(cand, "") hints.append(f"- {cand}: {trans}")
if guidance:
hints.append(f"- {cand}: {trans} (ВНИМАНИЕ: {guidance})")
else:
hints.append(f"- {cand}: {trans}")
if len(hints) >= 8: if len(hints) >= 8:
break break
-38
View File
@@ -286,44 +286,6 @@ def split_long_text(text: str, target_words: int = 3000) -> List[str]:
return chunks return chunks
def parse_text(content: str, title: str = "Untitled", author: str = "") -> Tuple[str, str, List[Dict[str, str]]]:
"""
Parses plain text or Markdown into readable chapters.
Splits by explicit chapter markers (e.g. 'Chapter X', '# Chapter') or chunks of ~3000 words.
"""
content = content.replace("\r\n", "\n").replace("\r", "\n").strip()
if not content:
return title, author, [{"title": title if title != "Untitled" else "Chapter 1", "content": ""}]
lines = content.split("\n")
first_line = lines[0].strip()
# Extract title from first line or # Heading / <h1...> if default or generic README
if title == "Untitled" or title.lower().startswith("readme"):
if first_line.startswith("# "):
title = first_line.lstrip("# ").strip()
if len(lines) > 1:
content = "\n".join(lines[1:]).strip()
elif first_line.lower().startswith("title:"):
title = first_line.split(":", 1)[1].strip()
if len(lines) > 1:
content = "\n".join(lines[1:]).strip()
else:
h1_match = re.search(r"<h1[^>]*>(.*?)</h1>", content[:1500], re.IGNORECASE)
if h1_match:
detected = re.sub(r"<[^>]+>", "", h1_match.group(1)).strip()
if detected:
title = detected
# Extract author from next line if missing
if not author:
lines = content.split("\n")
if lines and lines[0].lower().startswith(("author:", "by:")):
author = lines[0].split(":", 1)[1].strip()
if len(lines) > 1:
content = "\n".join(lines[1:]).strip()
def detect_text_headings(content: str) -> List[Dict]: def detect_text_headings(content: str) -> List[Dict]:
""" """
Detects section and chapter headings with high accuracy across Markdown, Detects section and chapter headings with high accuracy across Markdown,
+18 -48
View File
@@ -49,54 +49,24 @@ def update_task_progress(
""" """
Updates the progress and status of a running task. Updates the progress and status of a running task.
""" """
if total is not None and message is not None: set_clauses = ["status = 'running'", "progress_current = ?", "updated_at = CURRENT_TIMESTAMP"]
conn.execute( params: List[Any] = [current]
"""
UPDATE background_tasks if total is not None:
SET status = 'running', set_clauses.append("progress_total = ?")
progress_current = ?, params.append(total)
progress_total = ?,
message = ?, if message is not None:
updated_at = CURRENT_TIMESTAMP set_clauses.append("message = ?")
WHERE id = ? AND status != 'cancelled' params.append(message)
""",
(current, total, message, task_id), params.append(task_id)
) sql = f"""
elif total is not None: UPDATE background_tasks
conn.execute( SET {', '.join(set_clauses)}
""" WHERE id = ? AND status != 'cancelled'
UPDATE background_tasks """
SET status = 'running', conn.execute(sql, params)
progress_current = ?,
progress_total = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ? AND status != 'cancelled'
""",
(current, total, task_id),
)
elif message is not None:
conn.execute(
"""
UPDATE background_tasks
SET status = 'running',
progress_current = ?,
message = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ? AND status != 'cancelled'
""",
(current, message, task_id),
)
else:
conn.execute(
"""
UPDATE background_tasks
SET status = 'running',
progress_current = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ? AND status != 'cancelled'
""",
(current, task_id),
)
def complete_task( def complete_task(