tzero-mcp 12.2.1 ā 12.3.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.
- package/README.md +6 -30
- package/bin/tzero-mcp.js +2 -2
- package/bin/tzero.js +11 -6
- package/package.json +1 -2
- package/src/addmcp.py +10 -5
- package/src/app.py +3 -9
- package/src/tzero/__init__.py +1 -1
- package/src/tzero/anti_rea/__init__.py +16 -2
- package/src/tzero/anti_rea/algebraic_mutator.py +65 -44
- package/src/tzero/anti_rea/anti_debugger.py +51 -18
- package/src/tzero/anti_rea/asar_shield.py +24 -1
- package/src/tzero/anti_rea/auditor.py +62 -12
- package/src/tzero/anti_rea/canary_beacon.py +56 -76
- package/src/tzero/anti_rea/cli.py +37 -5
- package/src/tzero/anti_rea/confusables.py +62 -18
- package/src/tzero/anti_rea/crypto_loader.py +132 -0
- package/src/tzero/anti_rea/engine.py +129 -29
- package/src/tzero/anti_rea/extractor_shield.py +91 -13
- package/src/tzero/anti_rea/gui.py +1 -4
- package/src/tzero/anti_rea/integrity_guard.py +17 -5
- package/src/tzero/anti_rea/rdtsc_guard.py +21 -8
- package/src/tzero/anti_rea/string_vault.py +10 -7
- package/src/tzero/anti_rea/tier_catalog.py +388 -0
- package/src/tzero/siber_akademi.ico +0 -0
- package/src/tzero/siber_akademi_icon.py +14 -8
- package/src/tzero/tzero_armor.py +29 -7
- package/src/tzero/tzero_benchmark.py +4 -2
- package/src/tzero/tzero_budget.py +14 -5
- package/src/tzero/tzero_ci.py +2 -2
- package/src/tzero/tzero_contracts.py +7 -5
- package/src/tzero/tzero_dashboard.py +28 -9
- package/src/tzero/tzero_debt.py +19 -4
- package/src/tzero/tzero_deps.py +109 -87
- package/src/tzero/tzero_explain.py +1 -1
- package/src/tzero/tzero_features.py +43 -29
- package/src/tzero/tzero_federation.py +9 -2
- package/src/tzero/tzero_fixer/mcp_server.py +10 -0
- package/src/tzero/tzero_golden.py +37 -9
- package/src/tzero/tzero_growth.py +166 -8
- package/src/tzero/tzero_guard.py +147 -46
- package/src/tzero/tzero_jarvis/workspace_orchestrator.py +1 -1
- package/src/tzero/tzero_jarvis/zero_key_router.py +10 -78
- package/src/tzero/tzero_lsp.py +1 -1
- package/src/tzero/tzero_mcp.py +71 -23
- package/src/tzero/tzero_mutation.py +92 -15
- package/src/tzero/tzero_promo.py +1 -1
- package/src/tzero/tzero_proxy.py +105 -12
- package/src/tzero/tzero_scip.py +12 -6
- package/src/tzero/tzero_security.py +404 -60
- package/src/tzero/tzero_task_benchmark.py +2 -2
- package/src/tzero/tzero_traffic.py +35 -10
- package/src/tzero/tzero_tui.py +20 -11
- package/src/tzero/tzero_v3.py +304 -153
- package/src/tzero/tzero_welcome.py +12 -4
- package/bin/postinstall.js +0 -30
package/src/tzero/tzero_guard.py
CHANGED
|
@@ -41,9 +41,11 @@ TOKEN_WARN_THRESHOLD = 8000 # Tokens (~32,000 characters)
|
|
|
41
41
|
class GitSecurityGuard:
|
|
42
42
|
"""Enterprise pre-commit guard ensuring zero secret leaks and optimal prompt tokens."""
|
|
43
43
|
|
|
44
|
+
_TZERO_MARKER = "T-Zero Git Pre-Commit"
|
|
45
|
+
|
|
44
46
|
@classmethod
|
|
45
47
|
def install_hook(cls, repo_dir: str = ".") -> Dict[str, Any]:
|
|
46
|
-
"""Installs pre-commit hook into target repository
|
|
48
|
+
"""Installs pre-commit hook into target repository while preserving existing hooks."""
|
|
47
49
|
abs_repo = os.path.abspath(repo_dir)
|
|
48
50
|
git_dir = os.path.join(abs_repo, ".git")
|
|
49
51
|
|
|
@@ -57,9 +59,43 @@ class GitSecurityGuard:
|
|
|
57
59
|
os.makedirs(hooks_dir, exist_ok=True)
|
|
58
60
|
|
|
59
61
|
hook_path = os.path.join(hooks_dir, "pre-commit")
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
backup_path = os.path.join(hooks_dir, "pre-commit.user-backup")
|
|
63
|
+
bat_path = os.path.join(hooks_dir, "pre-commit.bat")
|
|
64
|
+
bat_backup = os.path.join(hooks_dir, "pre-commit.bat.user-backup")
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
# Preserve pre-existing non-T-Zero Unix pre-commit hook cleanly
|
|
68
|
+
if os.path.isfile(hook_path):
|
|
69
|
+
with open(hook_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
70
|
+
existing = f.read()
|
|
71
|
+
if cls._TZERO_MARKER not in existing and not os.path.exists(backup_path):
|
|
72
|
+
with open(backup_path, "w", encoding="utf-8", newline="\n") as bf:
|
|
73
|
+
bf.write(existing)
|
|
74
|
+
try:
|
|
75
|
+
st_b = os.stat(hook_path)
|
|
76
|
+
os.chmod(backup_path, st_b.st_mode | stat.S_IEXEC)
|
|
77
|
+
except Exception:
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
# Preserve pre-existing non-T-Zero Windows batch hook cleanly
|
|
81
|
+
if os.path.isfile(bat_path):
|
|
82
|
+
with open(bat_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
83
|
+
existing_bat = f.read()
|
|
84
|
+
if cls._TZERO_MARKER not in existing_bat and not os.path.exists(bat_backup):
|
|
85
|
+
with open(bat_backup, "w", encoding="utf-8") as bf:
|
|
86
|
+
bf.write(existing_bat)
|
|
87
|
+
|
|
88
|
+
hook_script = f"""#!/bin/sh
|
|
89
|
+
# {cls._TZERO_MARKER} & Token Guard
|
|
62
90
|
# Auto-generated by Siber Akademi T-Zero Context Architect
|
|
91
|
+
HOOK_DIR="$(dirname "$0")"
|
|
92
|
+
if [ -f "$HOOK_DIR/pre-commit.user-backup" ]; then
|
|
93
|
+
sh "$HOOK_DIR/pre-commit.user-backup" "$@"
|
|
94
|
+
USER_EXIT=$?
|
|
95
|
+
if [ $USER_EXIT -ne 0 ]; then
|
|
96
|
+
exit $USER_EXIT
|
|
97
|
+
fi
|
|
98
|
+
fi
|
|
63
99
|
|
|
64
100
|
python -c "try:
|
|
65
101
|
from tzero.tzero_guard import GitSecurityGuard
|
|
@@ -69,35 +105,34 @@ import sys; sys.exit(GitSecurityGuard.run_cli_check('.'))"
|
|
|
69
105
|
EXIT_CODE=$?
|
|
70
106
|
|
|
71
107
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
72
|
-
echo "\\033[31m[T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks or
|
|
108
|
+
echo "\\033[31m[T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks or scan errors.\\033[0m"
|
|
73
109
|
exit 1
|
|
74
110
|
fi
|
|
75
111
|
|
|
76
112
|
exit 0
|
|
77
113
|
"""
|
|
78
|
-
|
|
79
|
-
try:
|
|
80
114
|
with open(hook_path, "w", encoding="utf-8", newline="\n") as f:
|
|
81
115
|
f.write(hook_script)
|
|
82
116
|
|
|
83
|
-
# Mark executable on Unix/Mac
|
|
84
117
|
try:
|
|
85
118
|
st = os.stat(hook_path)
|
|
86
119
|
os.chmod(hook_path, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
|
|
87
120
|
except Exception:
|
|
88
121
|
pass
|
|
89
122
|
|
|
90
|
-
# Also create pre-commit.bat for native Windows cmd / powershell hooks
|
|
91
|
-
bat_path = os.path.join(hooks_dir, "pre-commit.bat")
|
|
92
123
|
bat_script = f"""@echo off
|
|
93
|
-
REM
|
|
124
|
+
REM {cls._TZERO_MARKER} for Windows
|
|
125
|
+
if exist "%~dp0pre-commit.bat.user-backup" (
|
|
126
|
+
call "%~dp0pre-commit.bat.user-backup" %*
|
|
127
|
+
if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
|
|
128
|
+
)
|
|
94
129
|
python -c "try:^
|
|
95
130
|
from tzero.tzero_guard import GitSecurityGuard^
|
|
96
131
|
except ImportError:^
|
|
97
132
|
import tzero_guard; GitSecurityGuard = tzero_guard.GitSecurityGuard^
|
|
98
133
|
import sys; sys.exit(GitSecurityGuard.run_cli_check('.'))"
|
|
99
134
|
if %ERRORLEVEL% NEQ 0 (
|
|
100
|
-
echo [T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks.
|
|
135
|
+
echo [T-ZERO GUARD BLOCKED COMMIT] Commit aborted due to secret leaks or scan errors.
|
|
101
136
|
exit /b 1
|
|
102
137
|
)
|
|
103
138
|
exit /b 0
|
|
@@ -109,6 +144,7 @@ exit /b 0
|
|
|
109
144
|
"success": True,
|
|
110
145
|
"hook_path": hook_path,
|
|
111
146
|
"bat_path": bat_path,
|
|
147
|
+
"preserved_existing": os.path.isfile(backup_path) or os.path.isfile(bat_backup),
|
|
112
148
|
"message": f"Successfully installed T-Zero Pre-Commit Guard in {hook_path}"
|
|
113
149
|
}
|
|
114
150
|
except Exception as e:
|
|
@@ -118,10 +154,37 @@ exit /b 0
|
|
|
118
154
|
}
|
|
119
155
|
|
|
120
156
|
@classmethod
|
|
121
|
-
def
|
|
157
|
+
def uninstall_hook(cls, repo_dir: str = ".") -> Dict[str, Any]:
|
|
158
|
+
"""Uninstalls T-Zero pre-commit hook and restores any backed-up user hook cleanly."""
|
|
159
|
+
hooks_dir = os.path.join(os.path.abspath(repo_dir), ".git", "hooks")
|
|
160
|
+
if not os.path.isdir(hooks_dir):
|
|
161
|
+
return {"success": False, "message": "Missing .git/hooks directory."}
|
|
162
|
+
for main_name, bak_name in (("pre-commit", "pre-commit.user-backup"), ("pre-commit.bat", "pre-commit.bat.user-backup")):
|
|
163
|
+
main_p = os.path.join(hooks_dir, main_name)
|
|
164
|
+
bak_p = os.path.join(hooks_dir, bak_name)
|
|
165
|
+
is_tzero_hook = False
|
|
166
|
+
if os.path.isfile(main_p):
|
|
167
|
+
with open(main_p, "r", encoding="utf-8", errors="ignore") as f:
|
|
168
|
+
is_tzero_hook = cls._TZERO_MARKER in f.read()
|
|
169
|
+
if is_tzero_hook:
|
|
170
|
+
os.remove(main_p)
|
|
171
|
+
if os.path.isfile(bak_p):
|
|
172
|
+
os.replace(bak_p, main_p)
|
|
173
|
+
return {"success": True, "message": "Uninstalled T-Zero Pre-Commit Guard and restored prior hooks."}
|
|
174
|
+
|
|
175
|
+
@classmethod
|
|
176
|
+
def scan_staged_content(
|
|
177
|
+
cls,
|
|
178
|
+
files_map: Dict[str, str],
|
|
179
|
+
total_input: Optional[int] = None,
|
|
180
|
+
skipped_files: Optional[List[str]] = None,
|
|
181
|
+
errored_files: Optional[List[str]] = None,
|
|
182
|
+
) -> Dict[str, Any]:
|
|
122
183
|
"""Scans in-memory staged files map {filename: content} for secrets and token bloat."""
|
|
123
184
|
violations = []
|
|
124
185
|
warnings = []
|
|
186
|
+
err_list = list(errored_files or [])
|
|
187
|
+
skip_list = list(skipped_files or [])
|
|
125
188
|
|
|
126
189
|
for filename, content in files_map.items():
|
|
127
190
|
findings = ZeroLeakEngine.scan_text(content, check_entropy=True)
|
|
@@ -135,19 +198,23 @@ exit /b 0
|
|
|
135
198
|
"entropy": f.entropy
|
|
136
199
|
})
|
|
137
200
|
|
|
138
|
-
# Check token bloat
|
|
139
201
|
approx_tokens = max(1, len(content) // 4)
|
|
140
202
|
if approx_tokens > TOKEN_WARN_THRESHOLD:
|
|
141
203
|
warnings.append(
|
|
142
204
|
f"File '{filename}' has {approx_tokens:,} tokens. Consider compressing with T-Zero before committing."
|
|
143
205
|
)
|
|
144
206
|
|
|
145
|
-
clean = (len(violations) == 0)
|
|
207
|
+
clean = (len(violations) == 0 and len(err_list) == 0)
|
|
146
208
|
return {
|
|
147
209
|
"clean": clean,
|
|
148
210
|
"violations": violations,
|
|
149
211
|
"warnings": warnings,
|
|
150
|
-
"
|
|
212
|
+
"errors": err_list,
|
|
213
|
+
"skipped": skip_list,
|
|
214
|
+
"files_input": total_input if total_input is not None else len(files_map) + len(skip_list) + len(err_list),
|
|
215
|
+
"files_scanned": len(files_map),
|
|
216
|
+
"files_skipped": len(skip_list),
|
|
217
|
+
"files_errored": len(err_list),
|
|
151
218
|
}
|
|
152
219
|
|
|
153
220
|
@classmethod
|
|
@@ -155,12 +222,15 @@ exit /b 0
|
|
|
155
222
|
"""Scans all repository files for hardcoded secrets, keys, and credentials."""
|
|
156
223
|
abs_repo = os.path.abspath(repo_dir)
|
|
157
224
|
files_map: Dict[str, str] = {}
|
|
225
|
+
skipped_files: List[str] = []
|
|
226
|
+
errored_files: List[str] = []
|
|
158
227
|
skip_dirs = {".git", "__pycache__", ".pytest_cache", "target", "dist", "build", ".venv", "venv", ".egg-info", "node_modules"}
|
|
159
228
|
skip_files = {
|
|
160
229
|
"package-lock.json", "yarn.lock", "pnpm-lock.yaml", "Cargo.lock",
|
|
161
230
|
"poetry.lock", "composer.lock", "Gemfile.lock", "Pipfile.lock"
|
|
162
231
|
}
|
|
163
|
-
code_exts = {".py", ".rs", ".js", ".ts", ".jsx", ".tsx", ".go", ".java", ".json", ".toml", ".yaml", ".yml", ".env"}
|
|
232
|
+
code_exts = {".py", ".rs", ".js", ".ts", ".jsx", ".tsx", ".go", ".java", ".json", ".toml", ".yaml", ".yml", ".env", ".sh", ".ps1", ".cfg", ".ini"}
|
|
233
|
+
total_seen = 0
|
|
164
234
|
|
|
165
235
|
for root, dirs, files in os.walk(abs_repo):
|
|
166
236
|
dirs[:] = [d for d in dirs if d not in skip_dirs]
|
|
@@ -169,66 +239,97 @@ exit /b 0
|
|
|
169
239
|
continue
|
|
170
240
|
_, ext = os.path.splitext(f)
|
|
171
241
|
if ext.lower() in code_exts or f.startswith(".env"):
|
|
242
|
+
total_seen += 1
|
|
172
243
|
fpath = os.path.join(root, f)
|
|
173
244
|
rel_path = os.path.relpath(fpath, abs_repo).replace("\\", "/")
|
|
174
|
-
if "test" in rel_path.lower():
|
|
175
|
-
continue
|
|
176
245
|
if f.startswith(".env") and f != ".env.example":
|
|
177
|
-
# Skip local gitignored environment files
|
|
178
246
|
try:
|
|
179
247
|
check = subprocess.run(["git", "-C", abs_repo, "check-ignore", fpath], capture_output=True)
|
|
180
248
|
if check.returncode == 0:
|
|
249
|
+
skipped_files.append(rel_path)
|
|
181
250
|
continue
|
|
182
251
|
except Exception:
|
|
183
252
|
pass
|
|
184
253
|
try:
|
|
185
|
-
with open(fpath, "r", encoding="utf-8", errors="
|
|
254
|
+
with open(fpath, "r", encoding="utf-8", errors="strict") as fp:
|
|
186
255
|
files_map[rel_path] = fp.read()
|
|
187
|
-
except
|
|
188
|
-
|
|
189
|
-
|
|
256
|
+
except UnicodeDecodeError:
|
|
257
|
+
try:
|
|
258
|
+
with open(fpath, "r", encoding="utf-8", errors="replace") as fp:
|
|
259
|
+
files_map[rel_path] = fp.read()
|
|
260
|
+
except Exception as exc:
|
|
261
|
+
errored_files.append(f"{rel_path}: {exc}")
|
|
262
|
+
except Exception as exc:
|
|
263
|
+
errored_files.append(f"{rel_path}: {exc}")
|
|
264
|
+
return cls.scan_staged_content(
|
|
265
|
+
files_map, total_input=total_seen, skipped_files=skipped_files, errored_files=errored_files
|
|
266
|
+
)
|
|
190
267
|
|
|
191
268
|
@classmethod
|
|
192
269
|
def run_cli_check(cls, repo_dir: str = ".") -> int:
|
|
193
270
|
"""Executes pre-commit check on currently staged git files."""
|
|
194
271
|
abs_repo = os.path.abspath(repo_dir)
|
|
272
|
+
git_dir = os.path.join(abs_repo, ".git")
|
|
195
273
|
try:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
except Exception:
|
|
201
|
-
|
|
274
|
+
proc = subprocess.run(
|
|
275
|
+
["git", "-C", abs_repo, "diff", "--cached", "--name-only"],
|
|
276
|
+
capture_output=True, text=True, check=False,
|
|
277
|
+
)
|
|
278
|
+
except Exception as exc:
|
|
279
|
+
print(f"[T-ZERO GUARD ERROR] Unable to execute git diff: {exc}", file=sys.stderr)
|
|
280
|
+
return 1
|
|
202
281
|
|
|
282
|
+
if proc.returncode != 0:
|
|
283
|
+
err_msg = (proc.stderr or proc.stdout or "git diff --cached failed").strip()
|
|
284
|
+
print(f"[T-ZERO GUARD ERROR] Staged file listing failed ({git_dir}): {err_msg}", file=sys.stderr)
|
|
285
|
+
return 1
|
|
286
|
+
|
|
287
|
+
staged_names = [line.strip() for line in proc.stdout.splitlines() if line.strip()]
|
|
203
288
|
if not staged_names:
|
|
204
289
|
return 0
|
|
205
290
|
|
|
206
|
-
# Read content of staged files from git index
|
|
207
291
|
files_map: Dict[str, str] = {}
|
|
292
|
+
skipped_files: List[str] = []
|
|
293
|
+
errored_files: List[str] = []
|
|
208
294
|
for fname in staged_names:
|
|
209
|
-
if
|
|
295
|
+
if fname.startswith(".agents/"):
|
|
296
|
+
skipped_files.append(fname)
|
|
210
297
|
continue
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
|
|
298
|
+
show_proc = subprocess.run(
|
|
299
|
+
["git", "-C", abs_repo, "show", f":{fname}"],
|
|
300
|
+
capture_output=True,
|
|
301
|
+
check=False,
|
|
302
|
+
)
|
|
303
|
+
if show_proc.returncode != 0:
|
|
304
|
+
err_txt = show_proc.stderr.decode("utf-8", errors="replace").strip()
|
|
305
|
+
errored_files.append(f"{fname}: git show failed ({err_txt})")
|
|
306
|
+
continue
|
|
307
|
+
raw_bytes = show_proc.stdout
|
|
308
|
+
if b"\x00" in raw_bytes[:4096]:
|
|
309
|
+
skipped_files.append(fname)
|
|
220
310
|
continue
|
|
311
|
+
files_map[fname] = raw_bytes.decode("utf-8", errors="replace")
|
|
221
312
|
|
|
222
|
-
res = cls.scan_staged_content(
|
|
313
|
+
res = cls.scan_staged_content(
|
|
314
|
+
files_map,
|
|
315
|
+
total_input=len(staged_names),
|
|
316
|
+
skipped_files=skipped_files,
|
|
317
|
+
errored_files=errored_files,
|
|
318
|
+
)
|
|
223
319
|
|
|
224
320
|
if not res["clean"]:
|
|
225
321
|
print("\n" + "=" * 70)
|
|
226
322
|
print("šØ \033[31mT-ZERO ZERO-LEAK SECURITY GUARD: COMMIT BLOCKED!\033[0m")
|
|
227
323
|
print("=" * 70)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
324
|
+
if res["errors"]:
|
|
325
|
+
print("Unreadable or failed staged files:")
|
|
326
|
+
for err in res["errors"]:
|
|
327
|
+
print(f" ā {err}")
|
|
328
|
+
if res["violations"]:
|
|
329
|
+
print("Found prohibited credentials / hardcoded secrets in staged files:")
|
|
330
|
+
for v in res["violations"]:
|
|
331
|
+
print(f" ā \033[33m{v['file']}\033[0m (Line {v['line']}): Detected {v['type']}")
|
|
332
|
+
print(f"\nCounts: input={res['files_input']} scanned={res['files_scanned']} skipped={res['files_skipped']} errored={res['files_errored']}")
|
|
232
333
|
print("=" * 70 + "\n")
|
|
233
334
|
return 1
|
|
234
335
|
|
|
@@ -237,7 +338,7 @@ exit /b 0
|
|
|
237
338
|
for w in res["warnings"]:
|
|
238
339
|
print(f" ⢠{w}")
|
|
239
340
|
|
|
240
|
-
print("ā” \033[32m[T-Zero Pre-Commit Guard]
|
|
341
|
+
print(f"ā” \033[32m[T-Zero Pre-Commit Guard] Scanned {res['files_scanned']}/{res['files_input']} staged files cleanly.\033[0m")
|
|
241
342
|
return 0
|
|
242
343
|
|
|
243
344
|
|
|
@@ -1041,7 +1041,7 @@ flowchart LR
|
|
|
1041
1041
|
|
|
1042
1042
|
return f"""# T-ZERO JARVIS MASTER WORKSPACE ORCHESTRATOR
|
|
1043
1043
|
*Executive AI Engineering Manager & Autonomous Multi-Agent Coordinator*
|
|
1044
|
-
*Version: 5.1.0 |
|
|
1044
|
+
*Version: 5.1.0 | Local AST Core | $0.00 Cost | 100% Zero-Leak Certified*
|
|
1045
1045
|
|
|
1046
1046
|
---
|
|
1047
1047
|
|
|
@@ -5,26 +5,13 @@ JARVIS ZERO-KEY INTELLIGENCE ROUTER
|
|
|
5
5
|
Developer: Toprak Ahmet AydoÄmuÅ (Siber Akademi)
|
|
6
6
|
Version: 4.2.0
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
4 Katmanlı Akıllı Havuz:
|
|
12
|
-
1. Yerel Ollama (EÄer makinede yüklüyse, sıfır internet ve sıfır maliyetle ƧalıÅır)
|
|
13
|
-
2. Pollinations AI Ćcretsiz UƧ Noktası (Kayıt, kredi kartı veya API Key gerektirmez)
|
|
14
|
-
3. OpenRouter Free Whitelist (Sadece ':free' etiketli modeller)
|
|
15
|
-
4. Deterministik AST Tamircisi (Sƶzdizimi ve import hatalarını LLM olmadan doÄrudan onarır)
|
|
8
|
+
Runs keyless inference through a local Ollama API and exposes a separate web
|
|
9
|
+
search helper.
|
|
16
10
|
"""
|
|
17
11
|
|
|
18
|
-
import os
|
|
19
|
-
import sys
|
|
20
12
|
import json
|
|
21
|
-
import logging
|
|
22
13
|
import urllib.request
|
|
23
|
-
import
|
|
24
|
-
import urllib.parse
|
|
25
|
-
from typing import Dict, List, Optional, Any
|
|
26
|
-
|
|
27
|
-
logger = logging.getLogger("TZeroJarvisRouter")
|
|
14
|
+
from typing import Any, Dict, Optional
|
|
28
15
|
|
|
29
16
|
|
|
30
17
|
class ZeroCostSecurityGuard:
|
|
@@ -49,8 +36,6 @@ class ZeroCostSecurityGuard:
|
|
|
49
36
|
class ZeroKeyAIRouter:
|
|
50
37
|
"""API Key gerektirmeyen, hatasız ve yedekli yapay zeka motoru."""
|
|
51
38
|
|
|
52
|
-
POLLINATIONS_URL = "https://text.pollinations.ai/"
|
|
53
|
-
|
|
54
39
|
@classmethod
|
|
55
40
|
def check_ollama_available(cls) -> bool:
|
|
56
41
|
"""Yerel makinede Ollama'nın ƧalıÅıp ƧalıÅmadıÄını yoklar."""
|
|
@@ -71,45 +56,6 @@ class ZeroKeyAIRouter:
|
|
|
71
56
|
data = json.loads(resp.read().decode("utf-8"))
|
|
72
57
|
return data.get("response", "")
|
|
73
58
|
|
|
74
|
-
@classmethod
|
|
75
|
-
def call_pollinations_free(cls, prompt: str, system_prompt: str = "Sen T-Zero Jarvis otonom kodlama asistanısın.") -> str:
|
|
76
|
-
"""
|
|
77
|
-
Pollinations AI ücretsiz REST uƧ noktasını ƧaÄırır.
|
|
78
|
-
HİĆBİR API KEY VEYA KAYIT GEREKTİRMEZ.
|
|
79
|
-
"""
|
|
80
|
-
payload = {
|
|
81
|
-
"messages": [
|
|
82
|
-
{"role": "system", "content": system_prompt},
|
|
83
|
-
{"role": "user", "content": prompt}
|
|
84
|
-
],
|
|
85
|
-
"model": "openai",
|
|
86
|
-
"seed": 42,
|
|
87
|
-
"jsonMode": False
|
|
88
|
-
}
|
|
89
|
-
data = json.dumps(payload).encode("utf-8")
|
|
90
|
-
req = urllib.request.Request(
|
|
91
|
-
cls.POLLINATIONS_URL,
|
|
92
|
-
data=data,
|
|
93
|
-
headers={
|
|
94
|
-
"Content-Type": "application/json",
|
|
95
|
-
"User-Agent": "T-Zero-Jarvis-Autonomous/4.2"
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
try:
|
|
99
|
-
with urllib.request.urlopen(req, timeout=45) as resp:
|
|
100
|
-
return resp.read().decode("utf-8", errors="replace").strip()
|
|
101
|
-
except urllib.error.HTTPError as e:
|
|
102
|
-
# Yedek GET parametreli ücretsiz ƧaÄrı
|
|
103
|
-
try:
|
|
104
|
-
encoded_prompt = urllib.parse.quote(prompt[:500])
|
|
105
|
-
fallback_url = f"{cls.POLLINATIONS_URL}{encoded_prompt}?system={urllib.parse.quote(system_prompt[:200])}"
|
|
106
|
-
fallback_req = urllib.request.Request(fallback_url, headers={"User-Agent": "T-Zero-Jarvis"})
|
|
107
|
-
with urllib.request.urlopen(fallback_req, timeout=30) as f_resp:
|
|
108
|
-
return f_resp.read().decode("utf-8", errors="replace").strip()
|
|
109
|
-
except Exception as e2:
|
|
110
|
-
logger.error(f"Pollinations fallback failed: {e2}")
|
|
111
|
-
raise RuntimeError(f"Ćcretsiz genel Ƨıkarım uƧ noktasına baÄlanılamadı: {e}")
|
|
112
|
-
|
|
113
59
|
@classmethod
|
|
114
60
|
def search_duckduckgo_free(cls, query: str, max_results: int = 4) -> str:
|
|
115
61
|
"""API anahtarı olmadan canlı internet araması yapar."""
|
|
@@ -128,10 +74,7 @@ class ZeroKeyAIRouter:
|
|
|
128
74
|
|
|
129
75
|
@classmethod
|
|
130
76
|
def query_intelligence(cls, prompt: str, system_prompt: Optional[str] = None) -> Dict[str, Any]:
|
|
131
|
-
"""
|
|
132
|
-
Kullanıcıdan tek bir API key istemeden en uygun ücretsiz saÄlayıcıyı
|
|
133
|
-
otomatik seçip yanıtı döndüren ana fonksiyon.
|
|
134
|
-
"""
|
|
77
|
+
"""Return an Ollama completion or report that local inference is unavailable."""
|
|
135
78
|
sys_p = system_prompt or "Sen Siber Akademi T-Zero Jarvis otonom yazılım mühendisisin."
|
|
136
79
|
|
|
137
80
|
# 1. Ćncelik: Yerel Ollama (Maksimum Gizlilik & Sıfır İnternet)
|
|
@@ -148,23 +91,12 @@ class ZeroKeyAIRouter:
|
|
|
148
91
|
except Exception:
|
|
149
92
|
pass
|
|
150
93
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"cost": "0.00$",
|
|
158
|
-
"response": ans
|
|
159
|
-
}
|
|
160
|
-
except Exception as e:
|
|
161
|
-
# 3. Fallback: Deterministik yanıt
|
|
162
|
-
return {
|
|
163
|
-
"provider": "tzero_deterministic_engine",
|
|
164
|
-
"model": "ast-rule-engine",
|
|
165
|
-
"cost": "0.00$",
|
|
166
|
-
"response": f"[T-Zero Deterministik Zeka]: İstek AST motoru tarafından iÅlendi. AÄ baÄlantısı veya yerel LLM olmadan deterministik Ƨƶzüm uygulandı."
|
|
167
|
-
}
|
|
94
|
+
return {
|
|
95
|
+
"provider": "unavailable",
|
|
96
|
+
"model": "",
|
|
97
|
+
"cost": "0.00$",
|
|
98
|
+
"response": "Local Ollama is unavailable or returned no response.",
|
|
99
|
+
}
|
|
168
100
|
|
|
169
101
|
route_query = query_intelligence
|
|
170
102
|
|
package/src/tzero/tzero_lsp.py
CHANGED
package/src/tzero/tzero_mcp.py
CHANGED
|
@@ -33,7 +33,7 @@ import ast
|
|
|
33
33
|
import inspect
|
|
34
34
|
import logging
|
|
35
35
|
|
|
36
|
-
SERVER_VERSION = "12.2
|
|
36
|
+
SERVER_VERSION = "12.3.2"
|
|
37
37
|
|
|
38
38
|
# Version checks must not initialize the MCP SDK or dependency bootstrap. Besides
|
|
39
39
|
# being needlessly expensive, that path may wait on package discovery/network
|
|
@@ -1434,22 +1434,47 @@ def create_mcp_server():
|
|
|
1434
1434
|
return "\n".join(out)
|
|
1435
1435
|
return f"š [ZERO-LEAK PASS] File `{target_file}` is 100% clean. Zero hardcoded secrets detected."
|
|
1436
1436
|
|
|
1437
|
-
# Audit entire workspace
|
|
1437
|
+
# Audit entire workspace on FULL unpruned raw files (never AST-pruned skeletons)
|
|
1438
1438
|
scanner = CodebaseScanner()
|
|
1439
|
-
files,
|
|
1439
|
+
files, _, _ = scanner.scan_directory(abs_root)
|
|
1440
1440
|
all_leaks = []
|
|
1441
|
+
fully_scanned = 0
|
|
1442
|
+
partially_scanned = 0
|
|
1443
|
+
skipped = 0
|
|
1444
|
+
unreadable = []
|
|
1441
1445
|
for f in files:
|
|
1442
|
-
|
|
1446
|
+
fp = os.path.join(abs_root, f)
|
|
1447
|
+
try:
|
|
1448
|
+
with open(fp, "r", encoding="utf-8", errors="replace") as fh:
|
|
1449
|
+
content = fh.read()
|
|
1450
|
+
fully_scanned += 1
|
|
1451
|
+
except Exception as exc:
|
|
1452
|
+
unreadable.append(f"{f} ({exc})")
|
|
1453
|
+
continue
|
|
1443
1454
|
leaks = scan_text_for_secrets(content)
|
|
1444
1455
|
for leak in leaks:
|
|
1445
1456
|
all_leaks.append((f, leak))
|
|
1446
|
-
|
|
1457
|
+
|
|
1447
1458
|
if all_leaks:
|
|
1448
|
-
out = [
|
|
1459
|
+
out = [
|
|
1460
|
+
f"šØ **[ZERO-LEAK ALERT] Zero-Leak Security Audit: Found {len(all_leaks)} potential secret leaks in workspace `{abs_root}`!**",
|
|
1461
|
+
f"- Scan Coverage: `{fully_scanned}` fully scanned, `{partially_scanned}` partial, `{skipped}` skipped, `{len(unreadable)}` unreadable\n",
|
|
1462
|
+
]
|
|
1449
1463
|
for fname, leak in all_leaks[:20]:
|
|
1450
1464
|
out.append(f"- `{fname}` (Line {leak['line']}): {leak['desc']}")
|
|
1465
|
+
if unreadable:
|
|
1466
|
+
out.append(f"\nā ļø Unreadable files: {', '.join(unreadable[:10])}")
|
|
1451
1467
|
return "\n".join(out)
|
|
1452
|
-
|
|
1468
|
+
if unreadable or partially_scanned > 0:
|
|
1469
|
+
return (
|
|
1470
|
+
f"ā ļø **[ZERO-LEAK INCOMPLETE]** Scan could not certify `{abs_root}` clean: "
|
|
1471
|
+
f"`{fully_scanned}` full, `{partially_scanned}` partial, `{skipped}` skipped, `{len(unreadable)}` unreadable "
|
|
1472
|
+
f"({', '.join(unreadable[:10])})."
|
|
1473
|
+
)
|
|
1474
|
+
return (
|
|
1475
|
+
f"š [ZERO-LEAK PASS] All {fully_scanned} files in `{abs_root}` (0 partial, 0 skipped, 0 unreadable) "
|
|
1476
|
+
f"passed full raw unpruned Zero-Leak security audit. Zero exposed secrets."
|
|
1477
|
+
)
|
|
1453
1478
|
|
|
1454
1479
|
# -------------------------------------------------------------------------
|
|
1455
1480
|
# TOOL 17: verify_hallucination_guard
|
|
@@ -1865,9 +1890,9 @@ def create_mcp_server():
|
|
|
1865
1890
|
# -------------------------------------------------------------------------
|
|
1866
1891
|
@_maybe_tool(
|
|
1867
1892
|
name="jarvis_zero_key_query",
|
|
1868
|
-
title="Query
|
|
1893
|
+
title="Query Local Ollama Models via Zero Key Gateway",
|
|
1869
1894
|
description=(
|
|
1870
|
-
"Dispatches inference prompts to
|
|
1895
|
+
"Dispatches inference prompts strictly to a local Ollama daemon (127.0.0.1:11434) with zero external API keys, distinguishing from 'search_codebase_semantic' and 'get_project_context_tree' by generating natural language completions rather than static codebase context.\n"
|
|
1871
1896
|
"\n"
|
|
1872
1897
|
"Parameters:\n"
|
|
1873
1898
|
"- `prompt` (str, required): User prompt, code question, or instruction for the AI model.\n"
|
|
@@ -1876,15 +1901,15 @@ def create_mcp_server():
|
|
|
1876
1901
|
"Behavior:\n"
|
|
1877
1902
|
"- Read-only: Performs query inference without modifying workspace files or persisting conversational state.\n"
|
|
1878
1903
|
"- Non-idempotent: Model responses may vary across invocations.\n"
|
|
1879
|
-
"- Open-World Network Operation: Dispatches HTTP requests to local Ollama (127.0.0.1:11434)
|
|
1880
|
-
"- Auth & Rate Limits: Zero credentials required; no account or credit card needed.
|
|
1881
|
-
"- Error Handling:
|
|
1904
|
+
"- Open-World Network Operation: Dispatches local HTTP requests strictly to local Ollama (127.0.0.1:11434) with zero user API keys, zero billing, and zero external cloud fallbacks.\n"
|
|
1905
|
+
"- Auth & Rate Limits: Zero credentials required; no account or credit card needed. Local daemon check has a 1.5-second timeout and inference has a 60-second timeout.\n"
|
|
1906
|
+
"- Error Handling: Reports unavailability immediately if local Ollama is inactive without falling back to external cloud services.\n"
|
|
1882
1907
|
"\n"
|
|
1883
1908
|
"Usage Guidelines:\n"
|
|
1884
|
-
"- When to use: Query free
|
|
1909
|
+
"- When to use: Query free local Ollama inference for coding questions or reasoning without configuring API keys or paying commercial provider fees.\n"
|
|
1885
1910
|
"- When NOT to use: Do not use for local codebase search or AST parsing (use 'search_codebase_semantic' or 'get_project_context_tree' instead); do not use for structured file modifications (use 'generate_smart_micro_patch' instead).\n"
|
|
1886
1911
|
"\n"
|
|
1887
|
-
"Returns: Structured Markdown containing selected
|
|
1912
|
+
"Returns: Structured Markdown containing selected local provider name, model identifier, cost confirmation ($0.00), and response completion text."
|
|
1888
1913
|
),
|
|
1889
1914
|
annotations=ToolAnnotations(read_only_hint=True, destructive_hint=False, idempotent_hint=False, open_world_hint=True)
|
|
1890
1915
|
)
|
|
@@ -4738,6 +4763,13 @@ def create_mcp_server():
|
|
|
4738
4763
|
md.append(f"- **Video Prompt:** `{sc.video_prompt}`\n")
|
|
4739
4764
|
return "\n".join(md)
|
|
4740
4765
|
|
|
4766
|
+
elif act in ("telemetry", "savings_telemetry", "sqlite_telemetry"):
|
|
4767
|
+
from tzero.tzero_telemetry import render_report, get_summary
|
|
4768
|
+
target_dir = target if os.path.isdir(target) else "."
|
|
4769
|
+
if opts.get("format") == "json" or query.strip().lower() == "json":
|
|
4770
|
+
return json.dumps(get_summary(workspace_dir=target_dir), indent=2)
|
|
4771
|
+
return render_report(workspace_dir=target_dir)
|
|
4772
|
+
|
|
4741
4773
|
# Fallback to general dispatch
|
|
4742
4774
|
handler = _CANONICAL_DISPATCH.get(act) or _LEGACY_DISPATCH.get(act)
|
|
4743
4775
|
if handler:
|
|
@@ -4759,7 +4791,7 @@ def create_mcp_server():
|
|
|
4759
4791
|
f"ā Unknown action '{act}'.\n"
|
|
4760
4792
|
f"Supported actions: 'auto', 'context', 'audit', 'security', 'blueprint', 'dependencies', "
|
|
4761
4793
|
f"'impact', 'search', 'prune', 'rules', 'enforce', 'cost', 'memory', 'swarm', 'heal', 'design', "
|
|
4762
|
-
f"'patch', 'pagerank', 'dead_code', 'duplicity', 'call_chain', 'sync', 'roi', 'drift', 'ci', 'local_ci', "
|
|
4794
|
+
f"'patch', 'pagerank', 'dead_code', 'duplicity', 'call_chain', 'sync', 'roi', 'drift', 'telemetry', 'ci', 'local_ci', "
|
|
4763
4795
|
f"'armor', 'anti_rea', 'audit_rea'."
|
|
4764
4796
|
)
|
|
4765
4797
|
|
|
@@ -5202,27 +5234,43 @@ def create_mcp_server():
|
|
|
5202
5234
|
)
|
|
5203
5235
|
def resource_file_skeleton(path: str) -> str:
|
|
5204
5236
|
import urllib.parse
|
|
5205
|
-
ws_root = os.path.abspath(".")
|
|
5237
|
+
ws_root = os.path.realpath(os.path.abspath("."))
|
|
5206
5238
|
rel_clean = urllib.parse.unquote(path or "").lstrip("/\\")
|
|
5207
5239
|
if not rel_clean or ".." in rel_clean.replace("\\", "/").split("/"):
|
|
5208
5240
|
return f"[BLOCKED] Unsafe relative path blocked: {rel_clean or path}"
|
|
5209
|
-
|
|
5241
|
+
joined = os.path.abspath(os.path.join(ws_root, rel_clean))
|
|
5242
|
+
if os.path.islink(joined):
|
|
5243
|
+
return f"[BLOCKED] Symlink traversal blocked: {path}"
|
|
5244
|
+
real_target = os.path.realpath(joined)
|
|
5210
5245
|
try:
|
|
5211
|
-
if os.path.commonpath([ws_root,
|
|
5212
|
-
return f"[BLOCKED]
|
|
5246
|
+
if os.path.commonpath([ws_root, real_target]) != ws_root:
|
|
5247
|
+
return f"[BLOCKED] Real path escapes workspace root: {path}"
|
|
5213
5248
|
except ValueError:
|
|
5214
5249
|
return f"[BLOCKED] Invalid workspace path: {path}"
|
|
5215
|
-
if not os.path.isfile(
|
|
5250
|
+
if not os.path.isfile(real_target):
|
|
5216
5251
|
return f"[ERROR] File not found: {rel_clean}"
|
|
5217
5252
|
try:
|
|
5218
|
-
|
|
5219
|
-
|
|
5253
|
+
open_flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0)
|
|
5254
|
+
fd = os.open(real_target, open_flags)
|
|
5255
|
+
try:
|
|
5256
|
+
st_expected = os.stat(real_target)
|
|
5257
|
+
st_opened = os.fstat(fd)
|
|
5258
|
+
if st_expected.st_ino and st_opened.st_ino and (st_expected.st_ino != st_opened.st_ino or st_expected.st_dev != st_opened.st_dev):
|
|
5259
|
+
return f"[BLOCKED] Target identity changed during open: {path}"
|
|
5260
|
+
with os.fdopen(fd, "r", encoding="utf-8", errors="replace") as fp:
|
|
5261
|
+
fd = -1
|
|
5262
|
+
raw_code = fp.read()
|
|
5263
|
+
finally:
|
|
5264
|
+
if fd >= 0:
|
|
5265
|
+
os.close(fd)
|
|
5220
5266
|
from tzero.tzero_polyglot import PolyglotTokenReducer
|
|
5221
|
-
reduced = PolyglotTokenReducer.reduce_code(raw_code, filename=
|
|
5267
|
+
reduced = PolyglotTokenReducer.reduce_code(raw_code, filename=real_target, mode="ultra")
|
|
5222
5268
|
from tzero.tzero_security import ZeroLeakEngine
|
|
5223
5269
|
if ZeroLeakEngine.scan_text(reduced):
|
|
5224
5270
|
reduced = ZeroLeakEngine.sanitize_text(reduced)
|
|
5225
5271
|
return reduced
|
|
5272
|
+
except OSError as e:
|
|
5273
|
+
return f"[BLOCKED] Unsafe or inaccessible file '{rel_clean}': {e}"
|
|
5226
5274
|
except Exception as e:
|
|
5227
5275
|
return f"[ERROR] Failed to extract skeleton for '{rel_clean}': {e}"
|
|
5228
5276
|
|