@chen_hu_hu/pi-qq 1.5.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.5.1] - 2026-11-05
11
+
12
+ ### Changed
13
+
14
+ - Logs are now written only during QQ-triggered runs after login. Local runs, login/QR flows, bot lifecycle events, and idle periods no longer create log files.
15
+
10
16
  ## [1.5.0] - 2026-11-05
11
17
 
12
18
  ### Added
package/README-zh.md CHANGED
@@ -126,7 +126,7 @@ QQ 侧命令:
126
126
  | `/qq-test-md [text]` | 发送 Markdown 测试消息 |
127
127
  | `/qq-test-stream` | 运行流式时间线诊断(`resume` 验证续写) |
128
128
 
129
- 将 `logLevel` 设为 `debug` 时,本地 run 和 QQ run 都会写入通用的 agent/message/tool 日志;`scope: "media"` 记录媒体工具的关键步骤。QQ relay 日志只在 QQ 触发的 run 中出现。
129
+ 将 `logLevel` 设为 `debug` 时,只有在登录后由 QQ 消息触发的 run 期间才会写入 agent/message/tool 日志;本地 run、登录流程和空闲时段不写日志。`scope: "media"` 记录媒体工具在这些 run 中的关键步骤,QQ relay 日志也只在 QQ 触发的 run 中出现。
130
130
 
131
131
  ## 设置
132
132
 
@@ -150,7 +150,7 @@ QQ 侧命令:
150
150
 
151
151
  配置在 pi 会话启动时读取;修改文件后请重启 pi。未知配置项会被忽略,无效值会回退到默认值并给出提示。
152
152
 
153
- 启用日志后,日志写入 `<cwd>/.pi/pi-qq/logs/pi-qq-YYYY-MM-DD.log`。可用 `PI_QQ_LOG_DIR` 覆盖目录。`info` 只记录元数据;`debug` 记录完整事件、附件、提示词和工具参数/结果。
153
+ 启用日志后,只有 QQ 触发的 run 处于活动状态时才会写入记录,路径为 `<cwd>/.pi/pi-qq/logs/pi-qq-YYYY-MM-DD.log`;可用 `PI_QQ_LOG_DIR` 覆盖目录。`info` 只记录元数据;`debug` 记录完整事件、附件、提示词和工具参数/结果。
154
154
 
155
155
  ## 开发
156
156
 
package/README.md CHANGED
@@ -126,7 +126,7 @@ These terminal commands are intended for troubleshooting:
126
126
  | `/qq-test-md [text]` | Send a Markdown test message |
127
127
  | `/qq-test-stream` | Run a streamed timeline diagnostic (`resume` for probe) |
128
128
 
129
- With `logLevel: "debug"`, general agent/message/tool logs are written for local and QQ runs, and `scope: "media"` covers media-tool steps. QQ relay logs only appear for QQ-triggered runs.
129
+ With `logLevel: "debug"`, logs are written only while a QQ-triggered run is active after login; local runs, login, and idle periods are not logged. `scope: "media"` covers media-tool steps during those runs, and QQ relay logs only appear for QQ-triggered runs.
130
130
 
131
131
  ## Settings
132
132
 
@@ -150,7 +150,7 @@ Create `~/.pi/agent/pi-qq.json` to override defaults. It stores settings only; c
150
150
 
151
151
  Settings are read when a pi session starts; restart pi after editing the file. Unknown keys are ignored, and invalid values fall back to defaults with a warning.
152
152
 
153
- When logging is enabled, logs are written to `<cwd>/.pi/pi-qq/logs/pi-qq-YYYY-MM-DD.log`. `PI_QQ_LOG_DIR` overrides the directory. `info` records metadata only; `debug` records full events, attachments, prompts, and tool payloads.
153
+ When logging is enabled, records are written only while a QQ-triggered run is active. Logs go to `<cwd>/.pi/pi-qq/logs/pi-qq-YYYY-MM-DD.log`; `PI_QQ_LOG_DIR` overrides the directory. `info` records metadata only; `debug` records full events, attachments, prompts, and tool payloads.
154
154
 
155
155
  ## Development
156
156
 
package/index.ts CHANGED
@@ -9,7 +9,7 @@ import { registerQQDiagnostics } from "./src/qq/qq-diagnostics";
9
9
  import { markdownToPlain, sendReply } from "./src/qq/reply-sender";
