argent-metro-debugger

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

1. Prerequisites

1. 前提条件

The debugger requires Metro dev server running (default
localhost:8081
) and a React Native app connected to Metro (at least one CDP target). Verify via
debugger-status
.
调试器要求Metro开发服务器处于运行状态(默认地址为
localhost:8081
),且React Native应用已连接到Metro(至少存在一个CDP目标)。可通过
debugger-status
命令验证连接状态。

Android: reverse port for Metro

Android:为Metro反向端口映射

Android emulators and physical devices do not resolve the host's
localhost
by default. Before the RN app can reach Metro, forward port 8081 (or whichever port Metro is on) from the device back to the host:
bash
adb -s <serial> reverse tcp:8081 tcp:8081
<serial>
is the Android
serial
from
list-devices
. Once reversed, the app on the device connects to Metro just like an iOS simulator does, and all
debugger-*
/
network-*
/
react-profiler-*
tools work unchanged. If the device restarts or adb drops, re-run the command. A failing Metro connection on Android almost always means
adb reverse
has not been done or has been lost.
Android模拟器和物理设备默认无法解析主机的
localhost
地址。在RN应用能够连接Metro之前,需将设备的8081端口(或Metro使用的其他端口)反向映射到主机:
bash
adb -s <serial> reverse tcp:8081 tcp:8081
<serial>
list-devices
命令返回的Android设备序列号。完成反向映射后,设备上的应用即可像iOS模拟器一样连接Metro,所有
debugger-*
/
network-*
/
react-profiler-*
工具均可正常使用。若设备重启或adb连接中断,需重新运行该命令。Android设备无法连接Metro的问题几乎都是因为未执行或丢失了
adb reverse
配置。

2. Tool Overview

2. 工具概述

All tools accept
port
(default 8081) AND
device_id
(the iOS Simulator UDID or Android serial, a.k.a.
logicalDeviceId
— the CDP-reported id that matches the device). Always make sure you target the correct app on the correct device.
One Metro port can serve multiple connected devices (e.g. two simulators on
localhost:8081
, or an iOS simulator alongside an Android emulator with
adb reverse
set up).
device_id
pins every debugger/network/profiler call to a specific device so sessions do not collide.
所有工具均支持
port
(默认8081)和
device_id
参数(iOS模拟器UDID或Android序列号,即CDP报告的
logicalDeviceId
,与设备匹配的标识)。请始终确保目标为正确设备上的正确应用。
单个Metro端口可服务多个已连接设备(例如,两个模拟器连接到
localhost:8081
,或iOS模拟器与已配置
adb reverse
的Android模拟器同时连接)。
device_id
可将所有调试器/网络/性能分析器的调用绑定到特定设备,避免会话冲突。

Connect & diagnostics

连接与诊断

ToolPurpose
debugger-connect
Connect to Metro CDP. Returns port, projectRoot, deviceName, appName,
logicalDeviceId
, isNewDebugger, connected. The returned
logicalDeviceId
is the
device_id
for every subsequent debugger/network/profiler call.
debugger-status
Like connect + loadedScripts, enabledDomains, sourceMapReady. Use to diagnose.
工具用途
debugger-connect
连接到Metro CDP。返回端口、项目根目录、设备名称、应用名称、
logicalDeviceId
、是否为新调试器、连接状态。返回的
logicalDeviceId
将作为后续所有调试器/网络/性能分析器调用的
device_id
debugger-status
功能类似connect,额外返回已加载脚本、启用的域、源映射就绪状态。用于诊断问题。

Reload & recovery

重载与恢复

ToolPurpose
debugger-reload-metro
Reload all connected apps (like pressing "r" in Metro terminal). Needs a CDP target.
restart-app
Terminate and relaunch the app by device id and bundleId. Use when app lost Metro connection.
工具用途
debugger-reload-metro
重载所有已连接的应用(类似在Metro终端中按"r"键)。需要存在CDP目标。
restart-app
根据设备ID和bundleId终止并重新启动应用。适用于应用丢失Metro连接的场景。

Inspection & console

检查与控制台

