xenfra 0.4.4__tar.gz → 0.4.5__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 (28) hide show
  1. {xenfra-0.4.4 → xenfra-0.4.5}/PKG-INFO +1 -1
  2. {xenfra-0.4.4 → xenfra-0.4.5}/pyproject.toml +7 -7
  3. xenfra-0.4.5/src/xenfra/blueprints/__init__.py +55 -0
  4. xenfra-0.4.5/src/xenfra/blueprints/base.py +85 -0
  5. xenfra-0.4.5/src/xenfra/blueprints/cache.py +286 -0
  6. xenfra-0.4.5/src/xenfra/blueprints/dry_run.py +251 -0
  7. xenfra-0.4.5/src/xenfra/blueprints/e2b.py +101 -0
  8. xenfra-0.4.5/src/xenfra/blueprints/factory.py +113 -0
  9. xenfra-0.4.5/src/xenfra/blueprints/railpack.py +319 -0
  10. xenfra-0.4.5/src/xenfra/blueprints/validation.py +182 -0
  11. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/deployments.py +303 -78
  12. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/intelligence.py +5 -5
  13. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/main.py +4 -1
  14. {xenfra-0.4.4 → xenfra-0.4.5}/README.md +0 -0
  15. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/__init__.py +0 -0
  16. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/__init__.py +0 -0
  17. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/auth.py +0 -0
  18. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/auth_device.py +0 -0
  19. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/projects.py +0 -0
  20. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/commands/security_cmd.py +0 -0
  21. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/__init__.py +0 -0
  22. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/auth.py +0 -0
  23. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/codebase.py +0 -0
  24. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/config.py +0 -0
  25. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/errors.py +0 -0
  26. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/file_sync.py +0 -0
  27. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/security.py +0 -0
  28. {xenfra-0.4.4 → xenfra-0.4.5}/src/xenfra/utils/validation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: xenfra
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Xenfra CLI: Hands for AI to deploy on DigitalOcean.
5
5
  Author: xenfra-cloud
6
6
  Author-email: xenfra-cloud <xenfracloud@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xenfra"
3
- version = "0.4.4"
3
+ version = "0.4.5"
4
4
  description = "Xenfra CLI: Hands for AI to deploy on DigitalOcean."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -17,6 +17,8 @@ classifiers = [
17
17
  "Topic :: System :: Systems Administration",
18
18
  ]
19
19
 
