tzero-mcp 11.0.0 ā 11.11.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.
- package/CHANGELOG.md +56 -56
- package/CONTRIBUTING.md +71 -71
- package/LICENSE +21 -21
- package/README.md +64 -64
- package/bin/tzero-mcp.js +62 -62
- package/bin/tzero.js +61 -61
- package/index.d.ts +25 -25
- package/index.js +15 -15
- package/package.json +89 -88
- package/src/addmcp.py +1203 -1197
- package/src/app.py +1810 -1810
- package/src/main.py +60 -60
- package/src/pc_fixer_mcp.py +25 -25
- package/src/tzero/__init__.py +54 -54
- package/src/tzero/__main__.py +6 -6
- package/src/tzero/siber_akademi_icon.py +77 -77
- package/src/tzero/tzero_arch_test.py +463 -463
- package/src/tzero/tzero_benchmark.py +475 -475
- package/src/tzero/tzero_blackboard.py +257 -257
- package/src/tzero/tzero_bridge.py +546 -546
- package/src/tzero/tzero_budget.py +195 -195
- package/src/tzero/tzero_card.py +431 -0
- package/src/tzero/tzero_ci.py +153 -153
- package/src/tzero/tzero_commit.py +192 -192
- package/src/tzero/tzero_contracts.py +1093 -1093
- package/src/tzero/tzero_cost.py +166 -166
- package/src/tzero/tzero_dashboard.py +1960 -1960
- package/src/tzero/tzero_debt.py +461 -461
- package/src/tzero/tzero_deps.py +462 -462
- package/src/tzero/tzero_drift.py +208 -208
- package/src/tzero/tzero_explain.py +306 -306
- package/src/tzero/tzero_features.py +3024 -3024
- package/src/tzero/tzero_federation.py +299 -299
- package/src/tzero/tzero_fix.py +557 -228
- package/src/tzero/tzero_fixer/__init__.py +63 -63
- package/src/tzero/tzero_fixer/amalgamation.py +334 -334
- package/src/tzero/tzero_fixer/ast_syntax_healer.py +464 -464
- package/src/tzero/tzero_fixer/ast_type_modernizer.py +288 -288
- package/src/tzero/tzero_fixer/async_io_modernizer.py +127 -127
- package/src/tzero/tzero_fixer/automated_regression_suite.py +600 -600
- package/src/tzero/tzero_fixer/benchmarks_and_diagnostics.py +174 -174
- package/src/tzero/tzero_fixer/ci_cd_self_healing_gate.py +246 -246
- package/src/tzero/tzero_fixer/code_duplicity_and_refactorer.py +151 -151
- package/src/tzero/tzero_fixer/code_smells_healer.py +260 -260
- package/src/tzero/tzero_fixer/cwe_remediator.py +171 -171
- package/src/tzero/tzero_fixer/dead_code_eliminator.py +150 -150
- package/src/tzero/tzero_fixer/dependency_vulnerability_auditor.py +309 -309
- package/src/tzero/tzero_fixer/git_advanced_surgeon.py +280 -280
- package/src/tzero/tzero_fixer/hardware_and_disk_doctor.py +325 -325
- package/src/tzero/tzero_fixer/import_graph_healer.py +412 -412
- package/src/tzero/tzero_fixer/interactive_tui.py +91 -91
- package/src/tzero/tzero_fixer/knowledge_base.py +295 -295
- package/src/tzero/tzero_fixer/knowledge_base_extended.py +940 -940
- package/src/tzero/tzero_fixer/linters_and_static_analyzer.py +307 -307
- package/src/tzero/tzero_fixer/mcp_server.py +489 -489
- package/src/tzero/tzero_fixer/models.py +385 -385
- package/src/tzero/tzero_fixer/orchestrator.py +375 -375
- package/src/tzero/tzero_fixer/os_doctor.py +502 -502
- package/src/tzero/tzero_fixer/packaging_abi_surgeon.py +323 -323
- package/src/tzero/tzero_fixer/pc_fixer_doctor.py +600 -600
- package/src/tzero/tzero_fixer/performance_and_memory_profiler.py +274 -274
- package/src/tzero/tzero_fixer/polyglot_ast_parsers.py +313 -313
- package/src/tzero/tzero_fixer/polyglot_build_healer.py +364 -364
- package/src/tzero/tzero_fixer/polyglot_config_healer.py +318 -318
- package/src/tzero/tzero_fixer/polyglot_doctor.py +372 -372
- package/src/tzero/tzero_fixer/polyglot_linters.py +619 -619
- package/src/tzero/tzero_fixer/polyglot_schema_validator.py +305 -305
- package/src/tzero/tzero_fixer/security_cwe_database.py +444 -444
- package/src/tzero/tzero_fixer/security_deep_rules.py +114 -114
- package/src/tzero/tzero_fixer/security_rules_catalog.py +110 -110
- package/src/tzero/tzero_fixer/security_zero_leak.py +326 -326
- package/src/tzero/tzero_fixer/smart_patch_recommender.py +223 -223
- package/src/tzero/tzero_fixer/synthetic_workspace_generator.py +220 -220
- package/src/tzero/tzero_fixer/system_diagnostics_extended.py +493 -493
- package/src/tzero/tzero_fixer/system_repair_recipes.py +447 -447
- package/src/tzero/tzero_fixer/venv_doctor.py +309 -309
- package/src/tzero/tzero_golden.py +319 -319
- package/src/tzero/tzero_graph_hud.html +338 -338
- package/src/tzero/tzero_graph_rag.py +263 -263
- package/src/tzero/tzero_growth.py +415 -0
- package/src/tzero/tzero_guard.py +251 -243
- package/src/tzero/tzero_hooks.py +565 -565
- package/src/tzero/tzero_infra.py +274 -274
- package/src/tzero/tzero_jarvis/__init__.py +134 -124
- package/src/tzero/tzero_jarvis/causal_graph.py +310 -310
- package/src/tzero/tzero_jarvis/creative_director.py +333 -0
- package/src/tzero/tzero_jarvis/graph_visualizer.py +395 -395
- package/src/tzero/tzero_jarvis/hybrid_search.py +214 -214
- package/src/tzero/tzero_jarvis/latent_press.py +137 -137
- package/src/tzero/tzero_jarvis/memory_consolidation.py +212 -212
- package/src/tzero/tzero_jarvis/minhash_lsh.py +184 -184
- package/src/tzero/tzero_jarvis/orchestrator.py +335 -335
- package/src/tzero/tzero_jarvis/self_healing.py +308 -308
- package/src/tzero/tzero_jarvis/semantic_compressor.py +887 -887
- package/src/tzero/tzero_jarvis/swarm.py +261 -261
- package/src/tzero/tzero_jarvis/swarm_bft.py +144 -144
- package/src/tzero/tzero_jarvis/workspace_orchestrator.py +1167 -1167
- package/src/tzero/tzero_jarvis/zero_key_router.py +173 -173
- package/src/tzero/tzero_lsp.py +634 -634
- package/src/tzero/tzero_mcp.py +5314 -5237
- package/src/tzero/tzero_mutation.py +358 -358
- package/src/tzero/tzero_neural_cortex.py +1425 -1425
- package/src/tzero/tzero_packer.py +577 -577
- package/src/tzero/tzero_patch.py +624 -624
- package/src/tzero/tzero_pc_fixer.py +12699 -12699
- package/src/tzero/tzero_pipe.py +95 -95
- package/src/tzero/tzero_polyglot.py +799 -799
- package/src/tzero/tzero_proxy.py +127 -127
- package/src/tzero/tzero_reachability.py +272 -272
- package/src/tzero/tzero_replay.py +141 -141
- package/src/tzero/tzero_rust_bridge.py +198 -198
- package/src/tzero/tzero_scip.py +368 -368
- package/src/tzero/tzero_security.py +573 -573
- package/src/tzero/tzero_semantic_merge.py +189 -189
- package/src/tzero/tzero_snapshot.py +471 -471
- package/src/tzero/tzero_stubs.py +313 -313
- package/src/tzero/tzero_subagent_engine.py +459 -459
- package/src/tzero/tzero_superdesign.py +774 -774
- package/src/tzero/tzero_sync.py +241 -241
- package/src/tzero/tzero_task_benchmark.py +506 -458
- package/src/tzero/tzero_tui.py +313 -313
- package/src/tzero/tzero_turbo.py +264 -264
- package/src/tzero/tzero_v3.py +9997 -9900
- package/src/tzero.py +6 -6
- package/src/tzero_mcp.py +25 -0
- package/test/package.test.js +55 -55
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Siber Akademi ā T-Zero AST Semantic 3-Way Merge & Conflict Healer.
|
|
4
|
-
Developer: Toprak Ahmet AydoÄmuÅ (Siber Akademi)
|
|
5
|
-
License: MIT
|
|
6
|
-
|
|
7
|
-
Performs AST-aware 3-way code merging and automated resolution of git conflict blocks.
|
|
8
|
-
Safely combines independent function additions, deduplicates polyglot imports,
|
|
9
|
-
and eliminates broken syntax markers without relying on external cloud APIs.
|
|
10
|
-
100% Free, Zero External Dependencies, 100% Zero-Leak Certified.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import os
|
|
14
|
-
import sys
|
|
15
|
-
import ast
|
|
16
|
-
import re
|
|
17
|
-
from dataclasses import dataclass, field
|
|
18
|
-
from typing import Dict, List, Optional, Set, Tuple
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass
|
|
22
|
-
class MergeResult:
|
|
23
|
-
success: bool
|
|
24
|
-
merged_code: str
|
|
25
|
-
auto_resolved_conflicts: int
|
|
26
|
-
unresolved_conflicts: int
|
|
27
|
-
symbols_added_ours: List[str] = field(default_factory=list)
|
|
28
|
-
symbols_added_theirs: List[str] = field(default_factory=list)
|
|
29
|
-
details: List[str] = field(default_factory=list)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class ASTSemanticMerger:
|
|
33
|
-
"""Semantic AST-aware 3-way merger and git conflict block healer."""
|
|
34
|
-
|
|
35
|
-
CONFLICT_PATTERN = re.compile(
|
|
36
|
-
r'<<<<<<<[^\n]*\n(.*?)=======\n(.*?)>>>>>>>[^\n]*\n',
|
|
37
|
-
re.DOTALL
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
@classmethod
|
|
41
|
-
def has_conflict_markers(cls, text: str) -> bool:
|
|
42
|
-
"""Returns True if file contains standard git conflict markers."""
|
|
43
|
-
return bool(cls.CONFLICT_PATTERN.search(text))
|
|
44
|
-
|
|
45
|
-
@classmethod
|
|
46
|
-
def extract_ast_symbols(cls, code: str) -> Dict[str, str]:
|
|
47
|
-
"""Extracts top-level functions, classes, and imports as symbol_name -> code string."""
|
|
48
|
-
symbols: Dict[str, str] = {}
|
|
49
|
-
try:
|
|
50
|
-
tree = ast.parse(code)
|
|
51
|
-
except SyntaxError:
|
|
52
|
-
return symbols
|
|
53
|
-
|
|
54
|
-
lines = code.splitlines(keepends=True)
|
|
55
|
-
for node in tree.body:
|
|
56
|
-
name = None
|
|
57
|
-
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
58
|
-
name = node.name
|
|
59
|
-
elif isinstance(node, ast.Import):
|
|
60
|
-
name = "import::" + ",".join(a.name for a in node.names)
|
|
61
|
-
elif isinstance(node, ast.ImportFrom):
|
|
62
|
-
name = f"from::{node.module or ''}::" + ",".join(a.name for a in node.names)
|
|
63
|
-
|
|
64
|
-
if name and hasattr(node, "lineno") and hasattr(node, "end_lineno"):
|
|
65
|
-
node_lines = lines[node.lineno - 1:node.end_lineno]
|
|
66
|
-
symbols[name] = "".join(node_lines)
|
|
67
|
-
|
|
68
|
-
return symbols
|
|
69
|
-
|
|
70
|
-
@classmethod
|
|
71
|
-
def heal_conflict_file(cls, content: str) -> MergeResult:
|
|
72
|
-
"""
|
|
73
|
-
Scans content for git conflict blocks (<<<<<<< ... ======= ... >>>>>>>)
|
|
74
|
-
and attempts semantic AST healing.
|
|
75
|
-
"""
|
|
76
|
-
matches = list(cls.CONFLICT_PATTERN.finditer(content))
|
|
77
|
-
if not matches:
|
|
78
|
-
return MergeResult(
|
|
79
|
-
success=True,
|
|
80
|
-
merged_code=content,
|
|
81
|
-
auto_resolved_conflicts=0,
|
|
82
|
-
unresolved_conflicts=0,
|
|
83
|
-
details=["No conflict markers found in input."]
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
auto_resolved = 0
|
|
87
|
-
unresolved = 0
|
|
88
|
-
details = []
|
|
89
|
-
result_text = content
|
|
90
|
-
added_ours = []
|
|
91
|
-
added_theirs = []
|
|
92
|
-
|
|
93
|
-
# Process each conflict block
|
|
94
|
-
for idx, m in enumerate(matches, 1):
|
|
95
|
-
full_match = m.group(0)
|
|
96
|
-
ours_block = m.group(1)
|
|
97
|
-
theirs_block = m.group(2)
|
|
98
|
-
|
|
99
|
-
ours_syms = cls.extract_ast_symbols(ours_block)
|
|
100
|
-
theirs_syms = cls.extract_ast_symbols(theirs_block)
|
|
101
|
-
|
|
102
|
-
# Check colliding definitions (exclude imports, which are safely unified and deduplicated)
|
|
103
|
-
ours_defs = {k: v for k, v in ours_syms.items() if not k.startswith("import::") and not k.startswith("from::")}
|
|
104
|
-
theirs_defs = {k: v for k, v in theirs_syms.items() if not k.startswith("import::") and not k.startswith("from::")}
|
|
105
|
-
shared_defs = set(ours_defs.keys()).intersection(set(theirs_defs.keys()))
|
|
106
|
-
|
|
107
|
-
# If definitions are disjoint (or purely imports/declarations), merge safely!
|
|
108
|
-
if not shared_defs:
|
|
109
|
-
merged_snippet = ours_block.strip() + "\n\n" + theirs_block.strip() + "\n"
|
|
110
|
-
result_text = result_text.replace(full_match, merged_snippet, 1)
|
|
111
|
-
auto_resolved += 1
|
|
112
|
-
added_ours.extend(list(ours_defs.keys()))
|
|
113
|
-
added_theirs.extend(list(theirs_defs.keys()))
|
|
114
|
-
details.append(
|
|
115
|
-
f"Conflict #{idx}: Auto-healed disjoint AST symbols (Ours: {list(ours_defs.keys())}, Theirs: {list(theirs_defs.keys())})."
|
|
116
|
-
)
|
|
117
|
-
else:
|
|
118
|
-
# True semantic collision on same definition symbol
|
|
119
|
-
safe_block = (
|
|
120
|
-
f"# --- T-ZERO AST MERGE CONFLICT (Shared symbols: {list(shared_defs)}) ---\n"
|
|
121
|
-
f"# [OURS VERSION]:\n{ours_block}\n"
|
|
122
|
-
f"# [THEIRS VERSION]:\n{theirs_block}\n"
|
|
123
|
-
f"# --- END CONFLICT ---\n"
|
|
124
|
-
)
|
|
125
|
-
result_text = result_text.replace(full_match, safe_block, 1)
|
|
126
|
-
unresolved += 1
|
|
127
|
-
details.append(
|
|
128
|
-
f"Conflict #{idx}: Semantic collision on symbol(s) {list(shared_defs)}. Sanitized markers into comments."
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
# Post-process: deduplicate imports if syntactically valid Python
|
|
132
|
-
try:
|
|
133
|
-
tree = ast.parse(result_text)
|
|
134
|
-
# Check for duplicate import lines
|
|
135
|
-
import_lines_seen = set()
|
|
136
|
-
cleaned_lines = []
|
|
137
|
-
for line in result_text.splitlines():
|
|
138
|
-
stripped = line.strip()
|
|
139
|
-
if (stripped.startswith("import ") or stripped.startswith("from ")) and "#" not in stripped:
|
|
140
|
-
if stripped in import_lines_seen:
|
|
141
|
-
continue
|
|
142
|
-
import_lines_seen.add(stripped)
|
|
143
|
-
cleaned_lines.append(line)
|
|
144
|
-
result_text = "\n".join(cleaned_lines)
|
|
145
|
-
if not result_text.endswith("\n"):
|
|
146
|
-
result_text += "\n"
|
|
147
|
-
except SyntaxError:
|
|
148
|
-
pass
|
|
149
|
-
|
|
150
|
-
return MergeResult(
|
|
151
|
-
success=(unresolved == 0),
|
|
152
|
-
merged_code=result_text,
|
|
153
|
-
auto_resolved_conflicts=auto_resolved,
|
|
154
|
-
unresolved_conflicts=unresolved,
|
|
155
|
-
symbols_added_ours=added_ours,
|
|
156
|
-
symbols_added_theirs=added_theirs,
|
|
157
|
-
details=details
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
@classmethod
|
|
161
|
-
def heal_file_on_disk(cls, file_path: str, write_in_place: bool = True) -> MergeResult:
|
|
162
|
-
"""Reads a file with git conflict markers, heals it, and optionally overwrites it."""
|
|
163
|
-
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
164
|
-
content = f.read()
|
|
165
|
-
|
|
166
|
-
res = cls.heal_conflict_file(content)
|
|
167
|
-
if write_in_place and res.auto_resolved_conflicts > 0:
|
|
168
|
-
with open(file_path, "w", encoding="utf-8") as f:
|
|
169
|
-
f.write(res.merged_code)
|
|
170
|
-
|
|
171
|
-
return res
|
|
172
|
-
|
|
173
|
-
@classmethod
|
|
174
|
-
def render_cli(cls, res: MergeResult, file_hint: str = "file"):
|
|
175
|
-
status_color = "\033[32m" if res.success else "\033[33m"
|
|
176
|
-
print(f"\nš§© \033[1mT-ZERO AST SEMANTIC MERGE & CONFLICT HEALER\033[0m")
|
|
177
|
-
print("=" * 70)
|
|
178
|
-
print(f"š Target: {file_hint}")
|
|
179
|
-
print(f"ā” Auto-Healed Blocks: \033[32m{res.auto_resolved_conflicts}\033[0m")
|
|
180
|
-
print(f"ā ļø Collisions: {status_color}{res.unresolved_conflicts}\033[0m")
|
|
181
|
-
print("=" * 70)
|
|
182
|
-
for d in res.details:
|
|
183
|
-
print(f" ⢠{d}")
|
|
184
|
-
print("=" * 70)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
def heal_conflicts(content: str) -> MergeResult:
|
|
188
|
-
"""Convenience functional interface."""
|
|
189
|
-
return ASTSemanticMerger.heal_conflict_file(content)
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Siber Akademi ā T-Zero AST Semantic 3-Way Merge & Conflict Healer.
|
|
4
|
+
Developer: Toprak Ahmet AydoÄmuÅ (Siber Akademi)
|
|
5
|
+
License: MIT
|
|
6
|
+
|
|
7
|
+
Performs AST-aware 3-way code merging and automated resolution of git conflict blocks.
|
|
8
|
+
Safely combines independent function additions, deduplicates polyglot imports,
|
|
9
|
+
and eliminates broken syntax markers without relying on external cloud APIs.
|
|
10
|
+
100% Free, Zero External Dependencies, 100% Zero-Leak Certified.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import ast
|
|
16
|
+
import re
|
|
17
|
+
from dataclasses import dataclass, field
|
|
18
|
+
from typing import Dict, List, Optional, Set, Tuple
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class MergeResult:
|
|
23
|
+
success: bool
|
|
24
|
+
merged_code: str
|
|
25
|
+
auto_resolved_conflicts: int
|
|
26
|
+
unresolved_conflicts: int
|
|
27
|
+
symbols_added_ours: List[str] = field(default_factory=list)
|
|
28
|
+
symbols_added_theirs: List[str] = field(default_factory=list)
|
|
29
|
+
details: List[str] = field(default_factory=list)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ASTSemanticMerger:
|
|
33
|
+
"""Semantic AST-aware 3-way merger and git conflict block healer."""
|
|
34
|
+
|
|
35
|
+
CONFLICT_PATTERN = re.compile(
|
|
36
|
+
r'<<<<<<<[^\n]*\n(.*?)=======\n(.*?)>>>>>>>[^\n]*\n',
|
|
37
|
+
re.DOTALL
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def has_conflict_markers(cls, text: str) -> bool:
|
|
42
|
+
"""Returns True if file contains standard git conflict markers."""
|
|
43
|
+
return bool(cls.CONFLICT_PATTERN.search(text))
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def extract_ast_symbols(cls, code: str) -> Dict[str, str]:
|
|
47
|
+
"""Extracts top-level functions, classes, and imports as symbol_name -> code string."""
|
|
48
|
+
symbols: Dict[str, str] = {}
|
|
49
|
+
try:
|
|
50
|
+
tree = ast.parse(code)
|
|
51
|
+
except SyntaxError:
|
|
52
|
+
return symbols
|
|
53
|
+
|
|
54
|
+
lines = code.splitlines(keepends=True)
|
|
55
|
+
for node in tree.body:
|
|
56
|
+
name = None
|
|
57
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
58
|
+
name = node.name
|
|
59
|
+
elif isinstance(node, ast.Import):
|
|
60
|
+
name = "import::" + ",".join(a.name for a in node.names)
|
|
61
|
+
elif isinstance(node, ast.ImportFrom):
|
|
62
|
+
name = f"from::{node.module or ''}::" + ",".join(a.name for a in node.names)
|
|
63
|
+
|
|
64
|
+
if name and hasattr(node, "lineno") and hasattr(node, "end_lineno"):
|
|
65
|
+
node_lines = lines[node.lineno - 1:node.end_lineno]
|
|
66
|
+
symbols[name] = "".join(node_lines)
|
|
67
|
+
|
|
68
|
+
return symbols
|
|
69
|
+
|
|
70
|
+
@classmethod
|
|
71
|
+
def heal_conflict_file(cls, content: str) -> MergeResult:
|
|
72
|
+
"""
|
|
73
|
+
Scans content for git conflict blocks (<<<<<<< ... ======= ... >>>>>>>)
|
|
74
|
+
and attempts semantic AST healing.
|
|
75
|
+
"""
|
|
76
|
+
matches = list(cls.CONFLICT_PATTERN.finditer(content))
|
|
77
|
+
if not matches:
|
|
78
|
+
return MergeResult(
|
|
79
|
+
success=True,
|
|
80
|
+
merged_code=content,
|
|
81
|
+
auto_resolved_conflicts=0,
|
|
82
|
+
unresolved_conflicts=0,
|
|
83
|
+
details=["No conflict markers found in input."]
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
auto_resolved = 0
|
|
87
|
+
unresolved = 0
|
|
88
|
+
details = []
|
|
89
|
+
result_text = content
|
|
90
|
+
added_ours = []
|
|
91
|
+
added_theirs = []
|
|
92
|
+
|
|
93
|
+
# Process each conflict block
|
|
94
|
+
for idx, m in enumerate(matches, 1):
|
|
95
|
+
full_match = m.group(0)
|
|
96
|
+
ours_block = m.group(1)
|
|
97
|
+
theirs_block = m.group(2)
|
|
98
|
+
|
|
99
|
+
ours_syms = cls.extract_ast_symbols(ours_block)
|
|
100
|
+
theirs_syms = cls.extract_ast_symbols(theirs_block)
|
|
101
|
+
|
|
102
|
+
# Check colliding definitions (exclude imports, which are safely unified and deduplicated)
|
|
103
|
+
ours_defs = {k: v for k, v in ours_syms.items() if not k.startswith("import::") and not k.startswith("from::")}
|
|
104
|
+
theirs_defs = {k: v for k, v in theirs_syms.items() if not k.startswith("import::") and not k.startswith("from::")}
|
|
105
|
+
shared_defs = set(ours_defs.keys()).intersection(set(theirs_defs.keys()))
|
|
106
|
+
|
|
107
|
+
# If definitions are disjoint (or purely imports/declarations), merge safely!
|
|
108
|
+
if not shared_defs:
|
|
109
|
+
merged_snippet = ours_block.strip() + "\n\n" + theirs_block.strip() + "\n"
|
|
110
|
+
result_text = result_text.replace(full_match, merged_snippet, 1)
|
|
111
|
+
auto_resolved += 1
|
|
112
|
+
added_ours.extend(list(ours_defs.keys()))
|
|
113
|
+
added_theirs.extend(list(theirs_defs.keys()))
|
|
114
|
+
details.append(
|
|
115
|
+
f"Conflict #{idx}: Auto-healed disjoint AST symbols (Ours: {list(ours_defs.keys())}, Theirs: {list(theirs_defs.keys())})."
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
# True semantic collision on same definition symbol
|
|
119
|
+
safe_block = (
|
|
120
|
+
f"# --- T-ZERO AST MERGE CONFLICT (Shared symbols: {list(shared_defs)}) ---\n"
|
|
121
|
+
f"# [OURS VERSION]:\n{ours_block}\n"
|
|
122
|
+
f"# [THEIRS VERSION]:\n{theirs_block}\n"
|
|
123
|
+
f"# --- END CONFLICT ---\n"
|
|
124
|
+
)
|
|
125
|
+
result_text = result_text.replace(full_match, safe_block, 1)
|
|
126
|
+
unresolved += 1
|
|
127
|
+
details.append(
|
|
128
|
+
f"Conflict #{idx}: Semantic collision on symbol(s) {list(shared_defs)}. Sanitized markers into comments."
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Post-process: deduplicate imports if syntactically valid Python
|
|
132
|
+
try:
|
|
133
|
+
tree = ast.parse(result_text)
|
|
134
|
+
# Check for duplicate import lines
|
|
135
|
+
import_lines_seen = set()
|
|
136
|
+
cleaned_lines = []
|
|
137
|
+
for line in result_text.splitlines():
|
|
138
|
+
stripped = line.strip()
|
|
139
|
+
if (stripped.startswith("import ") or stripped.startswith("from ")) and "#" not in stripped:
|
|
140
|
+
if stripped in import_lines_seen:
|
|
141
|
+
continue
|
|
142
|
+
import_lines_seen.add(stripped)
|
|
143
|
+
cleaned_lines.append(line)
|
|
144
|
+
result_text = "\n".join(cleaned_lines)
|
|
145
|
+
if not result_text.endswith("\n"):
|
|
146
|
+
result_text += "\n"
|
|
147
|
+
except SyntaxError:
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
return MergeResult(
|
|
151
|
+
success=(unresolved == 0),
|
|
152
|
+
merged_code=result_text,
|
|
153
|
+
auto_resolved_conflicts=auto_resolved,
|
|
154
|
+
unresolved_conflicts=unresolved,
|
|
155
|
+
symbols_added_ours=added_ours,
|
|
156
|
+
symbols_added_theirs=added_theirs,
|
|
157
|
+
details=details
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
@classmethod
|
|
161
|
+
def heal_file_on_disk(cls, file_path: str, write_in_place: bool = True) -> MergeResult:
|
|
162
|
+
"""Reads a file with git conflict markers, heals it, and optionally overwrites it."""
|
|
163
|
+
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
164
|
+
content = f.read()
|
|
165
|
+
|
|
166
|
+
res = cls.heal_conflict_file(content)
|
|
167
|
+
if write_in_place and res.auto_resolved_conflicts > 0:
|
|
168
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
169
|
+
f.write(res.merged_code)
|
|
170
|
+
|
|
171
|
+
return res
|
|
172
|
+
|
|
173
|
+
@classmethod
|
|
174
|
+
def render_cli(cls, res: MergeResult, file_hint: str = "file"):
|
|
175
|
+
status_color = "\033[32m" if res.success else "\033[33m"
|
|
176
|
+
print(f"\nš§© \033[1mT-ZERO AST SEMANTIC MERGE & CONFLICT HEALER\033[0m")
|
|
177
|
+
print("=" * 70)
|
|
178
|
+
print(f"š Target: {file_hint}")
|
|
179
|
+
print(f"ā” Auto-Healed Blocks: \033[32m{res.auto_resolved_conflicts}\033[0m")
|
|
180
|
+
print(f"ā ļø Collisions: {status_color}{res.unresolved_conflicts}\033[0m")
|
|
181
|
+
print("=" * 70)
|
|
182
|
+
for d in res.details:
|
|
183
|
+
print(f" ⢠{d}")
|
|
184
|
+
print("=" * 70)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def heal_conflicts(content: str) -> MergeResult:
|
|
188
|
+
"""Convenience functional interface."""
|
|
189
|
+
return ASTSemanticMerger.heal_conflict_file(content)
|