f4a82c9的任务收尾

This commit is contained in:
2025-12-18 18:18:43 +08:00
parent f4a82c96ee
commit b1c422ad7b
16 changed files with 301 additions and 244 deletions

View File

@@ -10,6 +10,63 @@ from tomli_w import dumps as toml_dumps
from aide.core import output
def find_project_root(start_path: Path | None = None) -> Path:
"""递归向上查找包含有效 .aide 目录的项目根目录。
类似于 git 查找 .git 目录的逻辑:从当前目录开始向上遍历,
直到找到包含有效 .aide 目录的父目录。
查找策略(两遍遍历):
1. 第一遍:优先查找包含 flow-status.json 的目录(活跃任务)
2. 第二遍:如果第一遍未找到,查找包含 config.toml 的目录
这样可以确保从子目录运行时,优先找到有活跃任务的项目根目录。
Args:
start_path: 起始路径,默认为当前工作目录
Returns:
找到有效 .aide 目录的父目录路径,如果未找到则返回起始路径
"""
if start_path is None:
start_path = Path.cwd()
start_path = start_path.resolve()
def search_upward(check_fn) -> Path | None:
"""向上遍历查找满足条件的目录"""
current = start_path
while current != current.parent:
if check_fn(current):
return current
current = current.parent
# 检查根目录本身
if check_fn(current):
return current
return None
def has_flow_status(path: Path) -> bool:
"""检查是否有活跃任务状态文件"""
return (path / ".aide" / "flow-status.json").exists()
def has_config(path: Path) -> bool:
"""检查是否有配置文件"""
return (path / ".aide" / "config.toml").exists()
# 第一遍:优先查找有活跃任务的目录
result = search_upward(has_flow_status)
if result is not None:
return result
# 第二遍:查找有配置文件的目录
result = search_upward(has_config)
if result is not None:
return result
# 未找到有效 .aide 目录,返回原始起始路径
return start_path
DEFAULT_CONFIG = """################################################################################
# Aide 配置文件 (config.toml)
################################################################################

View File

@@ -118,6 +118,8 @@ class BranchManager:
- 清空任务原文件 (task.source),保留文件本身
- 备份并删除 flow-status.json
- 备份并删除 decisions/*.json
- 删除 pending-items.json
- 删除流程图目录下的所有文件 (.puml, .plantuml, .png)
"""
# 确保 logs 目录存在
self.logs_dir.mkdir(parents=True, exist_ok=True)
@@ -175,6 +177,25 @@ class BranchManager:
except OSError:
pass
# 6. 删除 pending-items.json
pending_items_path = self.aide_dir / "pending-items.json"
if pending_items_path.exists():
try:
pending_items_path.unlink()
except OSError:
pass
# 7. 删除流程图目录下的所有文件
diagram_path = self.cfg.get_value("flow.diagram_path") or ".aide/diagrams"
diagram_dir = self.root / diagram_path
if diagram_dir.exists() and diagram_dir.is_dir():
for diagram_file in diagram_dir.iterdir():
if diagram_file.is_file() and diagram_file.suffix in (".puml", ".plantuml", ".png"):
try:
diagram_file.unlink()
except OSError:
pass
def load_branches(self) -> BranchesData:
"""加载分支概况"""
if self._data is not None:

View File

@@ -8,7 +8,7 @@ from pathlib import Path
from typing import Any
from aide.core import output
from aide.core.config import ConfigManager
from aide.core.config import ConfigManager, find_project_root
from aide.env.manager import EnvManager
from aide.flow.tracker import FlowTracker
@@ -162,7 +162,7 @@ def build_parser() -> argparse.ArgumentParser:
def handle_init(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
cfg.ensure_config()
cfg.ensure_gitignore()
@@ -174,7 +174,7 @@ def handle_env_default(args: argparse.Namespace) -> bool:
"""aide env无子命令等同于 aide env ensure。"""
if args.env_command is None:
# 无子命令,执行默认的 ensure
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
manager = EnvManager(root, cfg)
return manager.ensure()
@@ -183,7 +183,7 @@ def handle_env_default(args: argparse.Namespace) -> bool:
def handle_env_ensure(args: argparse.Namespace) -> bool:
"""aide env ensure 处理。"""
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
manager = EnvManager(root, cfg)
@@ -202,7 +202,7 @@ def handle_env_ensure(args: argparse.Namespace) -> bool:
def handle_env_list(args: argparse.Namespace) -> bool:
"""aide env list 处理。"""
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
manager = EnvManager(root, cfg)
manager.list_modules()
@@ -211,7 +211,7 @@ def handle_env_list(args: argparse.Namespace) -> bool:
def handle_env_set(args: argparse.Namespace) -> bool:
"""aide env set 处理。"""
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
manager = EnvManager(root, cfg)
@@ -238,7 +238,7 @@ def handle_env_set(args: argparse.Namespace) -> bool:
def handle_config_get(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
value = cfg.get_value(args.key)
if value is None:
@@ -249,7 +249,7 @@ def handle_config_get(args: argparse.Namespace) -> bool:
def handle_config_set(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
parsed_value = _parse_value(args.value)
cfg.set_value(args.key, parsed_value)
@@ -262,49 +262,49 @@ def handle_flow_help(args: argparse.Namespace) -> bool:
def handle_flow_start(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.start(args.phase, args.summary)
def handle_flow_next_step(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.next_step(args.summary)
def handle_flow_back_step(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.back_step(args.reason)
def handle_flow_next_part(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.next_part(args.phase, args.summary)
def handle_flow_back_part(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.back_part(args.phase, args.reason)
def handle_flow_issue(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.issue(args.description)
def handle_flow_error(args: argparse.Namespace) -> bool:
root = Path.cwd()
root = find_project_root()
cfg = ConfigManager(root)
tracker = FlowTracker(root, cfg)
return tracker.error(args.description)
@@ -314,7 +314,7 @@ def handle_flow_status(args: argparse.Namespace) -> bool:
"""aide flow status - 查看当前任务状态。"""
from aide.flow.storage import FlowStorage
root = Path.cwd()
root = find_project_root()
storage = FlowStorage(root)
try:
@@ -346,7 +346,7 @@ def handle_flow_list(args: argparse.Namespace) -> bool:
"""aide flow list - 列出所有任务。"""
from aide.flow.storage import FlowStorage
root = Path.cwd()
root = find_project_root()
storage = FlowStorage(root)
try:
@@ -374,7 +374,7 @@ def handle_flow_show(args: argparse.Namespace) -> bool:
"""aide flow show <task_id> - 查看指定任务的详细状态。"""
from aide.flow.storage import FlowStorage
root = Path.cwd()
root = find_project_root()
storage = FlowStorage(root)
try: