tzero-mcp 10.7.3 → 11.0.0

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 (127) hide show
  1. package/CHANGELOG.md +44 -577
  2. package/CONTRIBUTING.md +71 -71
  3. package/README.md +64 -64
  4. package/bin/tzero-mcp.js +62 -65
  5. package/bin/tzero.js +61 -64
  6. package/index.d.ts +25 -25
  7. package/index.js +15 -15
  8. package/package.json +88 -67
  9. package/src/addmcp.py +14 -11
  10. package/src/app.py +1810 -0
  11. package/src/main.py +1 -1
  12. package/src/pc_fixer_mcp.py +25 -0
  13. package/src/tzero/__init__.py +54 -0
  14. package/src/tzero/__main__.py +6 -0
  15. package/src/tzero/siber_akademi.ico +0 -0
  16. package/src/tzero/tzero_arch_test.py +463 -0
  17. package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
  18. package/src/tzero/tzero_blackboard.py +257 -0
  19. package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
  20. package/src/tzero/tzero_budget.py +195 -0
  21. package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
  22. package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
  23. package/src/tzero/tzero_contracts.py +1093 -0
  24. package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
  25. package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
  26. package/src/tzero/tzero_debt.py +461 -0
  27. package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
  28. package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
  29. package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
  30. package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
  31. package/src/tzero/tzero_federation.py +299 -0
  32. package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
  33. package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
  34. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
  35. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
  36. package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
  37. package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
  38. package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
  39. package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
  40. package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
  41. package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
  42. package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
  43. package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
  44. package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
  45. package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
  46. package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
  47. package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
  48. package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
  49. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
  50. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
  51. package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
  52. package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
  53. package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
  54. package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
  55. package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
  56. package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
  57. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
  58. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
  59. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
  60. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
  61. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
  62. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
  63. package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
  64. package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
  65. package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
  66. package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
  67. package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
  68. package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
  69. package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
  70. package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
  71. package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
  72. package/src/tzero/tzero_golden.py +319 -0
  73. package/src/tzero/tzero_graph_hud.html +338 -0
  74. package/src/tzero/tzero_graph_rag.py +263 -0
  75. package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
  76. package/src/tzero/tzero_hooks.py +565 -0
  77. package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
  78. package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
  79. package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
  80. package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
  81. package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
  82. package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
  83. package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
  84. package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
  85. package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
  86. package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
  87. package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
  88. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
  89. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
  90. package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
  91. package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
  92. package/src/tzero/tzero_lsp.py +634 -0
  93. package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
  94. package/src/tzero/tzero_mutation.py +358 -0
  95. package/src/tzero/tzero_packer.py +577 -0
  96. package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
  97. package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
  98. package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
  99. package/src/tzero/tzero_polyglot.py +799 -0
  100. package/src/tzero/tzero_proxy.py +127 -0
  101. package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
  102. package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
  103. package/src/tzero/tzero_rust_bridge.py +198 -0
  104. package/src/tzero/tzero_scip.py +368 -0
  105. package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
  106. package/src/tzero/tzero_semantic_merge.py +189 -0
  107. package/src/tzero/tzero_snapshot.py +471 -0
  108. package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
  109. package/src/tzero/tzero_subagent_engine.py +459 -0
  110. package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
  111. package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
  112. package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
  113. package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
  114. package/src/tzero/tzero_turbo.py +264 -0
  115. package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
  116. package/src/tzero.py +2 -54
  117. package/test/package.test.js +55 -19
  118. package/src/tzero/jarvis/semantic_compressor.py +0 -373
  119. package/src/tzero_gateway.py +0 -885
  120. package/src/tzero_packer.py +0 -370
  121. package/src/tzero_polyglot.py +0 -422
  122. package/src/tzero_snapshot.py +0 -258
  123. /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
  124. /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
  125. /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
  126. /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
  127. /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
