/** * 看设备上内核当前的真实设置(判断"保存后被清空"是否真的发生)。 * 用法: node scripts/device-state.mjs [serial] [port] */ import { spawnSync } from 'node:child_process'; const SERIAL = process.argv[2] || 'YOUR_DEVICE_SERIAL'; const PORT = process.argv[3] || '5199'; const ADB = 'C:\\Android\\Sdk\\platform-tools\\adb.exe'; function sh(cmd, timeout = 60000) { const res = spawnSync(ADB, ['-s', SERIAL, 'shell', cmd], { encoding: 'utf8', timeout }); return `${res.stdout || ''}${res.stderr || ''}`.trim(); } const out = sh(`curl -s --max-time 20 http://127.0.0.1:${PORT}/api/state`); let state; try { state = JSON.parse(out); } catch { console.log('原始返回:', out.slice(0, 400)); process.exit(1); } const s = state.settings || {}; console.log('=== 设备内核当前设置 ==='); for (const key of ['provider', 'baseUrl', 'model', 'temperature', 'maxRounds', 'thinkingLevel', 'toolsDir', 'nickname', 'activeAgentId']) { console.log(` ${key.padEnd(14)} = ${JSON.stringify(s[key])}`); } console.log(` hasApiKey = ${s.hasApiKey}`); console.log(` systemPrompt = ${(s.systemPrompt || '').length} 字`); console.log(` tools = ${JSON.stringify(s.tools)}`); console.log(` security = ${JSON.stringify(s.security)}`); console.log(` agents = ${(state.agents || []).length} 个`); console.log(` conversations = ${(state.conversations || []).length} 个`); const empty = []; if (!s.baseUrl) empty.push('baseUrl'); if (!s.model) empty.push('model'); if (!s.hasApiKey) empty.push('apiKey'); if (!s.systemPrompt) empty.push('systemPrompt'); console.log(empty.length ? `\n⚠️ 这些是空的:${empty.join(', ')}` : '\n✅ 关键字段都有值');