Skip to content

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

Description

@objectstack-fleet

repo:cloud#5 · hotlong · session_01Q4EjjMouQg4opwRbvXunTA

Filing gate: ③ maintainer-directed task · Source: topic #37690 — Jack 2026-11-27T00:09Z:「对话界面改进 ,用fable评估,开始分拆」;Fable 评审后本卡范围缩小为只搬工具卡。
Grade: area:ai · Task · p2 · reach: 无行为变化的重构 · evidence: read(基线 objectstack main 80519b5 + PR #37720 head c2b7b6a)
Reader: 专题 objectstack#37690 的拆分卡线程(os-dev)。
Dedupe: 同 #37728,无重叠。
Blocked-by: #37728(拆分卡 A,同文件,A 合并后开工)

为什么

卡 A 之后主组件仍约 1372 行,其中 renderToolDetail 闭包约 450 行,是最大的一块,也是后续审批卡改动要动的地方。

做什么

把主组件里的 renderToolDetail 闭包搬到 ui/packages/plugin-chatbot/src/chat/toolDetail.tsx,主组件约 1372 → 920 行。

  • 首选写法:模块顶层的纯函数 renderToolDetail(tool, ctx),返回的元素树与现在逐字一致(仍是 <Tool key={tool.toolCallId} defaultOpen={…}> 开头)。ctx 是一个对象,装闭包现在读的 props、标签和回调(约 40 个:toolDecisions、onToolApprove、processVisibility、L、tt、toolStatusLabels 等)。主组件原地调用 renderToolDetail(tool, ctx)。
  • 若改成组件 ToolDetailCard,必须同时满足:定义在模块顶层;key={tool.toolCallId} 放在调用处外层;只收一个 ctx 对象;不新增 hook 或 memo。
  • writtenRecordOf、formatRecordWriteValue 从卡 A 的 toolRecordWrite.ts 引入。

先加一条测试(不改旧测试)

在拆分之前,在基线上新增一条测试并跑绿:用户手动折叠或展开某张工具卡后,父组件 rerender(例如追加一条消息),该卡的展开状态保持不变。拆分后同一测试仍绿。这是本卡唯一允许新增的测试文件,旧测试文件一律不改。

不做

MessageItem、ChatComposer 这类按区域的拆分本轮不做:它们各要传 50 多个闭包变量,边界等第 3 段的体验改动来定。

通用约束(本专题三张拆分卡共用)

  1. 只搬代码,不改行为:不改 JSX 结构、className、文案键、hook 调用顺序、memo 依赖、条件分支。
  2. 原文件保留具名 re-export(export { a, b } from './x',类型用 export type { … }),⛔ 不用 export *:docs/qa/platform-checklist/ 的符号锚点(scripts/symbol-anchors.mjs)只认具名导出。所有现有 import 路径保持不变。
  3. 测试文件不改,本卡另列的例外除外。
  4. 新文件不得 import 原大文件(避免环)。对 ../mapMessages 等反向依赖方只能 import type。
  5. 公开入口冻结:ui/packages/plugin-chatbot/src/index.tsx、ui/packages/plugin-chatbot/src/core.ts、ui/packages/app-shell/src/index.ts 三个文件 diff 为空。
  6. 验收:现有测试全绿;type-check、lint、build 通过;PR 描述贴 git diff --color-moved=zebra --stat 和一句说明“删除行与新增行之差只有 import/export 行”。
  7. changeset:放仓根 .changeset/(ui/AGENTS.md),级别 patch;changeset 正文和 PR 描述都写 Clause-②: no 与 Metadata-protocol: none 两行(AGENTS.md「Post-Task Checklist」第 3 步)。不碰 CHANGELOG。
  8. 推送前跑 overlap-check。cloud#5027 agent 效果专题优先:它若有在飞 PR 碰同一文件,本卡让路。

Activity

  1. added
    priority:p2
    pm:epic
    domain:ui
    area:ai
    on Nov 27, 2026
  2. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Triage: lands in area:ai · domain:ui · Task · priority:p2 · pm:blocked · size M; rationale: chat component split B (the tool-card renderer). It is a split card, not a topic: pm:epic is for the maintainer's topics only, so it moves from pm:epic to pm:blocked on its named Blocked-by: #37728. p2 as filed.

  3. added
    pm:blocked
    and removed
    pm:epic
    on Nov 27, 2026
  4. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Claim: PM loop round 2 · area o1-D (hand-off 7209013967 from epic:#5027#1, accepted 7210179549; unblocked: #37728's PR #37799 merged 11:53Z as 754e216) · 2026-11-27T11:56Z
    Session: session_016WV4cwGVgec21LwQTtRY85
    Account: os-elon-musk
    Branch: claude/issue-37729-tool-detail-split
    Worktree: objectstack-issue-37729
    Domain: domain:ui
    Area: o1-D
    Seat: repo:objectstack#1
    File surface: ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx, new ui/packages/plugin-chatbot/src/chat/toolDetail.tsx, the one new test file the card allows, one changeset (stop on breach; explain in the report)
    Container & model: M, mode:subagent, model: default tier (dispatch-gates --tier on ChatbotEnhanced.tsx: "no path-derived mandate"), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: n/a — not a defect card (Task)
    Thread-read: 7207101921
    Premise: holds — on origin/main f926dfa ChatbotEnhanced.tsx is 1514 lines (the card's "about 1372" was read before #37799's final head; re-measured), renderToolDetail is the closure at line 539 called at line 1180, and writtenRecordOf / formatRecordWriteValue live in chat/toolRecordWrite.ts.
    Serial constraints cleared: none: overlap-check on a probe branch touching ChatbotEnhanced.tsx and a new chat/toolDetail.tsx exit 0 against origin/main f926dfaba8; #37728 (PR #37799) and #37730 (PR #37803) merged.
    Pre-claim lane: ui/packages/plugin-chatbot/** ⇒ domain:ui (file ownership only); not governed.
    Pre-claim deps: Blocked-by: #37728 closed (PR #37799 merged); seat relay 11:55Z.
    Prior rulings read: topic #37690 maintainer order 「对话界面改进 ,用fable评估,开始分拆」 (quoted in the card); the card's eight shared constraints (move only, named re-exports, frozen public entries) are the binding text; no ruling in the tree bounds the move.
    Fold-or-serial: not folded — no other o1-D card touches plugin-chatbot except #37833's additive useAgents.ts edit (another file).

  5. added
    pm:dispatched
    and removed
    pm:blocked
    on Nov 27, 2026
  6. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

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

    {
      "issue": 37729,
      "status": "done",
      "branch": "claude/issue-37729-tool-detail-split",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37964",
      "head_sha": "41c8abab90",
      "session": "session_016WV4cwGVgec21LwQTtRY85",
      "model_effort": "claude-opus-5-5 (default tier, as dispatched); effort: dispatched high, the served effort is not readable from inside the run",
      "premise_still_valid": true,
      "summary": "renderToolDetail moved from ChatbotEnhanced.tsx into the new chat/toolDetail.tsx as the card's preferred form: a module-level pure function renderToolDetail(tool, ctx). Its 447-line body is byte-identical to the closure body after a 4-space dedent (diff of the two bodies: empty), still opening with the Tool element at key={tool.toolCallId}; a destructure of ctx re-binds the same 41 names, and the component builds one plain toolDetailCtx object (no hook, no memo) and calls renderToolDetail(tool, toolDetailCtx). The card's pre-split test (collapse/expand survives a re-render) was committed alone on the baseline (30a37370), run green there, and stays green after the split; a key mutation turns it red. Premise re-measured on f926dfab: 1514 lines, closure at line 539, call at line 1180 - holds.",
      "files_changed": [
        "ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx (modified, +46/-463)",
        "ui/packages/plugin-chatbot/src/chat/toolDetail.tsx (new, 580 lines)",
        "ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.toolCardOpenState-37729.test.tsx (new, 87 lines; the one test file the card allows)",
        ".changeset/37729-chatbot-enhanced-split-b.md (new, patch for @object-ui/plugin-chatbot, Clause-②: no, Metadata-protocol: none)"
      ],
      "line_budget": "ChatbotEnhanced.tsx 1514 -> 1097 (-417; the card's 1372 -> 920 predates split A's final head); chat/toolDetail.tsx 580 (447 moved body lines + 41-name destructure + ToolDetailContext type + imports + header); PR total +723/-463 = 1186 changed lines, under the 3000 human-merge threshold. Frozen entries index.tsx, core.ts, app-shell index.ts: diff empty.",
      "tests": "Baseline 30a37370 (test only, before the split): vitest run packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.toolCardOpenState-37729.test.tsx -> Test Files 1 passed (1), Tests 1 passed (1); lock VERDICT command-exit 0. After the split, head 41c8abab: same command -> Test Files 1 passed (1), Tests 1 passed (1). Mutation (not owed - no behaviour changed - done to show the test can fail): card key set on disk to a per-render value, restored from HEAD by trap -> 1 failed, at the post-rerender assertion aria-expanded expected true, received false; tree clean after. Package suite on 41c8abab: pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-chatbot/ -> Test Files 70 passed (70), Tests 662 passed (662) (70 = every test file in the package). type-check (tsc --noEmit && tsc -p tsconfig.test.json, include covers the new test): VERDICT command-exit 0. build (vite build x2): BUILD_EXIT=0. eslint on the 3 changed source/test files: exit 0, 0 errors, 1 warning react-refresh/only-export-components on ChatbotEnhanced.tsx, identical to the baseline file's one warning.",
      "gates": "Local, head 41c8abab: node scripts/pm/dispatch-gates.mjs --commands derived 38; all 38 ran, each exit captured before any pipe, every one exit 0 (37 unlocked check commands + pnpm --dir ui exec vitest run scripts/ under the lock: Test Files 172 passed | 2 skipped (174), Tests 5138 passed | 2 skipped). dispatch-gates --ran: 38 derived, 38 run, 0 NOT-MEASURED (a DERIVED zero, all with exit codes). Extra: pnpm --dir ui check:new-line-citations exit 0 (0 new); check-platform-checklist --changed-from origin/main exit 0 (no anchored file); overlap-check VERDICT clean exit 0 against origin/main d1139f98 and 0 sharing PR heads. CI: PR check-runs on 41c8abab were in_progress/queued at report time (Lint, Type Check, Governed Surface Queue Guard, Check Changeset, Check PR Size, PR-body guards) - not awaited, per os-dev.md.",
      "ci": "in_progress at report time on 41c8abab; not awaited",
      "dogfood_battery": "n/a - no ! in the PR title and no (narrowing) arm",
      "mcp_calls": "0 - no MCP GitHub calls",
      "api_writes": "2 relay strokes, 3 REST writes: fleet-write pr_create (POST /repos/objectstack-ai/objectstack/pulls draft + POST /repos/objectstack-ai/objectstack/issues/37964/assignees os-elon-musk), read back identical (8116 bytes); post-stamped comment POST /repos/objectstack-ai/objectstack/issues/37729/comments (this report). Plus 3 git pushes (not REST).",
      "deviations": [
        "detectPackageRemovedResult rides in ctx instead of a value import: it is a value exported by ../mapMessages and shared constraint 4 allows only import type from that module, so toolDetail.tsx imports its type and ChatbotEnhanced (which already imported it) hands it in. mapMessages' own edge back to ChatbotEnhanced is import type only, so a value import would make no runtime cycle; if the area reads constraint 4 as cycle-only, a one-line follow-up can switch it.",
        "The card's sentence 'deleted and added lines differ only in import/export lines' is stated in the PR with its true qualifier: the multiset leftover is import/export lines plus the ctx plumbing the card's renderToolDetail(tool, ctx) form requires (ToolDetailContext, the destructure, the toolDetailCtx object, the signature and call-site argument) and the new module's header. Nothing in the moved body differs.",
        "--color-moved=zebra alone does not paint the moved block because every moved line is 4 spaces shallower; the PR cites the required stat and names --color-moved-ws=allow-indentation-change for the painted view.",
        "Branch not merged with main: since base f926dfab, main gained QuestionCard in plugin-chatbot (#37932: new files + an index.tsx export). It touches none of this PR's files and overlap-check reports a clean merge; no local re-run on the merged tree.",
        "Lock waits: two type-check attempts and one final-test attempt hit queue-timeout (exit 99, NOT MEASURED) behind sibling runs; each was re-run with the same slot and the readings above are the measured re-runs."
      ],
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": []
    }
  7. removed
    pm:dispatched
    on Nov 27, 2026
  8. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Closed by PR #37964 (merged through the queue). pm:dispatched removed with this note. Area o1-D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:uipriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions