refactor: vá 4 hồi quy, tách 4 file chạm trần LOC, docstring lên 100%

Hồi quy đã vá
-------------
F-12  Kéo–thả hoặc dán tệp vào ô chat ném NameError. R08 tách `_Input` sang
      `chat_input_box.py` nhưng để `_paths_from_mime()` ở lại
      `composer_widget.py`, nên hai hàm sự kiện Qt gọi một cái tên không tồn
      tại. Bốn hàm dùng chung chuyển sang `composer_mime.py` — module thứ ba
      là chỗ duy nhất không lặp lại được lỗi này. Đo lại: cả thả lẫn dán đều
      gắn 1 tệp, khớp bản trước refactor.

F-01  Đổi provider thì bộ chọn model AI-Edit không làm gì. Hook cũ kiểm
      `folder.ai_model_combo`, thuộc tính R08-T12 đã dời sang
      `ai_panel.resolver`. Làm mới vô điều kiện, đúng như tab cũ: lần lấy đầu
      tiên hỏng thì đổi provider chính là lúc phải thử lại.

F-07  Hàng chọn kỳ của Dashboard bị đẩy xuống dưới các thẻ số liệu. Hàng này
      lọc CẢ BA thẻ con chứ không riêng biểu đồ, nên để nó nằm dưới là bắt
      người dùng đọc con số trước khi thấy con số đó tính cho kỳ nào. Kèm
      theo: `TokenUsageCardWidget` bị bỏ sót `setContentsMargins(0,0,0,0)`
      mà hai thẻ con còn lại đã có, đẩy cả hàng thẻ lệch 9px.
      `check_layout_geometry` nay khớp TỪNG BYTE với bản trước refactor.

F-11  Hai lớp khai trùng tên phương thức; Python giữ bản sau nên bản đầu là
      mã chết. `co4e_tab.py::showEvent` bản đầu gọi `_narrow_guard.attach()`
      và không bao giờ chạy.

Tách file (F-09)
----------------
Bốn file chạm trần 400 dòng, mỗi lần cắt ra một trách nhiệm thật:

    graph_renderer.py         -> graph_scene_builder.py + graph_export.py
    co4e_workflow_service.py  -> co4e_run_history.py
    json_config_repository.py -> config_sections.py
    agents_admin_tab.py       -> shared/agent_kind_visuals.py

File cuối còn xoá 3 bản sao của hàm đã có trong `shared/formatters.py`,
giống hệt đến từng dòng — nay định dạng thời gian và avatar không lệch nhau
giữa các bảng Giám sát nữa.

Docstring
---------
41,6% -> 100% (3.478/3.478 định nghĩa production), kể cả module dormant và
phương thức dunder. Toàn bộ phần bổ sung viết bằng tiếng Việt; comment tiếng
Anh có sẵn giữ nguyên — dịch ngược là một đợt riêng.

Seam chưa nối dây (F-05)
------------------------
9 seam mang nhãn `SEAM · dựng <ngày>` kèm hai câu: được nối khi nào, và để
dormant thì hỏng gì. Ngày lấy từ lịch sử git, không phải hạn tự đặt. Gate O
đọc nhãn đó và nhắc khi quá 30 ngày.