20
+ requires-python = ">=3.11"
21
+
20
22
  dependencies = [
21
23
  "click>=8.1.7",
22
24
  "rich>=14.2.0",
@@ -33,12 +35,6 @@ dependencies = [
33
35
  "cryptography>=43.0.0", # For encrypted file-based token storage
34
36
  "toml>=0.10.2",
35
37
  ]
36
- requires-python = ">=3.11"
37
-
38
-
39
- [project.urls]
40
- Homepage = "https://github.com/xenfra-cloud/xenfra-cli"
41
- Issues = "https://github.com/xenfra-cloud/xenfra-cli/issues"
42
38
 
43
39
  [project.optional-dependencies]
44
40
  test = [
@@ -46,6 +42,10 @@ test = [
46
42
  "pytest-mock>=3.12.0",
47
43
  ]
48
44
 
45
+ [project.urls]
46
+ Homepage = "https://github.com/xenfra-cloud/xenfra-cli"
47
+ Issues = "https://github.com/xenfra-cloud/xenfra-cli/issues"
48
+
49
49
  [project.scripts]
50
50
  xenfra = "xenfra.main:main"
51
51
 
@@ -0,0 +1,55 @@
1
+ """
2
+ Blueprint factory for framework detection and build plan generation.
3
+
4
+ Implements Railpack-first routing with 3-tier dry-run validation:
5
+ - Tier 1: Local validation (~100ms) - Syntax, imports, config
6
+ - Tier 2: Railpack plan (~1-2s) - Build plan generation
7
+ - Tier 3: E2B Sandbox (~30-60s) - Full build validation via Xenfra API
8
+
9
+ Tier 3 runs on Xenfra's servers - users don't need E2B installed.
10
+
11
+ Environment Variables:
12
+ - XENFRA_AI=off: Disable all AI features
13
+ - XENFRA_SANDBOX=force: Always run Tier 3 validation
14
+ - XENFRA_SANDBOX=skip: Skip Tier 3 validation
15
+ - XENFRA_SANDBOX=auto: Smart detection (default)
16
+ """
17
+
18
+ from .base import Blueprint, BuildPlan
19
+ from .factory import BlueprintFactory, get_factory, detect_project
20
+ from .railpack import RailpackBlueprint
21
+ from .dry_run import (
22
+ DryRunEngine,
23
+ DryRunResult,
24
+ run_dry_run,
25
+ quick_validate,
26
+ )
27
+ from .validation import ValidationResult, validate_project
28
+ from .e2b import E2BSandbox, SandboxResult, get_sandbox
29
+
30
+ __all__ = [
31
+ # Base classes
32
+ "Blueprint",
33
+ "BuildPlan",
34
+
35
+ # Factory
36
+ "BlueprintFactory",
37
+ "get_factory",
38
+ "detect_project",
39
+ "RailpackBlueprint",
40
+
41
+ # 3-Tier Dry Run
42
+ "DryRunEngine",
43
+ "DryRunResult",
44
+ "run_dry_run",
45
+ "quick_validate",
46
+
47
+ # Tier 1
48
+ "ValidationResult",
49
+ "validate_project",
50
+
51
+ # Tier 3
52
+ "E2BSandbox",
53
+ "SandboxResult",
54
+ "get_sandbox",
55
+ ]
@@ -0,0 +1,85 @@
1
+ """
2
+ Base blueprint interface for build plan generation.
3
+ """
4
+
5
+ from abc import ABC, abstractmethod
6
+ from dataclasses import dataclass, field
7
+ from typing import Optional
8
+ from pathlib import Path
9
+
10
+
11
+ @dataclass
12
+ class BuildPlan:
13
+ """A build plan containing all information needed to build and deploy."""
14
+
15
+ framework: str
16
+ language: str
17
+ package_manager: str
18
+ dependency_file: str
19
+ build_command: Optional[str] = None
20
+ start_command: Optional[str] = None
21
+ port: int = 8000
22
+ dockerfile: Optional[str] = None
23
+ env_vars: dict = field(default_factory=dict)
24
+ detected_from: str = "unknown" # How the framework was detected
25
+
26
+ def to_dict(self) -> dict:
27
+ """Convert build plan to dictionary."""
28
+ return {
29
+ "framework": self.framework,
30
+ "language": self.language,
31
+ "package_manager": self.package_manager,
32
+ "dependency_file": self.dependency_file,
33
+ "build_command": self.build_command,
34
+ "start_command": self.start_command,
35
+ "port": self.port,
36
+ "dockerfile": self.dockerfile,
37
+ "env_vars": self.env_vars,
38
+ "detected_from": self.detected_from,
39
+ }
40
+
41
+
42
+ class Blueprint(ABC):
43
+ """
44
+ Abstract base class for deployment blueprints.
45
+
46
+ Blueprints analyze project structure and generate build plans.
47
+ """
48
+
49
+ name: str = "base"
50
+ languages: list[str] = []
51
+
52
+ @abstractmethod
53
+ def detect(self, project_path: Path) -> bool:
54
+ """
55
+ Detect if this blueprint applies to the given project.
56
+
57
+ Args:
58
+ project_path: Path to the project directory
59
+
60
+ Returns:
61
+ True if this blueprint can handle the project
62
+ """
63
+ pass
64
+
65
+ @abstractmethod
66
+ def generate_plan(self, project_path: Path) -> BuildPlan:
67
+ """
68
+ Generate a build plan for the project.
69
+
70
+ Args:
71
+ project_path: Path to the project directory
72
+
73
+ Returns:
74
+ BuildPlan with all build/deployment information
75
+ """
76
+ pass
77
+
78
+ def get_priority(self) -> int:
79
+ """
80
+ Get the priority of this blueprint (higher = tried first).
81
+
82
+ Returns:
83
+ Priority integer
84
+ """
85
+ return 100
@@ -0,0 +1,286 @@
1
+ """
2
+ Smart detection and caching for Tier 3 validation decisions.
3
+
4
+ Tracks build state to determine when full sandbox validation is needed.
5
+ """
6
+
7
+ import hashlib
8
+ import json
9
+ import os
10
+ from datetime import datetime
11
+ from pathlib import Path
12
+ from typing import Optional
13
+ from dataclasses import dataclass, asdict
14
+
15
+
16
+ @dataclass
17
+ class BuildState:
18
+ """Cached state of a successful build."""
19
+ project_name: str
20
+ framework: str
21
+ language: str
22
+ dependency_hash: str
23
+ config_hash: str
24
+ build_plan_hash: str
25
+ status: str # "success" or "failed"
26
+ timestamp: str
27
+
28
+ def to_dict(self) -> dict:
29
+ return asdict(self)
30
+
31
+ @classmethod
32
+ def from_dict(cls, data: dict) -> "BuildState":
33
+ return cls(**data)
34
+
35
+
36
+ class BuildCache:
37
+ """
38
+ Manages build state cache for smart detection.
39
+
40
+ Stores hashes of key files to detect changes that would
41
+ require re-validation in the sandbox.
42
+ """
43
+
44
+ CACHE_DIR_NAME = ".xenfra"
45
+ CACHE_FILE_NAME = "build_state.json"
46
+
47
+ def __init__(self, project_path: Path):
48
+ self.project_path = project_path
49
+ self.cache_dir = project_path / self.CACHE_DIR_NAME
50
+ self.cache_file = self.cache_dir / self.CACHE_FILE_NAME
51
+
52
+ def get_cached_state(self) -> Optional[BuildState]:
53
+ """
54
+ Get the cached build state if it exists.
55
+
56
+ Returns:
57
+ BuildState if cache exists, None otherwise
58
+ """
59
+ if not self.cache_file.exists():
60
+ return None
61
+
62
+ try:
63
+ content = self.cache_file.read_text()
64
+ data = json.loads(content)
65
+ return BuildState.from_dict(data)
66
+ except (json.JSONDecodeError, KeyError, TypeError):
67
+ return None
68
+
69
+ def save_state(self, state: BuildState):
70
+ """
71
+ Save the build state to cache.
72
+
73
+ Args:
74
+ state: BuildState to cache
75
+ """
76
+ self.cache_dir.mkdir(exist_ok=True)
77
+ # Add to .gitignore if not already there
78
+ self._ensure_gitignore()
79
+
80
+ self.cache_file.write_text(json.dumps(state.to_dict(), indent=2))
81
+
82
+ def _ensure_gitignore(self):
83
+ """Ensure .xenfra is in .gitignore."""
84
+ gitignore = self.project_path / ".gitignore"
85
+ entry = ".xenfra/"
86
+
87
+ if gitignore.exists():
88
+ content = gitignore.read_text()
89
+ if entry not in content:
90
+ with open(gitignore, "a") as f:
91
+ f.write(f"\n{entry}\n")
92
+ else:
93
+ gitignore.write_text(f"{entry}\n")
94
+
95
+ def compute_dependency_hash(self, plan: "BuildPlan") -> str:
96
+ """
97
+ Compute hash of dependency files.
98
+
99
+ Args:
100
+ plan: BuildPlan with dependency information
101
+
102
+ Returns:
103
+ Hash string of dependency files
104
+ """
105
+ hasher = hashlib.sha256()
106
+
107
+ # Main dependency file
108
+ dep_file = self.project_path / plan.dependency_file
109
+ if dep_file.exists():
110
+ hasher.update(dep_file.read_bytes())
111
+
112
+ # Lock files
113
+ lock_files = {
114
+ "python": ["poetry.lock", "uv.lock", "Pipfile.lock"],
115
+ "node": ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb"],
116
+ "go": ["go.sum"],
117
+ "rust": ["Cargo.lock"],
118
+ "ruby": ["Gemfile.lock"],
119
+ }
120
+
121
+ for lock in lock_files.get(plan.language, []):
122
+ lock_path = self.project_path / lock
123
+ if lock_path.exists():
124
+ hasher.update(lock_path.read_bytes())
125
+
126
+ return hasher.hexdigest()[:16]
127
+
128
+ def compute_config_hash(self, plan: "BuildPlan") -> str:
129
+ """
130
+ Compute hash of configuration files.
131
+
132
+ Args:
133
+ plan: BuildPlan with configuration information
134
+
135
+ Returns:
136
+ Hash string of config files
137
+ """
138
+ hasher = hashlib.sha256()
139
+
140
+ # xenfra.yaml
141
+ config_file = self.project_path / "xenfra.yaml"
142
+ if config_file.exists():
143
+ hasher.update(config_file.read_bytes())
144
+
145
+ # Dockerfile
146
+ dockerfile = self.project_path / "Dockerfile"
147
+ if dockerfile.exists():
148
+ hasher.update(dockerfile.read_bytes())
149
+
150
+ # Docker Compose
151
+ compose_files = ["docker-compose.yml", "docker-compose.yaml"]
152
+ for cf in compose_files:
153
+ cf_path = self.project_path / cf
154
+ if cf_path.exists():
155
+ hasher.update(cf_path.read_bytes())
156
+
157
+ return hasher.hexdigest()[:16]
158
+
159
+ def compute_build_plan_hash(self, plan: "BuildPlan") -> str:
160
+ """
161
+ Compute hash of the build plan itself.
162
+
163
+ Args:
164
+ plan: BuildPlan to hash
165
+
166
+ Returns:
167
+ Hash string of build plan
168
+ """
169
+ plan_dict = plan.to_dict()
170
+ plan_str = json.dumps(plan_dict, sort_keys=True)
171
+ return hashlib.sha256(plan_str.encode()).hexdigest()[:16]
172
+
173
+
174
+ class SmartDetector:
175
+ """
176
+ Smart detection for Tier 3 (E2B) validation.
177
+
178
+ Determines when full sandbox validation is needed based on
179
+ changes to dependencies, config, or previous build failures.
180
+ """
181
+
182
+ def __init__(self, project_path: Path):
183
+ self.project_path = project_path
184
+ self.cache = BuildCache(project_path)
185
+
186
+ def should_run_sandbox(
187
+ self,
188
+ plan: "BuildPlan",
189
+ force: bool = False
190
+ ) -> tuple[bool, str]:
191
+ """
192
+ Determine if Tier 3 (E2B) validation should run.
193
+
194
+ Args:
195
+ plan: BuildPlan for the project
196
+ force: If True, always run sandbox
197
+
198
+ Returns:
199
+ Tuple of (should_run, reason)
200
+ """
201
+ if force:
202
+ return True, "Forced by --force flag"
203
+
204
+ # Check for environment variable override
205
+ sandbox_mode = os.environ.get("XENFRA_SANDBOX", "auto").lower()
206
+
207
+ if sandbox_mode == "force":
208
+ return True, "Forced by XENFRA_SANDBOX=force"
209
+
210
+ if sandbox_mode == "skip":
211
+ return False, "Skipped by XENFRA_SANDBOX=skip"
212
+
213
+ # Get cached state
214
+ cached = self.cache.get_cached_state()
215
+ if not cached:
216
+ return True, "First deployment - validation required"
217
+
218
+ # Compute current hashes
219
+ current_dep_hash = self.cache.compute_dependency_hash(plan)
220
+ current_config_hash = self.cache.compute_config_hash(plan)
221
+ current_plan_hash = self.cache.compute_build_plan_hash(plan)
222
+
223
+ # Check for failures
224
+ if cached.status == "failed":
225
+ return True, "Previous build failed - re-validation required"
226
+
227
+ # Check for dependency changes
228
+ if current_dep_hash != cached.dependency_hash:
229
+ return True, "Dependencies changed - validation required"
230
+
231
+ # Check for config changes
232
+ if current_config_hash != cached.config_hash:
233
+ return True, "Build configuration changed - validation required"
234
+
235
+ # Check for framework changes
236
+ if plan.framework != cached.framework:
237
+ return True, "Framework changed - validation required"
238
+
239
+ # Check for build plan changes
240
+ if current_plan_hash != cached.build_plan_hash:
241
+ return True, "Build plan changed - validation required"
242
+
243
+ return False, "No significant changes - skipping sandbox"
244
+
245
+ def record_success(self, plan: "BuildPlan"):
246
+ """
247
+ Record a successful build.
248
+
249
+ Args:
250
+ plan: BuildPlan that succeeded
251
+ """
252
+ state = BuildState(
253
+ project_name=self.project_path.name,
254
+ framework=plan.framework,
255
+ language=plan.language,
256
+ dependency_hash=self.cache.compute_dependency_hash(plan),
257
+ config_hash=self.cache.compute_config_hash(plan),
258
+ build_plan_hash=self.cache.compute_build_plan_hash(plan),
259
+ status="success",
260
+ timestamp=datetime.utcnow().isoformat()
261
+ )
262
+ self.cache.save_state(state)
263
+
264
+ def record_failure(self, plan: "BuildPlan"):
265
+ """
266
+ Record a failed build.
267
+
268
+ Args:
269
+ plan: BuildPlan that failed
270
+ """
271
+ state = BuildState(
272
+ project_name=self.project_path.name,
273
+ framework=plan.framework,
274
+ language=plan.language,
275
+ dependency_hash=self.cache.compute_dependency_hash(plan),
276
+ config_hash=self.cache.compute_config_hash(plan),
277
+ build_plan_hash=self.cache.compute_build_plan_hash(plan),
278
+ status="failed",
279
+ timestamp=datetime.utcnow().isoformat()
280
+ )
281
+ self.cache.save_state(state)
282
+
283
+
284
+ def get_detector(project_path: Path) -> SmartDetector:
285
+ """Get smart detector for a project."""
286
+ return SmartDetector(project_path)