Skip to content

Fix type#1242

Merged
claude-code-best merged 6 commits into
claude-code-best:mainfrom
xiaoFjun-eng:fixType
May 19, 2026
Merged

Fix type#1242
claude-code-best merged 6 commits into
claude-code-best:mainfrom
xiaoFjun-eng:fixType

Conversation

@xiaoFjun-eng
Copy link
Copy Markdown
Contributor

@xiaoFjun-eng xiaoFjun-eng commented May 19, 2026

1.修复claude-for-chrome-mcp中的type和interface类型缺失。
2.完善注释。

Summary by CodeRabbit

Release Notes

  • New Features

    • Added structured error logging with improved diagnostics across logging calls.
    • Introduced typed metadata for bridge telemetry events.
  • Refactor

    • Enhanced logger interface with stronger type safety for error details.
    • Improved event handler type definitions for better compile-time checking.
  • Documentation

    • Updated inline comments for clarity.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

This PR refactors error logging across MCP packages and strengthens type safety for event handlers in the Ink UI framework. It introduces a structured LoggerDetail type (narrowing to Error | NodeJS.ErrnoException), exports a toLoggerDetail() helper function, and updates the Logger interface to accept typed optional detail instead of variadic arguments. All error logging sites in Chrome MCP, Computer Use MCP, and adapter code are updated to use the new helper. Additionally, event handler field types in Ink are tightened from generic records to structured EventHandlerProps shapes.

Changes

Logger Detail Typing and Event Handler Type Safety

Layer / File(s) Summary
Logger Detail type contract and helper function
packages/@ant/claude-for-chrome-mcp/src/types.ts, packages/@ant/claude-for-chrome-mcp/src/index.ts, packages/@ant/computer-use-mcp/src/types.ts
Introduces LoggerDetail as Error | NodeJS.ErrnoException, adds toLoggerDetail() helper to safely narrow unknown error values, and updates Logger interface methods from variadic (...args: unknown[]) to typed optional (message: string, detail?: LoggerDetail). Also introduces bridge telemetry metadata types for structured event tracking.
Chrome MCP error logging integration
packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts, packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts, packages/@ant/claude-for-chrome-mcp/src/toolCalls.ts
WebSocket creation, message parsing, socket error events, tool call errors, and bridge result validation logging all use toLoggerDetail() for consistent structured error output.
Computer Use MCP error logging integration
packages/@ant/computer-use-mcp/src/pixelCompare.ts, packages/@ant/computer-use-mcp/src/toolCalls.ts
Pixel validation errors and tool handler exceptions are logged using toLoggerDetail() for structured detail.
Logger adapter implementations
src/utils/claudeInChrome/mcpServer.ts, src/utils/computerUse/hostAdapter.ts
DebugLogger implementations adapt from variadic arguments to typed optional LoggerDetail parameter, updating format calls accordingly.
Event handler type safety in Ink
packages/@ant/ink/src/core/dom.ts, packages/@ant/ink/src/core/events/terminal-event.ts, packages/@ant/ink/src/core/reconciler.ts
Event handler fields (_eventHandlers) change from generic Record<string, unknown> to structured Partial<EventHandlerProps>. Internal setEventHandler helper becomes generic and type-constrained to EventHandlerProps keys and values.
Comment localization
src/utils/auth.ts
Inline comment in getAccountInformation() rewritten in Chinese.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Suggested Reviewers

  • KonghaYao

🐰 A logging leap of faith, where errors find their shape,
and handlers bind with types to save the scape,
from wild unknowns to structured rest,
this code review puts safety to the test!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Fix type" is extremely vague and does not clearly describe the main changes in the pull request, which involve restructuring logger interfaces, adding new type definitions, and improving type safety across multiple packages. Consider using a more descriptive title such as "Restructure logger interface and add bridge telemetry types" or "Refactor logger to use structured LoggerDetail type" to better communicate the primary changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/utils/claudeInChrome/mcpServer.ts (1)

280-294: ⚡ Quick win

Consider preserving Error stack traces in log output.

The current implementation passes Error objects directly to util.format(), which converts them to "Error: message" strings without including stack traces. For a debugging logger, stack traces provide valuable context when errors occur.