859 test xanh · 4/4 cổng CASAN · 19/24 checker khớp từng byte bản cũ.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-30 10:41:45 +09:00
co-authored by Claude Opus 5
parent d20306be08
commit e29a0ccdbd
264 changed files with 4593 additions and 359 deletions
@@ -57,6 +57,11 @@ class DocumentPreviewManager(QWidget):
ai_reset_requested = Signal() # a DIFFERENT file was opened by the user
def __init__(self, root: str, parent=None):
"""Khung xem tài liệu.
Mọi lượt đọc tệp đi qua ``FileWorkspaceService`` nên không thoát ra ngoài
thư mục gốc, kể cả khi đường dẫn có ``..``.
"""
super().__init__(parent)
self._root = root
self._file_service = FileWorkspaceService(WorkspaceSession.unscoped(Path(root)))
@@ -123,6 +128,7 @@ class DocumentPreviewManager(QWidget):
self.retranslate()
def retranslate(self) -> None:
"""Áp lại chữ theo ngôn ngữ đang chọn cho các nút và ô trống."""
self.save_btn.setText(tr("folder.save"))
self.ext_btn.setText(tr("folder.open_external"))
if not self._current_file:
@@ -130,23 +136,28 @@ class DocumentPreviewManager(QWidget):
self._retranslate_mode_btn()
def _retranslate_mode_btn(self) -> None:
"""Nhãn nút chuyển chế độ đổi theo trạng thái: đang xem thì ghi "Sửa" và ngược lại."""
self.mode_btn.setText(tr("folder.edit") if not self.mode_btn.isChecked()
else tr("folder.preview"))
# ---- public API used by the shell / AI panel --------------------------- #
@property
def current_file(self) -> Optional[str]:
"""Đường dẫn tệp đang mở; ``None`` nếu chưa mở tệp nào."""
return self._current_file
@property
def edit_kind(self) -> Optional[str]:
"""Loại nội dung đang sửa ('pptx', 'html', 'text'…); ``None`` nếu đang chỉ xem."""
return self._edit_kind
@property
def root(self) -> str:
"""Thư mục gốc mà mọi thao tác ghi phải nằm bên trong."""
return self._root
def set_root(self, root: str) -> None:
"""Đổi thư mục gốc và dựng lại dịch vụ ghi tệp gắn với phạm vi mới."""
self._root = root
self._file_service = FileWorkspaceService(WorkspaceSession.unscoped(Path(root)))
@@ -155,6 +166,13 @@ class DocumentPreviewManager(QWidget):
# (reset_ai=False when the AI itself just CREATED this file — keep
# that chat). Whether/how to reset is the AI panel's own business —
# this class only announces that a genuine file switch happened.
"""Mở một tệp, tự chọn cách hiển thị theo đuôi và kích thước.
Thứ tự ưu tiên: ảnh → HTML → PowerPoint → Excel → tài liệu Office → nhị
phân (quá lớn hoặc không phải văn bản) → mã nguồn. Đổi sang tệp KHÁC thì
báo cho panel AI biết để nó bắt đầu hội thoại mới; ``reset_ai=False`` dùng
khi chính AI vừa tạo ra tệp này — giữ nguyên đoạn chat đang dở.
"""
if reset_ai and path != self._current_file:
self.ai_reset_requested.emit()
self._current_file = path
@@ -206,6 +224,7 @@ class DocumentPreviewManager(QWidget):
return False
def save(self) -> None:
"""Lưu nội dung đang sửa xuống tệp; pptx ghi ngược vào bản trình chiếu."""
if not self._current_file:
return
try:
@@ -261,6 +280,7 @@ class DocumentPreviewManager(QWidget):
return dest
def open_external(self) -> None:
"""Mở tệp đang xem bằng ứng dụng mặc định của hệ điều hành."""
if self._current_file:
from cowork_local.ui.osutil import open_location
open_location(self._current_file)
@@ -278,6 +298,7 @@ class DocumentPreviewManager(QWidget):
# ---- simple renderers (HTML/PPTX/Excel/PDF/office live in
# office_document_renderer.py) --------------------------------------------- #
def _show_code(self, path: str) -> None:
"""Hiện tệp trong ô soạn thảo có tô màu cú pháp, cho phép sửa và lưu."""
text = read_text(path)
self.editor.setReadOnly(False)
self.editor.load_file(path, text)
@@ -285,6 +306,7 @@ class DocumentPreviewManager(QWidget):
self.stack.setCurrentWidget(self.editor)
def _show_image(self, path: str) -> None:
"""Hiện ảnh; ảnh hỏng hoặc không đọc được thì rơi về khung nhị phân."""
from PySide6.QtGui import QPixmap
pix = QPixmap(path)
if pix.isNull():
@@ -296,6 +318,7 @@ class DocumentPreviewManager(QWidget):
self.stack.setCurrentWidget(self._img_scroll)
def _show_binary(self, path: str) -> None:
"""Hiện thông báo "tệp nhị phân" kèm nút mở bằng ứng dụng ngoài."""
self._placeholder.setText(tr("folder.binary_file"))
self.ext_btn.setVisible(True)
self.stack.setCurrentWidget(self._placeholder)