Skip to content

Commit 703d8cb

Browse files
authored
Merge pull request #110 from Integration-Automation/dev
Dev
2 parents 8a91b06 + 1a5bf79 commit 703d8cb

File tree

25 files changed

+882
-198
lines changed

25 files changed

+882
-198
lines changed

automation_ide/automation_editor_ui/prompt_edit_gui/__init__.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/__init__.py

File renamed without changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.code_smell_detector import \
2+
CODE_SMELL_DETECTOR_TEMPLATE
3+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.first_code_review import \
4+
FIRST_CODE_REVIEW_TEMPLATE
5+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.first_summary_prompt import \
6+
FIRST_SUMMARY_TEMPLATE
7+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.global_rule import \
8+
GLOBAL_RULE_TEMPLATE
9+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.linter import \
10+
LINTER_TEMPLATE
11+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.total_summary import \
12+
TOTAL_SUMMARY_TEMPLATE
13+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.skills_prompt_templates.code_explainer import \
14+
CODE_EXPLAINER_TEMPLATE
15+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.skills_prompt_templates.code_review import \
16+
CODE_REVIEW_SKILL_TEMPLATE
17+
18+
COT_TEMPLATE_FILES = [
19+
"global_rule.md",
20+
"first_summary_prompt.md",
21+
"first_code_review.md",
22+
"linter.md",
23+
"code_smell_detector.md",
24+
"total_summary.md",
25+
]
26+
27+
COT_TEMPLATE_RELATION = {
28+
"global_rule.md": GLOBAL_RULE_TEMPLATE,
29+
"first_summary_prompt.md": FIRST_SUMMARY_TEMPLATE,
30+
"first_code_review.md": FIRST_CODE_REVIEW_TEMPLATE,
31+
"linter.md": LINTER_TEMPLATE,
32+
"code_smell_detector.md": CODE_SMELL_DETECTOR_TEMPLATE,
33+
"total_summary.md": TOTAL_SUMMARY_TEMPLATE,
34+
}
35+
36+
SKILLS_TEMPLATE_FILES = [
37+
"code_review_skill.md",
38+
"code_explainer_skill.md",
39+
]
40+
41+
SKILLS_TEMPLATE_RELATION = {
42+
"code_review_skill.md": CODE_REVIEW_SKILL_TEMPLATE,
43+
"code_explainer_skill.md": CODE_EXPLAINER_TEMPLATE
44+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import sys
2+
3+
import requests
4+
from PySide6.QtCore import QThread, Signal
5+
from PySide6.QtWidgets import (
6+
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
7+
QPushButton, QTextEdit, QLabel, QLineEdit, QComboBox, QMessageBox
8+
)
9+
from je_editor import language_wrapper
10+
11+
from automation_ide.automation_editor_ui.extend_ai_gui.ai_gui_global_variable import COT_TEMPLATE_FILES, \
12+
COT_TEMPLATE_RELATION
13+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.global_rule import \
14+
build_global_rule_template
15+
from automation_ide.automation_editor_ui.extend_multi_language.update_language_dict import update_language_dict
16+
17+
18+
# Worker Thread 負責傳送資料
19+
class SenderThread(QThread):
20+
update_response = Signal(str, str) # (filename, response)
21+
22+
def __init__(self, files: list, code: str, url: str):
23+
super().__init__()
24+
self.files = files
25+
self.code = code
26+
self.url = url
27+
28+
def run(self):
29+
code = self.code
30+
first_code_review_result = None
31+
first_summary_result = None
32+
linter_result = None
33+
code_smell_result = None
34+
for file in self.files:
35+
match file:
36+
case "first_summary_prompt.md":
37+
first_summary_prompt = COT_TEMPLATE_RELATION.get("first_summary_prompt.md")
38+
prompt = build_global_rule_template(
39+
prompt=first_summary_prompt.format(code_diff=code)
40+
)
41+
case "first_code_review.md":
42+
first_code_review_prompt = COT_TEMPLATE_RELATION.get("first_code_review.md")
43+
prompt = build_global_rule_template(
44+
prompt=first_code_review_prompt.format(code_diff=code)
45+
)
46+
case "linter.md":
47+
linter_prompt = COT_TEMPLATE_RELATION.get("linter.md")
48+
prompt = build_global_rule_template(
49+
prompt=linter_prompt.format(code_diff=code)
50+
)
51+
case "code_smell_detector.md":
52+
code_smell_detector_prompt = COT_TEMPLATE_RELATION.get("code_smell_detector.md")
53+
prompt = build_global_rule_template(
54+
prompt=code_smell_detector_prompt.format(code_diff=code)
55+
)
56+
case "total_summary.md":
57+
total_summary_prompt = COT_TEMPLATE_RELATION.get("total_summary.md")
58+
prompt = build_global_rule_template(
59+
prompt=total_summary_prompt.format(
60+
first_code_review=first_code_review_result,
61+
first_summary=first_summary_result,
62+
linter_result=linter_result,
63+
code_smell_result=code_smell_result,
64+
code_diff=code,
65+
)
66+
)
67+
case _:
68+
continue
69+
70+
try:
71+
# 傳送到指定 URL
72+
resp = requests.post(self.url, json={"prompt": prompt})
73+
reply_text = resp.text
74+
match file:
75+
case "first_summary_prompt.md":
76+
first_summary_result = reply_text
77+
case "first_code_review.md":
78+
first_code_review_result = reply_text
79+
case "linter.md":
80+
linter_result = reply_text
81+
case "code_smell_detector.md":
82+
code_smell_result = reply_text
83+
case _:
84+
continue
85+
except Exception as e:
86+
reply_text = f"{language_wrapper.language_word_dict.get("cot_gui_error_sending")} {file} {e}"
87+
88+
# 發送訊號更新 UI
89+
self.update_response.emit(file, reply_text)
90+
91+
92+
class CoTCodeReviewGUI(QWidget):
93+
def __init__(self):
94+
super().__init__()
95+
self.setWindowTitle(language_wrapper.language_word_dict.get("cot_gui_window_title"))
96+
97+
# 檔案清單
98+
self.files = COT_TEMPLATE_FILES
99+
100+
# UI 元件
101+
layout = QVBoxLayout()
102+
103+
# URL 輸入框
104+
url_layout = QHBoxLayout()
105+
url_layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_api_url")))
106+
self.url_input = QLineEdit()
107+
self.url_input.setPlaceholderText(language_wrapper.language_word_dict.get("cot_gui_placeholder_api_url"))
108+
url_layout.addWidget(self.url_input)
109+
layout.addLayout(url_layout)
110+
111+
# 傳送資料區域
112+
self.code_paste_area = QTextEdit()
113+
self.code_paste_area.setPlaceholderText(
114+
language_wrapper.language_word_dict.get("cot_gui_placeholder_code_paste_area"))
115+
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_prompt_area")))
116+
layout.addWidget(self.code_paste_area)
117+
118+
# 回傳區域
119+
self.response_selector = QComboBox() # 改用 ComboBox
120+
self.response_view = QTextEdit()
121+
self.response_view.setReadOnly(True) # 可複製但不可編輯
122+
123+
hbox_layout = QHBoxLayout()
124+
hbox_layout.addWidget(self.response_selector, 2)
125+
hbox_layout.addWidget(self.response_view, 5)
126+
127+
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_response_area")))
128+
layout.addLayout(hbox_layout)
129+
130+
# 傳送按鈕
131+
self.send_button = QPushButton(language_wrapper.language_word_dict.get("cot_gui_button_send"))
132+
layout.addWidget(self.send_button)
133+
134+
self.setLayout(layout)
135+
136+
# 綁定事件
137+
self.response_selector.currentTextChanged.connect(self.show_response)
138+
self.send_button.clicked.connect(self.start_sending)
139+
140+
# 儲存回覆
141+
self.responses = {}
142+
143+
def show_response(self, filename):
144+
if filename in self.responses:
145+
self.response_view.setPlainText(self.responses[filename])
146+
147+
def start_sending(self):
148+
# 取得 URL
149+
url = self.url_input.text().strip()
150+
if not url:
151+
message_box = QMessageBox()
152+
message_box.warning(self, "Warning", language_wrapper.language_word_dict.get("cot_gui_error_no_url"))
153+
message_box.exec_()
154+
return
155+
156+
# 啟動傳送 Thread
157+
self.thread = SenderThread(files=self.files, code=self.code_paste_area.toPlainText(), url=url)
158+
self.thread.update_response.connect(self.handle_response)
159+
self.thread.start()
160+
161+
def handle_response(self, filename, response):
162+
self.responses[filename] = response
163+
self.response_selector.addItem(filename) # 加入 ComboBox
164+
# 自動顯示最新回覆
165+
self.response_selector.setCurrentText(filename)

automation_ide/automation_editor_ui/prompt_edit_gui/prompt_templates/__init__.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/__init__.py

File renamed without changes.

automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CODE_SMELL_DETECTOR_TEMPLATE = """
2+
You are a senior software engineer specializing in code quality reviews.
3+
Carefully analyze the following code and identify all possible **code smells**.
4+
Provide a structured and detailed output.
5+
6+
### Output Requirements:
7+
1. **Code Smell Type**: Specify the exact issue (e.g., long function, magic numbers, duplicate code, unclear naming, tight coupling, violation of single responsibility principle, etc.).
8+
2. **Problem Location**: Point out the relevant code block or example.
9+
3. **Detailed Explanation**: Explain why this is considered a code smell and what problems it may cause in terms of readability, maintainability, or scalability.
10+
4. **Improvement Suggestions**: Provide specific refactoring or optimization recommendations that follow software engineering best practices.
11+
5. **Priority Level**: Rank the severity as High, Medium, or Low to help developers decide the order of fixes.
12+
13+
### Output Format:
14+
- Code Smell Type:
15+
- Problem Location:
16+
- Detailed Explanation:
17+
- Improvement Suggestions:
18+
- Priority Level:
19+
20+
### Code:
21+
{code_diff}
22+
"""
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FIRST_CODE_REVIEW_TEMPLATE = """
2+
# Code Review Template
3+
4+
## Review Rules
5+
Perform a first-step code review focusing on:
6+
1. Code readability (indentation, formatting, comments).
7+
2. Clarity and descriptiveness of variable, function, and class names; avoid vague or cryptic naming.
8+
3. Adherence to basic software engineering standards (modularity, maintainability, avoidance of duplicate code).
9+
4. Identification of obvious logical errors or potential bugs.
10+
5. Provide concise improvement suggestions with short explanations.
11+
6. Focus only on the most obvious issues; avoid deep analysis at this stage.
12+
13+
Respond in a structured bullet-point format, keeping feedback concise and professional.
14+
15+
## Code diff
16+
{code_diff}
17+
"""

automation_ide/automation_editor_ui/prompt_edit_gui/prompt_templates/first_summary_prompt.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/first_summary_prompt.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
FIRST_SUMMARY_PROMPT = """
2-
## PR Description
3-
{pr_description}}
1+
FIRST_SUMMARY_TEMPLATE = """
2+
# PR Summary Template
43
54
## Summary Rules
6-
Please generate a first-step Pull Request summary (PR Summary) focusing on:
5+
Generate a first-step Pull Request summary focusing on:
76
1. Key changes: Briefly describe the core modifications or new features.
87
2. Impact scope: Identify affected modules, files, or functionalities.
98
3. Purpose of changes: Explain why these modifications are needed (e.g., bug fix, performance optimization, feature addition).
109
4. Risks and considerations: Highlight potential impacts on existing functionality or areas requiring extra testing.
1110
5. Items to confirm: List specific points that reviewers should pay attention to or validate.
12-
6. Avoid excessive technical detail; keep the summary at a high level for quick team understanding.
11+
6. Avoid excessive technical detail; keep the summary high-level for quick team understanding.
1312
14-
Write in a structured, bullet-point format, keeping the summary concise and professional for quick team understanding.
13+
Write in structured bullet points; keep concise and professional.
1514
16-
## Code diff to review:
17-
```diff
18-
# Paste your code diff here
15+
## Code diff to review
1916
{code_diff}
20-
```
2117
"""

automation_ide/automation_editor_ui/prompt_edit_gui/prompt_templates/global_rule.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/global_rule.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,36 @@
2424
6. Documentation & Testing
2525
- Ensure necessary comments and documentation are present.
2626
- Verify sufficient unit and integration tests are included.
27-
28-
7. When scoring, balance conciseness with comprehensiveness; avoid penalizing completeness for being less concise.”
2927
30-
Provide review feedback in a structured bullet-point format, keeping it professional, concise, and with actionable improvement suggestions.
28+
7. Scoring & Feedback Style
29+
- Balance conciseness with comprehensiveness.
30+
- Do not penalize completeness for being less concise.
31+
32+
{rag_rules_section}
33+
---
34+
35+
# Prompt Content
36+
{prompt}
37+
"""
38+
39+
def build_global_rule_template(rag_rules=None, prompt=""):
40+
if not rag_rules:
41+
rag_rules_section = "" # 忽略 RAG Rules 區塊
42+
else:
43+
if isinstance(rag_rules, list):
44+
rag_rules_text = "".join(f" - {rule}" for rule in rag_rules)
45+
else:
46+
rag_rules_text = f" - {rag_rules}"
47+
48+
rag_rules_section = f"""
49+
8. RAG Rules (Retrieval-Augmented Guidance)
50+
- Apply RAG-provided rules when available.
51+
- If a rule conflicts or duplicates existing global rules, prioritize the RAG rule.
52+
- Ensure integration of RAG rules maintains consistency with overall review standards.
53+
{rag_rules_text}
3154
"""
55+
56+
return GLOBAL_RULE_TEMPLATE.format(
57+
rag_rules_section=rag_rules_section,
58+
prompt=prompt
59+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
LINTER_TEMPLATE = """
2+
You are a strict code linter.
3+
Your task is to analyze the given source code and produce structured linter_messages.
4+
Follow these rules:
5+
6+
1. Do not rewrite or fix the code — only report issues.
7+
2. Each linter_message must include:
8+
- rule_id: A short identifier for the rule violated (e.g., "no-unused-vars").
9+
- severity: One of ["error", "warning", "info"].
10+
- message: A clear explanation of the issue.
11+
- line: The line number where the issue occurs.
12+
- suggestion: A concise recommendation for improvement.
13+
3. If no issues are found, return an empty list.
14+
15+
Now analyze the following code:
16+
{code_diff}
17+
"""

0 commit comments

Comments
 (0)