@zxh126/pi-qqbot 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -221,7 +221,7 @@ The QQ gateway keeps only one active connection per bot. The extension uses a `p
221
221
 
222
222
  ## Logs
223
223
 
224
- Debug logs are written to `~/.pi/agent/pi-qqbot.log`.
224
+ Debug logs are written to `~/.pi/agent/pi-qqbot.log`. Each line starts with a **local** timestamp that carries the UTC offset, e.g. `[2026-10-24T07:39:09.762+08:00]`, so it lines up with file mtimes and process start times without mental arithmetic.
225
225
 
226
226
  ## License
227
227
 
@@ -211,7 +211,7 @@ QQ 网关对同一 bot 只保留一个活跃连接。插件用 `proper-lockfile`
211
211
 
212
212
  ## 日志
213
213
 
214
- 调试日志写入 `~/.pi/agent/pi-qqbot.log`。
214
+ 调试日志写入 `~/.pi/agent/pi-qqbot.log`。每行开头是**本地时间 + 时区偏移**(如 `[2026-10-24T07:39:09.762+08:00]`),和文件 mtime、进程启动时间直接对得上,不需要再拿 UTC 换算。
215
215
 
216
216
  ## License
217
217
 
package/logger.ts CHANGED
@@ -4,12 +4,28 @@ import path from "node:path";
4
4
 
5
5
  const LOG_PATH = path.join(os.homedir(), ".pi", "agent", "pi-qqbot.log");
6
6
 
7
- function ts() {
8
- return new Date().toISOString();
7
+ const pad = (value: number, width = 2): string =>
8
+ String(Math.trunc(Math.abs(value))).padStart(width, "0");
9
+
10
+ /**
11
+ * 本地时间戳 + 时区偏移,例如 `2026-10-24T07:39:09.762+08:00`。
12
+ *
13
+ * 以前用 `toISOString()`(UTC),看日志要和文件 mtime、进程启动时间(都是本地)
14
+ * 来回换算,容易对不上;北京时间直接读即可,同时又保留偏移,跨时区不会歧义。
15
+ */
16
+ export function timestamp(date = new Date()): string {
17
+ const offsetMinutes = -date.getTimezoneOffset(); // 东八区 = +480
18
+ const sign = offsetMinutes >= 0 ? "+" : "-";
19
+ const offset = `${sign}${pad(offsetMinutes / 60)}:${pad(offsetMinutes % 60)}`;
20
+ const local =
21
+ `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` +
22
+ `T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}` +
23
+ `.${pad(date.getMilliseconds(), 3)}`;
24
+ return `${local}${offset}`;
9
25
  }
10
26
 
11
27
  export function log(...args: unknown[]) {
12
- const line = `[${ts()}] ${args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")}\n`;
28
+ const line = `[${timestamp()}] ${args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")}\n`;
13
29
  try {
14
30
  fs.appendFileSync(LOG_PATH, line, "utf8");
15
31
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zxh126/pi-qqbot",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "Bridge the Pi coding agent into QQ private chats, with remote tool-call approval",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  ]
28
28
  },
29
29
  "scripts": {
30
- "test": "node test/queue.test.mjs"
30
+ "test": "node test/queue.test.mjs && node test/logger.test.mjs"
31
31
  },
32
32
  "files": [
33
33
  "*.ts",