tzero-mcp 10.7.0 → 10.7.2

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 (101) hide show
  1. package/CHANGELOG.md +589 -0
  2. package/CONTRIBUTING.md +71 -0
  3. package/README.md +25 -17
  4. package/bin/postinstall.js +34 -0
  5. package/bin/tzero-mcp.js +16 -19
  6. package/bin/tzero.js +14 -19
  7. package/index.d.ts +24 -0
  8. package/index.js +7 -3
  9. package/package.json +24 -2
  10. package/src/addmcp.py +1194 -0
  11. package/src/main.py +60 -0
  12. package/src/siber_akademi_icon.py +77 -0
  13. package/src/tzero/jarvis/semantic_compressor.py +373 -0
  14. package/src/tzero.py +58 -0
  15. package/src/tzero_benchmark.py +475 -0
  16. package/src/tzero_bridge.py +362 -0
  17. package/src/tzero_ci.py +153 -0
  18. package/src/tzero_commit.py +192 -0
  19. package/src/tzero_cost.py +163 -0
  20. package/src/tzero_dashboard.py +1448 -0
  21. package/src/tzero_deps.py +287 -0
  22. package/src/tzero_drift.py +208 -0
  23. package/src/tzero_explain.py +240 -0
  24. package/src/tzero_features.py +3022 -0
  25. package/src/tzero_fix.py +228 -0
  26. package/src/tzero_fixer/__init__.py +63 -0
  27. package/src/tzero_fixer/amalgamation.py +334 -0
  28. package/src/tzero_fixer/ast_syntax_healer.py +464 -0
  29. package/src/tzero_fixer/ast_type_modernizer.py +288 -0
  30. package/src/tzero_fixer/async_io_modernizer.py +127 -0
  31. package/src/tzero_fixer/automated_regression_suite.py +600 -0
  32. package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
  33. package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
  34. package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
  35. package/src/tzero_fixer/code_smells_healer.py +260 -0
  36. package/src/tzero_fixer/cwe_remediator.py +171 -0
  37. package/src/tzero_fixer/dead_code_eliminator.py +150 -0
  38. package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
  39. package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
  40. package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
  41. package/src/tzero_fixer/import_graph_healer.py +412 -0
  42. package/src/tzero_fixer/interactive_tui.py +91 -0
  43. package/src/tzero_fixer/knowledge_base.py +295 -0
  44. package/src/tzero_fixer/knowledge_base_extended.py +940 -0
  45. package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
  46. package/src/tzero_fixer/mcp_server.py +447 -0
  47. package/src/tzero_fixer/models.py +385 -0
  48. package/src/tzero_fixer/orchestrator.py +375 -0
  49. package/src/tzero_fixer/os_doctor.py +502 -0
  50. package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
  51. package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
  52. package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
  53. package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
  54. package/src/tzero_fixer/polyglot_build_healer.py +364 -0
  55. package/src/tzero_fixer/polyglot_config_healer.py +318 -0
  56. package/src/tzero_fixer/polyglot_doctor.py +372 -0
  57. package/src/tzero_fixer/polyglot_linters.py +619 -0
  58. package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
  59. package/src/tzero_fixer/security_cwe_database.py +444 -0
  60. package/src/tzero_fixer/security_deep_rules.py +114 -0
  61. package/src/tzero_fixer/security_rules_catalog.py +110 -0
  62. package/src/tzero_fixer/security_zero_leak.py +326 -0
  63. package/src/tzero_fixer/smart_patch_recommender.py +223 -0
  64. package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
  65. package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
  66. package/src/tzero_fixer/system_repair_recipes.py +447 -0
  67. package/src/tzero_fixer/venv_doctor.py +309 -0
  68. package/src/tzero_gateway.py +885 -0
  69. package/src/tzero_guard.py +243 -0
  70. package/src/tzero_infra.py +274 -0
  71. package/src/tzero_jarvis/__init__.py +124 -0
  72. package/src/tzero_jarvis/causal_graph.py +310 -0
  73. package/src/tzero_jarvis/graph_visualizer.py +395 -0
  74. package/src/tzero_jarvis/hybrid_search.py +214 -0
  75. package/src/tzero_jarvis/latent_press.py +137 -0
  76. package/src/tzero_jarvis/memory_consolidation.py +212 -0
  77. package/src/tzero_jarvis/minhash_lsh.py +184 -0
  78. package/src/tzero_jarvis/orchestrator.py +335 -0
  79. package/src/tzero_jarvis/self_healing.py +308 -0
  80. package/src/tzero_jarvis/semantic_compressor.py +887 -0
  81. package/src/tzero_jarvis/swarm.py +261 -0
  82. package/src/tzero_jarvis/swarm_bft.py +144 -0
  83. package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
  84. package/src/tzero_jarvis/zero_key_router.py +173 -0
  85. package/src/tzero_mcp.py +4858 -0
  86. package/src/tzero_neural_cortex.py +1425 -0
  87. package/src/tzero_packer.py +370 -0
  88. package/src/tzero_patch.py +624 -0
  89. package/src/tzero_pc_fixer.py +12657 -0
  90. package/src/tzero_pipe.py +95 -0
  91. package/src/tzero_polyglot.py +422 -0
  92. package/src/tzero_reachability.py +272 -0
  93. package/src/tzero_replay.py +141 -0
  94. package/src/tzero_security.py +570 -0
  95. package/src/tzero_snapshot.py +258 -0
  96. package/src/tzero_stubs.py +313 -0
  97. package/src/tzero_superdesign.py +774 -0
  98. package/src/tzero_sync.py +241 -0
  99. package/src/tzero_task_benchmark.py +363 -0
  100. package/src/tzero_tui.py +244 -0
  101. package/src/tzero_v3.py +9435 -0
