melech-debug-mode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDebug Mode
调试模式
Treat the current task as an active debugging session. Diagnose from runtime
evidence before proposing a fix.
For the intended first-use, reproduction, iteration, verification, and later-use
experience, read DEVELOPER_JOURNEY_EXAMPLE.md
and use it as the interaction model. For autopilot attach, read
LIVE_BROWSER.md when that mode starts. Chrome
setup is the official M144 auto-connect flow in
CHROME_DEVTOOLS_MCP.md.
将当前任务视为一个活跃的调试会话。在提出修复方案前,先从运行时证据入手进行诊断。
关于首次使用、复现、迭代、验证及后续使用流程,请阅读DEVELOPER_JOURNEY_EXAMPLE.md并将其作为交互模型参考。若使用自动驾驶模式,请在模式启动时阅读LIVE_BROWSER.md。Chrome配置遵循CHROME_DEVTOOLS_MCP.md中官方的M144自动连接流程。
Guardrails
防护规则
- Keep the collector local. Do not enable Portless ,
--tailscale,--funnel, LAN mode, or any other remote exposure.--ngrok - Never collect credentials, tokens, cookies, authorization headers, personal data, full request bodies, or unrelated application state. Prefer booleans, counts, IDs already safe for development, enum values, and narrow summaries.
- Add the fewest probes that distinguish the current hypotheses. Start with at most five unless the control flow genuinely requires more.
- Make probes non-blocking and failure-isolated so collector failure cannot alter product behavior.
- Mark every temporary edit with and keep a list of touched files for cleanup.
DEBUG_MODE:<session-id>:<probe-id> - Do not fix the bug before the evidence identifies a cause, unless the user explicitly asks to skip diagnosis.
- Stop only this session. Never run ,
portless proxy stop, or broad process-kill commands.portless clean - When driving Chrome, attach only. Never cookies or tokens, never collect credentials from the page, never quit the user's Chrome, and never close tabs you did not open. Do not tunnel CDP through Portless or any remote exposure.
state save
- 保持采集器本地运行。请勿启用Portless的、
--tailscale、--funnel参数、LAN模式或任何其他远程暴露方式。--ngrok - 绝不收集凭证、令牌、Cookie、授权头、个人数据、完整请求体或无关的应用状态。优先使用布尔值、计数、已确保安全的开发环境ID、枚举值和精简摘要。
- 仅添加能验证当前假设的最少探针。除非控制流确实需要,否则初始最多添加5个探针。
- 确保探针是非阻塞且故障隔离的,避免采集器故障影响产品行为。
- 所有临时编辑都标记为,并记录所有修改过的文件以便后续清理。
DEBUG_MODE:<session-id>:<probe-id> - 在证据明确根因前,请勿修复bug,除非用户明确要求跳过诊断步骤。
- 仅停止当前会话。绝不要执行、
portless proxy stop或大范围进程终止命令。portless clean - 操控Chrome时仅进行附加操作。绝不使用保存Cookie或令牌,绝不从页面收集凭证,绝不关闭用户的Chrome,绝不关闭非你打开的标签页。请勿通过Portless或任何远程暴露方式隧道传输CDP。
state save
Start A Session
启动会话
-
Inspect the failing path, current logs, and relevant tests. State one to three concrete hypotheses and what observation would distinguish them.
-
Locate this installed skill directory and confirm bothand
python3are available. If Portless is missing, stop and tell the user to install the official Vercel Labs CLI withportless. Do not silently substitute another tunnel or server.npm install -g portless -
Source the bundled command once so the shortverb is available for the rest of this session (the shell keeps it across later calls):
dmbashsource <skill-dir>/scripts/dm.shEvery launcher call below uses, which is identical todm. Ifpython3 <skill-dir>/scripts/debug_session.pyis ever undefined in a later step (fresh shell), re-sourcedmor fall back to the full path.dm.sh -
If this machine has not used Portless before, run. Follow its local trust/setup guidance before starting the background session.
portless doctor -
Start the bundled collector:bash
dm startSave the returned,session_dir,session_id,log_endpoint, andevents_file. The launcher copies the lean server skeleton into a new temporary directory. Portless assigns a different free backend port and a unique local route for every session.backend_port -
Verify the returnedbefore editing application code.
health_url
-
检查失败路径、当前日志及相关测试。提出1-3个具体假设,以及能验证这些假设的观测结果。
-
找到已安装的skill目录,确认和
python3可用。若缺少Portless,请停止操作并告知用户通过portless安装官方Vercel Labs CLI。请勿静默替换为其他隧道或服务器。npm install -g portless -
一次性加载捆绑命令,以便在后续会话中使用简短的命令(shell会在后续调用中保留该命令):
dmbashsource <skill-dir>/scripts/dm.sh以下所有启动器调用均使用,其功能与dm完全一致。若后续步骤中python3 <skill-dir>/scripts/debug_session.py未定义(如新开shell),请重新加载dm或使用完整路径调用。dm.sh -
若该机器从未使用过Portless,请运行。遵循其本地信任/设置指引后再启动后台会话。
portless doctor -
启动捆绑的采集器:bash
dm start保存返回的、session_dir、session_id、log_endpoint和events_file。启动器会将精简的服务器框架复制到新的临时目录。Portless会为每个会话分配不同的空闲后端端口和唯一的本地路由。backend_port -
在修改应用代码前,验证返回的是否可用。
health_url
Add Dynamic Request Probes
添加动态请求探针
Place probes only where they can confirm or eliminate a hypothesis: branch
entries, values immediately before a transformation, boundary inputs/outputs,
and error paths. Give each a stable descriptive ID.
POST a small JSON object to the session's :
log_endpointjson
{
"run": "run-1",
"probe": "checkout-before-submit",
"hypothesis": "disabled state is stale",
"data": {
"isDisabled": true,
"itemCount": 2
}
}For browser JavaScript, use a fire-and-forget request and swallow collector
errors locally:
js
// DEBUG_MODE:<session-id>:checkout-before-submit
void fetch("<log-endpoint>", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
run: "run-1",
probe: "checkout-before-submit",
hypothesis: "disabled state is stale",
data: { isDisabled, itemCount: items.length },
}),
}).catch(() => {});Adapt the request idiom to the target language. Preserve the same payload
shape, marker, narrow data selection, and failure isolation. Do not log whole
objects when a few fields answer the question.
Run the cheapest compile, type, or syntax check needed to ensure the temporary
instrumentation itself did not break the workflow.
仅在能确认或排除假设的位置放置探针:分支入口、转换前的数值、边界输入/输出及错误路径。为每个探针分配一个稳定的描述性ID。
向会话的发送一个小型JSON对象:
log_endpointjson
{
"run": "run-1",
"probe": "checkout-before-submit",
"hypothesis": "disabled state is stale",
"data": {
"isDisabled": true,
"itemCount": 2
}
}对于浏览器JavaScript,使用即发即弃请求并在本地捕获采集器错误:
js
// DEBUG_MODE:<session-id>:checkout-before-submit
void fetch("<log-endpoint>", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
run: "run-1",
probe: "checkout-before-submit",
hypothesis: "disabled state is stale",
data: { isDisabled, itemCount: items.length },
}),
}).catch(() => {});根据目标语言调整请求方式。保留相同的负载结构、标记、精简数据选择和故障隔离机制。仅在少数字段能回答问题时,才记录完整对象。
执行最低成本的编译、类型检查或语法检查,确保临时 instrumentation 本身不会破坏工作流程。
Pick A Reproduction Mode
选择复现模式
Same collector and probes either way. Only who drives the repro changes.
- Manual — the user holds the wheel. You instrument, tell them the exact
clicks, then stop until they reply .
proceed - Autopilot — you drive their already-open Chrome end-to-end with
Chrome DevTools MCP (same tabs, same logins). They only enable remote debugging and click Allow. If this host is missing that MCP, you write the official config with
--autoConnectand wait for a reload so the host can start the server.dm mcp-setup
Choose once, then announce it in the user-facing message:
- User said they will reproduce, hold the wheel, or reply → manual.
proceed - User said autopilot, drive my browser, already logged in, or do it for me → autopilot.
- UI bug and they did not pick → announce both modes in one short message
and wait. Do not attach and do not hand them a script until they answer.
proceed - Not a UI bug, or the tab looks like production you should not touch → manual.
Never silently attach. Before any Chrome DevTools MCP call, tell the user
they are in autopilot and what they must do in Chrome.
无论选择哪种模式,采集器和探针保持不变,仅复现的操控者不同。
- 手动模式 — 用户操控。你负责 instrumentation,告知用户具体的点击操作,然后等待用户回复后再继续。
proceed - 自动驾驶模式 — 你通过Chrome DevTools MCP 功能全程操控用户已打开的Chrome(保留相同标签页和登录状态)。用户仅需启用远程调试并点击“允许”。若当前主机缺少该MCP,你可通过
--autoConnect写入官方配置,等待重载后主机即可启动服务器。dm mcp-setup
选择模式后,在面向用户的消息中明确告知:
- 用户表示将自行复现、操控或回复→ 手动模式。
proceed - 用户要求自动驾驶、操控浏览器、已登录或代其操作 → 自动驾驶模式。
- UI bug且用户未选择模式 → 在一条简短消息中说明两种模式并等待回复。在用户答复前,请勿附加会话或提供脚本。
proceed - 非UI bug,或标签页为生产环境不应触碰 → 手动模式。
绝不要静默附加会话。在执行任何Chrome DevTools MCP调用前,告知用户当前处于自动驾驶模式及他们需在Chrome中执行的操作。
Autopilot
自动驾驶模式
Keep probes in place. Snapshots are extra evidence, not a substitute for
. Read LIVE_BROWSER.md and
CHROME_DEVTOOLS_MCP.md.
dm logs-
Check whether Chrome DevTools MCP tools are already available in this session. Then run the bundled setup (idempotent):bash
dm mcp-setupThat inspects known host MCP configs, writes the officialentry when it is missing, and prefetches the npm package. It does not inject tools into a live host; the host still has to spawn the server.chrome-devtools-mcp@latest --autoConnect- Tools already present and → continue.
ready: true - → tell the user to reload the
reload_required: trueMCP server (or restart the host), then wait. Do not attach to a profile that is missingchrome-devtools.--autoConnect - → show the official snippet from the command output and switch to Manual unless they want the
ready: falsefallback.dm browser-check
Do not silently switch to Playwright, Puppeteer, a fresh empty Chrome, a cloud browser, or a custom extension. - Tools already present and
-
Before the first MCP call, tell the user verbatim:Autopilot is on. I will drive the tab you already have open.
One-time: open chrome://inspect/#remote-debugging and enable Allow remote debugging for this browser instance (Chrome 144+).
When Chrome prompts, click Allow. A “controlled by automated test software” banner is expected. I will not quit Chrome or close other tabs.Then wait only if they have not confirmed they can click Allow. If they already said to go, list pages and keep those steps visible. -
Discover pages through Chrome DevTools MCP. Select the existing app tab. Do not open a new URL unless the repro needs a fresh navigation. Do not close Chrome or other tabs. Do not close the last tab.
-
Snapshot, then drive the workflow with click / fill / type on snapshot uids. If they already selected a node in the Elements panel or a request in the Network panel, start there.
-
If attach fails, print the inspect-page + Allow steps and switch to Manual. Useonly when this host has no Chrome DevTools MCP at all.
dm browser-check -
After one reproduction attempt, readthe same as on
dm logs. Do not claim a reproduction from a snapshot alone.proceed
保留探针位置。快照是额外证据,不能替代。请阅读LIVE_BROWSER.md和CHROME_DEVTOOLS_MCP.md。
dm logs-
检查当前会话是否已具备Chrome DevTools MCP工具。然后运行捆绑的设置脚本(幂等操作):bash
dm mcp-setup该脚本会检查已知的主机MCP配置,若缺少则写入官方的配置项,并预取npm包。它不会向活跃主机注入工具;主机仍需自行启动服务器。chrome-devtools-mcp@latest --autoConnect- 工具已存在且→ 继续。
ready: true - → 告知用户重载
reload_required: trueMCP服务器(或重启主机),然后等待。请勿附加到缺少chrome-devtools配置的配置文件。--autoConnect - → 显示命令输出中的官方代码片段,除非用户希望使用
ready: false降级方案,否则切换到手动模式。dm browser-check
绝不要静默切换到Playwright、Puppeteer、全新空白Chrome、云端浏览器或自定义扩展。 - 工具已存在且
-
在首次MCP调用前,逐字告知用户:自动驾驶模式已开启。我将操控你已打开的标签页。
一次性操作:打开chrome://inspect/#remote-debugging,为当前浏览器实例启用“允许远程调试”(Chrome 144+)。
当Chrome弹出提示时,点击“允许”。出现“由自动化测试软件控制”的横幅属于正常现象。我不会关闭Chrome或其他标签页。若用户未确认可点击“允许”,则等待回复。若用户已同意执行,则列出步骤并保持可见。 -
通过Chrome DevTools MCP发现页面。选择已存在的应用标签页。除非复现需要全新导航,否则不要打开新URL。不要关闭Chrome或其他标签页,不要关闭最后一个标签页。
-
拍摄快照,然后通过快照UID执行点击/填充/输入操作来驱动工作流程。若用户已在Elements面板选择节点或在Network面板选择请求,则从该位置开始。
-
若附加失败,打印检查页面+允许步骤并切换到手动模式。仅当主机完全没有Chrome DevTools MCP时,才使用。
dm browser-check -
完成一次复现尝试后,读取,与等待
dm logs时的操作一致。不要仅通过快照就声称已复现bug。proceed
Manual
手动模式
Use this path when the user holds the wheel, autopilot is unavailable or
denied, or you should not touch the open tabs. Tell the user:
- Debug mode is active in manual. They hold the wheel.
- The exact workflow to perform, including any reset or starting state.
- Which visible outcome identifies the bug.
- To reply exactly after one reproduction attempt.
proceed
Then stop. Do not poll the event file or claim a reproduction before the user
replies.
当用户操控、自动驾驶模式不可用或被拒绝,或不应触碰已打开的标签页时,使用此模式。告知用户:
- 调试模式已激活,当前为手动模式,由用户操控。
- 需执行的具体工作流程,包括任何重置或初始状态。
- 能识别bug的可见结果。
- 完成一次复现尝试后,准确回复。
proceed
然后停止操作。在用户回复前,不要轮询事件文件或声称已复现bug。
Inspect On proceed
proceed收到proceed
后检查
proceedAfter an autopilot reproduction, use this same command and the same
outcomes without waiting for .
proceedRead the evidence with:
bash
dm logs <session-dir> --run run-1Correlate event order and values against the stated hypotheses, then choose
one outcome:
- Reproduced and conclusive: explain the observed causal chain, implement the smallest root-cause fix, and verify it. Keep probes only if one user rerun is still needed to validate the fix.
- Reproduced but inconclusive: say what the evidence ruled out, revise the
hypothesis, add or move only the probes needed for , and ask for the precise workflow again.
run-2 - No application events: check session status () and send one synthetic event to distinguish collector delivery failure from an unvisited code path. Check browser CSP/CORS or environment reachability when relevant, then repair the instrumentation and retry.
dm status <session-dir> - Workflow did not reproduce: record that result, adjust the starting state or probe placement, increment the run ID, and retry without pretending the bug was observed.
Do not equate correlation with cause. Cite the specific probe sequence and
values that support the next action.
自动驾驶模式完成复现后,使用相同命令和结果,无需等待。
proceed通过以下命令读取证据:
bash
dm logs <session-dir> --run run-1将事件顺序和数值与提出的假设关联,然后选择以下结果之一:
- 已复现且结论明确:解释观察到的因果链,实现最小化的根因修复并验证。仅当需要用户再次运行以验证修复时,才保留探针。
- 已复现但结论不明确:说明证据排除的假设,修订假设,仅添加或移动所需的探针,并再次询问具体工作流程。
run-2 - 无应用事件:检查会话状态()并发送一个合成事件,以区分采集器交付失败与未访问的代码路径。若相关,检查浏览器CSP/CORS或环境可达性,然后修复 instrumentation 并重试。
dm status <session-dir> - 工作流程未复现bug:记录结果,调整初始状态或探针位置,递增运行ID,并重试,不要假装已观察到bug。
不要将相关性等同于因果关系。引用支持下一步操作的具体探针序列和数值。
Doctor: Monitor Live Sessions
诊断工具:监控活跃会话
To inspect every debug-mode collector on the machine at once, run the live TUI:
bash
dm doctor # or bare `dm`It scans the temp root for all sessions and shows, per session, a
health status derived from the process state plus the collector's
endpoint:
debug-mode-*/health- running (green): launcher and collector processes are alive and returns 200.
/health - degraded (yellow): processes are alive but is unreachable or non-200 (hung or wedged port).
/healthmeans the collector metadata has not been written yet.starting - dead (red): the launcher or collector process is gone.
The detail pane live-tails the selected session's , auto-scrolling
to the newest event, shows the live entry count, and surfaces the last error
line from when the collector crashed or is throwing.
events.jsonlruntime.logKeys: / or / to move, to kill the selected session (stops its
processes and deletes its temp directory, same as ; asks / first),
to force a refresh, to quit. Killing only ever targets a validated
session directory; it never issues a broad process kill.
↑↓jkxstopynrqdebug-mode-*For scripting or when no TTY is available, use to print a
one-shot JSON snapshot of all sessions instead of launching the TUI.
dm doctor --once要一次性检查机器上所有调试模式采集器,运行实时TUI:
bash
dm doctor # 或直接运行 `dm`它会扫描临时目录根目录下所有会话,并根据进程状态和采集器的端点显示每个会话的健康状态:
debug-mode-*/health- 运行中(绿色):启动器和采集器进程均存活,且返回200。
/health - 降级(黄色):进程存活但不可达或返回非200状态(端口挂起或阻塞)。
/health表示采集器元数据尚未写入。starting - 已终止(红色):启动器或采集器进程已消失。
详情面板会实时跟踪所选会话的,自动滚动到最新事件,显示实时事件计数,并在采集器崩溃或抛出错误时显示中的最后一条错误信息。
events.jsonlruntime.log快捷键:/或/移动,终止所选会话(停止其进程并删除临时目录,与功能相同;会先询问/确认),强制刷新,退出。终止操作仅针对已验证的会话目录;绝不会执行大范围进程终止命令。
↑↓jkxstopynrqdebug-mode-*若需脚本化执行或无TTY可用,使用打印所有会话的一次性JSON快照,而非启动TUI。
dm doctor --onceInstalling dm
persistently for the user
dm为用户持久化安装dm
dmThe skill sources for its own session, but the user gets in their
own terminals only after a one-time install. Offer it once per machine:
dm.shdmbash
sh <skill-dir>/scripts/install-dm.shThis appends a single line to the user's
shell rc ( or , auto-detected; pass a path to override) and
is idempotent. After reloading the shell:
source <skill-dir>/scripts/dm.sh~/.zshrc~/.bashrc- — open the doctor TUI
dm - — list every command
dm help - ,
dm start,dm status <dir>,dm logs <dir>,dm stop <dir>,dm mcp-setup— launcher subcommandsdm browser-check
dm.shpython3 <skill-dir>/scripts/debug_session.py doctorskill会在自身会话中加载,但用户需执行一次性安装才能在自己的终端中使用。每台机器仅需提供一次安装命令:
dm.shdmbash
sh <skill-dir>/scripts/install-dm.sh该脚本会在用户的shell配置文件(自动检测或;可传入路径覆盖)中添加一行,且操作是幂等的。重载shell后:
~/.zshrc~/.bashrcsource <skill-dir>/scripts/dm.sh- — 打开诊断工具TUI
dm - — 列出所有命令
dm help - ,
dm start,dm status <dir>,dm logs <dir>,dm stop <dir>,dm mcp-setup— 启动器子命令dm browser-check
dm.shpython3 <skill-dir>/scripts/debug_session.py doctorFinish Or Abort
结束或中止会话
Whether the bug is fixed, the user stops, or the session fails:
-
Remove everyprobe and any debug-only imports, helpers, configuration, or CSP changes. Preserve the actual fix and useful regression tests.
DEBUG_MODE:<session-id>: -
Search the touched files forand inspect the diff to confirm no temporary instrumentation remains.
DEBUG_MODE: -
Stop issuing Chrome DevTools MCP commands. Do not close tabs you did not open, quit Chrome, or close the last tab. Remind them they can disable remote debugging atif they no longer want local processes to attach.
chrome://inspect/#remote-debugging -
Tear down only this collector and delete its temporary directory:bash
dm stop <session-dir> -
Confirm the command reports. If teardown fails, report the exact session directory and PID instead of using a broad kill command.
removed: true
If context is interrupted, recover from the saved ; re-source
if needed, then use , , and , or run
to see and manage every live session at once.
session_dirdm.shdm statusdm logsdm stopdm doctor无论bug已修复、用户停止操作或会话失败:
-
删除所有标记为的探针,以及任何仅用于调试的导入、辅助工具、配置或CSP修改。保留实际修复和有用的回归测试。
DEBUG_MODE:<session-id>: -
在修改过的文件中搜索,检查差异以确认无临时 instrumentation 残留。
DEBUG_MODE: -
停止执行Chrome DevTools MCP命令。不要关闭非你打开的标签页,不要退出Chrome,不要关闭最后一个标签页。提醒用户若不再希望本地进程附加,可在中禁用远程调试。
chrome://inspect/#remote-debugging -
仅终止当前采集器并删除其临时目录:bash
dm stop <session-dir> -
确认命令返回。若终止失败,报告确切的会话目录和PID,而非使用大范围终止命令。
removed: true
若上下文中断,可从保存的恢复;若需重新加载,然后使用、和,或运行查看并管理所有活跃会话。
session_dirdm.shdm statusdm logsdm stopdm doctor