📝 Proposed enhancement to include stack traces
 class DebugLogger implements Logger {
   silly(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'debug' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'debug' })
   }
   debug(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'debug' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'debug' })
   }
   info(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'info' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'info' })
   }
   warn(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'warn' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'warn' })
   }
   error(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'error' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'error' })
   }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/claudeInChrome/mcpServer.ts` around lines 280 - 294, The logger
methods silly, debug, info, warn, and error call format(message, detail) which
drops Error stacks; update each of these methods in mcpServer.ts to detect when
detail is an Error (instanceof Error) and pass the error's stack (or
`${error.name}: ${error.message}\n${error.stack}`) into logForDebugging instead
of the Error object so stack traces are preserved in logs while non-Error detail
values continue to be formatted as before.
src/utils/computerUse/hostAdapter.ts (1)

14-28: ⚡ Quick win

Consider preserving Error stack traces in log output.

The current implementation passes Error objects directly to util.format(), which converts them to "Error: message" strings without including stack traces. For a debugging logger, stack traces provide valuable context when errors occur.

📝 Proposed enhancement to include stack traces
 class DebugLogger implements Logger {
   silly(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'debug' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'debug' })
   }
   debug(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'debug' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'debug' })
   }
   info(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'info' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'info' })
   }
   warn(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'warn' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'warn' })
   }
   error(message: string, detail?: LoggerDetail): void {
-    logForDebugging(format(message, detail ?? ''), { level: 'error' })
+    const formatted = detail instanceof Error 
+      ? format(message, detail.stack ?? detail.message)
+      : format(message, detail ?? '')
+    logForDebugging(formatted, { level: 'error' })
   }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/computerUse/hostAdapter.ts` around lines 14 - 28, The logging
helpers (silly, debug, info, warn, error) currently call format(message, detail
?? '') which loses Error stacks; update each to detect when detail is an Error
(or contains an Error) and pass the error.stack (or error.toString() + '\n' +
stack) into format or append it to the formatted message before calling
logForDebugging; use the same symbols present (silly/debug/info/warn/error,
format, logForDebugging, LoggerDetail) so stack traces are preserved in the log
output.
packages/@ant/ink/src/core/events/terminal-event.ts (1)

104-104: 💤 Low value

Consider moving the import to the top of the file.

The EventHandlerProps import appears after the TerminalEvent class definition. While valid for type-only imports, conventional practice places all imports at the top of the file for consistency and readability.

📦 Proposed refactor to move import to top

Move the import from line 104 to the import section at the top of the file (after line 1):

 import { Event } from './event.js'
+import type { EventHandlerProps } from './event-handlers.js'

Then remove it from line 104.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/`@ant/ink/src/core/events/terminal-event.ts at line 104, Move the
type-only import "EventHandlerProps" up into the main import block at the top of
the file so all imports are grouped consistently (instead of the current import
after the TerminalEvent class); update references to EventHandlerProps remain
unchanged and remove the trailing import statement at line 104 to avoid a late
import and keep imports consistently at the top of the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/`@ant/ink/src/core/events/terminal-event.ts:
- Line 104: Move the type-only import "EventHandlerProps" up into the main
import block at the top of the file so all imports are grouped consistently
(instead of the current import after the TerminalEvent class); update references
to EventHandlerProps remain unchanged and remove the trailing import statement
at line 104 to avoid a late import and keep imports consistently at the top of
the file.

In `@src/utils/claudeInChrome/mcpServer.ts`:
- Around line 280-294: The logger methods silly, debug, info, warn, and error
call format(message, detail) which drops Error stacks; update each of these
methods in mcpServer.ts to detect when detail is an Error (instanceof Error) and
pass the error's stack (or `${error.name}: ${error.message}\n${error.stack}`)
into logForDebugging instead of the Error object so stack traces are preserved
in logs while non-Error detail values continue to be formatted as before.

In `@src/utils/computerUse/hostAdapter.ts`:
- Around line 14-28: The logging helpers (silly, debug, info, warn, error)
currently call format(message, detail ?? '') which loses Error stacks; update
each to detect when detail is an Error (or contains an Error) and pass the
error.stack (or error.toString() + '\n' + stack) into format or append it to the
formatted message before calling logForDebugging; use the same symbols present
(silly/debug/info/warn/error, format, logForDebugging, LoggerDetail) so stack
traces are preserved in the log output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d2215a05-0a97-4b6b-a856-300f9c613c78

📥 Commits

Reviewing files that changed from the base of the PR and between ea399f1 and a26b07b.

📒 Files selected for processing (14)
  • packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts
  • packages/@ant/claude-for-chrome-mcp/src/index.ts
  • packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts
  • packages/@ant/claude-for-chrome-mcp/src/toolCalls.ts
  • packages/@ant/claude-for-chrome-mcp/src/types.ts
  • packages/@ant/computer-use-mcp/src/pixelCompare.ts
  • packages/@ant/computer-use-mcp/src/toolCalls.ts
  • packages/@ant/computer-use-mcp/src/types.ts
  • packages/@ant/ink/src/core/dom.ts
  • packages/@ant/ink/src/core/events/terminal-event.ts
  • packages/@ant/ink/src/core/reconciler.ts
  • src/utils/auth.ts
  • src/utils/claudeInChrome/mcpServer.ts
  • src/utils/computerUse/hostAdapter.ts

@claude-code-best claude-code-best merged commit 27b665a into claude-code-best:main May 19, 2026
4 checks passed
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