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>
94 lines
4.2 KiB
Python
94 lines
4.2 KiB
Python
"""ExecutionWorkspace - the output folder vs. the scratch folder for one
|
|
turn, as two distinct properties instead of a name convention (R06-T03).
|
|
|
|
Today the ``.scratch`` subtree is a special case buried inside
|
|
``_flatten_rel`` (``infrastructure/filesystem/file_tools.py``): a generator
|
|
script writes there, the deliverable lands in the output root, and
|
|
``core/chat_agent.py`` cleans ``.scratch`` up after the turn — but nothing
|
|
NAMES "the scratch folder" as a thing; every call site re-derives
|
|
``workdir / ".scratch"`` (or checks ``Path(rel).parts[0] == ".scratch"``) by
|
|
hand. This class gives that convention one home.
|
|
|
|
It does not change WHERE files land - ``workspace_root/.scratch`` stays
|
|
exactly what it always was. It exists so a caller (an application service,
|
|
R06-T05's ``FileWorkspaceService``, or a future turn-cleanup step) can ask
|
|
for "the output dir" / "the scratch dir" instead of hand-building the path
|
|
and hoping the convention hasn't drifted.
|
|
|
|
SEAM · dựng 2026-08-21 · chưa nối dây (F-05)
|
|
------------------------------------------------------------
|
|
Được nối khi: một chỗ gọi thật hỏi ``output_dir``/``scratch_dir`` thay vì tự ghép ``workdir / ".scratch"``.
|
|
Để dormant thì sao: Quy ước ``.scratch`` vẫn nằm rải trong ``file_tools.py``
|
|
và ``core/chat_agent.py``. File này đặt tên cho nó nhưng chưa ai dùng, nên
|
|
quy ước vẫn trôi được.
|
|
|
|
Cổng ``scripts/check_orphan_modules.py`` đếm tuổi seam từ ngày trên
|
|
và nhắc khi quá ``SEAM_MAX_AGE_DAYS``. Đổi nội dung dòng đó thì cổng
|
|
đọc theo — đừng sửa ngày để làm im lời nhắc.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from cowork_local.domain.workspaces import WorkspaceSession
|
|
|
|
SCRATCH_DIRNAME = ".scratch"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ExecutionWorkspace:
|
|
"""The two folders a turn actually writes to, derived from a
|
|
:class:`WorkspaceSession`.
|
|
|
|
``output_dir`` is always the session's ``workspace_root`` itself, not a
|
|
per-turn subfolder - Cowork's whole design is that every deliverable lands
|
|
directly in the one configured Output folder (see
|
|
``infrastructure/filesystem/file_tools.py::_flatten_rel``'s docstring).
|
|
``scratch_dir`` is the SAME flat ``workspace_root/.scratch`` every turn on
|
|
that workspace already shares today (``core/chat_agent.py``'s
|
|
``_cleanup_cowork_intermediates`` operates on that exact path) - this
|
|
class does not introduce per-turn namespacing that doesn't exist in the
|
|
engine yet, only names the existing convention.
|
|
|
|
``turn_id`` is kept as metadata for callers that want to attribute a
|
|
workspace to the turn that used it (logging, future per-turn scratch
|
|
namespacing); it does not affect either path today.
|
|
"""
|
|
|
|
session: WorkspaceSession
|
|
turn_id: str
|
|
|
|
@property
|
|
def output_dir(self) -> Path:
|
|
"""Thư mục agent được phép ghi kết quả — chính là gốc của phiên làm việc."""
|
|
return self.session.workspace_root
|
|
|
|
@property
|
|
def scratch_dir(self) -> Path:
|
|
"""Thư mục nháp bên trong phiên, cho file tạm không phải kết quả cuối."""
|
|
return self.session.workspace_root / SCRATCH_DIRNAME
|
|
|
|
def ensure_dirs(self) -> None:
|
|
"""Create both folders if they don't exist yet. Callers that only
|
|
need one (most do) can skip this and let ``write_file`` create parents
|
|
on demand, same as today."""
|
|
self.output_dir.mkdir(parents=True, exist_ok=True)
|
|
self.scratch_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
def cleanup_scratch(self) -> None:
|
|
"""Unconditionally remove the scratch subtree.
|
|
|
|
Coarser than ``core/chat_agent.py::_cleanup_cowork_intermediates``,
|
|
which rescues any real deliverable a generator script wrote INSIDE
|
|
``.scratch`` before wiping it - that rescue logic stays there. This
|
|
is for callers that only need "make the scratch folder go away"
|
|
(e.g. before starting a fresh run) and know it holds nothing worth
|
|
saving.
|
|
"""
|
|
shutil.rmtree(self.scratch_dir, ignore_errors=True)
|
|
|
|
|
|
__all__ = ["ExecutionWorkspace", "SCRATCH_DIRNAME"]
|