auto-sync: 2026-05-20 20:35:41
This commit is contained in:
@@ -231,7 +231,53 @@ class ProjectRegistry:
|
||||
# 迁移(从 _registry.yaml)
|
||||
# ===================================================================
|
||||
|
||||
def migrate_from_yaml(self, yaml_path: Optional[Path] = None) -> int:
|
||||
def discover_sanguo_projects(self, scan_dir: Optional[Path] = None) -> List[str]:
|
||||
"""扫描 sanguo_projects 开发目录,自动注册正式项目"""
|
||||
scan_dir = scan_dir or Path.home() / ".openclaw" / "sanguo_projects"
|
||||
discovered = []
|
||||
|
||||
if not scan_dir.exists():
|
||||
return discovered
|
||||
|
||||
conn = self._connect()
|
||||
try:
|
||||
for child in sorted(scan_dir.iterdir()):
|
||||
if not child.is_dir():
|
||||
continue
|
||||
if not child.name.startswith("sanguo_"):
|
||||
continue
|
||||
|
||||
# 跳过已注册的(含 deleted/archived)
|
||||
existing = conn.execute(
|
||||
"SELECT id, status FROM projects WHERE id=?", (child.name,)
|
||||
).fetchone()
|
||||
if existing:
|
||||
continue
|
||||
|
||||
# 自动注册,创建 blackboard.db
|
||||
project_dir = self.root / child.name
|
||||
project_dir.mkdir(parents=True, exist_ok=True)
|
||||
for subdir in ("artifacts", "experiences", "skills", "config"):
|
||||
(project_dir / subdir).mkdir(exist_ok=True)
|
||||
|
||||
now = self._now()
|
||||
conn.execute(
|
||||
"""INSERT INTO projects (id, name, description, status, source, created_at)
|
||||
VALUES (?,?,?,?,?,?)""",
|
||||
(child.name, child.name, "auto_discovered", "active",
|
||||
"sanguo_projects_scan", now),
|
||||
)
|
||||
discovered.append(child.name)
|
||||
logger.info("Auto-discovered sanguo project: %s", child.name)
|
||||
|
||||
if discovered:
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
return discovered
|
||||
|
||||
def migrate_from_yaml(self, yaml_path: Optional[Path] = None) -> int: int:
|
||||
"""从旧 _registry.yaml 迁移项目数据"""
|
||||
import yaml
|
||||
|
||||
|
||||
Reference in New Issue
Block a user