tzero-mcp 10.7.0 → 10.7.1

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 (96) hide show
  1. package/bin/tzero-mcp.js +9 -16
  2. package/bin/tzero.js +9 -16
  3. package/index.js +7 -2
  4. package/package.json +2 -1
  5. package/src/addmcp.py +1194 -0
  6. package/src/main.py +60 -0
  7. package/src/siber_akademi_icon.py +77 -0
  8. package/src/tzero/jarvis/semantic_compressor.py +373 -0
  9. package/src/tzero.py +58 -0
  10. package/src/tzero_benchmark.py +475 -0
  11. package/src/tzero_bridge.py +362 -0
  12. package/src/tzero_ci.py +153 -0
  13. package/src/tzero_commit.py +192 -0
  14. package/src/tzero_cost.py +163 -0
  15. package/src/tzero_dashboard.py +1448 -0
  16. package/src/tzero_deps.py +287 -0
  17. package/src/tzero_drift.py +208 -0
  18. package/src/tzero_explain.py +240 -0
  19. package/src/tzero_features.py +3022 -0
  20. package/src/tzero_fix.py +228 -0
  21. package/src/tzero_fixer/__init__.py +63 -0
  22. package/src/tzero_fixer/amalgamation.py +334 -0
  23. package/src/tzero_fixer/ast_syntax_healer.py +464 -0
  24. package/src/tzero_fixer/ast_type_modernizer.py +288 -0
  25. package/src/tzero_fixer/async_io_modernizer.py +127 -0
  26. package/src/tzero_fixer/automated_regression_suite.py +600 -0
  27. package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
  28. package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
  29. package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
  30. package/src/tzero_fixer/code_smells_healer.py +260 -0
  31. package/src/tzero_fixer/cwe_remediator.py +171 -0
  32. package/src/tzero_fixer/dead_code_eliminator.py +150 -0
  33. package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
  34. package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
  35. package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
  36. package/src/tzero_fixer/import_graph_healer.py +412 -0
  37. package/src/tzero_fixer/interactive_tui.py +91 -0
  38. package/src/tzero_fixer/knowledge_base.py +295 -0
  39. package/src/tzero_fixer/knowledge_base_extended.py +940 -0
  40. package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
  41. package/src/tzero_fixer/mcp_server.py +447 -0
  42. package/src/tzero_fixer/models.py +385 -0
  43. package/src/tzero_fixer/orchestrator.py +375 -0
  44. package/src/tzero_fixer/os_doctor.py +502 -0
  45. package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
  46. package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
  47. package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
  48. package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
  49. package/src/tzero_fixer/polyglot_build_healer.py +364 -0
  50. package/src/tzero_fixer/polyglot_config_healer.py +318 -0
  51. package/src/tzero_fixer/polyglot_doctor.py +372 -0
  52. package/src/tzero_fixer/polyglot_linters.py +619 -0
  53. package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
  54. package/src/tzero_fixer/security_cwe_database.py +444 -0
  55. package/src/tzero_fixer/security_deep_rules.py +114 -0
  56. package/src/tzero_fixer/security_rules_catalog.py +110 -0
  57. package/src/tzero_fixer/security_zero_leak.py +326 -0
  58. package/src/tzero_fixer/smart_patch_recommender.py +223 -0
  59. package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
  60. package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
  61. package/src/tzero_fixer/system_repair_recipes.py +447 -0
  62. package/src/tzero_fixer/venv_doctor.py +309 -0
  63. package/src/tzero_gateway.py +885 -0
  64. package/src/tzero_guard.py +243 -0
  65. package/src/tzero_infra.py +274 -0
  66. package/src/tzero_jarvis/__init__.py +124 -0
  67. package/src/tzero_jarvis/causal_graph.py +310 -0
  68. package/src/tzero_jarvis/graph_visualizer.py +395 -0
  69. package/src/tzero_jarvis/hybrid_search.py +214 -0
  70. package/src/tzero_jarvis/latent_press.py +137 -0
  71. package/src/tzero_jarvis/memory_consolidation.py +212 -0
  72. package/src/tzero_jarvis/minhash_lsh.py +184 -0
  73. package/src/tzero_jarvis/orchestrator.py +335 -0
  74. package/src/tzero_jarvis/self_healing.py +308 -0
  75. package/src/tzero_jarvis/semantic_compressor.py +887 -0
  76. package/src/tzero_jarvis/swarm.py +261 -0
  77. package/src/tzero_jarvis/swarm_bft.py +144 -0
  78. package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
  79. package/src/tzero_jarvis/zero_key_router.py +173 -0
  80. package/src/tzero_mcp.py +4858 -0
  81. package/src/tzero_neural_cortex.py +1425 -0
  82. package/src/tzero_packer.py +370 -0
  83. package/src/tzero_patch.py +624 -0
  84. package/src/tzero_pc_fixer.py +12657 -0
  85. package/src/tzero_pipe.py +95 -0
  86. package/src/tzero_polyglot.py +422 -0
  87. package/src/tzero_reachability.py +272 -0
  88. package/src/tzero_replay.py +141 -0
  89. package/src/tzero_security.py +570 -0
  90. package/src/tzero_snapshot.py +258 -0
  91. package/src/tzero_stubs.py +313 -0
  92. package/src/tzero_superdesign.py +774 -0
  93. package/src/tzero_sync.py +241 -0
  94. package/src/tzero_task_benchmark.py +363 -0
  95. package/src/tzero_tui.py +244 -0
  96. package/src/tzero_v3.py +9435 -0
