codemind-sh 0.1.2__tar.gz → 0.1.4__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.
Files changed (74) hide show
  1. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/PKG-INFO +1 -1
  2. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/__init__.py +1 -1
  3. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/cli.py +22 -8
  4. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/license/client.py +27 -16
  5. codemind_sh-0.1.4/codemind/license/enforcer.py +102 -0
  6. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/license/license.py +45 -87
  7. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/pyproject.toml +1 -1
  8. codemind_sh-0.1.2/codemind/license/enforcer.py +0 -156
  9. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/LICENSE +0 -0
  10. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/README.md +0 -0
  11. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/__main__.py +0 -0
  12. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/ai/__init__.py +0 -0
  13. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/ai/enricher.py +0 -0
  14. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/ai/pro_features.py +0 -0
  15. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/ai/stack_learner.py +0 -0
  16. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/analyzer/__init__.py +0 -0
  17. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/analyzer/base.py +0 -0
  18. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/analyzer/dependency_analyzer.py +0 -0
  19. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/analyzer/java_analyzer.py +0 -0
  20. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/analyzer/typescript_analyzer.py +0 -0
  21. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/context/__init__.py +0 -0
  22. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/context/engine.py +0 -0
  23. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/core/__init__.py +0 -0
  24. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/core/config.py +0 -0
  25. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/core/constants.py +0 -0
  26. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/core/graph.py +0 -0
  27. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/core/project.py +0 -0
  28. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/git/__init__.py +0 -0
  29. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/graph/__init__.py +0 -0
  30. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/graph/builder.py +0 -0
  31. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/graph/query.py +0 -0
  32. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/graph/store.py +0 -0
  33. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/health/__init__.py +0 -0
  34. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/health/checker.py +0 -0
  35. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/health/dependency_check.py +0 -0
  36. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/health/pattern_check.py +0 -0
  37. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/health/test_coverage.py +0 -0
  38. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/__init__.py +0 -0
  39. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/architecture.py +0 -0
  40. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/connection_builder.py +0 -0
  41. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/connections.py +0 -0
  42. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/generator.py +0 -0
  43. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/knowledge/index_builder.py +0 -0
  44. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/license/__init__.py +0 -0
  45. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/license/keygen.py +0 -0
  46. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/mcp/__init__.py +0 -0
  47. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/mcp/connect.py +0 -0
  48. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/mcp/decisions.py +0 -0
  49. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/mcp/server.py +0 -0
  50. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/mcp/tools.py +0 -0
  51. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/__init__.py +0 -0
  52. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/base.py +0 -0
  53. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/gap_detector.py +0 -0
  54. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/java_parser.py +0 -0
  55. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/python_parser.py +0 -0
  56. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/registry.py +0 -0
  57. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/rule_cache.py +0 -0
  58. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/parser/typescript_parser.py +0 -0
  59. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/router/__init__.py +0 -0
  60. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/router/call_extractor.py +0 -0
  61. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/router/linker.py +0 -0
  62. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/router/route_extractor.py +0 -0
  63. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/__init__.py +0 -0
  64. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/generator.py +0 -0
  65. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/pattern_extractor.py +0 -0
  66. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/java/controller.java.j2 +0 -0
  67. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/java/entity.java.j2 +0 -0
  68. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/java/repository.java.j2 +0 -0
  69. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/java/service.java.j2 +0 -0
  70. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/java/test.java.j2 +0 -0
  71. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/scaffold/templates/typescript/service.ts.j2 +0 -0
  72. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/tasks/__init__.py +0 -0
  73. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/watcher/__init__.py +0 -0
  74. {codemind_sh-0.1.2 → codemind_sh-0.1.4}/codemind/watcher/handler.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codemind-sh
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Local-first knowledge graph for software projects. Gives AI tools structural facts about your codebase via 11 MCP tools.
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,4 @@
1
1
  """CodeMind — Local-first intelligence layer for software projects."""
2
2
 
