tzero-mcp 10.7.3 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +44 -577
  2. package/CONTRIBUTING.md +71 -71
  3. package/README.md +64 -64
  4. package/bin/tzero-mcp.js +62 -65
  5. package/bin/tzero.js +61 -64
  6. package/index.d.ts +25 -25
  7. package/index.js +15 -15
  8. package/package.json +88 -67
  9. package/src/addmcp.py +14 -11
  10. package/src/app.py +1810 -0
  11. package/src/main.py +1 -1
  12. package/src/pc_fixer_mcp.py +25 -0
  13. package/src/tzero/__init__.py +54 -0
  14. package/src/tzero/__main__.py +6 -0
  15. package/src/tzero/siber_akademi.ico +0 -0
  16. package/src/tzero/tzero_arch_test.py +463 -0
  17. package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
  18. package/src/tzero/tzero_blackboard.py +257 -0
  19. package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
  20. package/src/tzero/tzero_budget.py +195 -0
  21. package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
  22. package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
  23. package/src/tzero/tzero_contracts.py +1093 -0
  24. package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
  25. package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
  26. package/src/tzero/tzero_debt.py +461 -0
  27. package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
  28. package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
  29. package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
  30. package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
  31. package/src/tzero/tzero_federation.py +299 -0
  32. package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
  33. package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
  34. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
  35. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
  36. package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
  37. package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
  38. package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
  39. package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
  40. package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
  41. package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
  42. package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
  43. package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
  44. package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
  45. package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
  46. package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
  47. package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
  48. package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
  49. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
  50. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
  51. package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
  52. package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
  53. package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
  54. package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
  55. package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
  56. package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
  57. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
  58. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
  59. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
  60. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
  61. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
  62. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
  63. package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
  64. package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
  65. package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
  66. package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
  67. package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
  68. package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
  69. package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
  70. package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
  71. package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
  72. package/src/tzero/tzero_golden.py +319 -0
  73. package/src/tzero/tzero_graph_hud.html +338 -0
  74. package/src/tzero/tzero_graph_rag.py +263 -0
  75. package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
  76. package/src/tzero/tzero_hooks.py +565 -0
  77. package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
  78. package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
  79. package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
  80. package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
  81. package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
  82. package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
  83. package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
  84. package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
  85. package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
  86. package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
  87. package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
  88. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
  89. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
  90. package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
  91. package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
  92. package/src/tzero/tzero_lsp.py +634 -0
  93. package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
  94. package/src/tzero/tzero_mutation.py +358 -0
  95. package/src/tzero/tzero_packer.py +577 -0
  96. package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
  97. package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
  98. package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
  99. package/src/tzero/tzero_polyglot.py +799 -0
  100. package/src/tzero/tzero_proxy.py +127 -0
  101. package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
  102. package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
  103. package/src/tzero/tzero_rust_bridge.py +198 -0
  104. package/src/tzero/tzero_scip.py +368 -0
  105. package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
  106. package/src/tzero/tzero_semantic_merge.py +189 -0
  107. package/src/tzero/tzero_snapshot.py +471 -0
  108. package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
  109. package/src/tzero/tzero_subagent_engine.py +459 -0
  110. package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
  111. package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
  112. package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
  113. package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
  114. package/src/tzero/tzero_turbo.py +264 -0
  115. package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
  116. package/src/tzero.py +2 -54
  117. package/test/package.test.js +55 -19
  118. package/src/tzero/jarvis/semantic_compressor.py +0 -373
  119. package/src/tzero_gateway.py +0 -885
  120. package/src/tzero_packer.py +0 -370
  121. package/src/tzero_polyglot.py +0 -422
  122. package/src/tzero_snapshot.py +0 -258
  123. /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
  124. /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
  125. /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
  126. /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
  127. /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
