Skip to content

fix(opencode): 修复启用召回后生成无效代理配置 - #344

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
BAIABAIO:fix-opencode-recall-332
Aug 27, 2026
Merged

fix(opencode): 修复启用召回后生成无效代理配置#344
jeff-r2026 merged 2 commits into
Tencent:mainfrom
BAIABAIO:fix-opencode-recall-332

Conversation

@BAIABAIO

Copy link
Copy Markdown
Contributor

Summary

修复启用 recall 后,TeamAI 将 Claude 格式的内置代理配置直接复制到 OpenCode,导致 OpenCode 配置校验失败、无法启动的问题。

内置代理现在会复用现有的目标工具原生渲染流程。OpenCode 生成的代理配置使用 mode: subagent,不再包含 Claude 专用的 name 和字符串格式的 tools 字段。对于尚无原生渲染器的目标工具,将跳过部署并输出可操作的警告。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit 通过
  • npx vitest run --coverage 通过
  • 已增加或更新相关测试
  • npm run build 通过
  • 使用真实 OpenCode CLI 验证旧配置会因 tools 字段失败
  • 执行 teamai recall enableteamai pull --force
  • 使用当前 OpenCode schema 逐个验证所有生成的 agent 文件
  • 验证 OpenCode 能正常加载最终配置并启动

本地验证结果:

  • 165 个测试文件全部通过
  • 2254 个测试全部通过
  • src/builtin-agents.ts 语句覆盖率为 81.94%
  • OpenCode E2E 使用固定版本 1.18.23

Related Issues

Fixes #332

Notes for Reviewers

内置 recall agent 仍以 Claude Markdown 格式作为唯一源文件,部署时通过现有的 reverseFromClauderenderForTool 转换成不同工具的原生格式。

本次修改没有为 OpenCode 单独维护第二份模板,避免内置代理与普通团队代理的渲染逻辑继续分叉。

真实 OpenCode E2E 包含负向对照:先确认旧版原样复制的配置确实会被 OpenCode 拒绝,再验证修复后的生成文件和完整配置均能通过校验。

@jeff-r2026
jeff-r2026 requested a review from m0Nst3r873 August 27, 2026 02:32
@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Thanks for this — root cause is spot on, and the negative-control E2E (proving the old file is actually rejected before validating the fix) is excellent.

One blocker before merge (P1): routing all tools through renderForTool introduces a new regression for Codex-family tools.

  • renderForCodex / renderForCodexInternal return ext: '.toml' (agent-format.ts:165,173), and codex / codex-internal / tcodex all have an agents path in the default toolPaths and are in ALL_SUPPORTED_TOOLS. So on a machine with Codex installed, recall enable now writes .codex/agents/teamai-recall.toml (previously copyFile produced teamai-recall.md).
  • Both removal paths hardcode .md: recall-toggle.ts:33 (remove(.../teamai-recall.md)) and uninstall.ts:294 (${name}.md).

Result: teamai recall disable and teamai uninstall can no longer delete the generated .toml — Codex users are left with a permanent orphan file. This did not happen before the change (Codex got a .md, which the removal paths could delete).

The new tests do not catch it because every case only configures opencode as a target — there is no Codex target exercised.

Suggested fix (any one):

  1. Derive the extension in the removal paths from renderForTool(spec, tool).ext instead of hardcoding .md (most thorough), or
  2. Skip non-.md targets (Codex family) in the deploy loop with a warning, or
  3. Constrain built-in recall deployment via spec.targets.

Please add a regression test with a Codex target covering enable -> disable leaves no orphan.

@BAIABAIO

BAIABAIO commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

已按 CR 修复并推送提交 2d80731,感谢指出。

这个 P1 在 recall disable 路径确实成立:我先新增 Codex「enable → disable」回归测试,修复前该测试会失败,表现为 teamai-recall.toml 在禁用后仍然存在。

本次处理:

  • 新增 agentFileExtensionForTool,让 agent renderer 与清理逻辑共用同一份工具原生扩展名映射,避免生成和删除规则再次漂移;
  • recall disable 会精确删除当前工具的原生文件以及历史 .md 文件,覆盖升级后的遗留清理;
  • 只删除 teamai-recall.md / teamai-recall.toml,回归测试同时证明 teamai-recall.backup 等用户文件不会被误删;
  • uninstall 当前实现本身已经按 .md | .toml 且匹配 agent stem 收集文件,因此没有改生产逻辑;补充了 Codex built-in TOML 卸载测试,明确证明该路径会清理 teamai-recall.toml

验证结果:

  • 定向回归:4 个测试文件,90/90 通过;
  • 全量覆盖率测试:166 个测试文件,2256/2256 通过;
  • npm run typechecknpm run build 通过;
  • 使用真实 OpenCode 1.18.23 的启动 E2E:1/1 通过。

@jeff-r2026
jeff-r2026 merged commit c3782a3 into Tencent:main Aug 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] enabling recall generates an invalid OpenCode agent config and blocks startup

3 participants