Skip to content

Commit e0fa820

Browse files
SummerOneTwoclaude
andcommitted
refactor: 全面优化项目架构与代码质量
### Features - 升级 Python 版本要求至 3.14 - 添加完整的开发工具配置 (ruff, mypy, pytest-cov) - 新增 Makefile 提供常用开发命令 - 新增 GitHub Actions CI/CD 工作流 - 新增 MIT LICENSE、CONTRIBUTING.md、CHANGELOG.md - 新增 .gitignore 忽略规则 ### Code Quality - 修复所有 ruff lint 错误 (48个) - 清理未使用的导入和变量 - 统一代码风格和格式化 ### Tests - 新增 stress_test 工具测试 (3个) - 新增 resources 模块测试 (6个) - 新增 prompts 模块测试 (7个) - 测试总数从 35 增加到 51 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4cddbff commit e0fa820

33 files changed

Lines changed: 897 additions & 272 deletions
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
env:
14+
LANG: "en_US.utf-8"
15+
LC_ALL: "en_US.utf-8"
16+
PYTHONIOENCODING: "UTF-8"
17+
18+
jobs:
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.14"
29+
30+
- name: Setup uv
31+
uses: astral-sh/setup-uv@v4
32+
33+
- name: Install dependencies
34+
run: uv sync --all-extras
35+
36+
- name: Run ruff lint
37+
run: uv run ruff check src/ tests/
38+
39+
- name: Run ruff format check
40+
run: uv run ruff format --check src/ tests/
41+
42+
typecheck:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: "3.14"
52+
53+
- name: Setup uv
54+
uses: astral-sh/setup-uv@v4
55+
56+
- name: Install dependencies
57+
run: uv sync --all-extras
58+
59+
- name: Run mypy
60+
run: uv run mypy src/
61+
62+
test:
63+
strategy:
64+
matrix:
65+
python-version: ["3.11", "3.12", "3.13", "3.14"]
66+
os: [ubuntu-latest, windows-latest, macos-latest]
67+
fail-fast: false
68+
69+
runs-on: ${{ matrix.os }}
70+
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v4
74+
75+
- name: Setup Python
76+
uses: actions/setup-python@v5
77+
with:
78+
python-version: ${{ matrix.python-version }}
79+
allow-prereleases: true
80+
81+
- name: Setup uv
82+
uses: astral-sh/setup-uv@v4
83+
with:
84+
enable-cache: true
85+
86+
- name: Install dependencies
87+
run: uv sync --all-extras
88+
89+
- name: Run tests
90+
run: uv run pytest tests/ -v --tb=short
91+
92+
- name: Run tests with coverage
93+
if: matrix.python-version == '3.14' && matrix.os == 'ubuntu-latest'
94+
run: uv run pytest tests/ --cov=src/autocode_mcp --cov-report=xml --cov-report=term
95+
96+
- name: Upload coverage
97+
if: matrix.python-version == '3.14' && matrix.os == 'ubuntu-latest'
98+
uses: codecov/codecov-action@v4
99+
with:
100+
files: ./coverage.xml
101+
fail_ci_if_error: false
102+
103+
# 所有检查通过后的综合状态
104+
ci:
105+
needs: [lint, typecheck, test]
106+
runs-on: ubuntu-latest
107+
steps:
108+
- name: CI passed
109+
run: echo "All CI checks passed!"

autocode_mcp/.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
.venv/
25+
venv/
26+
ENV/
27+
env/
28+
29+
# Testing
30+
.pytest_cache/
31+
.coverage
32+
htmlcov/
33+
coverage.xml
34+
*.cover
35+
36+
# Type checking
37+
.mypy_cache/
38+
.dmypy.json
39+
dmypy.json
40+
41+
# Linting
42+
.ruff_cache/
43+
44+
# IDE
45+
.idea/
46+
.vscode/
47+
*.swp
48+
*.swo
49+
*~
50+
51+
# Project specific
52+
*.exe
53+
*.out
54+
*.o
55+
.tmp/
56+
57+
# OS
58+
.DS_Store
59+
Thumbs.db

autocode_mcp/CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2025-03-30
9+
10+
### Features
11+
12+
- 初始化 AutoCode MCP Server 基础架构
13+
- 实现 14 个原子工具:
14+
- File 工具组:`file_read`, `file_save`
15+
- Solution 工具组:`solution_build`, `solution_run`
16+
- Stress Test 工具组:`stress_test_run`
17+
- Problem 工具组:`problem_create`, `problem_generate_tests`, `problem_pack_polygon`
18+
- Validator 工具组:`validator_build`, `validator_select`
19+
- Generator 工具组:`generator_build`, `generator_run`
20+
- Checker 工具组:`checker_build`
21+
- Interactor 工具组:`interactor_build`
22+
- 添加 testlib.h 和 C++ 代码模板
23+
- 实现 MCP Resources 和 Prompts
24+
- 添加 51 个测试用例
25+
26+
### Design Rationale
27+
28+
- **纯工具模式**:Server 不调用任何 LLM,由 Client 提供智能编排
29+
- **无状态设计**:每次调用独立,状态由 `problem_dir` 参数管理
30+
- **统一返回格式**`{success, error, data}`
31+
32+
### Notes & Caveats
33+
34+
- Interactor 工具的交互测试逻辑尚未完全实现(有 TODO 标记)
35+
- Windows 平台不支持内存限制(ulimit)
36+
- 需要 g++ 编译器支持 C++2C 标准

