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>
96 lines
3.9 KiB
Python
96 lines
3.9 KiB
Python
"""TaskRepository - an object-shaped, atomic-write-backed facade over
|
|
``core/tasks.py`` (R07-T01).
|
|
|
|
``core/tasks.py``'s module-level functions (``list_tasks``, ``load_task``,
|
|
``save_task``, ``delete_task``, ``new_task``, ``duplicate_task``) are still
|
|
what every existing call site (``core/task_scheduler.py``,
|
|
``core/task_executors.py``, ``ui/schedule_task_tab.py``) uses, and stay that
|
|
way - ``save_task`` now writes through :func:`atomic_write.write_json`
|
|
itself (R07-T01, same class of durability fix already applied to
|
|
``core/projects.py``/``core/history.py`` at R06-T02), so the fix applies
|
|
whether or not a caller ever touches this class.
|
|
|
|
This repository exists for the application layer
|
|
(``application/scheduling``, R07-T04) to depend on an interface instead of
|
|
reaching into ``core/`` directly. It is a thin pass-through today, not a
|
|
re-implementation: same on-disk format, same directory, same functions
|
|
underneath.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
|
|
class TaskRepository:
|
|
"""CRUD over task dicts (see ``core/tasks.py::DEFAULT_TASK`` for shape),
|
|
scoped to one ``directory`` (defaults to the app's real ``TASKS_DIR``;
|
|
tests pass a ``tmp_path`` so nothing touches the user's real config
|
|
folder)."""
|
|
|
|
def __init__(self, directory: Optional[Path] = None) -> None:
|
|
"""``directory`` để None thì dùng thư mục task mặc định.
|
|
|
|
Hai đường import cho cùng một hằng số: gói có thể được nạp dưới tên đầy đủ
|
|
``cowork_local`` hoặc dưới dạng tương đối tuỳ cách chạy.
|
|
"""
|
|
if directory is None:
|
|
try:
|
|
from cowork_local.core.tasks import TASKS_DIR
|
|
except ImportError:
|
|
from ...core.tasks import TASKS_DIR
|
|
self._directory = TASKS_DIR
|
|
else:
|
|
self._directory = directory
|
|
|
|
def list(self) -> List[Dict[str, Any]]:
|
|
"""Liệt kê mọi task trong thư mục."""
|
|
try:
|
|
from cowork_local.core.tasks import list_tasks
|
|
except ImportError:
|
|
from ...core.tasks import list_tasks
|
|
return list_tasks(self._directory)
|
|
|
|
def get(self, task_id: str) -> Optional[Dict[str, Any]]:
|
|
"""Đọc một task theo id; trả về ``None`` nếu không có."""
|
|
try:
|
|
from cowork_local.core.tasks import load_task
|
|
except ImportError:
|
|
from ...core.tasks import load_task
|
|
return load_task(task_id, self._directory)
|
|
|
|
def save(self, task: Dict[str, Any]) -> Path:
|
|
"""Ghi task xuống đĩa (ghi nguyên tử) và trả về đường dẫn file."""
|
|
try:
|
|
from cowork_local.core.tasks import save_task
|
|
except ImportError:
|
|
from ...core.tasks import save_task
|
|
return save_task(task, self._directory)
|
|
|
|
def create(self, title: str = "", **overrides: Any) -> Dict[str, Any]:
|
|
"""Tạo một task mới trong bộ nhớ theo mẫu mặc định; chưa ghi đĩa."""
|
|
try:
|
|
from cowork_local.core.tasks import new_task
|
|
except ImportError:
|
|
from ...core.tasks import new_task
|
|
return new_task(title, **overrides)
|
|
|
|
def duplicate(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Nhân bản một task (id mới, trạng thái và lịch sử chạy được đặt lại)."""
|
|
try:
|
|
from cowork_local.core.tasks import duplicate_task
|
|
except ImportError:
|
|
from ...core.tasks import duplicate_task
|
|
return duplicate_task(task)
|
|
|
|
def delete(self, task_id: str) -> None:
|
|
"""Xoá hẳn một task khỏi đĩa."""
|
|
try:
|
|
from cowork_local.core.tasks import delete_task
|
|
except ImportError:
|
|
from ...core.tasks import delete_task
|
|
delete_task(task_id, self._directory)
|
|
|
|
|
|
__all__ = ["TaskRepository"]
|