codedthemes-cli 0.1.13__tar.gz → 0.1.14__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codedthemes-cli
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: CLI tool for Code Theme and Integration
5
5
  Author: codedthemes
6
6
  Requires-Python: >=3.10
@@ -38,7 +38,15 @@ codedthemes login
38
38
  ```
39
39
  *Enter your registered email and license key when prompted.*
40
40
 
41
- ### 2. Initialization (Optional)
41
+ ### 2. Logout
42
+
43
+ Log out from the current device to free up a license slot on the server.
44
+
45
+ ```bash
46
+ codedthemes logout
47
+ ```
48
+
49
+ ### 3. Initialization (Optional)
42
50
 
43
51
  Initialize your repository to establish a baseline for synchronization. This is recommended for first-time use in a project.
44
52
 
@@ -28,7 +28,15 @@ codedthemes login
28
28
  ```
29
29
  *Enter your registered email and license key when prompted.*
30
30
 
31
- ### 2. Initialization (Optional)
31
+ ### 2. Logout
32
+
33
+ Log out from the current device to free up a license slot on the server.
34
+
35
+ ```bash
36
+ codedthemes logout
37
+ ```
38
+
39
+ ### 3. Initialization (Optional)
32
40
 
33
41
  Initialize your repository to establish a baseline for synchronization. This is recommended for first-time use in a project.
34
42
 
@@ -73,8 +73,10 @@ def handle_login(server_url: str = None):
73
73
  save_config({
74
74
  "access_token": token,
75
75
  "server_url": client.server_url,
76
- "device_id": device_id
76
+ "device_id": device_id,
77
+ "license_key": license_key
77
78
  })
79
+
78
80
  print(f"✔ {result.get('message')}")
79
81
  print("\n🚀 Next Step: Run 'codedthemes init' to initialize your repository and sync it with the cloud.")
80
82
  else:
@@ -89,7 +91,45 @@ def handle_login(server_url: str = None):
89
91
  sys.exit(1)
90
92
 
91
93
 
94
+ def handle_logout():
95
+ """
96
+ Clears local session and notifies server to de-authenticate this device.
97
+ """
98
+ try:
99
+ config = load_config()
100
+ token = config.get("access_token")
101
+ license_key = config.get("license_key")
102
+
103
+ if not token:
104
+ print("ℹ Not logged in.")
105
+ return
106
+
107
+ device_id = get_device_id()
108
+ client = MCPClient()
109
+
110
+ print("Logging out...")
111
+ if license_key:
112
+ try:
113
+ client.call("logout", {
114
+ "license_key": license_key,
115
+ "device_id": device_id
116
+ })
117
+ except Exception as e:
118
+ # Silently fail if server logout fails, we still want to clear local state
119
+ pass
120
+
121
+ # Local cleanup: Remove config.json but KEEP device.json
122
+ from .config import CONFIG_FILE
123
+ if CONFIG_FILE.exists():
124
+ CONFIG_FILE.unlink()
125
+
126
+ print("✔ Logged out successfully.")
127
+ except Exception as e:
128
+ print(f"✖ Logout failed: {e}")
129
+
130
+
92
131
  def handle_init():
132
+
93
133
  """
94
134
  Initializes the local repository and syncs it with the cloud.
95
135
  """
@@ -409,6 +449,8 @@ def main():
409
449
  apply_parser.add_argument("query", help="Description of changes to make")
410
450
 
411
451
  subparsers.add_parser("init", help="Initialize repository and sync to cloud")
452
+ subparsers.add_parser("logout", help="Log out from current device")
453
+
412
454
 
413
455
  args = parser.parse_args()
414
456
 
@@ -422,6 +464,9 @@ def main():
422
464
  handle_init()
423
465
  elif args.command == "apply":
424
466
  handle_apply(args.query)
467
+ elif args.command == "logout":
468
+ handle_logout()
469
+
425
470
 
426
471
 
427
472
  if __name__ == "__main__":
@@ -29,27 +29,41 @@ def save_config(data: dict):
29
29
 
30
30
  def get_device_id():
31
31
  """
32
- Generates or retrieves a unique device ID for the machine.
32
+ Returns a unique device ID, stored globally in ~/.codedthemes/device.json.
33
33
  """
34
+ device_file = CONFIG_DIR / "device.json"
34
35
 
35
- config = load_config()
36
- if "device_id" in config:
37
- return config["device_id"]
38
-
39
- # Generate a stable device ID based on hostname and machine UUID
36
+ if device_file.exists():
37
+ try:
38
+ with open(device_file, "r") as f:
39
+ data = json.load(f)
40
+ if data.get("device_id"):
41
+ return data["device_id"]
42
+ except:
43
+ pass
44
+
45
+ # Generate new device ID
40
46
  try:
41
47
  hostname = socket.gethostname()
42
- device_uuid = str(uuid.getnode()) # MAC address based
48
+ device_uuid = str(uuid.getnode())
43
49
  raw_id = f"{hostname}-{device_uuid}"
44
50
  device_id = hashlib.sha256(raw_id.encode()).hexdigest()[:12]
45
51
  except:
46
52
  device_id = str(uuid.uuid4())[:12]
53
+
54
+ # Save globally (create dir if not exists)
55
+ CONFIG_DIR.mkdir(exist_ok=True)
56
+ try:
57
+ with open(device_file, "w") as f:
58
+ json.dump({"device_id": device_id}, f)
59
+ except:
60
+ pass
47
61
 
48
- save_config({"device_id": device_id})
49
62
  return device_id
50
63
 
51
64
 
52
65
 
66
+
53
67
  def load_config():
54
68
  """
55
69
  Loads the configuration data from the config file.
@@ -66,12 +66,15 @@ class MCPClient:
66
66
  if self.token:
67
67
  headers["Authorization"] = f"Bearer {self.token}"
68
68
 
69
- # Login uses a dedicated endpoint, not the tools bridge
69
+ # Login and Logout use dedicated endpoints
70
70
  if tool_name == "login":
71
71
  url = f"{self.server_url}/auth/login"
72
+ elif tool_name == "logout":
73
+ url = f"{self.server_url}/auth/logout"
72
74
  else:
73
75
  url = f"{self.server_url}/tools/{tool_name}"
74
76
 
77
+
75
78
  response = requests.post(
76
79
  url,
77
80
  json=payload,
@@ -104,23 +104,23 @@ def _is_gitignored(rel_path, patterns):
104
104
 
105
105
  def detect_repo_root(start_path=None):
106
106
  """
107
- Traverses up from start_path to find a repository root containing
108
- ai.json, or .git. Stricter than previous versions to avoid false positives.
107
+ Checks if the current directory contains ai.json or .git.
108
+ Strictly restricted to the current path (no upward traversal) to avoid
109
+ incorrectly detecting parent repos.
109
110
  """
110
111
  if not start_path:
111
112
  start_path = os.getcwd()
112
113
 
113
114
  current = Path(start_path).resolve()
114
115
 
115
- while current != current.parent:
116
- if any((current / f).exists() for f in ["ai.json", ".git"]):
117
- return current
118
- current = current.parent
116
+ if any((current / f).exists() for f in ["ai.json", ".git"]):
117
+ return current
119
118
 
120
119
  raise Exception("No repository root found. Please run this command inside a Git repository or one initialized with 'codedthemes init'.")
121
120
 
122
121
 
123
122
 
123
+
124
124
  def zip_repo(repo_root):
125
125
  """
126
126
  Creates a temporary ZIP archive of the repository with aggressive filtering:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codedthemes-cli
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: CLI tool for Code Theme and Integration
5
5
  Author: codedthemes
6
6
  Requires-Python: >=3.10
@@ -38,7 +38,15 @@ codedthemes login
38
38
  ```
39
39
  *Enter your registered email and license key when prompted.*
40
40
 
41
- ### 2. Initialization (Optional)
41
+ ### 2. Logout
42
+
43
+ Log out from the current device to free up a license slot on the server.
44
+
45
+ ```bash
46
+ codedthemes logout
47
+ ```
48
+
49
+ ### 3. Initialization (Optional)
42
50
 
43
51
  Initialize your repository to establish a baseline for synchronization. This is recommended for first-time use in a project.
44
52
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codedthemes-cli"
7
- version = "0.1.13"
7
+ version = "0.1.14"
8
8
  description = "CLI tool for Code Theme and Integration"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"