claude-migrate 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/migrate.py ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env python3
2
+ """claude-migrate: move a Claude Code setup (config + history) to another Mac."""
3
+ import argparse
4
+ import datetime
5
+ import os
6
+ import sys
7
+
8
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9
+
10
+ import json
11
+
12
+ from cm_bundle import export_bundle, scan_components
13
+ from cm_layout import discover
14
+ from cm_import import (BundleError, PlanError, RunningError, apply_import, build_plan, default_mapping_path,
15
+ format_plan, propose_mapping, verify_bundle)
16
+ from cm_paths import PathMapper
17
+ from cm_ui import UI
18
+ import cm_wizard
19
+
20
+
21
+ def human(n):
22
+ for unit in ("B", "KB", "MB", "GB"):
23
+ if n < 1024 or unit == "GB":
24
+ return "%.1f %s" % (n, unit) if unit != "B" else "%d B" % n
25
+ n /= 1024.0
26
+
27
+
28
+ def parse_components(args, layout):
29
+ """Turn --only / --exclude into a component list (None = everything). Raises ValueError on unknown ids."""
30
+ all_ids = [c[0] for c in layout.components()]
31
+
32
+ def ids(value):
33
+ got = [x.strip() for x in value.split(",") if x.strip()]
34
+ unknown = sorted(set(got) - set(all_ids))
35
+ if unknown:
36
+ raise ValueError("unknown component(s): %s (see --list-components)" % ", ".join(unknown))
37
+ return got
38
+ if args.only:
39
+ return ids(args.only)
40
+ if args.exclude:
41
+ drop = set(ids(args.exclude))
42
+ return [c for c in all_ids if c not in drop]
43
+ return None
44
+
45
+
46
+ def print_components(home):
47
+ layout = discover(home)
48
+ scan = scan_components(home, layout)
49
+ print("%-15s %-40s %8s %s" % ("ID", "WHAT", "SIZE", "FILES"))
50
+ for cid, label, hint in layout.components():
51
+ info = scan[cid]
52
+ print("%-15s %-40s %8s %d" % (cid, label + (" (%s)" % hint if hint else ""), human(info["bytes"]), info["files"]))
53
+
54
+
55
+ def cmd_export(args):
56
+ if args.list_components:
57
+ print_components(args.home)
58
+ return 0
59
+ try:
60
+ layout = discover(args.home)
61
+ components = parse_components(args, layout)
62
+ except ValueError as e:
63
+ print("error: %s" % e, file=sys.stderr)
64
+ return 2
65
+ out = args.out or "claude-migrate-%s.tar.gz" % datetime.date.today().isoformat()
66
+ rep = export_bundle(args.home, out, no_history=args.no_history, no_plugins=args.no_plugins, components=components,
67
+ layout=layout)
68
+ print("Bundle: %s (%s)" % (rep["out"], human(rep["bytes"])))
69
+ print("Files: %d Projects: %d" % (rep["files"], rep["projects"]))
70
+ print("Masked: %d secret value(s). Re-enter these on the new Mac:" % len(rep["masked"]))
71
+ for m in rep["masked"]:
72
+ print(" - " + m)
73
+ for s in rep["skipped"]:
74
+ print("Skipped (unparseable JSON): " + s)
75
+ for s in rep["excluded_sensitive"]:
76
+ print("Excluded (credential file): " + s)
77
+ for w in rep["warnings"]:
78
+ print("Warning: " + w)
79
+ return 0
80
+
81
+
82
+ def cmd_import(args):
83
+ try:
84
+ manifest = verify_bundle(args.bundle)
85
+ except BundleError as e:
86
+ print("error: %s" % e, file=sys.stderr)
87
+ return 1
88
+ mapping_path = args.mapping or default_mapping_path(args.bundle)
89
+ if os.path.exists(mapping_path):
90
+ mapper = PathMapper.from_file(mapping_path)
91
+ else:
92
+ proposal = propose_mapping(manifest, args.home)
93
+ with open(mapping_path, "w") as f:
94
+ json.dump(proposal, f, indent=2)
95
+ mapper = PathMapper(proposal["default"], proposal["projects"])
96
+ print("Wrote %s - edit it, then re-run to see the updated plan.\n" % mapping_path)
97
+ plan = build_plan(manifest, mapper, args.home)
98
+ print(format_plan(plan, manifest, args.home, mapping_path))
99
+ if plan["errors"]:
100
+ return 1
101
+ if not args.apply:
102
+ print("\nDry run only. Re-run with --apply to import.")
103
+ return 0
104
+ try:
105
+ rep = apply_import(args.bundle, mapper, args.home, force=args.force, zsh=args.zsh)
106
+ except (PlanError, RunningError, BundleError) as e:
107
+ print("error: %s" % e, file=sys.stderr)
108
+ return 1
109
+ print_apply_report(rep, args)
110
+ return 1 if rep["problems"] else 0
111
+
112
+
113
+ def print_apply_report(rep, args):
114
+ print("\nImported: %d file(s) written." % rep["written"])
115
+ if rep["backup"]:
116
+ print("Backup of replaced files: %s" % rep["backup"])
117
+ for w in rep["warnings"]:
118
+ print("warning: " + w)
119
+ for p in rep["problems"]:
120
+ print("PROBLEM: " + p)
121
+ if rep["zsh_lines"]:
122
+ if rep["zsh_installed"]:
123
+ print("\nAdded to ~/.zshrc between claude-migrate markers (secrets left commented):")
124
+ for l in rep["zsh_lines"]:
125
+ print(" " + l)
126
+ else:
127
+ print("\nShell aliases from the old Mac (add to ~/.zshrc, or re-run with --zsh):")
128
+ for l in rep["zsh_lines"]:
129
+ print(" " + l)
130
+ print("\nNext steps:")
131
+ print(" 1. Run `claude` and sign in with /login (credentials are never copied).")
132
+ print(" 2. Re-enter any masked API keys (see the export report).")
133
+ print(" 3. Open a project and use /resume to check your history.")
134
+
135
+
136
+ def build_parser():
137
+ p = argparse.ArgumentParser(
138
+ prog="claude-migrate", description=__doc__,
139
+ epilog="Run with no arguments in a terminal for the guided wizard.")
140
+ p.add_argument("--home", default=os.path.expanduser("~"), help="home directory the wizard works on (default: ~)")
141
+ sub = p.add_subparsers(dest="command")
142
+ e = sub.add_parser("export", help="write a portable bundle from this Mac")
143
+ e.add_argument("--home", default=os.path.expanduser("~"), help="home directory to export (default: ~)")
144
+ e.add_argument("--out", help="bundle path (default: ./claude-migrate-<date>.tar.gz)")
145
+ e.add_argument("--no-history", action="store_true",
146
+ help="shortcut: skip history, memory, prompt history and file history")
147
+ e.add_argument("--no-plugins", action="store_true", help="shortcut: skip plugins and marketplaces")
148
+ pick = e.add_mutually_exclusive_group()
149
+ pick.add_argument("--only", metavar="IDS", help="export only these comma-separated components")
150
+ pick.add_argument("--exclude", metavar="IDS", help="export everything except these comma-separated components")
151
+ e.add_argument("--list-components", action="store_true", help="show the components, sizes and exit")
152
+ e.set_defaults(func=cmd_export)
153
+ i = sub.add_parser("import", help="plan (and with --apply, perform) an import on this Mac")
154
+ i.add_argument("bundle", help="bundle produced by `export`")
155
+ i.add_argument("--home", default=os.path.expanduser("~"), help="target home directory (default: ~)")
156
+ i.add_argument("--mapping", help="mapping file (default: <bundle>.mapping.json, created if missing)")
157
+ i.add_argument("--apply", action="store_true", help="perform the import (default is a dry run)")
158
+ i.add_argument("--force", action="store_true", help="import even if Claude Code is running")
159
+ i.add_argument("--zsh", action="store_true", help="add the Claude aliases to ~/.zshrc (marked block)")
160
+ i.set_defaults(func=cmd_import)
161
+ return p
162
+
163
+
164
+ def main(argv=None):
165
+ parser = build_parser()
166
+ args = parser.parse_args(argv)
167
+ if not getattr(args, "func", None):
168
+ if sys.stdin.isatty() and sys.stdout.isatty():
169
+ return cm_wizard.run(UI(), args.home)
170
+ parser.print_help()
171
+ return 2
172
+ return args.func(args)
173
+
174
+
175
+ if __name__ == "__main__":
176
+ sys.exit(main())
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "claude-migrate",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Move your Claude Code setup (config, plugins, history) to a new Mac, with project paths re-mapped.",
5
+ "bin": {
6
+ "claude-migrate": "bin/claude-migrate.js"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "*.py",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "os": [
15
+ "darwin"
16
+ ],
17
+ "engines": {
18
+ "node": ">=16"
19
+ },
20
+ "scripts": {
21
+ "test": "python3 -m unittest discover -s tests && node --test test/*.test.js"
22
+ },
23
+ "keywords": [
24
+ "claude",
25
+ "claude-code",
26
+ "migrate",
27
+ "macos",
28
+ "backup",
29
+ "dotfiles"
30
+ ],
31
+ "author": "Hackoak",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/Hackoak/claude-migrate.git"
36
+ },
37
+ "homepage": "https://github.com/Hackoak/claude-migrate#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/Hackoak/claude-migrate/issues"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }