Skip to content

refactor(app-components): extract shared tool card and task list setup hooks - #5543

Open
liruifengv wants to merge 2 commits into
mainfrom
refactor/tool-card-setup
Open

liruifengv wants to merge 2 commits into
mainfrom
refactor/tool-card-setup

Conversation

@liruifengv

@liruifengv liruifengv commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

为后续移除 packages/app-components 内部对自身公共桶文件(@moonshot-ai/app-components)的自引用做准备。当前工具卡片(chat/tool-calls/*Tool.vue)与任务面板(SubagentGrid.vue、TasksPane.vue)的 <script setup> 头部存在大段复制粘贴的样板代码,多对组件已有超过 60 tokens 的相同片段;一旦仅修改 import 路径,既有重复片段的指纹就会变化,从而触发 CI lint 中的 check:duplication(jscpd)新增重复门禁。本 PR 先将这些公共 setup 收敛为业务 hooks,消除存量重复,让后续断环 PR 保持纯粹的 import 路径调整。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

按「业务逻辑收敛到 hooks,UI 组件组合 hooks 驱动视图」的方式提取公共 setup,不改变任何组件的模板结构、样式、交互行为与持久化存储键。浏览器相关组件(BrowserTool.vue、browser/*)不在本 PR 范围内,未做改动。

 <*Tool.vue>
-  useHistoryState / useI18n / inject(panelApiKey)
-  computed status(含 as 强转)/ hasOutput / args / argText / open / watch(defaultExpanded)
+  useToolCard(props)                 // 上下文与惰性派生值
+  useToolCardExpansion(props, canExpand) // 折叠持久化与自动展开
   各工具特有的参数解析与 canExpand 计算
   <ToolDisclosure />                 // 模板与样式保持不变

新增与调整的模块

模块 职责
chat/tool-calls/useToolCard.ts(新增) 导出 ToolCardProps;useToolCard(props) 提供 panelApi、status、kind、args、argText、toolNameLabel、label、summary、summaryFull、hasOutput(均为惰性 computed,未使用不求值);useToolCardExpansion(props, canExpand) 负责 useHistoryState 折叠状态持久化与 defaultExpanded 自动展开监听
chat/dock/useTaskList.ts(新增) 导出 TaskListProps / TaskListEmits;useTaskList(props, t) 提供 SubagentGrid 与 TasksPane 共用的 panelApi、modelDisplay、subagentEffort、isCancelling、stateLabel、durationLabel
chat/tool-calls/goalToolOutput.ts 保留原 updateGoalVisibleOutput 导出及既有单测;新增 GOAL_TOOL_KIND 常量、goalHeadline、goalVisibleOutput 与 useGoalToolCard,将 Goal 卡片标题/预算/状态文案与展开逻辑收拢为纯函数与 hook
11 个工具卡片 .vue + 2 个任务面板 .vue 改为组合上述 hooks,仅保留各自特有的参数解析与模板渲染

旧路径功能清单与等价性对照

原有行为 / 边界 新路径中的位置
status 运行时值原样透传给 ToolDisclosure(原代码用 as 'running'|'ok'|'error' 窄化类型) useToolCard 返回真实 ToolStatus,运行时值完全不变;ToolDisclosure 本身已支持 'cancelled',无需类型强转
折叠状态持久化 key tool:${tool.id}:open useToolCardExpansion 中保持完全相同的 key 与初始值 defaultExpanded === true && canExpand
自动展开 watch 统一监听 [defaultExpanded, output?.length, status, name];同一 toolCall 的 name 不变,与原先监听前 3 项行为一致
EditTool(初始 open=false、无自动展开 watch)、ReadTool(everOpened 跟踪) EditTool 保留自身的 useHistoryState;ReadTool 保留 everOpened watch
展开逻辑不同的卡片(AgentTool、AskUserTool、PlanTool、SelectToolsTool、SwarmTool、TodoTool、BashTool、CronTool) 本 PR 保持原样不动,避免改变各自特有的展开触发条件
TasksPane 状态文案 stateLabel(task) 统一为 useTaskList 的 stateLabel(state),模板改为 stateLabel(task.state)
vue-i18n 的使用方式 useI18n() 保持在各 .vue 组件中单独调用;需要翻译的 hooks / 纯函数(useTaskList、useGoalToolCard、goalHeadline)通过参数接收 t,不在业务 hooks 内二次包装 useI18n

同时运行 ratchet.mjs --update 与 app-boundaries.mjs --update 下调基线:SubagentGrid.vue、TasksPane.vue、GoalTool.vue 已提前退出 app-components 运行时循环依赖环。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
工具卡片与任务面板的渲染、展开/折叠、自动展开与刷新后状态恢复 各组件内联实现 由共享 hooks 提供相同行为,DOM、CSS、storage key 均不变 Desktop 与 Web 聊天用户 N/A
Goal 卡片标题与输出截断规则 组件内联 switch 与 updateGoalVisibleOutput 委托给 goalToolOutput.ts 纯函数,规则与原单测保持一致 使用 Goal 模式的会话 N/A
验证记录
  • pnpm --filter kimi-code-app run typecheck:通过。
  • pnpm exec vitest run --reporter=agent packages/app-components:101 个测试文件、1018/1018 通过。
  • pnpm lint:通过(0 退出),oxlint-ratchet 与 app-boundaries 基线均已下调。
  • pnpm run check:duplication origin/main:本 PR 涉及的 app-components 重复片段已全部消除;本地 macOS(jscpd-darwin-arm64@5.1.2)在 diff 非空时会对未触碰的 packages/core/src/tool/tool-executor.ts:403-444 同文件自克隆报出基线指纹缺失(纯净 origin/main 无 diff 时不触发),本 PR 未修改 core,以 CI Linux 门禁结果为准。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).(内部重构前置 PR,无关联 issue)
  • I have added tests that prove my feature works.(复用 app-components 现有 1018 个组件与工具输出单测验证等价性,保留 goalToolOutput.test.ts 全部断言)
  • 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: 68cc663

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-26T12:46:48.087506Z 3f03c68 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@68cc663
npx https://pkg.pr.new/@moonshot-ai/kimi-code@68cc663

commit: 68cc663

This branch has not been deployed

No deployments
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