@@ -0,0 +1,95 @@
1
+ # -*- coding: utf-8 -*-
2
+ """T-Zero CLI Stdin/Stdout Pipeline & Token Streaming Compressor.
3
+
4
+ Enables UNIX pipeline integration (e.g. `cat file.py | tzero --pipe` or `git diff | tzero --pipe`)
5
+ for instant terminal token compression and optional clipboard copy.
6
+
7
+ Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
8
+ Part of T-Zero Context Architect v7.0.0 Master Edition.
9
+ """
10
+
11
+ import sys
12
+ import ast
13
+ import os
14
+ from typing import Optional
15
+
16
+ from tzero_v3 import TokenReducer
17
+
18
+
19
+ class PipeCompressor:
20
+ """Zero-latency streaming pipe compressor for UNIX pipelines and developer CLI tooling."""
21
+
22
+ @classmethod
23
+ def compress_stream(cls, content: str, filename_hint: str = "", tier: str = "T-3") -> str:
24
+ """Compresses streaming code, diff, or schema content using best AST strategy."""
25
+ if not content or not content.strip():
26
+ return ""
27
+
28
+ hint = (filename_hint or "").strip()
29
+ stripped = content.strip()
30
+
31
+ # Map tier to mode (T-3 / T-4 -> ultra, T-2 -> light, T-1 -> full)
32
+ mode = "ultra" if tier in ("T-3", "T-4", "ultra") else "light"
33
+
34
+ # 1. Autodetect unified diffs
35
+ if hint.lower().endswith((".diff", ".patch")) or stripped.startswith(("diff --git", "--- a/", "Index:")):
36
+ reduced, _ = TokenReducer.reduce_content("stream.diff", content, mode=mode)
37
+ return reduced
38
+
39
+ # 2. Known filename hint routing
40
+ if hint:
41
+ reduced, _ = TokenReducer.reduce_content(hint, content, mode=mode)
42
+ return reduced
43
+
44
+ # 3. Content autodetect: try Python AST
45
+ try:
46
+ ast.parse(content)
47
+ reduced, _ = TokenReducer.reduce_content("stream.py", content, mode=mode)
48
+ return reduced
49
+ except Exception:
50
+ pass
51
+
52
+ # 4. Fallback generic token reduction
53
+ reduced, _ = TokenReducer.reduce_content("stream.txt", content, mode=mode)
54
+ return reduced
55
+
56
+ @classmethod
57
+ def run_cli_pipe(cls, filename_hint: str = "", tier: str = "T-3", copy_to_clipboard: bool = False):
58
+ """Reads stdin, compresses content, and writes to stdout / clipboard."""
59
+ try:
60
+ # Safe stdin reading
61
+ if sys.stdin.isatty():
62
+ print("[T-Zero Pipe] Waiting for input from stdin (Ctrl+Z then Enter on Windows, Ctrl+D on Unix)...", file=sys.stderr)
63
+ raw_input = sys.stdin.read()
64
+ except Exception as e:
65
+ print(f"[ERROR] Failed to read from stdin: {e}", file=sys.stderr)
66
+ sys.exit(1)
67
+
68
+ result = cls.compress_stream(raw_input, filename_hint=filename_hint, tier=tier)
69
+
70
+ # Output to stdout
71
+ sys.stdout.write(result)
72
+ sys.stdout.flush()
73
+
74
+ # Optional clipboard copy
75
+ if copy_to_clipboard and result:
76
+ cls._copy_clipboard(result)
77
+
78
+ @staticmethod
79
+ def _copy_clipboard(text: str):
80
+ """Copies text to system clipboard safely using platform tools."""
81
+ try:
82
+ if sys.platform.startswith("win"):
83
+ import subprocess
84
+ p = subprocess.Popen(["clip"], stdin=subprocess.PIPE, shell=True)
85
+ p.communicate(input=text.encode("utf-8"))
86
+ elif sys.platform == "darwin":
87
+ import subprocess
88
+ p = subprocess.Popen(["pbcopy"], stdin=subprocess.PIPE)
89
+ p.communicate(input=text.encode("utf-8"))
90
+ elif sys.platform.startswith("linux"):
91
+ import subprocess
92
+ p = subprocess.Popen(["xclip", "-selection", "clipboard"], stdin=subprocess.PIPE)
93
+ p.communicate(input=text.encode("utf-8"))
94
+ except Exception:
95
+ pass
@@ -0,0 +1,422 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Siber Akademi T-Zero — Universal Polyglot AST Engine.
3
+
4
+ Provides zero-dependency, deterministic structural parsing and signature extraction
5
+ for Python, TypeScript/JavaScript, Rust, Go, C/C++, Java/C#, and Solidity.
6
+ Prunes function/method bodies, loops, and implementation details down to signatures,
7
+ interfaces, structs, and declarations with up to 95% context token reduction.
8
+
9
+ Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
10
+ License: MIT
11
+ """
12
+
13
+ import re
14
+ from typing import Dict, List, Tuple, Optional
15
+
16
+
17
+ class PolyglotTokenReducer:
18
+ """Universal multi-language structural signature extractor."""
19
+
20
+ SUPPORTED_LANGUAGES = {
21
+ "python": [".py", ".pyw"],
22
+ "javascript": [".js", ".jsx", ".mjs", ".cjs"],
23
+ "typescript": [".ts", ".tsx"],
24
+ "rust": [".rs"],
25
+ "go": [".go"],
26
+ "cpp": [".c", ".cpp", ".cc", ".cxx", ".h", ".hpp", ".hxx"],
27
+ "java": [".java", ".cs"],
28
+ "solidity": [".sol"],
29
+ "ruby": [".rb", ".rake", ".gemspec"],
30
+ "php": [".php", ".phtml"],
31
+ "swift": [".swift"],
32
+ "kotlin": [".kt", ".kts"],
33
+ "dart": [".dart"],
34
+ "scala": [".scala", ".sc"],
35
+ "elixir": [".ex", ".exs"]
36
+ }
37
+
38
+ @classmethod
39
+ def detect_language(cls, filename: str) -> Optional[str]:
40
+ """Detect language from filename extension."""
41
+ ext = "." + filename.rsplit(".", 1)[-1].lower() if "." in filename else ""
42
+ for lang, exts in cls.SUPPORTED_LANGUAGES.items():
43
+ if ext in exts:
44
+ return lang
45
+ return None
46
+
47
+ @classmethod
48
+ def reduce_code(cls, content: str, filename: str = "", mode: str = "ultra") -> str:
49
+ """Prunes code content to its structural signatures based on detected language."""
50
+ lang = cls.detect_language(filename)
51
+ if not lang or mode == "none":
52
+ return content
53
+
54
+ if lang == "python":
55
+ return cls.reduce_python(content, mode)
56
+ elif lang in ("javascript", "typescript"):
57
+ return cls.reduce_javascript(content, mode)
58
+ elif lang == "rust":
59
+ return cls.reduce_rust(content, mode)
60
+ elif lang == "go":
61
+ return cls.reduce_go(content, mode)
62
+ elif lang == "cpp":
63
+ return cls.reduce_cpp(content, mode)
64
+ elif lang == "java":
65
+ return cls.reduce_java(content, mode)
66
+ elif lang == "solidity":
67
+ return cls.reduce_solidity(content, mode)
68
+ elif lang == "ruby":
69
+ return cls.reduce_ruby(content, mode)
70
+ elif lang == "php":
71
+ return cls.reduce_php(content, mode)
72
+ elif lang == "swift":
73
+ return cls.reduce_swift(content, mode)
74
+ elif lang == "kotlin":
75
+ return cls.reduce_kotlin(content, mode)
76
+ elif lang == "dart":
77
+ return cls.reduce_dart(content, mode)
78
+ elif lang == "scala":
79
+ return cls.reduce_scala(content, mode)
80
+ elif lang == "elixir":
81
+ return cls.reduce_elixir(content, mode)
82
+ return content
83
+
84
+ @staticmethod
85
+ def reduce_python(content: str, mode: str = "ultra") -> str:
86
+ """Reduces Python source to imports, class/func headers, and ellipses."""
87
+ lines = content.splitlines()
88
+ pruned: List[str] = []
89
+ in_docstring = False
90
+
91
+ for line in lines:
92
+ stripped = line.strip()
93
+ # Handle multiline docstrings
94
+ if stripped.startswith('"""') or stripped.startswith("'''"):
95
+ if stripped.count('"""') == 1 or stripped.count("'''") == 1:
96
+ in_docstring = not in_docstring
97
+ continue
98
+ if in_docstring:
99
+ continue
100
+
101
+ if (stripped.startswith("import ") or stripped.startswith("from ") or
102
+ stripped.startswith("def ") or stripped.startswith("async def ") or
103
+ stripped.startswith("class ") or stripped.startswith("@")):
104
+ indent = len(line) - len(line.lstrip())
105
+ if (stripped.startswith("def ") or stripped.startswith("async def ")) and not stripped.endswith("..."):
106
+ if stripped.endswith(":"):
107
+ pruned.append(f"{line[:-1]}: ...")
108
+ else:
109
+ pruned.append(f"{line} ...")
110
+ else:
111
+ pruned.append(line)
112
+
113
+ return "\n".join(pruned) if pruned else content
114
+
115
+ @staticmethod
116
+ def reduce_javascript(content: str, mode: str = "ultra") -> str:
117
+ """Reduces JavaScript/TypeScript source to imports, interfaces, types, and function signatures."""
118
+ lines = content.splitlines()
119
+ pruned: List[str] = []
120
+ in_multiline_import = False
121
+ in_interface_or_type = False
122
+ in_block_comment = False
123
+
124
+ for line in lines:
125
+ stripped = line.strip()
126
+ if not stripped:
127
+ continue
128
+
129
+ # Multi-line comment tracking
130
+ if in_block_comment:
131
+ if "*/" in stripped:
132
+ in_block_comment = False
133
+ continue
134
+ if stripped.startswith("/*") and not stripped.endswith("*/"):
135
+ in_block_comment = True
136
+ continue
137
+ if stripped.startswith("//"):
138
+ continue
139
+
140
+ # Multi-line imports
141
+ if in_multiline_import:
142
+ pruned.append(line)
143
+ if "}" in stripped or ";" in stripped:
144
+ in_multiline_import = False
145
+ continue
146
+
147
+ if stripped.startswith("import ") and "{" in stripped and "}" not in stripped:
148
+ in_multiline_import = True
149
+ pruned.append(line)
150
+ continue
151
+
152
+ # Interfaces and Type declarations (keep interface definitions and fields)
153
+ if re.match(r"^(export\s+)?(interface|type)\s+[A-Za-z0-9_]+", stripped):
154
+ pruned.append(line)
155
+ if "{" in stripped and "}" not in stripped:
156
+ in_interface_or_type = True
157
+ continue
158
+
159
+ if in_interface_or_type:
160
+ pruned.append(line)
161
+ if "}" in stripped:
162
+ in_interface_or_type = False
163
+ continue
164
+
165
+ # Function declarations, arrow functions, classes
166
+ if (stripped.startswith("import ") or stripped.startswith("export ") or
167
+ stripped.startswith("class ") or stripped.startswith("function ") or
168
+ stripped.startswith("async function ") or
169
+ (stripped.startswith("const ") and "=>" in stripped) or
170
+ (stripped.startswith("let ") and "=>" in stripped)):
171
+ if "{" in stripped and "}" not in stripped:
172
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
173
+ elif stripped.endswith("{"):
174
+ pruned.append(f"{line[:-1]}{{ ... }}")
175
+ else:
176
+ pruned.append(line)
177
+ return "\n".join(pruned) if pruned else content
178
+
179
+ @staticmethod
180
+ def reduce_rust(content: str, mode: str = "ultra") -> str:
181
+ """Reduces Rust source code to use statements, traits, structs, enums, and fn signatures."""
182
+ lines = content.splitlines()
183
+ pruned: List[str] = []
184
+ for line in lines:
185
+ stripped = line.strip()
186
+ is_fn = bool(re.match(r'^(pub(\([^)]+\))?\s+)?(async\s+)?(unsafe\s+)?fn\s+', stripped))
187
+ if (stripped.startswith("use ") or stripped.startswith("pub use ") or
188
+ is_fn or
189
+ stripped.startswith("pub struct ") or stripped.startswith("struct ") or
190
+ stripped.startswith("pub enum ") or stripped.startswith("enum ") or
191
+ stripped.startswith("pub trait ") or stripped.startswith("trait ") or
192
+ stripped.startswith("impl ") or stripped.startswith("#[") or
193
+ stripped.startswith("pub const ") or stripped.startswith("pub type ") or
194
+ stripped.startswith("const ") or stripped.startswith("type ")):
195
+ if "{" in stripped and not stripped.endswith("}"):
196
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
197
+ elif stripped.endswith(";"):
198
+ pruned.append(line)
199
+ elif stripped.endswith("{"):
200
+ pruned.append(f"{line[:-1]}{{ ... }}")
201
+ else:
202
+ pruned.append(line)
203
+ return "\n".join(pruned) if pruned else content
204
+
205
+ @staticmethod
206
+ def reduce_go(content: str, mode: str = "ultra") -> str:
207
+ """Reduces Go source code to package, imports, types, interfaces, and func signatures."""
208
+ lines = content.splitlines()
209
+ pruned: List[str] = []
210
+ for line in lines:
211
+ stripped = line.strip()
212
+ if (stripped.startswith("package ") or stripped.startswith("import ") or
213
+ stripped.startswith("type ") or stripped.startswith("func ") or
214
+ stripped.startswith("var ") or stripped.startswith("const ")):
215
+ if stripped.startswith("func ") and "{" in stripped:
216
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
217
+ else:
218
+ pruned.append(line)
219
+ return "\n".join(pruned) if pruned else content
220
+
221
+ @staticmethod
222
+ def reduce_cpp(content: str, mode: str = "ultra") -> str:
223
+ """Reduces C/C++ source code to headers, classes, structs, templates, and prototypes."""
224
+ lines = content.splitlines()
225
+ pruned: List[str] = []
226
+ for line in lines:
227
+ stripped = line.strip()
228
+ if (stripped.startswith("#include") or stripped.startswith("#define") or
229
+ stripped.startswith("template") or stripped.startswith("class ") or
230
+ stripped.startswith("struct ") or stripped.startswith("namespace ") or
231
+ stripped.startswith("using ") or stripped.startswith("typedef ") or
232
+ re.match(r'^(?:virtual\s+|static\s+|inline\s+)?[\w:<>]+\s+[\w:]+\s*\([^;]*\)\s*(?:const)?\s*\{?$', stripped)):
233
+ if "{" in stripped:
234
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
235
+ elif not stripped.endswith(";") and not stripped.startswith("#") and not stripped.startswith("namespace"):
236
+ pruned.append(f"{line};")
237
+ else:
238
+ pruned.append(line)
239
+ return "\n".join(pruned) if pruned else content
240
+
241
+ @staticmethod
242
+ def reduce_java(content: str, mode: str = "ultra") -> str:
243
+ """Reduces Java/C# source code to packages, imports, classes, interfaces, records, and method signatures."""
244
+ lines = content.splitlines()
245
+ pruned: List[str] = []
246
+ for line in lines:
247
+ stripped = line.strip()
248
+ if (stripped.startswith("package ") or stripped.startswith("import ") or
249
+ stripped.startswith("using ") or stripped.startswith("namespace ") or
250
+ "class " in stripped or "interface " in stripped or "record " in stripped or
251
+ "enum " in stripped or re.match(r'^\s*(?:public|private|protected|static|final|abstract|async)\s+.*\(.*\)', stripped)):
252
+ if "{" in stripped:
253
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
254
+ elif not stripped.endswith(";") and not stripped.startswith("package") and not stripped.startswith("import"):
255
+ pruned.append(f"{line} { ... }")
256
+ else:
257
+ pruned.append(line)
258
+ return "\n".join(pruned) if pruned else content
259
+
260
+ @staticmethod
261
+ def reduce_solidity(content: str, mode: str = "ultra") -> str:
262
+ """Reduces Solidity smart contracts to pragma, interfaces, contracts, structs, events, and function headers."""
263
+ lines = content.splitlines()
264
+ pruned: List[str] = []
265
+ for line in lines:
266
+ stripped = line.strip()
267
+ if (stripped.startswith("pragma ") or stripped.startswith("import ") or
268
+ stripped.startswith("contract ") or stripped.startswith("interface ") or
269
+ stripped.startswith("library ") or stripped.startswith("struct ") or
270
+ stripped.startswith("event ") or stripped.startswith("modifier ") or
271
+ stripped.startswith("function ") or stripped.startswith("mapping(")):
272
+ if "{" in stripped and not stripped.endswith("}"):
273
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
274
+ elif stripped.startswith("function ") and not stripped.endswith(";"):
275
+ pruned.append(f"{line};")
276
+ else:
277
+ pruned.append(line)
278
+ return "\n".join(pruned) if pruned else content
279
+
280
+ @staticmethod
281
+ def reduce_ruby(content: str, mode: str = "ultra") -> str:
282
+ """Reduces Ruby source code to module/class declarations, requires, mixins, and method signatures."""
283
+ lines = content.splitlines()
284
+ pruned: List[str] = []
285
+ for line in lines:
286
+ stripped = line.strip()
287
+ if (stripped.startswith("require ") or stripped.startswith("require_relative ") or
288
+ stripped.startswith("module ") or stripped.startswith("class ") or
289
+ stripped.startswith("def ") or stripped.startswith("attr_") or
290
+ stripped.startswith("include ") or stripped.startswith("extend ") or
291
+ stripped.startswith("has_many ") or stripped.startswith("belongs_to ") or
292
+ stripped in ("private", "protected", "public")):
293
+ if stripped.startswith("def ") and not stripped.endswith("end"):
294
+ pruned.append(f"{line}; ...; end")
295
+ else:
296
+ pruned.append(line)
297
+ return "\n".join(pruned) if pruned else content
298
+
299
+ @staticmethod
300
+ def reduce_php(content: str, mode: str = "ultra") -> str:
301
+ """Reduces PHP source code to namespace, imports, classes, interfaces, traits, and method signatures."""
302
+ lines = content.splitlines()
303
+ pruned: List[str] = []
304
+ for line in lines:
305
+ stripped = line.strip()
306
+ if (stripped.startswith("<?php") or stripped.startswith("namespace ") or
307
+ stripped.startswith("use ") or "class " in stripped or
308
+ "interface " in stripped or "trait " in stripped or "enum " in stripped or
309
+ "function " in stripped):
310
+ if "{" in stripped:
311
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
312
+ elif "function " in stripped and not stripped.endswith(";"):
313
+ pruned.append(f"{line} {{ ... }}")
314
+ else:
315
+ pruned.append(line)
316
+ return "\n".join(pruned) if pruned else content
317
+
318
+ @staticmethod
319
+ def reduce_swift(content: str, mode: str = "ultra") -> str:
320
+ """Reduces Swift source code to imports, protocols, classes, structs, enums, extensions, and func signatures."""
321
+ lines = content.splitlines()
322
+ pruned: List[str] = []
323
+ for line in lines:
324
+ stripped = line.strip()
325
+ if (stripped.startswith("import ") or stripped.startswith("protocol ") or
326
+ "class " in stripped or "struct " in stripped or "enum " in stripped or
327
+ "extension " in stripped or "func " in stripped or stripped.startswith("init(")):
328
+ if "{" in stripped:
329
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
330
+ elif not stripped.endswith(";"):
331
+ pruned.append(f"{line} {{ ... }}")
332
+ else:
333
+ pruned.append(line)
334
+ return "\n".join(pruned) if pruned else content
335
+
336
+ @staticmethod
337
+ def reduce_kotlin(content: str, mode: str = "ultra") -> str:
338
+ """Reduces Kotlin source code to package, imports, classes, interfaces, objects, and function headers."""
339
+ lines = content.splitlines()
340
+ pruned: List[str] = []
341
+ for line in lines:
342
+ stripped = line.strip()
343
+ if (stripped.startswith("package ") or stripped.startswith("import ") or
344
+ "class " in stripped or "interface " in stripped or "object " in stripped or
345
+ stripped.startswith("fun ") or " fun " in stripped):
346
+ if "{" in stripped:
347
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
348
+ elif not stripped.endswith(";"):
349
+ pruned.append(f"{line} {{ ... }}")
350
+ else:
351
+ pruned.append(line)
352
+ return "\n".join(pruned) if pruned else content
353
+
354
+ @staticmethod
355
+ def reduce_dart(content: str, mode: str = "ultra") -> str:
356
+ """Reduces Dart source code to imports, exports, classes, mixins, enums, and method signatures."""
357
+ lines = content.splitlines()
358
+ pruned: List[str] = []
359
+ for line in lines:
360
+ stripped = line.strip()
361
+ if not stripped or stripped.startswith("//") or stripped.startswith("/*"):
362
+ continue
363
+ if stripped.startswith(("return ", "return;", "if ", "if(", "for ", "for(", "while ", "while(", "switch ", "throw ", "print(")):
364
+ continue
365
+ if (stripped.startswith("import ") or stripped.startswith("export ") or
366
+ stripped.startswith("part ") or "class " in stripped or
367
+ "mixin " in stripped or "enum " in stripped or "extension " in stripped or
368
+ re.match(r'^\s*(?:@\w+\s+)*(?:static\s+|async\s+)?[\w<>,]+\s+\w+\s*\(.*?\)', stripped)):
369
+ if "{" in stripped and not ("class " in stripped or "mixin " in stripped):
370
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
371
+ elif not stripped.endswith(";") and not stripped.endswith("{"):
372
+ pruned.append(f"{line} {{ ... }}")
373
+ else:
374
+ pruned.append(line)
375
+ return "\n".join(pruned) if pruned else content
376
+
377
+ @staticmethod
378
+ def reduce_scala(content: str, mode: str = "ultra") -> str:
379
+ """Reduces Scala source code to packages, imports, traits, objects, classes, and def headers."""
380
+ lines = content.splitlines()
381
+ pruned: List[str] = []
382
+ for line in lines:
383
+ stripped = line.strip()
384
+ if not stripped or stripped.startswith("//") or stripped.startswith("/*"):
385
+ continue
386
+ if (stripped.startswith("package ") or stripped.startswith("import ") or
387
+ "class " in stripped or "trait " in stripped or "object " in stripped or
388
+ "enum " in stripped or stripped.startswith("def ") or " def " in stripped):
389
+ if "{" in stripped and not ("class " in stripped or "trait " in stripped or "object " in stripped):
390
+ pruned.append(re.sub(r'\{.*$', '{ ... }', line))
391
+ elif not stripped.endswith(";") and not stripped.endswith("{"):
392
+ pruned.append(f"{line} {{ ... }}")
393
+ else:
394
+ pruned.append(line)
395
+ return "\n".join(pruned) if pruned else content
396
+
397
+ @staticmethod
398
+ def reduce_elixir(content: str, mode: str = "ultra") -> str:
399
+ """Reduces Elixir source code to module headers, structs, specs, and function signatures."""
400
+ lines = content.splitlines()
401
+ pruned: List[str] = []
402
+ for line in lines:
403
+ stripped = line.strip()
404
+ if not stripped or stripped.startswith("#"):
405
+ continue
406
+ if (stripped.startswith("defmodule ") or stripped.startswith("defstruct ") or
407
+ stripped.startswith("alias ") or stripped.startswith("import ") or
408
+ stripped.startswith("require ") or stripped.startswith("use ") or
409
+ stripped.startswith("@type ") or stripped.startswith("@spec ") or
410
+ stripped.startswith("def ") or stripped.startswith("defp ") or
411
+ stripped.startswith("defmacro ")):
412
+ if stripped.startswith("defmodule "):
413
+ pruned.append(line)
414
+ elif ", do:" in stripped:
415
+ pruned.append(re.sub(r', do:.*$', ', do: ...', line))
416
+ elif stripped.endswith(" do"):
417
+ pruned.append(re.sub(r'\s+do$', ', do: ...', line))
418
+ else:
419
+ pruned.append(line)
420
+ return "\n".join(pruned) if pruned else content
421
+
422
+