tzero-mcp 10.7.4 → 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.
- package/CHANGELOG.md +56 -29
- package/CONTRIBUTING.md +71 -71
- package/README.md +64 -64
- package/bin/tzero-mcp.js +62 -66
- package/bin/tzero.js +61 -65
- package/index.d.ts +25 -25
- package/index.js +15 -15
- package/package.json +88 -88
- package/src/addmcp.py +14 -11
- package/src/app.py +1810 -0
- package/src/main.py +1 -1
- package/src/pc_fixer_mcp.py +25 -0
- package/src/tzero/__init__.py +54 -0
- package/src/tzero/__main__.py +6 -0
- package/src/tzero/siber_akademi.ico +0 -0
- package/src/tzero/tzero_arch_test.py +463 -0
- package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
- package/src/tzero/tzero_blackboard.py +257 -0
- package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
- package/src/tzero/tzero_budget.py +195 -0
- package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
- package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
- package/src/tzero/tzero_contracts.py +1093 -0
- package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
- package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
- package/src/tzero/tzero_debt.py +461 -0
- package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
- package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
- package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
- package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
- package/src/tzero/tzero_federation.py +299 -0
- package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
- package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
- package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
- package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
- package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
- package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
- package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
- package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
- package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
- package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
- package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
- package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
- package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
- package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
- package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
- package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
- package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
- package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
- package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
- package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
- package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
- package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
- package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
- package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
- package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
- package/src/tzero/tzero_golden.py +319 -0
- package/src/tzero/tzero_graph_hud.html +338 -0
- package/src/tzero/tzero_graph_rag.py +263 -0
- package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
- package/src/tzero/tzero_hooks.py +565 -0
- package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
- package/src/tzero/tzero_lsp.py +634 -0
- package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
- package/src/tzero/tzero_mutation.py +358 -0
- package/src/tzero/tzero_packer.py +577 -0
- package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
- package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
- package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
- package/src/tzero/tzero_polyglot.py +799 -0
- package/src/tzero/tzero_proxy.py +127 -0
- package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
- package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
- package/src/tzero/tzero_rust_bridge.py +198 -0
- package/src/tzero/tzero_scip.py +368 -0
- package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
- package/src/tzero/tzero_semantic_merge.py +189 -0
- package/src/tzero/tzero_snapshot.py +471 -0
- package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
- package/src/tzero/tzero_subagent_engine.py +459 -0
- package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
- package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
- package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
- package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
- package/src/tzero/tzero_turbo.py +264 -0
- package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
- package/src/tzero.py +2 -54
- package/test/package.test.js +55 -43
- package/src/tzero/jarvis/semantic_compressor.py +0 -373
- package/src/tzero_gateway.py +0 -885
- package/src/tzero_packer.py +0 -370
- package/src/tzero_polyglot.py +0 -422
- package/src/tzero_snapshot.py +0 -258
- /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
- /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Siber Akademi — T-Zero Local Semantic Git Commit & Changelog Synthesizer.
|
|
4
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
-
License: MIT
|
|
6
|
-
|
|
7
|
-
Analyzes staged or unstaged AST git diffs locally (100% offline, $0 cost) to
|
|
8
|
-
synthesize Conventional Commit messages and structured CHANGELOG entries
|
|
9
|
-
without transmitting code to cloud LLMs.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
import sys
|
|
13
|
-
if sys.platform == "win32":
|
|
14
|
-
try:
|
|
15
|
-
sys.stdout.reconfigure(encoding="utf-8")
|
|
16
|
-
sys.stderr.reconfigure(encoding="utf-8")
|
|
17
|
-
except Exception:
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
import os
|
|
21
|
-
import re
|
|
22
|
-
import subprocess
|
|
23
|
-
from dataclasses import dataclass, field
|
|
24
|
-
from typing import Dict, List, Optional, Tuple, Any
|
|
25
|
-
|
|
26
|
-
from tzero_patch import ASTFuzzyPatcher
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@dataclass
|
|
30
|
-
class DiffSemantics:
|
|
31
|
-
"""Analyzed semantics of a git diff."""
|
|
32
|
-
commit_type: str
|
|
33
|
-
scope: str
|
|
34
|
-
headline: str
|
|
35
|
-
bullets: List[str] = field(default_factory=list)
|
|
36
|
-
modified_files: List[str] = field(default_factory=list)
|
|
37
|
-
symbols_modified: List[str] = field(default_factory=list)
|
|
38
|
-
raw_diff_tokens: int = 0
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class LocalSemanticCommitSynthesizer:
|
|
42
|
-
"""Zero-cost local synthesizer for Conventional Commits and release notes."""
|
|
43
|
-
|
|
44
|
-
@classmethod
|
|
45
|
-
def get_git_diff(cls, repo_dir: str = ".", staged: bool = True) -> str:
|
|
46
|
-
"""Retrieves staged or unstaged git diff."""
|
|
47
|
-
cmd = ["git", "diff", "--staged"] if staged else ["git", "diff"]
|
|
48
|
-
try:
|
|
49
|
-
res = subprocess.run(cmd, cwd=repo_dir, capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
50
|
-
output = res.stdout
|
|
51
|
-
if not output.strip() and staged:
|
|
52
|
-
# Fallback to unstaged or HEAD~1 if staged is empty
|
|
53
|
-
res2 = subprocess.run(["git", "diff", "HEAD~1"], cwd=repo_dir, capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
54
|
-
output = res2.stdout
|
|
55
|
-
return output
|
|
56
|
-
except Exception:
|
|
57
|
-
return ""
|
|
58
|
-
|
|
59
|
-
@classmethod
|
|
60
|
-
def analyze_diff(cls, diff_text: str) -> DiffSemantics:
|
|
61
|
-
"""Parses diff hunks and infers conventional commit type, scope, and bullets."""
|
|
62
|
-
if not diff_text or not diff_text.strip():
|
|
63
|
-
return DiffSemantics(
|
|
64
|
-
commit_type="chore",
|
|
65
|
-
scope="repo",
|
|
66
|
-
headline="update codebase files",
|
|
67
|
-
bullets=["general maintenance updates"]
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
file_patches = ASTFuzzyPatcher.parse_patch(diff_text)
|
|
71
|
-
files = [fp.target_file or fp.source_file or "unknown" for fp in file_patches if fp.target_file or fp.source_file]
|
|
72
|
-
|
|
73
|
-
# Extract symbols touched from hunk scopes and newly added definitions
|
|
74
|
-
symbols = []
|
|
75
|
-
for fp in file_patches:
|
|
76
|
-
for h in fp.hunks:
|
|
77
|
-
sym = ASTFuzzyPatcher.extract_symbol_name(h.symbol_scope)
|
|
78
|
-
if sym and sym not in symbols:
|
|
79
|
-
symbols.append(sym)
|
|
80
|
-
for nl in h.new_lines:
|
|
81
|
-
trimmed_nl = nl.strip()
|
|
82
|
-
m_def = re.match(r"^(?:async\s+)?(?:def|class|pub\s+fn|func|fn|struct|interface)\s+([A-Za-z0-9_]+)", trimmed_nl)
|
|
83
|
-
if m_def:
|
|
84
|
-
s_name = m_def.group(1)
|
|
85
|
-
if s_name not in symbols:
|
|
86
|
-
symbols.append(s_name)
|
|
87
|
-
|
|
88
|
-
# Inferred scope
|
|
89
|
-
scope = "core"
|
|
90
|
-
if files:
|
|
91
|
-
first = files[0].lower().replace("\\", "/")
|
|
92
|
-
if "test" in first:
|
|
93
|
-
scope = "tests"
|
|
94
|
-
elif "benchmark" in first or "dashboard" in first:
|
|
95
|
-
scope = "dashboard"
|
|
96
|
-
elif "patch" in first:
|
|
97
|
-
scope = "patcher"
|
|
98
|
-
elif "polyglot" in first:
|
|
99
|
-
scope = "polyglot"
|
|
100
|
-
elif "packer" in first:
|
|
101
|
-
scope = "packer"
|
|
102
|
-
elif "features" in first:
|
|
103
|
-
scope = "features"
|
|
104
|
-
elif "mcp" in first:
|
|
105
|
-
scope = "mcp"
|
|
106
|
-
elif "vscode" in first or "extension" in first:
|
|
107
|
-
scope = "vscode"
|
|
108
|
-
else:
|
|
109
|
-
base = os.path.basename(first).split(".")[0]
|
|
110
|
-
scope = base.replace("tzero_", "").replace("_", "-")
|
|
111
|
-
|
|
112
|
-
# Inferred type
|
|
113
|
-
all_tests = all("test" in f.lower() for f in files) if files else False
|
|
114
|
-
all_docs = all(f.lower().endswith((".md", ".rst", ".txt")) for f in files) if files else False
|
|
115
|
-
|
|
116
|
-
diff_lower = diff_text.lower()
|
|
117
|
-
has_fixes = any(w in diff_lower for w in ("fix", "bug", "error", "traceback", "exception", "failed", "crash"))
|
|
118
|
-
has_tests = any("def test_" in diff_text or "class Test" in diff_text for _ in [1])
|
|
119
|
-
has_new_defs = bool(re.search(r"^\+\s*(?:def|class|pub fn|func|struct)\s+[A-Za-z0-9_]+", diff_text, re.MULTILINE))
|
|
120
|
-
|
|
121
|
-
if all_tests:
|
|
122
|
-
commit_type = "test"
|
|
123
|
-
elif all_docs:
|
|
124
|
-
commit_type = "docs"
|
|
125
|
-
elif has_new_defs:
|
|
126
|
-
commit_type = "feat"
|
|
127
|
-
elif has_fixes:
|
|
128
|
-
commit_type = "fix"
|
|
129
|
-
elif has_tests:
|
|
130
|
-
commit_type = "test"
|
|
131
|
-
else:
|
|
132
|
-
commit_type = "refactor"
|
|
133
|
-
|
|
134
|
-
# Generate descriptive bullets
|
|
135
|
-
bullets = []
|
|
136
|
-
for fp in file_patches:
|
|
137
|
-
fname = fp.target_file or fp.source_file or "file"
|
|
138
|
-
bname = os.path.basename(fname)
|
|
139
|
-
hunk_count = len(fp.hunks)
|
|
140
|
-
fp_syms = [ASTFuzzyPatcher.extract_symbol_name(h.symbol_scope) for h in fp.hunks]
|
|
141
|
-
valid_syms = [s for s in fp_syms if s]
|
|
142
|
-
if valid_syms:
|
|
143
|
-
bullets.append(f"enhance `{bname}` ({', '.join(valid_syms[:3])})")
|
|
144
|
-
else:
|
|
145
|
-
bullets.append(f"update `{bname}` with {hunk_count} hunk{'s' if hunk_count > 1 else ''}")
|
|
146
|
-
|
|
147
|
-
# Construct headline
|
|
148
|
-
if symbols:
|
|
149
|
-
top_sym = symbols[0]
|
|
150
|
-
action = "add" if commit_type == "feat" else "update"
|
|
151
|
-
headline = f"{action} {top_sym} and related AST capabilities"
|
|
152
|
-
elif files:
|
|
153
|
-
headline = f"improve {scope} components and workflow definitions"
|
|
154
|
-
else:
|
|
155
|
-
headline = "update workspace components"
|
|
156
|
-
|
|
157
|
-
return DiffSemantics(
|
|
158
|
-
commit_type=commit_type,
|
|
159
|
-
scope=scope,
|
|
160
|
-
headline=headline,
|
|
161
|
-
bullets=bullets[:6],
|
|
162
|
-
modified_files=files,
|
|
163
|
-
symbols_modified=symbols,
|
|
164
|
-
raw_diff_tokens=max(1, len(diff_text) // 4)
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
@classmethod
|
|
168
|
-
def generate_commit_message(cls, repo_dir: str = ".", staged: bool = True, diff_override: Optional[str] = None) -> str:
|
|
169
|
-
"""Generates a Conventional Commit message from local AST git diff."""
|
|
170
|
-
diff_text = diff_override if diff_override is not None else cls.get_git_diff(repo_dir=repo_dir, staged=staged)
|
|
171
|
-
sem = cls.analyze_diff(diff_text)
|
|
172
|
-
|
|
173
|
-
subject = f"{sem.commit_type}({sem.scope}): {sem.headline}"
|
|
174
|
-
body_lines = [f"- {b}" for b in sem.bullets]
|
|
175
|
-
body = "\n".join(body_lines)
|
|
176
|
-
|
|
177
|
-
msg = f"{subject}\n\n{body}\n\nSigned-off-by: T-Zero Autonomous Local Synthesizer ($0 Local Engine)"
|
|
178
|
-
return msg
|
|
179
|
-
|
|
180
|
-
@classmethod
|
|
181
|
-
def generate_changelog_entry(cls, version: str = "v8.1.0", repo_dir: str = ".") -> str:
|
|
182
|
-
"""Generates a Markdown release changelog entry from git history."""
|
|
183
|
-
msg = cls.generate_commit_message(repo_dir=repo_dir, staged=True)
|
|
184
|
-
sem = cls.analyze_diff(cls.get_git_diff(repo_dir=repo_dir, staged=True))
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
f"## [{version}] - Local AST Release\n\n"
|
|
188
|
-
f"### 🚀 {sem.commit_type.upper()}: {sem.scope.capitalize()}\n"
|
|
189
|
-
+ "\n".join(f"* {b}" for b in sem.bullets)
|
|
190
|
-
+ f"\n\n* **Modified Modules:** {len(sem.modified_files)} files\n"
|
|
191
|
-
f"* **AST Symbols Touched:** {', '.join(sem.symbols_modified[:5]) or 'Internal Logic'}\n"
|
|
192
|
-
)
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Siber Akademi — T-Zero Local Semantic Git Commit & Changelog Synthesizer.
|
|
4
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
+
License: MIT
|
|
6
|
+
|
|
7
|
+
Analyzes staged or unstaged AST git diffs locally (100% offline, $0 cost) to
|
|
8
|
+
synthesize Conventional Commit messages and structured CHANGELOG entries
|
|
9
|
+
without transmitting code to cloud LLMs.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
if sys.platform == "win32":
|
|
14
|
+
try:
|
|
15
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
16
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
17
|
+
except Exception:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import subprocess
|
|
23
|
+
from dataclasses import dataclass, field
|
|
24
|
+
from typing import Dict, List, Optional, Tuple, Any
|
|
25
|
+
|
|
26
|
+
from tzero.tzero_patch import ASTFuzzyPatcher
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class DiffSemantics:
|
|
31
|
+
"""Analyzed semantics of a git diff."""
|
|
32
|
+
commit_type: str
|
|
33
|
+
scope: str
|
|
34
|
+
headline: str
|
|
35
|
+
bullets: List[str] = field(default_factory=list)
|
|
36
|
+
modified_files: List[str] = field(default_factory=list)
|
|
37
|
+
symbols_modified: List[str] = field(default_factory=list)
|
|
38
|
+
raw_diff_tokens: int = 0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class LocalSemanticCommitSynthesizer:
|
|
42
|
+
"""Zero-cost local synthesizer for Conventional Commits and release notes."""
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def get_git_diff(cls, repo_dir: str = ".", staged: bool = True) -> str:
|
|
46
|
+
"""Retrieves staged or unstaged git diff."""
|
|
47
|
+
cmd = ["git", "diff", "--staged"] if staged else ["git", "diff"]
|
|
48
|
+
try:
|
|
49
|
+
res = subprocess.run(cmd, cwd=repo_dir, capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
50
|
+
output = res.stdout
|
|
51
|
+
if not output.strip() and staged:
|
|
52
|
+
# Fallback to unstaged or HEAD~1 if staged is empty
|
|
53
|
+
res2 = subprocess.run(["git", "diff", "HEAD~1"], cwd=repo_dir, capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
54
|
+
output = res2.stdout
|
|
55
|
+
return output
|
|
56
|
+
except Exception:
|
|
57
|
+
return ""
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def analyze_diff(cls, diff_text: str) -> DiffSemantics:
|
|
61
|
+
"""Parses diff hunks and infers conventional commit type, scope, and bullets."""
|
|
62
|
+
if not diff_text or not diff_text.strip():
|
|
63
|
+
return DiffSemantics(
|
|
64
|
+
commit_type="chore",
|
|
65
|
+
scope="repo",
|
|
66
|
+
headline="update codebase files",
|
|
67
|
+
bullets=["general maintenance updates"]
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
file_patches = ASTFuzzyPatcher.parse_patch(diff_text)
|
|
71
|
+
files = [fp.target_file or fp.source_file or "unknown" for fp in file_patches if fp.target_file or fp.source_file]
|
|
72
|
+
|
|
73
|
+
# Extract symbols touched from hunk scopes and newly added definitions
|
|
74
|
+
symbols = []
|
|
75
|
+
for fp in file_patches:
|
|
76
|
+
for h in fp.hunks:
|
|
77
|
+
sym = ASTFuzzyPatcher.extract_symbol_name(h.symbol_scope)
|
|
78
|
+
if sym and sym not in symbols:
|
|
79
|
+
symbols.append(sym)
|
|
80
|
+
for nl in h.new_lines:
|
|
81
|
+
trimmed_nl = nl.strip()
|
|
82
|
+
m_def = re.match(r"^(?:async\s+)?(?:def|class|pub\s+fn|func|fn|struct|interface)\s+([A-Za-z0-9_]+)", trimmed_nl)
|
|
83
|
+
if m_def:
|
|
84
|
+
s_name = m_def.group(1)
|
|
85
|
+
if s_name not in symbols:
|
|
86
|
+
symbols.append(s_name)
|
|
87
|
+
|
|
88
|
+
# Inferred scope
|
|
89
|
+
scope = "core"
|
|
90
|
+
if files:
|
|
91
|
+
first = files[0].lower().replace("\\", "/")
|
|
92
|
+
if "test" in first:
|
|
93
|
+
scope = "tests"
|
|
94
|
+
elif "benchmark" in first or "dashboard" in first:
|
|
95
|
+
scope = "dashboard"
|
|
96
|
+
elif "patch" in first:
|
|
97
|
+
scope = "patcher"
|
|
98
|
+
elif "polyglot" in first:
|
|
99
|
+
scope = "polyglot"
|
|
100
|
+
elif "packer" in first:
|
|
101
|
+
scope = "packer"
|
|
102
|
+
elif "features" in first:
|
|
103
|
+
scope = "features"
|
|
104
|
+
elif "mcp" in first:
|
|
105
|
+
scope = "mcp"
|
|
106
|
+
elif "vscode" in first or "extension" in first:
|
|
107
|
+
scope = "vscode"
|
|
108
|
+
else:
|
|
109
|
+
base = os.path.basename(first).split(".")[0]
|
|
110
|
+
scope = base.replace("tzero_", "").replace("_", "-")
|
|
111
|
+
|
|
112
|
+
# Inferred type
|
|
113
|
+
all_tests = all("test" in f.lower() for f in files) if files else False
|
|
114
|
+
all_docs = all(f.lower().endswith((".md", ".rst", ".txt")) for f in files) if files else False
|
|
115
|
+
|
|
116
|
+
diff_lower = diff_text.lower()
|
|
117
|
+
has_fixes = any(w in diff_lower for w in ("fix", "bug", "error", "traceback", "exception", "failed", "crash"))
|
|
118
|
+
has_tests = any("def test_" in diff_text or "class Test" in diff_text for _ in [1])
|
|
119
|
+
has_new_defs = bool(re.search(r"^\+\s*(?:def|class|pub fn|func|struct)\s+[A-Za-z0-9_]+", diff_text, re.MULTILINE))
|
|
120
|
+
|
|
121
|
+
if all_tests:
|
|
122
|
+
commit_type = "test"
|
|
123
|
+
elif all_docs:
|
|
124
|
+
commit_type = "docs"
|
|
125
|
+
elif has_new_defs:
|
|
126
|
+
commit_type = "feat"
|
|
127
|
+
elif has_fixes:
|
|
128
|
+
commit_type = "fix"
|
|
129
|
+
elif has_tests:
|
|
130
|
+
commit_type = "test"
|
|
131
|
+
else:
|
|
132
|
+
commit_type = "refactor"
|
|
133
|
+
|
|
134
|
+
# Generate descriptive bullets
|
|
135
|
+
bullets = []
|
|
136
|
+
for fp in file_patches:
|
|
137
|
+
fname = fp.target_file or fp.source_file or "file"
|
|
138
|
+
bname = os.path.basename(fname)
|
|
139
|
+
hunk_count = len(fp.hunks)
|
|
140
|
+
fp_syms = [ASTFuzzyPatcher.extract_symbol_name(h.symbol_scope) for h in fp.hunks]
|
|
141
|
+
valid_syms = [s for s in fp_syms if s]
|
|
142
|
+
if valid_syms:
|
|
143
|
+
bullets.append(f"enhance `{bname}` ({', '.join(valid_syms[:3])})")
|
|
144
|
+
else:
|
|
145
|
+
bullets.append(f"update `{bname}` with {hunk_count} hunk{'s' if hunk_count > 1 else ''}")
|
|
146
|
+
|
|
147
|
+
# Construct headline
|
|
148
|
+
if symbols:
|
|
149
|
+
top_sym = symbols[0]
|
|
150
|
+
action = "add" if commit_type == "feat" else "update"
|
|
151
|
+
headline = f"{action} {top_sym} and related AST capabilities"
|
|
152
|
+
elif files:
|
|
153
|
+
headline = f"improve {scope} components and workflow definitions"
|
|
154
|
+
else:
|
|
155
|
+
headline = "update workspace components"
|
|
156
|
+
|
|
157
|
+
return DiffSemantics(
|
|
158
|
+
commit_type=commit_type,
|
|
159
|
+
scope=scope,
|
|
160
|
+
headline=headline,
|
|
161
|
+
bullets=bullets[:6],
|
|
162
|
+
modified_files=files,
|
|
163
|
+
symbols_modified=symbols,
|
|
164
|
+
raw_diff_tokens=max(1, len(diff_text) // 4)
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
@classmethod
|
|
168
|
+
def generate_commit_message(cls, repo_dir: str = ".", staged: bool = True, diff_override: Optional[str] = None) -> str:
|
|
169
|
+
"""Generates a Conventional Commit message from local AST git diff."""
|
|
170
|
+
diff_text = diff_override if diff_override is not None else cls.get_git_diff(repo_dir=repo_dir, staged=staged)
|
|
171
|
+
sem = cls.analyze_diff(diff_text)
|
|
172
|
+
|
|
173
|
+
subject = f"{sem.commit_type}({sem.scope}): {sem.headline}"
|
|
174
|
+
body_lines = [f"- {b}" for b in sem.bullets]
|
|
175
|
+
body = "\n".join(body_lines)
|
|
176
|
+
|
|
177
|
+
msg = f"{subject}\n\n{body}\n\nSigned-off-by: T-Zero Autonomous Local Synthesizer ($0 Local Engine)"
|
|
178
|
+
return msg
|
|
179
|
+
|
|
180
|
+
@classmethod
|
|
181
|
+
def generate_changelog_entry(cls, version: str = "v8.1.0", repo_dir: str = ".") -> str:
|
|
182
|
+
"""Generates a Markdown release changelog entry from git history."""
|
|
183
|
+
msg = cls.generate_commit_message(repo_dir=repo_dir, staged=True)
|
|
184
|
+
sem = cls.analyze_diff(cls.get_git_diff(repo_dir=repo_dir, staged=True))
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
f"## [{version}] - Local AST Release\n\n"
|
|
188
|
+
f"### 🚀 {sem.commit_type.upper()}: {sem.scope.capitalize()}\n"
|
|
189
|
+
+ "\n".join(f"* {b}" for b in sem.bullets)
|
|
190
|
+
+ f"\n\n* **Modified Modules:** {len(sem.modified_files)} files\n"
|
|
191
|
+
f"* **AST Symbols Touched:** {', '.join(sem.symbols_modified[:5]) or 'Internal Logic'}\n"
|
|
192
|
+
)
|