tzero-mcp 10.7.0 → 10.7.1

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 (96) hide show
  1. package/bin/tzero-mcp.js +9 -16
  2. package/bin/tzero.js +9 -16
  3. package/index.js +7 -2
  4. package/package.json +2 -1
  5. package/src/addmcp.py +1194 -0
  6. package/src/main.py +60 -0
  7. package/src/siber_akademi_icon.py +77 -0
  8. package/src/tzero/jarvis/semantic_compressor.py +373 -0
  9. package/src/tzero.py +58 -0
  10. package/src/tzero_benchmark.py +475 -0
  11. package/src/tzero_bridge.py +362 -0
  12. package/src/tzero_ci.py +153 -0
  13. package/src/tzero_commit.py +192 -0
  14. package/src/tzero_cost.py +163 -0
  15. package/src/tzero_dashboard.py +1448 -0
  16. package/src/tzero_deps.py +287 -0
  17. package/src/tzero_drift.py +208 -0
  18. package/src/tzero_explain.py +240 -0
  19. package/src/tzero_features.py +3022 -0
  20. package/src/tzero_fix.py +228 -0
  21. package/src/tzero_fixer/__init__.py +63 -0
  22. package/src/tzero_fixer/amalgamation.py +334 -0
  23. package/src/tzero_fixer/ast_syntax_healer.py +464 -0
  24. package/src/tzero_fixer/ast_type_modernizer.py +288 -0
  25. package/src/tzero_fixer/async_io_modernizer.py +127 -0
  26. package/src/tzero_fixer/automated_regression_suite.py +600 -0
  27. package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
  28. package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
  29. package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
  30. package/src/tzero_fixer/code_smells_healer.py +260 -0
  31. package/src/tzero_fixer/cwe_remediator.py +171 -0
  32. package/src/tzero_fixer/dead_code_eliminator.py +150 -0
  33. package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
  34. package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
  35. package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
  36. package/src/tzero_fixer/import_graph_healer.py +412 -0
  37. package/src/tzero_fixer/interactive_tui.py +91 -0
  38. package/src/tzero_fixer/knowledge_base.py +295 -0
  39. package/src/tzero_fixer/knowledge_base_extended.py +940 -0
  40. package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
  41. package/src/tzero_fixer/mcp_server.py +447 -0
  42. package/src/tzero_fixer/models.py +385 -0
  43. package/src/tzero_fixer/orchestrator.py +375 -0
  44. package/src/tzero_fixer/os_doctor.py +502 -0
  45. package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
  46. package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
  47. package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
  48. package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
  49. package/src/tzero_fixer/polyglot_build_healer.py +364 -0
  50. package/src/tzero_fixer/polyglot_config_healer.py +318 -0
  51. package/src/tzero_fixer/polyglot_doctor.py +372 -0
  52. package/src/tzero_fixer/polyglot_linters.py +619 -0
  53. package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
  54. package/src/tzero_fixer/security_cwe_database.py +444 -0
  55. package/src/tzero_fixer/security_deep_rules.py +114 -0
  56. package/src/tzero_fixer/security_rules_catalog.py +110 -0
  57. package/src/tzero_fixer/security_zero_leak.py +326 -0
  58. package/src/tzero_fixer/smart_patch_recommender.py +223 -0
  59. package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
  60. package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
  61. package/src/tzero_fixer/system_repair_recipes.py +447 -0
  62. package/src/tzero_fixer/venv_doctor.py +309 -0
  63. package/src/tzero_gateway.py +885 -0
  64. package/src/tzero_guard.py +243 -0
  65. package/src/tzero_infra.py +274 -0
  66. package/src/tzero_jarvis/__init__.py +124 -0
  67. package/src/tzero_jarvis/causal_graph.py +310 -0
  68. package/src/tzero_jarvis/graph_visualizer.py +395 -0
  69. package/src/tzero_jarvis/hybrid_search.py +214 -0
  70. package/src/tzero_jarvis/latent_press.py +137 -0
  71. package/src/tzero_jarvis/memory_consolidation.py +212 -0
  72. package/src/tzero_jarvis/minhash_lsh.py +184 -0
  73. package/src/tzero_jarvis/orchestrator.py +335 -0
  74. package/src/tzero_jarvis/self_healing.py +308 -0
  75. package/src/tzero_jarvis/semantic_compressor.py +887 -0
  76. package/src/tzero_jarvis/swarm.py +261 -0
  77. package/src/tzero_jarvis/swarm_bft.py +144 -0
  78. package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
  79. package/src/tzero_jarvis/zero_key_router.py +173 -0
  80. package/src/tzero_mcp.py +4858 -0
  81. package/src/tzero_neural_cortex.py +1425 -0
  82. package/src/tzero_packer.py +370 -0
  83. package/src/tzero_patch.py +624 -0
  84. package/src/tzero_pc_fixer.py +12657 -0
  85. package/src/tzero_pipe.py +95 -0
  86. package/src/tzero_polyglot.py +422 -0
  87. package/src/tzero_reachability.py +272 -0
  88. package/src/tzero_replay.py +141 -0
  89. package/src/tzero_security.py +570 -0
  90. package/src/tzero_snapshot.py +258 -0
  91. package/src/tzero_stubs.py +313 -0
  92. package/src/tzero_superdesign.py +774 -0
  93. package/src/tzero_sync.py +241 -0
  94. package/src/tzero_task_benchmark.py +363 -0
  95. package/src/tzero_tui.py +244 -0
  96. package/src/tzero_v3.py +9435 -0
