tzero-mcp 10.7.4 → 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 +56 -29
  2. package/CONTRIBUTING.md +71 -71
  3. package/README.md +64 -64
  4. package/bin/tzero-mcp.js +62 -66
  5. package/bin/tzero.js +61 -65
  6. package/index.d.ts +25 -25
  7. package/index.js +15 -15
  8. package/package.json +88 -88
  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 -43
  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,257 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Siber Akademi — T-Zero Multi-Agent Swarm Blackboard & In-Memory Working Memory.
4
+ Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
5
+ License: MIT
6
+
7
+ Provides thread-safe inter-agent blackboard communication, symbol-level reservation locks,
8
+ shared architectural invariants, and zero-token AST context caching for multi-agent swarms.
9
+ 100% Free, Zero External Dependencies, 100% Zero-Leak Certified.
10
+ """
11
+
12
+ import os
13
+ import sys
14
+ import time
15
+ import json
16
+ import threading
17
+ import hashlib
18
+ from dataclasses import dataclass, field, asdict
19
+ from typing import Dict, List, Optional, Any, Set
20
+
21
+
22
+ @dataclass
23
+ class BlackboardEntry:
24
+ entry_id: str
25
+ author_agent: str
26
+ topic: str
27
+ payload: Any
28
+ timestamp: float = field(default_factory=time.time)
29
+ tags: List[str] = field(default_factory=list)
30
+
31
+
32
+ @dataclass
33
+ class SymbolLock:
34
+ symbol_name: str
35
+ file_path: str
36
+ agent_id: str
37
+ acquired_at: float = field(default_factory=time.time)
38
+
39
+
40
+ @dataclass
41
+ class SharedInvariant:
42
+ invariant_id: str
43
+ source_agent: str
44
+ description: str
45
+ severity: str = "HIGH" # CRITICAL, HIGH, MEDIUM, LOW
46
+ created_at: float = field(default_factory=time.time)
47
+
48
+
49
+ class MultiAgentBlackboard:
50
+ """Thread-safe, high-speed shared working memory for autonomous agent swarms."""
51
+
52
+ _instance: Optional["MultiAgentBlackboard"] = None
53
+ _lock = threading.Lock()
54
+
55
+ def __init__(self, workspace_root: str = "."):
56
+ self.workspace_root = os.path.abspath(workspace_root)
57
+ self._entries: List[BlackboardEntry] = []
58
+ self._symbol_locks: Dict[str, SymbolLock] = {} # key: "file:symbol"
59
+ self._invariants: Dict[str, SharedInvariant] = {}
60
+ self._ast_cache: Dict[str, str] = {} # file_path -> compressed AST text
61
+ self._mutex = threading.RLock()
62
+
63
+ @classmethod
64
+ def get_instance(cls, workspace_root: str = ".") -> "MultiAgentBlackboard":
65
+ with cls._lock:
66
+ if cls._instance is None:
67
+ cls._instance = cls(workspace_root=workspace_root)
68
+ return cls._instance
69
+
70
+ @classmethod
71
+ def reset_instance(cls):
72
+ with cls._lock:
73
+ cls._instance = None
74
+
75
+ # -------------------------------------------------------------------------
76
+ # Symbol Locking & Concurrency Control
77
+ # -------------------------------------------------------------------------
78
+ def claim_symbol(self, agent_id: str, file_path: str, symbol_name: str) -> bool:
79
+ """Claims exclusive modification lock for an AST symbol. Returns True if granted."""
80
+ norm_path = os.path.normpath(file_path)
81
+ key = f"{norm_path}::{symbol_name}"
82
+ with self._mutex:
83
+ existing = self._symbol_locks.get(key)
84
+ if existing is not None:
85
+ if existing.agent_id == agent_id:
86
+ return True # Reentrant acquisition
87
+ return False # Locked by another agent
88
+ self._symbol_locks[key] = SymbolLock(
89
+ symbol_name=symbol_name,
90
+ file_path=norm_path,
91
+ agent_id=agent_id
92
+ )
93
+ return True
94
+
95
+ def release_symbol(self, agent_id: str, file_path: str, symbol_name: str) -> bool:
96
+ """Releases modification lock for an AST symbol. Returns True if successfully released."""
97
+ norm_path = os.path.normpath(file_path)
98
+ key = f"{norm_path}::{symbol_name}"
99
+ with self._mutex:
100
+ existing = self._symbol_locks.get(key)
101
+ if existing is None:
102
+ return True
103
+ if existing.agent_id != agent_id:
104
+ return False # Cannot release another agent's lock
105
+ del self._symbol_locks[key]
106
+ return True
107
+
108
+ def get_active_locks(self) -> List[SymbolLock]:
109
+ """Returns list of currently held symbol locks."""
110
+ with self._mutex:
111
+ return list(self._symbol_locks.values())
112
+
113
+ # -------------------------------------------------------------------------
114
+ # Shared Invariants & Architectural Rules
115
+ # -------------------------------------------------------------------------
116
+ def post_invariant(self, source_agent: str, description: str, severity: str = "HIGH") -> str:
117
+ """Publishes an invariant rule that all swarming agents must respect."""
118
+ rule_hash = hashlib.sha256(f"{source_agent}::{description}".encode()).hexdigest()[:8]
119
+ inv_id = f"INV-{rule_hash.upper()}"
120
+ with self._mutex:
121
+ self._invariants[inv_id] = SharedInvariant(
122
+ invariant_id=inv_id,
123
+ source_agent=source_agent,
124
+ description=description,
125
+ severity=severity.upper()
126
+ )
127
+ return inv_id
128
+
129
+ def get_invariants(self) -> List[SharedInvariant]:
130
+ """Retrieves all shared invariants posted on the blackboard."""
131
+ with self._mutex:
132
+ return list(self._invariants.values())
133
+
134
+ # -------------------------------------------------------------------------
135
+ # Discoveries & Knowledge Feeds
136
+ # -------------------------------------------------------------------------
137
+ def post_discovery(self, author_agent: str, topic: str, payload: Any, tags: Optional[List[str]] = None) -> str:
138
+ """Appends a new discovery or progress update to the shared blackboard."""
139
+ e_hash = hashlib.sha256(f"{author_agent}::{topic}::{time.time()}".encode()).hexdigest()[:10]
140
+ entry = BlackboardEntry(
141
+ entry_id=f"ENT-{e_hash}",
142
+ author_agent=author_agent,
143
+ topic=topic,
144
+ payload=payload,
145
+ tags=tags or []
146
+ )
147
+ with self._mutex:
148
+ self._entries.append(entry)
149
+ return entry.entry_id
150
+
151
+ def query_discoveries(self, topic: Optional[str] = None, tag: Optional[str] = None) -> List[BlackboardEntry]:
152
+ """Queries discoveries filtered by topic or tag."""
153
+ with self._mutex:
154
+ results = self._entries
155
+ if topic:
156
+ results = [e for e in results if e.topic.lower() == topic.lower()]
157
+ if tag:
158
+ results = [e for e in results if tag.lower() in [t.lower() for t in e.tags]]
159
+ return list(results)
160
+
161
+ # -------------------------------------------------------------------------
162
+ # Zero-Token AST Context Caching
163
+ # -------------------------------------------------------------------------
164
+ def cache_ast_summary(self, file_path: str, summary: str):
165
+ """Caches compressed AST signature so other subagents don't re-parse."""
166
+ norm_path = os.path.normpath(file_path)
167
+ with self._mutex:
168
+ self._ast_cache[norm_path] = summary
169
+
170
+ def get_ast_summary(self, file_path: str) -> Optional[str]:
171
+ """Retrieves cached AST signature for file if present."""
172
+ norm_path = os.path.normpath(file_path)
173
+ with self._mutex:
174
+ return self._ast_cache.get(norm_path)
175
+
176
+ # -------------------------------------------------------------------------
177
+ # Persistence & Reporting
178
+ # -------------------------------------------------------------------------
179
+ def export_status_markdown(self) -> str:
180
+ """Produces comprehensive Markdown report of blackboard state for LLM context."""
181
+ with self._mutex:
182
+ lines = [
183
+ "### 📋 T-Zero Multi-Agent Blackboard State",
184
+ f"- **Active Symbol Locks:** {len(self._symbol_locks)}",
185
+ f"- **Shared Invariants:** {len(self._invariants)}",
186
+ f"- **Knowledge Entries:** {len(self._entries)}",
187
+ f"- **Cached AST Profiles:** {len(self._ast_cache)}",
188
+ ""
189
+ ]
190
+
191
+ if self._invariants:
192
+ lines.append("#### 🛡️ Active Shared Invariants:")
193
+ for inv in self._invariants.values():
194
+ lines.append(f"- **[{inv.severity}] {inv.invariant_id}** (`{inv.source_agent}`): {inv.description}")
195
+ lines.append("")
196
+
197
+ if self._symbol_locks:
198
+ lines.append("#### 🔒 Reserved Symbol Locks:")
199
+ for lock in self._symbol_locks.values():
200
+ lines.append(f"- `{lock.symbol_name}` in `{lock.file_path}` held by **{lock.agent_id}**")
201
+ lines.append("")
202
+
203
+ if self._entries:
204
+ lines.append("#### 💡 Recent Swarm Discoveries:")
205
+ for e in self._entries[-5:]:
206
+ lines.append(f"- **{e.author_agent}** on `{e.topic}`: {str(e.payload)[:100]}")
207
+
208
+ return "\n".join(lines)
209
+
210
+ def persist_to_disk(self, file_path: Optional[str] = None):
211
+ """Persists state to JSON file."""
212
+ if file_path is None:
213
+ tzero_dir = os.path.join(self.workspace_root, ".tzero")
214
+ os.makedirs(tzero_dir, exist_ok=True)
215
+ file_path = os.path.join(tzero_dir, "blackboard.json")
216
+
217
+ with self._mutex:
218
+ data = {
219
+ "version": "10.8.0",
220
+ "timestamp": time.time(),
221
+ "symbol_locks": {k: asdict(v) for k, v in self._symbol_locks.items()},
222
+ "invariants": {k: asdict(v) for k, v in self._invariants.items()},
223
+ "entries": [asdict(e) for e in self._entries],
224
+ }
225
+ with open(file_path, "w", encoding="utf-8") as f:
226
+ json.dump(data, f, indent=2)
227
+
228
+ def load_from_disk(self, file_path: Optional[str] = None) -> bool:
229
+ """Loads state from JSON file if available."""
230
+ if file_path is None:
231
+ file_path = os.path.join(self.workspace_root, ".tzero", "blackboard.json")
232
+
233
+ if not os.path.isfile(file_path):
234
+ return False
235
+
236
+ try:
237
+ with open(file_path, "r", encoding="utf-8") as f:
238
+ data = json.load(f)
239
+ with self._mutex:
240
+ self._symbol_locks = {
241
+ k: SymbolLock(**v) for k, v in data.get("symbol_locks", {}).items()
242
+ }
243
+ self._invariants = {
244
+ k: SharedInvariant(**v) for k, v in data.get("invariants", {}).items()
245
+ }
246
+ self._entries = [
247
+ BlackboardEntry(**v) for v in data.get("entries", [])
248
+ ]
249
+ return True
250
+ except Exception:
251
+ return False
252
+
253
+
254
+ def get_shared_blackboard(workspace_root: str = ".") -> MultiAgentBlackboard:
255
+ """Convenience accessor for the singleton MultiAgentBlackboard."""
256
+ return MultiAgentBlackboard.get_instance(workspace_root=workspace_root)
257
+