- Trang file:// cần LocalContentCanAccessRemoteUrls mới tải được ảnh, CSS, JS trên web; khi bật "Chặn mạng" bộ chặn request vẫn chặn. - Dùng một QWebEngineProfile chung thuộc QApplication: profile do view sở hữu bị huỷ trước trang, Qt báo "Release of profile requested but WebEnginePage still not deleted" và app văng (0xc0000409 trong Qt6Core.dll) khi chuyển tab Graph sang Folder. - Giữ tham chiếu Python tới bộ chặn request để nó không bị thu gom. - Thêm CLAUDE.md hướng dẫn làm việc trong repo. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
7.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project
Cowork Local (user-facing brand "Cowork-Local BamBOO") is a local-first PySide6 desktop app: multi-turn AI agents, per-project workspaces with GraphRAG, scheduled agent tasks (Kanban), MCP connectors, a sandbox security layer, model routing, and a monitoring dashboard. User config lives in ~/.cowork_local. The internal name cowork_local / APP_NAME must not be rebranded. Only DISPLAY_NAME is the brand.
The package-name quirk (read first)
The repository root is the cowork_local package: __init__.py and __main__.py sit at the root, and code imports itself as cowork_local.* or through relative imports. This checkout's folder is not named cowork_local, so:
- Running the app:
python -m cowork_localworks only from the parent of a folder literally namedcowork_local. On Windows,install.bat(once; add--devfor test deps,--systemto skip the venv) builds a venv under%LOCALAPPDATA%\CoworkLocaland creates a junction%LOCALAPPDATA%\CoworkLocal\launcher\<key>\cowork_localpointing at this checkout. After that, userun.bat. The MS365 MCP server is spawned aspython -m cowork_local.mcp_servers.ms365_server, so the junction is needed for subprocesses too. - Never create a
.venvinside the repo. The quality gates walk the whole tree. - Tests: the root
conftest.pyandtests/conftest.pybindsys.modules["cowork_local"]to this checkout, so pytest works whatever the folder is named. Tests use both import styles: top-level (from providers.base import ...) and qualified (from cowork_local.core... import ...). Characterization tests that spawnpython -c "from cowork_local..."subprocesses still need a realcowork_localdirectory onPYTHONPATH. CI checks out intocowork_local/for this reason.
Commands
python -m pip install -r requirements.txt # single requirements file (includes pytest)
python -m pytest tests -q # full suite (what CI runs)
python -m pytest tests/unit/test_schedule_calculator.py -q # one file
python -m pytest tests/unit/test_schedule_calculator.py -k name -q # one test
python -m pytest tests/e2e/test_smoke.py -v # release smoke test
python scripts/run_quality_gate.py # all CASAN gates + pytest
python scripts/run_quality_gate.py --skip-tests # static gates only
python scripts/check_imports.py # domain/ + application/ must not import PySide6/PyQt/ui/app
python scripts/audit_security.py # no plaintext credentials (CI also runs --self-test)
python scripts/check_loc.py # <= 400 lines per production file
python scripts/check_orphan_modules.py # every production module must be reachable by import
Widget tests run headless with QT_QPA_PLATFORM=offscreen. tools/check_*.py are standalone offscreen smoke checkers against a real MainWindow built on a copy of ~/.cowork_local (for example python tools/check_nav.py). Some of them still import private names re-exported from app.py, so keep those re-exports. Set COWORK_PERF_TRACE=1 to log timing spans from performance.py.
Architecture
Target design is 4-tier Clean Architecture (docs/architecture/ADR-001-layered-architecture.md):
domain/: pure stdlib entities, frozen request snapshots (ConversationExecutionRequest),AgentEvent, tool/provider descriptors,ScheduleCalculator.application/: pure-Python use-case services (conversations, model_routing, scheduling, workspaces, monitoring, workflows). No Qt. Must run headless.infrastructure/: adapters: config (JsonConfigRepositoryoverAtomicJsonFile), OS-keyringSecretStore, providers, MCP (McpToolSourceManager), sandbox, filesystem, telemetry, and Qt bridges (infrastructure/qt).presentation/: PySide6 widgets by feature (shell,chat,co4e,dashboard,scheduling,workspace,monitoring,graph,settings, ...). Widgets callapplication/services. They don't touch persistence or run LLM calls on the GUI thread. Agent work runs in worker threads and reaches the UI asAgentEvents through Qt signal bridges.
The refactor is incomplete. Legacy top-level packages are still live and imported by the app:
ui/: older tabs such ascowork_tab,workspace_tab,monitoring_tab,settings_dialog,chat_panel, andco4e_*.core/: agents, the Co4E flow runner, task scheduler, skills, tools, audit/usage tracking, routing.providers/:base,anthropic,openai_compat,factory.security/: validators, command risk classifier.- Root modules:
config.py,state.py.
docs/architecture/dormant-code.md lists deprecated pieces, such as state.py::active_project_id and the monolithic core/tools.py. New layers must not import dormant code.
Wiring:
__main__.py→app.run().presentation/shell/bootstrap.pyis the Composition Root. It buildsAppContext(state.py) aroundJsonConfigRepositoryplusKeyringAdapter, falling back to the config file when no keyring exists.run()then seeds the built-in skills (skill_library/*.skill) and the Co4E flows, applies the theme, and openspresentation/shell/main_window.MainWindow.- Pages are registered in
presentation/shell/page_registry.py.
Other cross-cutting pieces:
i18n/:tr(key, **kw)with en/ja/vi (defaultvi). Long-lived widgets must usebind_text(...)oron_language_changed(...)so a language switch re-applies their text. Transient dialogs just calltr()at construction.theme/: palettes and QSS. Use theme tokens, not hard-coded colors.mcp_servers/: bundled MCP servers (MS365, project_context).agent/: a markdown instruction library for UI/UX bug-fix agents, not runtime code.
Step-by-step recipes for adding a provider, a tool or MCP server, or a screen are in docs/governance/contributor-recipes.md.
Rules enforced by gates and review
- 400-line limit for every production file. This covers
domain,application,infrastructure,presentation,ui,core,providers,security,mcp_servers,i18n,theme, and root.pyfiles. Legacy oversized files have per-file caps inscripts/check_loc.pythat may only go down. Split files; never raise a cap. - No orphan modules.
check_orphan_modules.pyhas anALLOWLISTthat may only shrink. Wire up or delete a module instead of allowlisting it. - Secrets belong in the OS keyring, never in
config.jsonor the code..env.exampleis not auto-loaded. Tests never use live provider credentials (usetests/fakes/:FakeProvider,FakeToolExecutor,FakeToolPolicyGateway,FakeConfigRepository/FakeSecretStore,FakeClock, ...). - Test layout:
tests/unit(fast, no I/O),tests/contracts,tests/integration(Qt offscreen),tests/characterization(pinned legacy behavior during refactors),tests/e2e,tests/ui, plus flattests/test_*.py. - Startup housekeeping (seeding, pruning) is wrapped in
try/exceptand must never block app launch. - Comments: the ADR asks for English comments. Existing code mixes English and Vietnamese docstrings and comments, so match the surrounding file.
Git workflow
- Branches:
feat/,fix/,test/,docs/,perf/,refactor/<short-desc>. Core AI work usescore-ai/<task-id>-<name>. - Commits use Conventional Commit prefixes (
feat:,fix:,test:,docs:,refactor:,perf:,chore:). - One logical change per PR, using
.gitea/PULL_REQUEST_TEMPLATE.md. The remote is a Gitea instance, and CI (.gitea/workflows/ci.yaml, Python 3.11) runs on PRs tomain. - Critical areas listed in
SECURITY.mdget extra review.