已合并
feat(cuda2ascend): support TraeCode as target tool #918
feat(cuda2ascend): support TraeCode as target tool #918
已合并
xutianze创建于 26 天前
xutianze
xutianze成员
26 天前

描述

【cuda2ascend 工作流】新增 TraeCode(Trae)作为目标工具支持,使工作流可初始化到 TraeCode 环境并复用全部技能、Subagent 角色与静默模式能力。

改动内容

  • init.shSUPPORTED_TOOLS 增加 trae--list-tools 同步);project 级配置根 <install>/.trae/、global 级 ~/.trae-cn/;Step 3 从 agents/*.md 生成 .trae/agents/*.md(TraeCode Subagent,frontmatter 按角色注入 tools 静态限权白名单,Trae 原生机制);Step 4+ 在 .trae/hooks.json 幂等注册 PreToolUse hook(matcher AskUserQuestion,静默问卷拦截);health check、CLI_NAME、help 文本同步。
  • 新增 hooks/trae/permission-guard.js:Trae 侧静默问卷拦截 hook——mode=silent 时阻断 AskUserQuestion 问卷发送(exit 2 回传原因),与 opencode/claude/dsh 三侧 SILENT_GUARDED_TOOLS / readSilentMode 语义一致。
  • 角色权限方案:Trae 的 PreToolUse stdin 无 agent 角色字段(与 opencode/claude 不同),角色写权限由 Subagent tools 字段静态限权承担,目录级写权限(.cannbot 等)由 prompt 约束(同 codex 降级,文档中已显式标注)。
  • example/init.shCLI_NAME 增加 trae 映射;子仓 init 零改动(C1-C4 兼容)。
  • 维护文档同步architecture-and-links.md(运行时目录树 / init 表 Step 3/4/4+ / 动态权限 hook 段)、review-checklist.md(L3/L8/M6 补 trae)、modify-skill.md(工具支持列表)、workflow-agent-permissionssettings.mdtask-prompts.mdworkflow-cp0/1/2-2agents/qa.mdplugin-experience-summary 等运行时文档补 trae 问卷工具枚举与权限机制说明。

关联的Issue

测试

  • init.sh --list-toolsopencode claude codex dsh trae
  • project 级安装:.trae/agents/ 生成 6 个 Subagent(frontmatter 含 tools 白名单)、43 个 skills 链接、.trae/hooks.json 注册成功
  • global 级安装:~/.trae-cn/ 配置根正确,hook 使用绝对路径
  • 静默问卷拦截行为:silent 模式拦截 AskUserQuestion(exit 2)、放行非问卷工具;interactive 模式放行问卷——符合预期
  • bash -n(init.sh / example/init.sh)与 node --check(permission-guard.js)语法检查通过

文档更新

  • plugins-community/cuda2ascend/README.md:工具支持与静默模式说明补 trae
  • plugins-community/cuda2ascend/AGENTS.md:权限预检补 trae 分支
  • 维护 skill 文档与运行时文档(见上)同步更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 xutianze 的贡献)
xutianzexutianze成员
26 天前 创建了 pull request,commit 5233b831
atomgit-bot
atomgit-bot
26 天前 评论:

变更摘要

本 PR 为 cuda2ascend 工作流新增 TraeCode(Trae)作为目标工具支持,使工作流可初始化到 TraeCode 环境并复用既有技能、Subagent 角色与静默模式能力。核心改动集中在 init.shSUPPORTED_TOOLS 增加 trae--list-tools 同步输出),project 级配置根为 <install>/.trae/、global 级为 ~/.trae-cn/;Step 3 从 agents/*.md 生成 .trae/agents/*.md(TraeCode Subagent,frontmatter 按角色注入 tools 静态限权白名单),Step 4+ 在 .trae/hooks.json 幂等注册 PreToolUse hook(matcher AskUserQuestion,静默问卷拦截),并同步 health check、CLI_NAME 与帮助文本。同时新增 hooks/trae/permission-guard.js hook 实现 Trae 侧静默问卷拦截,与 opencode/claude/dsh 三侧的 SILENT_GUARDED_TOOLS / readSilentMode 语义保持一致。

主要改动

  • 目标工具枚举扩展: init.shSUPPORTED_TOOLS 由四项扩为 ("opencode" "claude" "codex" "dsh" "trae")--list-tools、参数解析分支、CLI_NAME 映射及 help 文本同步补齐 trae,使工作流可初始化到 TraeCode 环境。

  • 配置根与 Subagent 生成: project 级配置根设为 ${INSTALL_BASE}/.trae、global 级设为 ${HOME}/.trae-cn;Step 3 新增 trae 分支,用内嵌 Python 脚本解析 agents/*.md 的 frontmatter(name/description),按角色(如 architectdeveloperqa 等)注入 tools 静态限权白名单后生成 .trae/agents/{name}.md,其中仅 qa 角色含 AskUserQuestion

  • 新增 hooks/trae/permission-guard.js: Trae 侧 PreToolUse 静默问卷拦截 hook——SILENT_GUARDED_TOOLS 按子串匹配 question/ask 类工具名,经 readSilentMode 读取 .cannbot/settings.jsonmode=silent 时阻断问卷并以 exit 2 回传原因,非问卷工具放行。

  • .trae/hooks.json 幂等注册 hook: Step 4+ 新增 trae 分支,将 permission-guard.js 软链至 ${CONFIG_ROOT}/hooks/,并用内嵌 Python 幂等写入 hooks.json(matcher 为 AskUserQuestion);project 级用 ${CLAUDE_PROJECT_DIR} 占位符引用、global 级用绝对路径,已注册则跳过或补充 matcher。

  • health check 与示例脚本同步: init.sh health check 新增 trae 检查(校验 permission-guard.js 软链存在及 hooks.json 是否注册 hook);example/init.sh 补充 [ "$TARGET_ENV" = "trae" ] && CLI_NAME="trae" 映射,子仓 init 保持零改动兼容。

likedislike
不准确?
atomgit-bot
atomgit-bot
26 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
26 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/cannbot-skills benwallace52, 汤平川 (2/2) benwallace52, 汤平川 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

xutianze, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robot成员
26 天前 评论:

CLA Signature Pass

xutianze, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
xutianze
xutianze成员26 天前进行代码检视2
plugins-community/cuda2ascend/README.md
已过期
@@ -125,3 +125,4 @@
125125- **静默模式(`silent`,完全无人值守)**:不输出中间进度、不发问卷(确认点由 QA 按默认决策执行,架构选型固定采用 SIMD),失败自动回退至最大轮次;仅输出启动时的权限预检警告(opencode 检查 opencode.json 未全量授权、dsh 检查运行上下文声明的文件/审批策略未全量授权时提示一次)与任务完成总结(含阻断中止性总结)。启动静默工作流前 PM 执行权限预检,未全量授权时提示「运行期间权限确认可能打断自动流程」。
126126- **会话内切换**:直接对 PM 说「开启静默模式 / 关闭静默模式」,即修改配置并落盘,无需重跑 init。
127127- **DSH 部署级权限守卫(可选)**:dsh 无项目级 hook(角色写隔离默认靠 prompt 约束);运行 `hooks/dsh/install.sh` 可安装部署级 Cordis 守卫插件(挂 `$DSH_HOME/cordis.patch.yml`,对所有 profile 生效),恢复按角色的写权限隔离与静默问卷拦截的机制保证(仅作用于 cuda2ascend 初始化的工作区)。
128+- **TraeCode 支持**`init.sh trae` 安装到 `.trae/`(skills 自动发现;Subagent 由 `agents/*.md` 生成并注入 `tools` 静态限权;`.trae/hooks.json` 注册 PreToolUse hook 做静默问卷拦截)。
xutianze
xutianze26 天前评论:

这一句有点多余

likedislike
System
系统消息系统
26 天前 评论:

changed this line on 61d30e6d view diff detail

xutianze
xutianze成员26 天前进行代码检视2
plugins-community/cuda2ascend/example/init.sh
已过期
@@ -20,3 +20,3 @@
2020# Quick Start content (shown after a successful install).
2121# Customize this block for your repo. $CLI_NAME is resolved at
22-# runtime from the target tool (opencode/claude/codex/dsh).
22+# runtime from the target tool (opencode/claude/codex/dsh/trae).
xutianze
xutianze26 天前评论:

这里不要把支持的框架列表都列出来,这样不方便扩展

likedislike
System
系统消息系统
26 天前 评论:

changed this line on 61d30e6d view diff detail

xutianze
xutianze成员26 天前进行代码检视2
plugins-community/cuda2ascend/example/init.sh
已过期
@@ -19,7 +19,7 @@ set -e
1919# ============================================================
2020# Quick Start content (shown after a successful install).
2121# Customize this block for your repo. $CLI_NAME is resolved at
22-# runtime from the target tool (opencode/claude/codex/dsh).
22+# runtime from the target tool (opencode/claude/codex/dsh/trae).
2323# ============================================================
2424show_quick_start() {
2525 echo ""
@@ -266,5 +266,6 @@ CLI_NAME="opencode"
266266[ "$TARGET_ENV" = "claude" ] && CLI_NAME="claude"
267267[ "$TARGET_ENV" = "codex" ] && CLI_NAME="codex"
268268[ "$TARGET_ENV" = "dsh" ] && CLI_NAME="dsh"
269+[ "$TARGET_ENV" = "trae" ] && CLI_NAME="trae"
xutianze
xutianze26 天前评论:

这里有必要用个映射吗,直接CLI_NAME=$TARGET_ENV是不是就行了

likedislike
System
系统消息系统
26 天前 评论:

changed this line on 61d30e6d view diff detail

xutianzexutianze成员
26 天前 预合并成功(commit_id: f076a1388756461afe9beb21066d0b755d5f6050)
xutianzexutianze成员
26 天前 推送  1 个提交:61d30e6d-refactor(cuda2ascend): decouple init scripts from concrete frameworks
xutianzexutianze成员
26 天前 预合并成功(commit_id: 0670e2258ee08c8b65d317b188e1816d6212be91)
CANN-robotCANN-robot成员
26 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
26 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
xutianze
xutianze成员26 天前进行代码检视2
plugins-community/cuda2ascend/example/init.sh
已过期
@@ -266,3 +265,1 @@
266-[ "$TARGET_ENV" = "claude" ] && CLI_NAME="claude"
267-[ "$TARGET_ENV" = "codex" ] && CLI_NAME="codex"
268-[ "$TARGET_ENV" = "dsh" ] && CLI_NAME="dsh"
265+# 与框架解耦:CLI 启动命令名与目标工具名一致,直接复用用户选择的 target;
xutianze
xutianze26 天前评论:

不要加注释

likedislike
System
系统消息系统
26 天前 评论:

changed this line on 5a027092 view diff detail

xutianze
xutianze成员
26 天前 评论:

compile

likedislike
xutianzexutianze成员
26 天前 解决了最后一个问题
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
26 天前 评论:

流水线任务触发成功
任务链接 [50a7f639559b4a789236e0d152aec183][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
UT_Test ❌ FAILED >>>>>
codecheck_style ✅ SUCCESS >>>>>
pre-commit ✅ SUCCESS
pre_comment ✅ SUCCESS >>>>>
likedislike
xutianzexutianze成员
26 天前 预合并成功(commit_id: 682c83acf567f4efc0e388699e16ce401cbfea24)
xutianzexutianze成员
26 天前 推送  1 个提交:5a027092-refactor(cuda2ascend): drop explanatory comments on CLI_NAME per review
xutianzexutianze成员
26 天前 预合并成功(commit_id: d7e7ac052bfad3f490178eceac79c79152286f60)
CANN-robotCANN-robot成员
26 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
xutianze
xutianze成员
26 天前 评论:

compile

likedislike
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-failed
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
26 天前 评论:

流水线任务触发成功
任务链接 [d856c786b4a24eeab64c929d3069aaf0][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
UT_Test ❌ FAILED >>>>>
codecheck_style ✅ SUCCESS >>>>>
pre-commit ✅ SUCCESS
pre_comment ✅ SUCCESS >>>>>
UT_Test_AI_review ✅ SUCCESS >>>>>
likedislike
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-running
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
xutianze
xutianze成员
26 天前 评论:

compile

likedislike
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
26 天前 评论:

流水线任务触发成功
任务链接 [3fe43b8ef9534543986c15b1b11495c3][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
UT_Test ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
pre-commit ✅ SUCCESS
pre_comment ✅ SUCCESS >>>>>
UT_Test_AI_review ✅ SUCCESS >>>>>
ST_Test_A2 ✅ SUCCESS >>>>>
ST_Test_A5 ✅ SUCCESS >>>>>

[2026-08-27 15:42:27]    CI执行结束

likedislike
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-passed
YanYL
YanYL成员
26 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:approved
TangPC
TangPC成员
26 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:lgtm
CANN-robotCANN-robot成员
26 天前 合入了pull request