11# CLAUDE.md
22
3- 此文件为 Claude Code (claude.ai/code) 在此代码仓库中工作时提供指导 。
3+ 此文件为 Claude Code / Cursor Agent 在本仓库工作时提供项目级指导 。
44
5- ## 项目概述
5+ ## 项目定位
66
7- AutoCode 是一个 Claude Code plugin,默认以远程仓库安装使用;仓库内部同时包含 ` autocode-mcp ` 这个 MCP server 实现。它基于论文《AutoCode: LLMs as Problem Setters for Competitive Programming》实现竞赛编程出题辅助能力,并提供 Validator-Generator-Checker 工作流约束。
7+ AutoCode 是一个 ** Claude Code plugin** ,面向竞赛编程出题工作流。仓库内部同时包含 ` autocode-mcp ` MCP server,但对外主路径是远程 plugin 安装,而不是单独本地 MCP 配置。
8+
9+ 它要解决的核心问题不是“让 AI 直接写完一道题”,而是把 AI 生成的题面、解法、validator、generator、checker/interactor、对拍、测试数据和 Polygon 打包放进可验证、可审计、会阻止跳步的流程。
10+
11+ 重点风险:
12+
13+ - AI 题面含糊、样例错误或题解不一致。
14+ - 标准解有隐藏 bug,复杂度判断过于乐观。
15+ - brute 不能作为可靠 oracle。
16+ - 测试数据覆盖不到边界、极限、TLE 和错解杀伤。
17+ - 生成最终数据后未重新验证就打包。
818
919## 开发命令
1020
@@ -26,96 +36,140 @@ claude plugin validate .
2636
2737# 运行 MCP Server(本地开发/测试)
2838uv run autocode-mcp
39+
40+ # 校验题目 manifest
41+ uv run autocode-verify examples/exact-sample
42+
43+ # 构建并检查分发包
44+ uv build
45+ uv run twine check dist/*
2946```
3047
3148## 项目结构
3249
33- ```
50+ ``` text
3451AutoCode/
35- ├── .claude-plugin/ # Claude plugin manifest
36- ├── agents/ # Claude plugin agent definitions
37- ├── hooks/ # Claude hook config
38- ├── scripts/ # Hook/runtime helper scripts
39- ├── skills/ # Claude plugin skills
40- ├── src/autocode_mcp/ # MCP server 源代码
41- │ ├── tools/ # MCP 工具实现
42- │ ├── templates/ # 内置模板资源
43- │ ├── prompts/ # 工作流提示词
44- │ └── utils/ # 工具函数
45- ├── tests/ # 测试用例
46- ├── .mcp.json # 本地 MCP 接入配置
47- ├── settings.json # Claude plugin settings
48- └── pyproject.toml # 项目配置
52+ ├── .claude-plugin/ # Claude plugin manifest
53+ ├── agents/ # Claude plugin agent definitions
54+ ├── hooks/ # Claude hook config
55+ ├── scripts/ # Hook/runtime helper scripts
56+ ├── skills/ # Claude plugin skills
57+ ├── examples/ # manifest/examples smoke samples
58+ ├── src/autocode_mcp/ # MCP server 源代码
59+ │ ├── cli/ # autocode-verify 等 CLI
60+ │ ├── tools/ # MCP 工具实现
61+ │ ├── templates/ # 内置模板资源
62+ │ ├── workflow/ # autocode.json manifest 模型
63+ │ ├── prompts/ # 工作流提示词
64+ │ └── utils/ # 编译、运行、资源限制等工具函数
65+ ├── tests/ # 测试用例
66+ ├── .mcp.json # 本地 MCP 接入配置(开发/兼容用)
67+ ├── settings.json # Claude plugin 默认 agent
68+ └── pyproject.toml # Python package / scripts
4969```
5070
5171## 工具列表
5272
53- | 工具 | 描述 |
73+ AutoCode 当前暴露 20 个 MCP 工具:
74+
75+ | 分组 | 工具 |
5476| ------| ------|
55- | file_read | 读取文件 |
56- | file_save | 保存文件 |
57- | solution_build | 构建解法 |
58- | solution_run | 执行解法 |
59- | solution_analyze | 分析解法复杂度 |
60- | solution_audit_std | 审计标准解实现质量 |
61- | solution_audit_brute | 审计暴力解实现质量 |
62- | validator_build | 构建校验器 |
63- | validator_select | 选择最佳校验器 |
64- | generator_build | 构建生成器 |
65- | generator_run | 运行生成器 |
66- | checker_build | 构建检查器 |
67- | interactor_build | 构建交互器 |
68- | stress_test_run | 压力测试 |
69- | problem_create | 初始化题目 |
70- | problem_generate_tests | 生成测试数据 |
71- | problem_cleanup_processes | 清理生成残留进程 |
72- | problem_verify_tests | 验证测试数据质量 |
73- | problem_validate | 验证题面样例 |
74- | problem_pack_polygon | 打包为 Polygon 格式 |
77+ | 文件 | ` file_read ` , ` file_save ` |
78+ | 解法 | ` solution_build ` , ` solution_run ` , ` solution_analyze ` , ` solution_audit_std ` , ` solution_audit_brute ` |
79+ | Validator | ` validator_build ` , ` validator_select ` |
80+ | Generator | ` generator_build ` , ` generator_run ` |
81+ | Checker / Interactor | ` checker_build ` , ` interactor_build ` |
82+ | Stress | ` stress_test_run ` |
83+ | Problem | ` problem_create ` , ` problem_validate ` , ` problem_generate_tests ` , ` problem_cleanup_processes ` , ` problem_verify_tests ` , ` problem_pack_polygon ` |
7584
7685## 题目目录结构
7786
7887` problem_create ` 初始化后的目录布局:
7988
80- ```
89+ ``` text
8190<problem_dir>/
82- ├── solutions/ # 解法
83- │ ├── sol.cpp # 标准解
84- │ └── brute.cpp # 暴力解
85- ├── files/ # 辅助程序
86- │ ├── gen.cpp # 生成器
87- │ ├── val.cpp # 校验器
88- │ ├── checker.cpp # 检查器(可选)
89- │ ├── interactor.cpp # 交互器(可选)
90- │ └── testlib.h # testlib 头文件
91- ├── statements/ # 题面
92- │ └── README.md
93- └── tests/ # 生成的测试数据
94- ├── 01.in
95- ├── 01.ans / 01.out(由 answer_ext 控制)
96- └── ...
91+ ├── autocode.json
92+ ├── solutions/
93+ │ ├── sol.cpp
94+ │ └── brute.cpp
95+ ├── files/
96+ │ ├── gen.cpp
97+ │ ├── val.cpp
98+ │ ├── checker.cpp
99+ │ ├── interactor.cpp
100+ │ └── testlib.h
101+ ├── statements/
102+ │ ├── README.md
103+ │ └── tutorial.md
104+ └── tests/
105+ ├── 01.in
106+ ├── 01.ans / 01.out
107+ └── .autocode_tests_manifest.json
97108```
98109
99- ## 出题工作流程
110+ ## 强制工作流
111+
112+ 该顺序由 ` hooks/hooks.json ` 和 ` scripts/workflow_guard.py ` 实际强制执行。
113+
114+ 1 . ` problem_create `
115+ 2 . ` solution_build(solution_type="sol") `
116+ 3 . ` solution_build(solution_type="brute") `
117+ 4 . 解法审计:` solution_analyze ` 、` solution_audit_std ` 、` solution_audit_brute `
118+ 5 . 非交互题:` validator_build(accuracy >= 0.9) ` ;交互题:` interactor_build `
119+ 6 . ` generator_build `
120+ 7 . ` stress_test_run(completed_rounds == total_rounds) `
121+ 8 . 需要特殊判题时:` checker_build(accuracy >= 0.9) ` (非交互)
122+ 9 . ` problem_validate(validation_passed) `
123+ 10 . ` problem_generate_tests(generated_test_count > 0) `
124+ 11 . ` problem_verify_tests(passed) `
125+ 12 . ` problem_pack_polygon `
126+
127+ 关键门禁:
128+
129+ - ` brute ` 必须在 ` sol ` 之后构建。
130+ - ` validator_build ` 没有有效 ` accuracy ` 不算通过。
131+ - 交互题不可运行 ` validator_build ` / ` checker_build ` ,应使用 ` interactor_build ` 。
132+ - 最终测试生成后会清除旧的 ` tests_verified ` ,必须重新跑 ` problem_verify_tests ` 。
133+ - ` problem_pack_polygon ` 前必须完成最终测试验证。
100134
101- 1 . 初始化题目目录 (` problem_create ` )
102- 2 . 构建标准解 (` solution_build ` , ` solution_type=sol ` )
103- 3 . 构建暴力解 (` solution_build ` , ` solution_type=brute ` )
104- 4 . 构建校验器 (` validator_build ` , accuracy >= 0.9)
105- 5 . 构建生成器 (` generator_build ` )
106- 6 . 运行压力测试 (` stress_test_run ` , completed_rounds == total_rounds)
107- 7 . 按需构建检查器 (` checker_build ` , accuracy >= 0.9)
108- 8 . 生成测试数据(` problem_generate_tests ` , generated_test_count > 0,支持 ` answer_ext ` ;最终 extreme/tle 至少占一半;候选不足时尽量满足;长任务中断可 ` resume=true ` 续跑)
109- 9 . 验证测试数据 (` problem_verify_tests ` , passed)
110- 10 . 打包 Polygon (` problem_pack_polygon ` )
135+ ## Agent 与 Skill
111136
112- 该顺序会被 [ hooks/hooks.json] ( /c:/userProgram/program/AutoCode/hooks/hooks.json ) 和 [ scripts/workflow_guard.py] ( /c:/userProgram/program/AutoCode/scripts/workflow_guard.py ) 实际强制执行。
137+ 默认 Agent:
138+
139+ - ` agents/autocode-workflow.md ` :主流程协调与门禁执行。
140+
141+ 只读审计 Agent:
142+
143+ - ` agents/autocode-idea-auditor.md ` :立项前审查题意是否可判定、可验证、可生成。
144+ - ` agents/autocode-solution-auditor.md ` :std/brute 复杂度、正确性假设和对拍策略审计。
145+ - ` agents/autocode-package-auditor.md ` :打包前检查题面、测试、错解杀伤和 manifest 一致性。
146+
147+ 核心 Skills:
148+
149+ - ` skills/autocode-workflow/SKILL.md `
150+ - ` skills/idea-feasibility/SKILL.md `
151+ - ` skills/solution-complexity-audit/SKILL.md `
152+ - ` skills/stress-strategy/SKILL.md `
153+ - ` skills/statement-audit/SKILL.md `
154+ - ` skills/testdata-quality/SKILL.md `
155+ - ` skills/problem-validate/SKILL.md `
156+
157+ ## Manifest
158+
159+ 每个题目应维护 ` autocode.json ` 作为人类和 CI 都可读的题目契约。模型位于 ` src/autocode_mcp/workflow/ ` ,模板位于 ` src/autocode_mcp/templates/autocode.json ` 。
160+
161+ 快速校验:
162+
163+ ``` bash
164+ uv run autocode-verify < problem_dir>
165+ ```
113166
114167## 关键约束
115168
116- - 包管理强制使用 ` uv ` (绝对禁用 pip/poetry/conda)
117- - 对外分发形态优先是 Claude plugin,不是单独的本地 MCP 配置
118- - 默认主路径是远程 plugin 安装;本地模式只用于开发、测试、验证
119- - ` hooks/ ` 只放 hook 配置,hook 逻辑脚本放在 ` scripts/ `
120- - 模板资源统一放在 ` src/autocode_mcp/templates/ ` ,不要再在仓库根目录维护一份重复模板
121- - C++ 标准使用 C++20(需要 GCC 10+)
169+ - 包管理强制使用 ` uv ` ;不要引入 pip/poetry/conda 流程。
170+ - 对外文档优先描述 Claude Code plugin;MCP server 是实现与开发入口。
171+ - 默认主路径是远程 plugin 安装;本地模式只用于开发、测试、验证。
172+ - ` hooks/ ` 只放 hook 配置,hook 逻辑脚本放在 ` scripts/ ` 。
173+ - 模板资源统一放在 ` src/autocode_mcp/templates/ ` 。
174+ - C++ 标准使用 C++20(需要 GCC 10+)。
175+ - 本项目会编译并执行 AI 生成代码,只能在本地可信环境使用。
0 commit comments