tzero-mcp 12.2.0 → 12.2.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 (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/src/addmcp.py +10 -5
  4. package/src/app.py +3 -9
  5. package/src/tzero/__init__.py +1 -1
  6. package/src/tzero/anti_rea/asar_shield.py +3 -1
  7. package/src/tzero/anti_rea/auditor.py +42 -12
  8. package/src/tzero/anti_rea/canary_beacon.py +27 -19
  9. package/src/tzero/anti_rea/cli.py +7 -1
  10. package/src/tzero/anti_rea/confusables.py +62 -18
  11. package/src/tzero/anti_rea/engine.py +79 -10
  12. package/src/tzero/anti_rea/extractor_shield.py +52 -9
  13. package/src/tzero/anti_rea/gui.py +1 -4
  14. package/src/tzero/anti_rea/integrity_guard.py +17 -5
  15. package/src/tzero/anti_rea/rdtsc_guard.py +21 -8
  16. package/src/tzero/anti_rea/string_vault.py +10 -7
  17. package/src/tzero/siber_akademi.ico +0 -0
  18. package/src/tzero/siber_akademi_icon.py +14 -8
  19. package/src/tzero/tzero_armor.py +27 -5
  20. package/src/tzero/tzero_benchmark.py +4 -2
  21. package/src/tzero/tzero_budget.py +14 -5
  22. package/src/tzero/tzero_ci.py +1 -1
  23. package/src/tzero/tzero_contracts.py +7 -5
  24. package/src/tzero/tzero_dashboard.py +28 -9
  25. package/src/tzero/tzero_debt.py +19 -4
  26. package/src/tzero/tzero_explain.py +1 -1
  27. package/src/tzero/tzero_features.py +43 -29
  28. package/src/tzero/tzero_federation.py +9 -2
  29. package/src/tzero/tzero_fixer/mcp_server.py +10 -0
  30. package/src/tzero/tzero_golden.py +37 -9
  31. package/src/tzero/tzero_growth.py +166 -8
  32. package/src/tzero/tzero_guard.py +147 -46
  33. package/src/tzero/tzero_lsp.py +1 -1
  34. package/src/tzero/tzero_mcp.py +64 -16
  35. package/src/tzero/tzero_mutation.py +88 -15
  36. package/src/tzero/tzero_promo.py +1 -1
  37. package/src/tzero/tzero_proxy.py +105 -12
  38. package/src/tzero/tzero_scip.py +12 -6
  39. package/src/tzero/tzero_security.py +375 -60
  40. package/src/tzero/tzero_task_benchmark.py +2 -2
  41. package/src/tzero/tzero_traffic.py +35 -10
  42. package/src/tzero/tzero_tui.py +17 -8
  43. package/src/tzero/tzero_v3.py +268 -88
  44. package/src/tzero/tzero_welcome.py +65 -30
@@ -8,7 +8,7 @@ Includes native Ring-3 anti-debugging against x64dbg, IDA Pro, WinDbg, and Cheat
8
8
  stealth canary beacon telemetry, in-flight string vault, and Electron asar shielding.
9
9
 
10
10
  Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
11
- Part of Siber Akademi T-Zero Context Architect v12.2.0 Master Edition.
11
+ Part of Siber Akademi T-Zero Context Architect v12.2.2 Master Edition.
12
12
  License: MIT
13
13
  """
14
14
 
@@ -98,22 +98,44 @@ def protect_path_with_armor(
98
98
  if p.is_file():
99
99
  return AntiREAEngine.protect_file(str(p), output_path=output_path, seed=seed, **options)
100
100
 
101
- # If directory, protect all .py files within
101
+ out_root: Optional[Path] = None
102
+ if output_path:
103
+ out_root = Path(output_path)
104
+ if out_root.exists() and not out_root.is_dir():
105
+ return {
106
+ "success": False,
107
+ "error": f"Output target for directory protection must be a directory, got file: {output_path}",
108
+ }
109
+ if out_root.resolve() == p.resolve():
110
+ out_root = None
111
+
102
112
  results = []
113
+ failures = []
103
114
  count = 0
104
115
  for py_file in p.rglob("*.py"):
105
116
  if "__pycache__" in str(py_file) or ".venv" in str(py_file):
106
117
  continue
107
- res = AntiREAEngine.protect_file(str(py_file), seed=seed, **options)
118
+ dst_path: Optional[str] = None
119
+ if out_root is not None:
120
+ rel = py_file.relative_to(p)
121
+ dst_file = out_root / rel
122
+ dst_file.parent.mkdir(parents=True, exist_ok=True)
123
+ dst_path = str(dst_file)
124
+ res = AntiREAEngine.protect_file(str(py_file), output_path=dst_path, seed=seed, **options)
108
125
  if res.get("success"):
109
126
  count += 1
110
127
  results.append(res)
128
+ else:
129
+ failures.append({"file": str(py_file), "error": res.get("error", "Unknown protection failure")})
111
130
 
112
131
  return {
113
- "success": count > 0,
132
+ "success": len(failures) == 0 and count > 0,
114
133
  "directory": str(p),
134
+ "output_directory": str(out_root) if out_root is not None else str(p),
115
135
  "files_protected": count,
116
- "details": results
136
+ "files_failed": len(failures),
137
+ "failures": failures,
138
+ "details": results,
117
139
  }
118
140
 
119
141
 
@@ -2,7 +2,7 @@
2
2
  """
3
3
  Siber Akademi — T-Zero Autonomous Benchmark & Performance Optimization Engine.
4
4
  Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
5
- Version: 11.15.2
5
+ Version: 12.2.2
6
6
  License: MIT
7
7
 
8
8
  Performs quantitative multi-model benchmarks comparing raw codebase context
@@ -154,9 +154,11 @@ class TZeroBenchmarkEngine:
154
154
  speedup_factor=speedup
155
155
  ))
156
156
 
157
+ from tzero import __version__ as tz_ver
158
+
157
159
  return BenchmarkReport(
158
160
  workspace_dir=abs_root,
159
- version="11.15.2",
161
+ version=tz_ver,
160
162
  total_files=total_files,
161
163
  total_loc=total_loc,
162
164
  raw_tokens=raw_tokens,
@@ -12,7 +12,7 @@ Capabilities:
12
12
  - 100% Offline, $0 cost, zero cloud dependencies (Python standard library only).
13
13
 
14
14
  Author: Toprak Ahmet Aydoğmuş (Siber Akademi)
15
- Part of T-Zero Context Architect v12.2.0 Master Edition.
15
+ Part of T-Zero Context Architect v12.2.2 Master Edition.
16
16
  """
17
17
 
18
18
  import hashlib
@@ -68,8 +68,13 @@ class ASTTokenBudgetOptimizer:
68
68
  import tempfile
69
69
  ws_root = os.path.realpath(".")
70
70
  tmp_root = os.path.realpath(tempfile.gettempdir())
71
- abs_root = os.path.normpath(os.path.realpath(os.path.abspath(workspace_root)))
72
- if abs_root != ws_root and not abs_root.startswith(ws_root + os.sep) and not abs_root.startswith(tmp_root + os.sep):
71
+ candidate = os.path.realpath(os.path.abspath(workspace_root))
72
+ base_root = tmp_root if (candidate == tmp_root or candidate.startswith(tmp_root + os.sep)) else ws_root
73
+ rel_ws = os.path.relpath(candidate, base_root)
74
+ if rel_ws == ".." or rel_ws.startswith(".." + os.sep) or os.path.isabs(rel_ws):
75
+ raise ValueError(f"Workspace path outside allowed scope: {workspace_root}")
76
+ abs_root = os.path.normpath(os.path.join(base_root, rel_ws))
77
+ if not abs_root.startswith(base_root):
73
78
  raise ValueError(f"Workspace path outside allowed scope: {workspace_root}")
74
79
  total_chars = 0
75
80
  file_count = 0
@@ -92,8 +97,12 @@ class ASTTokenBudgetOptimizer:
92
97
  dirs[:] = [d for d in dirs if d not in ignore_dirs and not d.startswith(".")]
93
98
  for f in files:
94
99
  if f.endswith((".py", ".ts", ".js", ".rs", ".go", ".cpp", ".c", ".h", ".swift", ".kt", ".dart")):
95
- full_p = os.path.realpath(os.path.join(root, f))
96
- if not (full_p == abs_root or full_p.startswith(abs_root + os.sep)):
100
+ resolved_f = os.path.realpath(os.path.join(root, f))
101
+ rel_f = os.path.relpath(resolved_f, abs_root)
102
+ if rel_f == ".." or rel_f.startswith(".." + os.sep) or os.path.isabs(rel_f):
103
+ continue
104
+ full_p = os.path.normpath(os.path.join(abs_root, rel_f))
105
+ if not full_p.startswith(abs_root):
97
106
  continue
98
107
  try:
99
108
  with open(full_p, "rb") as fp:
@@ -755,7 +755,7 @@ def main():
755
755
  prog="tzero-ci",
756
756
  description="Siber Akademi T-Zero Local CI Pipeline & Pre-Push Verification Shield"
757
757
  )
758
- parser.add_argument("--version", "-v", action="version", version="%(prog)s 12.2.0")
758
+ parser.add_argument("--version", "-v", action="version", version="%(prog)s 12.2.2")
759
759
  parser.add_argument("--quick", "-q", action="store_true", help="Run fast verification battery (seconds)")
760
760
  parser.add_argument("--all", "-a", action="store_true", help="Run full matrix verification battery")
761
761
  parser.add_argument("--fix", action="store_true", help="Attempt auto-repair for auto-fixable gates (metadata sync)")
@@ -13,7 +13,7 @@ Capabilities:
13
13
  - 100% Offline, $0 cost, zero external dependencies (pure Python standard library).
14
14
 
15
15
  Author: Toprak Ahmet Aydoğmuş (Siber Akademi)
16
- Part of T-Zero Context Architect v12.2.0 Master Edition.
16
+ Part of T-Zero Context Architect v12.2.2 Master Edition.
17
17
  """
18
18
 
19
19
  import ast
@@ -471,9 +471,11 @@ class ASTContractExtractor:
471
471
  if "\n" in header_tail and "extends" not in header_tail:
472
472
  continue
473
473
  bases: List[str] = []
474
- ext_m = re.search(r'\bextends\s+(.+)$', header_tail, re.DOTALL)
475
- if ext_m:
476
- bases = [b.strip() for b in ext_m.group(1).split(",") if b.strip()]
474
+ ext_idx = header_tail.find("extends")
475
+ if ext_idx != -1 and (ext_idx == 0 or not (header_tail[ext_idx - 1].isalnum() or header_tail[ext_idx - 1] == "_")):
476
+ after_ext = header_tail[ext_idx + 7:]
477
+ if after_ext and after_ext[0].isspace():
478
+ bases = [b.strip() for b in after_ext.strip().split(",") if b.strip()]
477
479
  end_brace = cls._find_matching_brace(clean_code, brace_idx)
478
480
  if end_brace == -1:
479
481
  end_brace = len(clean_code) - 1
@@ -1054,7 +1056,7 @@ class ASTContractComparator:
1054
1056
  "tool": {
1055
1057
  "driver": {
1056
1058
  "name": "T-Zero Contract Guardian",
1057
- "version": "12.2.0",
1059
+ "version": "12.2.2",
1058
1060
  "rules": rules_list
1059
1061
  }
1060
1062
  },
@@ -457,7 +457,7 @@ HTML_PAGE = """<!DOCTYPE html>
457
457
  <div class="brand-logo">T0</div>
458
458
  <div>
459
459
  <div class="brand-title">T-Zero Developer Console</div>
460
- <div class="brand-sub" id="headerBrandSub">Enterprise AST Context Architect &bull; v12.2.0</div>
460
+ <div class="brand-sub" id="headerBrandSub">Enterprise AST Context Architect &bull; v12.2.2</div>
461
461
  </div>
462
462
  </div>
463
463
  <div class="header-actions">
@@ -850,7 +850,7 @@ x = 2
850
850
  </main>
851
851
 
852
852
  <footer>
853
- <span id="footerBrand">T-Zero Context Architect v12.2.0</span> &bull; Developer: Toprak Ahmet Aydoğmuş &bull; Siber Akademi
853
+ <span id="footerBrand">T-Zero Context Architect v12.2.2</span> &bull; Developer: Toprak Ahmet Aydoğmuş &bull; Siber Akademi
854
854
  </footer>
855
855
 
856
856
  <script>
@@ -1481,7 +1481,7 @@ def compute_live_dashboard_stats(workspace_dir: str = ".") -> Dict[str, Any]:
1481
1481
  if cached is not None and (now - _DASHBOARD_STATS_CACHE["ts"]) < 60.0:
1482
1482
  return cached
1483
1483
 
1484
- version = "12.2.0"
1484
+ version = "12.2.2"
1485
1485
  tools_count = 57
1486
1486
  try:
1487
1487
  from tzero import tzero_mcp
@@ -1572,10 +1572,13 @@ class DashboardRequestHandler(http.server.BaseHTTPRequestHandler):
1572
1572
  raise ValueError("Invalid null byte in path.")
1573
1573
  ws_root = os.path.realpath(".")
1574
1574
  tmp_root = os.path.realpath(tempfile.gettempdir())
1575
- real_target = os.path.normpath(os.path.realpath(os.path.abspath(candidate)))
1576
- in_ws = (real_target == ws_root) or real_target.startswith(ws_root + os.sep)
1577
- in_tmp = (real_target == tmp_root) or real_target.startswith(tmp_root + os.sep)
1578
- if not in_ws and not in_tmp:
1575
+ resolved = os.path.realpath(os.path.abspath(candidate))
1576
+ base_root = tmp_root if (resolved == tmp_root or resolved.startswith(tmp_root + os.sep)) else ws_root
1577
+ rel = os.path.relpath(resolved, base_root)
1578
+ if rel == ".." or rel.startswith(".." + os.sep) or os.path.isabs(rel):
1579
+ raise ValueError(f"Access denied: path outside allowed workspace or temp scope ({candidate})")
1580
+ real_target = os.path.normpath(os.path.join(base_root, rel))
1581
+ if not real_target.startswith(base_root):
1579
1582
  raise ValueError(f"Access denied: path outside allowed workspace or temp scope ({candidate})")
1580
1583
  return real_target
1581
1584
  """Handles static UI and JSON-RPC API endpoints for T-Zero Dashboard."""
@@ -1832,8 +1835,16 @@ class DashboardRequestHandler(http.server.BaseHTTPRequestHandler):
1832
1835
  content_length = int(self.headers.get("Content-Length", 0))
1833
1836
  body = self.rfile.read(content_length).decode("utf-8")
1834
1837
  try:
1838
+ import tempfile
1835
1839
  payload = json.loads(body) if body.strip() else {}
1836
- target_p = self._resolve_safe_api_path(payload.get("path", "."))
1840
+ raw_debt = self._resolve_safe_api_path(payload.get("path", "."))
1841
+ ws_root = os.path.realpath(".")
1842
+ tmp_root = os.path.realpath(tempfile.gettempdir())
1843
+ base_root = tmp_root if (raw_debt == tmp_root or raw_debt.startswith(tmp_root + os.sep)) else ws_root
1844
+ rel_debt = os.path.relpath(raw_debt, base_root)
1845
+ target_p = os.path.normpath(os.path.join(base_root, rel_debt))
1846
+ if not target_p.startswith(base_root):
1847
+ raise ValueError("Access denied: debt path outside allowed root")
1837
1848
  from tzero.tzero_debt import CodeHealthAnalyzer
1838
1849
  if os.path.isfile(target_p):
1839
1850
  rep = CodeHealthAnalyzer.analyze_file(target_p)
@@ -1931,12 +1942,20 @@ class DashboardRequestHandler(http.server.BaseHTTPRequestHandler):
1931
1942
  self._send_json(resp)
1932
1943
  elif parsed.path == "/api/scip/summary":
1933
1944
  try:
1945
+ import tempfile
1934
1946
  payload = self._read_json_body()
1935
1947
  raw_scip = str(payload.get("path") or "").strip()
1936
1948
  if not raw_scip:
1937
1949
  resp = {"success": False, "error": "SCIP/LSIF index file not found: (empty)"}
1938
1950
  else:
1939
- scip_path = self._resolve_safe_api_path(raw_scip)
1951
+ resolved_scip = self._resolve_safe_api_path(raw_scip)
1952
+ ws_root = os.path.realpath(".")
1953
+ tmp_root = os.path.realpath(tempfile.gettempdir())
1954
+ base_root = tmp_root if (resolved_scip == tmp_root or resolved_scip.startswith(tmp_root + os.sep)) else ws_root
1955
+ rel_scip = os.path.relpath(resolved_scip, base_root)
1956
+ scip_path = os.path.normpath(os.path.join(base_root, rel_scip))
1957
+ if not scip_path.startswith(base_root):
1958
+ raise ValueError("Access denied: SCIP path outside allowed root")
1940
1959
  if not os.path.isfile(scip_path):
1941
1960
  resp = {"success": False, "error": f"SCIP/LSIF index file not found: {raw_scip}"}
1942
1961
  else:
@@ -13,7 +13,7 @@ Capabilities:
13
13
  - 100% Offline, $0 cost, zero cloud dependencies (Python standard library only).
14
14
 
15
15
  Author: Toprak Ahmet Aydoğmuş (Siber Akademi)
16
- Part of T-Zero Context Architect v12.2.0 Master Edition.
16
+ Part of T-Zero Context Architect v12.2.2 Master Edition.
17
17
  """
18
18
 
19
19
  import ast
@@ -214,8 +214,13 @@ class CodeHealthAnalyzer:
214
214
  import tempfile
215
215
  ws_root = os.path.realpath(".")
216
216
  tmp_root = os.path.realpath(tempfile.gettempdir())
217
- real_fp = os.path.normpath(os.path.realpath(os.path.abspath(file_path)))
218
- if not real_fp.startswith(ws_root + os.sep) and not real_fp.startswith(tmp_root + os.sep):
217
+ cand_fp = os.path.realpath(os.path.abspath(file_path))
218
+ base_root = tmp_root if (cand_fp == tmp_root or cand_fp.startswith(tmp_root + os.sep)) else ws_root
219
+ rel_fp = os.path.relpath(cand_fp, base_root)
220
+ if rel_fp == ".." or rel_fp.startswith(".." + os.sep) or os.path.isabs(rel_fp):
221
+ raise ValueError(f"Path outside allowed workspace/temp root: {file_path}")
222
+ real_fp = os.path.normpath(os.path.join(base_root, rel_fp))
223
+ if not real_fp.startswith(base_root):
219
224
  raise ValueError(f"Path outside allowed workspace/temp root: {file_path}")
220
225
  try:
221
226
  with open(real_fp, "r", encoding="utf-8", errors="replace") as f:
@@ -341,7 +346,17 @@ class CodeHealthAnalyzer:
341
346
 
342
347
  @classmethod
343
348
  def analyze_workspace(cls, workspace_root: str = ".", max_files: int = 250) -> WorkspaceHealthReport:
344
- abs_root = os.path.realpath(os.path.abspath(workspace_root))
349
+ import tempfile
350
+ ws_root = os.path.realpath(".")
351
+ tmp_root = os.path.realpath(tempfile.gettempdir())
352
+ cand_root = os.path.realpath(os.path.abspath(workspace_root))
353
+ base_root = tmp_root if (cand_root == tmp_root or cand_root.startswith(tmp_root + os.sep)) else ws_root
354
+ rel_root = os.path.relpath(cand_root, base_root)
355
+ if rel_root == ".." or rel_root.startswith(".." + os.sep) or os.path.isabs(rel_root):
356
+ raise ValueError(f"Workspace path outside allowed scope: {workspace_root}")
357
+ abs_root = os.path.normpath(os.path.join(base_root, rel_root))
358
+ if not abs_root.startswith(base_root):
359
+ raise ValueError(f"Workspace path outside allowed scope: {workspace_root}")
345
360
  reports: List[FileHealthReport] = []
346
361
 
347
362
  ignore_dirs = {".git", ".venv", "venv", "__pycache__", "node_modules", "dist", "build", ".pytest_cache"}
@@ -6,7 +6,7 @@ delivering maximum semantic grounding to LLMs (Claude, GPT, Gemini, DeepSeek) wi
6
6
  up to 95% token savings compared to raw file ingestion.
7
7
 
8
8
  Author: Toprak Ahmet Aydogmus (Siber Akademi)
9
- Version: 11.15.1
9
+ Version: 12.2.2
10
10
  """
11
11
 
12
12
  import ast
@@ -109,6 +109,7 @@ class ChangeImpactAnalyzer:
109
109
  self.symbol_locations: Dict[str, List[str]] = collections.defaultdict(list) # symbol -> [defining_files]
110
110
  self.import_graph: Dict[str, Set[str]] = collections.defaultdict(set) # file -> imported_modules
111
111
  self.inbound_graph: Dict[str, Set[str]] = collections.defaultdict(set) # module -> dependent_files
112
+ self._file_ref_cache: Dict[str, Tuple[Dict[str, Set[int]], Dict[str, Set[int]], Dict[str, Set[int]]]] = {}
112
113
  self._build_index()
113
114
 
114
115
  def _add_symbol_def(self, symbol: str, rel_path: str):
@@ -139,8 +140,7 @@ class ChangeImpactAnalyzer:
139
140
  try:
140
141
  tree = ast.parse(code)
141
142
  self.ast_trees[rel_path] = tree
142
- stem = os.path.splitext(os.path.basename(rel_path))[0]
143
-
143
+
144
144
  for node in tree.body:
145
145
  if isinstance(node, ast.ClassDef):
146
146
  self._add_symbol_def(node.name, rel_path)
@@ -163,6 +163,34 @@ class ChangeImpactAnalyzer:
163
163
  except Exception:
164
164
  pass
165
165
 
166
+ def _get_file_refs(self, rel_path: str, content: str) -> Tuple[Dict[str, Set[int]], Dict[str, Set[int]], Dict[str, Set[int]]]:
167
+ """Builds and caches a per-file AST reference index in a single traversal."""
168
+ cached = self._file_ref_cache.get(rel_path)
169
+ if cached is not None:
170
+ return cached
171
+ tree = self.ast_trees.get(rel_path)
172
+ if tree is None:
173
+ tree = ast.parse(content)
174
+ self.ast_trees[rel_path] = tree
175
+ name_lines: Dict[str, Set[int]] = collections.defaultdict(set)
176
+ call_attr_lines: Dict[str, Set[int]] = collections.defaultdict(set)
177
+ dotted_lines: Dict[str, Set[int]] = collections.defaultdict(set)
178
+ for node in ast.walk(tree):
179
+ if isinstance(node, ast.Call):
180
+ if isinstance(node.func, ast.Attribute):
181
+ lineno = getattr(node, 'lineno', 1)
182
+ call_attr_lines[node.func.attr].add(lineno)
183
+ if isinstance(node.func.value, ast.Name):
184
+ dotted_lines[f"{node.func.value.id}.{node.func.attr}"].add(lineno)
185
+ elif isinstance(node, ast.Attribute):
186
+ if isinstance(node.value, ast.Name):
187
+ dotted_lines[f"{node.value.id}.{node.attr}"].add(getattr(node, 'lineno', 1))
188
+ elif isinstance(node, ast.Name):
189
+ name_lines[node.id].add(getattr(node, 'lineno', 1))
190
+ entry = (name_lines, call_attr_lines, dotted_lines)
191
+ self._file_ref_cache[rel_path] = entry
192
+ return entry
193
+
166
194
  def analyze_symbol(self, symbol_name: str) -> Dict[str, Any]:
167
195
  """Calculates the blast radius for modifying a specific symbol (class/function).
168
196
 
@@ -176,44 +204,30 @@ class ChangeImpactAnalyzer:
176
204
 
177
205
  target_attr = symbol_name.split('.')[-1]
178
206
  target_class = symbol_name.split('.')[0] if '.' in symbol_name else ""
207
+ dotted_key = f"{target_class}.{target_attr}" if target_class else ""
179
208
 
180
209
  for f, content in self.snippets.items():
181
210
  if f in defining_locations or target_attr not in content:
182
211
  continue
183
212
 
184
- matches_lines: List[int] = []
213
+ matches_set: Set[int] = set()
185
214
  try:
186
- tree = self.ast_trees.get(f)
187
- if tree is None:
188
- tree = ast.parse(content)
189
- self.ast_trees[f] = tree
190
- for node in ast.walk(tree):
191
- if isinstance(node, ast.Call):
192
- matched = False
193
- if isinstance(node.func, ast.Name) and node.func.id == target_attr:
194
- matched = True
195
- elif isinstance(node.func, ast.Attribute) and node.func.attr == target_attr:
196
- if target_class:
197
- if isinstance(node.func.value, ast.Name) and node.func.value.id == target_class:
198
- matched = True
199
- else:
200
- matched = True
201
- if matched:
202
- matches_lines.append(getattr(node, 'lineno', 1))
203
- elif isinstance(node, ast.Attribute) and node.attr == target_attr:
204
- if target_class and isinstance(node.value, ast.Name) and node.value.id == target_class:
205
- matches_lines.append(getattr(node, 'lineno', 1))
206
- elif isinstance(node, ast.Name) and node.id == target_attr:
207
- # Direct symbol reference as argument, type annotation, or value
208
- matches_lines.append(getattr(node, 'lineno', 1))
215
+ name_lines, call_attr_lines, dotted_lines = self._get_file_refs(f, content)
216
+ if target_attr in name_lines:
217
+ matches_set.update(name_lines[target_attr])
218
+ if target_class:
219
+ if dotted_key in dotted_lines:
220
+ matches_set.update(dotted_lines[dotted_key])
221
+ else:
222
+ if target_attr in call_attr_lines:
223
+ matches_set.update(call_attr_lines[target_attr])
209
224
  except Exception:
210
225
  # Fallback for non-python files or invalid syntax
211
226
  pattern = rf"\b{re.escape(target_attr)}\b"
212
227
  for m in re.finditer(pattern, content):
213
- line_no = content[:m.start()].count('\n') + 1
214
- matches_lines.append(line_no)
228
+ matches_set.add(content[:m.start()].count('\n') + 1)
215
229
 
216
- unique_lines = sorted(list(set(matches_lines)))
230
+ unique_lines = sorted(matches_set)
217
231
  if unique_lines:
218
232
  direct_callers.append({
219
233
  "file": f,
@@ -239,8 +239,15 @@ class FederationSyncEngine:
239
239
  import tempfile
240
240
  ws_root = os.path.realpath(".")
241
241
  tmp_root = os.path.realpath(tempfile.gettempdir())
242
- safe_scip = os.path.normpath(os.path.realpath(os.path.abspath(scip_path)))
243
- if (safe_scip.startswith(ws_root + os.sep) or safe_scip.startswith(tmp_root + os.sep)) and os.path.isfile(safe_scip):
242
+ cand_scip = os.path.realpath(os.path.abspath(scip_path))
243
+ base_root = tmp_root if (cand_scip == tmp_root or cand_scip.startswith(tmp_root + os.sep)) else ws_root
244
+ rel_scip = os.path.relpath(cand_scip, base_root)
245
+ safe_scip = os.path.normpath(os.path.join(base_root, rel_scip))
246
+ if rel_scip == ".." or rel_scip.startswith(".." + os.sep) or os.path.isabs(rel_scip):
247
+ safe_scip = ""
248
+ elif not safe_scip.startswith(base_root):
249
+ safe_scip = ""
250
+ if safe_scip and os.path.isfile(safe_scip):
244
251
  try:
245
252
  from tzero.tzero_scip import ScipIndexImporter
246
253
  scip_trace = ScipIndexImporter.load(safe_scip).trace_symbol(sym)
@@ -481,6 +481,16 @@ class PCFixerMcpServer:
481
481
 
482
482
  def main():
483
483
  """Main CLI entrypoint for PC-Fixer MCP Server."""
484
+ import argparse
485
+ from tzero import __version__ as tzero_version
486
+
487
+ parser = argparse.ArgumentParser(
488
+ prog="pc-fixer-mcp",
489
+ description="T-Zero PC-Fixer & Codebase Doctor Standalone JSON-RPC 2.0 MCP Server (stdio)",
490
+ )
491
+ parser.add_argument("--version", action="version", version=f"pc-fixer-mcp {tzero_version}")
492
+ parser.parse_args()
493
+
484
494
  server = PCFixerMcpServer()
485
495
  server.run()
486
496
 
@@ -11,7 +11,7 @@ Capabilities:
11
11
  - 100% Offline, $0 cost, zero cloud dependencies (Python standard library only).
12
12
 
13
13
  Author: Toprak Ahmet Aydoğmuş (Siber Akademi)
14
- Part of T-Zero Context Architect v12.2.0 Master Edition.
14
+ Part of T-Zero Context Architect v12.2.2 Master Edition.
15
15
  """
16
16
 
17
17
  import ast
@@ -160,7 +160,17 @@ class ASTGoldenRegressionEngine:
160
160
  @classmethod
161
161
  def generate_baseline(cls, workspace_root: str = ".", max_files: int = 300) -> GoldenBaseline:
162
162
  """Scans workspace and generates the golden contract baseline."""
163
- abs_root = os.path.realpath(os.path.abspath(workspace_root))
163
+ import tempfile
164
+ ws_root = os.path.realpath(".")
165
+ tmp_root = os.path.realpath(tempfile.gettempdir())
166
+ candidate_root = os.path.realpath(os.path.abspath(workspace_root))
167
+ base_root = tmp_root if (candidate_root == tmp_root or candidate_root.startswith(tmp_root + os.sep)) else ws_root
168
+ rel_root = os.path.relpath(candidate_root, base_root)
169
+ if rel_root == ".." or rel_root.startswith(".." + os.sep) or os.path.isabs(rel_root):
170
+ raise ValueError(f"Workspace root outside allowed scope: {workspace_root}")
171
+ abs_root = os.path.normpath(os.path.join(base_root, rel_root))
172
+ if not abs_root.startswith(base_root):
173
+ raise ValueError(f"Workspace root outside allowed scope: {workspace_root}")
164
174
  all_sigs: Dict[str, Dict[str, Any]] = {}
165
175
  hasher = hashlib.sha256()
166
176
 
@@ -171,10 +181,14 @@ class ASTGoldenRegressionEngine:
171
181
  dirs[:] = [d for d in dirs if d not in ignore_dirs and not d.startswith(".")]
172
182
  for f in files:
173
183
  if f.endswith(".py"):
174
- full_p = os.path.realpath(os.path.join(root, f))
175
- if not (full_p == abs_root or full_p.startswith(abs_root + os.sep)):
184
+ resolved_p = os.path.realpath(os.path.join(root, f))
185
+ rel_file = os.path.relpath(resolved_p, abs_root)
186
+ if rel_file == ".." or rel_file.startswith(".." + os.sep) or os.path.isabs(rel_file):
176
187
  continue
177
- rel_p = os.path.relpath(full_p, abs_root).replace("\\", "/")
188
+ full_p = os.path.normpath(os.path.join(abs_root, rel_file))
189
+ if not full_p.startswith(abs_root):
190
+ continue
191
+ rel_p = rel_file.replace("\\", "/")
178
192
  try:
179
193
  with open(full_p, "r", encoding="utf-8", errors="replace") as fp:
180
194
  code = fp.read()
@@ -194,7 +208,7 @@ class ASTGoldenRegressionEngine:
194
208
 
195
209
  return GoldenBaseline(
196
210
  workspace_root=abs_root,
197
- version="12.2.0",
211
+ version="12.2.2",
198
212
  created_at=time.time(),
199
213
  symbols=all_sigs,
200
214
  total_symbols=len(all_sigs),
@@ -212,10 +226,24 @@ class ASTGoldenRegressionEngine:
212
226
  @classmethod
213
227
  def verify_against_golden(cls, workspace_root: str = ".", golden_path: Optional[str] = None) -> Dict[str, Any]:
214
228
  """Compares current working tree AST signatures against the golden baseline."""
215
- abs_root = os.path.realpath(os.path.abspath(workspace_root))
229
+ import tempfile
230
+ ws_root = os.path.realpath(".")
231
+ tmp_root = os.path.realpath(tempfile.gettempdir())
232
+ cand_root = os.path.realpath(os.path.abspath(workspace_root))
233
+ base_root = tmp_root if (cand_root == tmp_root or cand_root.startswith(tmp_root + os.sep)) else ws_root
234
+ rel_ws = os.path.relpath(cand_root, base_root)
235
+ if rel_ws == ".." or rel_ws.startswith(".." + os.sep) or os.path.isabs(rel_ws):
236
+ return {"success": False, "error": "Workspace root outside allowed scope."}
237
+ abs_root = os.path.normpath(os.path.join(base_root, rel_ws))
238
+ if not abs_root.startswith(base_root):
239
+ return {"success": False, "error": "Workspace root outside allowed scope."}
216
240
  raw_g_path = golden_path or os.path.join(abs_root, ".tzero", "goldens.json")
217
- g_path = os.path.realpath(os.path.abspath(raw_g_path))
218
- if not (g_path == abs_root or g_path.startswith(abs_root + os.sep)):
241
+ cand_g = os.path.realpath(os.path.abspath(raw_g_path))
242
+ rel_g = os.path.relpath(cand_g, abs_root)
243
+ if rel_g == ".." or rel_g.startswith(".." + os.sep) or os.path.isabs(rel_g):
244
+ return {"success": False, "error": "Golden path outside workspace root."}
245
+ g_path = os.path.normpath(os.path.join(abs_root, rel_g))
246
+ if not g_path.startswith(abs_root):
219
247
  return {"success": False, "error": "Golden path outside workspace root."}
220
248
 
221
249
  if not os.path.isfile(g_path):