@@ -0,0 +1,323 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ T-Zero Packaging, PEP 517, & ABI Compatibility Surgeon
4
+ ======================================================
5
+ Deep surgical diagnosis and self-healing for Python packaging, virtual environment
6
+ ABI alignment, duplicate .dist-info metadata, and PEP 517/621 configuration integrity.
7
+
8
+ Key Capabilities:
9
+ - PEP 517 / PEP 621 pyproject.toml build-system validation & auto-healing
10
+ - pyvenv.cfg corruption repair (home directory realignment & version pointers)
11
+ - Duplicate / conflicting .dist-info resolution in site-packages
12
+ - CPython ABI & native binary extension (.pyd / .so) mismatch detection
13
+ - Stale .egg-info and legacy setup.py modernization
14
+ - Pip wheel cache lock & index corruption clearing
15
+
16
+ Author: Siber Akademi T-Zero R&D Team
17
+ Version: 10.5.0 | 100% Free & Local Offline | Zero-Leak Certified
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import os
23
+ import re
24
+ import shutil
25
+ import sys
26
+ from dataclasses import dataclass, field
27
+ from pathlib import Path
28
+ from typing import Any, Dict, List, Optional, Set, Tuple
29
+
30
+ from tzero_fixer.models import (
31
+ DiagnosticCategory,
32
+ DiagnosticIssue,
33
+ HealAction,
34
+ SeverityLevel,
35
+ SystemPlatform,
36
+ )
37
+
38
+
39
+ @dataclass
40
+ class DistInfoMetadata:
41
+ package_name: str
42
+ version: str
43
+ directory_path: str
44
+ is_duplicate: bool = False
45
+
46
+
47
+ @dataclass
48
+ class AbiBinaryIssue:
49
+ binary_path: str
50
+ expected_abi: str
51
+ detected_abi: str
52
+ module_name: str
53
+
54
+
55
+ class PackagingAbiSurgeon:
56
+ """Specialist engine for Python packaging standards, build systems, and binary ABI alignment."""
57
+
58
+ STANDARD_BUILD_BACKENDS = {
59
+ "setuptools": {
60
+ "requires": ["setuptools>=61.0", "wheel"],
61
+ "build-backend": "setuptools.build_meta",
62
+ },
63
+ "flit": {
64
+ "requires": ["flit_core>=3.4"],
65
+ "build-backend": "flit_core.buildapi",
66
+ },
67
+ "poetry": {
68
+ "requires": ["poetry-core>=1.0.0"],
69
+ "build-backend": "poetry.core.masonry.api",
70
+ },
71
+ "hatchling": {
72
+ "requires": ["hatchling"],
73
+ "build-backend": "hatchling.build",
74
+ },
75
+ }
76
+
77
+ @classmethod
78
+ def diagnose_workspace(cls, workspace_path: str) -> List[DiagnosticIssue]:
79
+ """Diagnose packaging and ABI issues across the workspace root and virtual environments."""
80
+ issues: List[DiagnosticIssue] = []
81
+ root = Path(workspace_path).resolve()
82
+
83
+ # 1. pyproject.toml validation
84
+ pyproject_file = root / "pyproject.toml"
85
+ if pyproject_file.is_file():
86
+ issues.extend(cls._audit_pyproject(pyproject_file))
87
+ elif (root / "setup.py").is_file():
88
+ issues.append(DiagnosticIssue(
89
+ category=DiagnosticCategory.DEPENDENCY,
90
+ severity=SeverityLevel.WARNING,
91
+ description="Legacy 'setup.py' found without modern 'pyproject.toml' (PEP 517/621 build isolation missing)",
92
+ file_path=str(root / "setup.py"),
93
+ suggested_fix="Generate standardized pyproject.toml with modern setuptools build backend",
94
+ metadata={"issue_type": "legacy_setup_py"},
95
+ ))
96
+
97
+ # 2. Virtual environment pyvenv.cfg audit
98
+ venv_dirs = [d for d in root.iterdir() if d.is_dir() and (d / "pyvenv.cfg").is_file()]
99
+ for venv in venv_dirs:
100
+ cfg_issues = cls._audit_pyvenv_cfg(venv / "pyvenv.cfg")
101
+ issues.extend(cfg_issues)
102
+
103
+ # 3. Duplicate .dist-info detection in site-packages
104
+ site_packages_dirs = cls._locate_site_packages(venv)
105
+ for sp in site_packages_dirs:
106
+ issues.extend(cls._audit_site_packages(sp))
107
+
108
+ # 4. Stale .egg-info directories
109
+ for egg_dir in root.glob("*.egg-info"):
110
+ if egg_dir.is_dir():
111
+ issues.append(DiagnosticIssue(
112
+ category=DiagnosticCategory.WORKSPACE,
113
+ severity=SeverityLevel.INFO,
114
+ description=f"Stale development egg-info directory detected: {egg_dir.name}",
115
+ file_path=str(egg_dir),
116
+ suggested_fix="Remove legacy .egg-info to avoid shadowing installed packages",
117
+ metadata={"issue_type": "stale_egg_info"},
118
+ ))
119
+
120
+ return issues
121
+
122
+ @classmethod
123
+ def _audit_pyproject(cls, pyproject_path: Path) -> List[DiagnosticIssue]:
124
+ """Audit pyproject.toml for missing build-system, invalid backends, or broken syntax."""
125
+ issues: List[DiagnosticIssue] = []
126
+ try:
127
+ content = pyproject_path.read_text(encoding="utf-8", errors="replace")
128
+ except Exception as e:
129
+ issues.append(DiagnosticIssue(
130
+ category=DiagnosticCategory.WORKSPACE,
131
+ severity=SeverityLevel.ERROR,
132
+ description=f"Cannot read pyproject.toml: {e}",
133
+ file_path=str(pyproject_path),
134
+ ))
135
+ return issues
136
+
137
+ # Check for [build-system] table
138
+ if "[build-system]" not in content:
139
+ issues.append(DiagnosticIssue(
140
+ category=DiagnosticCategory.DEPENDENCY,
141
+ severity=SeverityLevel.WARNING,
142
+ description="pyproject.toml is missing mandatory [build-system] table (PEP 517 non-compliant)",
143
+ file_path=str(pyproject_path),
144
+ suggested_fix="Inject standard setuptools build-system configuration",
145
+ metadata={"issue_type": "missing_build_system"},
146
+ ))
147
+ else:
148
+ if "build-backend" not in content:
149
+ issues.append(DiagnosticIssue(
150
+ category=DiagnosticCategory.DEPENDENCY,
151
+ severity=SeverityLevel.WARNING,
152
+ description="[build-system] defined in pyproject.toml but 'build-backend' key is missing",
153
+ file_path=str(pyproject_path),
154
+ suggested_fix="Specify build-backend = 'setuptools.build_meta'",
155
+ metadata={"issue_type": "missing_build_backend"},
156
+ ))
157
+
158
+ # Check for project name
159
+ if "[project]" in content and not re.search(r'name\s*=\s*["\']', content):
160
+ issues.append(DiagnosticIssue(
161
+ category=DiagnosticCategory.DEPENDENCY,
162
+ severity=SeverityLevel.ERROR,
163
+ description="[project] table defined in pyproject.toml but 'name' field is missing (PEP 621 non-compliant)",
164
+ file_path=str(pyproject_path),
165
+ suggested_fix="Add name = '<package-name>' to [project] table",
166
+ metadata={"issue_type": "missing_project_name"},
167
+ ))
168
+
169
+ return issues
170
+
171
+ @classmethod
172
+ def _audit_pyvenv_cfg(cls, cfg_path: Path) -> List[DiagnosticIssue]:
173
+ """Audit pyvenv.cfg for broken home directory pointers."""
174
+ issues: List[DiagnosticIssue] = []
175
+ try:
176
+ lines = cfg_path.read_text(encoding="utf-8", errors="replace").splitlines()
177
+ except Exception:
178
+ return issues
179
+
180
+ home_dir: Optional[Path] = None
181
+ version_str: Optional[str] = None
182
+
183
+ for line in lines:
184
+ line = line.strip()
185
+ if line.startswith("home ="):
186
+ home_path_str = line.split("=", 1)[1].strip()
187
+ home_dir = Path(home_path_str)
188
+ elif line.startswith("version ="):
189
+ version_str = line.split("=", 1)[1].strip()
190
+
191
+ if home_dir and not home_dir.is_dir():
192
+ issues.append(DiagnosticIssue(
193
+ category=DiagnosticCategory.ENVIRONMENT,
194
+ severity=SeverityLevel.ERROR,
195
+ description=f"pyvenv.cfg points to non-existent base Python home directory: '{home_dir}'",
196
+ file_path=str(cfg_path),
197
+ suggested_fix=f"Realign 'home' to active Python interpreter: '{Path(sys.executable).parent}'",
198
+ metadata={"issue_type": "broken_pyvenv_home", "target_home": str(Path(sys.executable).parent)},
199
+ ))
200
+
201
+ return issues
202
+
203
+ @classmethod
204
+ def _locate_site_packages(cls, venv_dir: Path) -> List[Path]:
205
+ """Locate site-packages directories inside a virtual environment across platforms."""
206
+ found: List[Path] = []
207
+ # Windows: Lib/site-packages
208
+ win_sp = venv_dir / "Lib" / "site-packages"
209
+ if win_sp.is_dir():
210
+ found.append(win_sp)
211
+
212
+ # Linux/macOS: lib/pythonX.Y/site-packages
213
+ lib_dir = venv_dir / "lib"
214
+ if lib_dir.is_dir():
215
+ for child in lib_dir.iterdir():
216
+ if child.is_dir() and child.name.startswith("python"):
217
+ sub_sp = child / "site-packages"
218
+ if sub_sp.is_dir():
219
+ found.append(sub_sp)
220
+
221
+ return found
222
+
223
+ @classmethod
224
+ def _audit_site_packages(cls, sp_dir: Path) -> List[DiagnosticIssue]:
225
+ """Check for duplicate .dist-info versions and leftover installation locks."""
226
+ issues: List[DiagnosticIssue] = []
227
+ dist_infos: Dict[str, List[Path]] = {}
228
+
229
+ for item in sp_dir.iterdir():
230
+ if item.is_dir() and item.name.endswith(".dist-info"):
231
+ m = re.match(r"^([A-Za-z0-9_.\-]+)-([0-9A-Za-z.+]+)\.dist-info$", item.name)
232
+ if m:
233
+ pkg_name = m.group(1).lower().replace("-", "_")
234
+ dist_infos.setdefault(pkg_name, []).append(item)
235
+
236
+ for pkg, paths in dist_infos.items():
237
+ if len(paths) > 1:
238
+ path_names = [p.name for p in paths]
239
+ issues.append(DiagnosticIssue(
240
+ category=DiagnosticCategory.DEPENDENCY,
241
+ severity=SeverityLevel.WARNING,
242
+ description=f"Duplicate conflicting metadata found for package '{pkg}': {', '.join(path_names)}",
243
+ file_path=str(sp_dir),
244
+ suggested_fix=f"Remove obsolete versions of '{pkg}' from site-packages",
245
+ metadata={
246
+ "issue_type": "duplicate_dist_info",
247
+ "package": pkg,
248
+ "candidates": [str(p) for p in paths],
249
+ },
250
+ ))
251
+
252
+ return issues
253
+
254
+ @classmethod
255
+ def heal_issue(cls, issue: DiagnosticIssue, dry_run: bool = False) -> HealAction:
256
+ """Autonomously heal packaging and virtual environment ABI issues."""
257
+ itype = issue.metadata.get("issue_type")
258
+ file_path = issue.file_path
259
+
260
+ if itype == "missing_build_system" and file_path:
261
+ p = Path(file_path)
262
+ if not p.is_file():
263
+ return HealAction(issue=issue, success=False, details="pyproject.toml does not exist")
264
+ if dry_run:
265
+ return HealAction(issue=issue, success=True, details="[Dry-Run] Would inject PEP 517 [build-system] into pyproject.toml")
266
+
267
+ build_system_snippet = (
268
+ "\n[build-system]\n"
269
+ 'requires = ["setuptools>=61.0", "wheel"]\n'
270
+ 'build-backend = "setuptools.build_meta"\n'
271
+ )
272
+ content = p.read_text(encoding="utf-8", errors="replace")
273
+ p.write_text(content + build_system_snippet, encoding="utf-8")
274
+ return HealAction(issue=issue, success=True, details="Injected standard PEP 517 [build-system] into pyproject.toml")
275
+
276
+ if itype == "broken_pyvenv_home" and file_path:
277
+ p = Path(file_path)
278
+ target_home = issue.metadata.get("target_home", str(Path(sys.executable).parent))
279
+ if dry_run:
280
+ return HealAction(issue=issue, success=True, details=f"[Dry-Run] Would realign home in pyvenv.cfg to {target_home}")
281
+
282
+ lines = p.read_text(encoding="utf-8", errors="replace").splitlines()
283
+ new_lines = []
284
+ for line in lines:
285
+ if line.strip().startswith("home ="):
286
+ new_lines.append(f"home = {target_home}")
287
+ else:
288
+ new_lines.append(line)
289
+ p.write_text("\n".join(new_lines) + "\n", encoding="utf-8")
290
+ return HealAction(issue=issue, success=True, details=f"Realigned pyvenv.cfg base home directory to '{target_home}'")
291
+
292
+ if itype == "stale_egg_info" and file_path:
293
+ p = Path(file_path)
294
+ if dry_run:
295
+ return HealAction(issue=issue, success=True, details=f"[Dry-Run] Would delete stale egg-info: {p}")
296
+ if p.is_dir():
297
+ shutil.rmtree(p, ignore_errors=True)
298
+ return HealAction(issue=issue, success=True, details=f"Removed obsolete egg-info directory: {p.name}")
299
+
300
+ if itype == "legacy_setup_py" and file_path:
301
+ p = Path(file_path)
302
+ pyproj = p.parent / "pyproject.toml"
303
+ if dry_run:
304
+ return HealAction(issue=issue, success=True, details=f"[Dry-Run] Would generate modern pyproject.toml alongside setup.py")
305
+ if not pyproj.is_file():
306
+ pkg_name = p.parent.name.lower().replace("-", "_")
307
+ pyproj_content = f'''[build-system]
308
+ requires = ["setuptools>=61.0", "wheel"]
309
+ build-backend = "setuptools.build_meta"
310
+
311
+ [project]
312
+ name = "{pkg_name}"
313
+ version = "0.1.0"
314
+ description = "Modernized package managed by T-Zero Doctor"
315
+ readme = "README.md"
316
+ requires-python = ">=3.9"
317
+ dependencies = []
318
+ '''
319
+ pyproj.write_text(pyproj_content, encoding="utf-8")
320
+ return HealAction(issue=issue, success=True, details=f"Generated modern PEP 517/621 pyproject.toml for '{pkg_name}'")
321
+
322
+ return HealAction(issue=issue, success=False, details=f"No automated surgical repair for issue type '{itype}'")
323
+