chore: remove monitor debug logs and add log clear action

This commit is contained in:
superclaw
2026-03-14 14:16:03 +08:00
parent 8d5527990b
commit 731f022669
8 changed files with 61 additions and 10 deletions

View File

@@ -173,7 +173,6 @@ export class WcdbCore {
}
} catch {}
}
this.connectMonitorPipe(pipePath)
return true
} catch (e) {
@@ -194,8 +193,14 @@ export class WcdbCore {
let buffer = ''
this.monitorPipeClient.on('data', (data: Buffer) => {
buffer += data.toString('utf8')
const lines = buffer.split('\n')
const rawChunk = data.toString('utf8')
// macOS 侧可能使用 '\0' 或无换行分隔,统一归一化并兜底拆包
const normalizedChunk = rawChunk
.replace(/\u0000/g, '\n')
.replace(/}\s*{/g, '}\n{')
buffer += normalizedChunk
const lines = buffer.split(/\r?\n/)
buffer = lines.pop() || ''
for (const line of lines) {
if (line.trim()) {
@@ -207,9 +212,23 @@ export class WcdbCore {
}
}
}
// 兜底:如果没有分隔符但已形成完整 JSON则直接上报
const tail = buffer.trim()
if (tail.startsWith('{') && tail.endsWith('}')) {
try {
const parsed = JSON.parse(tail)
this.monitorCallback?.(parsed.action || 'update', tail)
buffer = ''
} catch {
// 不可解析则继续等待下一块数据
}
}
})
this.monitorPipeClient.on('error', () => {})
this.monitorPipeClient.on('error', () => {
// 保持静默,与现有错误处理策略一致
})
this.monitorPipeClient.on('close', () => {
this.monitorPipeClient = null