tt-help-cli-ycl 1.4.135 → 1.4.136
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/watchdog/agent.js
CHANGED
|
@@ -26,13 +26,11 @@ import { spawn } from "child_process";
|
|
|
26
26
|
import { join, dirname } from "path";
|
|
27
27
|
import { homedir, tmpdir } from "os";
|
|
28
28
|
import { fileURLToPath } from "url";
|
|
29
|
+
import { pushSelfLog, getSelfLogs } from "./self-log-buffer.js";
|
|
29
30
|
|
|
30
|
-
// ──
|
|
31
|
+
// ── 看门狗自身日志入环(供后台页面按需拉取,经 report-logs 回传落盘) ──
|
|
31
32
|
// 包装 console.error:本进程所有 [watchdog]/[llm-analyzer]/[upgrade] 等日志
|
|
32
|
-
//
|
|
33
|
-
// 托管进程日志走 process-manager 的 printProcessLine(stderr.write),不混入此环。
|
|
34
|
-
const WATCHDOG_SELF_LOG_MAX = 500;
|
|
35
|
-
const watchdogSelfLogs = [];
|
|
33
|
+
// 在正常输出的同时进共享环形缓冲(与托管进程日志同环,见 self-log-buffer.js)。
|
|
36
34
|
const _origConsoleError = console.error.bind(console);
|
|
37
35
|
console.error = (...args) => {
|
|
38
36
|
try {
|
|
@@ -47,22 +45,16 @@ console.error = (...args) => {
|
|
|
47
45
|
: String(a),
|
|
48
46
|
)
|
|
49
47
|
.join(" ");
|
|
50
|
-
|
|
51
|
-
if (watchdogSelfLogs.length > WATCHDOG_SELF_LOG_MAX)
|
|
52
|
-
watchdogSelfLogs.shift();
|
|
48
|
+
pushSelfLog(line);
|
|
53
49
|
} catch {
|
|
54
50
|
/* 缓冲失败不影响原始输出 */
|
|
55
51
|
}
|
|
56
52
|
_origConsoleError(...args);
|
|
57
53
|
};
|
|
58
54
|
|
|
59
|
-
/** 取最近 tail
|
|
55
|
+
/** 取最近 tail 行看门狗自身日志(含托管进程日志,只读) */
|
|
60
56
|
export function getWatchdogSelfLogs(tail = 500) {
|
|
61
|
-
|
|
62
|
-
1,
|
|
63
|
-
Math.min(Number(tail) || WATCHDOG_SELF_LOG_MAX, watchdogSelfLogs.length),
|
|
64
|
-
);
|
|
65
|
-
return watchdogSelfLogs.slice(-n);
|
|
57
|
+
return getSelfLogs(tail);
|
|
66
58
|
}
|
|
67
59
|
|
|
68
60
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -15,6 +15,7 @@ import { killEdgeProcesses } from "../lib/browser/cdp.js";
|
|
|
15
15
|
import { writeFileSync, unlinkSync } from "fs";
|
|
16
16
|
import { tmpdir } from "os";
|
|
17
17
|
import { join } from "path";
|
|
18
|
+
import { pushSelfLog } from "./self-log-buffer.js";
|
|
18
19
|
|
|
19
20
|
// === 2026-08-07 变更 ===
|
|
20
21
|
// syncCommands 改为 async,批量启动时每个进程间隔 SPAWN_STAGGER_MS(30s),避免抢网络
|
|
@@ -60,6 +61,7 @@ function fmtClock(d = new Date()) {
|
|
|
60
61
|
/**
|
|
61
62
|
* 打印子进程日志行(替代裸 console.error)。
|
|
62
63
|
* 只改显示形态,msg 内容一行不少;多行消息逐行加前缀。
|
|
64
|
+
* 同时以纯文本(无 ANSI 颜色)写入共享环形缓冲,供后台按需拉取。
|
|
63
65
|
*/
|
|
64
66
|
function printProcessLine(id, msg) {
|
|
65
67
|
const lines = String(msg).split(/\r?\n/);
|
|
@@ -68,6 +70,8 @@ function printProcessLine(id, msg) {
|
|
|
68
70
|
const useColor = canUseColor();
|
|
69
71
|
for (const line of lines) {
|
|
70
72
|
const clock = fmtClock();
|
|
73
|
+
// 环形缓冲:与 cmd 窗口同格式(时间 [cmdId] 内容),无颜色
|
|
74
|
+
pushSelfLog(`${clock} ${prefixId} ${line}`);
|
|
71
75
|
if (useColor) {
|
|
72
76
|
process.stderr.write(
|
|
73
77
|
`\x1b[90m${clock}\x1b[0m \x1b[${color}m${prefixId}\x1b[0m ${line}\n`,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 看门狗客户端本机日志环形缓冲(供后台页面按需拉取,经 report-logs 回传落盘)
|
|
3
|
+
*
|
|
4
|
+
* 两路来源:
|
|
5
|
+
* 1. watchdog 自身日志 —— agent.js 包装 console.error 写入([watchdog]/[llm-analyzer]/[upgrade] 等)
|
|
6
|
+
* 2. 托管进程日志 —— process-manager.js 的 printProcessLine 写入(纯文本,无 ANSI 颜色)
|
|
7
|
+
*
|
|
8
|
+
* 独立成模块是为了避免 agent.js ↔ process-manager.js 相互 import 形成循环依赖。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const MAX_LINES = 500; // 最多保留行数
|
|
12
|
+
|
|
13
|
+
const ring = [];
|
|
14
|
+
|
|
15
|
+
/** 追加一行(超容量丢弃最旧) */
|
|
16
|
+
export function pushSelfLog(line) {
|
|
17
|
+
ring.push(String(line));
|
|
18
|
+
if (ring.length > MAX_LINES) ring.shift();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 取最近 tail 行(只读) */
|
|
22
|
+
export function getSelfLogs(tail = MAX_LINES) {
|
|
23
|
+
const n = Math.max(1, Math.min(Number(tail) || MAX_LINES, ring.length));
|
|
24
|
+
return ring.slice(-n);
|
|
25
|
+
}
|