tzero-mcp 12.3.2 → 12.3.5
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/CONTRIBUTING.md +1 -1
- package/README.md +4 -0
- package/package.json +3 -4
- package/src/addmcp.py +2 -2
- package/src/app.py +1 -1
- package/src/main.py +4 -0
- package/src/tzero/__init__.py +1 -1
- package/src/tzero/desktop_updater.py +6 -0
- package/src/tzero/tzero_benchmark.py +1 -1
- package/src/tzero/tzero_budget.py +1 -1
- package/src/tzero/tzero_ci.py +1 -1
- package/src/tzero/tzero_contracts.py +2 -2
- package/src/tzero/tzero_dashboard.py +3 -3
- package/src/tzero/tzero_debt.py +85 -7
- package/src/tzero/tzero_deps.py +1 -0
- package/src/tzero/tzero_explain.py +1 -1
- package/src/tzero/tzero_features.py +31 -74
- package/src/tzero/tzero_golden.py +2 -2
- package/src/tzero/tzero_graph_hud.html +4 -4
- package/src/tzero/tzero_growth.py +1 -1
- package/src/tzero/tzero_jarvis/orchestrator.py +1 -1
- package/src/tzero/tzero_jarvis/swarm.py +23 -2
- package/src/tzero/tzero_jarvis/workspace_orchestrator.py +10 -21
- package/src/tzero/tzero_lsp.py +1 -1
- package/src/tzero/tzero_mcp.py +39 -122
- package/src/tzero/tzero_promo.py +1 -1
- package/src/tzero/tzero_security.py +3 -3
- package/src/tzero/tzero_sync.py +73 -148
- package/src/tzero/tzero_task_benchmark.py +2 -2
- package/src/tzero/tzero_traffic.py +1 -1
- package/src/tzero/tzero_tui.py +2 -13
- package/src/tzero/tzero_v3.py +433 -392
- package/src/tzero/tzero_welcome.py +1 -1
- package/src/tzero/anti_rea/__init__.py +0 -84
- package/src/tzero/anti_rea/algebraic_mutator.py +0 -107
- package/src/tzero/anti_rea/anti_agent_guard.py +0 -96
- package/src/tzero/anti_rea/anti_debugger.py +0 -272
- package/src/tzero/anti_rea/anti_vm.py +0 -160
- package/src/tzero/anti_rea/asar_shield.py +0 -122
- package/src/tzero/anti_rea/auditor.py +0 -208
- package/src/tzero/anti_rea/bpe_disrupter.py +0 -48
- package/src/tzero/anti_rea/bytecode_trap.py +0 -85
- package/src/tzero/anti_rea/canary_beacon.py +0 -167
- package/src/tzero/anti_rea/cli.py +0 -134
- package/src/tzero/anti_rea/confusables.py +0 -130
- package/src/tzero/anti_rea/crypto_loader.py +0 -132
- package/src/tzero/anti_rea/engine.py +0 -304
- package/src/tzero/anti_rea/extractor_shield.py +0 -180
- package/src/tzero/anti_rea/flattener.py +0 -136
- package/src/tzero/anti_rea/gui.py +0 -264
- package/src/tzero/anti_rea/honeypot.py +0 -58
- package/src/tzero/anti_rea/integrity_guard.py +0 -78
- package/src/tzero/anti_rea/jailbreak_decoy.py +0 -77
- package/src/tzero/anti_rea/mcp_poison.py +0 -41
- package/src/tzero/anti_rea/native_bridge.py +0 -169
- package/src/tzero/anti_rea/rdtsc_guard.py +0 -77
- package/src/tzero/anti_rea/string_vault.py +0 -97
- package/src/tzero/anti_rea/sybil_network.py +0 -53
- package/src/tzero/anti_rea/tier_catalog.py +0 -388
- package/src/tzero/anti_rea/timing_guard.py +0 -46
- package/src/tzero/anti_rea/token_bomb.py +0 -65
- package/src/tzero/anti_rea/traps.py +0 -76
- package/src/tzero/anti_rea/vm_obfuscator.py +0 -182
- package/src/tzero/tzero_armor.py +0 -187
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.3.
|
|
36
|
+
SERVER_VERSION = "12.3.5"
|
|
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
|
|
@@ -1163,8 +1163,8 @@ def create_mcp_server():
|
|
|
1163
1163
|
"- `target` (str, optional, default='all'): Target editor format: 'cursor', 'cline', 'windsurf', 'claude', 'copilot', or 'all'.\n"
|
|
1164
1164
|
"\n"
|
|
1165
1165
|
"Behavior:\n"
|
|
1166
|
-
"- Mutating: Creates
|
|
1167
|
-
"- Idempotent:
|
|
1166
|
+
"- Mutating: Creates missing configuration files in the target workspace directory.\n"
|
|
1167
|
+
"- Idempotent: Leaves existing files untouched.\n"
|
|
1168
1168
|
"- 100% Offline: Generates rule files locally using built-in templates with zero network requests.\n"
|
|
1169
1169
|
"- Auth & Rate Limits: Zero authentication or cloud credentials required; completes in <50ms.\n"
|
|
1170
1170
|
"- Error Handling: Defaults to standard T-Zero engineering templates if workspace configuration is empty.\n"
|
|
@@ -1183,45 +1183,7 @@ def create_mcp_server():
|
|
|
1183
1183
|
) -> str:
|
|
1184
1184
|
"""Exports AI coding agent rules into workspace."""
|
|
1185
1185
|
from tzero.tzero_features import AgentRulesGenerator
|
|
1186
|
-
|
|
1187
|
-
t = (target or "all").lower().strip()
|
|
1188
|
-
created = []
|
|
1189
|
-
if t in ("cursor", "cursorrules"):
|
|
1190
|
-
cr_path = os.path.join(project_root, ".cursorrules")
|
|
1191
|
-
with open(cr_path, "w", encoding="utf-8") as f:
|
|
1192
|
-
f.write(AgentRulesGenerator.generate_cursorrules(p_name))
|
|
1193
|
-
created.append(cr_path)
|
|
1194
|
-
c_rules_dir = os.path.join(project_root, ".cursor", "rules")
|
|
1195
|
-
os.makedirs(c_rules_dir, exist_ok=True)
|
|
1196
|
-
for mdc_name, content in AgentRulesGenerator.generate_cursor_mdc_rules(p_name, project_dir=project_root).items():
|
|
1197
|
-
mdc_path = os.path.join(c_rules_dir, mdc_name)
|
|
1198
|
-
with open(mdc_path, "w", encoding="utf-8") as f:
|
|
1199
|
-
f.write(content)
|
|
1200
|
-
created.append(mdc_path)
|
|
1201
|
-
elif t in ("cline", "clinerules"):
|
|
1202
|
-
cl_path = os.path.join(project_root, ".clinerules")
|
|
1203
|
-
with open(cl_path, "w", encoding="utf-8") as f:
|
|
1204
|
-
f.write(AgentRulesGenerator.generate_clinerules(p_name))
|
|
1205
|
-
created.append(cl_path)
|
|
1206
|
-
elif t in ("windsurf", "windsurfrules"):
|
|
1207
|
-
ws_path = os.path.join(project_root, ".windsurfrules")
|
|
1208
|
-
with open(ws_path, "w", encoding="utf-8") as f:
|
|
1209
|
-
f.write(AgentRulesGenerator.generate_windsurfrules(p_name))
|
|
1210
|
-
created.append(ws_path)
|
|
1211
|
-
elif t in ("claude", "claudemd"):
|
|
1212
|
-
claude_path = os.path.join(project_root, "CLAUDE.md")
|
|
1213
|
-
with open(claude_path, "w", encoding="utf-8") as f:
|
|
1214
|
-
f.write(AgentRulesGenerator.generate_claude_instructions(p_name))
|
|
1215
|
-
created.append(claude_path)
|
|
1216
|
-
elif t in ("copilot", "github"):
|
|
1217
|
-
gh_dir = os.path.join(project_root, ".github")
|
|
1218
|
-
os.makedirs(gh_dir, exist_ok=True)
|
|
1219
|
-
copilot_path = os.path.join(gh_dir, "copilot-instructions.md")
|
|
1220
|
-
with open(copilot_path, "w", encoding="utf-8") as f:
|
|
1221
|
-
f.write(AgentRulesGenerator.generate_copilot_instructions(p_name))
|
|
1222
|
-
created.append(copilot_path)
|
|
1223
|
-
else:
|
|
1224
|
-
created = AgentRulesGenerator.export_all(project_root)
|
|
1186
|
+
created = AgentRulesGenerator.export_all(project_root, target)
|
|
1225
1187
|
rel_paths = [os.path.relpath(p, project_root) for p in created]
|
|
1226
1188
|
return "✅ Generated AI Agent rule files:\n" + "\n".join(f"- `{p}`" for p in rel_paths)
|
|
1227
1189
|
|
|
@@ -3433,16 +3395,34 @@ def create_mcp_server():
|
|
|
3433
3395
|
)
|
|
3434
3396
|
def audit_code_quality(
|
|
3435
3397
|
project_root: Annotated[str, Field(default=".", description="Root directory of the repository to audit (default: current directory).")] = ".",
|
|
3436
|
-
check_type: Annotated[str, Field(default="all", description="Audit scope: 'all' for complete check, 'smells' for code complexity/smells, 'duplicity' for copy-paste blocks, 'hallucinations' for invalid imports/signatures.")] = "all",
|
|
3398
|
+
check_type: Annotated[str, Field(default="all", description="Audit scope: 'all' for complete check, 'smells' for code complexity/smells, 'duplicity' for copy-paste blocks, 'hallucinations' for invalid imports/signatures, 'debt' for TODO/FIXME/HACK/XXX/TEMP markers grouped by scope with estimated remediation hours.")] = "all",
|
|
3437
3399
|
file_path: Annotated[str, Field(default="", description="Optional path to a single file to audit.")] = ""
|
|
3438
3400
|
) -> str:
|
|
3439
|
-
"""Audits AST code smells, cyclomatic complexity, copy-paste duplicity, and
|
|
3401
|
+
"""Audits AST code smells, cyclomatic complexity, copy-paste duplicity, hallucinations, and debt markers."""
|
|
3440
3402
|
c_type = (check_type or "all").lower().strip()
|
|
3441
3403
|
if c_type == "duplicity":
|
|
3442
3404
|
return _legacy_find_code_duplicity(project_root=project_root, min_lines=6)
|
|
3443
3405
|
elif c_type == "hallucinations":
|
|
3444
3406
|
target = file_path or project_root
|
|
3445
3407
|
return _legacy_verify_hallucination_guard(candidate_code=target, project_root=project_root)
|
|
3408
|
+
elif c_type == "debt":
|
|
3409
|
+
from tzero.tzero_debt import CodeHealthAnalyzer, WorkspaceHealthReport, format_debt_markers_markdown
|
|
3410
|
+
target = file_path or project_root
|
|
3411
|
+
if os.path.isfile(target):
|
|
3412
|
+
fr = CodeHealthAnalyzer.analyze_file(target)
|
|
3413
|
+
single = WorkspaceHealthReport(
|
|
3414
|
+
workspace_root=os.path.dirname(os.path.abspath(target)),
|
|
3415
|
+
total_files=1,
|
|
3416
|
+
total_lines_of_code=fr.lines_of_code,
|
|
3417
|
+
average_maintainability_index=fr.maintainability_index,
|
|
3418
|
+
overall_rating=fr.rating,
|
|
3419
|
+
total_debt_hours=fr.debt_hours,
|
|
3420
|
+
total_debt_cost_usd=fr.debt_cost_usd,
|
|
3421
|
+
total_todo_markers=fr.todo_count,
|
|
3422
|
+
file_reports=[fr],
|
|
3423
|
+
)
|
|
3424
|
+
return format_debt_markers_markdown(single)
|
|
3425
|
+
return format_debt_markers_markdown(CodeHealthAnalyzer.analyze_workspace(target))
|
|
3446
3426
|
else:
|
|
3447
3427
|
return _legacy_audit_codebase_quality(project_root=project_root, file_path=file_path)
|
|
3448
3428
|
|
|
@@ -3527,7 +3507,7 @@ def create_mcp_server():
|
|
|
3527
3507
|
) -> str:
|
|
3528
3508
|
"""Calculates token counts, commercial provider pricing estimates, and developer ROI savings."""
|
|
3529
3509
|
if export_agent_rules:
|
|
3530
|
-
return _legacy_export_agent_rules(
|
|
3510
|
+
return _legacy_export_agent_rules(target=export_agent_rules, project_root=project_root)
|
|
3531
3511
|
return _legacy_estimate_token_cost(text=text, project_root=project_root, reduction_mode="ultra")
|
|
3532
3512
|
|
|
3533
3513
|
# -------------------------------------------------------------------------
|
|
@@ -3931,42 +3911,33 @@ def create_mcp_server():
|
|
|
3931
3911
|
|
|
3932
3912
|
@_maybe_tool(
|
|
3933
3913
|
name="sync_workspace_rules",
|
|
3934
|
-
title="
|
|
3914
|
+
title="Preview Multi-Agent Rule Synchronization",
|
|
3935
3915
|
description=(
|
|
3936
|
-
"
|
|
3937
|
-
"\n"
|
|
3938
|
-
"
|
|
3939
|
-
"
|
|
3940
|
-
"
|
|
3941
|
-
"
|
|
3942
|
-
"
|
|
3943
|
-
"-
|
|
3944
|
-
"-
|
|
3945
|
-
"
|
|
3946
|
-
"- Error Handling: Skips unparseable modules gracefully while indexing valid symbols.\n"
|
|
3947
|
-
"\n"
|
|
3948
|
-
"Usage Guidelines:\n"
|
|
3949
|
-
"- When to use: Use when syncing fresh codebase AST symbols into Cursor, Claude Code, Windsurf, and Git hooks.\n"
|
|
3950
|
-
"- When NOT to use: Do not use if you only want to generate static rules without installing Git hooks (use 'export_agent_rules' instead).\n"
|
|
3951
|
-
"\n"
|
|
3952
|
-
"Returns: Formatted Markdown summary of synchronized files and indexed AST symbols."
|
|
3916
|
+
"Previews workspace rule generation, distinguishing from 'export_agent_rules', which can create missing rule files.\n"
|
|
3917
|
+
"\nParameters:\n"
|
|
3918
|
+
"- `workspace_dir` (str, optional, default='.'): Workspace directory to scan.\n"
|
|
3919
|
+
"\nBehavior:\n"
|
|
3920
|
+
"- Read-only: Scans local Python symbols, writes no rule files, and installs no Git hooks.\n"
|
|
3921
|
+
"- Auth & Rate Limits: Uses no network or external credentials.\n"
|
|
3922
|
+
"\nUsage Guidelines:\n"
|
|
3923
|
+
"- When to use: Check which rule files a workspace sync could create.\n"
|
|
3924
|
+
"- When NOT to use: To create missing files, use the CLI with --apply-sync.\n"
|
|
3925
|
+
"\nReturns: Markdown with candidate files and AST symbol counts."
|
|
3953
3926
|
),
|
|
3954
|
-
annotations=ToolAnnotations(read_only_hint=
|
|
3927
|
+
annotations=ToolAnnotations(read_only_hint=True, destructive_hint=False, idempotent_hint=True, open_world_hint=False)
|
|
3955
3928
|
)
|
|
3956
3929
|
def sync_workspace_rules(
|
|
3957
3930
|
workspace_dir: Annotated[str, Field(default=".", description="Target repository root directory (default: current directory).")] = "."
|
|
3958
3931
|
) -> str:
|
|
3959
|
-
"""
|
|
3932
|
+
"""Preview workspace rule generation."""
|
|
3960
3933
|
from tzero.tzero_sync import WorkspaceSyncManager
|
|
3961
3934
|
res = WorkspaceSyncManager.sync(workspace_dir)
|
|
3962
|
-
files_str = "\n".join(f"- `{f}`" for f in res.synced_files)
|
|
3963
3935
|
return (
|
|
3964
3936
|
f"# ⚡ T-Zero Autonomous Rules Synchronization\n\n"
|
|
3965
3937
|
f"- **Workspace:** `{res.workspace_dir}`\n"
|
|
3966
3938
|
f"- **Modules Scanned:** {res.modules_scanned}\n"
|
|
3967
3939
|
f"- **AST Symbols Indexed:** {res.symbols_indexed}\n"
|
|
3968
3940
|
f"- **Zero-Leak Security:** {res.zero_leak_status}\n\n"
|
|
3969
|
-
f"### Synchronized Directives:\n{files_str}\n\n"
|
|
3970
3941
|
f"**Status:** {res.summary_message}"
|
|
3971
3942
|
)
|
|
3972
3943
|
|
|
@@ -4792,7 +4763,7 @@ def create_mcp_server():
|
|
|
4792
4763
|
f"Supported actions: 'auto', 'context', 'audit', 'security', 'blueprint', 'dependencies', "
|
|
4793
4764
|
f"'impact', 'search', 'prune', 'rules', 'enforce', 'cost', 'memory', 'swarm', 'heal', 'design', "
|
|
4794
4765
|
f"'patch', 'pagerank', 'dead_code', 'duplicity', 'call_chain', 'sync', 'roi', 'drift', 'telemetry', 'ci', 'local_ci', "
|
|
4795
|
-
f"
|
|
4766
|
+
f"See the tool list for available actions."
|
|
4796
4767
|
)
|
|
4797
4768
|
|
|
4798
4769
|
def run_local_ci(quick: bool = False, auto_fix: bool = False, install_hook: bool = False, uninstall_hook: bool = False, project_root: str = ".") -> str:
|
|
@@ -4815,63 +4786,9 @@ def create_mcp_server():
|
|
|
4815
4786
|
+ "\n".join([f"- [{'PASS' if s.passed else 'FAIL'}] **{s.name}** ({s.duration:.2f}s): {s.output or s.error}" for s in report.steps])
|
|
4816
4787
|
)
|
|
4817
4788
|
|
|
4818
|
-
def armor_against_ai_reverse_engineering(target: str = ".", output_path: str = "") -> str:
|
|
4819
|
-
"""Applies military-grade Anti-REA code and binary protection against AI reverse-engineering agents."""
|
|
4820
|
-
from tzero.tzero_armor import protect_path_with_armor
|
|
4821
|
-
res = protect_path_with_armor(target, output_path=output_path or None)
|
|
4822
|
-
if not res.get("success"):
|
|
4823
|
-
return f"❌ Anti-REA protection failed: {res.get('error', 'Unknown error')}"
|
|
4824
|
-
|
|
4825
|
-
if "score_after" in res:
|
|
4826
|
-
return (
|
|
4827
|
-
f"### 🛡️ T-Zero Anti-REA Military Armor Report\n"
|
|
4828
|
-
f"- **Target File:** `{res['output_file']}`\n"
|
|
4829
|
-
f"- **AI Resistance Score:** `{res['score_before']}/100` ➔ `{res['score_after']}/100`\n"
|
|
4830
|
-
f"- **Rating:** `{res['rating']}`\n"
|
|
4831
|
-
f"- **Status:** `ACTIVE` (Protected against morluto/rea, Ghidra MCP, pyinstxtractor)\n"
|
|
4832
|
-
)
|
|
4833
|
-
elif "files_protected" in res:
|
|
4834
|
-
return (
|
|
4835
|
-
f"### 🛡️ T-Zero Anti-REA Codebase Armor Report\n"
|
|
4836
|
-
f"- **Directory:** `{res['directory']}`\n"
|
|
4837
|
-
f"- **Files Protected:** `{res['files_protected']}`\n"
|
|
4838
|
-
f"- **Status:** `ACTIVE` (All Python modules hardened with Anti-REA defense matrix)\n"
|
|
4839
|
-
)
|
|
4840
|
-
return json.dumps(res, indent=2)
|
|
4841
|
-
|
|
4842
|
-
def audit_ai_decompilation_resistance(target: str = ".") -> str:
|
|
4843
|
-
"""Audits target code or binary for resistance against AI reverse engineering (0-100 score)."""
|
|
4844
|
-
from tzero.tzero_armor import audit_path_rea_resistance
|
|
4845
|
-
audit = audit_path_rea_resistance(target)
|
|
4846
|
-
if not audit.get("success", True):
|
|
4847
|
-
return f"❌ Audit failed: {audit.get('error', 'Unknown error')}"
|
|
4848
|
-
|
|
4849
|
-
report = [
|
|
4850
|
-
f"### 🛡️ AI Reverse-Engineering Resistance Audit (TDQS-REA)",
|
|
4851
|
-
f"- **Target:** `{target}`",
|
|
4852
|
-
f"- **Resistance Score:** `{audit.get('score', 0)} / 100` (`{audit.get('rating', 'UNKNOWN')}`)",
|
|
4853
|
-
f"- **Status:** `{audit.get('status', 'N/A')}`\n",
|
|
4854
|
-
f"#### Active Defenses:",
|
|
4855
|
-
]
|
|
4856
|
-
for k, v in audit.get("defenses_active", {}).items():
|
|
4857
|
-
report.append(f"- [{'✔' if v else ' '}] **{k}**")
|
|
4858
|
-
|
|
4859
|
-
recs = audit.get("sample_findings") or audit.get("findings", [])
|
|
4860
|
-
if recs:
|
|
4861
|
-
report.append("\n#### Hardening Recommendations:")
|
|
4862
|
-
for r in recs:
|
|
4863
|
-
report.append(f"- ⚠️ {r}")
|
|
4864
|
-
|
|
4865
|
-
return "\n".join(report)
|
|
4866
|
-
|
|
4867
4789
|
# Register canonical mappings
|
|
4868
4790
|
_CANONICAL_DISPATCH['execute_codebase_workflow'] = execute_codebase_workflow
|
|
4869
4791
|
_CANONICAL_DISPATCH['run_codebase_autopilot'] = execute_codebase_workflow
|
|
4870
|
-
_CANONICAL_DISPATCH['armor_against_ai_reverse_engineering'] = armor_against_ai_reverse_engineering
|
|
4871
|
-
_CANONICAL_DISPATCH['armor'] = armor_against_ai_reverse_engineering
|
|
4872
|
-
_CANONICAL_DISPATCH['anti_rea'] = armor_against_ai_reverse_engineering
|
|
4873
|
-
_CANONICAL_DISPATCH['audit_ai_decompilation_resistance'] = audit_ai_decompilation_resistance
|
|
4874
|
-
_CANONICAL_DISPATCH['audit_rea'] = audit_ai_decompilation_resistance
|
|
4875
4792
|
_CANONICAL_DISPATCH['build_project_context'] = build_project_context
|
|
4876
4793
|
_CANONICAL_DISPATCH['prune_code_snippet'] = prune_code_snippet
|
|
4877
4794
|
_CANONICAL_DISPATCH['manage_architecture_rules'] = manage_architecture_rules
|
package/src/tzero/tzero_promo.py
CHANGED
|
@@ -55,7 +55,7 @@ PLACEHOLDER_SUBSTRINGS = (
|
|
|
55
55
|
"YOUR_API_KEY", "YOUR-API-KEY", "YOUR_SECRET", "YOUR_TOKEN",
|
|
56
56
|
"YOUR-", "YOUR_", "ENTER_YOUR", "PLACEHOLDER", "CHANGEME", "INSERT_HERE",
|
|
57
57
|
"000000000000", "EXAMPLE_KEY", "EXAMPLEKEY", "EXAMPLE_SECRET",
|
|
58
|
-
"MOCK_KEY_PLACEHOLDER"
|
|
58
|
+
"MOCK_KEY_PLACEHOLDER"
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
|
|
@@ -302,7 +302,7 @@ class ZeroLeakEngine:
|
|
|
302
302
|
def is_placeholder(cls, s: str) -> bool:
|
|
303
303
|
"""Determines if a candidate string is an intentional placeholder/mock."""
|
|
304
304
|
up = s.upper()
|
|
305
|
-
return any(ph in up for ph in PLACEHOLDER_SUBSTRINGS)
|
|
305
|
+
return up in {"MOCK", "DEMO"} or any(ph in up for ph in PLACEHOLDER_SUBSTRINGS)
|
|
306
306
|
|
|
307
307
|
@classmethod
|
|
308
308
|
def is_natural_or_identifier(cls, s: str) -> bool:
|
|
@@ -387,7 +387,7 @@ class ZeroLeakEngine:
|
|
|
387
387
|
val = match.group(1)
|
|
388
388
|
else:
|
|
389
389
|
val = match.group(0)
|
|
390
|
-
if cls.is_placeholder(val)
|
|
390
|
+
if cls.is_placeholder(val):
|
|
391
391
|
continue
|
|
392
392
|
|
|
393
393
|
ent = calculate_shannon_entropy(val)
|
package/src/tzero/tzero_sync.py
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Siber Akademi — T-Zero Autonomous Multi-IDE Rules & Context Synchronizer.
|
|
4
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
-
License: MIT
|
|
6
|
-
|
|
7
|
-
Synchronizes current codebase AST topologies, helper catalogs, architecture layers,
|
|
8
|
-
and Zero-Leak security rules into:
|
|
9
|
-
1. .cursorrules & .cursor/rules/*.mdc (Cursor IDE)
|
|
10
|
-
2. CLAUDE.md (Claude Code & Claude Desktop)
|
|
11
|
-
3. .windsurfrules (Windsurf Cascade)
|
|
12
|
-
4. .agents/rules/tzero-context.md (Antigravity IDE & Autonomous Agents)
|
|
13
|
-
5. .git/hooks/pre-commit (Git Zero-Leak Security Guard)
|
|
14
|
-
"""
|
|
2
|
+
"""Preview and create local editor context files."""
|
|
15
3
|
|
|
16
|
-
import
|
|
17
|
-
import sys
|
|
4
|
+
import argparse
|
|
18
5
|
import ast
|
|
19
6
|
import json
|
|
7
|
+
import os
|
|
20
8
|
from dataclasses import dataclass, field
|
|
21
|
-
from
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any, Dict, List
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_workspace_file(root: str, relative_path: str, content: str) -> bool:
|
|
14
|
+
"""Create a new file and skip existing paths and redirected subdirectories."""
|
|
15
|
+
relative = Path(relative_path)
|
|
16
|
+
if relative.anchor or ".." in relative.parts:
|
|
17
|
+
return False
|
|
18
|
+
parent = Path(root).resolve()
|
|
19
|
+
for part in relative.parts[:-1]:
|
|
20
|
+
parent /= part
|
|
21
|
+
if parent.resolve() != parent or parent.is_symlink():
|
|
22
|
+
return False
|
|
23
|
+
parent.mkdir(exist_ok=True)
|
|
24
|
+
try:
|
|
25
|
+
with (parent / relative.name).open("x", encoding="utf-8") as output:
|
|
26
|
+
output.write(content)
|
|
27
|
+
except FileExistsError:
|
|
28
|
+
return False
|
|
29
|
+
return True
|
|
25
30
|
|
|
26
31
|
|
|
27
32
|
@dataclass
|
|
@@ -81,137 +86,53 @@ class WorkspaceSyncManager:
|
|
|
81
86
|
"function_count": len(functions)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
@
|
|
85
|
-
def
|
|
86
|
-
"""
|
|
87
|
-
|
|
88
|
-
# Workspace
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# Verification Command
|
|
104
|
-
Run verification before completing any task:
|
|
105
|
-
$ python -m unittest discover tests -v
|
|
106
|
-
"""
|
|
89
|
+
@staticmethod
|
|
90
|
+
def render_context(workspace_name: str, symbols: Dict[str, Any]) -> str:
|
|
91
|
+
"""Describe scanned workspace contents without issuing agent directives."""
|
|
92
|
+
lines = [
|
|
93
|
+
"# Workspace context generated by tzero sync",
|
|
94
|
+
"",
|
|
95
|
+
"This report lists symbols discovered by static analysis.",
|
|
96
|
+
"",
|
|
97
|
+
f"- Workspace: {json.dumps(workspace_name)}",
|
|
98
|
+
f"- Python modules: {symbols['module_count']}",
|
|
99
|
+
f"- Top-level classes: {symbols['class_count']}",
|
|
100
|
+
f"- Public top-level functions: {symbols['function_count']}",
|
|
101
|
+
"",
|
|
102
|
+
"## Selected symbols",
|
|
103
|
+
]
|
|
104
|
+
lines.extend(f"- {json.dumps(symbol)}" for symbol in symbols["classes"][:20])
|
|
105
|
+
lines.extend(f"- {json.dumps(symbol)}" for symbol in symbols["functions"][:25])
|
|
106
|
+
return "\n".join(lines) + "\n"
|
|
107
107
|
|
|
108
108
|
@classmethod
|
|
109
|
-
def
|
|
110
|
-
"""
|
|
111
|
-
return f"""# CLAUDE.md — Architecture & Operational Directives (Generated by tzero sync)
|
|
112
|
-
> Workspace: `{workspace_name}` | Engine: T-Zero Context Architect | Security: 100% Zero-Leak Certified
|
|
113
|
-
|
|
114
|
-
## Executive Mission
|
|
115
|
-
Execute all coding, refactoring, and debugging tasks with minimal blast radius, zero regressions, and maximum token efficiency.
|
|
116
|
-
|
|
117
|
-
## Quickstart & Verification Pipeline
|
|
118
|
-
```bash
|
|
119
|
-
# 1. Run Complete Test Suite
|
|
120
|
-
python -m unittest discover tests -v
|
|
121
|
-
|
|
122
|
-
# 2. Run T-Zero Security & AST Audit
|
|
123
|
-
tzero audit .
|
|
124
|
-
|
|
125
|
-
# 3. Synchronize AI Context
|
|
126
|
-
tzero sync
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Ground-Truth Architecture Symbols
|
|
130
|
-
- **Active Modules:** {symbols['module_count']} core files
|
|
131
|
-
- **Primary Classes:**
|
|
132
|
-
{chr(10).join(f" * `{c}`" for c in symbols['classes'][:15])}
|
|
133
|
-
- **Primary Public Functions:**
|
|
134
|
-
{chr(10).join(f" * `{f}`" for f in symbols['functions'][:20])}
|
|
135
|
-
|
|
136
|
-
## Security & Zero-Leak Policy
|
|
137
|
-
- All secrets, API keys, and sensitive database credentials must be kept out of commits.
|
|
138
|
-
- Hardcoded secrets will be intercepted and blocked by the T-Zero Git Pre-Commit Guard.
|
|
139
|
-
"""
|
|
140
|
-
|
|
141
|
-
@classmethod
|
|
142
|
-
def generate_windsurfrules(cls, workspace_name: str, symbols: Dict[str, Any]) -> str:
|
|
143
|
-
"""Generates tailored .windsurfrules file for Windsurf Cascade."""
|
|
144
|
-
return f"""# Windsurf Cascade Rules for {workspace_name} (Generated by tzero sync)
|
|
145
|
-
- Maintain 100% Zero-Leak security standards.
|
|
146
|
-
- Prefer existing helper functions in the repository AST before generating new ones.
|
|
147
|
-
- Run tests (`python -m unittest discover tests -v`) before asserting task completion.
|
|
148
|
-
- Key modules in this workspace: {', '.join(symbols['modules'][:10])}.
|
|
149
|
-
"""
|
|
150
|
-
|
|
151
|
-
@classmethod
|
|
152
|
-
def sync(cls, workspace_dir: str = ".") -> SyncResult:
|
|
153
|
-
"""Executes full autonomous synchronization across IDEs and Git hooks."""
|
|
109
|
+
def sync(cls, workspace_dir: str = ".", *, apply: bool = False) -> SyncResult:
|
|
110
|
+
"""Preview rule generation by default; never overwrite files or install hooks."""
|
|
154
111
|
abs_root = os.path.abspath(workspace_dir)
|
|
155
112
|
workspace_name = os.path.basename(abs_root) or "TZeroAlgorithm"
|
|
156
|
-
|
|
157
|
-
synced_files: List[str] = []
|
|
158
|
-
|
|
159
|
-
# 1. Extract AST symbols
|
|
160
113
|
symbols = cls.scan_symbols(abs_root)
|
|
161
114
|
total_symbols = symbols["class_count"] + symbols["function_count"]
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
with open(claude_path, "w", encoding="utf-8") as f:
|
|
176
|
-
f.write(cls.generate_claudemd(workspace_name, symbols))
|
|
177
|
-
synced_files.append("CLAUDE.md")
|
|
178
|
-
except Exception:
|
|
179
|
-
pass
|
|
180
|
-
|
|
181
|
-
# 4. Update .windsurfrules
|
|
182
|
-
windsurf_path = os.path.join(abs_root, ".windsurfrules")
|
|
183
|
-
try:
|
|
184
|
-
with open(windsurf_path, "w", encoding="utf-8") as f:
|
|
185
|
-
f.write(cls.generate_windsurfrules(workspace_name, symbols))
|
|
186
|
-
synced_files.append(".windsurfrules")
|
|
187
|
-
except Exception:
|
|
188
|
-
pass
|
|
189
|
-
|
|
190
|
-
# 5. Ensure .agents rules directory is synchronized if present
|
|
191
|
-
agents_rules_dir = os.path.join(abs_root, ".agents", "rules")
|
|
192
|
-
if os.path.isdir(os.path.join(abs_root, ".agents")):
|
|
193
|
-
os.makedirs(agents_rules_dir, exist_ok=True)
|
|
194
|
-
agent_rule_path = os.path.join(agents_rules_dir, "tzero-context.md")
|
|
195
|
-
try:
|
|
196
|
-
with open(agent_rule_path, "w", encoding="utf-8") as f:
|
|
197
|
-
f.write(cls.generate_claudemd(workspace_name, symbols))
|
|
198
|
-
synced_files.append(".agents/rules/tzero-context.md")
|
|
199
|
-
except Exception:
|
|
200
|
-
pass
|
|
201
|
-
|
|
202
|
-
# 6. Verify / install Git Pre-Commit Security Hook
|
|
203
|
-
hook_res = GitSecurityGuard.install_hook(abs_root)
|
|
204
|
-
if hook_res.get("success"):
|
|
205
|
-
synced_files.append(".git/hooks/pre-commit")
|
|
206
|
-
|
|
115
|
+
candidates = (".cursorrules", "CLAUDE.md", ".windsurfrules")
|
|
116
|
+
created = []
|
|
117
|
+
skipped = []
|
|
118
|
+
if apply:
|
|
119
|
+
content = cls.render_context(workspace_name, symbols)
|
|
120
|
+
for name in candidates:
|
|
121
|
+
try:
|
|
122
|
+
if create_workspace_file(abs_root, name, content):
|
|
123
|
+
created.append(name)
|
|
124
|
+
else:
|
|
125
|
+
skipped.append(name)
|
|
126
|
+
except OSError as exc:
|
|
127
|
+
skipped.append(f"{name} ({exc})")
|
|
207
128
|
return SyncResult(
|
|
208
|
-
success=
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
129
|
+
success=not skipped, workspace_dir=abs_root, synced_files=created,
|
|
130
|
+
symbols_indexed=total_symbols, modules_scanned=symbols["module_count"],
|
|
131
|
+
zero_leak_status="Not assessed",
|
|
132
|
+
summary_message=(
|
|
133
|
+
f"Created {len(created)} files. Skipped: {', '.join(skipped) or 'none'}."
|
|
134
|
+
if apply else f"Preview only; no files changed. Candidate files: {', '.join(candidates)}."
|
|
135
|
+
)
|
|
215
136
|
)
|
|
216
137
|
|
|
217
138
|
@classmethod
|
|
@@ -227,15 +148,19 @@ tzero sync
|
|
|
227
148
|
for sf in result.synced_files:
|
|
228
149
|
print(f" ✔ \033[32m{sf}\033[0m")
|
|
229
150
|
print("-" * 75)
|
|
230
|
-
print(
|
|
151
|
+
print(result.summary_message)
|
|
231
152
|
print("=" * 75 + "\n")
|
|
232
153
|
|
|
233
154
|
|
|
234
155
|
def main():
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
156
|
+
parser = argparse.ArgumentParser(description="Preview or create missing workspace rule files.")
|
|
157
|
+
parser.add_argument("workspace", nargs="?", default=".")
|
|
158
|
+
parser.add_argument("--apply", action="store_true", help="Create files that do not already exist")
|
|
159
|
+
args = parser.parse_args()
|
|
160
|
+
result = WorkspaceSyncManager.sync(args.workspace, apply=args.apply)
|
|
161
|
+
WorkspaceSyncManager.render_cli(result)
|
|
162
|
+
return 0 if result.success else 1
|
|
238
163
|
|
|
239
164
|
|
|
240
165
|
if __name__ == "__main__":
|
|
241
|
-
main()
|
|
166
|
+
raise SystemExit(main())
|
|
@@ -75,7 +75,7 @@ class TaskEvaluationResult:
|
|
|
75
75
|
|
|
76
76
|
@dataclass
|
|
77
77
|
class TaskBenchmarkReport:
|
|
78
|
-
version: str = "12.3.
|
|
78
|
+
version: str = "12.3.5"
|
|
79
79
|
tokenizer: str = "tiktoken (cl100k_base)" if TIKTOKEN_AVAILABLE else "character-ratio fallback"
|
|
80
80
|
total_tasks: int = 0
|
|
81
81
|
passed_tasks: int = 0
|
|
@@ -465,7 +465,7 @@ def analyze_symbol_impact(symbol_path: str, table: SymbolTable, dag: CallGraphDA
|
|
|
465
465
|
"""Formats ANSI-styled benchmark summary table."""
|
|
466
466
|
lines = []
|
|
467
467
|
lines.append("=" * 78)
|
|
468
|
-
lines.append(" T-ZERO TASK-COMPLETION & BPE TOKENIZER BENCHMARK REPORT (v12.3.
|
|
468
|
+
lines.append(" T-ZERO TASK-COMPLETION & BPE TOKENIZER BENCHMARK REPORT (v12.3.5)")
|
|
469
469
|
lines.append(f" Tokenizer: {report.tokenizer} | Tasks Evaluated: {report.total_tasks}")
|
|
470
470
|
lines.append("=" * 78)
|
|
471
471
|
lines.append(f"{'Task ID':<10} | {'Raw BPE':<8} | {'T-Zero':<8} | {'Saved %':<8} | {'Contract %':<10} | {'Status'}")
|
|
@@ -18,7 +18,7 @@ import webbrowser
|
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
from typing import Any, Dict, List, Optional, Tuple
|
|
20
20
|
|
|
21
|
-
CURRENT_VERSION = "12.3.
|
|
21
|
+
CURRENT_VERSION = "12.3.5"
|
|
22
22
|
REPO_URL = "https://github.com/toprakahmetaydogmus/TZeroAlgorithm"
|
|
23
23
|
RELEASES_URL = f"{REPO_URL}/releases"
|
|
24
24
|
PYPI_URL = "https://pypi.org/project/tzero-mcp/"
|
package/src/tzero/tzero_tui.py
CHANGED
|
@@ -135,7 +135,6 @@ class TZeroTerminalCockpit:
|
|
|
135
135
|
("9", "Run AST Mutation Test Suite", "🧬 Run AST Mutation Test Suite (`tzero --mutate <file>`)"),
|
|
136
136
|
("10", "Code Health & Technical Debt Index", "🏥 Code Health & Technical Debt Index (`tzero --debt`)"),
|
|
137
137
|
("11", "Context Budget Optimizer & Certificate", "📜 Context Budget Optimizer & Certificate (`tzero --budget`)"),
|
|
138
|
-
("12", "Anti-REA 180-Tier Armor & Audit", "🛡️ Anti-REA 180-Tier Armor & Audit (`tzero --audit-rea`)"),
|
|
139
138
|
("13", "Offline Telemetry & ROI Tracker", "📊 Offline Telemetry & ROI Tracker (`tzero --telemetry`)"),
|
|
140
139
|
("0", "Exit TUI", "🚪 Exit TUI"),
|
|
141
140
|
]
|
|
@@ -180,7 +179,7 @@ class TZeroTerminalCockpit:
|
|
|
180
179
|
box_bottom = f"{c.CYAN}╚{'═' * 78}╝{c.RESET}"
|
|
181
180
|
|
|
182
181
|
lines.append(box_top)
|
|
183
|
-
lines.append(cls._box_line(f" {c.BOLD}{c.BRIGHT_CYAN}⚡ SİBER AKADEMİ — T-ZERO CONTEXT ARCHITECT & LIVE COCKPIT v12.3.
|
|
182
|
+
lines.append(cls._box_line(f" {c.BOLD}{c.BRIGHT_CYAN}⚡ SİBER AKADEMİ — T-ZERO CONTEXT ARCHITECT & LIVE COCKPIT v12.3.5{c.RESET}"))
|
|
184
183
|
lines.append(cls._box_line(f" {c.DIM}Local AST Analysis | Optional Network Services{c.RESET}"))
|
|
185
184
|
lines.append(box_mid)
|
|
186
185
|
|
|
@@ -325,7 +324,7 @@ class TZeroTerminalCockpit:
|
|
|
325
324
|
elif choice == "4":
|
|
326
325
|
from tzero.tzero_commit import LocalSemanticCommitSynthesizer
|
|
327
326
|
print(f"\n{cls.YELLOW}[Synthesizing Release CHANGELOG]...{cls.RESET}")
|
|
328
|
-
entry = LocalSemanticCommitSynthesizer.generate_changelog_entry(version="v12.3.
|
|
327
|
+
entry = LocalSemanticCommitSynthesizer.generate_changelog_entry(version="v12.3.5", repo_dir=workspace_dir)
|
|
329
328
|
print(f"\n{cls.BRIGHT_CYAN}{entry}{cls.RESET}\n")
|
|
330
329
|
input("Press Enter to return to cockpit...")
|
|
331
330
|
elif choice == "5":
|
|
@@ -400,16 +399,6 @@ class TZeroTerminalCockpit:
|
|
|
400
399
|
print(f"\n{cls.BRIGHT_CYAN}{ASTTokenBudgetOptimizer.format_markdown_certificate(cert)}{cls.RESET}\n")
|
|
401
400
|
print(f"{cls.GREEN}[SUCCESS] Certificate saved to: {saved_p}{cls.RESET}")
|
|
402
401
|
input("Press Enter to return to cockpit...")
|
|
403
|
-
elif choice == "12":
|
|
404
|
-
from tzero.tzero_armor import audit_path_rea_resistance, protect_path_with_armor
|
|
405
|
-
print(f"\n{cls.YELLOW}[Auditing 180-Tier Anti-REA Resistance for {workspace_dir}]...{cls.RESET}")
|
|
406
|
-
audit = audit_path_rea_resistance(workspace_dir)
|
|
407
|
-
print(f"{cls.BRIGHT_CYAN}AI Resistance Score: {audit.get('score', 0)}/100 ({audit.get('rating', 'UNKNOWN')}){cls.RESET}")
|
|
408
|
-
apply_ans = input("Apply Anti-REA armor to target file/dir now? [y/N]: ").strip().lower()
|
|
409
|
-
if apply_ans == "y":
|
|
410
|
-
res = protect_path_with_armor(workspace_dir)
|
|
411
|
-
print(f"{cls.GREEN}[OK] Protected: {res}{cls.RESET}")
|
|
412
|
-
input("Press Enter to return to cockpit...")
|
|
413
402
|
elif choice == "13":
|
|
414
403
|
from tzero.tzero_telemetry import render_report
|
|
415
404
|
print(f"\n{cls.BRIGHT_CYAN}{render_report(workspace_dir)}{cls.RESET}\n")
|