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>
130 lines
5.3 KiB
Python
130 lines
5.3 KiB
Python
"""FolderTab shell (R08-T12) — assembles
|
|
``workspace_file_tree.py::WorkspaceFileTree``,
|
|
``document_preview_manager.py::DocumentPreviewManager`` and
|
|
``ai_file_editor_dialog.py::AiFileEditorDialog`` behind the splitter/terminal
|
|
layout that used to be inline in ``ui/folder_tab.py::FolderTab.__init__``
|
|
(lines 238-384 of the original 1587-line file).
|
|
|
|
The AI-panel toggle button (``ai_btn``) lives here because it controls
|
|
things two different children own: the panel's own visibility AND the
|
|
content splitter's sizing — a genuine shell-level concern, not either
|
|
child's.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QSplitter, QVBoxLayout, QWidget
|
|
from PySide6.QtCore import Qt, Signal
|
|
|
|
from cowork_local.i18n import on_language_changed, tr
|
|
from cowork_local.presentation.folder.ai_file_editor_dialog import AiFileEditorDialog
|
|
from cowork_local.presentation.folder.document_preview_manager import DocumentPreviewManager
|
|
from cowork_local.presentation.folder.workspace_file_tree import WorkspaceFileTree
|
|
from cowork_local.state import AppContext
|
|
from cowork_local.ui.icons import icon
|
|
|
|
|
|
class FolderTab(QWidget):
|
|
"""Two-pane file explorer: directory tree + view/edit pane (+ collapsible
|
|
AI-edit panel, + collapsible terminal)."""
|
|
|
|
status_message = Signal(str)
|
|
|
|
def __init__(self, ctx: AppContext, cowork=None):
|
|
"""Ghép ba phần của tab Thư mục: cây tệp, khung xem và terminal."""
|
|
super().__init__()
|
|
self.ctx = ctx
|
|
self._root = str(ctx.config.cowork_output_dir())
|
|
|
|
root_layout = QVBoxLayout(self)
|
|
split = QSplitter(Qt.Horizontal)
|
|
|
|
self.tree = WorkspaceFileTree(self._root)
|
|
split.addWidget(self.tree)
|
|
|
|
right = QWidget()
|
|
rl = QVBoxLayout(right)
|
|
rl.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.preview = DocumentPreviewManager(self._root)
|
|
self.ai_panel = AiFileEditorDialog(ctx, self.preview, cowork=cowork)
|
|
|
|
self.ai_btn = QPushButton() # expand/collapse the AI-edit panel
|
|
self.ai_btn.setIcon(icon("sparkle"))
|
|
self.ai_btn.setCheckable(True)
|
|
self.ai_btn.clicked.connect(self._toggle_ai_panel)
|
|
# Same visual position as the original single-class header: between
|
|
# the Preview⇄Edit toggle and Save (file_label=0, mode_btn=1).
|
|
self.preview.header_layout.insertWidget(2, self.ai_btn)
|
|
self.ai_panel.badge_changed.connect(self._on_ai_badge_changed)
|
|
|
|
content_split = QSplitter(Qt.Horizontal)
|
|
content_split.addWidget(self.preview)
|
|
content_split.addWidget(self.ai_panel)
|
|
content_split.setStretchFactor(0, 1)
|
|
content_split.setStretchFactor(1, 0)
|
|
content_split.setSizes([700, 320])
|
|
self._content_split = content_split
|
|
self.ai_panel.setVisible(False) # default collapsed
|
|
rl.addWidget(content_split, 1)
|
|
|
|
split.addWidget(right)
|
|
split.setStretchFactor(0, 0)
|
|
split.setStretchFactor(1, 1)
|
|
split.setSizes([300, 800])
|
|
root_layout.addWidget(split, 1)
|
|
|
|
# Terminal CLI below the file view — collapsible, default collapsed;
|
|
# opening it points the shell at the current workspace folder.
|
|
from cowork_local.ui.terminal_panel import TerminalPanel
|
|
|
|
self.terminal = TerminalPanel()
|
|
self.terminal.set_cwd(self._root)
|
|
self.terminal.expanded.connect(lambda: self.terminal.set_cwd(self._root))
|
|
root_layout.addWidget(self.terminal)
|
|
|
|
self.tree.file_selected.connect(self.preview.open_file)
|
|
self.preview.status_message.connect(self.status_message.emit)
|
|
self.ai_panel.status_message.connect(self.status_message.emit)
|
|
|
|
on_language_changed(self._retranslate)
|
|
self._retranslate()
|
|
|
|
# ---- public API ---------------------------------------------------------
|
|
def set_root(self, path: str) -> None:
|
|
"""Đổi thư mục gốc của cả ba widget con.
|
|
|
|
``WorkspaceFileTree`` lặng lẽ từ chối đường dẫn không hợp lệ, nên chỉ lan
|
|
sang khung xem và terminal khi cây thật sự đã nhận.
|
|
"""
|
|
self.tree.set_root(path)
|
|
# WorkspaceFileTree silently no-ops on an invalid path (same guard
|
|
# the original single-class _root setter had) — mirror that here by
|
|
# only propagating when the tree actually accepted it.
|
|
if self.tree.root == path:
|
|
self._root = path
|
|
self.preview.set_root(path)
|
|
self.terminal.set_cwd(path)
|
|
|
|
def _toggle_ai_panel(self) -> None:
|
|
"""Gập/mở panel AI-Edit; mở ra thì báo cho panel biết để nó nạp model lần đầu."""
|
|
show = self.ai_btn.isChecked()
|
|
self.ai_panel.setVisible(show)
|
|
if show:
|
|
self._content_split.setSizes([700, 320])
|
|
self.ai_panel.on_opened()
|
|
|
|
def _on_ai_badge_changed(self, suffix: str) -> None:
|
|
"""Cập nhật huy hiệu trên nút AI-Edit (số việc đang chờ)."""
|
|
self.ai_btn.setText(tr("folder.ai_edit") + suffix)
|
|
|
|
def _retranslate(self) -> None:
|
|
"""Chuyển lệnh dịch lại xuống cho cả ba widget con."""
|
|
self.tree.retranslate()
|
|
self.preview.retranslate()
|
|
self.ai_panel.retranslate()
|
|
self.ai_btn.setText(tr("folder.ai_edit"))
|
|
self.ai_btn.setToolTip(tr("folder.ai_edit_tooltip"))
|
|
|
|
|
|
__all__ = ["FolderTab"]
|