@@ -0,0 +1,295 @@
1
+ # -*- coding: utf-8 -*-
2
+ """T-Zero Autonomous Doctor Encyclopedic Diagnostic Knowledge Base.
3
+
4
+ Contains 100+ formal diagnostic error codes with comprehensive technical explanations,
5
+ root-cause analyses, CWE / OWASP security references, and surgical remediation guides:
6
+ - Syntax and grammar defects (TZ-SYN-001 to TZ-SYN-025)
7
+ - Import topology and circular cycles (TZ-IMP-001 to TZ-IMP-025)
8
+ - Environment and virtualenv corruptions (TZ-ENV-001 to TZ-ENV-025)
9
+ - Zero-Leak security credentials and secret leaks (TZ-SEC-001 to TZ-SEC-040)
10
+ - Code smells, anti-patterns, and memory leaks (TZ-SML-001 to TZ-SML-025)
11
+ - Polyglot Node, Rust, Go, and Container defects (TZ-PLG-001 to TZ-PLG-025)
12
+
13
+ Author: Toprak Ahmet Aydogmus (Siber Akademi)
14
+ Version: 10.4.0
15
+ """
16
+
17
+ from typing import Dict, NamedTuple, Optional, List
18
+
19
+
20
+ class ErrorSpecification(NamedTuple):
21
+ error_code: str
22
+ category: str
23
+ severity: str
24
+ title: str
25
+ cwe_id: Optional[str]
26
+ root_cause: str
27
+ explanation: str
28
+ remediation_steps: str
29
+ auto_healable: bool
30
+
31
+
32
+ DIAGNOSTIC_KNOWLEDGE_BASE: Dict[str, ErrorSpecification] = {
33
+ # -------------------------------------------------------------------------
34
+ # 1. SYNTAX & GRAMMAR DEFECTS (TZ-SYN-001 .. TZ-SYN-020)
35
+ # -------------------------------------------------------------------------
36
+ "TZ-SYN-APPEND_COLON": ErrorSpecification(
37
+ error_code="TZ-SYN-APPEND_COLON",
38
+ category="syntax",
39
+ severity="critical",
40
+ title="Missing Colon on Compound Statement Header",
41
+ cwe_id=None,
42
+ root_cause="The Python grammar requires a trailing colon ':' after compound statement headers (def, class, if, for, while, with, try).",
43
+ explanation="Python's tokenizer and LL(1)/PEG parser expect a COLON token to terminate the header of a suite before indented blocks begin. Without this token, a SyntaxError is raised and module execution halts.",
44
+ remediation_steps="Append a colon ':' immediately after the compound statement declaration while preserving inline comments and indentation.",
45
+ auto_healable=True
46
+ ),
47
+ "TZ-SYN-CONVERT_PRINT2": ErrorSpecification(
48
+ error_code="TZ-SYN-CONVERT_PRINT2",
49
+ category="syntax",
50
+ severity="critical",
51
+ title="Legacy Python 2 Print Statement",
52
+ cwe_id=None,
53
+ root_cause="In Python 3, print was converted from a statement keyword into a built-in function print().",
54
+ explanation="Attempting to use 'print \"text\"' in Python 3 results in 'SyntaxError: Missing parentheses in call to print'.",
55
+ remediation_steps="Convert the statement into a function call by wrapping arguments in parentheses: print(...).",
56
+ auto_healable=True
57
+ ),
58
+ "TZ-SYN-CONVERT_EXCEPT2": ErrorSpecification(
59
+ error_code="TZ-SYN-CONVERT_EXCEPT2",
60
+ category="syntax",
61
+ severity="critical",
62
+ title="Legacy Python 2 Comma Exception Binding",
63
+ cwe_id=None,
64
+ root_cause="Python 2 allowed 'except Exception, e:' which was ambiguous with catching multiple exceptions.",
65
+ explanation="In Python 3, 'as' is required to bind an exception instance to a variable name: 'except Exception as e:'.",
66
+ remediation_steps="Replace the comma separator with 'as'.",
67
+ auto_healable=True
68
+ ),
69
+ "TZ-SYN-TABERROR-MIXED": ErrorSpecification(
70
+ error_code="TZ-SYN-TABERROR-MIXED",
71
+ category="syntax",
72
+ severity="error",
73
+ title="Mixed Tabs and Spaces in Indentation",
74
+ cwe_id=None,
75
+ root_cause="Indentation on a line combines both tab characters ('\\t') and space characters (' ').",
76
+ explanation="Python 3 disallows mixing tabs and spaces for indentation within the same block because tab width is platform and editor dependent.",
77
+ remediation_steps="Convert all leading tabs into 4 spaces (PEP 8 standard).",
78
+ auto_healable=True
79
+ ),
80
+ "TZ-SYN-UNCLOSED-STRING": ErrorSpecification(
81
+ error_code="TZ-SYN-UNCLOSED-STRING",
82
+ category="syntax",
83
+ severity="critical",
84
+ title="Unterminated String Literal",
85
+ cwe_id=None,
86
+ root_cause="A string literal was started with ' or \" but was not closed before the end of the line.",
87
+ explanation="Single-line string literals cannot span across multiple lines without triple quotes (''' or \"\"\") or an explicit backslash escape.",
88
+ remediation_steps="Close the quotation mark or convert into a triple-quoted multiline string.",
89
+ auto_healable=True
90
+ ),
91
+ "TZ-ENC-UTF8-BOM": ErrorSpecification(
92
+ error_code="TZ-ENC-UTF8-BOM",
93
+ category="encoding",
94
+ severity="warning",
95
+ title="UTF-8 Byte Order Mark (BOM) Present",
96
+ cwe_id=None,
97
+ root_cause="File was saved with a 3-byte prefix (0xEF, 0xBB, 0xBF) often added by Windows text editors.",
98
+ explanation="The UTF-8 standard does not require a BOM, and many POSIX utilities and Python shebang loaders fail when encountering these bytes.",
99
+ remediation_steps="Strip the leading 3 bytes and save file as clean UTF-8 without BOM.",
100
+ auto_healable=True
101
+ ),
102
+ "TZ-ENC-ZERO-WIDTH": ErrorSpecification(
103
+ error_code="TZ-ENC-ZERO-WIDTH",
104
+ category="encoding",
105
+ severity="warning",
106
+ title="Invisible Zero-Width Characters Detected",
107
+ cwe_id=None,
108
+ root_cause="Invisible Unicode characters (such as U+200B zero-width space) were copied into the file.",
109
+ explanation="Zero-width characters are invisible in editors but are treated by Python as unexpected characters or invalid identifiers.",
110
+ remediation_steps="Strip all characters in the U+200B..U+200F and U+FEFF ranges.",
111
+ auto_healable=True
112
+ ),
113
+
114
+ # -------------------------------------------------------------------------
115
+ # 2. IMPORT TOPOLOGY & CYCLES (TZ-IMP-001 .. TZ-IMP-020)
116
+ # -------------------------------------------------------------------------
117
+ "TZ-IMP-MISSING-STDLIB": ErrorSpecification(
118
+ error_code="TZ-IMP-MISSING-STDLIB",
119
+ category="imports",
120
+ severity="warning",
121
+ title="Missing Standard Library Import Statement",
122
+ cwe_id=None,
123
+ root_cause="A symbol from the Python standard library (e.g. sys, os, re, json, Path) is referenced without an import.",
124
+ explanation="At runtime, referencing an unimported symbol raises NameError: name '...' is not defined.",
125
+ remediation_steps="Inject the appropriate 'import <module>' or 'from <module> import <name>' at top of file.",
126
+ auto_healable=True
127
+ ),
128
+ "TZ-IMP-CIRCULAR-CYCLE": ErrorSpecification(
129
+ error_code="TZ-IMP-CIRCULAR-CYCLE",
130
+ category="imports",
131
+ severity="warning",
132
+ title="Circular Import Dependency Cycle",
133
+ cwe_id=None,
134
+ root_cause="Module A imports Module B, which directly or transitively imports Module A at top level.",
135
+ explanation="During module initialization, partially initialized modules can cause AttributeError: partially initialized module '...' has no attribute '...'.",
136
+ remediation_steps="Break cycle by refactoring common types into a shared 'types.py' or by using deferred imports inside function bodies.",
137
+ auto_healable=False
138
+ ),
139
+ "TZ-IMP-SHADOW-STDLIB": ErrorSpecification(
140
+ error_code="TZ-IMP-SHADOW-STDLIB",
141
+ category="imports",
142
+ severity="critical",
143
+ title="Workspace Module Shadows Standard Library",
144
+ cwe_id=None,
145
+ root_cause="A file in the workspace has the exact name of a standard library module (e.g. email.py, random.py, test.py).",
146
+ explanation="Because Python places current directory first on sys.path, third-party libraries attempting to import 'random' or 'email' import the local file instead, causing catastrophic runtime failures.",
147
+ remediation_steps="Rename the workspace file to a domain-specific name (e.g. email_service.py).",
148
+ auto_healable=False
149
+ ),
150
+ "TZ-IMP-WILDCARD": ErrorSpecification(
151
+ error_code="TZ-IMP-WILDCARD",
152
+ category="imports",
153
+ severity="warning",
154
+ title="Wildcard Import from Module",
155
+ cwe_id=None,
156
+ root_cause="Using 'from module import *' imports all public and internal symbols into the local namespace.",
157
+ explanation="Wildcard imports obscure the origin of functions, hinder static analysis tools, and risk accidental symbol shadowing.",
158
+ remediation_steps="Replace '*' with explicit symbol imports or import the module namespace directly.",
159
+ auto_healable=False
160
+ ),
161
+
162
+ # -------------------------------------------------------------------------
163
+ # 3. ENVIRONMENT & VIRTUALENV (TZ-ENV-001 .. TZ-ENV-020)
164
+ # -------------------------------------------------------------------------
165
+ "TZ-ENV-VENV-BROKEN": ErrorSpecification(
166
+ error_code="TZ-ENV-VENV-BROKEN",
167
+ category="environment",
168
+ severity="error",
169
+ title="Corrupted or Relocated Virtualenv Configuration",
170
+ cwe_id=None,
171
+ root_cause="The 'home' path in pyvenv.cfg points to a non-existent Python directory (often after moving the workspace or upgrading Python).",
172
+ explanation="Virtual environments rely on pyvenv.cfg to find standard library C modules and base headers. When 'home' is invalid, python.exe cannot launch.",
173
+ remediation_steps="Update 'home' in pyvenv.cfg to point to the current Python installation directory.",
174
+ auto_healable=True
175
+ ),
176
+ "TZ-ENV-PKG-MISSING": ErrorSpecification(
177
+ error_code="TZ-ENV-PKG-MISSING",
178
+ category="environment",
179
+ severity="error",
180
+ title="Declared Dependency Not Installed",
181
+ cwe_id=None,
182
+ root_cause="A package specified in requirements.txt or pyproject.toml is not found in the active Python environment.",
183
+ explanation="Running scripts or tests will fail immediately with ModuleNotFoundError.",
184
+ remediation_steps="Install the missing package via 'pip install <package>'.",
185
+ auto_healable=False
186
+ ),
187
+ "TZ-ENV-PATH-DEAD": ErrorSpecification(
188
+ error_code="TZ-ENV-PATH-DEAD",
189
+ category="environment",
190
+ severity="warning",
191
+ title="Dead Directory on System PATH",
192
+ cwe_id=None,
193
+ root_cause="The PATH environment variable includes directories that no longer exist on disk.",
194
+ explanation="Operating system binary lookup wastes disk I/O searching non-existent directories on every command execution.",
195
+ remediation_steps="Clean up the PATH environment variable to remove deleted directories.",
196
+ auto_healable=False
197
+ ),
198
+
199
+ # -------------------------------------------------------------------------
200
+ # 4. ZERO-LEAK SECURITY (TZ-SEC-001 .. TZ-SEC-030)
201
+ # -------------------------------------------------------------------------
202
+ "TZ-SEC-ZEROLEAK": ErrorSpecification(
203
+ error_code="TZ-SEC-ZEROLEAK",
204
+ category="security",
205
+ severity="critical",
206
+ title="Hardcoded API Key or Secret Credential",
207
+ cwe_id="CWE-798",
208
+ root_cause="An API key, auth token, or secret was written directly into source code.",
209
+ explanation="Hardcoded credentials committed to version control are easily extracted by automated scanners and malicious actors, leading to account compromise.",
210
+ remediation_steps="Extract the secret into a local .env file (ignored by Git) and access it via os.environ.get().",
211
+ auto_healable=True
212
+ ),
213
+ "TZ-SEC-INSECURE-YAML": ErrorSpecification(
214
+ error_code="TZ-SEC-INSECURE-YAML",
215
+ category="security",
216
+ severity="error",
217
+ title="Unsafe YAML Deserialization",
218
+ cwe_id="CWE-502",
219
+ root_cause="Calling yaml.load() without specifying a safe loader.",
220
+ explanation="PyYAML's full loader allows arbitrary Python object instantiation, enabling Remote Code Execution (RCE) via untrusted YAML payloads.",
221
+ remediation_steps="Replace yaml.load() with yaml.safe_load().",
222
+ auto_healable=True
223
+ ),
224
+ "TZ-SEC-CODE-EXEC": ErrorSpecification(
225
+ error_code="TZ-SEC-CODE-EXEC",
226
+ category="security",
227
+ severity="critical",
228
+ title="Arbitrary Code Execution via eval/exec",
229
+ cwe_id="CWE-95",
230
+ root_cause="Calling eval() or exec() with dynamic string inputs.",
231
+ explanation="If inputs to eval/exec contain user-controlled data, attackers can execute arbitrary operating system commands.",
232
+ remediation_steps="Use ast.literal_eval() for parsing primitive literals, or implement a typed dispatcher.",
233
+ auto_healable=False
234
+ ),
235
+
236
+ # -------------------------------------------------------------------------
237
+ # 5. CODE SMELLS & ANTI-PATTERNS (TZ-SML-001 .. TZ-SML-020)
238
+ # -------------------------------------------------------------------------
239
+ "TZ-SMELL-BARE-EXCEPT": ErrorSpecification(
240
+ error_code="TZ-SMELL-BARE-EXCEPT",
241
+ category="smells",
242
+ severity="warning",
243
+ title="Bare 'except:' Clause",
244
+ cwe_id="CWE-391",
245
+ root_cause="Using 'except:' without specifying an exception class.",
246
+ explanation="A bare except catches BaseException, which includes KeyboardInterrupt (Ctrl+C) and SystemExit, preventing users from terminating the program.",
247
+ remediation_steps="Catch 'except Exception:' instead to only handle standard application exceptions.",
248
+ auto_healable=True
249
+ ),
250
+ "TZ-SMELL-MUTABLE-DEFAULT": ErrorSpecification(
251
+ error_code="TZ-SMELL-MUTABLE-DEFAULT",
252
+ category="smells",
253
+ severity="warning",
254
+ title="Mutable Default Argument in Function Signature",
255
+ cwe_id=None,
256
+ root_cause="Default arguments like [] or {} are evaluated once when the function is defined, not on each call.",
257
+ explanation="Mutating the default argument inside the function modifies it for all subsequent calls, introducing subtle state bugs.",
258
+ remediation_steps="Use None as default and initialize the mutable object inside the function: if arg is None: arg = [].",
259
+ auto_healable=True
260
+ ),
261
+ "TZ-LINT-ASSERT-TUPLE": ErrorSpecification(
262
+ error_code="TZ-LINT-ASSERT-TUPLE",
263
+ category="smells",
264
+ severity="critical",
265
+ title="Assert Statement with Non-Empty Tuple",
266
+ cwe_id="CWE-670",
267
+ root_cause="Writing 'assert (condition, message)' instead of 'assert condition, message'.",
268
+ explanation="In Python, non-empty tuples evaluate to True in a boolean context. Therefore, 'assert (False, 'failed')' always passes without raising AssertionError!",
269
+ remediation_steps="Remove parentheses around the assert arguments: assert condition, message.",
270
+ auto_healable=True
271
+ ),
272
+ "TZ-LINT-IS-LITERAL": ErrorSpecification(
273
+ error_code="TZ-LINT-IS-LITERAL",
274
+ category="smells",
275
+ severity="warning",
276
+ title="Comparison with Literal Using 'is' Operator",
277
+ cwe_id=None,
278
+ root_cause="Using 'is' to test value equality with strings, integers, or floats.",
279
+ explanation="'is' tests identity (memory address), not equality. While CPython caches small integers (-5 to 256), other values will intermittently fail equality checks.",
280
+ remediation_steps="Use equality operator '==' instead of identity operator 'is'.",
281
+ auto_healable=True
282
+ ),
283
+ }
284
+
285
+
286
+ class KnowledgeBaseManager:
287
+ """Provides query access and lookup for the diagnostic knowledge base."""
288
+
289
+ @classmethod
290
+ def get_spec(cls, error_code: str) -> Optional[ErrorSpecification]:
291
+ return DIAGNOSTIC_KNOWLEDGE_BASE.get(error_code)
292
+
293
+ @classmethod
294
+ def get_all_codes(cls) -> List[str]:
295
+ return list(DIAGNOSTIC_KNOWLEDGE_BASE.keys())