tzero-mcp 10.7.0 → 10.7.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +589 -0
  2. package/CONTRIBUTING.md +71 -0
  3. package/README.md +25 -17
  4. package/bin/postinstall.js +34 -0
  5. package/bin/tzero-mcp.js +16 -19
  6. package/bin/tzero.js +14 -19
  7. package/index.d.ts +24 -0
  8. package/index.js +7 -3
  9. package/package.json +24 -2
  10. package/src/addmcp.py +1194 -0
  11. package/src/main.py +60 -0
  12. package/src/siber_akademi_icon.py +77 -0
  13. package/src/tzero/jarvis/semantic_compressor.py +373 -0
  14. package/src/tzero.py +58 -0
  15. package/src/tzero_benchmark.py +475 -0
  16. package/src/tzero_bridge.py +362 -0
  17. package/src/tzero_ci.py +153 -0
  18. package/src/tzero_commit.py +192 -0
  19. package/src/tzero_cost.py +163 -0
  20. package/src/tzero_dashboard.py +1448 -0
  21. package/src/tzero_deps.py +287 -0
  22. package/src/tzero_drift.py +208 -0
  23. package/src/tzero_explain.py +240 -0
  24. package/src/tzero_features.py +3022 -0
  25. package/src/tzero_fix.py +228 -0
  26. package/src/tzero_fixer/__init__.py +63 -0
  27. package/src/tzero_fixer/amalgamation.py +334 -0
  28. package/src/tzero_fixer/ast_syntax_healer.py +464 -0
  29. package/src/tzero_fixer/ast_type_modernizer.py +288 -0
  30. package/src/tzero_fixer/async_io_modernizer.py +127 -0
  31. package/src/tzero_fixer/automated_regression_suite.py +600 -0
  32. package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
  33. package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
  34. package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
  35. package/src/tzero_fixer/code_smells_healer.py +260 -0
  36. package/src/tzero_fixer/cwe_remediator.py +171 -0
  37. package/src/tzero_fixer/dead_code_eliminator.py +150 -0
  38. package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
  39. package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
  40. package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
  41. package/src/tzero_fixer/import_graph_healer.py +412 -0
  42. package/src/tzero_fixer/interactive_tui.py +91 -0
  43. package/src/tzero_fixer/knowledge_base.py +295 -0
  44. package/src/tzero_fixer/knowledge_base_extended.py +940 -0
  45. package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
  46. package/src/tzero_fixer/mcp_server.py +447 -0
  47. package/src/tzero_fixer/models.py +385 -0
  48. package/src/tzero_fixer/orchestrator.py +375 -0
  49. package/src/tzero_fixer/os_doctor.py +502 -0
  50. package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
  51. package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
  52. package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
  53. package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
  54. package/src/tzero_fixer/polyglot_build_healer.py +364 -0
  55. package/src/tzero_fixer/polyglot_config_healer.py +318 -0
  56. package/src/tzero_fixer/polyglot_doctor.py +372 -0
  57. package/src/tzero_fixer/polyglot_linters.py +619 -0
  58. package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
  59. package/src/tzero_fixer/security_cwe_database.py +444 -0
  60. package/src/tzero_fixer/security_deep_rules.py +114 -0
  61. package/src/tzero_fixer/security_rules_catalog.py +110 -0
  62. package/src/tzero_fixer/security_zero_leak.py +326 -0
  63. package/src/tzero_fixer/smart_patch_recommender.py +223 -0
  64. package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
  65. package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
  66. package/src/tzero_fixer/system_repair_recipes.py +447 -0
  67. package/src/tzero_fixer/venv_doctor.py +309 -0
  68. package/src/tzero_gateway.py +885 -0
  69. package/src/tzero_guard.py +243 -0
  70. package/src/tzero_infra.py +274 -0
  71. package/src/tzero_jarvis/__init__.py +124 -0
  72. package/src/tzero_jarvis/causal_graph.py +310 -0
  73. package/src/tzero_jarvis/graph_visualizer.py +395 -0
  74. package/src/tzero_jarvis/hybrid_search.py +214 -0
  75. package/src/tzero_jarvis/latent_press.py +137 -0
  76. package/src/tzero_jarvis/memory_consolidation.py +212 -0
  77. package/src/tzero_jarvis/minhash_lsh.py +184 -0
  78. package/src/tzero_jarvis/orchestrator.py +335 -0
  79. package/src/tzero_jarvis/self_healing.py +308 -0
  80. package/src/tzero_jarvis/semantic_compressor.py +887 -0
  81. package/src/tzero_jarvis/swarm.py +261 -0
  82. package/src/tzero_jarvis/swarm_bft.py +144 -0
  83. package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
  84. package/src/tzero_jarvis/zero_key_router.py +173 -0
  85. package/src/tzero_mcp.py +4858 -0
  86. package/src/tzero_neural_cortex.py +1425 -0
  87. package/src/tzero_packer.py +370 -0
  88. package/src/tzero_patch.py +624 -0
  89. package/src/tzero_pc_fixer.py +12657 -0
  90. package/src/tzero_pipe.py +95 -0
  91. package/src/tzero_polyglot.py +422 -0
  92. package/src/tzero_reachability.py +272 -0
  93. package/src/tzero_replay.py +141 -0
  94. package/src/tzero_security.py +570 -0
  95. package/src/tzero_snapshot.py +258 -0
  96. package/src/tzero_stubs.py +313 -0
  97. package/src/tzero_superdesign.py +774 -0
  98. package/src/tzero_sync.py +241 -0
  99. package/src/tzero_task_benchmark.py +363 -0
  100. package/src/tzero_tui.py +244 -0
  101. package/src/tzero_v3.py +9435 -0