@@ -0,0 +1,299 @@
1
+ # -*- coding: utf-8 -*-
2
+ """T-Zero Cryptographic Multi-Repo AST Federation Sync (tzero_federation.py).
3
+
4
+ Exports signed, Zero-Leak sanitized AST interface contracts (no function bodies,
5
+ no secrets) for safe peer-repository sharing, verification, and cross-repo impact lookup.
6
+
7
+ 100% Free, Local, Offline, Zero-Leak Certified.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import hmac
14
+ import json
15
+ import os
16
+ import re
17
+ import sys
18
+ import time
19
+ from typing import Any, Dict, List, Optional
20
+
21
+ from tzero.tzero_features import should_skip_dir, should_skip_file
22
+ from tzero.tzero_polyglot import PolyglotTokenReducer, count_bpe_tokens
23
+ from tzero.tzero_security import ZeroLeakEngine
24
+
25
+
26
+ SCHEMA_VERSION = "1.0"
27
+ FEDERATION_DIR = os.path.join(".tzero", "federation")
28
+
29
+
30
+ class FederationSyncEngine:
31
+ """Exports, cryptographically verifies, and imports cross-repo AST interface contracts."""
32
+
33
+ @staticmethod
34
+ def _canonical_digest(payload: Dict[str, Any]) -> str:
35
+ body = {
36
+ "schema_version": payload.get("schema_version", SCHEMA_VERSION),
37
+ "repo_name": payload.get("repo_name", ""),
38
+ "modules": payload.get("modules", []),
39
+ }
40
+ canonical = json.dumps(body, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
41
+ return hashlib.sha256(canonical.encode("utf-8")).hexdigest()
42
+
43
+ @classmethod
44
+ def export_manifest(
45
+ cls,
46
+ workspace_dir: str = ".",
47
+ repo_name: Optional[str] = None,
48
+ out_file: Optional[str] = None,
49
+ ) -> Dict[str, Any]:
50
+ abs_ws = os.path.abspath(workspace_dir)
51
+ name = repo_name or os.path.basename(abs_ws) or "repository"
52
+ modules: List[Dict[str, Any]] = []
53
+
54
+ for root, dirs, files in os.walk(abs_ws):
55
+ dirs[:] = sorted(d for d in dirs if not should_skip_dir(os.path.join(root, d), abs_ws))
56
+ for fname in sorted(files):
57
+ fpath = os.path.join(root, fname)
58
+ if should_skip_file(fpath, abs_ws):
59
+ continue
60
+ lang = PolyglotTokenReducer.detect_language(fname)
61
+ if not lang:
62
+ continue
63
+ try:
64
+ with open(fpath, "r", encoding="utf-8", errors="replace") as f:
65
+ raw_code = f.read()
66
+ except OSError:
67
+ continue
68
+
69
+ reduced = PolyglotTokenReducer.reduce_code(raw_code, filename=fname, mode="ultra")
70
+ if ZeroLeakEngine.scan_text(reduced):
71
+ reduced = ZeroLeakEngine.sanitize_text(reduced)
72
+ rel = os.path.relpath(fpath, abs_ws).replace("\\", "/")
73
+ modules.append({
74
+ "rel_path": rel,
75
+ "lang": lang,
76
+ "skeleton_tokens": count_bpe_tokens(reduced),
77
+ "skeleton": reduced,
78
+ })
79
+
80
+ manifest: Dict[str, Any] = {
81
+ "schema_version": SCHEMA_VERSION,
82
+ "repo_name": name,
83
+ "exported_at": round(time.time(), 3),
84
+ "module_count": len(modules),
85
+ "modules": modules,
86
+ }
87
+ manifest["sha256"] = cls._canonical_digest(manifest)
88
+
89
+ if out_file:
90
+ out_abs = os.path.abspath(out_file)
91
+ os.makedirs(os.path.dirname(out_abs), exist_ok=True)
92
+ with open(out_abs, "w", encoding="utf-8") as f:
93
+ json.dump(manifest, f, indent=2)
94
+
95
+ return manifest
96
+
97
+ @classmethod
98
+ def verify_manifest(cls, manifest: Dict[str, Any]) -> bool:
99
+ expected = str(manifest.get("sha256") or "")
100
+ if len(expected) != 64:
101
+ return False
102
+ actual = cls._canonical_digest(manifest)
103
+ return hmac.compare_digest(actual, expected)
104
+
105
+ @classmethod
106
+ def import_manifest(cls, workspace_dir: str, manifest_path: str) -> Dict[str, Any]:
107
+ abs_ws = os.path.abspath(workspace_dir)
108
+ with open(manifest_path, "r", encoding="utf-8", errors="replace") as f:
109
+ manifest = json.load(f)
110
+
111
+ verified = cls.verify_manifest(manifest)
112
+ if not verified:
113
+ raise ValueError(f"Federation manifest failed SHA-256 verification: {manifest_path}")
114
+
115
+ raw_name = str(manifest.get("repo_name") or "peer")
116
+ safe_name = re.sub(r"[^A-Za-z0-9_.-]+", "_", raw_name).strip("._") or "peer"
117
+ store_dir = os.path.join(abs_ws, FEDERATION_DIR)
118
+ os.makedirs(store_dir, exist_ok=True)
119
+ dst = os.path.join(store_dir, f"{safe_name}.json")
120
+ with open(dst, "w", encoding="utf-8") as f:
121
+ json.dump(manifest, f, indent=2)
122
+
123
+ return {
124
+ "verified": True,
125
+ "repo_name": raw_name,
126
+ "module_count": manifest.get("module_count", len(manifest.get("modules", []))),
127
+ "stored_path": dst,
128
+ }
129
+
130
+ @classmethod
131
+ def list_peers(cls, workspace_dir: str = ".") -> List[Dict[str, Any]]:
132
+ store_dir = os.path.join(os.path.abspath(workspace_dir), FEDERATION_DIR)
133
+ if not os.path.isdir(store_dir):
134
+ return []
135
+ peers: List[Dict[str, Any]] = []
136
+ for fname in sorted(os.listdir(store_dir)):
137
+ if not fname.endswith(".json"):
138
+ continue
139
+ try:
140
+ with open(os.path.join(store_dir, fname), "r", encoding="utf-8", errors="replace") as f:
141
+ data = json.load(f)
142
+ peers.append({
143
+ "repo_name": data.get("repo_name", fname[:-5]),
144
+ "module_count": data.get("module_count", 0),
145
+ "verified": cls.verify_manifest(data),
146
+ "sha256": data.get("sha256", ""),
147
+ })
148
+ except Exception:
149
+ pass
150
+ return peers
151
+
152
+ @classmethod
153
+ def analyze_cross_repo_impact(
154
+ cls,
155
+ workspace_dir: str,
156
+ symbol_name: str,
157
+ scip_path: Optional[str] = None,
158
+ ) -> Dict[str, Any]:
159
+ if not symbol_name or not str(symbol_name).strip():
160
+ raise ValueError("symbol_name must be a non-empty string")
161
+
162
+ sym = str(symbol_name).strip()
163
+ pattern = re.compile(rf"\b{re.escape(sym)}\b")
164
+ abs_ws = os.path.abspath(workspace_dir)
165
+ local_hits: List[Dict[str, Any]] = []
166
+
167
+ # 1. Local workspace scan
168
+ scip_abs = os.path.abspath(scip_path) if scip_path else None
169
+ for root, dirs, files in os.walk(abs_ws):
170
+ dirs[:] = sorted(d for d in dirs if not should_skip_dir(os.path.join(root, d), abs_ws))
171
+ for fname in sorted(files):
172
+ fpath = os.path.join(root, fname)
173
+ if should_skip_file(fpath, abs_ws):
174
+ continue
175
+ if scip_abs and os.path.abspath(fpath) == scip_abs:
176
+ continue
177
+ lang = PolyglotTokenReducer.detect_language(fname)
178
+ if not lang:
179
+ continue
180
+ try:
181
+ with open(fpath, "r", encoding="utf-8", errors="replace") as f:
182
+ lines = f.readlines()
183
+ except OSError:
184
+ continue
185
+
186
+ matched_lines: List[int] = []
187
+ total_matches = 0
188
+ for idx, line in enumerate(lines, 1):
189
+ m_count = len(pattern.findall(line))
190
+ if m_count > 0:
191
+ matched_lines.append(idx)
192
+ total_matches += m_count
193
+
194
+ if total_matches > 0:
195
+ rel = os.path.relpath(fpath, abs_ws).replace("\\", "/")
196
+ local_hits.append({
197
+ "file": rel,
198
+ "matches": total_matches,
199
+ "lines": matched_lines,
200
+ })
201
+
202
+ # 2. Peer federations scan
203
+ store_dir = os.path.join(abs_ws, FEDERATION_DIR)
204
+ impacted_peers: List[Dict[str, Any]] = []
205
+ unverified_peers: List[str] = []
206
+
207
+ if os.path.isdir(store_dir):
208
+ for fname in sorted(os.listdir(store_dir)):
209
+ if not fname.endswith(".json"):
210
+ continue
211
+ peer_p = os.path.join(store_dir, fname)
212
+ try:
213
+ with open(peer_p, "r", encoding="utf-8", errors="replace") as f:
214
+ data = json.load(f)
215
+ except Exception:
216
+ unverified_peers.append(fname[:-5])
217
+ continue
218
+
219
+ if not isinstance(data, dict) or not cls.verify_manifest(data):
220
+ peer_id = (data.get("repo_name") if isinstance(data, dict) else None) or fname[:-5]
221
+ unverified_peers.append(str(peer_id))
222
+ continue
223
+
224
+ repo_name = str(data.get("repo_name") or fname[:-5])
225
+ for mod in data.get("modules", []):
226
+ skel = str(mod.get("skeleton") or "")
227
+ m_count = len(pattern.findall(skel))
228
+ if m_count > 0:
229
+ impacted_peers.append({
230
+ "repo_name": repo_name,
231
+ "rel_path": str(mod.get("rel_path") or ""),
232
+ "lang": str(mod.get("lang") or ""),
233
+ "matches": m_count,
234
+ })
235
+
236
+ # 3. Optional SCIP trace
237
+ scip_trace: Optional[Dict[str, Any]] = None
238
+ if scip_path and os.path.isfile(scip_path):
239
+ try:
240
+ from tzero.tzero_scip import ScipIndexImporter
241
+ scip_trace = ScipIndexImporter.load(scip_path).trace_symbol(sym)
242
+ except Exception as e:
243
+ scip_trace = {"error": str(e)}
244
+
245
+ return {
246
+ "symbol": sym,
247
+ "local_hits": local_hits,
248
+ "impacted_peers": impacted_peers,
249
+ "unverified_peers": unverified_peers,
250
+ "scip_trace": scip_trace,
251
+ "total_impacted_files": len(local_hits) + len(impacted_peers),
252
+ }
253
+
254
+
255
+ def run_federation_cli(
256
+ action: str = "list",
257
+ workspace_dir: str = ".",
258
+ target_file: Optional[str] = None,
259
+ repo_name: Optional[str] = None,
260
+ symbol_name: Optional[str] = None,
261
+ scip_path: Optional[str] = None,
262
+ ) -> int:
263
+ act = (action or "list").strip().lower()
264
+ if act == "impact":
265
+ if not symbol_name or not str(symbol_name).strip():
266
+ print(
267
+ json.dumps({"error": "Symbol name required for 'impact' (pass --federation-symbol <symbol>)"}, indent=2),
268
+ file=sys.stderr,
269
+ )
270
+ return 1
271
+ res = FederationSyncEngine.analyze_cross_repo_impact(workspace_dir, str(symbol_name).strip(), scip_path=scip_path)
272
+ print(json.dumps(res, indent=2))
273
+ return 0
274
+ if act in ("import", "verify") and not target_file:
275
+ print(
276
+ json.dumps({"error": f"Target manifest file required for '{act}' (pass --federation-out <file>)"}, indent=2),
277
+ file=sys.stderr,
278
+ )
279
+ return 1
280
+ if act == "export":
281
+ out_p = target_file or os.path.join(workspace_dir, FEDERATION_DIR, f"{repo_name or 'self'}.json")
282
+ res = FederationSyncEngine.export_manifest(workspace_dir=workspace_dir, repo_name=repo_name, out_file=out_p)
283
+ print(json.dumps({"action": "export", "repo_name": res["repo_name"], "module_count": res["module_count"], "sha256": res["sha256"], "out_file": out_p}, indent=2))
284
+ return 0
285
+ if act == "import" and target_file:
286
+ res = FederationSyncEngine.import_manifest(workspace_dir=workspace_dir, manifest_path=target_file)
287
+ print(json.dumps(res, indent=2))
288
+ return 0
289
+ if act == "verify" and target_file:
290
+ with open(target_file, "r", encoding="utf-8", errors="replace") as f:
291
+ data = json.load(f)
292
+ ok = FederationSyncEngine.verify_manifest(data)
293
+ print(json.dumps({"verified": ok, "repo_name": data.get("repo_name", "")}, indent=2))
294
+ return 0 if ok else 1
295
+
296
+ peers = FederationSyncEngine.list_peers(workspace_dir=workspace_dir)
297
+ print(json.dumps({"peers": peers}, indent=2))
298
+ return 0
299
+