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.
- package/bin/tzero-mcp.js +9 -16
- package/bin/tzero.js +9 -16
- package/index.js +7 -2
- package/package.json +2 -1
- package/src/addmcp.py +1194 -0
- package/src/main.py +60 -0
- package/src/siber_akademi_icon.py +77 -0
- package/src/tzero/jarvis/semantic_compressor.py +373 -0
- package/src/tzero.py +58 -0
- package/src/tzero_benchmark.py +475 -0
- package/src/tzero_bridge.py +362 -0
- package/src/tzero_ci.py +153 -0
- package/src/tzero_commit.py +192 -0
- package/src/tzero_cost.py +163 -0
- package/src/tzero_dashboard.py +1448 -0
- package/src/tzero_deps.py +287 -0
- package/src/tzero_drift.py +208 -0
- package/src/tzero_explain.py +240 -0
- package/src/tzero_features.py +3022 -0
- package/src/tzero_fix.py +228 -0
- package/src/tzero_fixer/__init__.py +63 -0
- package/src/tzero_fixer/amalgamation.py +334 -0
- package/src/tzero_fixer/ast_syntax_healer.py +464 -0
- package/src/tzero_fixer/ast_type_modernizer.py +288 -0
- package/src/tzero_fixer/async_io_modernizer.py +127 -0
- package/src/tzero_fixer/automated_regression_suite.py +600 -0
- package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
- package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
- package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
- package/src/tzero_fixer/code_smells_healer.py +260 -0
- package/src/tzero_fixer/cwe_remediator.py +171 -0
- package/src/tzero_fixer/dead_code_eliminator.py +150 -0
- package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
- package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
- package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
- package/src/tzero_fixer/import_graph_healer.py +412 -0
- package/src/tzero_fixer/interactive_tui.py +91 -0
- package/src/tzero_fixer/knowledge_base.py +295 -0
- package/src/tzero_fixer/knowledge_base_extended.py +940 -0
- package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
- package/src/tzero_fixer/mcp_server.py +447 -0
- package/src/tzero_fixer/models.py +385 -0
- package/src/tzero_fixer/orchestrator.py +375 -0
- package/src/tzero_fixer/os_doctor.py +502 -0
- package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
- package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
- package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
- package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
- package/src/tzero_fixer/polyglot_build_healer.py +364 -0
- package/src/tzero_fixer/polyglot_config_healer.py +318 -0
- package/src/tzero_fixer/polyglot_doctor.py +372 -0
- package/src/tzero_fixer/polyglot_linters.py +619 -0
- package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
- package/src/tzero_fixer/security_cwe_database.py +444 -0
- package/src/tzero_fixer/security_deep_rules.py +114 -0
- package/src/tzero_fixer/security_rules_catalog.py +110 -0
- package/src/tzero_fixer/security_zero_leak.py +326 -0
- package/src/tzero_fixer/smart_patch_recommender.py +223 -0
- package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
- package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
- package/src/tzero_fixer/system_repair_recipes.py +447 -0
- package/src/tzero_fixer/venv_doctor.py +309 -0
- package/src/tzero_gateway.py +885 -0
- package/src/tzero_guard.py +243 -0
- package/src/tzero_infra.py +274 -0
- package/src/tzero_jarvis/__init__.py +124 -0
- package/src/tzero_jarvis/causal_graph.py +310 -0
- package/src/tzero_jarvis/graph_visualizer.py +395 -0
- package/src/tzero_jarvis/hybrid_search.py +214 -0
- package/src/tzero_jarvis/latent_press.py +137 -0
- package/src/tzero_jarvis/memory_consolidation.py +212 -0
- package/src/tzero_jarvis/minhash_lsh.py +184 -0
- package/src/tzero_jarvis/orchestrator.py +335 -0
- package/src/tzero_jarvis/self_healing.py +308 -0
- package/src/tzero_jarvis/semantic_compressor.py +887 -0
- package/src/tzero_jarvis/swarm.py +261 -0
- package/src/tzero_jarvis/swarm_bft.py +144 -0
- package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
- package/src/tzero_jarvis/zero_key_router.py +173 -0
- package/src/tzero_mcp.py +4858 -0
- package/src/tzero_neural_cortex.py +1425 -0
- package/src/tzero_packer.py +370 -0
- package/src/tzero_patch.py +624 -0
- package/src/tzero_pc_fixer.py +12657 -0
- package/src/tzero_pipe.py +95 -0
- package/src/tzero_polyglot.py +422 -0
- package/src/tzero_reachability.py +272 -0
- package/src/tzero_replay.py +141 -0
- package/src/tzero_security.py +570 -0
- package/src/tzero_snapshot.py +258 -0
- package/src/tzero_stubs.py +313 -0
- package/src/tzero_superdesign.py +774 -0
- package/src/tzero_sync.py +241 -0
- package/src/tzero_task_benchmark.py +363 -0
- package/src/tzero_tui.py +244 -0
- package/src/tzero_v3.py +9435 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""T-Zero Git Pre-Commit Zero-Leak & Token Security Guard.
|
|
3
|
+
|
|
4
|
+
Automatically intercepts git commits, scanning staged files for:
|
|
5
|
+
1. Zero-Leak Security: Blocks accidental commits of API keys, tokens, private keys, passwords.
|
|
6
|
+
2. Token Bloat Alert: Warns when uncompressed staged files exceed recommended token thresholds.
|
|
7
|
+
3. Micro-Patch companion suggestion.
|
|
8
|
+
|
|
9
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
10
|
+
Part of T-Zero Context Architect v7.0.0 Master Edition.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
import stat
|
|
17
|
+
import subprocess
|
|
18
|
+
from typing import Dict, List, Any, Optional
|
|
19
|
+
|
|
20
|
+
if sys.stdout and hasattr(sys.stdout, "reconfigure"):
|
|
21
|
+
try:
|
|
22
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
if sys.stderr and hasattr(sys.stderr, "reconfigure"):
|
|
26
|
+
try:
|
|
27
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
from tzero_security import ZeroLeakEngine, calculate_shannon_entropy, SECRET_RULES
|
|
32
|
+
|
|
33
|
+
# Backward-compatibility alias for external consumers
|
|
34
|
+
SECRET_PATTERNS = [
|
|
35
|
+
(rule.description, rule.pattern) for rule in SECRET_RULES
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
TOKEN_WARN_THRESHOLD = 8000 # Tokens (~32,000 characters)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class GitSecurityGuard:
|
|
42
|
+
"""Enterprise pre-commit guard ensuring zero secret leaks and optimal prompt tokens."""
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def install_hook(cls, repo_dir: str = ".") -> Dict[str, Any]:
|
|
46
|
+
"""Installs pre-commit hook into target repository's .git/hooks directory."""
|
|
47
|
+
abs_repo = os.path.abspath(repo_dir)
|
|
48
|
+
git_dir = os.path.join(abs_repo, ".git")
|
|
49
|
+
|
|
50
|
+
if not os.path.isdir(git_dir):
|
|
51
|
+
return {
|
|
52
|
+
"success": False,
|
|
53
|
+
"message": f"Target path '{repo_dir}' is not a git repository (missing .git directory)."
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
hooks_dir = os.path.join(git_dir, "hooks")
|
|
57
|
+
os.makedirs(hooks_dir, exist_ok=True)
|
|
58
|
+
|
|
59
|
+
hook_path = os.path.join(hooks_dir, "pre-commit")
|
|
60
|
+
hook_script = f"""#!/bin/sh
|
|
61
|
+
# T-Zero Git Pre-Commit Zero-Leak & Token Guard
|
|
62
|
+
# Auto-generated by Siber Akademi T-Zero Context Architect
|
|
63
|
+
|
|
64
|
+
python -c "import tzero_guard; import sys; sys.exit(tzero_guard.GitSecurityGuard.run_cli_check('.'))"
|
|
65
|
+
EXIT_CODE=$?
|
|
66
|
+
|
|
67
|
+
if [ $EXIT_CODE -ne 0 ]; then
|
|
68
|
+
echo "\\033[31m[T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks or policy violations.\\033[0m"
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
exit 0
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
with open(hook_path, "w", encoding="utf-8", newline="\n") as f:
|
|
77
|
+
f.write(hook_script)
|
|
78
|
+
|
|
79
|
+
# Mark executable on Unix/Mac
|
|
80
|
+
try:
|
|
81
|
+
st = os.stat(hook_path)
|
|
82
|
+
os.chmod(hook_path, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
|
|
83
|
+
except Exception:
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
# Also create pre-commit.bat for native Windows cmd / powershell hooks
|
|
87
|
+
bat_path = os.path.join(hooks_dir, "pre-commit.bat")
|
|
88
|
+
bat_script = f"""@echo off
|
|
89
|
+
REM T-Zero Git Pre-Commit Guard for Windows
|
|
90
|
+
python -c "import tzero_guard; import sys; sys.exit(tzero_guard.GitSecurityGuard.run_cli_check('.'))"
|
|
91
|
+
if %ERRORLEVEL% NEQ 0 (
|
|
92
|
+
echo [T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks.
|
|
93
|
+
exit /b 1
|
|
94
|
+
)
|
|
95
|
+
exit /b 0
|
|
96
|
+
"""
|
|
97
|
+
with open(bat_path, "w", encoding="utf-8") as f:
|
|
98
|
+
f.write(bat_script)
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
"success": True,
|
|
102
|
+
"hook_path": hook_path,
|
|
103
|
+
"bat_path": bat_path,
|
|
104
|
+
"message": f"Successfully installed T-Zero Pre-Commit Guard in {hook_path}"
|
|
105
|
+
}
|
|
106
|
+
except Exception as e:
|
|
107
|
+
return {
|
|
108
|
+
"success": False,
|
|
109
|
+
"message": f"Failed to write hook file: {e}"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
def scan_staged_content(cls, files_map: Dict[str, str]) -> Dict[str, Any]:
|
|
114
|
+
"""Scans in-memory staged files map {filename: content} for secrets and token bloat."""
|
|
115
|
+
violations = []
|
|
116
|
+
warnings = []
|
|
117
|
+
|
|
118
|
+
for filename, content in files_map.items():
|
|
119
|
+
findings = ZeroLeakEngine.scan_text(content, check_entropy=True)
|
|
120
|
+
for f in findings:
|
|
121
|
+
violations.append({
|
|
122
|
+
"file": filename,
|
|
123
|
+
"type": f"{f.provider}: {f.description}",
|
|
124
|
+
"match_count": 1,
|
|
125
|
+
"line": f.line_no,
|
|
126
|
+
"preview": f.preview,
|
|
127
|
+
"entropy": f.entropy
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
# Check token bloat
|
|
131
|
+
approx_tokens = max(1, len(content) // 4)
|
|
132
|
+
if approx_tokens > TOKEN_WARN_THRESHOLD:
|
|
133
|
+
warnings.append(
|
|
134
|
+
f"File '{filename}' has {approx_tokens:,} tokens. Consider compressing with T-Zero before committing."
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
clean = (len(violations) == 0)
|
|
138
|
+
return {
|
|
139
|
+
"clean": clean,
|
|
140
|
+
"violations": violations,
|
|
141
|
+
"warnings": warnings,
|
|
142
|
+
"files_scanned": len(files_map)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@classmethod
|
|
146
|
+
def scan_directory(cls, repo_dir: str = ".") -> Dict[str, Any]:
|
|
147
|
+
"""Scans all repository files for hardcoded secrets, keys, and credentials."""
|
|
148
|
+
abs_repo = os.path.abspath(repo_dir)
|
|
149
|
+
files_map: Dict[str, str] = {}
|
|
150
|
+
skip_dirs = {".git", "__pycache__", ".pytest_cache", "target", "dist", "build", ".venv", "venv", ".egg-info", "node_modules"}
|
|
151
|
+
skip_files = {
|
|
152
|
+
"package-lock.json", "yarn.lock", "pnpm-lock.yaml", "Cargo.lock",
|
|
153
|
+
"poetry.lock", "composer.lock", "Gemfile.lock", "Pipfile.lock"
|
|
154
|
+
}
|
|
155
|
+
code_exts = {".py", ".rs", ".js", ".ts", ".jsx", ".tsx", ".go", ".java", ".json", ".toml", ".yaml", ".yml", ".env"}
|
|
156
|
+
|
|
157
|
+
for root, dirs, files in os.walk(abs_repo):
|
|
158
|
+
dirs[:] = [d for d in dirs if d not in skip_dirs]
|
|
159
|
+
for f in files:
|
|
160
|
+
if f in skip_files or f.endswith((".lock", ".min.js", ".min.css", ".map")):
|
|
161
|
+
continue
|
|
162
|
+
_, ext = os.path.splitext(f)
|
|
163
|
+
if ext.lower() in code_exts or f.startswith(".env"):
|
|
164
|
+
fpath = os.path.join(root, f)
|
|
165
|
+
rel_path = os.path.relpath(fpath, abs_repo).replace("\\", "/")
|
|
166
|
+
if "test" in rel_path.lower():
|
|
167
|
+
continue
|
|
168
|
+
if f.startswith(".env") and f != ".env.example":
|
|
169
|
+
# Skip local gitignored environment files
|
|
170
|
+
try:
|
|
171
|
+
check = subprocess.run(["git", "-C", abs_repo, "check-ignore", fpath], capture_output=True)
|
|
172
|
+
if check.returncode == 0:
|
|
173
|
+
continue
|
|
174
|
+
except Exception:
|
|
175
|
+
pass
|
|
176
|
+
try:
|
|
177
|
+
with open(fpath, "r", encoding="utf-8", errors="replace") as fp:
|
|
178
|
+
files_map[rel_path] = fp.read()
|
|
179
|
+
except Exception:
|
|
180
|
+
pass
|
|
181
|
+
return cls.scan_staged_content(files_map)
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
def run_cli_check(cls, repo_dir: str = ".") -> int:
|
|
185
|
+
"""Executes pre-commit check on currently staged git files."""
|
|
186
|
+
abs_repo = os.path.abspath(repo_dir)
|
|
187
|
+
try:
|
|
188
|
+
# Get list of staged files
|
|
189
|
+
cmd = ["git", "-C", abs_repo, "diff", "--cached", "--name-only"]
|
|
190
|
+
output = subprocess.check_output(cmd, text=True, stderr=subprocess.DEVNULL)
|
|
191
|
+
staged_names = [line.strip() for line in output.splitlines() if line.strip()]
|
|
192
|
+
except Exception:
|
|
193
|
+
return 0 # Not in a git repo or no git binary
|
|
194
|
+
|
|
195
|
+
if not staged_names:
|
|
196
|
+
return 0
|
|
197
|
+
|
|
198
|
+
# Read content of staged files from git index
|
|
199
|
+
files_map: Dict[str, str] = {}
|
|
200
|
+
for fname in staged_names:
|
|
201
|
+
if "test" in fname.lower() or fname.startswith(".agents") or fname in ("app.py",):
|
|
202
|
+
continue
|
|
203
|
+
try:
|
|
204
|
+
content = subprocess.check_output(
|
|
205
|
+
["git", "-C", abs_repo, "show", f":{fname}"],
|
|
206
|
+
text=True,
|
|
207
|
+
errors="replace",
|
|
208
|
+
stderr=subprocess.DEVNULL
|
|
209
|
+
)
|
|
210
|
+
files_map[fname] = content
|
|
211
|
+
except Exception:
|
|
212
|
+
continue
|
|
213
|
+
|
|
214
|
+
res = cls.scan_staged_content(files_map)
|
|
215
|
+
|
|
216
|
+
if not res["clean"]:
|
|
217
|
+
print("\n" + "=" * 70)
|
|
218
|
+
print("🚨 \033[31mT-ZERO ZERO-LEAK SECURITY GUARD: COMMIT BLOCKED!\033[0m")
|
|
219
|
+
print("=" * 70)
|
|
220
|
+
print("Found prohibited credentials / hardcoded secrets in staged files:")
|
|
221
|
+
for v in res["violations"]:
|
|
222
|
+
print(f" ❌ \033[33m{v['file']}\033[0m: Detected {v['type']}")
|
|
223
|
+
print("\nRemove all secrets and credentials before committing.")
|
|
224
|
+
print("=" * 70 + "\n")
|
|
225
|
+
return 1
|
|
226
|
+
|
|
227
|
+
if res["warnings"]:
|
|
228
|
+
print("\n⚠️ [T-Zero Token Optimization Notice]")
|
|
229
|
+
for w in res["warnings"]:
|
|
230
|
+
print(f" • {w}")
|
|
231
|
+
|
|
232
|
+
print("⚡ \033[32m[T-Zero Pre-Commit Guard] All staged files clean & safe.\033[0m")
|
|
233
|
+
return 0
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def main():
|
|
237
|
+
target = sys.argv[1] if len(sys.argv) > 1 else "."
|
|
238
|
+
sys.exit(GitSecurityGuard.run_cli_check(target))
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
if __name__ == "__main__":
|
|
242
|
+
main()
|
|
243
|
+
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Siber Akademi — T-Zero Infrastructure & Database Schema AST Compressor.
|
|
4
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
+
License: MIT
|
|
6
|
+
|
|
7
|
+
Extracts high-value architectural contracts from SQL DDL, Kubernetes YAML,
|
|
8
|
+
Dockerfiles, and Terraform HCL, achieving 75% to 95% token reduction on
|
|
9
|
+
infrastructure and database artifacts without semantic loss.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
if sys.platform == "win32":
|
|
14
|
+
try:
|
|
15
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
16
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
17
|
+
except Exception:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
import re
|
|
21
|
+
from typing import Tuple, List, Dict, Any
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SchemaInfraReducer:
|
|
25
|
+
"""AST & Structural heuristic compressor for SQL, Kubernetes, Dockerfile, and Terraform."""
|
|
26
|
+
|
|
27
|
+
# --------------------------------------------------------------------------
|
|
28
|
+
# 1. SQL DDL SCHEMA COMPRESSOR
|
|
29
|
+
# --------------------------------------------------------------------------
|
|
30
|
+
@staticmethod
|
|
31
|
+
def reduce_sql(content: str, mode: str = "ultra") -> Tuple[str, float]:
|
|
32
|
+
"""Compresses SQL DDL/DML into pure schema contracts.
|
|
33
|
+
|
|
34
|
+
Strips huge INSERT INTO statements, runtime log statements, and comments.
|
|
35
|
+
Retains: CREATE TABLE, CREATE VIEW, CREATE TYPE, ALTER TABLE ADD CONSTRAINT, CREATE INDEX.
|
|
36
|
+
"""
|
|
37
|
+
orig_len = len(content)
|
|
38
|
+
if orig_len < 100:
|
|
39
|
+
return content, 0.0
|
|
40
|
+
|
|
41
|
+
# Strip single line and multi-line comments
|
|
42
|
+
no_comments = re.sub(r"--.*?$", "", content, flags=re.MULTILINE)
|
|
43
|
+
no_comments = re.sub(r"/\*.*?\*/", "", no_comments, flags=re.DOTALL)
|
|
44
|
+
|
|
45
|
+
# Match CREATE TABLE blocks
|
|
46
|
+
table_pattern = re.compile(r"CREATE\s+(?:TEMP\s+|TEMPORARY\s+|UNLOGGED\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?([^\s(]+)\s*\((.*?)\);", re.IGNORECASE | re.DOTALL)
|
|
47
|
+
# Match CREATE VIEW / TYPE
|
|
48
|
+
view_pattern = re.compile(r"CREATE\s+(?:OR\s+REPLACE\s+)?VIEW\s+([^\s(]+)\s+AS\s+(.*?);", re.IGNORECASE | re.DOTALL)
|
|
49
|
+
type_pattern = re.compile(r"CREATE\s+TYPE\s+([^\s(]+)\s+AS\s+(?:ENUM\s*)?\((.*?)\);", re.IGNORECASE | re.DOTALL)
|
|
50
|
+
index_pattern = re.compile(r"CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?([^\s]+)\s+ON\s+([^\s(]+)\s*\((.*?)\);", re.IGNORECASE)
|
|
51
|
+
fk_pattern = re.compile(r"ALTER\s+TABLE\s+(?:ONLY\s+)?([^\s]+)\s+ADD\s+CONSTRAINT\s+([^\s]+)\s+FOREIGN\s+KEY\s*\((.*?)\)\s*REFERENCES\s+([^\s(]+)\s*\((.*?)\);", re.IGNORECASE)
|
|
52
|
+
|
|
53
|
+
output_blocks = []
|
|
54
|
+
|
|
55
|
+
# 1. Custom Types / Enums
|
|
56
|
+
types_found = list(type_pattern.finditer(no_comments))
|
|
57
|
+
if types_found:
|
|
58
|
+
output_blocks.append("-- [T-Zero AST Schema Types]")
|
|
59
|
+
for m in types_found:
|
|
60
|
+
name = m.group(1).strip()
|
|
61
|
+
vals = re.sub(r"\s+", " ", m.group(2)).strip()
|
|
62
|
+
output_blocks.append(f"CREATE TYPE {name} AS ({vals});")
|
|
63
|
+
output_blocks.append("")
|
|
64
|
+
|
|
65
|
+
# 2. Tables & Columns
|
|
66
|
+
tables_found = list(table_pattern.finditer(no_comments))
|
|
67
|
+
if tables_found:
|
|
68
|
+
output_blocks.append("-- [T-Zero AST Schema Tables]")
|
|
69
|
+
for m in tables_found:
|
|
70
|
+
tname = m.group(1).strip()
|
|
71
|
+
raw_cols = m.group(2)
|
|
72
|
+
|
|
73
|
+
# Parse individual column/constraint definitions
|
|
74
|
+
col_defs = []
|
|
75
|
+
# Split by commas not inside parentheses
|
|
76
|
+
lines = [c.strip() for c in re.split(r",\s*(?![^()]*\))", raw_cols) if c.strip()]
|
|
77
|
+
for col in lines:
|
|
78
|
+
col_clean = re.sub(r"\s+", " ", col)
|
|
79
|
+
if mode == "ultra":
|
|
80
|
+
# Ultra mode: keep Column Name + Type + Primary/Unique/Not Null/References
|
|
81
|
+
col_clean = re.sub(r"(?i)\s+DEFAULT\s+[^,]+", "", col_clean)
|
|
82
|
+
col_clean = re.sub(r"(?i)\s*(?:CONSTRAINT\s+[^\s]+\s+)?CHECK\s*\(.*?\)", "", col_clean)
|
|
83
|
+
if col_clean.strip():
|
|
84
|
+
col_defs.append(f" {col_clean.strip()}")
|
|
85
|
+
|
|
86
|
+
output_blocks.append(f"CREATE TABLE {tname} (\n" + ",\n".join(col_defs) + "\n);")
|
|
87
|
+
output_blocks.append("")
|
|
88
|
+
|
|
89
|
+
# 3. Foreign Keys / Relationships
|
|
90
|
+
fks_found = list(fk_pattern.finditer(no_comments))
|
|
91
|
+
if fks_found:
|
|
92
|
+
output_blocks.append("-- [T-Zero AST Foreign Keys & Boundaries]")
|
|
93
|
+
for m in fks_found:
|
|
94
|
+
tbl = m.group(1).strip()
|
|
95
|
+
cname = m.group(2).strip()
|
|
96
|
+
src_cols = m.group(3).strip()
|
|
97
|
+
ref_tbl = m.group(4).strip()
|
|
98
|
+
ref_cols = m.group(5).strip()
|
|
99
|
+
output_blocks.append(f"ALTER TABLE {tbl} ADD CONSTRAINT {cname} FOREIGN KEY ({src_cols}) REFERENCES {ref_tbl}({ref_cols});")
|
|
100
|
+
output_blocks.append("")
|
|
101
|
+
|
|
102
|
+
# 4. Indexes
|
|
103
|
+
idx_found = list(index_pattern.finditer(no_comments))
|
|
104
|
+
if idx_found and mode != "ultra":
|
|
105
|
+
output_blocks.append("-- [T-Zero AST Indexes]")
|
|
106
|
+
for m in idx_found:
|
|
107
|
+
iname = m.group(1).strip()
|
|
108
|
+
on_tbl = m.group(2).strip()
|
|
109
|
+
icols = m.group(3).strip()
|
|
110
|
+
output_blocks.append(f"CREATE INDEX {iname} ON {on_tbl} ({icols});")
|
|
111
|
+
output_blocks.append("")
|
|
112
|
+
|
|
113
|
+
res = "\n".join(output_blocks).strip()
|
|
114
|
+
if not res:
|
|
115
|
+
# Fallback if raw queries without explicit CREATE TABLE
|
|
116
|
+
lines = [l.strip() for l in no_comments.splitlines() if l.strip() and not l.strip().upper().startswith(("INSERT INTO", "COPY "))]
|
|
117
|
+
res = "\n".join(lines[:120])
|
|
118
|
+
|
|
119
|
+
savings = max(0.0, ((orig_len - len(res)) / max(orig_len, 1)) * 100.0)
|
|
120
|
+
return res, savings
|
|
121
|
+
|
|
122
|
+
# --------------------------------------------------------------------------
|
|
123
|
+
# 2. KUBERNETES MANIFEST & YAML COMPRESSOR
|
|
124
|
+
# --------------------------------------------------------------------------
|
|
125
|
+
@staticmethod
|
|
126
|
+
def reduce_k8s_yaml(content: str, mode: str = "ultra") -> Tuple[str, float]:
|
|
127
|
+
"""Compresses Kubernetes YAML manifests down to architectural interfaces."""
|
|
128
|
+
orig_len = len(content)
|
|
129
|
+
if orig_len < 80:
|
|
130
|
+
return content, 0.0
|
|
131
|
+
|
|
132
|
+
docs = re.split(r"^---\s*$", content, flags=re.MULTILINE)
|
|
133
|
+
reduced_docs = []
|
|
134
|
+
|
|
135
|
+
for doc in docs:
|
|
136
|
+
doc_str = doc.strip()
|
|
137
|
+
if not doc_str:
|
|
138
|
+
continue
|
|
139
|
+
|
|
140
|
+
lines = doc_str.splitlines()
|
|
141
|
+
retained_lines = []
|
|
142
|
+
skip_section = False
|
|
143
|
+
skip_indent = 0
|
|
144
|
+
|
|
145
|
+
for line in lines:
|
|
146
|
+
raw_indent = len(line) - len(line.lstrip())
|
|
147
|
+
stripped = line.strip()
|
|
148
|
+
|
|
149
|
+
# Skip kubectl / runtime status bloat
|
|
150
|
+
if re.match(r"^(status|managedFields|annotations):", stripped):
|
|
151
|
+
skip_section = True
|
|
152
|
+
skip_indent = raw_indent
|
|
153
|
+
continue
|
|
154
|
+
|
|
155
|
+
if skip_section:
|
|
156
|
+
if raw_indent > skip_indent:
|
|
157
|
+
continue
|
|
158
|
+
else:
|
|
159
|
+
skip_section = False
|
|
160
|
+
|
|
161
|
+
# Keep structural keys
|
|
162
|
+
if any(stripped.startswith(k) for k in [
|
|
163
|
+
"apiVersion:", "kind:", "name:", "namespace:", "replicas:",
|
|
164
|
+
"containers:", "- name:", "image:", "containerPort:", "port:",
|
|
165
|
+
"targetPort:", "protocol:", "serviceAccountName:", "type:",
|
|
166
|
+
"claimName:", "mountPath:", "host:", "path:", "service:"
|
|
167
|
+
]):
|
|
168
|
+
retained_lines.append(line)
|
|
169
|
+
elif mode == "balanced" and raw_indent <= 4 and ":" in stripped:
|
|
170
|
+
retained_lines.append(line)
|
|
171
|
+
|
|
172
|
+
if retained_lines:
|
|
173
|
+
reduced_docs.append("\n".join(retained_lines))
|
|
174
|
+
|
|
175
|
+
res = "\n---\n".join(reduced_docs)
|
|
176
|
+
if not res.strip():
|
|
177
|
+
res = content[:300]
|
|
178
|
+
|
|
179
|
+
savings = max(0.0, ((orig_len - len(res)) / max(orig_len, 1)) * 100.0)
|
|
180
|
+
return res, savings
|
|
181
|
+
|
|
182
|
+
# --------------------------------------------------------------------------
|
|
183
|
+
# 3. DOCKERFILE COMPRESSOR
|
|
184
|
+
# --------------------------------------------------------------------------
|
|
185
|
+
@staticmethod
|
|
186
|
+
def reduce_dockerfile(content: str, mode: str = "ultra") -> Tuple[str, float]:
|
|
187
|
+
"""Condenses Dockerfiles into clean build stage architectures."""
|
|
188
|
+
orig_len = len(content)
|
|
189
|
+
lines = content.splitlines()
|
|
190
|
+
pruned = []
|
|
191
|
+
|
|
192
|
+
in_multiline_run = False
|
|
193
|
+
for line in lines:
|
|
194
|
+
s = line.strip()
|
|
195
|
+
if not s or s.startswith("#"):
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
if in_multiline_run:
|
|
199
|
+
if s.endswith("\\"):
|
|
200
|
+
continue
|
|
201
|
+
else:
|
|
202
|
+
in_multiline_run = False
|
|
203
|
+
continue
|
|
204
|
+
|
|
205
|
+
if s.startswith(("FROM ", "EXPOSE ", "ENTRYPOINT ", "CMD ", "ENV ", "WORKDIR ", "ARG ", "HEALTHCHECK ")):
|
|
206
|
+
pruned.append(s)
|
|
207
|
+
elif s.startswith("COPY "):
|
|
208
|
+
pruned.append(re.sub(r"\s+", " ", s))
|
|
209
|
+
elif s.startswith("RUN "):
|
|
210
|
+
if s.endswith("\\"):
|
|
211
|
+
in_multiline_run = True
|
|
212
|
+
pruned.append(f"RUN [build dependencies & binary install]")
|
|
213
|
+
else:
|
|
214
|
+
pruned.append(s[:70] + ("..." if len(s) > 70 else ""))
|
|
215
|
+
|
|
216
|
+
res = "\n".join(pruned)
|
|
217
|
+
savings = max(0.0, ((orig_len - len(res)) / max(orig_len, 1)) * 100.0)
|
|
218
|
+
return res, savings
|
|
219
|
+
|
|
220
|
+
# --------------------------------------------------------------------------
|
|
221
|
+
# 4. TERRAFORM / HCL COMPRESSOR
|
|
222
|
+
# --------------------------------------------------------------------------
|
|
223
|
+
@staticmethod
|
|
224
|
+
def reduce_terraform(content: str, mode: str = "ultra") -> Tuple[str, float]:
|
|
225
|
+
"""Condenses Terraform HCL into infrastructure topology contracts."""
|
|
226
|
+
orig_len = len(content)
|
|
227
|
+
block_pattern = re.compile(
|
|
228
|
+
r'((?:resource|data|module|variable|output|provider|terraform)(?:\s+["\w_-]+){0,2})\s*\{(.*?)\n[ \t]*\}',
|
|
229
|
+
re.DOTALL
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
matches = list(block_pattern.finditer(content))
|
|
233
|
+
if not matches:
|
|
234
|
+
return content, 0.0
|
|
235
|
+
|
|
236
|
+
pruned_blocks = []
|
|
237
|
+
for m in matches:
|
|
238
|
+
header = m.group(1).strip()
|
|
239
|
+
body = m.group(2)
|
|
240
|
+
|
|
241
|
+
key_lines = []
|
|
242
|
+
for line in body.splitlines():
|
|
243
|
+
s = line.strip()
|
|
244
|
+
if not s or s.startswith("#") or s.startswith("//"):
|
|
245
|
+
continue
|
|
246
|
+
if "=" in s or "{" in s:
|
|
247
|
+
k = s.split("=")[0].strip()
|
|
248
|
+
if any(req in k for req in ["type", "default", "description", "source", "version", "name", "id", "ami", "instance_type"]):
|
|
249
|
+
key_lines.append(f" {s}")
|
|
250
|
+
|
|
251
|
+
if key_lines:
|
|
252
|
+
pruned_blocks.append(f"{header} {{\n" + "\n".join(key_lines) + "\n}")
|
|
253
|
+
else:
|
|
254
|
+
pruned_blocks.append(f"{header} {{ ... }}")
|
|
255
|
+
|
|
256
|
+
res = "\n\n".join(pruned_blocks)
|
|
257
|
+
savings = max(0.0, ((orig_len - len(res)) / max(orig_len, 1)) * 100.0)
|
|
258
|
+
return res, savings
|
|
259
|
+
|
|
260
|
+
# --------------------------------------------------------------------------
|
|
261
|
+
# UNIVERSAL DISPATCHER
|
|
262
|
+
# --------------------------------------------------------------------------
|
|
263
|
+
@classmethod
|
|
264
|
+
def reduce(cls, filename_or_ext: str, content: str, mode: str = "ultra") -> Tuple[str, float]:
|
|
265
|
+
f = filename_or_ext.lower()
|
|
266
|
+
if f.endswith(".sql"):
|
|
267
|
+
return cls.reduce_sql(content, mode)
|
|
268
|
+
elif f.endswith((".yaml", ".yml")):
|
|
269
|
+
return cls.reduce_k8s_yaml(content, mode)
|
|
270
|
+
elif "dockerfile" in f:
|
|
271
|
+
return cls.reduce_dockerfile(content, mode)
|
|
272
|
+
elif f.endswith((".tf", ".hcl")):
|
|
273
|
+
return cls.reduce_terraform(content, mode)
|
|
274
|
+
return content, 0.0
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
T-Zero Jarvis Autonomous Engine & Semantic Memory Package
|
|
4
|
+
---------------------------------------------------------
|
|
5
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
6
|
+
Version: 6.0.0
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .semantic_compressor import (
|
|
10
|
+
SemanticTriplet,
|
|
11
|
+
SemanticTripletExtractor,
|
|
12
|
+
SemanticExtractor,
|
|
13
|
+
TypedEntity,
|
|
14
|
+
EntityType,
|
|
15
|
+
VectorQuantizedCodebook,
|
|
16
|
+
DynamicVirtualMemoryInjector,
|
|
17
|
+
get_global_compressor
|
|
18
|
+
)
|
|
19
|
+
from .zero_key_router import (
|
|
20
|
+
ZeroKeyAIRouter,
|
|
21
|
+
ZeroCostSecurityGuard
|
|
22
|
+
)
|
|
23
|
+
from .orchestrator import (
|
|
24
|
+
JarvisOrchestrator,
|
|
25
|
+
AutonomousGoalResult
|
|
26
|
+
)
|
|
27
|
+
from .causal_graph import (
|
|
28
|
+
CausalTemporalGraph,
|
|
29
|
+
CausalRelationType,
|
|
30
|
+
CausalEdge,
|
|
31
|
+
CausalNode
|
|
32
|
+
)
|
|
33
|
+
from .self_healing import (
|
|
34
|
+
SelfHealingExecutionEngine,
|
|
35
|
+
ExecutionResult
|
|
36
|
+
)
|
|
37
|
+
from .memory_consolidation import (
|
|
38
|
+
ConsolidationEngine,
|
|
39
|
+
EpisodicMemoryBuffer,
|
|
40
|
+
Episode,
|
|
41
|
+
MacroTriplet
|
|
42
|
+
)
|
|
43
|
+
from .hybrid_search import (
|
|
44
|
+
ZeroVectorDBSearchEngine,
|
|
45
|
+
SearchDocument,
|
|
46
|
+
SearchResult
|
|
47
|
+
)
|
|
48
|
+
from .swarm import (
|
|
49
|
+
SwarmCoordinator,
|
|
50
|
+
SwarmAgentReport,
|
|
51
|
+
SecuritySentinelAgent,
|
|
52
|
+
EmbeddedHardwareAgent,
|
|
53
|
+
ASTOptimizerAgent,
|
|
54
|
+
AutonomousDevOpsAgent
|
|
55
|
+
)
|
|
56
|
+
from .graph_visualizer import (
|
|
57
|
+
CyberpunkGraphVisualizer,
|
|
58
|
+
DOMAIN_COLORS
|
|
59
|
+
)
|
|
60
|
+
from .minhash_lsh import (
|
|
61
|
+
MinHashLSHEngine,
|
|
62
|
+
MinHashSignature
|
|
63
|
+
)
|
|
64
|
+
from .swarm_bft import (
|
|
65
|
+
ByzantineFaultTolerantSwarm,
|
|
66
|
+
BFTConsensusCertificate
|
|
67
|
+
)
|
|
68
|
+
from .latent_press import (
|
|
69
|
+
LatentPressCompressor,
|
|
70
|
+
LatentPressResult
|
|
71
|
+
)
|
|
72
|
+
from .workspace_orchestrator import (
|
|
73
|
+
WorkspaceOrchestrator,
|
|
74
|
+
WorkspaceProfiler,
|
|
75
|
+
WorkspaceProfile,
|
|
76
|
+
WorkspaceGovernanceSynthesizer
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
ZeroKeyRouter = ZeroKeyAIRouter
|
|
80
|
+
AutonomousGoalOrchestrator = JarvisOrchestrator
|
|
81
|
+
|
|
82
|
+
__all__ = [
|
|
83
|
+
"SemanticTriplet",
|
|
84
|
+
"SemanticTripletExtractor",
|
|
85
|
+
"SemanticExtractor",
|
|
86
|
+
"TypedEntity",
|
|
87
|
+
"EntityType",
|
|
88
|
+
"VectorQuantizedCodebook",
|
|
89
|
+
"DynamicVirtualMemoryInjector",
|
|
90
|
+
"get_global_compressor",
|
|
91
|
+
"ZeroKeyAIRouter",
|
|
92
|
+
"ZeroKeyRouter",
|
|
93
|
+
"ZeroCostSecurityGuard",
|
|
94
|
+
"JarvisOrchestrator",
|
|
95
|
+
"AutonomousGoalOrchestrator",
|
|
96
|
+
"AutonomousGoalResult",
|
|
97
|
+
"CausalTemporalGraph",
|
|
98
|
+
"CausalRelationType",
|
|
99
|
+
"CausalEdge",
|
|
100
|
+
"CausalNode",
|
|
101
|
+
"SelfHealingExecutionEngine",
|
|
102
|
+
"ExecutionResult",
|
|
103
|
+
"ConsolidationEngine",
|
|
104
|
+
"EpisodicMemoryBuffer",
|
|
105
|
+
"Episode",
|
|
106
|
+
"MacroTriplet",
|
|
107
|
+
"ZeroVectorDBSearchEngine",
|
|
108
|
+
"SearchDocument",
|
|
109
|
+
"SearchResult",
|
|
110
|
+
"SwarmCoordinator",
|
|
111
|
+
"SwarmAgentReport",
|
|
112
|
+
"CyberpunkGraphVisualizer",
|
|
113
|
+
"DOMAIN_COLORS",
|
|
114
|
+
"MinHashLSHEngine",
|
|
115
|
+
"MinHashSignature",
|
|
116
|
+
"ByzantineFaultTolerantSwarm",
|
|
117
|
+
"BFTConsensusCertificate",
|
|
118
|
+
"LatentPressCompressor",
|
|
119
|
+
"LatentPressResult",
|
|
120
|
+
"WorkspaceOrchestrator",
|
|
121
|
+
"WorkspaceProfiler",
|
|
122
|
+
"WorkspaceProfile",
|
|
123
|
+
"WorkspaceGovernanceSynthesizer"
|
|
124
|
+
]
|