轻量版 SWE-smith-style Python code-agent 数据生成、修复轨迹采集与 SFT 导出框架。
本项目使用 3 个小型 Python 仓库,程序化生成能够破坏原有测试的 bug instance,让 MiniCode 在真实仓库副本中自行搜索、编辑和验证代码,并将成功的 message/tool-call 轨迹整理为可训练的 SFT 数据。
新会话先读本文件,再读 1075 条轨迹阶段总结。当前采集已经按用户要求停止,不要自动重新启动。
截至 2026-07-12:
| 项目 | 状态 |
|---|---|
| 正式 clean high SFT | 1075 条 |
| 本轮净新增 | 300 条(775 -> 1075) |
| Weak | 22 条 |
| 已完成连续采集批次 | 75 批 |
| 第 76 批 | 用户叫停,中断且未并入 high |
| 采集器 / supervisor | 已停止 |
| Clean 审计 | passed |
| 重复 instance / patch | 0 / 0 |
| 工具调用配对异常 | 0 |
正式训练入口:
dataspace/pool/minicode/sft/high_clean.jsonl
审计报告:
dataspace/pool/minicode/sft/high_clean_report.json
连续采集状态:
dataspace/collection_runs/target_1200_gpt56_terra/state.json
status = stopped_by_user
high_clean = 1075
last_completed_batch_index = 75
interrupted_batch_index = 76
- 从 SWE-smith / SWE-bench 公开数据中选择适合本地实验的小型 Python repo。
- 建立可复现的隔离环境和稳定测试命令。
- 用本地 AST procedural mutation 生成合成 bug,而不是直接抽取 SWE-smith-py 的补丁。
- 只保留能让原本通过测试变失败的有效实例。
- 让真实 MiniCode agent 在完整 buggy repo 内定位并修复问题。
- 保存 message、tool call、tool result、patch 和测试结果。
- 将高质量成功轨迹转换、清洗为 SFT 数据。
- 冻结、审计并可复现地维护正式轨迹池。
当前 1075 条正式轨迹已经冻结;训练与模型评测产物已从本仓库移除。
| Repo | 本地目录 | 稳定 baseline |
|---|---|---|
| boltons | repos/boltons |
约 422 passed, 1 Windows-sensitive test deselected |
| funcy | repos/funcy |
203 passed |
| bottle | repos/bottle |
270 passed, 2 deselected |
配置来源:
configs/selected_repos.json
configs/repo_envs.json
环境由 setup_repo_env.py 按需创建到 .venvs/<repo_id>,不作为仓库资产保留。
MiniCode 本身位于相邻仓库:
D:\VScode_Workspace\Repositories\MiniCode
当前连续采集使用 MiniCode .env 中配置的 OpenAI-compatible provider。不要把 API key 写入本仓库或报告。
selected repos
-> setup_repo_env.py
-> generate_bug_instances.py
-> prepare_repair_task.py
-> run_agent_task.py / run_agent_batch.py
-> initial/final harness validation
-> agent_trace.jsonl + final.patch + summary.json
-> export_sft_dataset.py
-> merge/consolidate pool
-> sanitize_sft_dataset.py
-> high_clean.jsonl
核心原则:
- MiniCode 负责真实 agent 行为和内部 trace。
- mini-smith 负责任务准备、测试、patch、归档、质量分级与 SFT 清洗。
- Agent 拿到的是 bug report、失败测试/traceback 和完整 buggy repo,不提供 ground-truth patch 或 mutation 答案。
- Focused test 只用于快速反馈,最终 high 必须通过 harness 的完整稳定测试命令。
configs/ repo 与环境配置
repos/ 3 个干净源仓库
scripts/ 生成、执行、验证、导出与清洗入口
docs/ 设计、调研、失败分析和阶段报告
dataspace/generated_instances/ 已验证的合成 bug instances
dataspace/agent_runs/ agent 原始运行、trace、patch、日志
dataspace/batch_runs/ 批次 summary、日志和单批 SFT 导出
dataspace/collection_runs/ 连续采集状态与事件
dataspace/pool/minicode/ 稳定、去重后的统一数据池
repair_runs/ 和 .venvs/ 都是按需生成、可安全重建的临时目录。
python -B scripts\setup_repo_env.py
python -B scripts\run_repo_tests.py --smoke
python -B scripts\run_repo_tests.py推荐增量生成:
python -B scripts\generate_bug_instances.py `
--append `
--skip-existing `
--max-per-repo 7 `
--workers 3权威实例索引:
dataspace/generated_instances/instances.jsonl
生成器采用 AST mutation + 原测试套件验证。候选只有在至少一个原本通过的测试失败后才会发布;失败数过多的 broad bug 默认进入 quarantine。
python -B scripts\prepare_repair_task.py `
--instance boltons__mini_smith_0006 `
--repair-root dataspace\repair_runs\manual_run_001python -B scripts\run_agent_task.py `
--instance boltons__mini_smith_0006 `
--repair-root dataspace\repair_runs\manual_run_001 `
--agent-cwd D:\VScode_Workspace\Repositories\MiniCode `
--agent-cmd '"D:\VScode_Workspace\Repositories\MiniCode\.venv\Scripts\python.exe" -B -m minicode run --repo-dir {repo_dir} --instruction {instruction} --max-rounds 15 --timeout 300 --no-mcp --trace {trace_path}' `
--output dataspace\agent_runs\manual_run_001\boltons__mini_smith_0006 `
--agent-name minicode单任务输出包括:
initial_test.log
agent_stdout.log
agent_stderr.log
agent_trace.jsonl
final.patch
final_test.log
summary.json
trajectory.jsonl
python -B scripts\run_agent_batch.py `
--run-id minicode_r15_prompt_v1_YYYYMMDD_001 `
--limit 5 `
--workers 1 `
--retries 0 `
--agent-timeout 300 `
--agent-cwd D:\VScode_Workspace\Repositories\MiniCode `
--agent-cmd '"D:\VScode_Workspace\Repositories\MiniCode\.venv\Scripts\python.exe" -B -m minicode run --repo-dir {repo_dir} --instruction {instruction} --max-rounds 15 --timeout 300 --no-mcp --trace {trace_path}'默认 batch closeout 会导出 SFT、更新统一 pool 并重新生成 high_clean.jsonl。临时 smoke 才使用 --skip-pool-update。
High 必须同时满足:
summary.status == passed
agent_exit_code == 0
final_test_exit_code == 0
agent_trace.jsonl exists
finish.status == completed
final.patch non-empty
tool_call / tool_result IDs fully paired
max_rounds_after_edit + harness passed 进入 weak,不进入 high。测试失败、空 patch、trace 缺失、工具调用不配对或 agent error 会被拒绝。
手动重建与清洗:
python -B scripts\consolidate_dataset_pool.py `
--output dataspace\pool\minicode
python -B scripts\sanitize_sft_dataset.py `
--input dataspace\pool\minicode\sft\high.jsonl `
--output dataspace\pool\minicode\sft\high_clean.jsonl `
--report dataspace\pool\minicode\sft\high_clean_report.json训练前必须确认 report 中:
status == passed
local_path_findings == []
tool_argument_findings == []
| Repo | High | 占比 |
|---|---|---|
| boltons | 556 | 51.72% |
| bottle | 266 | 24.74% |
| funcy | 253 | 23.53% |
1075 条 clean high 数据:
- 1075/1075
passed=true - 1075/1075
quality=high - 1075/1075 patch 非空
- 1075 个唯一 instance ID
- 1075 个唯一 patch
- 8477 个 tool call 与 8477 个 tool result 完整配对
- 17137 条 messages,平均 15.94 条/轨迹
- 本机绝对路径残留为 0
完整统计见 docs/trajectory_collection_summary_1075.md。
当前不需要继续采集。只有用户明确要求恢复时,才运行:
python -B scripts\wait_for_provider_and_resume.py `
--target 1200 `
--batch-size 5 `
--interval 300 `
--model-label gpt56_terra `
--collection-root dataspace\collection_runs\target_1200_gpt56_terra注意:
- 使用
workers=1,避免 provider 并发限流。 - 单实例 timeout 为 300 秒。
- 普通修复失败不自动重做;API 503、连接错误等瞬态失败可在后续批次重试。
high_clean只在整批 closeout 后原子增长。- 第 76 批是中断批次;恢复时让 collector 自己选择待处理实例,不要手工把中断产物并入 high。
- 阅读本 README。
- 阅读
docs/trajectory_collection_summary_1075.md。 - 检查
dataspace/collection_runs/target_1200_gpt56_terra/state.json。 - 检查
dataspace/pool/minicode/sft/high_clean_report.json。 - 不要删除 raw runs;统一 pool 是 curated view,raw runs 用于追溯。
- 不要自动恢复采集,除非用户明确要求。
- 重建 pool 时必须遵守
configs/dataset_policy.json,排除被叫停的第 76 批。
- 阶段 1 报告
- Repo selection
- Bug generation
- MiniCode integration
- Dataset pool
- Funcy failure analysis
- 1075 条轨迹阶段总结
- 备份
high_clean.jsonl并核对 SHA-256。 - 按 instance 和 repo 分层切分,避免同类 mutation 跨 train/test 泄漏。
- 任何后续训练或评测都使用独立仓库/输出目录,不再写回本仓库。
- 定期从
agent_runs做无附件审计重建,确认正式池仍为 1075 条。