## Summary epic r04 - begin refactor ## Change Type - [x] Cowork feature - [ ] Bug fix - [ ] Core AI contribution - [ ] Test / hardening - [ ] 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? What is intentionally NOT included? ## Validation - [ ] Unit tests - [ ] Integration tests - [ ] Manual verification - [ ] Regression check Commands / evidence: ## Security Impact Permission / credential / network / customer data impact: ## Compatibility - [ ] No breaking change - [ ] Breaking change documented ## Reviewer Notes Anything Cowork reviewers should pay attention to. --------- Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com> Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com> Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com> Co-authored-by: Vu Dam Tuan <vudt15@fpt.com> Co-authored-by: Hiep Ha Van <hiephv3@fpt.com> Co-authored-by: Lam Hoang Van <lamhv7@fpt.com> Reviewed-on: #7 Co-authored-by: Duy Le Huu <duylh19@fpt.com>
This commit was merged in pull request #7.
This commit is contained in:
+12
-3
@@ -44,6 +44,11 @@ STARTER_PROJECT_NAME = "My Workspace"
|
||||
|
||||
@dataclass
|
||||
class Project:
|
||||
"""Một project: id, tên, mô tả, chỉ dẫn chung và thư mục sandbox.
|
||||
|
||||
Chỉ dẫn chung được chèn vào MỌI lượt chat thuộc project, nên đây là chỗ đặt
|
||||
bối cảnh dùng lại thay vì gõ lại ở từng tin nhắn.
|
||||
"""
|
||||
project_id: str
|
||||
name: str
|
||||
description: str = ""
|
||||
@@ -92,6 +97,7 @@ def ensure_starter_project(directory: Path = None) -> Project:
|
||||
|
||||
|
||||
def _slugify(name: str) -> str:
|
||||
"""Định danh an toàn cho tên file, suy từ tên project."""
|
||||
s = "".join(c if (c.isalnum() or c in "-_") else "-" for c in name.strip().lower())
|
||||
s = "-".join(filter(None, s.split("-")))
|
||||
return s or "project"
|
||||
@@ -115,11 +121,14 @@ def new_project(name: str, description: str = "", instructions: str = "",
|
||||
|
||||
|
||||
def save_project(project: Project, directory: Path = None) -> Path:
|
||||
"""Ghi một project ra ``<project_id>.json`` (ghi nguyên tử)."""
|
||||
directory = directory or PROJECTS_DIR
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
path = directory / f"{project.project_id}.json"
|
||||
path.write_text(json.dumps(asdict(project), ensure_ascii=False, indent=2),
|
||||
encoding="utf-8")
|
||||
# R06-T02: atomic write — a crash/kill between truncate and write used to
|
||||
# leave a half-written project.json that load_project() then silently
|
||||
# treats as "missing" (see infrastructure/persistence/json/atomic_write.py).
|
||||
from ..infrastructure.persistence.json.atomic_write import write_json
|
||||
write_json(path, asdict(project))
|
||||
return path
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user