fix(history): "Tất cả project" và số liệu mỗi project đọc đủ mọi thư mục

Lịch sử hội thoại KHÔNG nằm chung một chỗ: _bind_project đặt
config._project_history_dir thành <workspace của project>/.cowork_history mỗi
lần chọn project khác — cố ý, để chia sẻ thư mục project là chia sẻ cả lịch sử.

Nhưng hai chỗ đọc lại chỉ đọc MỘT thư mục, gây hai triệu chứng cùng gốc:
- ui/sidebar.py đọc history_dir() (thư mục của project ĐANG mở), nên khung
  "Tất cả project…" dựng đủ tiêu đề nhóm mà mọi nhóm trừ một đều rỗng;
- _project_counts gọi list_conversations() KHÔNG tham số, tức đọc HISTORY_DIR
  toàn cục nơi không có hội thoại nào của project, nên mọi dòng project đều
  đếm "0 đoạn chat".

Thêm history_dirs() + list_conversations_by_project(), giữ đúng thứ tự cũ (ghim
trước, mới nhất trước) và chống trùng. Thư mục là chủ sở hữu có thẩm quyền: hội
thoại nằm trong workspace của project nào thì thuộc project đó, kể cả khi trường
project_id trong file đã cũ vì project bị đổi thư mục.

HISTORY_SUBDIR + project_history_dir() gom đường dẫn về một định nghĩa duy nhất
— chuỗi ".cowork_history" từng nằm rải trong ui/workspace_tab.py.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-07 19:55:02 +09:00
co-authored by Claude Opus 5
parent 971d39203b
commit d656c5c834
4 changed files with 230 additions and 1 deletions
+10 -1
View File
@@ -241,8 +241,17 @@ class HistorySidebar(QWidget):
for p in projects:
groups[p.project_id] = _make_group(p.name)
# Loc theo mot project -> doc dung thu muc cua no. Khong loc ("Tat ca
# project…") -> phai doc thu muc lich su cua TUNG project roi gop lai:
# lich su nam trong thu muc lam viec cua project, nen mot lan goi
# list_conversations chi thay duoc project dang mo, va moi nhom con lai
# hien ra rong tuy nguoi dung da chat trong do.
try:
convos = list_conversations(self.ctx.config.history_dir(), query=query)
if self._project_filter:
convos = list_conversations(self.ctx.config.history_dir(), query=query)
else:
from ..core.history import history_dirs, list_conversations_by_project
convos = list_conversations_by_project(history_dirs(), query=query)
except Exception:
convos = []