Skip to content

refactor(plugin-chatbot): move renderToolDetail out of ChatbotEnhanced into chat/toolDetail.tsx - #37964

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37729-tool-detail-split
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37729-tool-detail-split

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #37729

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户看到的变化:没有。对话里的工具卡片(审批、写记录、删软件包等卡片)照常显示,只是这部分代码从对话主组件搬进了单独的文件。
  • 为什么:对话界面拆分专题的第二张拆分卡;工具卡片是主组件里最大的一块,也是接下来审批卡改动要动的地方,拆开后冲突和审阅都更小。
  • 出问题会怎样:只搬代码不改逻辑,最坏是某张工具卡显示异常或类型检查变红;回滚这一个合并即可。
  • 需要你做的:无。

What changes

A move-only split of ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx: 1514 → 1097 lines. The renderToolDetail closure (447 body lines) becomes the module-level function renderToolDetail(tool, ctx) in the new ui/packages/plugin-chatbot/src/chat/toolDetail.tsx (580 lines), the card's preferred form.

  • The element tree is the same text. The function body is byte-identical to the closure body after a four-space dedent (checked with diff of the two bodies: no difference over 447 lines). It still returns the Tool element at key={tool.toolCallId} with the same defaultOpen expression. The first statement destructures ctx into the same 41 names the closure read from the component scope, so not one reference in the body changed.
  • ctx. ChatbotEnhanced builds one plain object, toolDetailCtx, where the closure used to be (no hook, no memo, so the hook order is unchanged) and calls renderToolDetail(tool, toolDetailCtx) where it called renderToolDetail(tool). Its type, ToolDetailContext, is spelled from ChatbotEnhancedProps: a Required pick of the props that have defaults, a plain pick of the four that have none (toolDecisions, onToolApprove, onOpenRecordForm, onOpenRecord), plus tt, L, toolStatusLabels, heldForApprovalLabel and detectPackageRemovedResult.
  • Dependency direction. toolDetail.tsx imports ../tool-display, ../elements/tool, ./toolSummary, ./toolRecordWrite (the card names this one) and, as types only, ./types and ../mapMessages. It never imports ChatbotEnhanced.tsx.
  • detectPackageRemovedResult rides in ctx. It is a value exported by ../mapMessages, and shared constraint 4 allows only import type from that module, so the component (which already imported it) hands it in; the new module takes its type only.
  • Exports. renderToolDetail and ToolDetailContext are exported from the new module only, because the component uses them. Nothing is added to or removed from what ChatbotEnhanced.tsx exports, so its re-export block is unchanged and every import path still works.
  • Imports dropped from ChatbotEnhanced.tsx, all of them now used only inside the card: seven lucide icons, humanizeToolName, unwrapToolResult, Tool/ToolHeader/ToolContent/ToolInput (the ToolStatusLabels type stays, now as import type), ChatbotEnhancedToolInvocation, SmartToolOutput, ToolRunningTimer, formatRecordWriteValue, writtenRecordOf.
  • Frozen entries. ui/packages/plugin-chatbot/src/index.tsx, ui/packages/plugin-chatbot/src/core.ts and ui/packages/app-shell/src/index.ts have an empty diff.

Tests

One new file, the only one the card allows; no existing test file is touched.

src/__tests__/ChatbotEnhanced.toolCardOpenState-37729.test.tsx renders a turn with two tool cards, one that starts closed (completed) and one that starts open (failed), flips both by clicking their headers, re-renders the component with two more messages and a fresh props object, and asserts that each card still shows what the user chose (aria-expanded). It was committed on the baseline first (30a3737, before the split) and run green there; it stays green after the split.

Acceptance notes

  • The card's own figure ("about 1372 → 920") was read before split A's final head. The measured figures are above: 1514 → 1097 for ChatbotEnhanced.tsx, 580 for the new module.
  • What is not a moved line: comparing the multiset of removed lines with the multiset of added lines (whitespace-stripped) over the two source files, everything left over is import/export lines plus the ctx plumbing the card prescribes: the ToolDetailContext type, the const { … } = ctx; destructure, the toolDetailCtx object, the new function's signature line and the call site's added argument, and the new module's license header and module comment. Nothing inside the card's body differs.
  • --color-moved=zebra alone does not paint the moved block, because every moved line is four spaces shallower; git diff --color-moved=zebra --color-moved-ws=allow-indentation-change origin/main...HEAD does.
  • The new module exports a function and a type, not a component, so it adds no react-refresh/only-export-components warning. eslint over ChatbotEnhanced.tsx reports the same one warning before and after the split.
  • The branch is not merged with main. Since its base, main gained the QuestionCard work in plugin-chatbot (new files plus an index.tsx export); it touches none of this PR's files and overlap-check reports a clean merge.

Verification

Read first: chat/toolDetail.tsx's ToolDetailContext and its destructure (the only new logic-shaped text), then the toolDetailCtx object in ChatbotEnhanced.tsx.

Two-minute check: pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.toolCardOpenState-37729.test.tsx from the repository root; expect 1 file, 1 test passed.

git diff --color-moved=zebra --stat origin/main...HEAD
 .changeset/37729-chatbot-enhanced-split-b.md       |  10 +
 ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx | 509 ++----------------
 ...hatbotEnhanced.toolCardOpenState-37729.test.tsx |  87 ++++
 ui/packages/plugin-chatbot/src/chat/toolDetail.tsx | 580 +++++++++++++++++++++
 4 files changed, 723 insertions(+), 463 deletions(-)

The deleted lines and the added lines differ only in import/export lines, plus the ctx object, its type and its destructure that the card's renderToolDetail(tool, ctx) form requires.

Local readings (objectstack-ai/objectstack, head 41c8aba on merge base f926dfa; main since moved to d1139f9, which merges cleanly)
  • The new test on the baseline, commit 30a3737 (before the split): pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.toolCardOpenState-37729.test.tsx: 1 file, 1 test passed.
  • The same test on 41c8aba (after the split): 1 file, 1 test passed.
  • The test can fail: with the card's key changed on disk to a fresh value per render (restored from HEAD afterwards), it fails at the post-re-render assertion (aria-expanded "false", expected "true").
  • pnpm --dir ui exec vitest run packages/plugin-chatbot/: 70 files, 662 tests passed.
  • pnpm --filter @object-ui/plugin-chatbot run type-check (tsc --noEmit and tsc -p tsconfig.test.json, whose include covers the new test): exit 0.
  • pnpm --filter @object-ui/plugin-chatbot run build: exit 0.
  • eslint over ChatbotEnhanced.tsx, chat/toolDetail.tsx and the new test: exit 0, 0 errors, 1 warning (react-refresh/only-export-components on ChatbotEnhanced.tsx); the baseline file has the same one warning.
  • dispatch-gates: all 38 derived commands ran and exit 0; dispatch-gates --ran reconciles 38 of 38, 0 NOT-MEASURED, every line with its exit code.
  • pnpm --dir ui check:new-line-citations: 0 new. check-platform-checklist --changed-from origin/main: exit 0, no anchored file in the change set.
  • overlap-check: merges cleanly with origin/main; no open PR shares a file.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85

… across a re-render

Added on the baseline, before renderToolDetail moves out of
ChatbotEnhanced.tsx, so the split is judged against it.

Claude-Session: https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
Co-authored-by: Claude <noreply@anthropic.com>
Move-only: the tool-card closure becomes the module-level function
renderToolDetail(tool, ctx). Its body is byte-identical to the closure's
after a four-space dedent; ctx carries what the closure read from the
component scope. Imports the component no longer uses are dropped.

Claude-Session: https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwGVgec21LwQTtRY85

Final head for review: 41c8abab904f6df103648c25233f23af375fc5b6 · area o1-D. Check-runs on this head: 39 success, 13 skipped, 0 failed; mergeable clean. +723/-463 in 4 files, not governed. ChatbotEnhanced.tsx 1514 → 1097 lines; the moved 447-line body is byte-identical after a 4-space dedent; the card's one allowed test was committed alone on the baseline (30a3737) and run green there and after. Dev report 7219280457 on #37729. L1 requested from seat 1's L1 thread.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3

L1 verdict (L1-a): ACCEPT at head 41c8abab904f6df103648c25233f23af375fc5b6 (Fixes #37729). Full read · 2026-11-27T13:36Z

席位核对

Shape and gates. 4 files, +723/-463. Check-runs at 41c8aba: 39 success, 13 skipped, 0 failed. Not governed. Clause-②: no · Metadata-protocol: none, both in the changeset and the body.

Point 1, the move is byte-identical: measured. I took the closure from ChatbotEnhanced.tsx at the merge base (line 539, 449 lines through its closing };), removed 4 spaces of indent, and diffed it against renderToolDetail in chat/toolDetail.tsx. The only difference is the first line, which gains export and the ctx parameter, plus the 43-line destructure of ctx inserted after it. Every line of the body is identical. The component builds toolDetailCtx with shorthand properties of the same names, so each name binds the same value the closure read. It is built in render with no hook and no memo, and the call site is renderToolDetail(tool, toolDetailCtx) at the same place. A free name the closure read that is missing from ctx would fail type-check, and type-check is green.

Point 2, detectPackageRemovedResult through ctx: accepted. Card constraint 4 allows only import type from ../mapMessages. Passing the component's own import in keeps the same function, and the type is typeof that import.

Point 3, the import/export sentence with its qualifier: accepted. The ctx plumbing is the form the card itself prescribes, so naming it next to the import/export lines is the honest version of constraint 6.

Point 4, the pre-split test: accepted. ChatbotEnhanced.toolCardOpenState-37729.test.tsx is the one new test file the card allows, committed alone on the baseline and green before and after the split. No existing test file changes.

Constraints. The public entries are frozen: index.tsx, core.ts and app-shell/src/index.ts are not in the diff. No re-export is owed, because renderToolDetail was a closure and never exported. The new module does not import ChatbotEnhanced.tsx. It takes writtenRecordOf and formatRecordWriteValue from card A's toolRecordWrite.ts, as the card says. The changeset is patch at the repo root.

Point 5, main not merged: fine. #37932 touches none of these files, and overlap-check is clean.

Changeset, sentence by sentence. It says this is a move-only split with no behaviour change and the same element tree: true by the byte diff above. It says the function is module-level and called with one context object: true. It says the entry points and published API are unchanged: true.

Landing: not governed, under 3000 lines, no narrowing. The area lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwGVgec21LwQTtRY85

Landing · area o1-D · 2026-11-27T13:37Z
ACCEPT → PR #37964 comment 7219724276 (L1-a, head 41c8abab904f6df103648c25233f23af375fc5b6).
Governed: check-governed-merges.mjs --pr 37964: not governed; 1186 changed lines ≤ 3000. Clause-②: no, not a narrowing.
Checks on this head: 39 success, 13 skipped, 0 failed; mergeable clean.
Action: ready + auto-merge (merge queue).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 13:37
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 57ab087 Nov 27, 2026
53 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37729-tool-detail-split branch November 27, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

对话组件拆分 B:把 ChatbotEnhanced 主组件里的工具卡渲染(renderToolDetail)搬成独立模块(不改行为)

2 participants