tzero-mcp 10.7.4 → 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 +27 -0
- package/LICENSE +21 -21
- package/README.md +3 -3
- package/bin/tzero-mcp.js +7 -11
- package/bin/tzero.js +7 -11
- package/index.js +3 -3
- package/package.json +3 -2
- package/src/addmcp.py +1203 -1194
- package/src/app.py +1810 -0
- package/src/main.py +60 -60
- package/src/pc_fixer_mcp.py +25 -0
- package/src/tzero/__init__.py +54 -0
- package/src/tzero/__main__.py +6 -0
- package/src/tzero/siber_akademi.ico +0 -0
- package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +77 -77
- package/src/tzero/tzero_arch_test.py +463 -0
- package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +2 -2
- package/src/tzero/tzero_blackboard.py +257 -0
- package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +184 -0
- package/src/tzero/tzero_budget.py +195 -0
- package/src/tzero/tzero_card.py +431 -0
- package/src/{tzero_ci.py → tzero/tzero_ci.py} +7 -7
- package/src/{tzero_commit.py → tzero/tzero_commit.py} +1 -1
- package/src/tzero/tzero_contracts.py +1093 -0
- package/src/{tzero_cost.py → tzero/tzero_cost.py} +4 -1
- package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +1960 -1448
- package/src/tzero/tzero_debt.py +461 -0
- package/src/{tzero_deps.py → tzero/tzero_deps.py} +462 -287
- package/src/{tzero_drift.py → tzero/tzero_drift.py} +1 -1
- package/src/{tzero_explain.py → tzero/tzero_explain.py} +306 -240
- package/src/{tzero_features.py → tzero/tzero_features.py} +3024 -3022
- package/src/tzero/tzero_federation.py +299 -0
- package/src/tzero/tzero_fix.py +557 -0
- package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +334 -334
- package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +8 -8
- package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +280 -280
- package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +325 -325
- package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +489 -447
- package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +385 -385
- package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +375 -375
- package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +323 -323
- package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +2 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +364 -364
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +619 -619
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +2 -2
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +493 -493
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +1 -1
- package/src/tzero/tzero_golden.py +319 -0
- package/src/tzero/tzero_graph_hud.html +338 -0
- package/src/tzero/tzero_graph_rag.py +263 -0
- package/src/tzero/tzero_growth.py +415 -0
- package/src/{tzero_guard.py → tzero/tzero_guard.py} +11 -3
- package/src/tzero/tzero_hooks.py +565 -0
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +11 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +1 -1
- package/src/tzero/tzero_jarvis/creative_director.py +333 -0
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +1 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +2 -2
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +1 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +1 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +2 -2
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +1 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +3 -3
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +1 -1
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +6 -6
- package/src/tzero/tzero_lsp.py +634 -0
- package/src/tzero/tzero_mcp.py +5314 -0
- package/src/tzero/tzero_mutation.py +358 -0
- package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +1425 -1425
- package/src/tzero/tzero_packer.py +577 -0
- package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +42 -0
- package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +1 -1
- package/src/tzero/tzero_polyglot.py +799 -0
- package/src/tzero/tzero_proxy.py +127 -0
- package/src/tzero/tzero_rust_bridge.py +198 -0
- package/src/tzero/tzero_scip.py +368 -0
- package/src/{tzero_security.py → tzero/tzero_security.py} +573 -570
- package/src/tzero/tzero_semantic_merge.py +189 -0
- package/src/tzero/tzero_snapshot.py +471 -0
- package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +1 -1
- package/src/tzero/tzero_subagent_engine.py +459 -0
- package/src/{tzero_sync.py → tzero/tzero_sync.py} +2 -2
- package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +174 -31
- package/src/{tzero_tui.py → tzero/tzero_tui.py} +313 -244
- package/src/tzero/tzero_turbo.py +264 -0
- package/src/{tzero_v3.py → tzero/tzero_v3.py} +9997 -9435
- package/src/tzero.py +6 -58
- package/src/tzero_mcp.py +25 -4858
- package/test/package.test.js +14 -2
- package/src/tzero/jarvis/semantic_compressor.py +0 -373
- package/src/tzero_fix.py +0 -228
- package/src/tzero_gateway.py +0 -885
- package/src/tzero_packer.py +0 -370
- package/src/tzero_polyglot.py +0 -422
- package/src/tzero_snapshot.py +0 -258
- /package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +0 -0
- /package/src/{tzero_infra.py → tzero/tzero_infra.py} +0 -0
- /package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +0 -0
- /package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +0 -0
- /package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +0 -0
- /package/src/{tzero_patch.py → tzero/tzero_patch.py} +0 -0
- /package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +0 -0
- /package/src/{tzero_replay.py → tzero/tzero_replay.py} +0 -0
- /package/src/{tzero_superdesign.py → tzero/tzero_superdesign.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
|
+
|