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>
102 lines
4.2 KiB
Python
102 lines
4.2 KiB
Python
"""Badge/label vocabulary shared by the Monitoring event tables and detail
|
|
panel — human labels for a raw audit ``name``, and the (QSS object name,
|
|
i18n key) pair for the "Trạng thái"/"Mức độ" pills.
|
|
|
|
``apply_badge`` replaces the two byte-identical
|
|
``_EventDetailPanel._apply_badge`` / ``MonitoringTab._set_badge`` static
|
|
methods the original file duplicated.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Tuple
|
|
|
|
from PySide6.QtWidgets import QLabel
|
|
|
|
from ....i18n import tr
|
|
|
|
# Human label for the raw ``name`` an audit event is recorded under — the
|
|
# "Loại" field in the detail panel. Anything not in this map (custom tool
|
|
# names, etc.) just shows its raw name, same as the table's Hành động column.
|
|
_ACTION_LABEL_KEYS = {
|
|
"prompt": "monitoring.action_prompt",
|
|
"dangerous_command": "monitoring.action_dangerous_command",
|
|
"run_command": "monitoring.action_dangerous_command",
|
|
"install_package": "monitoring.action_install_package",
|
|
"path_outside_sandbox": "monitoring.action_path_outside_sandbox",
|
|
"network_blocked": "monitoring.action_network_blocked",
|
|
"secret_in_output": "monitoring.action_secret_in_output",
|
|
}
|
|
|
|
|
|
def action_label(name: str) -> str:
|
|
"""Nhãn đã dịch của một loại hành động; không có trong bảng thì trả nguyên tên."""
|
|
key = _ACTION_LABEL_KEYS.get(name)
|
|
return tr(key) if key else name
|
|
|
|
|
|
# (badge QSS object name, i18n key) for the "Trạng thái" pill, mapped onto
|
|
# the app's existing badge* tones (theme.py).
|
|
_STATUS_INFO = {
|
|
"path_outside_sandbox": ("badgeSuccess", "monitoring.status_path"),
|
|
"network_blocked": ("badge", "monitoring.status_network"),
|
|
"secret_in_output": ("badgeWarn", "monitoring.status_secret"),
|
|
}
|
|
_STATUS_DEFAULT = ("badgePurple", "monitoring.status_blocked")
|
|
|
|
|
|
def status_info(name: str, kind: str = "security_block", ok: bool = False) -> Tuple[str, str]:
|
|
"""Cặp (tên style, khoá dịch) cho huy hiệu trạng thái của một sự kiện."""
|
|
if name in _STATUS_INFO:
|
|
return _STATUS_INFO[name]
|
|
if kind == "security_block":
|
|
# Security Events rows are always ok=False — an unmapped name here
|
|
# still means "blocked by some rule", never a plain failure.
|
|
return _STATUS_DEFAULT
|
|
# MCP calls / generic Action Logs rows: no fixed enforcement-rule
|
|
# vocabulary applies, so fall back to the event's own ok/fail outcome.
|
|
return ("badgeSuccess", "monitoring.status_ok") if ok else ("badgeDanger", "monitoring.status_failed")
|
|
|
|
|
|
def severity_info(name: str, kind: str = "security_block", ok: bool = False) -> Tuple[str, str]:
|
|
# An unapproved shell command is the one CRITICAL case; everything else
|
|
# blocked is MEDIUM.
|
|
"""Cặp (tên style, khoá dịch) cho huy hiệu mức nghiêm trọng.
|
|
|
|
Lệnh shell chạy mà chưa được duyệt là trường hợp NGHIÊM TRỌNG duy nhất; mọi
|
|
thứ bị chặn khác đều ở mức trung bình.
|
|
"""
|
|
if name in ("dangerous_command", "run_command"):
|
|
return "badgeDanger", "monitoring.severity_critical"
|
|
if kind == "security_block":
|
|
return "badgeWarn", "monitoring.severity_medium"
|
|
# A successful MCP call / action is routine (INFO); a failed one still
|
|
# deserves the same MEDIUM tone Security Events uses for a blocked rule.
|
|
return ("badge", "monitoring.severity_info") if ok else ("badgeWarn", "monitoring.severity_medium")
|
|
|
|
|
|
def agent_badge_name(name: str) -> str:
|
|
"""Badge tone for the Agent field's pill — the same identity-colour
|
|
mapping ``formatters.agent_avatar_colour`` uses, expressed as one of the
|
|
shared badge* QSS classes (theme.py) instead of a literal hex."""
|
|
if "Security" in name:
|
|
return "badgeDanger"
|
|
if "Cowork" in name:
|
|
return "badge"
|
|
if name == "schedule":
|
|
return "badgeWarn"
|
|
if name == "graphrag":
|
|
return "badgePurple"
|
|
if "Code" in name:
|
|
return "badgeSuccess"
|
|
return "badge"
|
|
|
|
|
|
def apply_badge(label: QLabel, object_name: str) -> None:
|
|
"""Gán style cho một nhãn huy hiệu và ép Qt vẽ lại.
|
|
|
|
Phải ``unpolish``/``polish`` vì Qt không tự áp lại QSS khi ``objectName`` đổi.
|
|
"""
|
|
label.setObjectName(object_name)
|
|
label.style().unpolish(label)
|
|
label.style().polish(label)
|