3
- __version__ = "0.1.2"
3
+ __version__ = "0.1.4"
4
4
  __app_name__ = "codemind"
@@ -18,7 +18,7 @@ from codemind.core.project import CodemindProject
18
18
  from codemind.core.constants import CODEMIND_DIR
19
19
  from codemind.license.license import LicenseManager
20
20
  from codemind.license.enforcer import LicenseEnforcer
21
- from codemind.license.client import LicenseClient
21
+ from codemind.license.client import LicenseClient, LicenseLimitReached
22
22
 
23
23
  # ── App Setup ──
24
24
  app = typer.Typer(
@@ -84,9 +84,7 @@ def init(
84
84
  default="",
85
85
  )
86
86
  if _email.strip():
87
- trial_state.email = _email.strip()
88
- _lic_mgr.save(trial_state)
89
- LicenseClient().register_email(trial_state.license_key, trial_state.email)
87
+ LicenseClient().register_email(trial_state.license_key, _email.strip())
90
88
  console.print(" [green]✓[/green] Email saved — we'll use it to restore your key.")
91
89
  else:
92
90
  console.print(" [dim]Skipped. You can always recover via your license key.[/dim]")
@@ -193,9 +191,9 @@ def init(
193
191
  project = CodemindProject(project_root)
194
192
  project.initialize(config)
195
193
 
196
- # Register project as Class A (activated during valid license)
197
- _lic_mgr.add_activated_project(project.config.project_id)
198
- # Best-effort: also tell the server so Class A survives key migration
194
+ # ── Server validation — authoritative project limit check ──────────────────
195
+ # The server is the source of truth. Local license.yml can be edited by
196
+ # anyone — only the server DB count is tamper-proof.
199
197
  if project.config.project_id and _lic_state.license_key:
200
198
  try:
201
199
  updated = LicenseClient().validate(
@@ -203,8 +201,24 @@ def init(
203
201
  )
204
202
  if updated:
205
203
  _lic_mgr.save(updated)
204
+ # Also add to local activated list for offline use
205
+ _lic_mgr.add_activated_project(project.config.project_id)
206
+ except LicenseLimitReached as e:
207
+ # Server rejected — rollback: remove the .codemind/ directory we just created
208
+ import shutil
209
+ _codemind_dir = project_root / CODEMIND_DIR
210
+ if _codemind_dir.exists():
211
+ shutil.rmtree(_codemind_dir)
212
+ console.print()
213
+ console.print(f" [red]✗[/red] {e.detail or _check.reason}")
214
+ console.print(
215
+ " Upgrade at [cyan]codemind.sh/upgrade[/cyan] to add unlimited projects."
216
+ )
217
+ console.print()
218
+ raise typer.Exit(1)
206
219
  except Exception:
207
- pass # offline — local activated_projects is enough
220
+ # Offline — local activated_projects is enough
221
+ _lic_mgr.add_activated_project(project.config.project_id)
208
222
 
209
223
  # ── Show result ──
210
224
  console.print()
@@ -11,18 +11,23 @@ import json
11
11
  import os
12
12
  import urllib.error
13
13
  import urllib.request
14
- from datetime import date
15
14
  from typing import Any
16
15
 
17
16
  from codemind.license.keygen import generate_trial_key
17
+
18
+
19
+ class LicenseLimitReached(Exception):
20
+ """Raised when the server rejects a new project due to plan limit (HTTP 402)."""
21
+ def __init__(self, detail: str = "") -> None:
22
+ self.detail = detail
23
+ super().__init__(detail)
24
+
25
+
18
26
  from codemind.license.license import (
19
27
  LICENSE_FILE,
20
28
  LicenseManager,
21
29
  LicenseState,
22
- TIER_FREE,
23
30
  FREE_FEATURES,
24
- FREE_PROJECT_LIMIT,
25
- OFFLINE_GRACE_DAYS,
26
31
  )
27
32
 
28
33
  _TIMEOUT = 5 # seconds — fast enough for CLI startup, long enough to work on slow VPS
@@ -35,7 +40,10 @@ def _server_url() -> str:
35
40
 
36
41
 
37
42
  def _post(path: str, payload: dict[str, Any]) -> dict[str, Any] | None:
38
- """POST JSON to the license server. Returns parsed JSON or None on any error."""
43
+ """POST JSON to the license server. Returns parsed JSON or None on any error.
44
+
45
+ Raises LicenseLimitReached on HTTP 402 (project limit reached on server).
46
+ """
39
47
  url = f"{_server_url()}{path}"
40
48
  data = json.dumps(payload).encode()
41
49
  req = urllib.request.Request(
@@ -47,6 +55,14 @@ def _post(path: str, payload: dict[str, Any]) -> dict[str, Any] | None:
47
55
  try:
48
56
  with urllib.request.urlopen(req, timeout=_TIMEOUT) as resp:
49
57
  return json.loads(resp.read().decode())
58
+ except urllib.error.HTTPError as e:
59
+ if e.code == 402:
60
+ try:
61
+ body = json.loads(e.read().decode())
62
+ raise LicenseLimitReached(body.get("detail", "Project limit reached."))
63
+ except (json.JSONDecodeError, AttributeError):
64
+ raise LicenseLimitReached("Project limit reached.")
65
+ return None
50
66
  except (urllib.error.URLError, OSError, json.JSONDecodeError, TimeoutError):
51
67
  return None
52
68
 
@@ -71,18 +87,13 @@ def _parse_state(data: dict[str, Any]) -> LicenseState:
71
87
  def _local_free() -> LicenseState:
72
88
  """Create an offline free-tier key when the license server is unreachable.
73
89
 
74
- Permanent free — 1 project, no expiry. The server will register it
75
- properly when connectivity is restored.
90
+ Permanent free — 1 project (server-enforced), no expiry.
91
+ The server will register it properly when connectivity is restored.
76
92
  """
77
93
  key = generate_trial_key()
78
94
  return LicenseState(
79
95
  license_key=key,
80
- tier=TIER_FREE,
81
- expires_at=None, # permanent — no expiry
82
96
  features=list(FREE_FEATURES),
83
- project_limit=FREE_PROJECT_LIMIT,
84
- grace_days=OFFLINE_GRACE_DAYS,
85
- validated_at=date.today(),
86
97
  activated_projects=[],
87
98
  )
88
99
 
@@ -103,8 +114,9 @@ class LicenseClient:
103
114
  def validate(self, license_key: str, project_id: str) -> LicenseState | None:
104
115
  """Validate key + register project activation on server.
105
116
 
106
- Returns updated LicenseState (possibly with project_id added to
107
- activated_projects) or None if the server is unreachable.
117
+ Returns updated LicenseState (with refreshed features from server)
118
+ or None if the server is unreachable.
119
+ Raises LicenseLimitReached on HTTP 402 (project limit reached).
108
120
  """
109
121
  result = _post(
110
122
  "/api/licenses/validate",
@@ -120,8 +132,7 @@ class LicenseClient:
120
132
  def register_email(self, license_key: str, email: str) -> bool:
121
133
  """Associate an email with a license key for recovery purposes.
122
134
 
123
- Silently returns False if the server is unreachable — the caller
124
- should store the email locally regardless.
135
+ Silently returns False if the server is unreachable.
125
136
  """
126
137
  result = _post(
127
138
  "/api/licenses/register-email",
@@ -0,0 +1,102 @@
1
+ """Hotel Key enforcement — the single gate for ``codemind init`` and ``codemind scan``.
2
+
3
+ Pricing model (v4 — server-authoritative, tamper-proof):
4
+
5
+ Free tier (permanent — no expiry):
6
+ - 1 project (enforced SERVER-SIDE — cannot be bypassed by editing local files)
7
+ - All core tools work offline (MCP, scaffold, decisions, health)
8
+ - AI via BYOK (user sets ANTHROPIC_API_KEY — they pay Anthropic directly)
9
+
10
+ ``codemind init``:
11
+ - Class A project (already in activated_projects) → always allow (offline ok)
12
+ - New project → call server to validate
13
+ - Server returns 402 → block + upgrade message + rollback
14
+
15
+ ``codemind scan``:
16
+ - Always allowed for any initialized project (graph exists)
17
+ - Never blocked — scan is never paused
18
+
19
+ AI features (enrichment, Pro review/brief/impact):
20
+ - BYOK features: allowed if ANTHROPIC_API_KEY is set (free tier)
21
+ - Pro features: require paid-tier feature in features list
22
+ - Expired paid license: server removes features on next validate
23
+
24
+ All other commands (serve, check, scaffold, decide, query) are never blocked.
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ from dataclasses import dataclass
30
+
31
+ from codemind.license.license import (
32
+ LicenseState,
33
+ FEATURE_AI_ENRICHMENT,
34
+ FEATURE_AI_ENRICHMENT_BYOK,
35
+ FEATURE_PRO_REVIEW,
36
+ FEATURE_PRO_BRIEF,
37
+ FEATURE_PRO_IMPACT,
38
+ )
39
+
40
+
41
+ @dataclass
42
+ class EnforcementResult:
43
+ """Return value from every enforcer check."""
44
+
45
+ allowed: bool
46
+ reason: str = "" # shown on block; empty when allowed
47
+ warning: str = "" # advisory banner; shown but does not block
48
+
49
+
50
+ class LicenseEnforcer:
51
+ """Apply Hotel Key rules. Stateless — takes a :class:`LicenseState` each call."""
52
+
53
+ def check_init(self, state: LicenseState, project_id: str) -> EnforcementResult:
54
+ """Can ``codemind init`` proceed for *project_id*?
55
+
56
+ Class A projects (already in activated_projects) are always allowed,
57
+ even offline. For new projects, this always returns allowed=True —
58
+ the server is the authoritative gate and will return HTTP 402 if the
59
+ plan limit is reached. The CLI rolls back .codemind/ on 402.
60
+ """
61
+ # Class A: project was previously registered on this key — always allow
62
+ if state.is_class_a(project_id):
63
+ return EnforcementResult(allowed=True)
64
+
65
+ # New project: allow through — server validates and enforces limits
66
+ return EnforcementResult(allowed=True)
67
+
68
+ def check_scan(
69
+ self,
70
+ state: LicenseState,
71
+ project_id: str,
72
+ graph_exists: bool,
73
+ ) -> EnforcementResult:
74
+ """Can ``codemind scan`` proceed?
75
+
76
+ Scan is always allowed for initialized projects. It is never paused —
77
+ only AI enrichment may be restricted by the features list.
78
+ """
79
+ return EnforcementResult(allowed=True)
80
+
81
+ def ai_allowed(self, state: LicenseState) -> bool:
82
+ """True when server-paid AI enrichment may run (Pro+).
83
+
84
+ Free tier users run AI via BYOK (their own key) — always allowed
85
+ if they have set ANTHROPIC_API_KEY. Only the Pro-tier managed
86
+ enrichment (we pay) requires a non-expired paid license.
87
+ """
88
+ return state.has_feature(FEATURE_AI_ENRICHMENT)
89
+
90
+ def byok_ai_allowed(self, state: LicenseState) -> bool:
91
+ """True when BYOK AI (user's own key) may run — free + paid tiers."""
92
+ return (
93
+ state.has_feature(FEATURE_AI_ENRICHMENT_BYOK)
94
+ or state.has_feature(FEATURE_AI_ENRICHMENT)
95
+ )
96
+
97
+ def pro_features_allowed(self, state: LicenseState) -> bool:
98
+ """True when Pro AI commands (review, brief, impact --ai) are available."""
99
+ return any(
100
+ state.has_feature(f)
101
+ for f in (FEATURE_PRO_REVIEW, FEATURE_PRO_BRIEF, FEATURE_PRO_IMPACT)
102
+ )
@@ -1,9 +1,17 @@
1
- """License state model and manager for ~/.codemind/license.yml."""
1
+ """License state model and manager for ~/.codemind/license.yml.
2
+
3
+ Local file is intentionally minimal — only 3 fields:
4
+ license_key — needed to call the server
5
+ features — cached from server; controls what CLI features are enabled
6
+ activated_projects — Class A registry (projects activated on this key)
7
+
8
+ ALL enforcement (project limits, tier, expiry) is server-side.
9
+ Nothing in this file can be edited to bypass plan limits.
10
+ """
2
11
 
3
12
  from __future__ import annotations
4
13
 
5
14
  from dataclasses import dataclass, field
6
- from datetime import date, timedelta
7
15
  from pathlib import Path
8
16
  from typing import Any
9
17
 
@@ -14,14 +22,6 @@ import yaml
14
22
  LICENSE_DIR = Path.home() / ".codemind"
15
23
  LICENSE_FILE = LICENSE_DIR / "license.yml"
16
24
 
17
- # ── Tier constants ─────────────────────────────────────────────────────────────
18
-
19
- TIER_FREE = "free"
20
- TIER_TRIAL = "trial" # legacy — old installs may have this; treated as free
21
- TIER_PRO = "pro"
22
- TIER_TEAM = "team"
23
- TIER_ENTERPRISE = "enterprise"
24
-
25
25
  # ── Feature constants ──────────────────────────────────────────────────────────
26
26
 
27
27
  FEATURE_AI_ENRICHMENT = "ai_enrichment" # Pro: we pay
@@ -45,92 +45,50 @@ PRO_FEATURES: list[str] = [
45
45
  ]
46
46
  TEAM_FEATURES: list[str] = PRO_FEATURES + [FEATURE_TEAM_DASHBOARD]
47
47
 
48
- # Legacy alias so old code referencing TRIAL_FEATURES still works
48
+ # Legacy aliases — kept so any imports elsewhere don't break
49
49
  TRIAL_FEATURES = FREE_FEATURES
50
+ FREE_PROJECT_LIMIT = 1 # informational only — enforcement is server-side
51
+ OFFLINE_GRACE_DAYS = 7 # kept for backwards-compat with any imports
50
52
 
51
- FREE_PROJECT_LIMIT = 1
52
- EXPIRY_WARNING_DAYS = 5 # warn when <= 5 days left (paid tiers with expiry)
53
- OFFLINE_GRACE_DAYS = 7 # days without server check before AI features warn
53
+ # Tier name constants — kept for any code that imports them
54
+ TIER_FREE = "free"
55
+ TIER_TRIAL = "trial"
56
+ TIER_PRO = "pro"
57
+ TIER_TEAM = "team"
58
+ TIER_ENTERPRISE = "enterprise"
59
+ EXPIRY_WARNING_DAYS = 5
54
60
 
55
61
 
56
62
  @dataclass
57
63
  class LicenseState:
58
64
  """In-memory representation of ~/.codemind/license.yml.
59
65
 
60
- The *features* list is server-controlled: to add a feature to a tier,
61
- push a server-side change — zero CLI update needed.
66
+ Minimal by design — only what is needed for offline operation.
67
+ The server is the single source of truth for tier, project limits, and expiry.
62
68
  """
63
69
 
64
70
  license_key: str = ""
65
- tier: str = TIER_TRIAL
66
- expires_at: date | None = None
67
71
  features: list[str] = field(default_factory=list)
68
- project_limit: int | None = FREE_PROJECT_LIMIT
69
- grace_days: int = OFFLINE_GRACE_DAYS
70
- validated_at: date | None = None
71
72
  activated_projects: list[str] = field(default_factory=list)
72
- email: str = "" # optional — for license recovery if user reinstalls
73
-
74
- # ── Derived properties ────────────────────────────────────────────────────
75
73
 
76
- @property
77
- def is_free(self) -> bool:
78
- """True for permanent free tier (and legacy 'trial' tier)."""
79
- return self.tier in (TIER_FREE, TIER_TRIAL)
80
-
81
- @property
82
- def is_paid(self) -> bool:
83
- return self.tier in (TIER_PRO, TIER_TEAM, TIER_ENTERPRISE)
84
-
85
- @property
86
- def is_expired(self) -> bool:
87
- """Only paid tiers with a set expires_at can expire. Free is permanent."""
88
- if self.is_free:
89
- return False # free tier never expires
90
- if self.expires_at is None:
91
- return False
92
- return date.today() > self.expires_at
93
-
94
- @property
95
- def days_until_expiry(self) -> int | None:
96
- """Days until expiry; None if perpetual; negative if already expired."""
97
- if self.expires_at is None:
98
- return None
99
- return (self.expires_at - date.today()).days
100
-
101
- @property
102
- def in_warning_window(self) -> bool:
103
- """True when <= EXPIRY_WARNING_DAYS days remain (and not yet expired)."""
104
- days = self.days_until_expiry
105
- if days is None:
106
- return False
107
- return 0 < days <= EXPIRY_WARNING_DAYS
108
-
109
- @property
110
- def offline_too_long(self) -> bool:
111
- """True if last server validation is older than grace_days."""
112
- if self.validated_at is None:
113
- return False
114
- age = (date.today() - self.validated_at).days
115
- return age > self.grace_days
74
+ # ── Methods ───────────────────────────────────────────────────────────────
116
75
 
117
76
  def is_class_a(self, project_id: str) -> bool:
118
- """Project was activated while license was valid — works offline forever."""
77
+ """True if project was previously activated on this key.
78
+
79
+ Class A projects always work offline — the key was server-validated at
80
+ activation time and the project_id is in the local registry.
81
+ """
119
82
  return bool(project_id) and project_id in self.activated_projects
120
83
 
121
84
  def has_feature(self, feature: str) -> bool:
122
- """True if feature is unlocked AND license is not expired."""
123
- return not self.is_expired and feature in self.features
85
+ """True if feature is in the server-controlled features list."""
86
+ return feature in self.features
124
87
 
125
88
  @property
126
89
  def active_project_count(self) -> int:
127
90
  return len(self.activated_projects)
128
91
 
129
- def within_project_limit(self) -> bool:
130
- if self.project_limit is None:
131
- return True
132
- return self.active_project_count < self.project_limit
133
-
134
92
 
135
93
  class LicenseManager:
136
94
  """Read/write ~/.codemind/license.yml atomically."""
@@ -174,29 +132,29 @@ class LicenseManager:
174
132
  # ── Private ───────────────────────────────────────────────────────────────
175
133
 
176
134
  def _from_dict(self, data: dict[str, Any]) -> LicenseState:
177
- expires_raw = data.get("expires_at")
178
- validated_raw = data.get("validated_at")
135
+ """Parse any dict (server response or local file) into LicenseState.
136
+
137
+ Extra fields from old license.yml files (tier, project_limit, expires_at,
138
+ grace_days, validated_at, email) are silently ignored — migration is
139
+ automatic the next time save() is called.
140
+ """
141
+ activated = data.get("activated_projects") or []
142
+ # Server returns list of UUID strings; old local files do too.
143
+ # Guard against any list-of-dicts format just in case.
144
+ activated_ids = [
145
+ a["project_id"] if isinstance(a, dict) else str(a)
146
+ for a in activated
147
+ ]
179
148
  return LicenseState(
180
149
  license_key=data.get("license_key", ""),
181
- tier=data.get("tier", TIER_TRIAL),
182
- expires_at=date.fromisoformat(str(expires_raw)) if expires_raw else None,
183
150
  features=list(data.get("features") or []),
184
- project_limit=data.get("project_limit", FREE_PROJECT_LIMIT),
185
- grace_days=int(data.get("grace_days", OFFLINE_GRACE_DAYS)),
186
- validated_at=date.fromisoformat(str(validated_raw)) if validated_raw else None,
187
- activated_projects=list(data.get("activated_projects") or []),
188
- email=data.get("email", ""),
151
+ activated_projects=activated_ids,
189
152
  )
190
153
 
191
154
  def _to_dict(self, state: LicenseState) -> dict[str, Any]:
155
+ """Only write the 3 essential fields — nothing else is stored locally."""
192
156
  return {
193
157
  "license_key": state.license_key,
194
- "tier": state.tier,
195
- "expires_at": state.expires_at.isoformat() if state.expires_at else None,
196
158
  "features": state.features,
197
- "project_limit": state.project_limit,
198
- "grace_days": state.grace_days,
199
- "validated_at": state.validated_at.isoformat() if state.validated_at else None,
200
159
  "activated_projects": state.activated_projects,
201
- "email": state.email,
202
160
  }
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codemind-sh"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  description = "Local-first knowledge graph for software projects. Gives AI tools structural facts about your codebase via 11 MCP tools."
5
5
  authors = ["Mohammed <mohammed@onixsolutions.net>"]
6
6
  license = "MIT"
@@ -1,156 +0,0 @@
1
- """Hotel Key enforcement — the single gate for ``codemind init`` and ``codemind scan``.
2
-
3
- Pricing model (v3.3 — permanent free tier, no time bombs):
4
-
5
- Free tier (permanent — no expiry):
6
- - 1 project forever
7
- - All core tools work offline (MCP, scaffold, decisions, health)
8
- - AI via BYOK (user sets ANTHROPIC_API_KEY — they pay Anthropic directly)
9
-
10
- ``codemind init``:
11
- - Class A project (already activated on this key) → always allow
12
- - New project + within_project_limit → allow
13
- - New project + limit reached (server rejected it) → BLOCK + upgrade message
14
-
15
- ``codemind scan``:
16
- - Always allowed if project was previously initialized (graph exists)
17
- - Never blocked for existing projects — scan is never paused
18
-
19
- AI features (enrichment, Pro review/brief/impact):
20
- - BYOK features: allowed if ANTHROPIC_API_KEY is set (free tier)
21
- - Pro features: require paid tier in features list
22
- - Expired paid license: AI paused, core tools continue
23
-
24
- All other commands (serve, check, scaffold, decide, query) are never blocked.
25
- """
26
-
27
- from __future__ import annotations
28
-
29
- from dataclasses import dataclass
30
-
31
- from codemind.license.license import (
32
- LicenseState,
33
- FEATURE_AI_ENRICHMENT,
34
- FEATURE_AI_ENRICHMENT_BYOK,
35
- FEATURE_PRO_REVIEW,
36
- FEATURE_PRO_BRIEF,
37
- FEATURE_PRO_IMPACT,
38
- EXPIRY_WARNING_DAYS,
39
- )
40
-
41
-
42
- @dataclass
43
- class EnforcementResult:
44
- """Return value from every enforcer check."""
45
-
46
- allowed: bool
47
- reason: str = "" # shown on block; empty when allowed
48
- warning: str = "" # advisory banner; shown but does not block
49
-
50
-
51
- def _expiry_warning(state: LicenseState) -> str:
52
- """Warning shown when a paid subscription is close to expiry."""
53
- days = state.days_until_expiry
54
- if days is None or days > EXPIRY_WARNING_DAYS or days <= 0:
55
- return ""
56
- unit = "day" if days == 1 else "days"
57
- return (
58
- f"Subscription expires in {days} {unit}. "
59
- "Visit codemind.sh/dashboard to renew."
60
- )
61
-
62
-
63
- def _limit_reached_reason() -> str:
64
- return (
65
- "Free plan supports 1 project.\n\n"
66
- " Upgrade at [cyan]codemind.sh/upgrade[/cyan] to add unlimited projects\n"
67
- " and unlock Pro AI features (review, brief, impact --ai)."
68
- )
69
-
70
-
71
- def _expired_paid_warning() -> str:
72
- return (
73
- "Subscription expired — AI features paused. "
74
- "Core tools continue working offline. "
75
- "Renew at codemind.sh/dashboard."
76
- )
77
-
78
-
79
- class LicenseEnforcer:
80
- """Apply Hotel Key rules. Stateless — takes a :class:`LicenseState` each call."""
81
-
82
- def check_init(self, state: LicenseState, project_id: str) -> EnforcementResult:
83
- """Can ``codemind init`` proceed for *project_id*?
84
-
85
- Rules:
86
- - Class A project (already in activated_projects): always allow.
87
- - New project + within project limit: allow.
88
- - New project + limit reached: BLOCK.
89
- (The server enforced this first; local check is a secondary gate
90
- when offline or when the server already rejected /validate.)
91
- """
92
- # Class A: project was previously initialized on this key — never block
93
- if state.is_class_a(project_id):
94
- return EnforcementResult(allowed=True, warning=_expiry_warning(state))
95
-
96
- # Expired paid license: block new project init (renewal required)
97
- if state.is_expired:
98
- return EnforcementResult(
99
- allowed=False,
100
- reason=(
101
- "Subscription expired. Existing projects continue working offline.\n"
102
- " Renew at [cyan]codemind.sh/dashboard[/cyan] to add new projects."
103
- ),
104
- )
105
-
106
- # Check project limit (secondary to server-side enforcement)
107
- if not state.within_project_limit():
108
- return EnforcementResult(allowed=False, reason=_limit_reached_reason())
109
-
110
- return EnforcementResult(allowed=True, warning=_expiry_warning(state))
111
-
112
- def check_scan(
113
- self,
114
- state: LicenseState,
115
- project_id: str,
116
- graph_exists: bool,
117
- ) -> EnforcementResult:
118
- """Can ``codemind scan`` proceed?
119
-
120
- Scan is always allowed for existing projects (graph exists or project
121
- was previously activated). It is never paused — only AI enrichment
122
- may be restricted.
123
- """
124
- if state.is_class_a(project_id) or graph_exists:
125
- # Warn if paid license expired but never block scan
126
- warning = _expired_paid_warning() if state.is_expired else _expiry_warning(state)
127
- return EnforcementResult(allowed=True, warning=warning)
128
-
129
- # Project not yet initialized — check limit before first scan
130
- if not state.within_project_limit():
131
- return EnforcementResult(allowed=False, reason=_limit_reached_reason())
132
-
133
- return EnforcementResult(allowed=True, warning=_expiry_warning(state))
134
-
135
- def ai_allowed(self, state: LicenseState) -> bool:
136
- """True when server-paid AI enrichment may run (Pro+).
137
-
138
- Free tier users run AI via BYOK (their own key) — always allowed
139
- if they have set ANTHROPIC_API_KEY. Only the Pro-tier managed
140
- enrichment (we pay) requires a non-expired paid license.
141
- """
142
- return state.has_feature(FEATURE_AI_ENRICHMENT)
143
-
144
- def byok_ai_allowed(self, state: LicenseState) -> bool:
145
- """True when BYOK AI (user's own key) may run — free + paid tiers."""
146
- return (
147
- state.has_feature(FEATURE_AI_ENRICHMENT_BYOK)
148
- or state.has_feature(FEATURE_AI_ENRICHMENT)
149
- )
150
-
151
- def pro_features_allowed(self, state: LicenseState) -> bool:
152
- """True when Pro AI commands (review, brief, impact --ai) are available."""
153
- return any(
154
- state.has_feature(f)
155
- for f in (FEATURE_PRO_REVIEW, FEATURE_PRO_BRIEF, FEATURE_PRO_IMPACT)
156
- )
File without changes
File without changes