From 33372e5102b4e394659a2df4d80d262ca652c0ff Mon Sep 17 00:00:00 2001 From: "sayurinana(vm)" Date: Mon, 15 Dec 2025 20:07:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8Denv=20s?= =?UTF-8?q?et=E4=BC=9A=E4=B8=A2=E5=A4=B1=E9=85=8D=E7=BD=AE=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aide-plugin/.claude-plugin/plugin.json | 2 +- .../aide-plugin/commands/_deprecated_exec.md | 211 ------------------ .../aide-plugin/commands/_deprecated_init.md | 106 --------- aide-program/aide/core/config.py | 71 +++++- 4 files changed, 69 insertions(+), 321 deletions(-) delete mode 100644 aide-marketplace/aide-plugin/commands/_deprecated_exec.md delete mode 100644 aide-marketplace/aide-plugin/commands/_deprecated_init.md diff --git a/aide-marketplace/aide-plugin/.claude-plugin/plugin.json b/aide-marketplace/aide-plugin/.claude-plugin/plugin.json index 416ffc4..4fd0732 100644 --- a/aide-marketplace/aide-plugin/.claude-plugin/plugin.json +++ b/aide-marketplace/aide-plugin/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "aide-plugin", "description": "Aide 工作流体系插件,提供环境配置、项目认知、文档管理和任务执行的标准化流程", - "version": "2.0.0", + "version": "2.0.1", "author": { "name": "Aide Team" }, diff --git a/aide-marketplace/aide-plugin/commands/_deprecated_exec.md b/aide-marketplace/aide-plugin/commands/_deprecated_exec.md deleted file mode 100644 index 3aca0e4..0000000 --- a/aide-marketplace/aide-plugin/commands/_deprecated_exec.md +++ /dev/null @@ -1,211 +0,0 @@ ---- -description: 任务执行流程。基于任务细则执行任务,包含流程设计、迭代实现、验证交付、文档更新。 -argument-hint: [任务细则文档路径] ---- - -# Aide 任务执行 - -你正在执行 Aide 任务执行流程。基于任务细则完成实际的任务实施。 - -## 参数 - -- `$ARGUMENTS`:任务细则文档路径(可选) -- 未传入时使用配置中的默认路径 - ---- - -## 前置准备 - -**首先触发 `aide` skill 学习 aide 命令的使用方法。** - -这是必要步骤,确保你了解 `aide flow` 等命令的正确用法。 - ---- - -## 开始 - -### 确定任务细则 - -```bash -# 如果传入了参数 -细则文档 = $ARGUMENTS - -# 如果未传入参数,使用配置默认值 -aide config get task.spec -``` - -读取任务细则内容。如文档不存在,提示用户先执行 `/aide:prep` 或指定文档路径。 - -### 进入流程设计环节 - -```bash -aide flow next-part flow-design "进入流程设计环节" -``` - ---- - -## 环节 1:流程设计 (flow-design) - -### 理解任务细则 - -- 明确任务目标和成功标准 -- 理解执行步骤和依赖关系 -- 识别技术决策和约束 - -### 分析项目环境 - -根据需要阅读相关代码/文档。 - -### 制定执行计划 - -- 具体的实现步骤 -- 每个步骤的预期产出 -- 潜在风险和应对方案 - -> 复杂任务建议使用 sequential-thinking 进行结构化规划 - -### 创建流程图(如需要) - -在配置指定的流程图目录创建 PlantUML 源文件。 - -```bash -aide flow next-step "流程图设计完成" -``` - -> aide flow 会在此环节自动校验 PlantUML 语法 - -### 进入下一环节 - -```bash -aide flow next-part main "流程设计完成,进入实现环节" -``` - -> aide flow 会自动生成 PNG 流程图 - ---- - -## 环节 2:迭代实现 (impl) - -### 按计划执行 - -对于每个实现步骤,完成后记录: - -```bash -aide flow next-step "<完成内容简述>" -``` - -### 处理问题 - -```bash -# 一般问题(可继续) -aide flow issue "<问题描述>" - -# 严重错误(需解决) -aide flow error "<错误描述>" -``` - -严重错误处理: -1. 尝试自行解决(最多3次) -2. 成功:在 `discuss/` 创建分析文档 -3. 失败:停止并告知用户 - -### 需要回退时 - -```bash -# 回退到上一步 -aide flow back-step "<原因>" - -# 回退到之前环节 -aide flow back-part <环节名> "<原因>" -``` - -### 进入下一环节 - -```bash -aide flow next-part verify "实现完成,进入验证环节" -``` - ---- - -## 环节 3:验证交付 (verify) - -### 对照任务细则验证 - -- 每个成功标准是否满足 -- 每个交付物是否完成 -- 功能是否正常工作 - -### 执行测试 - -根据项目情况运行测试或手动验证。 - -### 记录结果 - -```bash -aide flow next-step "验证完成: <验证结论>" -``` - -验证失败时回退修复: - -```bash -aide flow back-part main "验证失败: <原因>" -``` - -### 进入下一环节 - -```bash -aide flow next-part docs "验证通过,进入文档环节" -``` - ---- - -## 环节 4:文档更新 (docs) - -> aide flow 会在进入此环节时提示更新 CHANGELOG - -### 更新相关文档 - -- `README.md`(如有用户可见变更) -- `CHANGELOG.md` -- 其他相关文档 - -### 记录完成 - -```bash -aide flow next-step "文档更新完成" -``` - -### 进入下一环节 - -```bash -aide flow next-part finish "文档更新完成,进入收尾" -``` - -> aide flow 会校验 CHANGELOG 是否已更新 - ---- - -## 环节 5:收尾 (finish) - -### 清理工作 - -- 删除临时文件和调试代码 -- 确保代码格式规范 -- 检查遗漏的 TODO - -### 最终检查 - -确认所有计划步骤已完成。 - -### 记录完成 - -```bash -aide flow next-step "任务完成" -``` - -### 向用户汇报 - -总结本次任务: -- 完成了什么 -- 主要变更点 -- 遗留问题(如有) diff --git a/aide-marketplace/aide-plugin/commands/_deprecated_init.md b/aide-marketplace/aide-plugin/commands/_deprecated_init.md deleted file mode 100644 index 219970d..0000000 --- a/aide-marketplace/aide-plugin/commands/_deprecated_init.md +++ /dev/null @@ -1,106 +0,0 @@ ---- -description: 项目认知与环境初始化。进入新项目或开始工作前使用,触发对项目的主动认知和环境检测修复。 -argument-hint: [无参数] ---- - -# Aide 初始化 - -你正在使用 Aide 工作流体系。本命令帮助你快速认知项目并确保环境就绪。 - ---- - -## 核心约束(必须遵守) - -**禁止直接读取或编辑 `.aide/` 目录下的任何文件!** - -- ❌ 禁止使用 Read 工具读取 `.aide/config.toml` -- ❌ 禁止使用 Edit/Write 工具修改 `.aide/` 下的文件 -- ✅ 必须通过 `aide config get/set` 读写配置 -- ✅ 必须通过 `aide env set` 修改环境配置 -- ✅ 配置有误时,触发 `env-config` skill 学习正确的设置方法 - -**原因**:`.aide/` 是 aide 程序的内部数据目录,直接操作可能导致格式错误或状态不一致。 - ---- - -## 执行步骤 - -### 1. Aide 运行时环境检测 - -首先确保 aide 程序本身可以正常运行: - -```bash -aide env ensure --runtime -``` - -根据输出处理: -- `✓`:aide 运行时就绪,继续 -- `✗`:按提示修复后重试,无法修复则告知用户 - -> **重要**:`--runtime` 参数表示仅检查 aide 自身运行环境,不依赖项目配置文件 - -### 2. Aide 数据目录初始化 - -```bash -aide init -``` - -此命令会: -- 创建 `.aide/` 目录(如不存在) -- 生成默认配置文件 -- 检查并更新 `.gitignore` - -### 3. 项目认知 - -快速建立对项目的整体理解: - -1. 阅读项目根目录的 `README.md`(如存在) -2. 阅读 `CLAUDE.md`(如存在) -3. 浏览项目目录结构,理解核心模块划分 -4. 识别项目类型和主要技术栈 - -向用户简要汇报项目概况(3-5句话)。 - -### 4. 项目环境检测 - -```bash -aide env ensure -``` - -根据输出处理: -- `✓`:环境就绪,**直接进入步骤 5**(不要再查看配置文件) -- `⚠`:有警告但可继续,记录警告信息并继续 -- `✗`:**触发 `env-config` skill**,学习如何使用 `aide env set` 命令修复配置,然后重试 - -**环境检测失败时的正确做法**: -1. 触发 `env-config` skill 获取配置指导 -2. 使用 `aide env set <模块>.<配置项> <值>` 修改配置 -3. 重新执行 `aide env ensure` 验证 - -**错误做法**(禁止): -- 直接编辑 `.aide/config.toml` 文件 - -### 5. 汇报就绪状态 - -环境检测通过后,直接向用户汇报(不要再读取配置文件): - -``` -项目概况:[来自步骤3的概要] - -环境状态:[aide env ensure 的输出结果] - -Aide 已就绪,可用命令: -- /aide:prep [文档路径] - 任务准备 -- /aide:exec [文档路径] - 任务执行 -``` - -> 注:任务文档路径等配置信息已在 aide env ensure 输出中显示,无需额外查看配置文件。 - ---- - -## 注意事项 - -1. **不要读取 `.aide/` 目录下的文件**——所有配置操作通过 aide 命令完成 -2. 如果在初始化过程中发现严重环境问题无法解决,建议用户修复后重开对话 -3. 本命令只做认知和环境准备,不修改任何业务代码 -4. 所有输出使用简体中文 diff --git a/aide-program/aide/core/config.py b/aide-program/aide/core/config.py index 0d9714a..eaadd80 100644 --- a/aide-program/aide/core/config.py +++ b/aide-program/aide/core/config.py @@ -295,12 +295,77 @@ class ConfigManager: return self._walk_get(data, key) def set_value(self, key: str, value: Any) -> None: - data = self.ensure_config() - self._walk_set(data, key, value) - self._write_config(data) + self.ensure_config() + self._update_config_value(key, value) output.ok(f"已更新 {key} = {value!r}") + def _update_config_value(self, key: str, value: Any) -> None: + """保守更新配置值,保留注释和格式。""" + import re + + content = self.config_path.read_text(encoding="utf-8") + parts = key.split(".") + + # 格式化值为 TOML 格式 + if isinstance(value, bool): + toml_value = "true" if value else "false" + elif isinstance(value, str): + toml_value = f'"{value}"' + elif isinstance(value, (int, float)): + toml_value = str(value) + elif isinstance(value, list): + toml_value = toml_dumps({"_": value}).split("=", 1)[1].strip() + else: + toml_value = toml_dumps({"_": value}).split("=", 1)[1].strip() + + new_content = None + count = 0 + + if len(parts) == 1: + # 顶层键:key = value + pattern = rf'^({re.escape(parts[0])}\s*=\s*)(.*)$' + new_content, count = re.subn(pattern, rf'\g<1>{toml_value}', content, count=1, flags=re.MULTILINE) + elif len(parts) >= 2: + # 两级或三级键:找到对应 section,然后替换其中的 key + if len(parts) == 2: + section = parts[0] + subkey = parts[1] + else: + section = ".".join(parts[:-1]) + subkey = parts[-1] + + # 找到 section 的起始位置 + section_pattern = rf'^\[{re.escape(section)}\]\s*$' + section_match = re.search(section_pattern, content, flags=re.MULTILINE) + + if section_match: + section_start = section_match.end() + # 找到下一个 section 的位置(或文件末尾) + next_section = re.search(r'^\[', content[section_start:], flags=re.MULTILINE) + if next_section: + section_end = section_start + next_section.start() + else: + section_end = len(content) + + # 在 section 范围内查找并替换 key + section_content = content[section_start:section_end] + key_pattern = rf'^({re.escape(subkey)}\s*=\s*)(.*)$' + new_section, count = re.subn(key_pattern, rf'\g<1>{toml_value}', section_content, count=1, flags=re.MULTILINE) + + if count > 0: + new_content = content[:section_start] + new_section + content[section_end:] + + if count == 0 or new_content is None: + # 键不存在,需要添加(回退到传统方式,会丢失注释) + data = self.load_config() + self._walk_set(data, key, value) + self._write_config(data) + output.warn("配置键不存在,已添加(注释可能丢失)") + else: + self.config_path.write_text(new_content, encoding="utf-8") + def _write_config(self, data: dict[str, Any]) -> None: + """完全重写配置文件(会丢失注释,仅在添加新键时使用)。""" self.config_path.write_text(toml_dumps(data), encoding="utf-8") @staticmethod