feat: add standard init-db CLI for host install schema ensure
All checks were successful
技能自动化发布 / release (push) Successful in 4s

This commit is contained in:
2026-07-14 17:26:24 +08:00
parent af7a43a702
commit 6b64aad138
11 changed files with 76 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ from typing import List, Optional
from service.task_service import (
cmd_config_path,
cmd_health,
cmd_init_db,
cmd_log_get,
cmd_logs,
cmd_run,
@@ -62,6 +63,7 @@ def _print_full_usage() -> None:
print(" python main.py health")
print(" python main.py config-path")
print(" python main.py version")
print(" python main.py init-db")
def build_parser() -> ZhArgumentParser:
@@ -99,6 +101,9 @@ def build_parser() -> ZhArgumentParser:
sp = sub.add_parser("version", help="版本信息(JSON)")
sp.set_defaults(handler=lambda _a: cmd_version())
sp = sub.add_parser("init-db", help="幂等初始化本地数据库与数据管理元数据")
sp.set_defaults(handler=lambda _a: cmd_init_db())
return p
@@ -111,7 +116,8 @@ def main(argv: Optional[List[str]] = None) -> int:
_print_full_usage()
return 1
if len(argv) == 2 and argv[0] not in {
"run", "logs", "log-get", "health", "config-path", "version", "-h", "--help"
"run", "logs", "log-get", "health", "config-path", "version", "init-db",
"-h", "--help",
}:
return cmd_run(target=argv[0], input_id=argv[1])
parser = build_parser()

View File

@@ -26,8 +26,9 @@ from service.task_run_support import (
)
from util.constants import LOG_LOGGER_NAME, PLATFORM_KIT_MIN_VERSION, SKILL_SLUG, SKILL_VERSION
from util.logging_config import get_skill_logger, setup_skill_logging
from util.runtime_paths import get_skill_data_dir, get_skill_root
from util.runtime_paths import get_db_path, get_skill_data_dir, get_skill_root
from util.timeutil import unix_to_iso
from db.connection import init_db
def _get_task_logger():
@@ -292,3 +293,28 @@ def cmd_health() -> int:
def cmd_version() -> int:
print(json.dumps({"version": SKILL_VERSION, "skill": SKILL_SLUG}, ensure_ascii=False))
return 0
def cmd_init_db() -> int:
"""幂等创建/迁移本地 SQLite 与数据管理元数据(宿主 install/upgrade 可调用)。"""
try:
init_db()
except Exception as exc: # noqa: BLE001 — CLI 边界,统一成可机读失败
print(
json.dumps(
{"ok": False, "skill": SKILL_SLUG, "error": str(exc)},
ensure_ascii=False,
)
)
return 1
print(
json.dumps(
{
"ok": True,
"skill": SKILL_SLUG,
"db_path": get_db_path(),
},
ensure_ascii=False,
)
)
return 0

View File

@@ -1,6 +1,6 @@
"""技能标识、版本与平台公共库约束(复制后请修改 slug/version/logger"""
SKILL_SLUG = "your-skill-slug"
SKILL_VERSION = "1.0.40"
SKILL_VERSION = "1.0.42"
LOG_LOGGER_NAME = "openclaw.skill.your_skill_slug"
PLATFORM_KIT_MIN_VERSION = "1.2.0"