From 2001eddbff59c2ee0b63a94254be6eedec6ff673 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 21 Mar 2026 12:49:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(scripts):=20=E9=87=8D=E6=9E=84AI?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=94=9F=E6=88=90=E8=84=9A=E6=9C=AC=E4=BB=A5?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E5=85=B7=E9=80=89=E6=8B=A9=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除shell脚本中的冗余命令执行逻辑 - 添加select_tool函数统一处理工具偏好和回退逻辑 - 使用新函数重构搜索、JSON处理、脚本编写等工具选择 - 更新时间戳以反映代码变更后的重新生成 - 简化构建工具配置的回退策略 --- .ai/environment/tools.ai.yaml | 2 +- .ai/environment/tools.raw.yaml | 2 +- scripts/collect-dev-environment.sh | 10 ----- scripts/generate-ai-environment.py | 72 +++++++++++++++++------------- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.ai/environment/tools.ai.yaml b/.ai/environment/tools.ai.yaml index 66be9aa..968e9c1 100644 --- a/.ai/environment/tools.ai.yaml +++ b/.ai/environment/tools.ai.yaml @@ -1,5 +1,5 @@ schema_version: 1 -generated_at_utc: "2026-03-21T04:01:27Z" +generated_at_utc: "2026-03-21T04:47:58Z" generated_from: ".ai/environment/tools.raw.yaml" generator: "scripts/generate-ai-environment.py" platform: diff --git a/.ai/environment/tools.raw.yaml b/.ai/environment/tools.raw.yaml index 6f1c959..523817d 100644 --- a/.ai/environment/tools.raw.yaml +++ b/.ai/environment/tools.raw.yaml @@ -1,5 +1,5 @@ schema_version: 1 -generated_at_utc: "2026-03-21T04:00:19Z" +generated_at_utc: "2026-03-21T04:47:28Z" generator: "scripts/collect-dev-environment.sh" platform: diff --git a/scripts/collect-dev-environment.sh b/scripts/collect-dev-environment.sh index af79bb0..8a76f2b 100644 --- a/scripts/collect-dev-environment.sh +++ b/scripts/collect-dev-environment.sh @@ -266,13 +266,3 @@ if [[ "${MODE}" == "--write" ]]; then else collect_inventory fi - -ensure_supported_mode - -if [[ "${MODE}" == "--write" ]]; then - mkdir -p "$(dirname "${OUTPUT_PATH}")" - collect_inventory > "${OUTPUT_PATH}" - printf 'Wrote %s\n' "${OUTPUT_PATH}" -else - collect_inventory -fi diff --git a/scripts/generate-ai-environment.py b/scripts/generate-ai-environment.py index 4bccbc5..0ecbdb4 100644 --- a/scripts/generate-ai-environment.py +++ b/scripts/generate-ai-environment.py @@ -76,6 +76,18 @@ def available_tool(raw: dict[str, Any], section: str, name: str) -> bool: return bool_value(raw, section, name, "installed") +def select_tool( + use_for: str, + preferred: str | None, + fallback: str | None, +) -> dict[str, str]: + return { + "preferred": choose(preferred, fallback), + "fallback": fallback or "unavailable", + "use_for": use_for, + } + + def build_ai_inventory(raw: dict[str, Any]) -> dict[str, Any]: has_python = available_tool(raw, "required_runtimes", "python3") has_node = available_tool(raw, "required_runtimes", "node") @@ -86,36 +98,36 @@ def build_ai_inventory(raw: dict[str, Any]) -> dict[str, Any]: has_bash = available_tool(raw, "required_tools", "bash") has_docker = available_tool(raw, "project_tools", "docker") - search = { - "preferred": choose("rg" if has_rg else None, "grep"), - "fallback": "grep" if has_rg else "unavailable", - "use_for": "Repository text search.", - } - json = { - "preferred": choose("jq" if has_jq else None, "python3" if has_python else None), - "fallback": "python3" if has_jq and has_python else "unavailable", - "use_for": "Inspecting or transforming JSON command output.", - } - scripting = { - "preferred": choose("python3" if has_python else None, "bash" if has_bash else None), - "fallback": "bash" if has_python and has_bash else "unavailable", - "use_for": "Non-trivial local automation and helper scripts.", - } - shell = { - "preferred": choose("bash" if has_bash else None, "sh"), - "fallback": "sh" if has_bash else "unavailable", - "use_for": "Repository shell scripts and command execution.", - } - docs = { - "preferred": choose("bun" if has_bun else None, "npm" if has_node else None), - "fallback": "npm" if has_bun and has_node else "unavailable", - "use_for": "Installing and previewing the docs site.", - } - build = { - "preferred": choose("dotnet" if has_dotnet else None, None), - "fallback": "unavailable", - "use_for": "Build, test, restore, and solution validation.", - } + search = select_tool( + use_for="Repository text search.", + preferred="rg" if has_rg else None, + fallback="grep", + ) + json = select_tool( + use_for="Inspecting or transforming JSON command output.", + preferred="jq" if has_jq else None, + fallback="python3" if has_python else None, + ) + scripting = select_tool( + use_for="Non-trivial local automation and helper scripts.", + preferred="python3" if has_python else None, + fallback="bash" if has_bash else None, + ) + shell = select_tool( + use_for="Repository shell scripts and command execution.", + preferred="bash" if has_bash else None, + fallback="sh", + ) + docs = select_tool( + use_for="Installing and previewing the docs site.", + preferred="bun" if has_bun else None, + fallback="npm" if has_node else None, + ) + build = select_tool( + use_for="Build, test, restore, and solution validation.", + preferred="dotnet" if has_dotnet else None, + fallback=None, + ) if bool_value(raw, "platform", "wsl"): platform_family = "wsl-linux"