diff --git a/.aide/branches.json b/.aide/branches.json index 993c884..890bcbd 100644 --- a/.aide/branches.json +++ b/.aide/branches.json @@ -1,5 +1,5 @@ { - "next_number": 13, + "next_number": 14, "branches": [ { "number": 1, @@ -138,6 +138,18 @@ "task_summary": "开始任务准备: 修复 aide finish 后 .lock 文件残留问题", "started_at": "2025-12-18T10:09:00+08:00", "status": "active" + }, + { + "number": 13, + "branch_name": "aide/013", + "source_branch": "aide/012", + "start_commit": "f4b96202d0d4407407e9291f74dd74af3b1067a9", + "task_id": "2025-12-18T10-41-43", + "task_summary": "开始任务准备: 改进 aide flow 的 git 工作流", + "started_at": "2025-12-18T10:41:43+08:00", + "status": "finished", + "end_commit": "f4b96202d0d4407407e9291f74dd74af3b1067a9", + "finished_at": "2025-12-18T11:22:54+08:00" } ] } diff --git a/.aide/branches.md b/.aide/branches.md index 8fb8b5c..bf16227 100644 --- a/.aide/branches.md +++ b/.aide/branches.md @@ -1,5 +1,15 @@ # Git 分支概况 +## aide/013 + +- **任务**: 开始任务准备: 改进 aide flow 的 git 工作流 +- **任务ID**: 2025-12-18T10-41-43 +- **源分支**: aide/012 +- **起始提交**: f4b9620 +- **结束提交**: f4b9620 +- **状态**: finished +- **时间**: 2025-12-18 10:41 ~ 11:22 + ## aide/012 - **任务**: 开始任务准备: 修复 aide finish 后 .lock 文件残留问题 diff --git a/.aide/diagrams/program-logic.png b/.aide/diagrams/program-logic.png new file mode 100644 index 0000000..9a0bf1a Binary files /dev/null and b/.aide/diagrams/program-logic.png differ diff --git a/.aide/diagrams/program-logic.puml b/.aide/diagrams/program-logic.puml new file mode 100644 index 0000000..d901eeb --- /dev/null +++ b/.aide/diagrams/program-logic.puml @@ -0,0 +1,49 @@ +@startuml program-logic +title 程序逻辑流图:finish_branch_merge 重构 + +start +:进入 finish_branch_merge(); +note right: branch.py + +:获取分支信息\nbranch_info = get_active_branch_info(); + +if (源分支有新提交?) then (是) + :创建临时分支合并\n(保持现有逻辑); + :返回提示信息; + stop +else (否) + :进入 _merge_normal(); +endif + +partition "清理操作" { + :删除 .aide/*.lock; + :删除 task-spec.md; + :清空 task-now.md\n(保留文件); + :备份并删除\nflow-status.json; + :备份并删除\ndecisions/*.json; +} + +partition "创建临时提交" { + :git add -A; + :git commit\n"清理任务临时文件"; +} + +partition "切换并合并" { + :git checkout\n源分支; + :清理 .lock 文件; + :git merge --squash\n任务分支; + :构建提交信息\n格式: {hash}的任务收尾; + :git add -A; + :git commit\n收尾提交; +} + +partition "更新记录" { + :更新分支记录\nstatus = finished; + :git add -A; + :git commit\n更新分支记录; +} + +:返回成功; +stop + +@enduml diff --git a/.aide/diagrams/task-flow.png b/.aide/diagrams/task-flow.png index 26916ee..ffbd0e3 100644 Binary files a/.aide/diagrams/task-flow.png and b/.aide/diagrams/task-flow.png differ diff --git a/.aide/diagrams/task-flow.puml b/.aide/diagrams/task-flow.puml index 1be0eb6..4b2d675 100644 --- a/.aide/diagrams/task-flow.puml +++ b/.aide/diagrams/task-flow.puml @@ -1,48 +1,45 @@ @startuml task-flow -!theme plain -skinparam backgroundColor #FFFFFF -skinparam activityBackgroundColor #F5F5F5 -skinparam activityBorderColor #333333 +title 任务执行流程图:改进 aide flow 的 git 工作流 -title 任务执行流程图 - 多模块调整 - -|#LightBlue|子计划1: 创建 skill| start -:读取 statements/optimize.md; -:分析并扩展内容; -:创建 task-parser.md; -:验证 skill 结构完整性; +:阅读任务细则; +note right: task-spec.md -|#LightGreen|子计划2: 修改 run 命令| -:阅读现有 run.md; -:设计口语化检测逻辑; -:添加 skill 触发规则; -:更新命令文档; +partition "代码修改" { + :修改 branch.py; + note right + - 重构 _merge_normal() + - 添加清理函数 + - 修改提交信息格式 + end note -|#LightYellow|子计划3: 强化流程图规范| -:定义两种流程图类型; -:编写任务执行流程图规范; -:编写程序逻辑流图规范; -:更新 run.md 流程设计部分; + :修改 tracker.py; + note right + 调整 finish 触发逻辑 + (如需要) + end note +} -|#LightCoral|子计划4: 创建示例程序| -:设计 Python 程序结构; -:创建 test-cache/demo-program/; -:实现模块化程序; -:绘制程序逻辑流图; -:验证流程图规范有效性; +partition "测试验证" { + :创建测试任务; + :执行完整 flow 流程; + :检查最终 git 历史; -|#LightCyan|子计划5: 调整 git 提交顺序| -:分析 tracker.py 当前逻辑; -:重构 _apply_action 方法; -:确保状态先保存再提交; -:测试验证; - -|#Lavender|子计划6: 更新文档| -:更新 aide-plugin-skills.md; -:更新 aide-plugin-commands.md; -:更新 aide-program-flow.md; -:检查其他相关文档; + if (只有 2 个提交?) then (是) + :检查文件清理结果; + if (清理正确?) then (是) + :验证通过; + else (否) + :修复清理逻辑; + -> 执行完整 flow 流程; + endif + else (否) + :修复合并逻辑; + -> 执行完整 flow 流程; + endif +} +:更新文档; stop + @enduml diff --git a/.aide/decisions/2025-12-17T03-16-37.json b/.aide/logs/2025-12-18T10-41-43-decisions/2025-12-17T03-16-37.json similarity index 100% rename from .aide/decisions/2025-12-17T03-16-37.json rename to .aide/logs/2025-12-18T10-41-43-decisions/2025-12-17T03-16-37.json diff --git a/.aide/decisions/2025-12-17T04-59-10.json b/.aide/logs/2025-12-18T10-41-43-decisions/2025-12-17T04-59-10.json similarity index 100% rename from .aide/decisions/2025-12-17T04-59-10.json rename to .aide/logs/2025-12-18T10-41-43-decisions/2025-12-17T04-59-10.json diff --git a/.aide/decisions/pending.json b/.aide/logs/2025-12-18T10-41-43-decisions/pending.json similarity index 100% rename from .aide/decisions/pending.json rename to .aide/logs/2025-12-18T10-41-43-decisions/pending.json diff --git a/.aide/logs/2025-12-18T10-41-43-status.json b/.aide/logs/2025-12-18T10-41-43-status.json new file mode 100644 index 0000000..ba92181 --- /dev/null +++ b/.aide/logs/2025-12-18T10-41-43-status.json @@ -0,0 +1,107 @@ +{ + "task_id": "2025-12-18T10-41-43", + "current_phase": "finish", + "current_step": 12, + "started_at": "2025-12-18T10:41:43+08:00", + "history": [ + { + "timestamp": "2025-12-18T10:41:43+08:00", + "action": "start", + "phase": "task-optimize", + "step": 1, + "summary": "开始任务准备: 改进 aide flow 的 git 工作流", + "git_commit": "68db39fd46d28a8a22d4b8a3494d74be0fdcae47" + }, + { + "timestamp": "2025-12-18T11:09:10+08:00", + "action": "next-step", + "phase": "task-optimize", + "step": 2, + "summary": "任务细则已确认", + "git_commit": "39477a4bdc09a9303d97239d1451aed22ae5739b" + }, + { + "timestamp": "2025-12-18T11:09:24+08:00", + "action": "next-part", + "phase": "flow-design", + "step": 3, + "summary": "进入流程设计环节", + "git_commit": "88ae24d4a158fa17c5fd7f3cf38cf234718ef65d" + }, + { + "timestamp": "2025-12-18T11:11:04+08:00", + "action": "next-step", + "phase": "flow-design", + "step": 4, + "summary": "流程图设计完成", + "git_commit": "100a1339821494213fd33272e83d4a063ed01295" + }, + { + "timestamp": "2025-12-18T11:11:54+08:00", + "action": "next-part", + "phase": "impl", + "step": 5, + "summary": "流程设计完成,进入实现环节", + "git_commit": "6c2304e92cd353dd111b51082241c176a194c208" + }, + { + "timestamp": "2025-12-18T11:15:53+08:00", + "action": "next-step", + "phase": "impl", + "step": 6, + "summary": "完成 branch.py 和 tracker.py 修改", + "git_commit": "5397a4f6007baca020549ef66f9945176b06513f" + }, + { + "timestamp": "2025-12-18T11:18:38+08:00", + "action": "next-step", + "phase": "impl", + "step": 7, + "summary": "修复收尾提交逻辑,确保最终只有 2 个提交", + "git_commit": "59efe233b2e7976e674b39ed37739ae8ef59c162" + }, + { + "timestamp": "2025-12-18T11:19:03+08:00", + "action": "next-part", + "phase": "verify", + "step": 8, + "summary": "实现完成,进入验证环节", + "git_commit": "fc347f6bd3a886a7558729d98acb124c0aa7c1c0" + }, + { + "timestamp": "2025-12-18T11:20:24+08:00", + "action": "next-step", + "phase": "verify", + "step": 9, + "summary": "验证完成: 所有成功标准均已满足", + "git_commit": "f9bed1d6af0dfe2514756204045b8a51e59983f7" + }, + { + "timestamp": "2025-12-18T11:20:50+08:00", + "action": "next-part", + "phase": "docs", + "step": 10, + "summary": "验证通过,进入文档环节", + "git_commit": "dee577df67aac98d65088cfa4243d9c37260812c" + }, + { + "timestamp": "2025-12-18T11:22:42+08:00", + "action": "next-step", + "phase": "docs", + "step": 11, + "summary": "文档更新完成:CHANGELOG.md 已更新", + "git_commit": "c7d44fc3d7b4fe1465cbd0ab20dade20cfe7de49" + }, + { + "timestamp": "2025-12-18T11:22:53+08:00", + "action": "next-part", + "phase": "finish", + "step": 12, + "summary": "文档更新完成,进入收尾", + "git_commit": "41ccaa0b50054a28f543737e1eb33a9559c8b180" + } + ], + "source_branch": "aide/012", + "start_commit": "f4b96202d0d4407407e9291f74dd74af3b1067a9", + "task_branch": "aide/013" +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 293e325..a8cc504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ 本文件记录 Aide 项目对使用者可见的重要变更。 +## 2025-12-18 + +### 变更 + +**aide flow finish 流程重构** +- 简化 git 历史:finish 后原分支只保留 2 个提交(起始 + 收尾) +- 收尾提交信息格式改为:`{起始哈希}的任务收尾` +- 分支记录不再保存 `end_commit`(简化数据结构) + +**finish 时自动清理任务文件** +- 删除 `.aide/*.lock` 文件 +- 删除任务细则文件(`task.spec` 配置路径) +- 清空任务原文件(`task.source` 配置路径,保留文件本身) +- 备份并删除 `flow-status.json` 到 `.aide/logs/{task_id}-status.json` +- 备份并删除 `decisions/*.json` 到 `.aide/logs/{task_id}-decisions/` + +### 修改的文件 +- `aide-program/aide/flow/branch.py` - 重构 `_merge_normal()` 方法,新增 `_cleanup_task_files()` 清理函数 +- `aide-program/aide/flow/tracker.py` - 传递 `ConfigManager` 给 `BranchManager` + ## 2025-12-17 ### 修复 diff --git a/aide-program/aide/flow/branch.py b/aide-program/aide/flow/branch.py index fec653b..04574d4 100644 --- a/aide-program/aide/flow/branch.py +++ b/aide-program/aide/flow/branch.py @@ -3,14 +3,18 @@ from __future__ import annotations import json +import shutil from dataclasses import dataclass from pathlib import Path -from typing import Any +from typing import Any, TYPE_CHECKING from aide.flow.errors import FlowError from aide.flow.git import GitIntegration from aide.flow.utils import now_iso +if TYPE_CHECKING: + from aide.core.config import ConfigManager + @dataclass class BranchInfo: @@ -86,13 +90,15 @@ class BranchesData: class BranchManager: """管理 aide flow 任务分支""" - def __init__(self, root: Path, git: GitIntegration): + def __init__(self, root: Path, git: GitIntegration, cfg: "ConfigManager"): self.root = root self.git = git + self.cfg = cfg self.aide_dir = root / ".aide" self.branches_json = self.aide_dir / "branches.json" self.branches_md = self.aide_dir / "branches.md" self.lock_path = self.aide_dir / "flow-status.lock" + self.logs_dir = self.aide_dir / "logs" self._data: BranchesData | None = None self._current_branch_info: BranchInfo | None = None @@ -104,6 +110,71 @@ class BranchManager: except OSError: pass + def _cleanup_task_files(self, task_id: str) -> None: + """清理任务相关文件 + + - 删除 .aide/*.lock + - 删除任务细则文件 (task.spec) + - 清空任务原文件 (task.source),保留文件本身 + - 备份并删除 flow-status.json + - 备份并删除 decisions/*.json + """ + # 确保 logs 目录存在 + self.logs_dir.mkdir(parents=True, exist_ok=True) + + # 1. 删除所有 .lock 文件 + for lock_file in self.aide_dir.glob("*.lock"): + try: + lock_file.unlink() + except OSError: + pass + + # 2. 删除任务细则文件 + task_spec = self.cfg.get_value("task.spec") + if task_spec: + spec_path = self.root / task_spec + if spec_path.exists(): + try: + spec_path.unlink() + except OSError: + pass + + # 3. 清空任务原文件(保留文件本身) + task_source = self.cfg.get_value("task.source") + if task_source: + source_path = self.root / task_source + if source_path.exists(): + try: + source_path.write_text("", encoding="utf-8") + except OSError: + pass + + # 4. 备份并删除 flow-status.json + status_path = self.aide_dir / "flow-status.json" + if status_path.exists(): + backup_name = f"{task_id}-status.json" + backup_path = self.logs_dir / backup_name + try: + shutil.copy2(status_path, backup_path) + status_path.unlink() + except OSError: + pass + + # 5. 备份并删除 decisions/*.json + decisions_dir = self.aide_dir / "decisions" + if decisions_dir.exists(): + decision_files = list(decisions_dir.glob("*.json")) + if decision_files: + # 创建备份目录 + backup_decisions_dir = self.logs_dir / f"{task_id}-decisions" + backup_decisions_dir.mkdir(parents=True, exist_ok=True) + for decision_file in decision_files: + try: + shutil.copy2(decision_file, backup_decisions_dir / decision_file.name) + decision_file.unlink() + except OSError: + pass + def load_branches(self) -> BranchesData: """加载分支概况""" if self._data is not None: @@ -319,33 +390,37 @@ class BranchManager: branch_info: BranchInfo, task_summary: str, ) -> tuple[bool, str]: - """正常合并流程:squash 合并任务分支到源分支""" + """正常合并流程:清理 → 临时提交 → squash 合并 → 收尾提交""" source_branch = branch_info.source_branch task_branch = branch_info.branch_name + task_id = branch_info.task_id + start_commit = branch_info.start_commit - # 切回源分支 + # 1. 执行任务文件清理(在工作分支上) + self._cleanup_task_files(task_id) + + # 2. 创建临时提交保存清理后的变更 + self.git.add_all() + self.git.commit("[aide] 清理任务临时文件") + + # 3. 切回源分支 self.git.checkout(source_branch) - # 切换分支后清理 lock 文件(确保 master 上的 lock 文件也被删除) + # 切换分支后清理 lock 文件 self._cleanup_lock_file() - # squash 合并任务分支 + # 4. squash 合并任务分支 self.git.merge_squash(task_branch) - # 创建压缩提交(结束提交) - self.git.add_all() - commit_msg = f"[aide] 任务: {task_summary}" - end_commit = self.git.commit(commit_msg) + # 5. 先更新分支记录(不再记录 end_commit) + self.record_branch_finish(status="finished") - # 记录完成(更新 branches.json/md) - self.record_branch_finish( - status="finished", - end_commit=end_commit, - ) - - # 收尾提交:清理工作区(包含 branches.json/md 的更新) + # 6. 创建收尾提交(包含 squash 内容和分支记录更新) + # 格式:{起始哈希}的任务收尾 self.git.add_all() - self.git.commit("[aide] 收尾: 更新分支记录") + short_hash = start_commit[:7] if start_commit else "unknown" + commit_msg = f"{short_hash}的任务收尾" + self.git.commit(commit_msg) return True, f"任务分支已合并到 {source_branch}" diff --git a/aide-program/aide/flow/tracker.py b/aide-program/aide/flow/tracker.py index 8f76166..ba60c40 100644 --- a/aide-program/aide/flow/tracker.py +++ b/aide-program/aide/flow/tracker.py @@ -24,7 +24,7 @@ class FlowTracker: self.cfg = cfg self.storage = FlowStorage(root) self.git = GitIntegration(root) - self.branch_mgr = BranchManager(root, self.git) + self.branch_mgr = BranchManager(root, self.git, cfg) def start(self, phase: str, summary: str) -> bool: return self._run(action="start", to_phase=phase, text=summary) diff --git a/task-now.md b/task-now.md index 309620e..e69de29 100644 --- a/task-now.md +++ b/task-now.md @@ -1,6 +0,0 @@ -我期望的是,起始时的提交是为了保证工作仓库状态干净同时保存版本,要记录,但起始它不是flow的一环,它在start之前, -而后面的finish时的提交,完成之后要记录finish时的提交哈希到flow数据中,同时把这个记录为该工作分支的结束分支, -而且flow到这里其实已经结束了,后续的过程是清理也仅仅只是单纯地清理, -我希望能在工作分支aide/NNN完成删除多余文件和收尾的清理提交, -然后在工作仓库干净的情况下把这个工作分支合并到原分支的起始提交处然后把从起始提交到结束提交中的所有提交都进行squash压缩, -最后在原分支的git历史中应该只能看到3个提交,起始、结束、收尾,且此时仓库状态干净 \ No newline at end of file