Files
add-todo-all/examples/todo_skill/scripts/util/runtime_paths.py
2026-09-09 10:29:02 +08:00

33 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""技能数据目录与 DB 路径解析(简化版)。
真实模板用 ``jiangchang_skill_core.runtime_env``;本 demo 复用其 mock。
数据目录 = ``{data_root}/{user_id}/{slug}/``,DB 即 ``{slug}.db``。
"""
from __future__ import annotations
import os
from jiangchang_skill_core.runtime_env import get_data_root, get_user_id
from util.constants import SKILL_SLUG
_SCRIPTS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def get_skill_root() -> str:
"""技能根目录(含 SKILL.md / scripts/ 的目录)。"""
return os.path.dirname(_SCRIPTS_DIR)
def get_skill_data_dir() -> str:
"""本技能数据目录:``{data_root}/{user_id}/{slug}/``。"""
path = os.path.join(get_data_root(), get_user_id(), SKILL_SLUG)
os.makedirs(path, exist_ok=True)
return path
def get_db_path(filename: str | None = None) -> str:
"""SQLite 文件路径,默认 ``{slug}.db``。"""
name = filename or f"{SKILL_SLUG}.db"
return os.path.join(get_skill_data_dir(), name)