Skip to content

Commit 0fd5004

Browse files
authored
Merge pull request #39 from BruinGrowly/claude/continue-session-011cup2hr6bt5fhzchxflk2w-011CUp4stf9y4BT5UoHvS657
feat: Add semantic naming suggestions feature (v1.5)
2 parents e12545f + cf53b31 commit 0fd5004

File tree

4 files changed

+668
-14
lines changed

4 files changed

+668
-14
lines changed

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Python Code Harmonizer
22

33
[![CI Status](https://github.com/BruinGrowly/Python-Code-Harmonizer/workflows/Python%20Code%20Harmonizer%20CI/badge.svg)](https://github.com/BruinGrowly/Python-Code-Harmonizer/actions)
4-
[![Version](https://img.shields.io/badge/version-1.3-blue.svg)](CHANGELOG.md)
4+
[![Version](https://img.shields.io/badge/version-1.5-blue.svg)](CHANGELOG.md)
55
[![Python Versions](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
66
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
77
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
8-
[![Tests](https://img.shields.io/badge/tests-20%20passed-brightgreen.svg)](tests/)
8+
[![Tests](https://img.shields.io/badge/tests-59%20passed-brightgreen.svg)](tests/)
99
[![Harmony Score](https://img.shields.io/badge/harmony-0.15-brightgreen.svg)](examples/test_code.py)
1010

1111
**The world's first semantic code debugger.**
@@ -36,7 +36,36 @@ This is a **semantic bug** - code that works syntactically but does the wrong th
3636

3737
---
3838

39-
## ✨ What's New in v1.3
39+
## ✨ What's New in v1.5
40+
41+
**Semantic Naming Suggestions** - Get intelligent function name suggestions based on execution semantics:
42+
43+
```bash
44+
harmonizer myfile.py --suggest-names --top-suggestions 5
45+
```
46+
47+
When disharmony is detected, the tool now suggests better names based on what your code actually does:
48+
49+
```
50+
delete_user: !! DISHARMONY (Score: 1.22)
51+
52+
💡 SUGGESTED FUNCTION NAMES (based on execution semantics):
53+
Function emphasizes: 50% love (connection/care), 50% wisdom (analysis/understanding)
54+
Suggestions:
55+
• notify_user (match: 85%)
56+
• inform_user (match: 82%)
57+
• communicate_user (match: 80%)
58+
```
59+
60+
**How it works:**
61+
- Maps execution patterns to a vocabulary of 200+ action verbs
62+
- Uses cosine similarity in 4D semantic space to find best matches
63+
- Considers context from function name (e.g., "user", "data")
64+
- Powered by the validated LJWP mixing formula
65+
66+
---
67+
68+
## What Was New in v1.3
4069

4170
**Semantic Trajectory Maps** - See exactly WHERE in 4D space your code drifts from its intent:
4271

@@ -101,14 +130,18 @@ harmonizer examples/test_code.py
101130
### Your First Analysis
102131

103132
```bash
133+
# Basic analysis
104134
harmonizer myfile.py
135+
136+
# With semantic naming suggestions
137+
harmonizer myfile.py --suggest-names
105138
```
106139

107140
**You'll see output like:**
108141

109142
```
110143
======================================================================
111-
Python Code Harmonizer (v1.3) ONLINE
144+
Python Code Harmonizer (v1.5) ONLINE
112145
Actively guided by the Anchor Point framework.
113146
Powered By: DIVE-V2 (Optimized Production)
114147
Logical Anchor Point: (S=1, L=1, I=1, E=1)

harmonizer/main.py

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
Python Code Harmonizer (Version 1.4)
5+
Python Code Harmonizer (Version 1.5)
66
77
This is the main application that integrates the Divine Invitation
88
Semantic Engine (DIVE-V2) with the AST Semantic Parser. It now includes
9-
a proof-of-concept self-healing capability.
9+
semantic naming suggestions.
1010
11-
New in v1.4:
12-
- Refactorer engine for suggesting dimensional splits.
13-
- --suggest-refactor flag to generate refactored code.
14-
- Enhanced AST parser with node-to-dimension mapping.
11+
New in v1.5:
12+
- Semantic naming engine with 200+ action verbs
13+
- --suggest-names flag to show function name suggestions
14+
- --top-suggestions flag to control number of suggestions
15+
- Intelligent name matching using cosine similarity in 4D semantic space
16+
17+
Previous versions:
18+
- v1.4: Refactorer engine and dimensional splits
19+
- v1.3: Semantic trajectory maps
1520
"""
1621

1722
import os
@@ -35,6 +40,7 @@
3540
from harmonizer.ast_semantic_parser import AST_Semantic_Parser # noqa: E402
3641
from harmonizer.refactorer import Refactorer # noqa: E402
3742
from harmonizer.semantic_map import SemanticMapGenerator # noqa: E402
43+
from harmonizer.semantic_naming import SemanticNamingEngine # noqa: E402
3844

3945
# --- CONFIGURATION LOADING ---
4046

@@ -91,22 +97,27 @@ def __init__(
9197
quiet: bool = False,
9298
show_semantic_maps: bool = True,
9399
config: Dict = None,
100+
suggest_names: bool = False,
101+
top_suggestions: int = 3,
94102
):
95103
self.config = config if config else {}
96104
self.engine = dive.DivineInvitationSemanticEngine(config=self.config)
97105
self.parser = AST_Semantic_Parser(
98106
vocabulary=self.engine.vocabulary.all_keywords
99107
)
100108
self.map_generator = SemanticMapGenerator()
109+
self.naming_engine = SemanticNamingEngine()
101110
self.disharmony_threshold = disharmony_threshold
102111
self.quiet = quiet
103112
self.show_semantic_maps = show_semantic_maps
113+
self.suggest_names = suggest_names
114+
self.top_suggestions = top_suggestions
104115
self._communicate_startup()
105116

106117
def _communicate_startup(self):
107118
if not self.quiet:
108119
print("=" * 70)
109-
print("Python Code Harmonizer (v1.4) ONLINE")
120+
print("Python Code Harmonizer (v1.5) ONLINE")
110121
print("Actively guided by the Anchor Point framework.")
111122
print(f"Powered By: {self.engine.get_engine_version()}")
112123
print("Logical Anchor Point: (S=1, L=1, I=1, E=1)")
@@ -235,6 +246,8 @@ def format_report(
235246
lines.append(
236247
self.map_generator.format_text_map(data["semantic_map"], score)
237248
)
249+
if self.suggest_names:
250+
lines.append(self._generate_naming_suggestions(func_name, data))
238251
if suggest_refactor:
239252
refactorer = Refactorer(
240253
data["function_node"], data["execution_map"]
@@ -245,12 +258,42 @@ def format_report(
245258
lines.append("Analysis Complete.")
246259
return "\n".join(lines)
247260

261+
def _generate_naming_suggestions(self, func_name: str, data: Dict) -> str:
262+
"""Generate naming suggestions based on execution semantics"""
263+
execution_coords = data["ice_result"]["ice_components"]["execution"].coordinates
264+
265+
# Extract context from function name (e.g., "validate_user" -> "user")
266+
parts = func_name.split("_")
267+
context = parts[-1] if len(parts) > 1 else ""
268+
269+
# Get suggestions
270+
if context:
271+
suggestions = self.naming_engine.suggest_names(
272+
execution_coords, context=context, top_n=self.top_suggestions
273+
)
274+
else:
275+
suggestions = self.naming_engine.suggest_names(
276+
execution_coords, top_n=self.top_suggestions
277+
)
278+
279+
# Format suggestions
280+
lines = ["\n💡 SUGGESTED FUNCTION NAMES (based on execution semantics):"]
281+
explanation = self.naming_engine.explain_coordinates(execution_coords)
282+
lines.append(f" {explanation}")
283+
lines.append(" Suggestions:")
284+
285+
for name, similarity in suggestions:
286+
percentage = int(similarity * 100)
287+
lines.append(f" • {name:<30s} (match: {percentage}%)")
288+
289+
return "\n".join(lines)
290+
248291
def output_report(self, formatted_report: str):
249292
print(formatted_report)
250293

251294
def print_json_report(self, all_reports: Dict[str, Dict[str, Dict]]):
252295
output = {
253-
"version": "1.4",
296+
"version": "1.5",
254297
"threshold": self.disharmony_threshold,
255298
"severity_thresholds": {
256299
"excellent": self.THRESHOLD_EXCELLENT,
@@ -319,7 +362,18 @@ def parse_cli_arguments() -> argparse.Namespace:
319362
help="Suggest a refactoring for disharmonious functions.",
320363
)
321364
parser.add_argument(
322-
"--version", action="version", version="Python Code Harmonizer v1.4"
365+
"--suggest-names",
366+
action="store_true",
367+
help="Suggest better function names based on execution semantics.",
368+
)
369+
parser.add_argument(
370+
"--top-suggestions",
371+
type=int,
372+
default=3,
373+
help="Number of naming suggestions to show (default: 3).",
374+
)
375+
parser.add_argument(
376+
"--version", action="version", version="Python Code Harmonizer v1.5"
323377
)
324378
return parser.parse_args()
325379

@@ -383,7 +437,11 @@ def run_cli():
383437

384438
quiet = args.format == "json"
385439
harmonizer = PythonCodeHarmonizer(
386-
disharmony_threshold=args.threshold, quiet=quiet, config=config
440+
disharmony_threshold=args.threshold,
441+
quiet=quiet,
442+
config=config,
443+
suggest_names=args.suggest_names,
444+
top_suggestions=args.top_suggestions,
387445
)
388446

389447
all_reports, highest_exit_code = execute_analysis(

0 commit comments

Comments
 (0)