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.
- package/bin/tzero-mcp.js +9 -16
- package/bin/tzero.js +9 -16
- package/index.js +7 -2
- package/package.json +2 -1
- package/src/addmcp.py +1194 -0
- package/src/main.py +60 -0
- package/src/siber_akademi_icon.py +77 -0
- package/src/tzero/jarvis/semantic_compressor.py +373 -0
- package/src/tzero.py +58 -0
- package/src/tzero_benchmark.py +475 -0
- package/src/tzero_bridge.py +362 -0
- package/src/tzero_ci.py +153 -0
- package/src/tzero_commit.py +192 -0
- package/src/tzero_cost.py +163 -0
- package/src/tzero_dashboard.py +1448 -0
- package/src/tzero_deps.py +287 -0
- package/src/tzero_drift.py +208 -0
- package/src/tzero_explain.py +240 -0
- package/src/tzero_features.py +3022 -0
- package/src/tzero_fix.py +228 -0
- package/src/tzero_fixer/__init__.py +63 -0
- package/src/tzero_fixer/amalgamation.py +334 -0
- package/src/tzero_fixer/ast_syntax_healer.py +464 -0
- package/src/tzero_fixer/ast_type_modernizer.py +288 -0
- package/src/tzero_fixer/async_io_modernizer.py +127 -0
- package/src/tzero_fixer/automated_regression_suite.py +600 -0
- package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
- package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
- package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
- package/src/tzero_fixer/code_smells_healer.py +260 -0
- package/src/tzero_fixer/cwe_remediator.py +171 -0
- package/src/tzero_fixer/dead_code_eliminator.py +150 -0
- package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
- package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
- package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
- package/src/tzero_fixer/import_graph_healer.py +412 -0
- package/src/tzero_fixer/interactive_tui.py +91 -0
- package/src/tzero_fixer/knowledge_base.py +295 -0
- package/src/tzero_fixer/knowledge_base_extended.py +940 -0
- package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
- package/src/tzero_fixer/mcp_server.py +447 -0
- package/src/tzero_fixer/models.py +385 -0
- package/src/tzero_fixer/orchestrator.py +375 -0
- package/src/tzero_fixer/os_doctor.py +502 -0
- package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
- package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
- package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
- package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
- package/src/tzero_fixer/polyglot_build_healer.py +364 -0
- package/src/tzero_fixer/polyglot_config_healer.py +318 -0
- package/src/tzero_fixer/polyglot_doctor.py +372 -0
- package/src/tzero_fixer/polyglot_linters.py +619 -0
- package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
- package/src/tzero_fixer/security_cwe_database.py +444 -0
- package/src/tzero_fixer/security_deep_rules.py +114 -0
- package/src/tzero_fixer/security_rules_catalog.py +110 -0
- package/src/tzero_fixer/security_zero_leak.py +326 -0
- package/src/tzero_fixer/smart_patch_recommender.py +223 -0
- package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
- package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
- package/src/tzero_fixer/system_repair_recipes.py +447 -0
- package/src/tzero_fixer/venv_doctor.py +309 -0
- package/src/tzero_gateway.py +885 -0
- package/src/tzero_guard.py +243 -0
- package/src/tzero_infra.py +274 -0
- package/src/tzero_jarvis/__init__.py +124 -0
- package/src/tzero_jarvis/causal_graph.py +310 -0
- package/src/tzero_jarvis/graph_visualizer.py +395 -0
- package/src/tzero_jarvis/hybrid_search.py +214 -0
- package/src/tzero_jarvis/latent_press.py +137 -0
- package/src/tzero_jarvis/memory_consolidation.py +212 -0
- package/src/tzero_jarvis/minhash_lsh.py +184 -0
- package/src/tzero_jarvis/orchestrator.py +335 -0
- package/src/tzero_jarvis/self_healing.py +308 -0
- package/src/tzero_jarvis/semantic_compressor.py +887 -0
- package/src/tzero_jarvis/swarm.py +261 -0
- package/src/tzero_jarvis/swarm_bft.py +144 -0
- package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
- package/src/tzero_jarvis/zero_key_router.py +173 -0
- package/src/tzero_mcp.py +4858 -0
- package/src/tzero_neural_cortex.py +1425 -0
- package/src/tzero_packer.py +370 -0
- package/src/tzero_patch.py +624 -0
- package/src/tzero_pc_fixer.py +12657 -0
- package/src/tzero_pipe.py +95 -0
- package/src/tzero_polyglot.py +422 -0
- package/src/tzero_reachability.py +272 -0
- package/src/tzero_replay.py +141 -0
- package/src/tzero_security.py +570 -0
- package/src/tzero_snapshot.py +258 -0
- package/src/tzero_stubs.py +313 -0
- package/src/tzero_superdesign.py +774 -0
- package/src/tzero_sync.py +241 -0
- package/src/tzero_task_benchmark.py +363 -0
- package/src/tzero_tui.py +244 -0
- package/src/tzero_v3.py +9435 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""T-Zero Explain: Ultra-Dense AST Architectural Passport Generator.
|
|
3
|
+
|
|
4
|
+
Generates high-density, prompt-ready architectural passports for codebases and files,
|
|
5
|
+
delivering maximum semantic grounding to LLMs (Claude, GPT, Gemini, DeepSeek) with
|
|
6
|
+
up to 95% token savings compared to raw file ingestion.
|
|
7
|
+
|
|
8
|
+
Author: Toprak Ahmet Aydogmus (Siber Akademi)
|
|
9
|
+
Version: 10.5.0
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import ast
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
if sys.platform == "win32":
|
|
17
|
+
try:
|
|
18
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
19
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
20
|
+
if hasattr(sys.stderr, "reconfigure"):
|
|
21
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
22
|
+
except Exception:
|
|
23
|
+
pass
|
|
24
|
+
from dataclasses import asdict, dataclass, field
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class SymbolPassport:
|
|
31
|
+
name: str
|
|
32
|
+
kind: str # 'class', 'function', 'async_function'
|
|
33
|
+
lineno: int
|
|
34
|
+
docstring: Optional[str]
|
|
35
|
+
signatures: List[str] = field(default_factory=list)
|
|
36
|
+
complexity: int = 1
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class ModulePassport:
|
|
41
|
+
file_path: str
|
|
42
|
+
module_name: str
|
|
43
|
+
docstring: Optional[str]
|
|
44
|
+
raw_lines: int
|
|
45
|
+
raw_tokens: int
|
|
46
|
+
passport_tokens: int
|
|
47
|
+
token_savings_pct: float
|
|
48
|
+
role: str # 'presentation', 'business_service', 'data_model', 'utility'
|
|
49
|
+
symbols: List[SymbolPassport] = field(default_factory=list)
|
|
50
|
+
dependencies_internal: List[str] = field(default_factory=list)
|
|
51
|
+
dependencies_external: List[str] = field(default_factory=list)
|
|
52
|
+
markdown_passport: str = ""
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ArchitecturalPassportGenerator:
|
|
56
|
+
"""Extracts ultra-dense AST architecture passports for LLM prompts."""
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def _estimate_tokens(text: str) -> int:
|
|
60
|
+
return max(1, int(len(text) / 3.8))
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def _compute_complexity(cls, node: ast.AST) -> int:
|
|
64
|
+
"""Calculate cyclomatic complexity of an AST node."""
|
|
65
|
+
complexity = 1
|
|
66
|
+
for child in ast.walk(node):
|
|
67
|
+
if isinstance(child, (ast.If, ast.While, ast.For, ast.ExceptHandler,
|
|
68
|
+
ast.With, ast.Assert, ast.comprehension)):
|
|
69
|
+
complexity += 1
|
|
70
|
+
elif isinstance(child, ast.BoolOp):
|
|
71
|
+
complexity += len(child.values) - 1
|
|
72
|
+
return complexity
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def _classify_role(cls, path_str: str, symbols: List[SymbolPassport]) -> str:
|
|
76
|
+
name = Path(path_str).stem.lower()
|
|
77
|
+
parent_parts = [p.lower() for p in Path(path_str).parent.parts]
|
|
78
|
+
if any(k in name for k in ("cli", "gui", "tui", "view", "api", "mcp", "endpoint", "controller")) or any(k in parent_parts for k in ("cli", "gui", "ui", "views", "api", "mcp", "routes", "controllers")):
|
|
79
|
+
return "presentation"
|
|
80
|
+
elif any(k in name for k in ("model", "schema", "dto", "entity")) or any(k in parent_parts for k in ("models", "schemas", "dtos", "entities")):
|
|
81
|
+
return "data_model"
|
|
82
|
+
elif any(k in name for k in ("util", "helper", "common", "tools")) or any(k in parent_parts for k in ("utils", "helpers", "common")):
|
|
83
|
+
return "utility"
|
|
84
|
+
elif any(s.name.endswith(("Service", "Engine", "Manager", "Analyzer", "Architect", "Orchestrator")) for s in symbols):
|
|
85
|
+
return "business_service"
|
|
86
|
+
return "business_service"
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def explain_file(cls, file_path: str) -> ModulePassport:
|
|
90
|
+
"""Generate high-density AST passport for a single Python file."""
|
|
91
|
+
p = Path(file_path).resolve()
|
|
92
|
+
if not p.is_file():
|
|
93
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
with open(p, "r", encoding="utf-8", errors="replace") as f:
|
|
97
|
+
content = f.read()
|
|
98
|
+
except Exception as e:
|
|
99
|
+
raise IOError(f"Cannot read file {file_path}: {e}")
|
|
100
|
+
|
|
101
|
+
raw_lines = len(content.splitlines())
|
|
102
|
+
raw_tokens = cls._estimate_tokens(content)
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
tree = ast.parse(content, filename=str(p))
|
|
106
|
+
module_doc = ast.get_docstring(tree)
|
|
107
|
+
except SyntaxError:
|
|
108
|
+
module_doc = None
|
|
109
|
+
tree = None
|
|
110
|
+
|
|
111
|
+
symbols: List[SymbolPassport] = []
|
|
112
|
+
internal_deps: Set[str] = set()
|
|
113
|
+
external_deps: Set[str] = set()
|
|
114
|
+
|
|
115
|
+
if tree:
|
|
116
|
+
for node in tree.body:
|
|
117
|
+
if isinstance(node, ast.Import):
|
|
118
|
+
for alias in node.names:
|
|
119
|
+
base = alias.name.split(".")[0]
|
|
120
|
+
if base in sys.builtin_module_names or base in ("os", "sys", "json", "re", "math", "typing", "pathlib", "ast", "time", "shutil"):
|
|
121
|
+
external_deps.add(base)
|
|
122
|
+
else:
|
|
123
|
+
internal_deps.add(base)
|
|
124
|
+
elif isinstance(node, ast.ImportFrom):
|
|
125
|
+
if node.module:
|
|
126
|
+
base = node.module.split(".")[0]
|
|
127
|
+
if node.level > 0 or base not in sys.builtin_module_names:
|
|
128
|
+
internal_deps.add(node.module)
|
|
129
|
+
else:
|
|
130
|
+
external_deps.add(base)
|
|
131
|
+
|
|
132
|
+
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
133
|
+
fn_doc = ast.get_docstring(node)
|
|
134
|
+
# build signature
|
|
135
|
+
args_list = []
|
|
136
|
+
for a in node.args.args:
|
|
137
|
+
ann = f": {ast.unparse(a.annotation)}" if a.annotation else ""
|
|
138
|
+
args_list.append(f"{a.arg}{ann}")
|
|
139
|
+
ret = f" -> {ast.unparse(node.returns)}" if node.returns else ""
|
|
140
|
+
sig = f"def {node.name}({', '.join(args_list)}){ret}"
|
|
141
|
+
symbols.append(SymbolPassport(
|
|
142
|
+
name=node.name,
|
|
143
|
+
kind="async_function" if isinstance(node, ast.AsyncFunctionDef) else "function",
|
|
144
|
+
lineno=node.lineno,
|
|
145
|
+
docstring=fn_doc.split("\n")[0] if fn_doc else None,
|
|
146
|
+
signatures=[sig],
|
|
147
|
+
complexity=cls._compute_complexity(node)
|
|
148
|
+
))
|
|
149
|
+
|
|
150
|
+
elif isinstance(node, ast.ClassDef):
|
|
151
|
+
cls_doc = ast.get_docstring(node)
|
|
152
|
+
bases = [ast.unparse(b) for b in node.bases]
|
|
153
|
+
base_str = f"({', '.join(bases)})" if bases else ""
|
|
154
|
+
methods_sig = []
|
|
155
|
+
for item in node.body:
|
|
156
|
+
if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
157
|
+
m_args = []
|
|
158
|
+
for a in item.args.args:
|
|
159
|
+
m_ann = f": {ast.unparse(a.annotation)}" if a.annotation else ""
|
|
160
|
+
m_args.append(f"{a.arg}{m_ann}")
|
|
161
|
+
m_ret = f" -> {ast.unparse(item.returns)}" if item.returns else ""
|
|
162
|
+
methods_sig.append(f" def {item.name}({', '.join(m_args)}){m_ret}")
|
|
163
|
+
|
|
164
|
+
symbols.append(SymbolPassport(
|
|
165
|
+
name=node.name,
|
|
166
|
+
kind="class",
|
|
167
|
+
lineno=node.lineno,
|
|
168
|
+
docstring=cls_doc.split("\n")[0] if cls_doc else None,
|
|
169
|
+
signatures=[f"class {node.name}{base_str}:"] + methods_sig[:10],
|
|
170
|
+
complexity=cls._compute_complexity(node)
|
|
171
|
+
))
|
|
172
|
+
|
|
173
|
+
role = cls._classify_role(str(p), symbols)
|
|
174
|
+
|
|
175
|
+
# Build Markdown Passport
|
|
176
|
+
md_lines = [
|
|
177
|
+
f"### 🏛️ AST Architectural Passport: `{p.name}`",
|
|
178
|
+
f"- **Role:** `{role.upper()}` | **Lines:** {raw_lines} | **Symbols:** {len(symbols)}",
|
|
179
|
+
]
|
|
180
|
+
if module_doc:
|
|
181
|
+
md_lines.append(f"- **Purpose:** {module_doc.strip().splitlines()[0]}")
|
|
182
|
+
if internal_deps:
|
|
183
|
+
md_lines.append(f"- **Internal Dependencies:** `{', '.join(sorted(internal_deps)[:6])}`")
|
|
184
|
+
if external_deps:
|
|
185
|
+
md_lines.append(f"- **External Dependencies:** `{', '.join(sorted(external_deps)[:6])}`")
|
|
186
|
+
|
|
187
|
+
md_lines.append("\n```python")
|
|
188
|
+
for sym in symbols:
|
|
189
|
+
doc_str = f" # {sym.docstring}" if sym.docstring else ""
|
|
190
|
+
if sym.kind == "class":
|
|
191
|
+
md_lines.append(f"{sym.signatures[0]}{doc_str}")
|
|
192
|
+
for ms in sym.signatures[1:]:
|
|
193
|
+
md_lines.append(ms)
|
|
194
|
+
else:
|
|
195
|
+
md_lines.append(f"{sym.signatures[0]}: ...{doc_str}")
|
|
196
|
+
md_lines.append("```\n")
|
|
197
|
+
|
|
198
|
+
markdown_passport = "\n".join(md_lines)
|
|
199
|
+
passport_tokens = cls._estimate_tokens(markdown_passport)
|
|
200
|
+
savings_pct = round(max(0.0, (1.0 - passport_tokens / max(1, raw_tokens)) * 100), 1)
|
|
201
|
+
|
|
202
|
+
return ModulePassport(
|
|
203
|
+
file_path=str(p),
|
|
204
|
+
module_name=p.stem,
|
|
205
|
+
docstring=module_doc,
|
|
206
|
+
raw_lines=raw_lines,
|
|
207
|
+
raw_tokens=raw_tokens,
|
|
208
|
+
passport_tokens=passport_tokens,
|
|
209
|
+
token_savings_pct=savings_pct,
|
|
210
|
+
role=role,
|
|
211
|
+
symbols=symbols,
|
|
212
|
+
dependencies_internal=sorted(internal_deps),
|
|
213
|
+
dependencies_external=sorted(external_deps),
|
|
214
|
+
markdown_passport=markdown_passport
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
@classmethod
|
|
218
|
+
def render_cli(cls, passport: ModulePassport):
|
|
219
|
+
"""Render passport output to stdout."""
|
|
220
|
+
print("=" * 80)
|
|
221
|
+
print("\033[1;36m🏛️ T-ZERO AST ARCHITECTURAL PASSPORT\033[0m")
|
|
222
|
+
print("=" * 80)
|
|
223
|
+
print(f"File: \033[33m{passport.file_path}\033[0m")
|
|
224
|
+
print(f"Module: \033[32m{passport.module_name}\033[0m")
|
|
225
|
+
print(f"Layer Role: \033[1;35m{passport.role.upper()}\033[0m")
|
|
226
|
+
print(f"Token Economy: Raw: \033[31m{passport.raw_tokens:,} tokens\033[0m -> "
|
|
227
|
+
f"Passport: \033[32m{passport.passport_tokens:,} tokens\033[0m "
|
|
228
|
+
f"(\033[1;32m-{passport.token_savings_pct}%\033[0m reduction)")
|
|
229
|
+
print("-" * 80)
|
|
230
|
+
print(passport.markdown_passport)
|
|
231
|
+
print("=" * 80)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
if __name__ == "__main__":
|
|
235
|
+
if len(sys.argv) < 2:
|
|
236
|
+
print("Usage: python tzero_explain.py <path_to_file.py>")
|
|
237
|
+
sys.exit(1)
|
|
238
|
+
target = sys.argv[1]
|
|
239
|
+
res = ArchitecturalPassportGenerator.explain_file(target)
|
|
240
|
+
ArchitecturalPassportGenerator.render_cli(res)
|