Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion astrbot/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import click

from . import __version__
from .commands import conf, init, plug, run
from .commands import conf, init, migrate, plug, run

logo_tmpl = r"""
___ _______.___________..______ .______ ______ .___________.
Expand Down Expand Up @@ -54,6 +54,7 @@ def help(command_name: str | None) -> None:
cli.add_command(help)
cli.add_command(plug)
cli.add_command(conf)
cli.add_command(migrate)

if __name__ == "__main__":
cli()
3 changes: 2 additions & 1 deletion astrbot/cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .cmd_conf import conf
from .cmd_init import init
from .cmd_migrate import migrate
from .cmd_plug import plug
from .cmd_run import run

__all__ = ["conf", "init", "plug", "run"]
__all__ = ["conf", "init", "migrate", "plug", "run"]
83 changes: 83 additions & 0 deletions astrbot/cli/commands/cmd_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from __future__ import annotations

from pathlib import Path

import click

from ..utils import get_astrbot_root
from ..utils.openclaw_migrate import run_openclaw_migration


@click.group(name="migrate")
def migrate() -> None:
"""Data migration utilities for external runtimes."""


@migrate.command(name="openclaw")
@click.option(
"--source",
"source_path",
type=click.Path(path_type=Path, file_okay=False, resolve_path=True),
default=None,
help="Path to OpenClaw root directory (default: ~/.openclaw).",
)
@click.option(
"--target",
"target_path",
type=click.Path(path_type=Path, file_okay=False, resolve_path=True),
default=None,
help=(
"Custom output directory. If omitted, writes to "
"data/migrations/openclaw/run-<timestamp>."
),
)
@click.option(
"--dry-run",
is_flag=True,
default=False,
help="Preview migration candidates without writing files.",
)
def migrate_openclaw(
source_path: Path | None,
target_path: Path | None,
dry_run: bool,
) -> None:
"""Migrate OpenClaw workspace snapshots into AstrBot migration artifacts."""

astrbot_root = get_astrbot_root()
source_root = source_path or (Path.home() / ".openclaw")

report = run_openclaw_migration(
source_root=source_root,
astrbot_root=astrbot_root,
dry_run=dry_run,
target_dir=target_path,
)

click.echo("OpenClaw migration report:")
click.echo(f" Source root: {report.source_root}")
click.echo(f" Source workspace: {report.source_workspace}")
click.echo(f" Dry run: {report.dry_run}")
click.echo(f" Memory entries: {report.memory_entries_total}")
click.echo(f" - sqlite: {report.memory_entries_from_sqlite}")
click.echo(f" - markdown: {report.memory_entries_from_markdown}")
click.echo(f" Workspace files: {report.workspace_files_total}")
click.echo(f" Workspace size: {report.workspace_bytes_total} bytes")
click.echo(f" Config found: {report.config_found}")

if dry_run:
click.echo("")
click.echo("Dry-run mode: no files were written.")
click.echo("Run without --dry-run to perform migration.")
return

click.echo("")
click.echo(f"Migration output: {report.target_dir}")
click.echo(f" Copied files: {report.copied_workspace_files}")
click.echo(f" Imported memories: {report.copied_memory_entries}")
click.echo(f" Timeline written: {report.wrote_timeline}")
click.echo(f" Config TOML written:{report.wrote_config_toml}")
click.echo("Done.")
Comment thread
sourcery-ai[bot] marked this conversation as resolved.


__all__ = ["migrate"]
8 changes: 8 additions & 0 deletions astrbot/cli/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
check_dashboard,
get_astrbot_root,
)
from .openclaw_migrate import (
MemoryEntry,
MigrationReport,
run_openclaw_migration,
)
from .plugin import PluginStatus, build_plug_list, get_git_repo, manage_plugin
from .version_comparator import VersionComparator

__all__ = [
"PluginStatus",
"VersionComparator",
"MemoryEntry",
"MigrationReport",
"build_plug_list",
"check_astrbot_root",
"check_dashboard",
"get_astrbot_root",
"get_git_repo",
"manage_plugin",
"run_openclaw_migration",
]
Loading