@@ -0,0 +1,447 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ T-Zero System Repair Playbooks & Operating System Healer Recipes
4
+ ===============================================================
5
+ Production-grade system repair recipes for engineering workstations.
6
+ Provides automated playbooks and verified remediation commands for:
7
+ - Windows 10/11 & Server: LongPaths, DeveloperMode, UTF-8 console, Symlinks, ExecutionPolicy
8
+ - Linux (Ubuntu/Debian, Fedora/RHEL, Arch): inotify watchers, file descriptors, tmp permissions, SSH keys
9
+ - macOS (Apple Silicon & Intel): Gatekeeper quarantine, Homebrew permissions, Xcode CLI tools
10
+ - Language Runtimes: Python (pip/pyenv/poetry/pdm), Node.js (npm/yarn/pnpm), Rust (cargo), Go
11
+ - Version Control & Storage: Stale git locks, detached HEADs, Git LFS pointer corruptions, disk caches
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 os
20
+ import sys
21
+ import platform
22
+ import subprocess
23
+ from dataclasses import dataclass, field
24
+ from pathlib import Path
25
+ from typing import Dict, List, Optional, Tuple, Any
26
+
27
+ from tzero_fixer.models import (
28
+ DiagnosticCategory,
29
+ DiagnosticIssue,
30
+ HealAction,
31
+ SeverityLevel,
32
+ SystemPlatform,
33
+ )
34
+
35
+
36
+ @dataclass
37
+ class SystemRepairRecipe:
38
+ """Executable repair recipe for a specific operating system or toolchain defect."""
39
+ recipe_id: str
40
+ target_platform: SystemPlatform
41
+ title: str
42
+ description: str
43
+ diagnostic_code: str
44
+ requires_elevation: bool
45
+ automated_fix_available: bool
46
+ windows_powershell_cmd: Optional[str] = None
47
+ posix_bash_cmd: Optional[str] = None
48
+ verification_check_cmd: Optional[str] = None
49
+ safety_notes: str = ""
50
+
51
+
52
+ class SystemRepairPlaybooks:
53
+ """
54
+ Exhaustive catalog and execution engine for cross-platform system repair recipes.
55
+ """
56
+
57
+ RECIPES: List[SystemRepairRecipe] = [
58
+ # =====================================================================
59
+ # 1. WINDOWS OPERATING SYSTEM RECIPES
60
+ # =====================================================================
61
+ SystemRepairRecipe(
62
+ recipe_id="REC-WIN-001",
63
+ target_platform=SystemPlatform.WINDOWS,
64
+ title="Enable Windows LongPathsEnabled in Registry",
65
+ description="Removes the legacy 260-character MAX_PATH limit in Windows, allowing deeply nested node_modules and python virtual environments to function without crashing.",
66
+ diagnostic_code="TZ-WIN-001",
67
+ requires_elevation=True,
68
+ automated_fix_available=True,
69
+ windows_powershell_cmd='Set-ItemProperty -Path "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWord',
70
+ verification_check_cmd='(Get-ItemProperty "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem").LongPathsEnabled',
71
+ safety_notes="Completely safe. Supported natively in Windows 10 (version 1607+) and Windows 11.",
72
+ ),
73
+ SystemRepairRecipe(
74
+ recipe_id="REC-WIN-002",
75
+ target_platform=SystemPlatform.WINDOWS,
76
+ title="Enable Developer Mode for Unprivileged Symlink Creation",
77
+ description="Allows standard non-administrator users to create symbolic links (mklink) required by npm, yarn, and python virtual environments.",
78
+ diagnostic_code="TZ-WIN-002",
79
+ requires_elevation=True,
80
+ automated_fix_available=True,
81
+ windows_powershell_cmd='Set-ItemProperty -Path "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock" -Name "AllowDevelopmentWithoutDevLicense" -Value 1 -Type DWord',
82
+ verification_check_cmd='(Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock").AllowDevelopmentWithoutDevLicense',
83
+ safety_notes="Enables Windows Developer Mode. Safe for engineering development workstations.",
84
+ ),
85
+ SystemRepairRecipe(
86
+ recipe_id="REC-WIN-003",
87
+ target_platform=SystemPlatform.WINDOWS,
88
+ title="Configure UTF-8 Code Page 65001 for Windows Console",
89
+ description="Configures Windows command prompt and PowerShell to default to UTF-8 encoding (cp65001), eliminating UnicodeEncodeError crashes.",
90
+ diagnostic_code="TZ-WIN-003",
91
+ requires_elevation=False,
92
+ automated_fix_available=True,
93
+ windows_powershell_cmd="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::UTF8",
94
+ verification_check_cmd="[Console]::OutputEncoding.CodePage",
95
+ safety_notes="Non-destructive in-session or profile configuration.",
96
+ ),
97
+ SystemRepairRecipe(
98
+ recipe_id="REC-WIN-004",
99
+ target_platform=SystemPlatform.WINDOWS,
100
+ title="Set PowerShell ExecutionPolicy to RemoteSigned",
101
+ description="Allows local developer activation scripts (e.g. .venv\\Scripts\\Activate.ps1) to run while still blocking unsigned remote internet scripts.",
102
+ diagnostic_code="TZ-WIN-004",
103
+ requires_elevation=False,
104
+ automated_fix_available=True,
105
+ windows_powershell_cmd="Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force",
106
+ verification_check_cmd="Get-ExecutionPolicy -Scope CurrentUser",
107
+ safety_notes="Restricted to CurrentUser scope; does not lower machine-wide security policies.",
108
+ ),
109
+ SystemRepairRecipe(
110
+ recipe_id="REC-WIN-005",
111
+ target_platform=SystemPlatform.WINDOWS,
112
+ title="Purge Windows Temp Stale Build Directories (%TEMP%)",
113
+ description="Safely deletes abandoned pip-build-*, tmp*, and npm cache directories older than 24 hours from user temporary storage.",
114
+ diagnostic_code="TZ-SYS-052",
115
+ requires_elevation=False,
116
+ automated_fix_available=True,
117
+ windows_powershell_cmd='Get-ChildItem -Path $env:TEMP -Filter "pip-*" -Directory | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-1) } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue',
118
+ verification_check_cmd='(Get-ChildItem -Path $env:TEMP -Filter "pip-*" -Directory).Count',
119
+ safety_notes="Only purges build folders older than 24 hours.",
120
+ ),
121
+
122
+ # =====================================================================
123
+ # 2. LINUX OPERATING SYSTEM RECIPES
124
+ # =====================================================================
125
+ SystemRepairRecipe(
126
+ recipe_id="REC-LNX-001",
127
+ target_platform=SystemPlatform.LINUX,
128
+ title="Increase inotify File Watcher Limit for Dev Servers",
129
+ description="Increases fs.inotify.max_user_watches from default 8192 to 524288 to prevent 'ENOSPC: System limit for number of file watchers reached' in Vite, Next.js, and Webpack.",
130
+ diagnostic_code="TZ-LNX-001",
131
+ requires_elevation=True,
132
+ automated_fix_available=True,
133
+ posix_bash_cmd='echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.d/99-tzero-inotify.conf && sudo sysctl -p /etc/sysctl.d/99-tzero-inotify.conf',
134
+ verification_check_cmd="cat /proc/sys/fs/inotify/max_user_watches",
135
+ safety_notes="Standard configuration for frontend and fullstack web developers on Linux.",
136
+ ),
137
+ SystemRepairRecipe(
138
+ recipe_id="REC-LNX-002",
139
+ target_platform=SystemPlatform.LINUX,
140
+ title="Increase Max Open File Descriptors (nofile limit)",
141
+ description="Increases the maximum number of open files per user process to 65535, preventing 'Too many open files' in database and high-concurrency dev testing.",
142
+ diagnostic_code="TZ-LNX-002",
143
+ requires_elevation=True,
144
+ automated_fix_available=True,
145
+ posix_bash_cmd='sudo sh -c \'echo "* soft nofile 65535\\n* hard nofile 65535" >> /etc/security/limits.d/99-tzero-nofile.conf\'',
146
+ verification_check_cmd="ulimit -n",
147
+ safety_notes="Requires user re-login or new shell session to take effect.",
148
+ ),
149
+ SystemRepairRecipe(
150
+ recipe_id="REC-LNX-003",
151
+ target_platform=SystemPlatform.LINUX,
152
+ title="Enforce Secure Permissions on ~/.ssh and Private Keys",
153
+ description="Applies chmod 700 to ~/.ssh directory and chmod 600 to private keys (id_rsa, id_ed25519) to prevent SSH from rejecting key authentication.",
154
+ diagnostic_code="TZ-SEC-080",
155
+ requires_elevation=False,
156
+ automated_fix_available=True,
157
+ posix_bash_cmd="chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_* 2>/dev/null || true",
158
+ verification_check_cmd="stat -c '%a' ~/.ssh",
159
+ safety_notes="Standard POSIX security practice mandated by OpenSSH clients.",
160
+ ),
161
+ SystemRepairRecipe(
162
+ recipe_id="REC-LNX-004",
163
+ target_platform=SystemPlatform.LINUX,
164
+ title="Ensure /tmp Sticky Bit (1777 Permissions)",
165
+ description="Restores the required sticky bit (drwxrwxrwt) on /tmp so any user can create files but only file owners can delete them.",
166
+ diagnostic_code="TZ-LNX-003",
167
+ requires_elevation=True,
168
+ automated_fix_available=True,
169
+ posix_bash_cmd="sudo chmod 1777 /tmp",
170
+ verification_check_cmd="stat -c '%a' /tmp",
171
+ safety_notes="Essential for multi-user Linux system integrity.",
172
+ ),
173
+
174
+ # =====================================================================
175
+ # 3. MACOS OPERATING SYSTEM RECIPES
176
+ # =====================================================================
177
+ SystemRepairRecipe(
178
+ recipe_id="REC-MAC-001",
179
+ target_platform=SystemPlatform.MACOS,
180
+ title="Strip macOS Gatekeeper Quarantine from Dev Tools",
181
+ description="Removes 'com.apple.quarantine' extended attributes from downloaded compilers, shims, and CLI utilities blocking command execution.",
182
+ diagnostic_code="TZ-MAC-001",
183
+ requires_elevation=False,
184
+ automated_fix_available=True,
185
+ posix_bash_cmd="xattr -d com.apple.quarantine ./bin/* 2>/dev/null || true",
186
+ verification_check_cmd="xattr ./bin/*",
187
+ safety_notes="Only execute on trusted developer tools and verified local binaries.",
188
+ ),
189
+ SystemRepairRecipe(
190
+ recipe_id="REC-MAC-002",
191
+ target_platform=SystemPlatform.MACOS,
192
+ title="Verify Active Xcode Command Line Tools Path",
193
+ description="Checks and restores active developer directory path (xcode-select) to prevent compiler header missing errors.",
194
+ diagnostic_code="TZ-MAC-002",
195
+ requires_elevation=True,
196
+ automated_fix_available=False,
197
+ posix_bash_cmd="sudo xcode-select --switch /Library/Developer/CommandLineTools",
198
+ verification_check_cmd="xcode-select -p",
199
+ safety_notes="Ensures clang, make, and git resolve properly from macOS SDK.",
200
+ ),
201
+
202
+ # =====================================================================
203
+ # 4. PYTHON RUNTIME & PACKAGE MANAGER RECIPES
204
+ # =====================================================================
205
+ SystemRepairRecipe(
206
+ recipe_id="REC-PY-001",
207
+ target_platform=SystemPlatform.UNKNOWN,
208
+ title="Purge Corrupted pip Cache and Download Artifacts",
209
+ description="Cleans the local pip cache directory to fix 'Hash mismatch' and corrupted wheel download errors.",
210
+ diagnostic_code="TZ-PY-001",
211
+ requires_elevation=False,
212
+ automated_fix_available=True,
213
+ windows_powershell_cmd="python -m pip cache purge",
214
+ posix_bash_cmd="python -m pip cache purge",
215
+ verification_check_cmd="python -m pip cache list",
216
+ safety_notes="Completely safe; cached wheels will re-download on next pip install.",
217
+ ),
218
+ SystemRepairRecipe(
219
+ recipe_id="REC-PY-002",
220
+ target_platform=SystemPlatform.UNKNOWN,
221
+ title="Purge Orphaned Bytecode (__pycache__/*.pyc) Recursively",
222
+ description="Deletes all compiled .pyc files across the workspace to guarantee fresh module loading without stale bytecode caching.",
223
+ diagnostic_code="TZ-ENV-003",
224
+ requires_elevation=False,
225
+ automated_fix_available=True,
226
+ windows_powershell_cmd='Get-ChildItem -Path . -Include "__pycache__","*.pyc" -Recurse -Force | Remove-Item -Recurse -Force',
227
+ posix_bash_cmd='find . -type d -name "__pycache__" -exec rm -rf {} + -o -name "*.pyc" -delete',
228
+ verification_check_cmd='find . -name "*.pyc"',
229
+ safety_notes="Bytecode is automatically regenerated by Python on subsequent imports.",
230
+ ),
231
+ SystemRepairRecipe(
232
+ recipe_id="REC-PY-003",
233
+ target_platform=SystemPlatform.UNKNOWN,
234
+ title="Repair Corrupted Virtualenv pyvenv.cfg Interpreter Home",
235
+ description="Discovers the active Python interpreter path and re-links the broken 'home' entry in pyvenv.cfg.",
236
+ diagnostic_code="TZ-ENV-001",
237
+ requires_elevation=False,
238
+ automated_fix_available=True,
239
+ safety_notes="T-Zero autonomously updates pyvenv.cfg preserving all installed site-packages.",
240
+ ),
241
+
242
+ # =====================================================================
243
+ # 5. NODE.JS & JAVASCRIPT PACKAGE MANAGER RECIPES
244
+ # =====================================================================
245
+ SystemRepairRecipe(
246
+ recipe_id="REC-NODE-001",
247
+ target_platform=SystemPlatform.UNKNOWN,
248
+ title="Purge Corrupted npm Cache and Verify Integrity",
249
+ description="Executes 'npm cache clean --force' and verifies checksums when npm packages fail with tarball checksum mismatches.",
250
+ diagnostic_code="TZ-NODE-001",
251
+ requires_elevation=False,
252
+ automated_fix_available=True,
253
+ windows_powershell_cmd="npm cache clean --force; npm cache verify",
254
+ posix_bash_cmd="npm cache clean --force && npm cache verify",
255
+ verification_check_cmd="npm cache verify",
256
+ safety_notes="Safe npm maintenance command.",
257
+ ),
258
+
259
+ # =====================================================================
260
+ # 6. GIT VERSION CONTROL RECIPES
261
+ # =====================================================================
262
+ SystemRepairRecipe(
263
+ recipe_id="REC-GIT-001",
264
+ target_platform=SystemPlatform.UNKNOWN,
265
+ title="Remove Stale .git/index.lock Lockfile",
266
+ description="Unlocks git operations blocked by a crashed or aborted git process leaving a dangling index.lock.",
267
+ diagnostic_code="TZ-ENV-002",
268
+ requires_elevation=False,
269
+ automated_fix_available=True,
270
+ windows_powershell_cmd='if (Test-Path ".git\\index.lock") { Remove-Item ".git\\index.lock" -Force }',
271
+ posix_bash_cmd="rm -f .git/index.lock",
272
+ verification_check_cmd="git status",
273
+ safety_notes="T-Zero verifies no git process is currently running before deleting.",
274
+ ),
275
+ SystemRepairRecipe(
276
+ recipe_id="REC-GIT-002",
277
+ target_platform=SystemPlatform.UNKNOWN,
278
+ title="Execute Git Garbage Collection and Optimize Packfiles",
279
+ description="Runs 'git gc --prune=now' to compress loose objects, prune unreachable dangling commits, and speed up git repository I/O.",
280
+ diagnostic_code="TZ-GIT-002",
281
+ requires_elevation=False,
282
+ automated_fix_available=True,
283
+ windows_powershell_cmd="git gc --prune=now",
284
+ posix_bash_cmd="git gc --prune=now",
285
+ verification_check_cmd="git count-objects -v",
286
+ safety_notes="Optimizes internal Git repository storage without altering branch history.",
287
+ ),
288
+ SystemRepairRecipe(
289
+ recipe_id="REC-GIT-003",
290
+ target_platform=SystemPlatform.UNKNOWN,
291
+ title="Verify Git Repository Object Database Integrity",
292
+ description="Runs 'git fsck --full' to identify corrupted blobs, broken references, or dangling tree objects in .git store.",
293
+ diagnostic_code="TZ-GIT-003",
294
+ requires_elevation=False,
295
+ automated_fix_available=True,
296
+ windows_powershell_cmd="git fsck --full",
297
+ posix_bash_cmd="git fsck --full",
298
+ verification_check_cmd="git status",
299
+ safety_notes="Read-only diagnostic verification of git object database integrity.",
300
+ ),
301
+ SystemRepairRecipe(
302
+ recipe_id="REC-GIT-004",
303
+ target_platform=SystemPlatform.UNKNOWN,
304
+ title="Safe Dry-Run Sweep of Untracked Files and Build Artifacts",
305
+ description="Executes 'git clean -ndX' to preview all untracked and gitignored dead artifacts without deleting them.",
306
+ diagnostic_code="TZ-GIT-004",
307
+ requires_elevation=False,
308
+ automated_fix_available=True,
309
+ windows_powershell_cmd="git clean -ndX",
310
+ posix_bash_cmd="git clean -ndX",
311
+ verification_check_cmd="git status --short",
312
+ safety_notes="Dry-run preview only; never deletes files without explicit confirmation.",
313
+ ),
314
+
315
+ # =====================================================================
316
+ # 7. DOCKER & CONTAINER REPAIR RECIPES
317
+ # =====================================================================
318
+ SystemRepairRecipe(
319
+ recipe_id="REC-DOCKER-001",
320
+ target_platform=SystemPlatform.UNKNOWN,
321
+ title="Prune Dangling Containers, Unused Networks, and Builder Cache",
322
+ description="Reclaims disk space and resolves port allocation conflicts caused by dead or zombie Docker containers.",
323
+ diagnostic_code="TZ-DOCKER-001",
324
+ requires_elevation=False,
325
+ automated_fix_available=True,
326
+ windows_powershell_cmd="docker container prune -f; docker network prune -f",
327
+ posix_bash_cmd="docker container prune -f && docker network prune -f",
328
+ verification_check_cmd="docker ps -a",
329
+ safety_notes="Removes only stopped containers and unused networks; running containers are unaffected.",
330
+ ),
331
+ SystemRepairRecipe(
332
+ recipe_id="REC-DOCKER-002",
333
+ target_platform=SystemPlatform.UNKNOWN,
334
+ title="Prune Stale Docker Buildx Cache",
335
+ description="Purges corrupted layer build caches when multi-stage Docker builds fail with cryptic filesystem layer errors.",
336
+ diagnostic_code="TZ-DOCKER-002",
337
+ requires_elevation=False,
338
+ automated_fix_available=True,
339
+ windows_powershell_cmd="docker builder prune -f",
340
+ posix_bash_cmd="docker builder prune -f",
341
+ verification_check_cmd="docker builder du",
342
+ safety_notes="Frees intermediate builder layers; images and volumes are preserved.",
343
+ ),
344
+
345
+ # =====================================================================
346
+ # 8. RUST CARGO & GO TOOLCHAIN REPAIR RECIPES
347
+ # =====================================================================
348
+ SystemRepairRecipe(
349
+ recipe_id="REC-CARGO-001",
350
+ target_platform=SystemPlatform.UNKNOWN,
351
+ title="Clean Rust Cargo Target Directory and Fingerprint Cache",
352
+ description="Executes 'cargo clean' to wipe corrupted incremental compilation artifacts and rebuild rustc fingerprints.",
353
+ diagnostic_code="TZ-RUST-001",
354
+ requires_elevation=False,
355
+ automated_fix_available=True,
356
+ windows_powershell_cmd="cargo clean",
357
+ posix_bash_cmd="cargo clean",
358
+ verification_check_cmd="cargo check",
359
+ safety_notes="Removes target/ directory cleanly; next build compiles from fresh source.",
360
+ ),
361
+ SystemRepairRecipe(
362
+ recipe_id="REC-GO-001",
363
+ target_platform=SystemPlatform.UNKNOWN,
364
+ title="Purge Corrupted Go Build and Test Cache",
365
+ description="Runs 'go clean -cache -testcache' to resolve corrupted Go package archives causing checksum verification panics.",
366
+ diagnostic_code="TZ-GO-001",
367
+ requires_elevation=False,
368
+ automated_fix_available=True,
369
+ windows_powershell_cmd="go clean -cache -testcache",
370
+ posix_bash_cmd="go clean -cache -testcache",
371
+ verification_check_cmd="go version",
372
+ safety_notes="Cleans temporary build outputs while keeping downloaded vendor modules intact.",
373
+ ),
374
+
375
+ # =====================================================================
376
+ # 9. NETWORKING & SYSTEM RESOLVER RECIPES
377
+ # =====================================================================
378
+ SystemRepairRecipe(
379
+ recipe_id="REC-WIN-003",
380
+ target_platform=SystemPlatform.WINDOWS,
381
+ title="Flush Windows DNS Client Resolver Cache",
382
+ description="Flushes and resets the local Windows DNS client cache when API endpoints or package hosts fail to resolve.",
383
+ diagnostic_code="TZ-NET-001",
384
+ requires_elevation=False,
385
+ automated_fix_available=True,
386
+ windows_powershell_cmd="Clear-DnsClientCache",
387
+ posix_bash_cmd=None,
388
+ verification_check_cmd="Get-DnsClientCache",
389
+ safety_notes="Safe network cache flush; resolves stale DNS records immediately.",
390
+ ),
391
+ SystemRepairRecipe(
392
+ recipe_id="REC-POSIX-002",
393
+ target_platform=SystemPlatform.LINUX,
394
+ title="Harden OpenSSH ~/.ssh Directory and Key Permissions",
395
+ description="Enforces strict POSIX permissions (chmod 700 ~/.ssh, chmod 600 ~/.ssh/*) required by SSH daemon to prevent key rejection.",
396
+ diagnostic_code="TZ-SSH-001",
397
+ requires_elevation=False,
398
+ automated_fix_available=True,
399
+ windows_powershell_cmd=None,
400
+ posix_bash_cmd="chmod 700 ~/.ssh && chmod 600 ~/.ssh/* 2>/dev/null || true",
401
+ verification_check_cmd="ls -ld ~/.ssh",
402
+ safety_notes="Enforces standard OpenSSH security standards across POSIX systems.",
403
+ ),
404
+ ]
405
+
406
+ _INDEX_BY_RECIPE: Dict[str, SystemRepairRecipe] = {r.recipe_id: r for r in RECIPES}
407
+ _INDEX_BY_DIAG_CODE: Dict[str, SystemRepairRecipe] = {r.diagnostic_code: r for r in RECIPES}
408
+
409
+ @classmethod
410
+ def get_recipe(cls, recipe_id: str) -> Optional[SystemRepairRecipe]:
411
+ return cls._INDEX_BY_RECIPE.get(recipe_id.upper())
412
+
413
+ @classmethod
414
+ def find_recipe_for_issue(cls, diagnostic_code: str) -> Optional[SystemRepairRecipe]:
415
+ return cls._INDEX_BY_DIAG_CODE.get(diagnostic_code.upper())
416
+
417
+ @classmethod
418
+ def list_recipes_for_platform(cls, target_platform: SystemPlatform) -> List[SystemRepairRecipe]:
419
+ return [
420
+ r for r in cls.RECIPES
421
+ if r.target_platform == target_platform or r.target_platform == SystemPlatform.UNKNOWN
422
+ ]
423
+
424
+ @classmethod
425
+ def execute_recipe_command(cls, recipe: SystemRepairRecipe, dry_run: bool = False) -> Tuple[bool, str]:
426
+ """Executes the appropriate platform command for a given repair recipe."""
427
+ if dry_run:
428
+ return True, f"[DRY-RUN] Would execute recipe '{recipe.title}'"
429
+
430
+ sys_name = platform.system().lower()
431
+ cmd: Optional[str] = None
432
+
433
+ if "windows" in sys_name and recipe.windows_powershell_cmd:
434
+ cmd = f'powershell -NoProfile -Command "{recipe.windows_powershell_cmd}"'
435
+ elif ("linux" in sys_name or "darwin" in sys_name) and recipe.posix_bash_cmd:
436
+ cmd = f'bash -c "{recipe.posix_bash_cmd}"'
437
+
438
+ if not cmd:
439
+ return False, f"No automated command configured for platform {sys_name} in recipe {recipe.recipe_id}"
440
+
441
+ try:
442
+ res = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=15)
443
+ if res.returncode == 0:
444
+ return True, f"Successfully executed recipe '{recipe.title}': {res.stdout.strip() or 'OK'}"
445
+ return False, f"Recipe '{recipe.title}' failed with code {res.returncode}: {res.stderr.strip()}"
446
+ except Exception as e:
447
+ return False, f"Exception executing recipe '{recipe.title}': {e}"