autocode_mcp/CONTRIBUTING.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Contributing to AutoCode MCP
2+
3+
感谢您有兴趣为 AutoCode MCP 做出贡献!
4+
5+
## 开发环境设置
6+
7+
```bash
8+
# 克隆仓库
9+
git clone https://github.com/yourusername/autocode-mcp.git
10+
cd autocode-mcp
11+
12+
# 安装依赖
13+
uv sync --all-extras
14+
```
15+
16+
## 开发工作流
17+
18+
### 运行测试
19+
20+
```bash
21+
# 运行所有测试
22+
make test
23+
24+
# 运行测试并生成覆盖率报告
25+
make test-cov
26+
```
27+
28+
### 代码质量
29+
30+
```bash
31+
# 运行 lint 检查
32+
make lint
33+
34+
# 格式化代码
35+
make format
36+
37+
# 运行类型检查
38+
make typecheck
39+
40+
# 运行所有检查
41+
make check
42+
```
43+
44+
## 项目结构
45+
46+
```
47+
autocode_mcp/
48+
├── src/autocode_mcp/ # 源代码
49+
│ ├── tools/ # 工具实现
50+
│ ├── utils/ # 工具函数
51+
│ ├── resources/ # MCP Resources
52+
│ ├── prompts/ # MCP Prompts
53+
│ └── server.py # MCP Server 入口
54+
├── tests/ # 测试文件
55+
├── templates/ # C++ 模板文件
56+
├── pyproject.toml # 项目配置
57+
└── Makefile # 开发命令
58+
```
59+
60+
## 代码风格
61+
62+
- 使用 ruff 进行 lint 和格式化
63+
- 使用 mypy 进行类型检查
64+
- 遵循 PEP 8 规范
65+
- 使用 f-string 格式化字符串
66+
- 添加类型注解到公共 API
67+
68+
## 提交规范
69+
70+
使用 Conventional Commits:
71+
72+
- `feat:` 新功能
73+
- `fix:` Bug 修复
74+
- `docs:` 文档更新
75+
- `test:` 测试相关
76+
- `refactor:` 重构
77+
- `chore:` 其他更改
78+
79+
## Pull Request 流程
80+
81+
1. Fork 仓库
82+
2. 创建功能分支
83+
3. 进行更改
84+
4. 运行测试和 lint
85+
5. 提交 Pull Request
86+
87+
## 问题反馈
88+
89+
请使用 GitHub Issues 报告问题或提出功能建议。

autocode_mcp/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 AutoCode MCP Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

autocode_mcp/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.PHONY: $(MAKECMDGOALS)
2+
3+
# 默认目标
4+
help:
5+
@echo "Available targets:"
6+
@echo " setup - 安装依赖"
7+
@echo " test - 运行测试"
8+
@echo " test-cov - 运行测试并生成覆盖率报告"
9+
@echo " lint - 运行 ruff lint 检查"
10+
@echo " format - 格式化代码"
11+
@echo " typecheck - 运行 mypy 类型检查"
12+
@echo " check - 运行所有检查 (lint + typecheck + test)"
13+
@echo " clean - 清理缓存和临时文件"
14+
@echo " docs - 启动文档服务器"
15+
16+
# 安装依赖
17+
setup:
18+
uv sync --all-extras
19+
20+
# 运行测试
21+
test:
22+
uv run pytest tests/ -v
23+
24+
# 运行测试并生成覆盖率报告
25+
test-cov:
26+
uv run pytest tests/ --cov=src/autocode_mcp --cov-report=html --cov-report=term
27+
28+
# 运行 ruff lint 检查
29+
lint:
30+
uv run ruff check src/ tests/
31+
32+
# 格式化代码
33+
format:
34+
uv run ruff format src/ tests/
35+
36+
# 运行 mypy 类型检查
37+
typecheck:
38+
uv run mypy src/
39+
40+
# 运行所有检查
41+
check: lint typecheck test
42+
43+
# 清理缓存和临时文件
44+
clean:
45+
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
46+
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
47+
find . -type d -name ".mypy_cache" -exec rm -rf {} + 2>/dev/null || true
48+
find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
49+
rm -rf htmlcov/ .coverage 2>/dev/null || true
50+
51+
# 启动文档服务器 (如果有 mkdocs)
52+
docs:
53+
uv run mkdocs serve

0 commit comments

Comments
 (0)