From a9a7816e1605bd67ab5128fd1e587368e0424f09 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Sat, 14 Mar 2026 22:46:49 +0800 Subject: [PATCH] fix: show claw_id in activation box, remove noisy startup logs Made-with: Cursor --- lib/client.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/client.js b/lib/client.js index 5da5d5d..fb0b468 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,10 +18,7 @@ class ClawClient { } start() { - console.log(`[clawd] 启动中...`); - console.log(`[clawd] box_id = ${this._boxId}`); - console.log(`[clawd] 服务器 = ${this._cfg.server}`); - console.log(`[clawd] 配置文件 = ${config.getConfigPath()}`); + console.log(`[clawd] 启动中... 服务器 = ${this._cfg.server}`); this._connect(); } @@ -96,8 +93,14 @@ class ClawClient { break; case 'error': console.error(`[clawd] 服务器错误: ${msg.msg}`); - // 若是鉴权失败,清空本地凭证后重连 - if (msg.msg && msg.msg.includes('invalid')) { + if (msg.msg === 'hardware_mismatch') { + // box_id 与库中不符:硬件变更或凭证泄露 + // 清空本地凭证,下次重连走全新注册流程 + console.warn('[clawd] 硬件指纹与服务器不符(硬件变更或凭证泄露),清除本地凭证重新注册...'); + this._cfg.claw_id = null; + this._cfg.token = null; + config.save(this._cfg); + } else if (msg.msg && msg.msg.includes('invalid')) { console.warn('[clawd] 凭证无效,清除本地凭证并重新注册...'); this._cfg.claw_id = null; this._cfg.token = null; @@ -122,15 +125,18 @@ class ClawClient { } if (msg.status === 'inactive') { + const id = String(msg.claw_id).padEnd(6); + const pin = String(msg.pin); console.log(''); - console.log('╔══════════════════════════════════╗'); - console.log(`║ 激活 PIN 码: ${msg.pin} ║`); - console.log('║ 请在管理后台或前台输入此 PIN 码 ║'); - console.log('╚══════════════════════════════════╝'); + console.log('╔════════════════════════════════════╗'); + console.log(`║ Claw ID : ${id} ║`); + console.log(`║ PIN 码 : ${pin} ║`); + console.log('║ 请在网页前台「添加设备」中输入 ║'); + console.log('╚════════════════════════════════════╝'); console.log(''); - console.log('[clawd] 等待激活中,心跳正常运行...'); + console.log('[clawd] 等待激活,心跳正常运行...'); } else { - console.log(`[clawd] 设备已激活,claw_id = ${msg.claw_id}`); + console.log(`[clawd] 已激活 claw_id = ${msg.claw_id}`); } // 开始心跳