10
10
  import { ReplyBudget } from "./src/quota/reply-quota";
11
11
  import { RunFeedback } from "./src/relay/run-stream-relay";
12
- import { configureLogger, flushLogs, isLogEnabled, log, previewForLog } from "./src/infra/file-logger";
12
+ import { configureLogger, flushLogs, isLogEnabled, log, previewForLog, setLogGate } from "./src/infra/file-logger";
13
13
  import { configureI18n, t } from "./src/infra/i18n";
14
14
  import { getPowerStatus } from "./src/infra/power-status";
15
15
  import { formatStatusReport } from "./src/qq/status-report";
@@ -97,6 +97,8 @@ function stopEventLoopMonitor(): void {
97
97
  }
98
98
 
99
99
  export default function (pi: ExtensionAPI) {
100
+ setLogGate(() => Boolean(getLoginState()) && runFeedback.isQQRunActive());
101
+
100
102
  mediaTool = registerMediaTool(pi, {
101
103
  getBot: () => running?.bot,
102
104
  getLogin: () => getLoginState(),
@@ -204,7 +206,6 @@ export default function (pi: ExtensionAPI) {
204
206
  pi.on("session_start", async (_event, ctx) => {
205
207
  const { settings, error } = applyConfig(ctx);
206
208
  configureLogger(settings.logLevel, join(ctx.cwd, ".pi", "pi-qq", "logs"));
207
- startEventLoopMonitor();
208
209
 
209
210
  const login = getLoginState();
210
211
  log.info("session", "started", {
@@ -229,8 +230,8 @@ export default function (pi: ExtensionAPI) {
229
230
  });
230
231
 
231
232
  pi.on("agent_start", () => {
232
- log.info("agent", "run started");
233
233
  runFeedback.onAgentStart();
234
+ log.info("agent", "run started");
234
235
  if (isLogEnabled("debug")) {
235
236
  log.debug("agent", "run state", {
236
237
  phase: "start",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chen_hu_hu/pi-qq",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Connect pi to QQ private chats.",
5
5
  "license": "MIT",
6
6
  "author": "CQ-Developer",
@@ -18,6 +18,7 @@ const DEFAULT_LOG_LEVEL: LogLevel = "silent";
18
18
  let activeLevel: LogLevel = DEFAULT_LOG_LEVEL;
19
19
  let activeDir: string | undefined;
20
20
  let writeQueue: Promise<void> = Promise.resolve();
21
+ let logGate: (() => boolean) | undefined;
21
22
 
22
23
  function isLogLevel(value: unknown): value is LogLevel {
23
24
  return typeof value === "string" && Object.hasOwn(LEVEL_WEIGHT, value);
@@ -44,6 +45,19 @@ export function configureLogger(level: LogLevel, dir?: string): void {
44
45
  activeDir = dir;
45
46
  }
46
47
 
48
+ export function setLogGate(gate: (() => boolean) | undefined): void {
49
+ logGate = gate;
50
+ }
51
+
52
+ function isLogAllowed(): boolean {
53
+ if (!logGate) return true;
54
+ try {
55
+ return logGate();
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+
47
61
  function resolveLogDir(): string {
48
62
  return process.env.PI_QQ_LOG_DIR ?? activeDir ?? join(process.cwd(), ".pi", "pi-qq", "logs");
49
63
  }
@@ -77,6 +91,7 @@ function stringifyError(err: unknown): string {
77
91
 
78
92
  function writeRecord(level: Exclude<LogLevel, "silent">, scope: string, message: string, data?: unknown): void {
79
93
  if (!isLevelEnabled(activeLevel, level)) return;
94
+ if (!isLogAllowed()) return;
80
95
 
81
96
  const localized = localizeLogMessage(message);
82
97
  const record: LogFields = {
@@ -343,12 +343,12 @@ export class RunFeedback {
343
343
  lastCompletedTextLength: this.lastCompletedText?.length ?? 0,
344
344
  ...this.diagnostics(run),
345
345
  });
346
- this.run = null;
347
346
  log.debug("run", "run ended", {
348
347
  phase: "finished",
349
348
  msgId: run.msgId?.slice(0, 8) ?? "?",
350
349
  elapsedMs: Date.now() - run.startedAt,
351
350
  });
351
+ this.run = null;
352
352
  if (!run.writer.hasPushed) {
353
353
  run.writer.dispose();
354
354
  this.finishEnd();