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.
- claudeshift/__init__.py +3 -0
- claudeshift/cli.py +634 -0
- claudeshift/config/__init__.py +0 -0
- claudeshift/config/paths.py +73 -0
- claudeshift/core/__init__.py +0 -0
- claudeshift/core/inspector.py +113 -0
- claudeshift/core/models.py +98 -0
- claudeshift/core/vault.py +723 -0
- claudeshift/licensing/__init__.py +0 -0
- claudeshift/licensing/entitlements.py +60 -0
- claudeshift/licensing/gumroad.py +291 -0
- claudeshift/providers/__init__.py +0 -0
- claudeshift/providers/base.py +136 -0
- claudeshift/providers/plan_detector.py +249 -0
- claudeshift/telemetry/__init__.py +0 -0
- claudeshift/telemetry/analytics.py +200 -0
- claudeshift/telemetry/dashboard.py +157 -0
- claudeshift/telemetry/exporter.py +93 -0
- claudeshift/telemetry/parser.py +400 -0
- claudeshift/telemetry/pricing.py +362 -0
- claudeshift_cli-0.1.0.dist-info/METADATA +38 -0
- claudeshift_cli-0.1.0.dist-info/RECORD +26 -0
- claudeshift_cli-0.1.0.dist-info/WHEEL +5 -0
- claudeshift_cli-0.1.0.dist-info/entry_points.txt +3 -0
- claudeshift_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- claudeshift_cli-0.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from claudeshift.licensing.gumroad import load_verified_license
|
|
7
|
+
|
|
8
|
+
FREE_MAX_PROFILES_PER_PROVIDER = 2
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ProFeatureRequiredError(RuntimeError):
|
|
12
|
+
"""Raised when a user invokes a Pro-only capability without an active license."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, feature: str, detail: str) -> None:
|
|
15
|
+
self.feature = feature
|
|
16
|
+
self.detail = detail
|
|
17
|
+
super().__init__(detail)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Entitlements:
|
|
22
|
+
is_pro: bool
|
|
23
|
+
tier_name: str
|
|
24
|
+
max_profiles_per_provider: int | None
|
|
25
|
+
rolling_backups: bool
|
|
26
|
+
profile_diff: bool
|
|
27
|
+
live_dashboard: bool
|
|
28
|
+
csv_export: bool
|
|
29
|
+
license_source: str
|
|
30
|
+
license_email: str = ""
|
|
31
|
+
grace_until: str = ""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_entitlements(config_dir: Path) -> Entitlements:
|
|
35
|
+
"""Resolve current Free vs Pro entitlements using HMAC-verified local license."""
|
|
36
|
+
record, reason = load_verified_license(config_dir)
|
|
37
|
+
if record is not None:
|
|
38
|
+
return Entitlements(
|
|
39
|
+
is_pro=True,
|
|
40
|
+
tier_name="PRO",
|
|
41
|
+
max_profiles_per_provider=None,
|
|
42
|
+
rolling_backups=True,
|
|
43
|
+
profile_diff=True,
|
|
44
|
+
live_dashboard=True,
|
|
45
|
+
csv_export=True,
|
|
46
|
+
license_source="gumroad-verified",
|
|
47
|
+
license_email=record.email,
|
|
48
|
+
grace_until=record.grace_until,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return Entitlements(
|
|
52
|
+
is_pro=False,
|
|
53
|
+
tier_name="FREE",
|
|
54
|
+
max_profiles_per_provider=FREE_MAX_PROFILES_PER_PROVIDER,
|
|
55
|
+
rolling_backups=False,
|
|
56
|
+
profile_diff=False,
|
|
57
|
+
live_dashboard=False,
|
|
58
|
+
csv_export=False,
|
|
59
|
+
license_source=reason,
|
|
60
|
+
)
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import getpass
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import platform
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.parse
|
|
11
|
+
import urllib.request
|
|
12
|
+
import uuid
|
|
13
|
+
from dataclasses import asdict, dataclass
|
|
14
|
+
from datetime import datetime, timedelta, timezone
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
GUMROAD_VERIFY_URL = "https://api.gumroad.com/v2/licenses/verify"
|
|
19
|
+
PLACEHOLDER_PRODUCT_ID = "REPLACE_WITH_GUMROAD_PRODUCT_ID"
|
|
20
|
+
DEFAULT_GUMROAD_PRODUCT_ID = "xmBRCXkC5mrDkN2y5_EOyw=="
|
|
21
|
+
GUMROAD_PRODUCT_URL = "https://mgm15.gumroad.com/l/claudeshift-cli"
|
|
22
|
+
OFFLINE_GRACE_DAYS = 14
|
|
23
|
+
_SIGNING_SALT = "claudeshift::pro::v1::hmac-guard"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class LicenseError(RuntimeError):
|
|
27
|
+
"""Raised when license activation or verification fails."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class LicenseRecord:
|
|
32
|
+
status: str # active | revoked | expired
|
|
33
|
+
key_masked: str
|
|
34
|
+
key_hash: str
|
|
35
|
+
product_id: str
|
|
36
|
+
email: str
|
|
37
|
+
product_name: str
|
|
38
|
+
uses: int
|
|
39
|
+
activated_at: str
|
|
40
|
+
last_verified_at: str
|
|
41
|
+
grace_until: str
|
|
42
|
+
machine_id: str
|
|
43
|
+
signature: str
|
|
44
|
+
|
|
45
|
+
def to_dict(self) -> dict[str, Any]:
|
|
46
|
+
return asdict(self)
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def from_dict(cls, d: dict[str, Any]) -> LicenseRecord:
|
|
50
|
+
return cls(
|
|
51
|
+
status=str(d["status"]),
|
|
52
|
+
key_masked=str(d["key_masked"]),
|
|
53
|
+
key_hash=str(d["key_hash"]),
|
|
54
|
+
product_id=str(d["product_id"]),
|
|
55
|
+
email=str(d.get("email", "")),
|
|
56
|
+
product_name=str(d.get("product_name", "claudeshift Pro")),
|
|
57
|
+
uses=int(d.get("uses", 1)),
|
|
58
|
+
activated_at=str(d["activated_at"]),
|
|
59
|
+
last_verified_at=str(d["last_verified_at"]),
|
|
60
|
+
grace_until=str(d["grace_until"]),
|
|
61
|
+
machine_id=str(d["machine_id"]),
|
|
62
|
+
signature=str(d["signature"]),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def is_production_product_pinned() -> bool:
|
|
67
|
+
"""True once DEFAULT_GUMROAD_PRODUCT_ID is configured to a real Gumroad product."""
|
|
68
|
+
return bool(DEFAULT_GUMROAD_PRODUCT_ID and DEFAULT_GUMROAD_PRODUCT_ID != PLACEHOLDER_PRODUCT_ID)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_gumroad_product_id() -> str:
|
|
72
|
+
"""
|
|
73
|
+
Return the authoritative Gumroad Product ID.
|
|
74
|
+
Once pinned for production, environment overrides are strictly ignored to prevent
|
|
75
|
+
attackers from verifying keys against their own $0 Gumroad products.
|
|
76
|
+
"""
|
|
77
|
+
if is_production_product_pinned():
|
|
78
|
+
return DEFAULT_GUMROAD_PRODUCT_ID
|
|
79
|
+
return os.getenv("CLAUDESHIFT_GUMROAD_PRODUCT_ID", "").strip() or PLACEHOLDER_PRODUCT_ID
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def mask_license_key(key: str) -> str:
|
|
83
|
+
clean = key.strip()
|
|
84
|
+
if len(clean) <= 8:
|
|
85
|
+
return "****"
|
|
86
|
+
return f"{clean[:4]}-****-****-{clean[-4:]}"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_machine_fingerprint() -> str:
|
|
90
|
+
raw = f"{platform.system()}|{platform.node()}|{getpass.getuser()}|{platform.machine()}"
|
|
91
|
+
return hashlib.sha256(raw.encode()).hexdigest()[:24]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _compute_signature(
|
|
95
|
+
status: str,
|
|
96
|
+
key_hash: str,
|
|
97
|
+
product_id: str,
|
|
98
|
+
email: str,
|
|
99
|
+
grace_until: str,
|
|
100
|
+
machine_id: str,
|
|
101
|
+
) -> str:
|
|
102
|
+
payload = f"{status}|{key_hash}|{product_id}|{email}|{grace_until}|{machine_id}"
|
|
103
|
+
secret = f"{_SIGNING_SALT}:{machine_id}".encode()
|
|
104
|
+
return hmac.new(secret, payload.encode(), hashlib.sha256).hexdigest()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def build_signed_record(
|
|
108
|
+
license_key: str,
|
|
109
|
+
product_id: str,
|
|
110
|
+
email: str,
|
|
111
|
+
product_name: str = "claudeshift Pro",
|
|
112
|
+
uses: int = 1,
|
|
113
|
+
now_utc: datetime | None = None,
|
|
114
|
+
) -> LicenseRecord:
|
|
115
|
+
now = now_utc or datetime.now(timezone.utc)
|
|
116
|
+
now_iso = now.isoformat(timespec="seconds")
|
|
117
|
+
grace_iso = (now + timedelta(days=OFFLINE_GRACE_DAYS)).isoformat(timespec="seconds")
|
|
118
|
+
key_hash = hashlib.sha256(license_key.strip().encode()).hexdigest()
|
|
119
|
+
machine_id = get_machine_fingerprint()
|
|
120
|
+
sig = _compute_signature("active", key_hash, product_id, email, grace_iso, machine_id)
|
|
121
|
+
|
|
122
|
+
return LicenseRecord(
|
|
123
|
+
status="active",
|
|
124
|
+
key_masked=mask_license_key(license_key),
|
|
125
|
+
key_hash=key_hash,
|
|
126
|
+
product_id=product_id,
|
|
127
|
+
email=email,
|
|
128
|
+
product_name=product_name,
|
|
129
|
+
uses=uses,
|
|
130
|
+
activated_at=now_iso,
|
|
131
|
+
last_verified_at=now_iso,
|
|
132
|
+
grace_until=grace_iso,
|
|
133
|
+
machine_id=machine_id,
|
|
134
|
+
signature=sig,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def save_license_record(config_dir: Path, record: LicenseRecord) -> Path:
|
|
139
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
|
140
|
+
target = config_dir / "license.json"
|
|
141
|
+
tmp = target.with_suffix(f".{uuid.uuid4().hex[:6]}.tmp")
|
|
142
|
+
tmp.write_text(json.dumps(record.to_dict(), indent=2), encoding="utf-8")
|
|
143
|
+
os.replace(tmp, target)
|
|
144
|
+
return target
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def verify_local_record(record: LicenseRecord, now_utc: datetime | None = None) -> tuple[bool, str]:
|
|
148
|
+
"""Validate product ID pinning, HMAC signature, machine binding, status, and grace window."""
|
|
149
|
+
if record.status != "active":
|
|
150
|
+
return False, f"License status is '{record.status}'."
|
|
151
|
+
|
|
152
|
+
expected_pid = get_gumroad_product_id()
|
|
153
|
+
if expected_pid != PLACEHOLDER_PRODUCT_ID and record.product_id != expected_pid:
|
|
154
|
+
return False, "License belongs to a different product ID."
|
|
155
|
+
|
|
156
|
+
current_machine = get_machine_fingerprint()
|
|
157
|
+
if record.machine_id != current_machine:
|
|
158
|
+
return False, "License cache belongs to a different machine. Re-activate with your Gumroad key."
|
|
159
|
+
|
|
160
|
+
expected_sig = _compute_signature(
|
|
161
|
+
record.status,
|
|
162
|
+
record.key_hash,
|
|
163
|
+
record.product_id,
|
|
164
|
+
record.email,
|
|
165
|
+
record.grace_until,
|
|
166
|
+
record.machine_id,
|
|
167
|
+
)
|
|
168
|
+
if not hmac.compare_digest(expected_sig, record.signature):
|
|
169
|
+
return False, "Local license signature is invalid or tampered."
|
|
170
|
+
|
|
171
|
+
now = now_utc or datetime.now(timezone.utc)
|
|
172
|
+
try:
|
|
173
|
+
grace_dt = datetime.fromisoformat(record.grace_until.replace("Z", "+00:00"))
|
|
174
|
+
if grace_dt.tzinfo is None:
|
|
175
|
+
grace_dt = grace_dt.replace(tzinfo=timezone.utc)
|
|
176
|
+
except ValueError:
|
|
177
|
+
return False, "Invalid license expiration timestamp."
|
|
178
|
+
|
|
179
|
+
if now > grace_dt:
|
|
180
|
+
return False, "Offline grace period (14 days) expired. Re-run 'claudeshift license activate <KEY>' online."
|
|
181
|
+
|
|
182
|
+
return True, "valid"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def load_verified_license(config_dir: Path) -> tuple[LicenseRecord | None, str]:
|
|
186
|
+
license_file = config_dir / "license.json"
|
|
187
|
+
if not license_file.is_file():
|
|
188
|
+
return None, "not_activated"
|
|
189
|
+
try:
|
|
190
|
+
raw = json.loads(license_file.read_text(encoding="utf-8"))
|
|
191
|
+
record = LicenseRecord.from_dict(raw)
|
|
192
|
+
except Exception:
|
|
193
|
+
return None, "corrupted_license_file"
|
|
194
|
+
|
|
195
|
+
ok, reason = verify_local_record(record)
|
|
196
|
+
if not ok:
|
|
197
|
+
return None, reason
|
|
198
|
+
return record, "valid"
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def deactivate_license(config_dir: Path) -> bool:
|
|
202
|
+
license_file = config_dir / "license.json"
|
|
203
|
+
if license_file.is_file():
|
|
204
|
+
license_file.unlink(missing_ok=True)
|
|
205
|
+
return True
|
|
206
|
+
return False
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def verify_with_gumroad(
|
|
210
|
+
license_key: str,
|
|
211
|
+
product_id: str | None = None,
|
|
212
|
+
increment_uses: bool = True,
|
|
213
|
+
timeout_sec: float = 12.0,
|
|
214
|
+
) -> dict[str, Any]:
|
|
215
|
+
"""Verify a license key directly against Gumroad Licenses API v2."""
|
|
216
|
+
clean_key = license_key.strip()
|
|
217
|
+
if not clean_key:
|
|
218
|
+
raise LicenseError("License key cannot be empty.")
|
|
219
|
+
|
|
220
|
+
pid = DEFAULT_GUMROAD_PRODUCT_ID if is_production_product_pinned() else (product_id or get_gumroad_product_id()).strip()
|
|
221
|
+
if not pid or pid == PLACEHOLDER_PRODUCT_ID:
|
|
222
|
+
raise LicenseError(
|
|
223
|
+
"Gumroad Product ID is not configured yet. "
|
|
224
|
+
"Set CLAUDESHIFT_GUMROAD_PRODUCT_ID or configure DEFAULT_GUMROAD_PRODUCT_ID."
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
body = urllib.parse.urlencode(
|
|
228
|
+
{
|
|
229
|
+
"product_id": pid,
|
|
230
|
+
"license_key": clean_key,
|
|
231
|
+
"increment_uses_count": "true" if increment_uses else "false",
|
|
232
|
+
}
|
|
233
|
+
).encode()
|
|
234
|
+
|
|
235
|
+
req = urllib.request.Request(
|
|
236
|
+
GUMROAD_VERIFY_URL,
|
|
237
|
+
data=body,
|
|
238
|
+
headers={
|
|
239
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
240
|
+
"User-Agent": "claudeshift-cli/0.1.0",
|
|
241
|
+
},
|
|
242
|
+
method="POST",
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
with urllib.request.urlopen(req, timeout=timeout_sec) as resp:
|
|
247
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
248
|
+
except urllib.error.HTTPError as err:
|
|
249
|
+
msg = f"HTTP {err.code}"
|
|
250
|
+
try:
|
|
251
|
+
err_body = json.loads(err.read().decode("utf-8"))
|
|
252
|
+
if isinstance(err_body, dict) and err_body.get("message"):
|
|
253
|
+
msg = str(err_body["message"])
|
|
254
|
+
except Exception:
|
|
255
|
+
pass
|
|
256
|
+
raise LicenseError(f"Gumroad rejected license key: {msg}") from err
|
|
257
|
+
except urllib.error.URLError as err:
|
|
258
|
+
raise LicenseError(f"Network error contacting Gumroad: {err.reason}") from err
|
|
259
|
+
except Exception as err:
|
|
260
|
+
raise LicenseError(f"Unexpected verification error: {err}") from err
|
|
261
|
+
|
|
262
|
+
if not data.get("success"):
|
|
263
|
+
raise LicenseError(str(data.get("message") or "Invalid license key."))
|
|
264
|
+
|
|
265
|
+
purchase = data.get("purchase") or {}
|
|
266
|
+
if purchase.get("refunded"):
|
|
267
|
+
raise LicenseError("This license has been refunded and is no longer active.")
|
|
268
|
+
if purchase.get("chargebacked") or purchase.get("disputed"):
|
|
269
|
+
raise LicenseError("This license is suspended due to a payment dispute/chargeback.")
|
|
270
|
+
|
|
271
|
+
return data
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def activate_gumroad_license(
|
|
275
|
+
config_dir: Path,
|
|
276
|
+
license_key: str,
|
|
277
|
+
product_id: str | None = None,
|
|
278
|
+
) -> LicenseRecord:
|
|
279
|
+
pid = DEFAULT_GUMROAD_PRODUCT_ID if is_production_product_pinned() else (product_id or get_gumroad_product_id()).strip()
|
|
280
|
+
resp = verify_with_gumroad(license_key=license_key, product_id=pid, increment_uses=True)
|
|
281
|
+
purchase = resp.get("purchase") or {}
|
|
282
|
+
|
|
283
|
+
record = build_signed_record(
|
|
284
|
+
license_key=license_key,
|
|
285
|
+
product_id=pid,
|
|
286
|
+
email=str(purchase.get("email") or ""),
|
|
287
|
+
product_name=str(purchase.get("product_name") or "claudeshift Pro"),
|
|
288
|
+
uses=int(resp.get("uses") or 1),
|
|
289
|
+
)
|
|
290
|
+
save_license_record(config_dir, record)
|
|
291
|
+
return record
|
|
File without changes
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import sys
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class ProviderSpec:
|
|
12
|
+
id: str
|
|
13
|
+
display_name: str
|
|
14
|
+
targets: tuple[str, ...]
|
|
15
|
+
executables: tuple[str, ...] = ()
|
|
16
|
+
supports_usage_logs: bool = False
|
|
17
|
+
usage_glob: str = ""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class ProviderStatus:
|
|
22
|
+
spec: ProviderSpec
|
|
23
|
+
detected: bool
|
|
24
|
+
installed: bool
|
|
25
|
+
has_data: bool
|
|
26
|
+
found_paths: tuple[Path, ...]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _claude_desktop_targets() -> tuple[str, ...]:
|
|
30
|
+
if sys.platform == "win32":
|
|
31
|
+
targets = ["AppData/Roaming/Claude"]
|
|
32
|
+
# Support Windows Microsoft Store (MSIX) sandboxed Claude Desktop path automatically
|
|
33
|
+
pkgs = Path.home() / "AppData" / "Local" / "Packages"
|
|
34
|
+
if pkgs.is_dir():
|
|
35
|
+
for pkg in sorted(pkgs.glob("Claude_*")):
|
|
36
|
+
roaming = pkg / "LocalCache" / "Roaming" / "Claude"
|
|
37
|
+
if roaming.exists():
|
|
38
|
+
rel = roaming.relative_to(Path.home()).as_posix()
|
|
39
|
+
targets.append(rel)
|
|
40
|
+
break
|
|
41
|
+
return tuple(targets)
|
|
42
|
+
if sys.platform == "darwin":
|
|
43
|
+
return ("Library/Application Support/Claude",)
|
|
44
|
+
return (".config/Claude",)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
PROVIDERS: dict[str, ProviderSpec] = {
|
|
48
|
+
"claude": ProviderSpec(
|
|
49
|
+
id="claude",
|
|
50
|
+
display_name="Claude Code CLI",
|
|
51
|
+
targets=(".claude", ".claude.json"),
|
|
52
|
+
executables=("claude",),
|
|
53
|
+
supports_usage_logs=True,
|
|
54
|
+
usage_glob=".claude/projects/**/*.jsonl",
|
|
55
|
+
),
|
|
56
|
+
"claude-desktop": ProviderSpec(
|
|
57
|
+
id="claude-desktop",
|
|
58
|
+
display_name="Claude Desktop App",
|
|
59
|
+
targets=_claude_desktop_targets(),
|
|
60
|
+
executables=("claude-desktop",),
|
|
61
|
+
supports_usage_logs=False,
|
|
62
|
+
),
|
|
63
|
+
"codex": ProviderSpec(
|
|
64
|
+
id="codex",
|
|
65
|
+
display_name="OpenAI Codex CLI",
|
|
66
|
+
targets=(".codex",),
|
|
67
|
+
executables=("codex",),
|
|
68
|
+
supports_usage_logs=True,
|
|
69
|
+
usage_glob=".codex/sessions/**/*.jsonl",
|
|
70
|
+
),
|
|
71
|
+
"gemini": ProviderSpec(
|
|
72
|
+
id="gemini",
|
|
73
|
+
display_name="Gemini CLI",
|
|
74
|
+
targets=(".gemini",),
|
|
75
|
+
executables=("gemini",),
|
|
76
|
+
supports_usage_logs=False,
|
|
77
|
+
),
|
|
78
|
+
"cursor": ProviderSpec(
|
|
79
|
+
id="cursor",
|
|
80
|
+
display_name="Cursor (MCP / CLI Config)",
|
|
81
|
+
targets=(".cursor",),
|
|
82
|
+
executables=("cursor",),
|
|
83
|
+
supports_usage_logs=False,
|
|
84
|
+
),
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _is_desktop_app_installed(provider_id: str) -> bool:
|
|
89
|
+
if provider_id == "claude-desktop":
|
|
90
|
+
if sys.platform == "win32":
|
|
91
|
+
local_app = Path(os.getenv("LOCALAPPDATA", ""))
|
|
92
|
+
if local_app.is_dir():
|
|
93
|
+
if (local_app / "AnthropicClaude" / "claude.exe").is_file():
|
|
94
|
+
return True
|
|
95
|
+
if (local_app / "Programs" / "claude" / "Claude.exe").is_file():
|
|
96
|
+
return True
|
|
97
|
+
pkgs = local_app / "Packages"
|
|
98
|
+
if pkgs.is_dir() and any(pkgs.glob("Claude_*")):
|
|
99
|
+
return True
|
|
100
|
+
elif sys.platform == "darwin":
|
|
101
|
+
return Path("/Applications/Claude.app").exists()
|
|
102
|
+
elif provider_id == "cursor":
|
|
103
|
+
if sys.platform == "win32":
|
|
104
|
+
local_app = Path(os.getenv("LOCALAPPDATA", ""))
|
|
105
|
+
if (local_app / "Programs" / "cursor" / "Cursor.exe").is_file():
|
|
106
|
+
return True
|
|
107
|
+
elif sys.platform == "darwin":
|
|
108
|
+
return Path("/Applications/Cursor.app").exists()
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _is_provider_installed(spec: ProviderSpec) -> bool:
|
|
113
|
+
if any(shutil.which(exe) is not None for exe in spec.executables):
|
|
114
|
+
return True
|
|
115
|
+
return _is_desktop_app_installed(spec.id)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def inspect_provider(
|
|
119
|
+
spec: ProviderSpec,
|
|
120
|
+
target_home: Path,
|
|
121
|
+
is_sandbox: bool = False,
|
|
122
|
+
) -> ProviderStatus:
|
|
123
|
+
found = tuple(target_home / rel for rel in spec.targets if (target_home / rel).exists())
|
|
124
|
+
has_data = len(found) > 0
|
|
125
|
+
installed = False if is_sandbox else _is_provider_installed(spec)
|
|
126
|
+
return ProviderStatus(
|
|
127
|
+
spec=spec,
|
|
128
|
+
detected=has_data or installed,
|
|
129
|
+
installed=installed,
|
|
130
|
+
has_data=has_data,
|
|
131
|
+
found_paths=found,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def inspect_all_providers(target_home: Path, is_sandbox: bool = False) -> list[ProviderStatus]:
|
|
136
|
+
return [inspect_provider(spec, target_home, is_sandbox=is_sandbox) for spec in PROVIDERS.values()]
|