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,362 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Siber Akademi — T-Zero Universal Polyglot Type & Schema Transpiler.
|
|
4
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
+
License: MIT
|
|
6
|
+
|
|
7
|
+
Transpiles Python @dataclass and Pydantic data models into TypeScript interfaces,
|
|
8
|
+
Rust structs, and Go structs deterministically via AST.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
import ast
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Dict, List, Any, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class ModelField:
|
|
20
|
+
name: str
|
|
21
|
+
py_type: str
|
|
22
|
+
is_optional: bool = False
|
|
23
|
+
doc: str = ""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class TranspiledModel:
|
|
28
|
+
class_name: str
|
|
29
|
+
fields: List[ModelField] = field(default_factory=list)
|
|
30
|
+
docstring: str = ""
|
|
31
|
+
typescript: str = ""
|
|
32
|
+
rust: str = ""
|
|
33
|
+
golang: str = ""
|
|
34
|
+
kotlin: str = ""
|
|
35
|
+
swift: str = ""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PolyglotTypeBridge:
|
|
39
|
+
"""Deterministic Polyglot Type & Schema Transpiler."""
|
|
40
|
+
|
|
41
|
+
# Type Mapping Tables
|
|
42
|
+
TYPE_MAP_TS = {
|
|
43
|
+
"str": "string",
|
|
44
|
+
"int": "number",
|
|
45
|
+
"float": "number",
|
|
46
|
+
"bool": "boolean",
|
|
47
|
+
"bytes": "Uint8Array",
|
|
48
|
+
"dict": "Record<string, any>",
|
|
49
|
+
"list": "any[]",
|
|
50
|
+
"set": "Set<any>",
|
|
51
|
+
"tuple": "[any]",
|
|
52
|
+
"Any": "any",
|
|
53
|
+
"datetime": "string",
|
|
54
|
+
"date": "string",
|
|
55
|
+
"UUID": "string",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
TYPE_MAP_RUST = {
|
|
59
|
+
"str": "String",
|
|
60
|
+
"int": "i64",
|
|
61
|
+
"float": "f64",
|
|
62
|
+
"bool": "bool",
|
|
63
|
+
"bytes": "Vec<u8>",
|
|
64
|
+
"dict": "std::collections::HashMap<String, serde_json::Value>",
|
|
65
|
+
"list": "Vec<serde_json::Value>",
|
|
66
|
+
"set": "std::collections::HashSet<String>",
|
|
67
|
+
"Any": "serde_json::Value",
|
|
68
|
+
"datetime": "chrono::DateTime<chrono::Utc>",
|
|
69
|
+
"date": "chrono::NaiveDate",
|
|
70
|
+
"UUID": "uuid::Uuid",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
TYPE_MAP_GO = {
|
|
74
|
+
"str": "string",
|
|
75
|
+
"int": "int64",
|
|
76
|
+
"float": "float64",
|
|
77
|
+
"bool": "bool",
|
|
78
|
+
"bytes": "[]byte",
|
|
79
|
+
"dict": "map[string]interface{}",
|
|
80
|
+
"list": "[]interface{}",
|
|
81
|
+
"set": "[]string",
|
|
82
|
+
"Any": "interface{}",
|
|
83
|
+
"datetime": "time.Time",
|
|
84
|
+
"date": "time.Time",
|
|
85
|
+
"UUID": "string",
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
TYPE_MAP_KOTLIN = {
|
|
89
|
+
"str": "String",
|
|
90
|
+
"int": "Long",
|
|
91
|
+
"float": "Double",
|
|
92
|
+
"bool": "Boolean",
|
|
93
|
+
"bytes": "ByteArray",
|
|
94
|
+
"dict": "Map<String, Any>",
|
|
95
|
+
"list": "List<Any>",
|
|
96
|
+
"set": "Set<String>",
|
|
97
|
+
"Any": "Any",
|
|
98
|
+
"datetime": "java.time.Instant",
|
|
99
|
+
"date": "java.time.LocalDate",
|
|
100
|
+
"UUID": "java.util.UUID",
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
TYPE_MAP_SWIFT = {
|
|
104
|
+
"str": "String",
|
|
105
|
+
"int": "Int",
|
|
106
|
+
"float": "Double",
|
|
107
|
+
"bool": "Bool",
|
|
108
|
+
"bytes": "Data",
|
|
109
|
+
"dict": "[String: Any]",
|
|
110
|
+
"list": "[Any]",
|
|
111
|
+
"set": "Set<String>",
|
|
112
|
+
"Any": "Any",
|
|
113
|
+
"datetime": "Date",
|
|
114
|
+
"date": "Date",
|
|
115
|
+
"UUID": "UUID",
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@classmethod
|
|
119
|
+
def _parse_py_type(cls, node: ast.AST) -> Tuple[str, bool]:
|
|
120
|
+
"""Returns (base_type_str, is_optional)."""
|
|
121
|
+
if node is None:
|
|
122
|
+
return "Any", False
|
|
123
|
+
|
|
124
|
+
# e.g. Optional[T] or Union[T, None]
|
|
125
|
+
if isinstance(node, ast.Subscript):
|
|
126
|
+
val_name = getattr(node.value, "id", "")
|
|
127
|
+
if val_name == "Optional":
|
|
128
|
+
inner, _ = cls._parse_py_type(node.slice)
|
|
129
|
+
return inner, True
|
|
130
|
+
elif val_name in ("List", "list"):
|
|
131
|
+
inner, _ = cls._parse_py_type(node.slice)
|
|
132
|
+
return f"List[{inner}]", False
|
|
133
|
+
elif val_name in ("Dict", "dict"):
|
|
134
|
+
if isinstance(node.slice, ast.Tuple) and len(node.slice.elts) == 2:
|
|
135
|
+
k, _ = cls._parse_py_type(node.slice.elts[0])
|
|
136
|
+
v, _ = cls._parse_py_type(node.slice.elts[1])
|
|
137
|
+
return f"Dict[{k}, {v}]", False
|
|
138
|
+
return "Dict[str, Any]", False
|
|
139
|
+
elif val_name == "Union":
|
|
140
|
+
# Check if None is in union
|
|
141
|
+
elts = node.slice.elts if isinstance(node.slice, ast.Tuple) else [node.slice]
|
|
142
|
+
non_none = [e for e in elts if not (isinstance(e, ast.Constant) and e.value is None) and getattr(e, "id", "") != "None"]
|
|
143
|
+
if len(non_none) == 1:
|
|
144
|
+
inner, _ = cls._parse_py_type(non_none[0])
|
|
145
|
+
return inner, True
|
|
146
|
+
return "Any", True
|
|
147
|
+
return "Any", False
|
|
148
|
+
elif isinstance(node, ast.Name):
|
|
149
|
+
return node.id, False
|
|
150
|
+
elif isinstance(node, ast.Constant):
|
|
151
|
+
return str(node.value), False
|
|
152
|
+
|
|
153
|
+
return "Any", False
|
|
154
|
+
|
|
155
|
+
@classmethod
|
|
156
|
+
def _to_ts_type(cls, py_type: str, is_optional: bool) -> str:
|
|
157
|
+
if py_type.startswith("List["):
|
|
158
|
+
inner = py_type[5:-1]
|
|
159
|
+
ts_inner = cls._to_ts_type(inner, False)
|
|
160
|
+
res = f"{ts_inner}[]"
|
|
161
|
+
elif py_type.startswith("Dict["):
|
|
162
|
+
parts = py_type[5:-1].split(",", 1)
|
|
163
|
+
k = cls._to_ts_type(parts[0].strip(), False) if len(parts) > 0 else "string"
|
|
164
|
+
v = cls._to_ts_type(parts[1].strip(), False) if len(parts) > 1 else "any"
|
|
165
|
+
res = f"Record<{k}, {v}>"
|
|
166
|
+
else:
|
|
167
|
+
res = cls.TYPE_MAP_TS.get(py_type, py_type)
|
|
168
|
+
|
|
169
|
+
return f"{res} | null" if is_optional else res
|
|
170
|
+
|
|
171
|
+
@classmethod
|
|
172
|
+
def _to_rust_type(cls, py_type: str, is_optional: bool) -> str:
|
|
173
|
+
if py_type.startswith("List["):
|
|
174
|
+
inner = py_type[5:-1]
|
|
175
|
+
rust_inner = cls._to_rust_type(inner, False)
|
|
176
|
+
res = f"Vec<{rust_inner}>"
|
|
177
|
+
elif py_type.startswith("Dict["):
|
|
178
|
+
parts = py_type[5:-1].split(",", 1)
|
|
179
|
+
k = cls._to_rust_type(parts[0].strip(), False) if len(parts) > 0 else "String"
|
|
180
|
+
v = cls._to_rust_type(parts[1].strip(), False) if len(parts) > 1 else "serde_json::Value"
|
|
181
|
+
res = f"std::collections::HashMap<{k}, {v}>"
|
|
182
|
+
else:
|
|
183
|
+
res = cls.TYPE_MAP_RUST.get(py_type, py_type)
|
|
184
|
+
|
|
185
|
+
return f"Option<{res}>" if is_optional else res
|
|
186
|
+
|
|
187
|
+
@classmethod
|
|
188
|
+
def _to_go_type(cls, py_type: str, is_optional: bool) -> str:
|
|
189
|
+
if py_type.startswith("List["):
|
|
190
|
+
inner = py_type[5:-1]
|
|
191
|
+
go_inner = cls._to_go_type(inner, False)
|
|
192
|
+
res = f"[]{go_inner}"
|
|
193
|
+
elif py_type.startswith("Dict["):
|
|
194
|
+
parts = py_type[5:-1].split(",", 1)
|
|
195
|
+
k = cls._to_go_type(parts[0].strip(), False) if len(parts) > 0 else "string"
|
|
196
|
+
v = cls._to_go_type(parts[1].strip(), False) if len(parts) > 1 else "interface{}"
|
|
197
|
+
res = f"map[{k}]{v}"
|
|
198
|
+
else:
|
|
199
|
+
res = cls.TYPE_MAP_GO.get(py_type, py_type)
|
|
200
|
+
|
|
201
|
+
return f"*{res}" if is_optional else res
|
|
202
|
+
|
|
203
|
+
@classmethod
|
|
204
|
+
def _to_kotlin_type(cls, py_type: str, is_optional: bool) -> str:
|
|
205
|
+
if py_type.startswith("List["):
|
|
206
|
+
inner = py_type[5:-1]
|
|
207
|
+
kt_inner = cls._to_kotlin_type(inner, False)
|
|
208
|
+
res = f"List<{kt_inner}>"
|
|
209
|
+
elif py_type.startswith("Dict["):
|
|
210
|
+
parts = py_type[5:-1].split(",", 1)
|
|
211
|
+
k = cls._to_kotlin_type(parts[0].strip(), False) if len(parts) > 0 else "String"
|
|
212
|
+
v = cls._to_kotlin_type(parts[1].strip(), False) if len(parts) > 1 else "Any"
|
|
213
|
+
res = f"Map<{k}, {v}>"
|
|
214
|
+
else:
|
|
215
|
+
res = cls.TYPE_MAP_KOTLIN.get(py_type, py_type)
|
|
216
|
+
|
|
217
|
+
return f"{res}?" if is_optional else res
|
|
218
|
+
|
|
219
|
+
@classmethod
|
|
220
|
+
def _to_swift_type(cls, py_type: str, is_optional: bool) -> str:
|
|
221
|
+
if py_type.startswith("List["):
|
|
222
|
+
inner = py_type[5:-1]
|
|
223
|
+
swift_inner = cls._to_swift_type(inner, False)
|
|
224
|
+
res = f"[{swift_inner}]"
|
|
225
|
+
elif py_type.startswith("Dict["):
|
|
226
|
+
parts = py_type[5:-1].split(",", 1)
|
|
227
|
+
k = cls._to_swift_type(parts[0].strip(), False) if len(parts) > 0 else "String"
|
|
228
|
+
v = cls._to_swift_type(parts[1].strip(), False) if len(parts) > 1 else "Any"
|
|
229
|
+
res = f"[{k}: {v}]"
|
|
230
|
+
else:
|
|
231
|
+
res = cls.TYPE_MAP_SWIFT.get(py_type, py_type)
|
|
232
|
+
|
|
233
|
+
return f"{res}?" if is_optional else res
|
|
234
|
+
|
|
235
|
+
@classmethod
|
|
236
|
+
def parse_python_models(cls, py_code: str) -> List[TranspiledModel]:
|
|
237
|
+
"""Parses Python classes and generates TypeScript, Rust, and Go interfaces."""
|
|
238
|
+
try:
|
|
239
|
+
tree = ast.parse(py_code)
|
|
240
|
+
except Exception:
|
|
241
|
+
return []
|
|
242
|
+
|
|
243
|
+
models: List[TranspiledModel] = []
|
|
244
|
+
|
|
245
|
+
for node in tree.body:
|
|
246
|
+
if isinstance(node, ast.ClassDef):
|
|
247
|
+
fields: List[ModelField] = []
|
|
248
|
+
doc = ast.get_docstring(node) or ""
|
|
249
|
+
|
|
250
|
+
for item in node.body:
|
|
251
|
+
if isinstance(item, ast.AnnAssign) and isinstance(item.target, ast.Name):
|
|
252
|
+
fname = item.target.id
|
|
253
|
+
ptype, opt = cls._parse_py_type(item.annotation)
|
|
254
|
+
fields.append(ModelField(name=fname, py_type=ptype, is_optional=opt))
|
|
255
|
+
|
|
256
|
+
if not fields:
|
|
257
|
+
continue
|
|
258
|
+
|
|
259
|
+
# Generate TS
|
|
260
|
+
ts_lines = [f"export interface {node.name} {{"]
|
|
261
|
+
for f in fields:
|
|
262
|
+
opt_mark = "?" if f.is_optional else ""
|
|
263
|
+
ts_t = cls._to_ts_type(f.py_type, f.is_optional)
|
|
264
|
+
ts_lines.append(f" {f.name}{opt_mark}: {ts_t};")
|
|
265
|
+
ts_lines.append("}")
|
|
266
|
+
ts_str = "\n".join(ts_lines)
|
|
267
|
+
|
|
268
|
+
# Generate Rust
|
|
269
|
+
rust_lines = [
|
|
270
|
+
"#[derive(Debug, Clone, Serialize, Deserialize)]",
|
|
271
|
+
f"pub struct {node.name} {{"
|
|
272
|
+
]
|
|
273
|
+
for f in fields:
|
|
274
|
+
r_type = cls._to_rust_type(f.py_type, f.is_optional)
|
|
275
|
+
rust_lines.append(f" pub {f.name}: {r_type},")
|
|
276
|
+
rust_lines.append("}")
|
|
277
|
+
rust_str = "\n".join(rust_lines)
|
|
278
|
+
|
|
279
|
+
# Generate Go
|
|
280
|
+
go_lines = [f"type {node.name} struct {{"]
|
|
281
|
+
for f in fields:
|
|
282
|
+
g_type = cls._to_go_type(f.py_type, f.is_optional)
|
|
283
|
+
pascal_name = "".join(p.capitalize() for p in f.name.split("_"))
|
|
284
|
+
go_lines.append(f'\t{pascal_name} {g_type} `json:"{f.name}"`')
|
|
285
|
+
go_lines.append("}")
|
|
286
|
+
go_str = "\n".join(go_lines)
|
|
287
|
+
|
|
288
|
+
# Generate Kotlin
|
|
289
|
+
kt_lines = [f"data class {node.name}("]
|
|
290
|
+
for idx, f in enumerate(fields):
|
|
291
|
+
kt_type = cls._to_kotlin_type(f.py_type, f.is_optional)
|
|
292
|
+
parts = f.name.split("_")
|
|
293
|
+
camel_name = parts[0] + "".join(p.capitalize() for p in parts[1:]) if len(parts) > 1 else f.name
|
|
294
|
+
default_suffix = " = null" if f.is_optional else ""
|
|
295
|
+
comma = "," if idx < len(fields) - 1 else ""
|
|
296
|
+
kt_lines.append(f" val {camel_name}: {kt_type}{default_suffix}{comma}")
|
|
297
|
+
kt_lines.append(")")
|
|
298
|
+
kt_str = "\n".join(kt_lines)
|
|
299
|
+
|
|
300
|
+
# Generate Swift
|
|
301
|
+
swift_lines = [
|
|
302
|
+
f"public struct {node.name}: Codable, Equatable {{",
|
|
303
|
+
]
|
|
304
|
+
for f in fields:
|
|
305
|
+
swift_type = cls._to_swift_type(f.py_type, f.is_optional)
|
|
306
|
+
parts = f.name.split("_")
|
|
307
|
+
camel_name = parts[0] + "".join(p.capitalize() for p in parts[1:]) if len(parts) > 1 else f.name
|
|
308
|
+
swift_lines.append(f" public let {camel_name}: {swift_type}")
|
|
309
|
+
swift_lines.append("}")
|
|
310
|
+
swift_str = "\n".join(swift_lines)
|
|
311
|
+
|
|
312
|
+
models.append(TranspiledModel(
|
|
313
|
+
class_name=node.name,
|
|
314
|
+
fields=fields,
|
|
315
|
+
docstring=doc,
|
|
316
|
+
typescript=ts_str,
|
|
317
|
+
rust=rust_str,
|
|
318
|
+
golang=go_str,
|
|
319
|
+
kotlin=kt_str,
|
|
320
|
+
swift=swift_str
|
|
321
|
+
))
|
|
322
|
+
|
|
323
|
+
return models
|
|
324
|
+
|
|
325
|
+
@classmethod
|
|
326
|
+
def transpile_file(cls, py_file_path: str, target_lang: str = "ts") -> str:
|
|
327
|
+
"""Reads Python file and returns transpiled definitions in requested language."""
|
|
328
|
+
with open(py_file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
329
|
+
code = f.read()
|
|
330
|
+
|
|
331
|
+
models = cls.parse_python_models(code)
|
|
332
|
+
if not models:
|
|
333
|
+
return f"// No typed models or dataclasses detected in {os.path.basename(py_file_path)}"
|
|
334
|
+
|
|
335
|
+
target = target_lang.lower().strip()
|
|
336
|
+
if target in ("ts", "typescript"):
|
|
337
|
+
return "\n\n".join(m.typescript for m in models)
|
|
338
|
+
elif target in ("rust", "rs"):
|
|
339
|
+
return "\n\n".join(m.rust for m in models)
|
|
340
|
+
elif target in ("go", "golang"):
|
|
341
|
+
return "\n\n".join(m.golang for m in models)
|
|
342
|
+
elif target in ("kt", "kotlin"):
|
|
343
|
+
return "\n\n".join(m.kotlin for m in models)
|
|
344
|
+
elif target in ("swift", "ios"):
|
|
345
|
+
return "\n\n".join(m.swift for m in models)
|
|
346
|
+
else:
|
|
347
|
+
return "\n\n".join(
|
|
348
|
+
f"// --- {m.class_name} ---\n// TypeScript:\n{m.typescript}\n\n// Rust:\n{m.rust}\n\n// Go:\n{m.golang}\n\n// Kotlin:\n{m.kotlin}\n\n// Swift:\n{m.swift}"
|
|
349
|
+
for m in models
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
@classmethod
|
|
353
|
+
def render_cli(cls, py_file: str, lang: str):
|
|
354
|
+
print(f"\n🌉 \033[1mT-ZERO POLYGLOT TYPE & SCHEMA TRANSPILER\033[0m")
|
|
355
|
+
print("=" * 70)
|
|
356
|
+
print(f"📄 Source Python Model: {py_file}")
|
|
357
|
+
print(f"🎯 Target Language: \033[36m{lang.upper()}\033[0m")
|
|
358
|
+
print("=" * 70)
|
|
359
|
+
out = cls.transpile_file(py_file, target_lang=lang)
|
|
360
|
+
print(out)
|
|
361
|
+
print("=" * 70)
|
|
362
|
+
|
package/src/tzero_ci.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Siber Akademi — T-Zero CI/CD Pipeline & Security Gate Generator.
|
|
4
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
+
License: MIT
|
|
6
|
+
|
|
7
|
+
Installs zero-dependency, automated CI/CD security and verification pipelines:
|
|
8
|
+
- GitHub Actions: .github/workflows/tzero_guard.yml
|
|
9
|
+
- GitLab CI: .gitlab-ci.yml
|
|
10
|
+
- Pre-commit: .pre-commit-config.yaml
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
if sys.platform == "win32":
|
|
15
|
+
try:
|
|
16
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
17
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
18
|
+
except Exception:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
from typing import Tuple, Dict, Any
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
GITHUB_WORKFLOW_TEMPLATE = """name: T-Zero Autonomous Quality & Zero-Leak Gate
|
|
26
|
+
|
|
27
|
+
on:
|
|
28
|
+
push:
|
|
29
|
+
branches: [ main, master ]
|
|
30
|
+
pull_request:
|
|
31
|
+
branches: [ main, master ]
|
|
32
|
+
|
|
33
|
+
jobs:
|
|
34
|
+
tzero-verify:
|
|
35
|
+
name: T-Zero Autonomous Verification Gate
|
|
36
|
+
runs-on: ${{ matrix.os }}
|
|
37
|
+
strategy:
|
|
38
|
+
fail-fast: false
|
|
39
|
+
matrix:
|
|
40
|
+
os: [ubuntu-24.04, windows-latest]
|
|
41
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
42
|
+
|
|
43
|
+
steps:
|
|
44
|
+
- name: Checkout Codebase
|
|
45
|
+
uses: actions/checkout@v5
|
|
46
|
+
with:
|
|
47
|
+
fetch-depth: 0
|
|
48
|
+
|
|
49
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
50
|
+
uses: actions/setup-python@v6
|
|
51
|
+
with:
|
|
52
|
+
python-version: ${{ matrix.python-version }}
|
|
53
|
+
cache: 'pip'
|
|
54
|
+
|
|
55
|
+
- name: Install Dependencies
|
|
56
|
+
run: |
|
|
57
|
+
python -m pip install --upgrade pip
|
|
58
|
+
pip install flake8 fastmcp keyring requests
|
|
59
|
+
|
|
60
|
+
- name: Zero-Leak Security & Code Quality Audit
|
|
61
|
+
run: |
|
|
62
|
+
python tzero_v3.py --audit . --format text
|
|
63
|
+
|
|
64
|
+
- name: Enforce T-4 Architectural Boundary Rules
|
|
65
|
+
run: |
|
|
66
|
+
python tzero_v3.py --enforce-boundaries tzero.rules.json
|
|
67
|
+
|
|
68
|
+
- name: Run Comprehensive Test Suite
|
|
69
|
+
run: |
|
|
70
|
+
python -m unittest discover -s tests -p "test_*.py" -v
|
|
71
|
+
|
|
72
|
+
- name: PR Incremental Token Savings Telemetry
|
|
73
|
+
if: github.event_name == 'pull_request'
|
|
74
|
+
run: |
|
|
75
|
+
python tzero_v3.py --diff HEAD~1
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
GITLAB_CI_TEMPLATE = """stages:
|
|
79
|
+
- audit
|
|
80
|
+
- test
|
|
81
|
+
|
|
82
|
+
variables:
|
|
83
|
+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
|
84
|
+
|
|
85
|
+
cache:
|
|
86
|
+
paths:
|
|
87
|
+
- .cache/pip
|
|
88
|
+
|
|
89
|
+
tzero_audit:
|
|
90
|
+
stage: audit
|
|
91
|
+
image: python:3.11-slim
|
|
92
|
+
script:
|
|
93
|
+
- pip install --upgrade pip
|
|
94
|
+
- pip install fastmcp keyring requests
|
|
95
|
+
- python tzero_v3.py --audit . --format text
|
|
96
|
+
- python tzero_v3.py --enforce-boundaries tzero.rules.json
|
|
97
|
+
|
|
98
|
+
tzero_tests:
|
|
99
|
+
stage: test
|
|
100
|
+
image: python:3.11-slim
|
|
101
|
+
script:
|
|
102
|
+
- pip install --upgrade pip
|
|
103
|
+
- pip install fastmcp keyring requests
|
|
104
|
+
- python -m unittest discover -s tests -p "test_*.py" -v
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
PRE_COMMIT_CONFIG_TEMPLATE = """repos:
|
|
108
|
+
- repo: local
|
|
109
|
+
hooks:
|
|
110
|
+
- id: tzero-zero-leak
|
|
111
|
+
name: T-Zero 100% Zero-Leak Security Scanner
|
|
112
|
+
entry: python tzero_v3.py --audit .
|
|
113
|
+
language: system
|
|
114
|
+
pass_filenames: false
|
|
115
|
+
always_run: true
|
|
116
|
+
|
|
117
|
+
- id: tzero-architectural-boundaries
|
|
118
|
+
name: T-Zero Architectural Boundaries Enforcer
|
|
119
|
+
entry: python tzero_v3.py --enforce-boundaries
|
|
120
|
+
language: system
|
|
121
|
+
pass_filenames: false
|
|
122
|
+
always_run: true
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class CIPipelineGenerator:
|
|
127
|
+
"""Turnkey generator for automated enterprise CI/CD verification workflows."""
|
|
128
|
+
|
|
129
|
+
@classmethod
|
|
130
|
+
def install_github_workflow(cls, repo_dir: str = ".") -> Tuple[bool, str]:
|
|
131
|
+
"""Installs GitHub Actions workflow into .github/workflows/tzero_guard.yml."""
|
|
132
|
+
wf_dir = os.path.join(repo_dir, ".github", "workflows")
|
|
133
|
+
os.makedirs(wf_dir, exist_ok=True)
|
|
134
|
+
wf_path = os.path.join(wf_dir, "tzero_guard.yml")
|
|
135
|
+
with open(wf_path, "w", encoding="utf-8") as f:
|
|
136
|
+
f.write(GITHUB_WORKFLOW_TEMPLATE.strip() + "\n")
|
|
137
|
+
return True, wf_path
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def install_gitlab_ci(cls, repo_dir: str = ".") -> Tuple[bool, str]:
|
|
141
|
+
"""Installs GitLab CI configuration into .gitlab-ci.yml."""
|
|
142
|
+
ci_path = os.path.join(repo_dir, ".gitlab-ci.yml")
|
|
143
|
+
with open(ci_path, "w", encoding="utf-8") as f:
|
|
144
|
+
f.write(GITLAB_CI_TEMPLATE.strip() + "\n")
|
|
145
|
+
return True, ci_path
|
|
146
|
+
|
|
147
|
+
@classmethod
|
|
148
|
+
def install_pre_commit(cls, repo_dir: str = ".") -> Tuple[bool, str]:
|
|
149
|
+
"""Installs pre-commit configuration into .pre-commit-config.yaml."""
|
|
150
|
+
pc_path = os.path.join(repo_dir, ".pre-commit-config.yaml")
|
|
151
|
+
with open(pc_path, "w", encoding="utf-8") as f:
|
|
152
|
+
f.write(PRE_COMMIT_CONFIG_TEMPLATE.strip() + "\n")
|
|
153
|
+
return True, pc_path
|