ToolPurpose
debugger-component-tree
Full React fiber tree (names, depth, bounding rects, tap coordinates).
debugger-inspect-element
Inspect at (x, y) using logical pixel coordinates (not normalized 0-1): component hierarchy with source file:line and code fragment. See
references/source-maps.md
.
debugger-log-registry
Get log summary (counts, clusters, file path). Then use
Grep
/
Read
on the flat log file for details.
debugger-evaluate
Run a JS expression in the app runtime.

工具用途
debugger-component-tree
获取完整的React Fiber树(包含组件名称、层级、边界矩形、点击坐标)。
debugger-inspect-element
使用逻辑像素坐标(非归一化0-1范围)在(x, y)位置检查元素:返回组件层级结构及对应的源文件:行号和代码片段。详情请参考
references/source-maps.md
debugger-log-registry
获取日志摘要(数量、聚类、文件路径)。随后可对扁平化日志文件使用
Grep
/
Read
命令查看详情。
debugger-evaluate
在应用运行时执行JS表达式。

3. Component Inspection

3. 组件检查

debugger-component-tree
vs
debugger-inspect-element

debugger-component-tree
vs
debugger-inspect-element

debugger-component-tree
debugger-inspect-element
Best forLayout overview; finding tap targets; user-defined component hierarchyIdentifying a visible element and tracing it to its source file
Use when"What's on screen and where?""What component is this and where is it defined?"
Both can point to source files, but
inspect-element
is purpose-built for source tracing.
component-tree
is for orientation and tap-target discovery.
debugger-component-tree
debugger-inspect-element
适用场景布局概览、查找点击目标、用户自定义组件层级分析识别可见元素并追踪到其源文件
使用时机需了解“屏幕上有什么,位置在哪里?”时需了解“这是什么组件,定义在哪里?”时
两者均可指向源文件,但
inspect-element
专为源文件追踪设计。
component-tree
则用于定位方向和发现点击目标。

includeSkipped
guidance

includeSkipped
参数指南

Applies to both
debugger-component-tree
and
debugger-inspect-element
. Set to
true
only when debugging filter behavior — e.g., an expected component is missing from output, or you need to inspect a very specific branch of the tree (not just an overview).
Warning: Output can be very large. Always combine with
maxNodes
(component-tree) or
maxItems
(inspect-element) and increase it incrementally (e.g., start at 50, then grow). Do not use
includeSkipped
without a limit on large apps.

该参数适用于
debugger-component-tree
debugger-inspect-element
。仅在调试过滤行为时设置为
true
——例如,预期的组件未出现在输出中,或需要检查树的某个特定分支(而非仅概览)。
警告: 输出内容可能非常庞大。请始终结合
maxNodes
(component-tree)或
maxItems
(inspect-element)参数使用,并逐步增加数值(例如,从50开始,再逐步增大)。在大型应用中,请勿在未设置限制的情况下使用
includeSkipped

4. Golden Rules

4. 黄金准则

  1. debugger-status
    first when something fails
    — it runs discovery, connection, and returns diagnostics.
  2. "No CDP targets" → get the app to connect to Metro — use
    restart-app
    on the device, then retry
    debugger-status
    .
  3. Never assume one failure is permanent — follow recovery steps before asking the user. For starting Metro and full failure recovery, see
    argent-react-native-app-workflow
    and
    references/failure-scenarios.md
    .

  1. 出现问题时首先使用
    debugger-status
    —— 该命令会执行发现、连接操作并返回诊断信息。
  2. 提示“无CDP目标” → 让应用连接到Metro —— 在设备上使用
    restart-app
    命令,然后重试
    debugger-status
  3. 永远不要假设一次失败是永久性的 —— 在询问用户之前先执行恢复步骤。关于启动Metro和完整故障恢复的内容,请参考
    argent-react-native-app-workflow
    references/failure-scenarios.md

5. Reading Console Logs (Log Registry)

5. 读取控制台日志(日志注册表)

Logs are written to a flat log file on disk. Use the log-registry → grep pattern instead of reading logs inline.
日志会写入磁盘上的扁平化日志文件。请使用日志注册表 → grep的模式,而非直接读取日志内容。

