Skip to content

refactor(app-components): import tool card helpers from their defining modules - #5548

Merged
wbxl2000 merged 1 commit into
mainfrom
refactor/app-components-tool-imports
Nov 27, 2026
Merged

wbxl2000 merged 1 commit into
mainfrom
refactor/app-components-tool-imports

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Requirement or Bug

packages/app-components/src/chat/tool-calls/ 下的 16 个工具卡片组件和 toolRegistry.ts 目前通过包自身的公共桶文件 @moonshot-ai/app-components 导入参数解析、工具名称/图标、问答解析等纯函数。这会让任意一张工具卡片在运行时静态拉入整个 index.ts,与聊天面板、后台管理页共同构成 33 个文件的运行时循环依赖环。本 PR 是 Desktop 分阶段重构的 PR 1.1(紧接 #5543),把这些纯工具导入改为直连真实定义模块,使工具卡片子树彻底退出循环依赖。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

只修改 chat/tool-calls/ 内的导入来源,不改动任何组件的模板、逻辑、props 与包对外导出(src/index.ts 保持不变)。浏览器相关组件不在本 PR 范围内。

 ToolCall.vue
   toolRegistry.ts
-    normalizeToolName ← @moonshot-ai/app-components (index.ts)
+    normalizeToolName ← @moonshot-ai/app-core/lib
   16 个 *Tool.vue
-    参数/名称/问答解析 ← @moonshot-ai/app-components (index.ts → 全包静态导入)
+    参数解析 (str / num / parseArgRecord / ...) ← ./toolArgs
+    名称与图标 (toolLabel / toolGlyph / ...)   ← ../../lib/toolMeta
+    问答解析 (parseAskInput / ...)            ← ./askUserToolParse

因为工具卡片子树不再回指 index.ts,ChatPane.vue 等剩余节点无法再经由 index.ts → ToolCall.vue 回到工具卡片,16 个工具卡片、toolRegistry.ts 与 ToolCall.vue 共 18 个文件一次性退出运行时环。

旧路径功能清单与符号映射

index.ts 原本只是对这些模块做 export * 透传,改为直连后拿到的是完全相同的函数绑定:

导入符号 原路径 新路径 涉及文件
str @moonshot-ai/app-components ./toolArgs BackgroundTaskTool、GlobTool、GrepTool、WaitForTool
parseArgRecord, str @moonshot-ai/app-components ./toolArgs SkillTool、TodoTool
str, urlHost @moonshot-ai/app-components ./toolArgs WebFetchTool
argFallbackText, parseArgRecord, str @moonshot-ai/app-components ./toolArgs BashTool
argFilePath, num @moonshot-ai/app-components ./toolArgs ReadTool
argFallbackText, argFilePath, parseArgRecord, pathDirname @moonshot-ai/app-components ./toolArgs EditTool
toolLabel @moonshot-ai/app-components ../../lib/toolMeta AgentTool、AskUserTool、SwarmTool
toolGlyph, toolLabel @moonshot-ai/app-components ../../lib/toolMeta PlanTool
computerUseArgFields, toolChip, toolGlyph @moonshot-ai/app-components ../../lib/toolMeta GenericTool
toolIconName, toolLabel, toolSummary @moonshot-ai/app-components ../../lib/toolMeta CronTool
normalizeToolName @moonshot-ai/app-components(经 toolMeta.ts 原样 re-export) @moonshot-ai/app-core/lib(合并进 CronTool 已有的同路径导入) CronTool、toolRegistry.ts
answerFor, parseAskBackground, parseAskInput, parseAskOutput, resolveAnswer @moonshot-ai/app-components ./askUserToolParse AskUserTool

测试与基线

  • packages/app-components/test/bashToolCommand.test.ts:删除 vi.mock('@moonshot-ai/app-components', () => import('../src/chat/tool-calls/toolArgs'))。该 mock 原本用于在单测中拦截 barrel 以避免加载全包;BashTool.vue 改为直连 ./toolArgs 后已不再需要,移除后测试直接验证组件在无 barrel mock 下的真实挂载行为。
  • 运行 node scripts/checks/app-boundaries.mjs --update 与 node scripts/checks/ratchet.mjs --update,基线只降不升:
    • chat/tool-calls/ 的 self-package-import:19 → 0(全包剩余 12 处集中在 chat/*.vue 与 admin/*.vue,留给 PR 1.2)。
    • app-components 的 runtime-cycle 成员:33 → 15。
    • oxlint import/no-cycle 与 import/no-duplicates(AskUserTool、CronTool 清零)同步下降。

阅读指南

先看 packages/app-components/src/chat/tool-calls/CronTool.vue 和 AskUserTool.vue(唯一涉及多来源拆分/合并的两个文件),其余 15 个文件均为单行 import 路径替换;test/bashToolCommand.test.ts 与两个基线 JSON 可略读。

Behavior Changes and Affected Users

None。

证据:所有符号均指向 index.ts 原本 re-export 的同一模块定义(normalizeToolName 在 toolMeta.ts 中也是 export { normalizeToolName } 的同一 ESM 绑定);未改动任何分支条件、默认值、模板、样式、src/index.ts 公共导出面或契约文件。

  • 受影响模块:Desktop 与 Web 聊天中的工具卡片渲染(Bash、Read、Edit/Write、Grep、Glob、WebFetch、Todo、Task、AgentSwarm、AskUserQuestion、ExitPlanMode、WaitFor、TaskList/TaskOutput/TaskStop、Cron、Skill 及 Generic 兜底卡片)。
  • 测试覆盖:packages/app-components 全部组件与工具解析单测(含 bashToolCommand.test.ts、toolCardState.test.ts、askUserToolParse 相关用例等)。
验证记录
  • pnpm lint:通过(0 退出)。
  • pnpm --filter kimi-code-app run typecheck:通过(主进程 tsc --noEmit 与渲染端 vue-tsc --noEmit -p tsconfig.renderer.json)。
  • pnpm exec vitest run --reporter=agent packages/app-components packages/app-core/test/activitySummary.test.ts:103 个测试文件、1063 个用例全部通过。
  • pnpm run check:duplication 88553c7d2ccc126ccafccac710d62f09f23455ff:通过,无新增重复片段(refactor(app-components): extract shared tool card and task list setup hooks #5543 抽取公共 hooks 后,本次 import 调整不再触发 jscpd 门禁)。
  • 平台核对:本 PR 仅调整 ESM import 说明符,不涉及文件系统路径处理、子进程、shell 或终端输入;上述检查在 macOS 本地通过,Linux 由 CI 验证。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).(内部重构 PR 1.1,无关联 issue)
  • I have added tests that prove my feature works.(纯导入路径重构,复用 app-components 现有 1063 个单测与 app-boundaries 门禁验证;移除 bashToolCommand.test.ts 中已过时的 barrel mock)
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.(私有 app-* UI 层内部重构,无用户可感知变化,无需 changeset)
  • Ran gen-docs skill, or this PR needs no doc update.(不改变用户可见功能,无需更新用户文档)

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 98fd510

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T13:46:39.181452Z 98fd510 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@98fd510
npx https://pkg.pr.new/@moonshot-ai/kimi-code@98fd510

commit: 98fd510

@wbxl2000
wbxl2000 merged commit e678db6 into main Nov 27, 2026
23 checks passed
@wbxl2000
wbxl2000 deleted the refactor/app-components-tool-imports branch November 27, 2026 03:54
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.

2 participants