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>
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
"""User-added custom icons for agents / flows.
|
|
|
|
Built-in glyphs live in ``ui/icons.py`` (``_PATHS``). This module lets a user
|
|
add their OWN icons (SVG files) under ``~/.cowork_local/icons/<slug>.svg`` so
|
|
they can be used by name anywhere an icon name is accepted (Co4E step/agent
|
|
``icon`` field, etc.). ``ui/icons.icon()`` resolves an unknown name against this
|
|
store before falling back. Qt-free so it's unit-testable.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import List, Optional
|
|
|
|
from ..config import CONFIG_DIR
|
|
|
|
ICONS_DIR = CONFIG_DIR / "icons"
|
|
_MAX_BYTES = 200_000
|
|
|
|
|
|
def icons_dir() -> Path:
|
|
"""Thư mục chứa icon do người dùng thêm."""
|
|
return ICONS_DIR
|
|
|
|
|
|
def slugify(name: str) -> str:
|
|
"""Định danh an toàn cho tên file icon; rỗng thì trả về 'icon'."""
|
|
s = "".join(c if (c.isalnum() or c in "-_") else "-" for c in (name or "").strip().lower())
|
|
return "-".join(filter(None, s.split("-"))) or "icon"
|
|
|
|
|
|
def list_custom(directory: Optional[Path] = None) -> List[str]:
|
|
"""Tên các icon tự thêm; thư mục chưa có thì trả list rỗng."""
|
|
directory = directory or ICONS_DIR
|
|
if not directory.exists():
|
|
return []
|
|
return sorted(p.stem for p in directory.glob("*.svg"))
|
|
|
|
|
|
def get_svg(name: str, directory: Optional[Path] = None) -> Optional[str]:
|
|
"""The raw SVG text for a custom icon slug, or None if there isn't one."""
|
|
directory = directory or ICONS_DIR
|
|
if not name:
|
|
return None
|
|
path = directory / f"{slugify(name)}.svg"
|
|
if not path.exists():
|
|
return None
|
|
try:
|
|
return path.read_text(encoding="utf-8")[:_MAX_BYTES]
|
|
except OSError:
|
|
return None
|
|
|
|
|
|
def add_svg(name: str, svg_text: str, directory: Optional[Path] = None) -> str:
|
|
"""Save raw SVG under a slug; returns the slug. Raises ValueError if the
|
|
text isn't SVG."""
|
|
if "<svg" not in (svg_text or "").lower():
|
|
raise ValueError("Not an SVG (no <svg> tag found).")
|
|
directory = directory or ICONS_DIR
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
slug = slugify(name)
|
|
(directory / f"{slug}.svg").write_text(svg_text[:_MAX_BYTES], encoding="utf-8")
|
|
return slug
|
|
|
|
|
|
def add_from_file(path, name: str = "", directory: Optional[Path] = None) -> str:
|
|
"""Import an .svg file. ``name`` defaults to the file's own stem."""
|
|
p = Path(path)
|
|
if p.suffix.lower() != ".svg":
|
|
raise ValueError("Only .svg icon files are supported.")
|
|
svg = p.read_text(encoding="utf-8", errors="replace")
|
|
return add_svg(name or p.stem, svg, directory)
|
|
|
|
|
|
def delete_custom(name: str, directory: Optional[Path] = None) -> None:
|
|
"""Xoá một icon tự thêm; không có thì bỏ qua."""
|
|
directory = directory or ICONS_DIR
|
|
path = directory / f"{slugify(name)}.svg"
|
|
if path.exists():
|
|
try:
|
|
path.unlink()
|
|
except OSError:
|
|
pass
|