claudeshift-cli 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import sys
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class RuntimePaths:
11
+ target_home: Path
12
+ is_sandbox: bool
13
+ vault_dir: Path
14
+ config_dir: Path
15
+
16
+
17
+ def get_target_home() -> tuple[Path, bool]:
18
+ """Return (target_home, is_sandbox). Never touches real home if sandbox env is set."""
19
+ override = os.getenv("CLAUDESHIFT_TARGET_HOME", "").strip()
20
+ if override:
21
+ return Path(override).expanduser().resolve(), True
22
+ return Path.home().resolve(), False
23
+
24
+
25
+ def get_vault_dir() -> Path:
26
+ """Resolve XDG-compliant / Windows-native vault storage directory."""
27
+ override = os.getenv("CLAUDESHIFT_VAULT_DIR", "").strip()
28
+ if override:
29
+ return Path(override).expanduser().resolve()
30
+
31
+ xdg_data = os.getenv("XDG_DATA_HOME", "").strip()
32
+ if xdg_data:
33
+ return Path(xdg_data).expanduser().resolve() / "claudeshift"
34
+
35
+ if sys.platform == "win32":
36
+ local_appdata = os.getenv("LOCALAPPDATA", "").strip()
37
+ if local_appdata:
38
+ return Path(local_appdata).resolve() / "claudeshift"
39
+
40
+ return Path.home().resolve() / ".local" / "share" / "claudeshift"
41
+
42
+
43
+ def get_config_dir(is_sandbox: bool = False, vault_dir: Path | None = None) -> Path:
44
+ """Resolve XDG-compliant / Windows-native config directory (isolated in sandbox)."""
45
+ override = os.getenv("CLAUDESHIFT_CONFIG_DIR", "").strip()
46
+ if override:
47
+ return Path(override).expanduser().resolve()
48
+
49
+ if is_sandbox and vault_dir is not None:
50
+ return vault_dir / "_config"
51
+
52
+ xdg_config = os.getenv("XDG_CONFIG_HOME", "").strip()
53
+ if xdg_config:
54
+ return Path(xdg_config).expanduser().resolve() / "claudeshift"
55
+
56
+ if sys.platform == "win32":
57
+ appdata = os.getenv("APPDATA", "").strip()
58
+ if appdata:
59
+ return Path(appdata).resolve() / "claudeshift"
60
+
61
+ return Path.home().resolve() / ".config" / "claudeshift"
62
+
63
+
64
+ def resolve_runtime_paths() -> RuntimePaths:
65
+ target_home, is_sandbox = get_target_home()
66
+ vault_dir = get_vault_dir()
67
+ config_dir = get_config_dir(is_sandbox=is_sandbox, vault_dir=vault_dir)
68
+ return RuntimePaths(
69
+ target_home=target_home,
70
+ is_sandbox=is_sandbox,
71
+ vault_dir=vault_dir,
72
+ config_dir=config_dir,
73
+ )
File without changes
@@ -0,0 +1,113 @@
1
+ from __future__ import annotations
2
+
3
+ import base64
4
+ import json
5
+ import re
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from claudeshift.core.models import ProfileIdentity
10
+
11
+
12
+ def _safe_load_json(path: Path) -> dict[str, Any]:
13
+ if not path.is_file():
14
+ return {}
15
+ try:
16
+ data = json.loads(path.read_text(encoding="utf-8", errors="replace"))
17
+ return data if isinstance(data, dict) else {}
18
+ except Exception:
19
+ return {}
20
+
21
+
22
+ def _extract_email_from_jwt(jwt_token: str) -> str:
23
+ """Read-only extraction of email claim from JWT id_token. Never prints or stores tokens."""
24
+ parts = jwt_token.split(".")
25
+ if len(parts) < 2:
26
+ return ""
27
+ segment = parts[1]
28
+ padding = "=" * (-len(segment) % 4)
29
+ try:
30
+ raw = base64.urlsafe_b64decode((segment + padding).encode("ascii"))
31
+ claims = json.loads(raw.decode("utf-8", errors="replace"))
32
+ if isinstance(claims, dict):
33
+ return str(claims.get("email") or "")
34
+ except Exception:
35
+ pass
36
+ return ""
37
+
38
+
39
+ def inspect_identity(provider: str, root_dir: Path) -> ProfileIdentity:
40
+ """Extract non-sensitive metadata (account email, org, model, MCP server names)."""
41
+ if provider == "claude":
42
+ cfg = _safe_load_json(root_dir / ".claude.json")
43
+ settings = _safe_load_json(root_dir / ".claude" / "settings.json")
44
+
45
+ oauth = cfg.get("oauthAccount") or {}
46
+ if not isinstance(oauth, dict):
47
+ oauth = {}
48
+
49
+ account = str(oauth.get("emailAddress") or oauth.get("accountUuid") or "")
50
+ org = str(oauth.get("organizationName") or "")
51
+ model = str(settings.get("model") or "")
52
+
53
+ mcp_names: set[str] = set()
54
+ for source in (cfg.get("mcpServers"), settings.get("mcpServers")):
55
+ if isinstance(source, dict):
56
+ mcp_names.update(str(k) for k in source)
57
+
58
+ return ProfileIdentity(
59
+ account=account,
60
+ organization=org,
61
+ model=model,
62
+ mcp_servers=tuple(sorted(mcp_names)),
63
+ )
64
+
65
+ if provider == "claude-desktop":
66
+ candidates = (
67
+ root_dir / "AppData" / "Roaming" / "Claude" / "claude_desktop_config.json",
68
+ root_dir / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json",
69
+ root_dir / ".config" / "Claude" / "claude_desktop_config.json",
70
+ )
71
+ cfg = {}
72
+ for c in candidates:
73
+ if c.is_file():
74
+ cfg = _safe_load_json(c)
75
+ break
76
+ mcp = cfg.get("mcpServers")
77
+ mcp_names = tuple(sorted(str(k) for k in mcp)) if isinstance(mcp, dict) else ()
78
+ return ProfileIdentity(account="Claude Desktop Profile", mcp_servers=mcp_names)
79
+
80
+ if provider == "codex":
81
+ auth = _safe_load_json(root_dir / ".codex" / "auth.json")
82
+ account = str(auth.get("account") or auth.get("email") or "")
83
+ if not account and isinstance(auth.get("tokens"), dict):
84
+ id_tok = auth["tokens"].get("id_token")
85
+ if isinstance(id_tok, str) and "." in id_tok:
86
+ account = _extract_email_from_jwt(id_tok)
87
+
88
+ model = ""
89
+ toml_path = root_dir / ".codex" / "config.toml"
90
+ if toml_path.is_file():
91
+ text = toml_path.read_text(encoding="utf-8", errors="replace")
92
+ match = re.search(r'^\s*model\s*=\s*["\']([^"\']+)["\']', text, re.MULTILINE)
93
+ if match:
94
+ model = match.group(1)
95
+ return ProfileIdentity(account=account, model=model)
96
+
97
+ if provider == "gemini":
98
+ settings = _safe_load_json(root_dir / ".gemini" / "settings.json")
99
+ account = str(
100
+ settings.get("selectedAuthType")
101
+ or (settings.get("security") or {}).get("auth", {}).get("selectedType", "")
102
+ )
103
+ mcp = settings.get("mcpServers")
104
+ mcp_names = tuple(sorted(str(k) for k in mcp)) if isinstance(mcp, dict) else ()
105
+ return ProfileIdentity(account=account, mcp_servers=mcp_names)
106
+
107
+ if provider == "cursor":
108
+ mcp_cfg = _safe_load_json(root_dir / ".cursor" / "mcp.json")
109
+ mcp = mcp_cfg.get("mcpServers")
110
+ mcp_names = tuple(sorted(str(k) for k in mcp)) if isinstance(mcp, dict) else ()
111
+ return ProfileIdentity(mcp_servers=mcp_names)
112
+
113
+ return ProfileIdentity()
@@ -0,0 +1,98 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict, dataclass, field
4
+ from typing import Any
5
+
6
+
7
+ @dataclass(frozen=True)
8
+ class ProfileIdentity:
9
+ account: str = ""
10
+ organization: str = ""
11
+ model: str = ""
12
+ mcp_servers: tuple[str, ...] = ()
13
+
14
+ def to_dict(self) -> dict[str, Any]:
15
+ return {
16
+ "account": self.account,
17
+ "organization": self.organization,
18
+ "model": self.model,
19
+ "mcp_servers": list(self.mcp_servers),
20
+ }
21
+
22
+ @classmethod
23
+ def from_dict(cls, data: dict[str, Any]) -> ProfileIdentity:
24
+ return cls(
25
+ account=str(data.get("account", "")),
26
+ organization=str(data.get("organization", "")),
27
+ model=str(data.get("model", "")),
28
+ mcp_servers=tuple(data.get("mcp_servers", [])),
29
+ )
30
+
31
+
32
+ @dataclass
33
+ class ProfileManifest:
34
+ schema_version: int
35
+ name: str
36
+ provider: str
37
+ created_at: str
38
+ updated_at: str
39
+ targets: list[str]
40
+ file_count: int
41
+ total_bytes: int
42
+ checksums: dict[str, str]
43
+ identity: ProfileIdentity = field(default_factory=ProfileIdentity)
44
+ note: str = ""
45
+
46
+ def to_dict(self) -> dict[str, Any]:
47
+ d = asdict(self)
48
+ d["identity"] = self.identity.to_dict()
49
+ return d
50
+
51
+ @classmethod
52
+ def from_dict(cls, data: dict[str, Any]) -> ProfileManifest:
53
+ return cls(
54
+ schema_version=int(data.get("schema_version", 1)),
55
+ name=str(data["name"]),
56
+ provider=str(data["provider"]),
57
+ created_at=str(data["created_at"]),
58
+ updated_at=str(data["updated_at"]),
59
+ targets=list(data.get("targets", [])),
60
+ file_count=int(data.get("file_count", 0)),
61
+ total_bytes=int(data.get("total_bytes", 0)),
62
+ checksums=dict(data.get("checksums", {})),
63
+ identity=ProfileIdentity.from_dict(data.get("identity", {})),
64
+ note=str(data.get("note", "")),
65
+ )
66
+
67
+
68
+ @dataclass(frozen=True)
69
+ class BackupInfo:
70
+ backup_id: str
71
+ provider: str
72
+ created_at: str
73
+ reason: str
74
+ total_bytes: int
75
+ path: str
76
+
77
+
78
+ @dataclass(frozen=True)
79
+ class SwitchResult:
80
+ provider: str
81
+ previous_profile: str | None
82
+ active_profile: str
83
+ synced_previous: bool
84
+ backup_id: str | None
85
+ elapsed_ms: float
86
+
87
+
88
+ @dataclass(frozen=True)
89
+ class ProfileDiff:
90
+ provider: str
91
+ profile_a: str
92
+ profile_b: str
93
+ only_in_a_mcp: tuple[str, ...]
94
+ only_in_b_mcp: tuple[str, ...]
95
+ shared_mcp: tuple[str, ...]
96
+ changed_files: tuple[str, ...]
97
+ only_in_a_files: tuple[str, ...]
98
+ only_in_b_files: tuple[str, ...]