Skip to content

♻️ refactor: unify tool content formatting with ComputerRuntime and shared UI#13470

Merged
arvinxx merged 8 commits intocanaryfrom
fix/tool-content-display
Apr 2, 2026
Merged

♻️ refactor: unify tool content formatting with ComputerRuntime and shared UI#13470
arvinxx merged 8 commits intocanaryfrom
fix/tool-content-display

Conversation

@arvinxx
Copy link
Copy Markdown
Member

@arvinxx arvinxx commented Apr 1, 2026

💻 Change Type

  • ♻️ refactor

🔗 Related Issue

N/A

🔀 Description of Change

Problem: Tool content formatting was inconsistent across local-system, cloud-sandbox, and skills packages:

  • local-system used formatCommandResult() for runCommand
  • cloud-sandbox used JSON.stringify() for runCommand, grepContent, getCommandOutput, killCommand
  • skills used plain text concatenation for runCommand

Inspector and Render components were duplicated across all three packages with 90%+ identical code.

Solution:

  1. New @lobechat/tool-runtime packageComputerRuntime abstract class that unifies content formatting via @lobechat/prompts format functions. Subclasses only implement callService():

    • CloudSandboxExecutionRuntime extends ComputerRuntime
    • LocalSystemExecutionRuntime extends ComputerRuntime (new)
    • SkillsExecutionRuntime uses formatCommandResult() directly
  2. New @lobechat/shared-tool-ui package — Shared Render and Inspector components:

    • RunCommandRender — unified render used by all 3 packages
    • createXxxInspector(translationKey) factories for RunCommand, EditLocalFile, ReadLocalFile, WriteLocalFile, ListLocalFiles, GlobLocalFiles, GrepContent
    • Shared FilePathDisplay component and inspector styles
    • Cloud-sandbox renders now reuse local-system renders for all overlapping tools
  3. State types unified — Flat state types (RunCommandState, GlobFilesState, etc.) defined once in @lobechat/tool-runtime, re-exported by each package

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

Verified via:

  • Type-check passes (bun run type-check)
  • Unit tests pass (local-system: 55 tests, prompts: 71 tests)
  • Electron desktop app tested with both Local and Cloud Sandbox modes — runCommand tool renders correctly in both environments with consistent formatting

📝 Additional Information

Breaking changes: State shape for local-system inspector components changed from nested (pluginState.result.output) to flat (pluginState.output). This only affects the internal tool rendering — no public API changes.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 2, 2026 2:33am

Request Review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@lobehubbot
Copy link
Copy Markdown
Member

@canisminor1990 @ONLY-yours - This refactor unifies tool content formatting with new @lobechat/tool-runtime and @lobechat/shared-tool-ui packages. Involves shared Inspector/Render UI components and execution runtime abstraction across cloud-sandbox, local-system, and skills packages. Please coordinate review.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 62.50000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.48%. Comparing base (df6d8f1) to head (46aec37).
⚠️ Report is 13 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13470      +/-   ##
==========================================
- Coverage   66.48%   66.48%   -0.01%     
==========================================
  Files        1972     1973       +1     
  Lines      160184   160229      +45     
  Branches    18340    18342       +2     
==========================================
+ Hits       106504   106530      +26     
- Misses      53560    53579      +19     
  Partials      120      120              
Flag Coverage Δ
app 58.32% <72.09%> (+<0.01%) ⬆️
database 96.66% <ø> (ø)
packages/agent-runtime 88.98% <ø> (ø)
packages/context-engine 86.51% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 66.68% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.67% <ø> (ø)
packages/prompts 66.84% <30.76%> (-0.24%) ⬇️
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.41% <ø> (ø)
packages/web-crawler 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 66.66% <ø> (ø)
Services 49.27% <ø> (ø)
Server 66.35% <ø> (+<0.01%) ⬆️
Libs 51.03% <ø> (ø)
Utils 89.08% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 049e6144e4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

arvinxx and others added 2 commits April 1, 2026 23:39
…hared UI components

Introduce `@lobechat/tool-runtime` with `ComputerRuntime` abstract class to ensure consistent
content formatting (via `formatCommandResult`, `formatFileContent`, etc.) across local-system,
cloud-sandbox, and skills packages. Create `@lobechat/shared-tool-ui` to share Render and
Inspector components, eliminating duplicated UI code across tool packages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…m denormalization

- Add legacy state field mappings in local-system executor (listResults, fileContent,
  searchResults) for backward compatibility with existing render components
- Add denormalizeParams in LocalSystemExecutionRuntime to map ComputerRuntime params
  back to IPC-expected field names (file_path, items, shell_id, etc.)
- Fix i18n type casting for dynamic translation keys in shared-tool-ui inspectors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e for cross-package render reuse

- Add ToolRenderContext with injectable capabilities (openFile, openFolder,
  isLoading, displayRelativePath) to shared-tool-ui
- Update local-system render components (ReadLocalFile, ListFiles, SearchFiles,
  MoveLocalFiles, FileItem) to use context instead of direct Electron imports
- Enrich ReadFileState with render-compatible fields (filename, fileType,
  charCount, loc, totalCharCount)
- Cloud-sandbox now fully reuses local-system renders — renders degrade
  gracefully when capabilities are not provided (no open file buttons in sandbox)
- Remove executor-level state mapping hacks

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
arvinxx and others added 2 commits April 2, 2026 01:09
… GlobFiles

- SearchFiles: ensure results is always an array (not object passthrough)
- GrepContent: update formatGrepResults to support object matches
  `{path, content, lineNumber}` alongside string matches
- MoveFiles: render now handles both IPC format (items/oldPath/newPath) and
  ComputerRuntime format (operations/source/destination)
- GlobFiles: fallback totalCount to files.length when API returns 0

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SearchLocalFiles inspector now supports all keyword field variants
(keyword, keywords, query) and reads from unified state (results/totalCount).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
arvinxx and others added 2 commits April 2, 2026 10:19
- EditLocalFile render: support both file_path (IPC) and path (sandbox) args
- SearchFiles render: support keyword/keywords/query arg variants
- FileItem: derive name from path when not provided

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🚀 Desktop App Build Completed!

Version: 0.0.0-nightly.pr13470.7694
Build Time: 2026-04-02T04:09:48.299Z

📦 Release Download · 📥 Actions Artifacts

Build Artifacts

Platform File Size
macOS (Apple Silicon) LobeHub-Nightly-0.0.0-nightly.pr13470.7694-arm64-mac.zip 138.26 MB
macOS (Apple Silicon) LobeHub-Nightly-0.0.0-nightly.pr13470.7694-arm64.dmg 133.00 MB
macOS (Intel) LobeHub-Nightly-0.0.0-nightly.pr13470.7694-mac.zip 146.54 MB
macOS (Intel) LobeHub-Nightly-0.0.0-nightly.pr13470.7694-x64.dmg 139.81 MB
Windows LobeHub-Nightly-0.0.0-nightly.pr13470.7694-setup.exe 126.56 MB
Linux LobeHub-Nightly-0.0.0-nightly.pr13470.7694.AppImage 154.59 MB

Warning

Note: This is a temporary build for testing purposes only.

@arvinxx arvinxx merged commit be99aae into canary Apr 2, 2026
45 checks passed
@arvinxx arvinxx deleted the fix/tool-content-display branch April 2, 2026 11:42
@lobehubbot
Copy link
Copy Markdown
Member

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

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

Labels

trigger:build-desktop Trigger Desktop build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants