Skip to content

Commit 61ef176

Browse files
authored
feat(jmanus): support load en | zh system agents (alibaba#1936)
* feat(jmanus): support load en | zh system agents * feat(jmanus): support load en | zh system agents * feat(jmanus): support load en | zh system agents * test * test * test * test * test * test * test
1 parent 4afb9b2 commit 61ef176

File tree

84 files changed

+2240
-824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2240
-824
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2024-2026 the original author or authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: Check Chinese Content in Jmanus
15+
16+
on:
17+
pull_request:
18+
paths:
19+
- 'spring-ai-alibaba-jmanus/src/main/java/**/*.java'
20+
21+
jobs:
22+
check-chinese-content:
23+
runs-on: ubuntu-latest
24+
name: Check for Chinese content in Java files
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v4
34+
with:
35+
python-version: '3.9'
36+
37+
- name: Check Chinese content in Jmanus Java files
38+
run: |
39+
cd spring-ai-alibaba-jmanus
40+
echo "🔍 Checking for Chinese content in Java files..."
41+
echo ""
42+
43+
if python scripts/check-chinese-content.py --dir src/main/java --fail-on-found; then
44+
echo "✅ No Chinese content found - Check passed!"
45+
else
46+
echo ""
47+
echo "## 🚨 Chinese Content Detected"
48+
echo ""
49+
echo "Chinese content has been detected in Java files under spring-ai-alibaba-jmanus/src/main/java directory."
50+
echo ""
51+
echo "### Detailed Check Results:"
52+
python scripts/check-chinese-content.py --dir src/main/java
53+
echo ""
54+
echo "### Modification Suggestions:"
55+
echo ""
56+
echo "1. **Chinese Comments** → Change to English Comments"
57+
echo " Example:"
58+
echo " // ❌ Incorrect: // 这是一个用户服务类"
59+
echo " // ✅ Correct: // This is a user service class"
60+
echo ""
61+
echo "2. **Chinese Strings** → Extract to resource files or use English"
62+
echo " Example:"
63+
echo " // ❌ Incorrect: throw new RuntimeException(\"用户不存在\");"
64+
echo " // ✅ Correct: throw new RuntimeException(\"User not found\");"
65+
echo ""
66+
echo "3. **Chinese Identifiers** → Change to English Identifiers"
67+
echo " Example:"
68+
echo " // ❌ Incorrect: String 用户名 = \"admin\";"
69+
echo " // ✅ Correct: String username = \"admin\";"
70+
echo ""
71+
echo "### Why Avoid Chinese Content?"
72+
echo ""
73+
echo "- 🌍 Internationalization Friendly: Facilitates project internationalization"
74+
echo "- 🔧 Development Environment Compatibility: Avoids encoding issues"
75+
echo "- 👥 Team Collaboration: Enables international team members to understand code"
76+
echo "- 📚 Code Standards: Follows open source project best practices"
77+
echo ""
78+
echo "❌ Please modify the relevant files and resubmit."
79+
exit 1
80+
fi
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
#
5+
# Copyright 2024-2026 the original author or authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# https://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
"""
21+
Spring AI Alibaba Jmanus Chinese Content Checker
22+
Tool for checking Chinese content in Java code for GitHub Actions
23+
"""
24+
25+
import os
26+
import re
27+
import sys
28+
import json
29+
import argparse
30+
from pathlib import Path
31+
from typing import List, Dict, Set
32+
from collections import defaultdict
33+
34+
class ChineseContentChecker:
35+
def __init__(self, target_dir: str):
36+
self.target_dir = Path(target_dir)
37+
# Detect Chinese characters, excluding Chinese punctuation to avoid false positives
38+
self.chinese_pattern = re.compile(r'[\u4e00-\u9fff]')
39+
# Chinese punctuation detection
40+
self.chinese_punctuation = re.compile(r',。!?;:""()【】《》')
41+
42+
# Exclude common English phrases to avoid false positives
43+
self.exclude_patterns = [
44+
r'\bAS IS\b', # "AS IS" in Apache License
45+
r'\bIS NULL\b', # "IS NULL" in SQL
46+
r'\bIS NOT\b', # "IS NOT" in SQL
47+
r'@author\s+\w+', # Author information
48+
r'@time\s+\d{4}/\d{1,2}/\d{1,2}', # Time information
49+
]
50+
51+
self.issues = []
52+
53+
def has_real_chinese_content(self, text: str) -> bool:
54+
"""Check if text contains real Chinese content (excluding false positives)"""
55+
# First check if there are Chinese characters or Chinese punctuation
56+
if not (self.chinese_pattern.search(text) or self.chinese_punctuation.search(text)):
57+
return False
58+
59+
# Exclude common English phrases
60+
for pattern in self.exclude_patterns:
61+
if re.search(pattern, text, re.IGNORECASE):
62+
# If matched exclude pattern, further check if it really contains Chinese
63+
temp_text = re.sub(pattern, '', text, flags=re.IGNORECASE)
64+
if not (self.chinese_pattern.search(temp_text) or self.chinese_punctuation.search(temp_text)):
65+
return False
66+
67+
return True
68+
69+
def check_file(self, file_path: Path) -> List[Dict]:
70+
"""Check single file for Chinese content, return list of issues"""
71+
issues = []
72+
73+
try:
74+
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
75+
lines = f.readlines()
76+
77+
in_multiline_comment = False
78+
79+
for line_num, line in enumerate(lines, 1):
80+
original_line = line.rstrip()
81+
line_stripped = line.strip()
82+
83+
if not line_stripped:
84+
continue
85+
86+
# Check if contains real Chinese content
87+
if not self.has_real_chinese_content(line_stripped):
88+
continue
89+
90+
# Analyze the type of location where Chinese content appears
91+
content_type = self._analyze_content_type(line_stripped, in_multiline_comment)
92+
93+
# Update multiline comment status
94+
if '/*' in line_stripped:
95+
in_multiline_comment = True
96+
if '*/' in line_stripped:
97+
in_multiline_comment = False
98+
99+
issues.append({
100+
'file': str(file_path.relative_to(self.target_dir.parent)),
101+
'line': line_num,
102+
'content': original_line,
103+
'type': content_type,
104+
'message': f"Found Chinese content in {content_type}"
105+
})
106+
107+
except Exception as e:
108+
print(f"Warning: Unable to read file {file_path}: {e}", file=sys.stderr)
109+
110+
return issues
111+
112+
def _analyze_content_type(self, line: str, in_multiline_comment: bool) -> str:
113+
"""Analyze the type of Chinese content location"""
114+
if in_multiline_comment or line.startswith('/*'):
115+
return "multiline comment"
116+
117+
if line.startswith('//'):
118+
return "single line comment"
119+
120+
if '//' in line:
121+
comment_part = line[line.find('//'):]
122+
if self.has_real_chinese_content(comment_part):
123+
return "inline comment"
124+
125+
# Check string literals
126+
string_matches = re.finditer(r'"([^"]*)"', line)
127+
for match in string_matches:
128+
if self.has_real_chinese_content(match.group(1)):
129+
return "string literal"
130+
131+
# Check character literals
132+
char_matches = re.finditer(r"'([^']*)'", line)
133+
for match in char_matches:
134+
if self.has_real_chinese_content(match.group(1)):
135+
return "character literal"
136+
137+
# Check identifiers
138+
temp_line = re.sub(r'"[^"]*"', '', line) # Remove strings
139+
temp_line = re.sub(r"'[^']*'", '', temp_line) # Remove characters
140+
temp_line = re.sub(r'//.*$', '', temp_line) # Remove single line comments
141+
142+
if self.has_real_chinese_content(temp_line):
143+
return "identifier or code"
144+
145+
return "unknown location"
146+
147+
def check_directory(self) -> bool:
148+
"""Check entire directory, return whether there are issues"""
149+
if not self.target_dir.exists():
150+
print(f"::error::Directory does not exist: {self.target_dir}")
151+
return False
152+
153+
java_files = list(self.target_dir.rglob("*.java"))
154+
155+
if not java_files:
156+
print(f"::notice::No Java files found in {self.target_dir}")
157+
return True
158+
159+
print(f"::notice::Found {len(java_files)} Java files, starting check...")
160+
161+
for java_file in java_files:
162+
file_issues = self.check_file(java_file)
163+
self.issues.extend(file_issues)
164+
165+
return len(self.issues) == 0
166+
167+
def report_issues(self) -> None:
168+
"""Report discovered issues"""
169+
if not self.issues:
170+
print("::notice::✅ No Java files with Chinese content found")
171+
return
172+
173+
print(f"::error::❌ Found {len(self.issues)} Chinese content issues")
174+
175+
# Group issues by file
176+
files_with_issues = defaultdict(list)
177+
for issue in self.issues:
178+
files_with_issues[issue['file']].append(issue)
179+
180+
for file_path, file_issues in files_with_issues.items():
181+
print(f"::error file={file_path}::File contains {len(file_issues)} Chinese content issues")
182+
183+
for issue in file_issues:
184+
print(f"::error file={file_path},line={issue['line']}::{issue['message']}: {issue['content'][:100]}")
185+
186+
# Output modification suggestions
187+
print("\n::notice::Modification suggestions:")
188+
print("::notice::1. Change Chinese comments to English comments")
189+
print("::notice::2. Extract Chinese strings to resource files or configuration files")
190+
print("::notice::3. Change Chinese identifiers to English identifiers")
191+
print("::notice::4. For test data, consider using English or placeholders")
192+
193+
def main():
194+
parser = argparse.ArgumentParser(description='Check Chinese content in Java code')
195+
parser.add_argument('--dir', '-d',
196+
default='src/main/java',
197+
help='Directory path to check (relative to current directory)')
198+
parser.add_argument('--fail-on-found', '-f',
199+
action='store_true',
200+
help='Return non-zero exit code when Chinese content is found')
201+
202+
args = parser.parse_args()
203+
204+
try:
205+
checker = ChineseContentChecker(args.dir)
206+
is_clean = checker.check_directory()
207+
checker.report_issues()
208+
209+
if args.fail_on_found and not is_clean:
210+
print(f"::error::Check failed: Found {len(checker.issues)} Chinese content issues")
211+
return 1
212+
213+
return 0
214+
215+
except Exception as e:
216+
print(f"::error::Error occurred during check: {e}")
217+
return 1
218+
219+
if __name__ == "__main__":
220+
sys.exit(main())

0 commit comments

Comments
 (0)