Skip to content

feat: 动态工具插件化——引入可扩展的 DynamicToolRegistry#3

Merged
QinQinChina merged 1 commit into
mainfrom
devin/1780830356-dynamic-tool-plugin-system
Jun 7, 2026
Merged

feat: 动态工具插件化——引入可扩展的 DynamicToolRegistry#3
QinQinChina merged 1 commit into
mainfrom
devin/1780830356-dynamic-tool-plugin-system

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

将动态工具系统从"写死的联合类型 + 静态记录"重构为可扩展的注册表模式

之前 BuiltinDynamicToolName = "image_generate" 是封闭联合,新增工具必须修改核心类型。
重构后新增工具只需:

import { dynamicToolRegistry } from "@codenexus/shared/dynamicTools";

dynamicToolRegistry.register({
  name: "local_search",
  namespace: "codenexus",
  label: "Local Search",
  description: "Searches workspace files by content",
  requiresApproval: false,
  inputSchema: {
    type: "object",
    properties: { query: { type: "string" } },
    required: ["query"],
  },
});

注册后工具自动出现在设置的启用/禁用列表中,并在下一次 Codex 会话启动时被注入。

Scope

  • packages/shared/src/dynamicTools.ts — 核心重构:DynamicToolRegistry 类 + 单例 + builtin 自注册 + 旧导出兼容层
  • packages/shared/src/localSettings.tsenabledByName 类型从 Record<BuiltinDynamicToolName, boolean> 放宽为 Record<string, boolean>
  • packages/shared/src/__tests__/dynamicTools.test.ts — 新增 6 个注册表测试,总计 36 个测试通过

Verification

  • pnpm run format:check
  • pnpm run lint
  • pnpm run typecheck(4 个子包全部通过)
  • pnpm run test — 36 tests passed

Screenshots or Recordings

N/A(无 UI 变更)

Notes

  • 旧 API(BUILTIN_DYNAMIC_TOOL_DEFINITIONSbuildBuiltinDynamicToolSpecsfilterEnabledBuiltinDynamicToolNamesnormalizeBuiltinDynamicToolName)标记 @deprecated 但仍可用,调用侧无需立即修改。
  • DynamicToolRegistry 是纯内存结构,渲染层和主进程各自维护独立实例;当前 dynamicToolRegistry 单例在模块加载时注册内置工具。
  • 后续可在此基础上加:工具配置 UI(设置页列出所有 registered tools)、工具 JSON manifest 文件加载、远程 MCP 工具自动注册等。

Link to Devin session: https://app.devin.ai/sessions/26c0ad2a81d3440eaa67d6f4feb3df33
Requested by: @QinQinChina

- Introduce DynamicToolRegistry class with register/unregister/getDefinition/
  getAllNames/buildEnabledSpecs/buildDefaultEnabledByName methods
- Export singleton dynamicToolRegistry pre-loaded with image_generate builtin
- New tools can now be added via dynamicToolRegistry.register({...}) without
  modifying core types or union definitions
- Update localSettings to use Record<string, boolean> for enabledByName
  (open to any registered tool name, not just closed union)
- Keep all existing exports as backward-compatible wrappers (marked @deprecated)
- Add 6 new unit tests for DynamicToolRegistry (total: 36 tests passing)
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@QinQinChina QinQinChina merged commit 58e8730 into main Jun 7, 2026
1 check 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.

1 participant