@@ -1,246 +1,246 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- T-Zero CI/CD Quality Gate, Hook Integrator, & SARIF/JUnit Exporter
4
- ================================================================
5
- Enterprise-grade integration engine for CI/CD continuous inspection pipelines.
6
- Provides:
7
- - Automated Git Pre-Commit & Pre-Push Hook Installer (.git/hooks/)
8
- - Native GitHub Actions Quality Gate Generator (.github/workflows/tzero_gate.yml)
9
- - GitLab CI / Bitbucket Pipelines Configuration Generators
10
- - Industry-standard SARIF 2.1.0 JSON Report Exporter (for GitHub Code Scanning)
11
- - JUnit XML Test Result Exporter (for Jenkins, CircleCI, Azure DevOps)
12
-
13
- Author: Siber Akademi T-Zero R&D Team
14
- License: MIT (100% Free, Local Offline, Zero-Leak)
15
- """
16
-
17
- from __future__ import annotations
18
-
19
- import json
20
- import os
21
- import sys
22
- import time
23
- from dataclasses import dataclass, field
24
- from pathlib import Path
25
- from typing import Any, Dict, List, Optional, Set, Tuple
26
-
27
- from tzero_fixer.models import (
28
- DiagnosticCategory,
29
- DiagnosticIssue,
30
- DiagnosticReport,
31
- HealReport,
32
- SeverityLevel,
33
- )
34
-
35
-
36
- class GitHookIntegrator:
37
- """Installs and manages git pre-commit and pre-push hooks."""
38
-
39
- PRE_COMMIT_SCRIPT = """#!/usr/bin/env sh
40
- # T-Zero Autonomous Pre-Commit Security & AST Verification Gate
41
- # Installed by Siber Akademi T-Zero Master Fixer
42
-
43
- echo "🔒 [T-ZERO GATE] Running pre-commit Zero-Leak and AST syntax validation..."
44
-
45
- # Execute tzero doctor check
46
- if command -v python >/dev/null 2>&1; then
47
- python -c "from tzero_pc_fixer import PCFixerDoctor; report = PCFixerDoctor.diagnose('.'); crit = [i for i in report.get('issues', []) if i.get('severity') in ('critical', 'error')]; exit(1 if crit else 0)"
48
- STATUS=$?
49
- if [ $STATUS -ne 0 ]; then
50
- echo "🚨 [T-ZERO GATE BLOCKED] Critical syntax errors or secret leaks detected in staging!"
51
- echo "💡 Run 'tzero doctor --fix' or 'tzero pc-fixer --heal' to automatically resolve issues."
52
- exit 1
53
- fi
54
- fi
55
-
56
- echo "✅ [T-ZERO GATE PASSED] Workspace is clean. Proceeding with commit."
57
- exit 0
58
- """
59
-
60
- @classmethod
61
- def install_hooks(cls, workspace_dir: str = ".") -> Tuple[bool, str]:
62
- """Installs pre-commit hook script into .git/hooks/pre-commit."""
63
- git_dir = Path(workspace_dir) / ".git"
64
- if not git_dir.is_dir():
65
- return False, f"Not a git repository: {workspace_dir}"
66
-
67
- hooks_dir = git_dir / "hooks"
68
- hooks_dir.mkdir(parents=True, exist_ok=True)
69
-
70
- hook_file = hooks_dir / "pre-commit"
71
- try:
72
- with open(hook_file, "w", encoding="utf-8", newline="\n") as f:
73
- f.write(cls.PRE_COMMIT_SCRIPT)
74
-
75
- # Mark executable on POSIX systems
76
- if hasattr(os, "chmod"):
77
- try:
78
- os.chmod(hook_file, 0o755)
79
- except Exception:
80
- pass
81
-
82
- return True, f"Successfully installed T-Zero pre-commit hook into {hook_file}"
83
- except Exception as e:
84
- return False, f"Failed to install git hook: {e}"
85
-
86
-
87
- class CiCdWorkflowGenerator:
88
- """Generates CI/CD quality gate workflow configurations."""
89
-
90
- @classmethod
91
- def generate_github_workflow(cls, workspace_dir: str = ".") -> Tuple[bool, str]:
92
- """Generates .github/workflows/tzero_gate.yml."""
93
- wf_dir = Path(workspace_dir) / ".github" / "workflows"
94
- wf_dir.mkdir(parents=True, exist_ok=True)
95
- wf_path = wf_dir / "tzero_gate.yml"
96
-
97
- content = """name: T-Zero Quality & Security Gate
98
- on:
99
- push:
100
- branches: [ main, master, develop ]
101
- pull_request:
102
- branches: [ main, master, develop ]
103
-
104
- jobs:
105
- tzero-audit:
106
- name: Zero-Leak & AST Health Audit
107
- runs-on: ubuntu-latest
108
- steps:
109
- - name: Checkout Codebase
110
- uses: actions/checkout@v4
111
-
112
- - name: Set up Python
113
- uses: actions/setup-python@v5
114
- with:
115
- python-version: '3.12'
116
-
117
- - name: Install T-Zero Engine
118
- run: |
119
- python -m pip install --upgrade pip
120
- pip install tzero
121
-
122
- - name: Run T-Zero Health & Security Check
123
- run: |
124
- tzero doctor --format sarif --out tzero-results.sarif
125
-
126
- - name: Upload SARIF Results to GitHub Security Tab
127
- uses: github/codeql-action/upload-sarif@v3
128
- if: always()
129
- with:
130
- sarif_file: tzero-results.sarif
131
- """
132
- try:
133
- with open(wf_path, "w", encoding="utf-8", newline="\n") as f:
134
- f.write(content)
135
- return True, f"Generated GitHub Actions quality workflow at {wf_path}"
136
- except Exception as e:
137
- return False, f"Failed to generate GitHub workflow: {e}"
138
-
139
-
140
- class SarifReportExporter:
141
- """Converts T-Zero diagnostic reports into SARIF 2.1.0 standard schema."""
142
-
143
- @classmethod
144
- def export_sarif(cls, issues: List[DiagnosticIssue], workspace_dir: str = ".") -> str:
145
- """Serializes issues into official OASIS SARIF v2.1.0 JSON."""
146
- rules_map: Dict[str, Dict[str, Any]] = {}
147
- results: List[Dict[str, Any]] = []
148
-
149
- for issue in issues:
150
- rule_id = issue.error_code or "TZ-GENERIC"
151
- if rule_id not in rules_map:
152
- rules_map[rule_id] = {
153
- "id": rule_id,
154
- "name": issue.category.title(),
155
- "shortDescription": {"text": issue.message[:100]},
156
- "fullDescription": {"text": issue.message},
157
- "defaultConfiguration": {
158
- "level": "error" if issue.severity in ("critical", "error") else "warning"
159
- },
160
- "properties": {
161
- "category": issue.category,
162
- "remediation": issue.suggested_fix,
163
- },
164
- }
165
-
166
- file_uri = issue.file_path or "workspace"
167
- if os.path.isabs(file_uri):
168
- try:
169
- file_uri = os.path.relpath(file_uri, workspace_dir).replace("\\", "/")
170
- except Exception:
171
- pass
172
-
173
- level = "error" if issue.severity in ("critical", "error") else "warning"
174
- if issue.severity == "info":
175
- level = "note"
176
-
177
- result_entry: Dict[str, Any] = {
178
- "ruleId": rule_id,
179
- "level": level,
180
- "message": {"text": issue.message},
181
- "locations": [
182
- {
183
- "physicalLocation": {
184
- "artifactLocation": {"uri": file_uri},
185
- "region": {
186
- "startLine": issue.line or 1,
187
- "startColumn": (issue.column or 0) + 1,
188
- },
189
- }
190
- }
191
- ],
192
- }
193
- results.append(result_entry)
194
-
195
- sarif_doc = {
196
- "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
197
- "version": "2.1.0",
198
- "runs": [
199
- {
200
- "tool": {
201
- "driver": {
202
- "name": "T-Zero PC-Fixer & Codebase Doctor",
203
- "semanticVersion": "10.4.0",
204
- "informationUri": "https://tzero-indol.vercel.app",
205
- "rules": list(rules_map.values()),
206
- }
207
- },
208
- "results": results,
209
- }
210
- ],
211
- }
212
-
213
- return json.dumps(sarif_doc, indent=2)
214
-
215
-
216
- class JUnitXmlExporter:
217
- """Exports diagnostic issues to JUnit XML for dashboard reporting."""
218
-
219
- @classmethod
220
- def export_junit_xml(cls, issues: List[DiagnosticIssue]) -> str:
221
- """Generates standard JUnit XML testsuite element."""
222
- critical_count = len([i for i in issues if i.severity in ("critical", "error")])
223
- warning_count = len([i for i in issues if i.severity == "warning"])
224
- total_tests = len(issues) if issues else 1
225
-
226
- lines = [
227
- '<?xml version="1.0" encoding="UTF-8"?>',
228
- f'<testsuite name="tzero-fixer-audit" tests="{total_tests}" failures="{critical_count}" errors="0" skipped="0">',
229
- ]
230
-
231
- if not issues:
232
- lines.append(' <testcase classname="TZeroDoctor" name="WorkspaceClean" time="0.001"/>')
233
- else:
234
- for idx, issue in enumerate(issues, 1):
235
- cname = f"TZero.{issue.category.capitalize()}"
236
- tname = f"{issue.error_code}_{idx}"
237
- escaped_msg = issue.message.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;")
238
- if issue.severity in ("critical", "error"):
239
- lines.append(f' <testcase classname="{cname}" name="{tname}" time="0.001">')
240
- lines.append(f' <failure message="{escaped_msg}" type="{issue.error_code}">{escaped_msg}\nRemediation: {issue.suggested_fix}</failure>')
241
- lines.append(' </testcase>')
242
- else:
243
- lines.append(f' <testcase classname="{cname}" name="{tname}" time="0.001"/>')
244
-
245
- lines.append('</testsuite>')
246
- return "\n".join(lines)
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ T-Zero CI/CD Quality Gate, Hook Integrator, & SARIF/JUnit Exporter
4
+ ================================================================
5
+ Enterprise-grade integration engine for CI/CD continuous inspection pipelines.
6
+ Provides:
7
+ - Automated Git Pre-Commit & Pre-Push Hook Installer (.git/hooks/)
8
+ - Native GitHub Actions Quality Gate Generator (.github/workflows/tzero_gate.yml)
9
+ - GitLab CI / Bitbucket Pipelines Configuration Generators
10
+ - Industry-standard SARIF 2.1.0 JSON Report Exporter (for GitHub Code Scanning)
11
+ - JUnit XML Test Result Exporter (for Jenkins, CircleCI, Azure DevOps)
12
+
13
+ Author: Siber Akademi T-Zero R&D Team
14
+ License: MIT (100% Free, Local Offline, Zero-Leak)
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import os
21
+ import sys
22
+ import time
23
+ from dataclasses import dataclass, field
24
+ from pathlib import Path
25
+ from typing import Any, Dict, List, Optional, Set, Tuple
26
+
27
+ from tzero.tzero_fixer.models import (
28
+ DiagnosticCategory,
29
+ DiagnosticIssue,
30
+ DiagnosticReport,
31
+ HealReport,
32
+ SeverityLevel,
33
+ )
34
+
35
+
36
+ class GitHookIntegrator:
37
+ """Installs and manages git pre-commit and pre-push hooks."""
38
+
39
+ PRE_COMMIT_SCRIPT = """#!/usr/bin/env sh
40
+ # T-Zero Autonomous Pre-Commit Security & AST Verification Gate
41
+ # Installed by Siber Akademi T-Zero Master Fixer
42
+
43
+ echo "🔒 [T-ZERO GATE] Running pre-commit Zero-Leak and AST syntax validation..."
44
+
45
+ # Execute tzero doctor check
46
+ if command -v python >/dev/null 2>&1; then
47
+ python -c "from tzero_pc_fixer import PCFixerDoctor; report = PCFixerDoctor.diagnose('.'); crit = [i for i in report.get('issues', []) if i.get('severity') in ('critical', 'error')]; exit(1 if crit else 0)"
48
+ STATUS=$?
49
+ if [ $STATUS -ne 0 ]; then
50
+ echo "🚨 [T-ZERO GATE BLOCKED] Critical syntax errors or secret leaks detected in staging!"
51
+ echo "💡 Run 'tzero doctor --fix' or 'tzero pc-fixer --heal' to automatically resolve issues."
52
+ exit 1
53
+ fi
54
+ fi
55
+
56
+ echo "✅ [T-ZERO GATE PASSED] Workspace is clean. Proceeding with commit."
57
+ exit 0
58
+ """
59
+
60
+ @classmethod
61
+ def install_hooks(cls, workspace_dir: str = ".") -> Tuple[bool, str]:
62
+ """Installs pre-commit hook script into .git/hooks/pre-commit."""
63
+ git_dir = Path(workspace_dir) / ".git"
64
+ if not git_dir.is_dir():
65
+ return False, f"Not a git repository: {workspace_dir}"
66
+
67
+ hooks_dir = git_dir / "hooks"
68
+ hooks_dir.mkdir(parents=True, exist_ok=True)
69
+
70
+ hook_file = hooks_dir / "pre-commit"
71
+ try:
72
+ with open(hook_file, "w", encoding="utf-8", newline="\n") as f:
73
+ f.write(cls.PRE_COMMIT_SCRIPT)
74
+
75
+ # Mark executable on POSIX systems
76
+ if hasattr(os, "chmod"):
77
+ try:
78
+ os.chmod(hook_file, 0o755)
79
+ except Exception:
80
+ pass
81
+
82
+ return True, f"Successfully installed T-Zero pre-commit hook into {hook_file}"
83
+ except Exception as e:
84
+ return False, f"Failed to install git hook: {e}"
85
+
86
+
87
+ class CiCdWorkflowGenerator:
88
+ """Generates CI/CD quality gate workflow configurations."""
89
+
90
+ @classmethod
91
+ def generate_github_workflow(cls, workspace_dir: str = ".") -> Tuple[bool, str]:
92
+ """Generates .github/workflows/tzero_gate.yml."""
93
+ wf_dir = Path(workspace_dir) / ".github" / "workflows"
94
+ wf_dir.mkdir(parents=True, exist_ok=True)
95
+ wf_path = wf_dir / "tzero_gate.yml"
96
+
97
+ content = """name: T-Zero Quality & Security Gate
98
+ on:
99
+ push:
100
+ branches: [ main, master, develop ]
101
+ pull_request:
102
+ branches: [ main, master, develop ]
103
+
104
+ jobs:
105
+ tzero-audit:
106
+ name: Zero-Leak & AST Health Audit
107
+ runs-on: ubuntu-latest
108
+ steps:
109
+ - name: Checkout Codebase
110
+ uses: actions/checkout@v4
111
+
112
+ - name: Set up Python
113
+ uses: actions/setup-python@v5
114
+ with:
115
+ python-version: '3.12'
116
+
117
+ - name: Install T-Zero Engine
118
+ run: |
119
+ python -m pip install --upgrade pip
120
+ pip install tzero
121
+
122
+ - name: Run T-Zero Health & Security Check
123
+ run: |
124
+ tzero doctor --format sarif --out tzero-results.sarif
125
+
126
+ - name: Upload SARIF Results to GitHub Security Tab
127
+ uses: github/codeql-action/upload-sarif@v3
128
+ if: always()
129
+ with:
130
+ sarif_file: tzero-results.sarif
131
+ """
132
+ try:
133
+ with open(wf_path, "w", encoding="utf-8", newline="\n") as f:
134
+ f.write(content)
135
+ return True, f"Generated GitHub Actions quality workflow at {wf_path}"
136
+ except Exception as e:
137
+ return False, f"Failed to generate GitHub workflow: {e}"
138
+
139
+
140
+ class SarifReportExporter:
141
+ """Converts T-Zero diagnostic reports into SARIF 2.1.0 standard schema."""
142
+
143
+ @classmethod
144
+ def export_sarif(cls, issues: List[DiagnosticIssue], workspace_dir: str = ".") -> str:
145
+ """Serializes issues into official OASIS SARIF v2.1.0 JSON."""
146
+ rules_map: Dict[str, Dict[str, Any]] = {}
147
+ results: List[Dict[str, Any]] = []
148
+
149
+ for issue in issues:
150
+ rule_id = issue.error_code or "TZ-GENERIC"
151
+ if rule_id not in rules_map:
152
+ rules_map[rule_id] = {
153
+ "id": rule_id,
154
+ "name": issue.category.title(),
155
+ "shortDescription": {"text": issue.message[:100]},
156
+ "fullDescription": {"text": issue.message},
157
+ "defaultConfiguration": {
158
+ "level": "error" if issue.severity in ("critical", "error") else "warning"
159
+ },
160
+ "properties": {
161
+ "category": issue.category,
162
+ "remediation": issue.suggested_fix,
163
+ },
164
+ }
165
+
166
+ file_uri = issue.file_path or "workspace"
167
+ if os.path.isabs(file_uri):
168
+ try:
169
+ file_uri = os.path.relpath(file_uri, workspace_dir).replace("\\", "/")
170
+ except Exception:
171
+ pass
172
+
173
+ level = "error" if issue.severity in ("critical", "error") else "warning"
174
+ if issue.severity == "info":
175
+ level = "note"
176
+
177
+ result_entry: Dict[str, Any] = {
178
+ "ruleId": rule_id,
179
+ "level": level,
180
+ "message": {"text": issue.message},
181
+ "locations": [
182
+ {
183
+ "physicalLocation": {
184
+ "artifactLocation": {"uri": file_uri},
185
+ "region": {
186
+ "startLine": issue.line or 1,
187
+ "startColumn": (issue.column or 0) + 1,
188
+ },
189
+ }
190
+ }
191
+ ],
192
+ }
193
+ results.append(result_entry)
194
+
195
+ sarif_doc = {
196
+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
197
+ "version": "2.1.0",
198
+ "runs": [
199
+ {
200
+ "tool": {
201
+ "driver": {
202
+ "name": "T-Zero PC-Fixer & Codebase Doctor",
203
+ "semanticVersion": "10.4.0",
204
+ "informationUri": "https://tzero-indol.vercel.app",
205
+ "rules": list(rules_map.values()),
206
+ }
207
+ },
208
+ "results": results,
209
+ }
210
+ ],
211
+ }
212
+
213
+ return json.dumps(sarif_doc, indent=2)
214
+
215
+
216
+ class JUnitXmlExporter:
217
+ """Exports diagnostic issues to JUnit XML for dashboard reporting."""
218
+
219
+ @classmethod
220
+ def export_junit_xml(cls, issues: List[DiagnosticIssue]) -> str:
221
+ """Generates standard JUnit XML testsuite element."""
222
+ critical_count = len([i for i in issues if i.severity in ("critical", "error")])
223
+ warning_count = len([i for i in issues if i.severity == "warning"])
224
+ total_tests = len(issues) if issues else 1
225
+
226
+ lines = [
227
+ '<?xml version="1.0" encoding="UTF-8"?>',
228
+ f'<testsuite name="tzero-fixer-audit" tests="{total_tests}" failures="{critical_count}" errors="0" skipped="0">',
229
+ ]
230
+
231
+ if not issues:
232
+ lines.append(' <testcase classname="TZeroDoctor" name="WorkspaceClean" time="0.001"/>')
233
+ else:
234
+ for idx, issue in enumerate(issues, 1):
235
+ cname = f"TZero.{issue.category.capitalize()}"
236
+ tname = f"{issue.error_code}_{idx}"
237
+ escaped_msg = issue.message.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;")
238
+ if issue.severity in ("critical", "error"):
239
+ lines.append(f' <testcase classname="{cname}" name="{tname}" time="0.001">')
240
+ lines.append(f' <failure message="{escaped_msg}" type="{issue.error_code}">{escaped_msg}\nRemediation: {issue.suggested_fix}</failure>')
241
+ lines.append(' </testcase>')
242
+ else:
243
+ lines.append(f' <testcase classname="{cname}" name="{tname}" time="0.001"/>')
244
+
245
+ lines.append('</testsuite>')
246
+ return "\n".join(lines)