## Summary Nhánh `feature/perf-ui-logic`: tối ưu hiệu năng/UI, sửa lỗi workspace và điều hướng, và làm cho công tắc **"Block network for agent-run commands"** chặn thật mọi đường ra mạng của app, **trừ nhà cung cấp AI**. **Chặn mạng (b78d483,8c497cf,10b8379)** - Bộ kiểm tra chung `application/network/network_guard.py`, nối vào cấu hình đang chạy ở Composition Root: đổi công tắc trong Settings là có hiệu lực ngay. - Lệnh shell của agent và task script chạy trong **Windows AppContainer không có quyền mạng**: kernel chặn socket, ping, DNS, Invoke-WebRequest… Không cần quyền admin. Không cô lập được thì lệnh bị từ chối, không chạy khi mạng còn mở. macOS dùng `sandbox-exec`, Linux dùng `unshare --net`. - Bật chặn thì: dừng MCP đang chạy, không khởi động server mới, từ chối lời gọi connector; Microsoft 365 (đăng nhập, Graph, đồng bộ cloud, rules, mail), Teams, nút Test REST/Jira/MCP, link đính kèm task, pip tự cài và tài nguyên web trong xem trước HTML đều bị từ chối. - Vẫn dùng được: chat, tải danh sách model, thử model; tool OneDrive đã đồng bộ trên máy. - Công tắc **mặc định tắt** khi mở app lần đầu; nhãn giữ nguyên như cũ. - Xem trước HTML trong tab Folder giờ hiện được ảnh/CSS/JS từ web khi mạng mở (trước đây trang `file://` không tải được). - Sửa lỗi app văng khi chuyển tab Graph → Folder: profile WebEngine của trang xem trước bị huỷ trước trang (`0xc0000409` trong Qt6Core.dll); giờ dùng một profile chung thuộc QApplication. - Không cấp quyền AppContainer kế thừa lên thư mục chứa PySide6 (nếu có, Chromium không nạp được `Qt6WebEngineCore.dll` và tab Graph trắng). - Cột mục lục trong Settings tính độ rộng theo kiểu chữ của mục đang chọn, "Sandbox Security Layer" không còn bị cắt. **Các commit khác trong nhánh** - `b7a41b3` mỗi thư mục làm việc chỉ thuộc về một project · `bbdf146` bật nút Sửa project khi đã có project đang mở - `35f24e0`, `cc8d5c8`, `2e3e719`, `c699beb` canh hàng / khoảng cách thanh điều hướng - `2759ed9` không refresh workspace khi chuyển tab Cowork · `7607f44` checkpoint hiệu năng và UI - `8548c1e` chặn tool mạng của agent · `caf3b74` renderer GraphRAG native trên macOS · `c00b83c` khoảng cách metadata hàng project · `a04f8a9` ẩn picker workspace cloud ## Change Type - [x] Cowork feature - [x] Bug fix - [ ] Core AI contribution - [x] Test / hardening - [x] Performance - [ ] Documentation ## Related Work Cowork Task: Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets Core AI Issue: Core Task: Related PR: ## Scope What is intentionally included? - Mọi đường ra mạng do app tự mở, trừ nhà cung cấp AI (xem Summary). - Test: `tests/test_network_guard_lanes.py` (có bài chạy AppContainer thật trên Windows), `tests/ui/test_html_preview_remote_images.py`. What is intentionally NOT included? - Chặn cả nhà cung cấp AI / chạy model trên máy (Phương án 2). - Terminal người dùng tự gõ trong tab Folder, sinh ảnh, cơ chế tự tin chứng chỉ lạ (`tls_trust`). - Huy hiệu trạng thái "đang chặn" trên thanh trên cùng. ## Validation - [x] Unit tests - [x] Integration tests - [x] Manual verification - [x] Regression check Commands / evidence: - `python -m pytest tests/test_network_guard_lanes.py tests/test_sandbox_block_network.py tests/ui -q` → chỉ còn 1 bài fail, fail cả trên `b7a41b3` (nhãn `ProjectRow` 'Project' chưa dịch, `tests/ui/test_i18n_khong_con_chu_cu.py`). - `python -m pytest tests -q --ignore=tests/ui` → 4 bài fail, cả 4 cũng fail trên `b7a41b3` (`test_canonical_audit_logger`, 2 bài `test_mcp_audit_security`, `test_monitoring_tab_container`). - Chạy cả `tests` trong một lượt thì treo ở các test dựng MainWindow trong `tests/ui`; `b7a41b3` cũng treo đúng chỗ đó. - `check_imports.py` và `check_orphan_modules.py` PASS. `check_loc.py` báo 9 file quá dài, giống hệt trước khi sửa (không file nào do nhánh này làm dài thêm). - Kiểm tra tay trên Windows 11: trong AppContainer, Python báo `WinError 10013`, ping/nslookup/PowerShell/curl đều không ra được mạng; cmd, git, python chạy bình thường. - Kiểm tra tay trên Windows 11: xem trước HTML tải được 4/4 tài nguyên web khi mạng mở, 0/4 khi bật chặn; tab Graph hoạt động; tạo/huỷ trang xem trước nhiều lần không còn cảnh báo profile của Qt. ## Security Impact Permission / credential / network / customer data impact: - Network: khi bật công tắc, chỉ nhà cung cấp AI còn ra mạng; nội dung chat vẫn gửi tới nhà cung cấp AI. - Permission: lần đầu chạy lệnh trong sandbox, app **thêm quyền (ACE) cho SID AppContainer** trên thư mục làm việc (ghi), thư mục cài Python gốc (đọc), gốc venv và `Scripts` (đọc). Không xoá quyền nào. Thư mục chứa PySide6 không bao giờ nhận quyền kế thừa; một quyền kế thừa sai trên venv (từ bản dev trước) được tự gỡ. - Credential: không đổi. Khi chặn, trạng thái đăng nhập M365 được đọc thẳng từ kho token trên máy, không dựng MSAL. ## Compatibility - [x] No breaking change - [ ] Breaking change documented Ghi chú: `block_network` mặc định đổi từ bật sang tắt cho cấu hình mới; máy đã lưu `true` thì giữ nguyên. Khi đang chặn, lệnh dùng công cụ cài trong thư mục người dùng (ngoài Program Files) có thể báo Access denied; thư viện trong venv của app không dùng được trong sandbox. ## Reviewer Notes - `infrastructure/sandbox/appcontainer_process.py` gọi Win32 bằng ctypes (CreateAppContainerProfile, CreateProcessW với SECURITY_CAPABILITIES) và dùng `icacls` để cấp quyền: nên xem kỹ phần cấp quyền. - `tests/conftest.py` thêm fixture autouse gỡ `network_guard` sau mỗi test, vì `build_context()` gắn cổng này ở mức process. - `core/task_executors.py` đang đúng bằng trần LOC nên `_run_script` được tách sang `core/task_script.py`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: minhanhpkpro <minhanhpkpro@gmail.com> Co-authored-by: Duy Le Huu <duylh19@fpt.com> Co-authored-by: thanhnv <thanhnv.ip@gmail.com> Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
+61
-16
@@ -27,13 +27,14 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from ..i18n import on_language_changed, tr
|
||||
from ..presentation.workspace.project_editing import ProjectEditingMixin, ProjectRow
|
||||
from ..presentation.workspace.project_folder_rules import ProjectFolderRuleMixin, folder_taken_blocked
|
||||
from ..state import AppContext
|
||||
from .icons import collapse_left_icon, icon
|
||||
from .osutil import open_folder
|
||||
from .widgets import CollapseStrip
|
||||
|
||||
|
||||
class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
class WorkspaceTab(ProjectEditingMixin, ProjectFolderRuleMixin, QWidget):
|
||||
"""Trang chủ Workspace: cột project, cột lịch sử, và 5 sub-tab
|
||||
(Dự án · Cowork · Co4E · Thư mục · GraphRAG).
|
||||
|
||||
@@ -202,27 +203,26 @@ class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
cpl.addWidget(self._cowork)
|
||||
self._cowork_tab_idx = self.tabs.addTab(cowork_page, tr("workspace.tab_cowork"))
|
||||
|
||||
# Co4E — node-graph workflow studio (built-in flows, agents, skills, a
|
||||
# runner + chat). Always available (not project-gated): its workflows
|
||||
# live globally under ~/.cowork_local/co4e, not inside one project.
|
||||
# Placed BEFORE GraphRAG in the tab order (user request).
|
||||
from .co4e_tab import Co4ETab
|
||||
|
||||
self._co4e = Co4ETab(self.ctx)
|
||||
self._co4e_tab_idx = self.tabs.addTab(self._co4e, tr("workspace.tab_co4e"))
|
||||
# Co4E and Folder are intentionally placeholders at startup. Their
|
||||
# widget trees pull in a large amount of Qt/UI code, but neither is on
|
||||
# the initial Project surface. The real page is created exactly once
|
||||
# when its tab is first selected (see _ensure_heavy_tab).
|
||||
self._co4e = None
|
||||
self._folder = None
|
||||
self._co4e_placeholder = QWidget()
|
||||
self._folder_placeholder = QWidget()
|
||||
self._co4e_tab_idx = self.tabs.addTab(self._co4e_placeholder, tr("workspace.tab_co4e"))
|
||||
self.tabs.setTabToolTip(self._co4e_tab_idx, tr("workspace.tab_co4e_tooltip"))
|
||||
|
||||
# Folder — a two-pane file explorer (tree + view/edit) placed right below
|
||||
# Co4E. Always available (not project-gated); its root follows the
|
||||
# selected project's workspace folder when one is chosen.
|
||||
from ..presentation.folder.folder_tab import FolderTab
|
||||
self._folder_tab_idx = self.tabs.addTab(self._folder_placeholder, tr("workspace.tab_folder"))
|
||||
|
||||
self._folder = FolderTab(self.ctx, cowork=self._cowork)
|
||||
self._folder.status_message.connect(self.status_message)
|
||||
self._folder_tab_idx = self.tabs.addTab(self._folder, tr("workspace.tab_folder"))
|
||||
|
||||
if self._structure is not None:
|
||||
self._graphrag_tab_idx = self.tabs.addTab(self._structure, tr("workspace.tab_graphrag"))
|
||||
self._graph_placeholder = QWidget()
|
||||
self._graphrag_tab_idx = self.tabs.addTab(
|
||||
self._structure if self._structure is not None else self._graph_placeholder,
|
||||
tr("workspace.tab_graphrag"))
|
||||
|
||||
self.tabs.currentChanged.connect(self._on_tab_changed)
|
||||
|
||||
@@ -307,6 +307,7 @@ class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
cloud_row.addWidget(self._cloud_sync_btn)
|
||||
cloud_row.addStretch(1)
|
||||
rl.addLayout(cloud_row)
|
||||
self._cloud_pick_btn.hide()
|
||||
self._cloud_badge_lbl = QLabel()
|
||||
self._cloud_badge_lbl.setWordWrap(True)
|
||||
self._cloud_badge_lbl.hide()
|
||||
@@ -420,10 +421,50 @@ class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
|
||||
Dựng lười như vậy chính là thứ giữ cho RAM lúc khởi động ở mức thấp.
|
||||
"""
|
||||
if idx in (self._co4e_tab_idx, self._folder_tab_idx, self._graphrag_tab_idx):
|
||||
self._ensure_heavy_tab(idx)
|
||||
if idx == self._graphrag_tab_idx and self._structure is not None:
|
||||
self._structure.auto_scan_and_fit()
|
||||
self._apply_pane_visibility()
|
||||
|
||||
def _ensure_heavy_tab(self, idx: int):
|
||||
"""Build a heavy Workspace child once, replacing its placeholder."""
|
||||
if idx == self._co4e_tab_idx and self._co4e is None:
|
||||
from .co4e_tab import Co4ETab
|
||||
real = Co4ETab(self.ctx)
|
||||
self._co4e = real
|
||||
self.tabs.removeTab(idx)
|
||||
self.tabs.insertTab(idx, real, tr("workspace.tab_co4e"))
|
||||
self.tabs.setCurrentIndex(idx)
|
||||
self.tabs.setTabToolTip(idx, tr("workspace.tab_co4e_tooltip"))
|
||||
self._bind_project(self._current_id)
|
||||
return real
|
||||
if idx == self._folder_tab_idx and self._folder is None:
|
||||
from ..presentation.folder.folder_tab import FolderTab
|
||||
real = FolderTab(self.ctx, cowork=self._cowork)
|
||||
real.status_message.connect(self.status_message)
|
||||
self._folder = real
|
||||
self.tabs.removeTab(idx)
|
||||
self.tabs.insertTab(idx, real, tr("workspace.tab_folder"))
|
||||
self.tabs.setCurrentIndex(idx)
|
||||
self._bind_project(self._current_id)
|
||||
return real
|
||||
if idx == self._graphrag_tab_idx and self._structure is None:
|
||||
from ..presentation.graph.structure_graph_view import StructureGraphView
|
||||
real = StructureGraphView(self.ctx)
|
||||
real.status_message.connect(self.status_message)
|
||||
if self._cowork is not None:
|
||||
self._cowork.output_changed.connect(real.schedule_rescan)
|
||||
self._structure = real
|
||||
self.tabs.removeTab(idx)
|
||||
self.tabs.insertTab(idx, real, tr("workspace.tab_graphrag"))
|
||||
self.tabs.setCurrentIndex(idx)
|
||||
self._bind_project(self._current_id)
|
||||
return real
|
||||
return {self._co4e_tab_idx: self._co4e,
|
||||
self._folder_tab_idx: self._folder,
|
||||
self._graphrag_tab_idx: self._structure}.get(idx)
|
||||
|
||||
def _apply_pane_visibility(self) -> None:
|
||||
"""Which side panes accompany each sub-tab:
|
||||
|
||||
@@ -901,6 +942,8 @@ class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
self, tr("workspace.browse_tooltip"), str(project.workspace_dir()))
|
||||
if not chosen:
|
||||
return
|
||||
if folder_taken_blocked(self, chosen, pid):
|
||||
return
|
||||
project.output_dir = chosen
|
||||
save_project(project)
|
||||
self.folder_lbl.setText(chosen)
|
||||
@@ -944,6 +987,8 @@ class WorkspaceTab(ProjectEditingMixin, QWidget):
|
||||
if not cloud_source:
|
||||
return
|
||||
local_dir = WORKSPACES_DIR / project.project_id / "_cloud_mirror"
|
||||
if folder_taken_blocked(self, str(local_dir), pid):
|
||||
return
|
||||
self._cloud_pick_btn.setEnabled(False)
|
||||
try:
|
||||
token = self._cloud_token()
|
||||
|
||||
Reference in New Issue
Block a user