Fix type#1242
Conversation
📝 WalkthroughWalkthroughThis PR refactors error logging across MCP packages and strengthens type safety for event handlers in the Ink UI framework. It introduces a structured ChangesLogger Detail Typing and Event Handler Type Safety
🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/utils/claudeInChrome/mcpServer.ts (1)
280-294: ⚡ Quick winConsider 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 winConsider 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 valueConsider moving the import to the top of the file.
The
EventHandlerPropsimport appears after theTerminalEventclass 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
📒 Files selected for processing (14)
packages/@ant/claude-for-chrome-mcp/src/bridgeClient.tspackages/@ant/claude-for-chrome-mcp/src/index.tspackages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.tspackages/@ant/claude-for-chrome-mcp/src/toolCalls.tspackages/@ant/claude-for-chrome-mcp/src/types.tspackages/@ant/computer-use-mcp/src/pixelCompare.tspackages/@ant/computer-use-mcp/src/toolCalls.tspackages/@ant/computer-use-mcp/src/types.tspackages/@ant/ink/src/core/dom.tspackages/@ant/ink/src/core/events/terminal-event.tspackages/@ant/ink/src/core/reconciler.tssrc/utils/auth.tssrc/utils/claudeInChrome/mcpServer.tssrc/utils/computerUse/hostAdapter.ts
1.修复claude-for-chrome-mcp中的type和interface类型缺失。
2.完善注释。
Summary by CodeRabbit
Release Notes
New Features
Refactor
Documentation