codedthemes-cli 0.1.12__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.12
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
 
@@ -29,6 +29,7 @@ def handle_login(server_url: str = None):
29
29
  choice = input("Switch account? (y/N): ").strip().lower()
30
30
  if choice not in ['y', 'yes']:
31
31
  print("Login cancelled.")
32
+ print("Please enter your credentials to log in.")
32
33
  return
33
34
  except:
34
35
  pass
@@ -62,28 +63,25 @@ def handle_login(server_url: str = None):
62
63
  "device_name": device_name
63
64
  })
64
65
 
65
- if isinstance(result, dict):
66
- if result.get("status") == "error":
67
- print(f"✖ Login failed: {result.get('message', 'Unknown error')}")
68
- sys.exit(1)
69
- elif "message" in result and "Login failed" in result["message"]:
70
- print(f"✖ {result['message']}")
66
+ if result.get("status") == "success":
67
+ token = result.get("access_token")
68
+ if not token:
69
+ print("✖ Login failed: No access token returned. Please check your credentials.")
71
70
  sys.exit(1)
72
71
 
73
- # Get token from result
74
- token = result.get("access_token") if isinstance(result, dict) else None
75
-
76
- if not token:
77
- print("✖ Login failed: No access token returned. Please check your credentials.")
78
- sys.exit(1)
72
+ # LAZY CONFIG: Only save if login succeeded
73
+ save_config({
74
+ "access_token": token,
75
+ "server_url": client.server_url,
76
+ "device_id": device_id,
77
+ "license_key": license_key
78
+ })
79
79
 
80
- save_config({
81
- "server_url": client.server_url,
82
- "access_token": token
83
- })
84
-
85
- print("✔ Login successful.")
86
- print("\n🚀 Next Step: Run 'codedthemes init' to initialize your repository and sync it with the cloud.")
80
+ print(f"✔ {result.get('message')}")
81
+ print("\n🚀 Next Step: Run 'codedthemes init' to initialize your repository and sync it with the cloud.")
82
+ else:
83
+ print(f"✖ {result.get('message', 'Login failed')}")
84
+ sys.exit(1)
87
85
  except Exception as e:
88
86
  err_msg = str(e)
89
87
  if "timed out" in err_msg.lower():
@@ -93,7 +91,45 @@ def handle_login(server_url: str = None):
93
91
  sys.exit(1)
94
92
 
95
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
+
96
131
  def handle_init():
132
+
97
133
  """
98
134
  Initializes the local repository and syncs it with the cloud.
99
135
  """
@@ -413,6 +449,8 @@ def main():
413
449
  apply_parser.add_argument("query", help="Description of changes to make")
414
450
 
415
451
  subparsers.add_parser("init", help="Initialize repository and sync to cloud")
452
+ subparsers.add_parser("logout", help="Log out from current device")
453
+
416
454
 
417
455
  args = parser.parse_args()
418
456
 
@@ -426,6 +464,9 @@ def main():
426
464
  handle_init()
427
465
  elif args.command == "apply":
428
466
  handle_apply(args.query)
467
+ elif args.command == "logout":
468
+ handle_logout()
469
+
429
470
 
430
471
 
431
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,20 +104,21 @@ 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
- package.json, pyproject.toml, ai.json, or .git.
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 ["package.json", "pyproject.toml", "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
118
+
119
+ raise Exception("No repository root found. Please run this command inside a Git repository or one initialized with 'codedthemes init'.")
120
+
119
121
 
120
- raise Exception("No repository root found.")
121
122
 
122
123
 
123
124
  def zip_repo(repo_root):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codedthemes-cli
3
- Version: 0.1.12
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.12"
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"