Workflow

工作流程

  1. Call
    debugger-log-registry
    — returns:
    file
    (log path),
    totalEntries
    ,
    byLevel
    ,
    clusters
    (top message groups with counts and source file info)
  2. Search the file using
    Grep
    or
    Read
    with patterns from the response.
Large log files: If
totalEntries
exceeds 10 000, delegate the grep exploration to an
Explore
subagent — pass it the file path, the entry format, and the patterns you need.
  1. 调用
    debugger-log-registry
    —— 返回:
    file
    (日志路径)、
    totalEntries
    (总条目数)、
    byLevel
    (按级别统计)、
    clusters
    (顶级消息分组,包含数量和源文件信息)
  2. 搜索文件 —— 使用
    Grep
    Read
    命令,结合返回结果中的模式进行搜索。
大型日志文件:
totalEntries
超过10000条,可将grep探索任务委托给
Explore
子代理——传递文件路径、条目格式和所需的搜索模式。

Flat log format

扁平化日志格式

One entry per line — fields (whitespace-separated,
|
delimiter before message)
FieldExampleNotes
[L:<id>]
[L:42]
Unique grep anchor
<timestamp>
2026-03-17T14:30:00.000Z
ISO 8601
<LEVEL>
ERROR
,
WARN 
,
LOG  
Uppercase, padded to 5 chars
<source>
src/api/user.ts:42
or
-
Relative path from source map;
-
if unavailable
<message>
Failed login attempt
Full message; embedded newlines replaced with space
Source attribution (file + line) is also available in
clusters
returned by
debugger-log-registry
.
Log files and messages can be large - Always scope your search, treat the file like a database, not a document.
When reading from the log file:
  • Never
    Read
    the log file directly. Use
    grep
    or shell commands with limits using the above file format tips.
  • Default to
    -m 50
    unless you need more.
  • Use
    tail -N
    recent entries.
  • clusters[].message
    gives you the exact text which you may look for
If the file is too large Delegate to an
Explore
subagent with the file path, the format spec above, and the specific patterns you need.

每行一条日志条目——字段(空格分隔,消息前使用
|
作为分隔符)
字段示例说明
[L:<id>]
[L:42]
唯一的grep锚点
<timestamp>
2026-03-17T14:30:00.000Z
ISO 8601格式
<LEVEL>
ERROR
,
WARN 
,
LOG  
大写,填充至5个字符
<source>
src/api/user.ts:42
or
-
源映射中的相对路径;若不可用则显示
-
<message>
Failed login attempt
完整消息;嵌入的换行符将替换为空格
源文件归属(文件+行号)也可在
debugger-log-registry
返回的
clusters
中查看。
日志文件和消息可能很大——请始终限定搜索范围,将文件视为数据库而非文档。
读取日志文件时:
  • 不要直接
    Read
    日志文件。使用grep或带限制的shell命令,并结合上述文件格式提示。
  • 默认使用
    -m 50
    参数,除非需要更多结果。
  • 使用
    tail -N
    查看最近的N条条目。
  • clusters[].message
    提供了可用于搜索的精确文本
若文件过大 将任务委托给
Explore
子代理,传递文件路径、上述格式规范和特定的搜索模式。

Quick Reference

快速参考

ActionTool
Diagnose / check connection
debugger-status
Connect to Metro CDP
debugger-connect
Reload JS (already connected)
debugger-reload-metro
Relaunch app on device
restart-app
Inspect component at point
debugger-inspect-element
Full component tree
debugger-component-tree
Console log overview
debugger-log-registry
(summary + log file path for
Grep
/
Read
)
Evaluate JS
debugger-evaluate
操作工具
诊断/检查连接状态
debugger-status
连接到Metro CDP
debugger-connect
重载JS(已连接状态下)
debugger-reload-metro
在设备上重新启动应用
restart-app
检查指定位置的组件
debugger-inspect-element
获取完整组件树
debugger-component-tree
控制台日志概览
debugger-log-registry
(返回摘要+日志文件路径,用于
Grep
/
Read
执行JS代码
debugger-evaluate