@linjz/opencode-qqbot 0.3.17 → 0.3.18

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.
@@ -3298,8 +3298,8 @@ function storageFile(name, appId) {
3298
3298
  }
3299
3299
 
3300
3300
  // src/index.ts
3301
- import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync15 } from "fs";
3302
- import { join as join13 } from "path";
3301
+ import { mkdirSync as mkdirSync15, writeFileSync as writeFileSync16 } from "fs";
3302
+ import { join as join14 } from "path";
3303
3303
  import { homedir as homedir8 } from "os";
3304
3304
 
3305
3305
  // src/opencode/client.ts
@@ -4332,9 +4332,15 @@ class SessionManager {
4332
4332
  return;
4333
4333
  const raw = readFileSync5(this.storeFile, "utf8").replace(/^\uFEFF/, "");
4334
4334
  const parsed = JSON.parse(raw);
4335
+ let dropped = 0;
4335
4336
  for (const [userId, session] of Object.entries(parsed)) {
4336
- if (session?.sessionId)
4337
+ if (session?.sessionId && /^ses_/.test(session.sessionId))
4337
4338
  this.sessions.set(userId, session);
4339
+ else
4340
+ dropped++;
4341
+ }
4342
+ if (dropped > 0) {
4343
+ console.warn(`[sessions] 加载时丢弃 ${dropped} 条非法映射(sessionId 形态不合法,不做整图回写保留)`);
4338
4344
  }
4339
4345
  if (this.sessions.size > 0) {
4340
4346
  console.log(`[sessions] 已从磁盘恢复 ${this.sessions.size} 个用户会话映射`);
@@ -4476,6 +4482,14 @@ class SessionManager {
4476
4482
  all() {
4477
4483
  return [...this.sessions.entries()].map(([userId, s]) => ({ userId, sessionId: s.sessionId, directory: s.directory }));
4478
4484
  }
4485
+ evict(userId) {
4486
+ const had = this.sessions.delete(userId);
4487
+ if (had) {
4488
+ this.saveSessions();
4489
+ console.log(`[sessions] 驱逐失效映射 userId=${userId.slice(0, 8)}…(400/404 三连判死)`);
4490
+ }
4491
+ return had;
4492
+ }
4479
4493
  async setModel(userId, providerId, modelId) {
4480
4494
  const s = this.sessions.get(userId);
4481
4495
  if (!s)
@@ -4990,8 +5004,8 @@ async function startGateway(options) {
4990
5004
  }
4991
5005
 
4992
5006
  // src/bridge.ts
4993
- import { existsSync as existsSync14, readFileSync as readFileSync16, mkdirSync as mkdirSync13, writeFileSync as writeFileSync14 } from "fs";
4994
- import { join as join12 } from "path";
5007
+ import { existsSync as existsSync15, readFileSync as readFileSync17, mkdirSync as mkdirSync14, writeFileSync as writeFileSync15 } from "fs";
5008
+ import { join as join13 } from "path";
4995
5009
  import { homedir as homedir7 } from "os";
4996
5010
 
4997
5011
  // src/qq/media.ts
@@ -5786,7 +5800,11 @@ async function handleCommand(ctx, cmdCtx) {
5786
5800
  case "progress":
5787
5801
  return cmdCtx.progress.query(ctx.userId);
5788
5802
  case "status":
5789
- return handleStatus(ctx, cmdCtx);
5803
+ return handleStatus(ctx, parsed.args, cmdCtx);
5804
+ case "watch":
5805
+ return "⌛ /watch 已退役:观察开关请用 /status watch on|off(盯当前绑定会话)。原 /watch <会话ID> 跨会话观察能力已随命令下线(owner 2026-11-23 裁决不保留)";
5806
+ case "mirror":
5807
+ return "⌛ /mirror 已退役:镜像开关请用 /status mirror on|off";
5790
5808
  case "sessions":
5791
5809
  return handleSessions(ctx, cmdCtx);
5792
5810
  case "help":
@@ -5800,11 +5818,11 @@ async function handleCommand(ctx, cmdCtx) {
5800
5818
  case "history":
5801
5819
  return handleHistory(ctx, parsed.args, cmdCtx);
5802
5820
  case "watch":
5803
- return handleWatch(ctx, parsed.args, cmdCtx);
5821
+ return "⌛ /watch 已退役:观察开关请用 /status watch on|off(盯当前绑定会话)。原 /watch <会话ID> 跨会话观察能力已随命令下线(owner 2026-11-23 裁决不保留)";
5804
5822
  case "send":
5805
5823
  return handleSend(ctx, parsed.args, cmdCtx);
5806
5824
  case "mirror":
5807
- return handleMirror(parsed.args, cmdCtx);
5825
+ return "⌛ /mirror 已退役:镜像开关请用 /status mirror on|off";
5808
5826
  default:
5809
5827
  return `不支持的命令:/${parsed.name}
5810
5828
  发送 /help 查看可用命令`;
@@ -5932,7 +5950,22 @@ async function resolveStatusSessionTitle(sessions, client, userId) {
5932
5950
  } catch {}
5933
5951
  return { title: session.title, sessionId: session.sessionId };
5934
5952
  }
5935
- async function handleStatus(ctx, cmdCtx) {
5953
+ async function handleStatus(ctx, args, cmdCtx) {
5954
+ const parts = args.trim().split(/\s+/).filter(Boolean);
5955
+ if (parts.length > 0) {
5956
+ const target = parts[0].toLowerCase();
5957
+ const sw = parts[1]?.toLowerCase();
5958
+ if ((target === "watch" || target === "mirror") && (sw === "on" || sw === "off")) {
5959
+ if (target === "mirror")
5960
+ return cmdCtx.mirror.set(sw === "on");
5961
+ if (sw === "on") {
5962
+ const session = await cmdCtx.sessions.getOrCreate(ctx.userId);
5963
+ return cmdCtx.watch.start(ctx.userId, session.sessionId, ctx);
5964
+ }
5965
+ return cmdCtx.watch.stop(ctx.userId);
5966
+ }
5967
+ return "用法:/status 查看状态|/status watch on|off 观察开关|/status mirror on|off 镜像开关";
5968
+ }
5936
5969
  const sessionInfo = await resolveStatusSessionTitle(cmdCtx.sessions, cmdCtx.client, ctx.userId);
5937
5970
  const { providerId, modelId } = cmdCtx.sessions.getModel(ctx.userId);
5938
5971
  const agentId = cmdCtx.sessions.getAgent(ctx.userId);
@@ -5951,6 +5984,8 @@ async function handleStatus(ctx, cmdCtx) {
5951
5984
  `会话:${sessionInfo.sessionId ? `${sessionInfo.title ?? "未命名会话"} (${sessionInfo.sessionId})` : "未创建"}`,
5952
5985
  `模型:${providerId && modelId ? `${providerId} / ${modelId}` : "默认"}`,
5953
5986
  `Agent:${agentId ?? "默认"}`,
5987
+ cmdCtx.watch.status(ctx.userId),
5988
+ cmdCtx.mirror.status(),
5954
5989
  cmdCtx.queue.summary(ctx.userId),
5955
5990
  logLine
5956
5991
  ].join(`
@@ -5999,7 +6034,7 @@ async function handleModel(ctx, args, cmdCtx) {
5999
6034
  }
6000
6035
  const model = splitModelId(args);
6001
6036
  if (!model) {
6002
- return "模型格式不对,请使用 /model <provider/model>";
6037
+ return "模型格式不对,请使用 /models <provider/model>";
6003
6038
  }
6004
6039
  let models;
6005
6040
  try {
@@ -6026,7 +6061,7 @@ async function handleAgent(ctx, args, cmdCtx) {
6026
6061
  const isCurrent = currentAgent === agent.id;
6027
6062
  return `${index + 1}. ${isCurrent ? "[当前] " : ""}${agent.label}`;
6028
6063
  });
6029
- return ["可用 Agent:", ...lines, "回复 /agent <name> 切换"].join(`
6064
+ return ["可用 Agent:", ...lines, "回复 /agents <name> 切换"].join(`
6030
6065
  `);
6031
6066
  }
6032
6067
  const normalized = args.trim().toLowerCase();
@@ -6066,31 +6101,6 @@ async function handleHistory(ctx, args, cmdCtx) {
6066
6101
 
6067
6102
  ${body}`;
6068
6103
  }
6069
- async function handleWatch(ctx, args, cmdCtx) {
6070
- const a = args.trim();
6071
- const lower = a.toLowerCase();
6072
- if (lower === "off" || lower === "stop") {
6073
- return cmdCtx.watch.stop(ctx.userId);
6074
- }
6075
- if (!a) {
6076
- const session = await cmdCtx.sessions.getOrCreate(ctx.userId);
6077
- return cmdCtx.watch.start(ctx.userId, session.sessionId, ctx);
6078
- }
6079
- if (/^ses_/i.test(a)) {
6080
- return cmdCtx.watch.start(ctx.userId, a, ctx);
6081
- }
6082
- return "用法:/watch 观察当前会话|/watch <会话ID> 观察指定会话|/watch off 停止观察";
6083
- }
6084
- function handleMirror(args, cmdCtx) {
6085
- const a = args.trim().toLowerCase();
6086
- if (!a)
6087
- return cmdCtx.mirror.status();
6088
- if (["on", "1", "开", "打开"].includes(a))
6089
- return cmdCtx.mirror.set(true);
6090
- if (["off", "0", "关", "关闭"].includes(a))
6091
- return cmdCtx.mirror.set(false);
6092
- return "用法:/mirror 查看状态|/mirror on 开启|/mirror off 关闭";
6093
- }
6094
6104
  async function ensureSession(userId, cmdCtx) {
6095
6105
  await cmdCtx.sessions.getOrCreate(userId);
6096
6106
  }
@@ -6184,30 +6194,25 @@ function buildHelpText() {
6184
6194
  return [
6185
6195
  "可用命令:",
6186
6196
  "/new - 创建新会话",
6187
- "/stop - 停止当前 AI 运行",
6188
- "/status - 查看服务器和当前会话状态",
6197
+ "/cancel - 中止当前生成并清空忙碌队列",
6198
+ "/status - 驾驶舱:服务器/会话/模型/Agent/观察/镜像/队列/日志;/status watch on|off 观察开关;/status mirror on|off 镜像开关",
6189
6199
  "/sessions - 列出历史会话并回复序号切换",
6190
6200
  "/help - 查看帮助",
6191
- "/model - 列出可用模型",
6192
- "/model <provider/model> - 切换模型",
6193
- "/agent - 列出可用 Agent",
6194
- "/agent <name> - 切换 Agent",
6201
+ "/models - 列出可用模型|/models <provider/model> 切换(session 级)",
6202
+ "/agents - 列出可用 Agent|/agents <name> 切换",
6195
6203
  "/rename <name> - 重命名当前会话",
6196
6204
  "/history [N] - 查看当前会话最近 N 轮历史(默认 3,最多 10)",
6197
6205
  "/send <路径> - 把白名单目录内的文件/图片发到 QQ",
6198
- "/watch - 观察当前会话实时过程(工具调用/完成会推送摘要)",
6199
- "/watch <会话ID> - 观察指定会话",
6200
- "/watch off - 停止观察",
6201
6206
  "/progress - 手动进度查询(工具调用/失败统计、在途状态,本地事件源零模型调用)",
6202
6207
  "/queue - 队列与台账对账视图;/queue all [页码] 全量;/queue clear 清空;/queue drop <编号> 定点删除;/queue <文本> 显性入队(steer 默认下排进 FIFO)",
6203
6208
  "/goal <目标> - 官方目标模式(引擎内置 v2.2.1+);/goal 查状态;pause/resume/clear 控制",
6204
6209
  "/compact /redo /btw - 官方引擎命令直通(压缩会话 / 恢复撤销 / 侧问)",
6205
6210
  "/ledger - 台账快照(在途/孤儿/最近拒绝);/ledger check 对账会话历史;/ledger settle <尾号> confirm 人工结清",
6206
- "/cancel - 同 /stop:中止当前 AI 运行并清空忙碌队列",
6207
- "/mirror [on|off] - 桌面问答摘要镜像开关(会话轮次完成推送问答摘要)",
6211
+ "/undo - 对齐官方:撤销上一回合,并恢复文件",
6212
+ "/amend <补充> - 忙时插话并入当前任务(官方 steer 语义)",
6208
6213
  "",
6209
6214
  "权限审批(AI 请求权限时):",
6210
- "回复「允许」= 本次允许|「总是」= 总是允许|「拒绝」= 拒绝",
6215
+ "点卡片按钮(允许一次/总是允许/拒绝/忽略),或回复「允许」= 本次允许|「总是」= 总是允许|「拒绝」= 拒绝",
6211
6216
  "(30 分钟无响应自动拒绝)"
6212
6217
  ].join(`
6213
6218
  `);
@@ -6274,7 +6279,7 @@ function digestTurnKey(messages) {
6274
6279
  }
6275
6280
  return null;
6276
6281
  }
6277
- function buildDigest(messages) {
6282
+ function buildDigest(messages, goalObjective) {
6278
6283
  const ordered = [...messages].reverse();
6279
6284
  let lastUserIdx = -1;
6280
6285
  let goalDriven = false;
@@ -6288,7 +6293,11 @@ function buildDigest(messages) {
6288
6293
  }
6289
6294
  if (lastUserIdx < 0)
6290
6295
  return null;
6291
- const userText = goalDriven ? "" : (ordered[lastUserIdx].text ?? "").trim();
6296
+ const boundaryMsg = ordered[lastUserIdx];
6297
+ const userText = goalDriven ? "" : (boundaryMsg.text ?? (boundaryMsg.content ?? []).filter((p) => p.type === "text").map((p) => p.text ?? "").join("") ?? "").trim();
6298
+ if (!goalDriven && goalObjective && userText && userText === goalObjective.trim()) {
6299
+ goalDriven = true;
6300
+ }
6292
6301
  let answer = "";
6293
6302
  for (let i = ordered.length - 1;i > lastUserIdx; i--) {
6294
6303
  const m = ordered[i];
@@ -6591,7 +6600,7 @@ function createMirror(deps) {
6591
6600
  mirroredTurns.set(sessionID, turnKey);
6592
6601
  return;
6593
6602
  }
6594
- const digest = buildDigest(messages);
6603
+ const digest = buildDigest(messages, deps.goalObjectiveOf?.(sessionID));
6595
6604
  if (!digest) {
6596
6605
  console.log(`[mirror] 跳过:无可摘要内容(空轮/纯工具轮)session=${sessionID}`);
6597
6606
  return;
@@ -6623,11 +6632,11 @@ function createMirror(deps) {
6623
6632
  } else {
6624
6633
  disableMirrorSubs();
6625
6634
  }
6626
- return enabled ? "✅ 摘要镜像已开启:桌面会话轮次完成后推送问答摘要" : "\uD83D\uDD07 摘要镜像已关闭(/mirror on 重新开启)";
6635
+ return enabled ? "✅ 摘要镜像已开启:桌面会话轮次完成后推送问答摘要" : "\uD83D\uDD07 摘要镜像已关闭(/status mirror on 重新开启)";
6627
6636
  },
6628
6637
  status() {
6629
6638
  const subs = mirrorUnsubs.size;
6630
- return mirrorState.enabled ? `\uD83D\uDCCB 摘要镜像:开(已挂 ${subs} 个会话订阅)` : "\uD83D\uDCCB 摘要镜像:关(/mirror on 开启)";
6639
+ return mirrorState.enabled ? `\uD83D\uDCCB 摘要镜像:开(已挂 ${subs} 个会话订阅)` : "\uD83D\uDCCB 摘要镜像:关(/status mirror on 开启)";
6631
6640
  }
6632
6641
  };
6633
6642
  return {
@@ -6771,6 +6780,51 @@ class ReminderScheduler {
6771
6780
  }
6772
6781
  }
6773
6782
 
6783
+ // src/core/turn-correction.ts
6784
+ function buildAmendPrompt(original, amendment) {
6785
+ return `${original}
6786
+
6787
+ 【补充指令】${amendment.trim()}`;
6788
+ }
6789
+ function selectAmendEntry(entries, userId, sessionId) {
6790
+ return entries.filter((e) => e.userId === userId && e.sessionId === sessionId && e.promptId && e.text).sort((a, b) => b.at - a.at)[0];
6791
+ }
6792
+ function lastUserMessageId(msgs) {
6793
+ for (let i = msgs.length - 1;i >= 0; i--) {
6794
+ if (msgs[i].type === "user" && msgs[i].id)
6795
+ return msgs[i].id;
6796
+ }
6797
+ return null;
6798
+ }
6799
+ function messageTextOf(m) {
6800
+ const c = m.content;
6801
+ if (typeof c === "string")
6802
+ return c;
6803
+ if (Array.isArray(c)) {
6804
+ return c.map((p) => typeof p === "object" && p !== null && ("text" in p) ? String(p.text ?? "") : "").join("");
6805
+ }
6806
+ return "";
6807
+ }
6808
+ function resolveBusyMode(envValue) {
6809
+ return envValue?.trim().toLowerCase() === "queue" ? "queue" : "steer";
6810
+ }
6811
+ function parseGoalState(raw) {
6812
+ const text = raw.trim();
6813
+ const jsonText = text.startsWith("{") ? text : "";
6814
+ if (!jsonText)
6815
+ return null;
6816
+ try {
6817
+ const j = JSON.parse(jsonText);
6818
+ const msg = j.message ?? "";
6819
+ if (!msg)
6820
+ return null;
6821
+ const head = msg.slice(0, 60);
6822
+ const state = /goal active|^\s*active/i.test(head) ? "active" : /paused/i.test(head) ? "paused" : /\bdone\b|complete/i.test(head) ? "done" : "unknown";
6823
+ return { state, message: msg };
6824
+ } catch {
6825
+ return null;
6826
+ }
6827
+ }
6774
6828
  // src/core/permission.ts
6775
6829
  import { existsSync as existsSync9, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "fs";
6776
6830
 
@@ -7592,6 +7646,19 @@ var UNDELIVERED_NOTICE = `(此前有未能送达的消息)
7592
7646
  var QQ_LIST_FORMAT_HINT = `
7593
7647
 
7594
7648
  (输出格式约定:本对话经 QQ 渲染,请用「1、2、3、」顿号或「-」无序列表代替 markdown 有序列表,避免表格;代码块不受影响可正常使用。)`;
7649
+ var QQ_SEND_FILE_HINT = "\n\n如需把本机文件/图片发给 QQ 用户:优先调用 qq_send_file 工具(若工具清单提供,失败会返回精确原因可据以修正);无该工具时,在回复末尾独立一行写 `QQ_SEND_FILE: <绝对路径>`(路径须在发送白名单内,默认 QQ 图片缓存目录与 bot 工作目录)。";
7650
+ function qqPromptHints() {
7651
+ try {
7652
+ const file = join9(storageRoot(), "qq-system-instructions.json");
7653
+ const st = statSync5(file);
7654
+ if (Date.now() - st.mtimeMs < 15 * 60000) {
7655
+ const parsed = JSON.parse(readFileSync11(file, "utf-8"));
7656
+ if (parsed?.mode === "entry" || parsed?.mode === "hook")
7657
+ return "";
7658
+ }
7659
+ } catch {}
7660
+ return QQ_LIST_FORMAT_HINT + QQ_SEND_FILE_HINT;
7661
+ }
7595
7662
  function qqListNormalize(text) {
7596
7663
  const lines = text.split(`
7597
7664
  `);
@@ -10066,6 +10133,78 @@ var DEFAULT_SUPERVISOR_POLICY = {
10066
10133
  claimTtlMs: 90000
10067
10134
  };
10068
10135
 
10136
+ // src/core/send-requests.ts
10137
+ import { existsSync as existsSync14, mkdirSync as mkdirSync13, readdirSync as readdirSync3, readFileSync as readFileSync16, renameSync as renameSync7, statSync as statSync10, writeFileSync as writeFileSync14 } from "node:fs";
10138
+ import { join as join12 } from "node:path";
10139
+ function sendRequestsDirFor(appId) {
10140
+ return join12(storageRoot(appId), "send-requests");
10141
+ }
10142
+ function startSendRequestConsumer(opts) {
10143
+ const dir = opts.dir ?? sendRequestsDirFor(opts.appId);
10144
+ const intervalMs = opts.intervalMs ?? 1500;
10145
+ const log = opts.log ?? (() => {});
10146
+ const seen = new Map;
10147
+ mkdirSync13(dir, { recursive: true });
10148
+ for (const f of readdirSync3(dir)) {
10149
+ if (!f.endsWith(".result.json"))
10150
+ continue;
10151
+ const full = join12(dir, f);
10152
+ try {
10153
+ const result = JSON.parse(readFileSync16(full, "utf-8"));
10154
+ const key = result.dedupeKey;
10155
+ if (key)
10156
+ seen.set(key, result);
10157
+ if (Date.now() - statSync10(full).mtimeMs > 24 * 60 * 60000)
10158
+ renameSync7(full, full + ".old");
10159
+ } catch {}
10160
+ }
10161
+ const sendFile = opts.sendFile ?? ((ctx, path) => sendLocalFile(ctx, path, { getToken: opts.getToken }));
10162
+ async function consumeOne(file) {
10163
+ const full = join12(dir, file);
10164
+ let req;
10165
+ try {
10166
+ req = JSON.parse(readFileSync16(full, "utf-8"));
10167
+ } catch {
10168
+ renameSync7(full, full + ".bad.json");
10169
+ log(`[send-requests] 坏请求已隔离: ${file}`);
10170
+ return;
10171
+ }
10172
+ const prior = seen.get(req.dedupeKey);
10173
+ const base = { id: req.id, ok: true, at: Date.now() };
10174
+ let result;
10175
+ if (prior) {
10176
+ result = { ...base, ok: prior.ok, detail: prior.detail, error: prior.error, deduped: true };
10177
+ } else {
10178
+ try {
10179
+ const ctx = opts.ctxForUser(req.userId);
10180
+ const detail = await sendFile(ctx, normalizeLocalPath(req.path));
10181
+ result = { ...base, ok: true, detail };
10182
+ } catch (error) {
10183
+ result = { ...base, ok: false, error: error instanceof Error ? error.message : String(error) };
10184
+ }
10185
+ seen.set(req.dedupeKey, { ...result, dedupeKey: req.dedupeKey });
10186
+ }
10187
+ const payload = JSON.stringify({ ...result, dedupeKey: req.dedupeKey });
10188
+ writeFileSync14(join12(dir, `${req.id}.result.tmp`), payload, "utf-8");
10189
+ renameSync7(join12(dir, `${req.id}.result.tmp`), join12(dir, `${req.id}.result.json`));
10190
+ renameSync7(full, full + ".done");
10191
+ log(`[send-requests] ${result.ok ? "已发送" : "发送失败"}${result.deduped ? "(去重)" : ""} user=${req.userId.slice(0, 8)}… path=${req.path}`);
10192
+ }
10193
+ const timer = setInterval(() => {
10194
+ let files;
10195
+ try {
10196
+ files = readdirSync3(dir).filter((f) => f.endsWith(".json") && !f.endsWith(".result.json") && !f.endsWith(".bad.json") && !f.endsWith(".done"));
10197
+ } catch {
10198
+ return;
10199
+ }
10200
+ for (const f of files) {
10201
+ consumeOne(f).catch((error) => log(`[send-requests] 消费失败 ${f}: ${error instanceof Error ? error.message : error}`));
10202
+ }
10203
+ }, intervalMs);
10204
+ timer.unref?.();
10205
+ return () => clearInterval(timer);
10206
+ }
10207
+
10069
10208
  // src/bridge.ts
10070
10209
  var QUEUE_MAX = 20;
10071
10210
  var QUEUE_RECEIPTS_ENABLED = /^(1|true|on)$/i.test(process.env.QQ_QUEUE_RECEIPTS ?? "");
@@ -10109,12 +10248,12 @@ function heartbeatDecision(lastHeartbeatAt, now, intervalMs = BG_HEARTBEAT_MS) {
10109
10248
  }
10110
10249
  function heartbeatText(execMin, idleMin, lastAction) {
10111
10250
  const action = lastAction ? `,刚才在处理【${lastAction}】` : "";
10112
- const stale = idleMin >= 30 ? `。⚠️ 注意:已 ${idleMin} 分钟没有任何动静,疑似卡住——可发 /stop 中止后重发` : "";
10251
+ const stale = idleMin >= 30 ? `。⚠️ 注意:已 ${idleMin} 分钟没有任何动静,疑似卡住——可发 /cancel 中止后重发` : "";
10113
10252
  return `⏳ 你的任务还在后台执行:已用时 ${execMin} 分钟${action}${stale}。完成后我会自动把结果发给你。`;
10114
10253
  }
10115
10254
  var MISSING_IDLE_GRACE_MS = 10 * 60000;
10116
- function missingIdleDone(turn, lastProgressAt, now, graceMs = MISSING_IDLE_GRACE_MS) {
10117
- return !turn.hasIdle && Boolean(turn.text) && now - lastProgressAt >= graceMs;
10255
+ function missingIdleDone(turn, lastProgressAt, now, graceMs = MISSING_IDLE_GRACE_MS, hasRunningTool = false) {
10256
+ return !turn.hasIdle && !hasRunningTool && Boolean(turn.text) && now - lastProgressAt >= graceMs;
10118
10257
  }
10119
10258
  var BG_STREAM_DEAD_MS_DEFAULT = 15 * 60000;
10120
10259
  var BG_TOOL_GRACE_MS_DEFAULT = 60 * 60000;
@@ -10128,6 +10267,16 @@ function resolveToolGraceMs(envValue) {
10128
10267
  const raw = Number(envValue);
10129
10268
  return Number.isFinite(raw) && raw >= 300000 && raw <= 14400000 ? Math.floor(raw) : BG_TOOL_GRACE_MS_DEFAULT;
10130
10269
  }
10270
+ function deadToolResumeHint(runningTools, abortConfirmed = true) {
10271
+ if (runningTools.length === 0)
10272
+ return "";
10273
+ const base = `
10274
+
10275
+ 【断点续作提示】上一轮在执行工具 ${runningTools.join("、")} 时中断,该工具执行结果未知(可能已生效)。重做任何写操作前,请先用只读手段核实副作用是否已发生(如查 git log、文件内容),避免重复执行。`;
10276
+ if (abortConfirmed)
10277
+ return base;
10278
+ return base + "另:上一轮中止未获确认,相关进程可能仍在运行——请先核实相关进程与副作用状态,再决定是否重做写操作。";
10279
+ }
10131
10280
  function resolveResumeMax(envValue) {
10132
10281
  if (envValue === undefined || envValue.trim() === "")
10133
10282
  return 3;
@@ -10137,37 +10286,10 @@ function resolveResumeMax(envValue) {
10137
10286
  function resumeDecision(resumeCount, max) {
10138
10287
  return max > 0 && resumeCount < max ? "resume" : "giveup";
10139
10288
  }
10140
- function resolveBusyMode(envValue) {
10141
- return envValue?.trim().toLowerCase() === "queue" ? "queue" : "steer";
10142
- }
10143
- function buildAmendPrompt(original, amendment) {
10144
- return `${original}
10145
-
10146
- 【补充指令】${amendment.trim()}`;
10147
- }
10148
- function selectAmendEntry(entries, userId, sessionId) {
10149
- return entries.filter((e) => e.userId === userId && e.sessionId === sessionId && e.promptId && e.text).sort((a, b) => b.at - a.at)[0];
10150
- }
10151
- function lastUserMessageId(msgs) {
10152
- for (let i = msgs.length - 1;i >= 0; i--) {
10153
- if (msgs[i].type === "user" && msgs[i].id)
10154
- return msgs[i].id;
10155
- }
10156
- return null;
10157
- }
10158
- function messageTextOf(m) {
10159
- const c = m.content;
10160
- if (typeof c === "string")
10161
- return c;
10162
- if (Array.isArray(c)) {
10163
- return c.map((p) => typeof p === "object" && p !== null && ("text" in p) ? String(p.text ?? "") : "").join("");
10164
- }
10165
- return "";
10166
- }
10167
- function streamLiveness(msgs, promptId, baseline, now, deadMs, toolGraceMs = BG_TOOL_GRACE_MS_DEFAULT) {
10289
+ function streamLivenessDetail(msgs, promptId, baseline, now, deadMs, toolGraceMs = BG_TOOL_GRACE_MS_DEFAULT) {
10168
10290
  const turn = turnStateOf(msgs, promptId, baseline);
10169
10291
  if (turn.hasIdle)
10170
- return "alive";
10292
+ return { state: "alive", runningTools: [] };
10171
10293
  const ordered = [...msgs].sort((a, b) => (a.time?.created ?? 0) - (b.time?.created ?? 0));
10172
10294
  let startIdx = 0;
10173
10295
  if (turn.anchored) {
@@ -10191,7 +10313,7 @@ function streamLiveness(msgs, promptId, baseline, now, deadMs, toolGraceMs = BG_
10191
10313
  }
10192
10314
  let latestActivity = 0;
10193
10315
  let anyUncompleted = false;
10194
- let anyRunningTool = false;
10316
+ const runningTools = new Set;
10195
10317
  for (let i = startIdx;i < ordered.length; i++) {
10196
10318
  const m = ordered[i];
10197
10319
  if (m.type !== "assistant")
@@ -10205,16 +10327,19 @@ function streamLiveness(msgs, promptId, baseline, now, deadMs, toolGraceMs = BG_
10205
10327
  anyUncompleted = true;
10206
10328
  for (const p of [...m.parts ?? [], ...m.content ?? []]) {
10207
10329
  if ((p.type === "tool" || p.type === undefined) && p.state?.status === "running")
10208
- anyRunningTool = true;
10330
+ runningTools.add(p.tool ?? "unknown");
10209
10331
  }
10210
10332
  }
10211
10333
  if (latestActivity === 0)
10212
- return "none";
10334
+ return { state: "none", runningTools: [] };
10213
10335
  if (!anyUncompleted)
10214
- return "alive";
10215
- if (anyRunningTool && now - latestActivity < toolGraceMs)
10216
- return "alive";
10217
- return now - latestActivity >= deadMs ? "dead" : "alive";
10336
+ return { state: "alive", runningTools: [...runningTools] };
10337
+ if (runningTools.size > 0 && now - latestActivity < toolGraceMs)
10338
+ return { state: "alive", runningTools: [...runningTools] };
10339
+ if (now - latestActivity >= deadMs) {
10340
+ return { state: runningTools.size > 0 ? "dead-tool" : "dead", runningTools: [...runningTools] };
10341
+ }
10342
+ return { state: "alive", runningTools: [...runningTools] };
10218
10343
  }
10219
10344
  function assistantTextOf(m) {
10220
10345
  return (m.content ?? []).filter((p) => p.type === "text" && p.text?.trim()).map((p) => p.text ?? "").join(`
@@ -10454,18 +10579,19 @@ ${text}` : "\uD83D\uDCE4 后台任务完成(无文本产出),详情可用
10454
10579
  await safeDeliver(ctx, `⚠️ 后台任务底层执行多次失去响应(已自动续作 ${resumeCount} 次仍失败),停止自动跟进;队列已放行。如仍需要该结果请重新发送`).catch(() => {});
10455
10580
  console.log(`[bridge] 后台回合流活性丧失:续作${resumeCount}次仍死,expired 结清 session=${sessionId} msg=${shortId(trackId)}`);
10456
10581
  }
10457
- async function resumeDead() {
10582
+ async function resumeDead(hint = "", abortConfirmed = true) {
10458
10583
  if (cancelled || finished)
10459
10584
  return;
10460
10585
  resumeCount += 1;
10461
10586
  console.log(`[bridge] 后台死回合自动续作 #${resumeCount}/${MAX_RESUME} session=${sessionId} msg=${shortId(trackId)}`);
10462
- await safeDeliver(ctx, `⚠️ 后台任务底层执行失去响应,已自动中止并续作(第 ${resumeCount}/${MAX_RESUME} 次);继续后台跟踪,完成自动回传`).catch(() => {});
10587
+ const notice = abortConfirmed ? `⚠️ 后台任务底层执行失去响应,已中止旧回合并续作(第 ${resumeCount}/${MAX_RESUME} 次);继续后台跟踪,完成自动回传` : `⚠️ 后台任务底层执行失去响应,已请求中止旧回合(未获已停止确认,旧进程可能仍在运行)并续作(第 ${resumeCount}/${MAX_RESUME} 次);继续后台跟踪,完成自动回传`;
10588
+ await safeDeliver(ctx, notice).catch(() => {});
10463
10589
  try {
10464
10590
  const prepared = ctx.preparedAttachments ?? await prepareQQAttachments(ctx.attachments, () => getAccessToken(config.qq.appId, config.qq.clientSecret));
10465
10591
  const { text: promptBody, files } = augmentPromptWithAttachments(ctx.content, prepared);
10466
10592
  const promptText = (ctx.quoteText ? `> 引用上文:${ctx.quoteText}
10467
10593
 
10468
- ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10594
+ ${promptBody}` : promptBody) + qqPromptHints() + hint;
10469
10595
  client.promptAndWait(sessionId, promptText, {
10470
10596
  files: files.length ? files : undefined,
10471
10597
  directory: anchorDirectory,
@@ -10539,13 +10665,13 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10539
10665
  console.log(`[bridge] 后台任务进度心跳 session=${sessionId} execMin=${hbExecMin} idleMin=${hbIdleMin}`);
10540
10666
  safeDeliver(ctx, heartbeatText(hbExecMin, hbIdleMin, hbAction)).catch(() => {});
10541
10667
  }
10542
- const live = streamLiveness(msgs, promptId, baseline, now, STREAM_DEAD_MS, TOOL_GRACE_MS);
10543
- if (live === "dead") {
10544
- await client.session.abort({ path: { id: sessionId } }).catch(() => {
10545
- return;
10546
- });
10668
+ const probe = streamLivenessDetail(msgs, promptId, baseline, now, STREAM_DEAD_MS, TOOL_GRACE_MS);
10669
+ const live = probe.state;
10670
+ if (live === "dead" || live === "dead-tool") {
10671
+ const abortConfirmed = await client.session.abort({ path: { id: sessionId } }).then(() => true).catch(() => false);
10672
+ console.log(`[bridge] 判死处置 session=${sessionId} live=${live} abortConfirmed=${abortConfirmed} resumeCount=${resumeCount}`);
10547
10673
  if (resumeDecision(resumeCount, MAX_RESUME) === "resume") {
10548
- await resumeDead();
10674
+ await resumeDead(live === "dead-tool" ? deadToolResumeHint(probe.runningTools, abortConfirmed) : "", abortConfirmed);
10549
10675
  } else {
10550
10676
  await finishDead();
10551
10677
  }
@@ -10553,7 +10679,7 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10553
10679
  }
10554
10680
  if (turn.superseded) {
10555
10681
  await finish("superseded");
10556
- } else if (turn.hasIdle || missingIdleDone(turn, lastProgressAt, now)) {
10682
+ } else if (turn.hasIdle || missingIdleDone(turn, lastProgressAt, now, MISSING_IDLE_GRACE_MS, probe.runningTools.length > 0)) {
10557
10683
  await finish("done");
10558
10684
  }
10559
10685
  } catch (error) {
@@ -10587,7 +10713,7 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10587
10713
  saveWatchedMap(activeWatches, storageAppId ? roleFile("watch.json") : undefined);
10588
10714
  return [
10589
10715
  `\uD83D\uDC41 已开启观察:${sessionID}`,
10590
- "该会话的工具调用/执行完成会实时推送摘要,/watch off 停止。",
10716
+ "该会话的工具调用/执行完成会实时推送摘要,/status watch off 停止。",
10591
10717
  "(≥2 秒节流合并;QQ 主动消息有日配额,被动窗口内不受限)"
10592
10718
  ].join(`
10593
10719
  `);
@@ -10619,6 +10745,44 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10619
10745
  }
10620
10746
  };
10621
10747
  const cronScheduler = new ReminderScheduler;
10748
+ const goalStates = new Map;
10749
+ const goalKickoffs = new Map;
10750
+ const GOAL_WATCH_INTERVAL_MS = 5 * 60000;
10751
+ const GOAL_NOTIFY_DEDUP_MS = 30 * 60000;
10752
+ let lastGoalWatchAt = 0;
10753
+ async function goalWatchTick() {
10754
+ if (Date.now() - lastGoalWatchAt < GOAL_WATCH_INTERVAL_MS)
10755
+ return;
10756
+ lastGoalWatchAt = Date.now();
10757
+ for (const s of sessions.all()) {
10758
+ const prev = goalStates.get(s.sessionId);
10759
+ if (!prev)
10760
+ continue;
10761
+ try {
10762
+ let raw = null;
10763
+ try {
10764
+ const res = await client.session.command({ path: { id: s.sessionId }, body: { name: "goal", text: "" } });
10765
+ raw = JSON.stringify(res);
10766
+ } catch (error) {
10767
+ raw = error.body ?? null;
10768
+ }
10769
+ const parsed = raw ? parseGoalState(raw) : null;
10770
+ if (!parsed)
10771
+ continue;
10772
+ const transitionToTerminal = (parsed.state === "paused" || parsed.state === "done") && prev.state === "active" && (!prev.notified || Date.now() - prev.at > GOAL_NOTIFY_DEDUP_MS);
10773
+ if (parsed.state === "active") {
10774
+ goalStates.set(s.sessionId, { state: "active", at: Date.now(), notified: false });
10775
+ } else if (transitionToTerminal) {
10776
+ goalStates.set(s.sessionId, { state: parsed.state, at: Date.now(), notified: true });
10777
+ const head = parsed.state === "done" ? "✅ 目标已达成" : "\uD83C\uDFAF 目标已暂停";
10778
+ safeDeliver(ctxForUser(s.userId), `${head}(${s.sessionId})
10779
+ ${parsed.message.slice(0, 400)}
10780
+ ——发 /goal 看详情;resume 继续 / clear 放弃`).catch(() => {});
10781
+ console.log(`[goal-watch] 状态转变通知 user=${s.userId.slice(0, 8)}… state=${parsed.state}`);
10782
+ }
10783
+ } catch {}
10784
+ }
10785
+ }
10622
10786
  const perm = createPermissionGate({
10623
10787
  client,
10624
10788
  sendReply,
@@ -10646,6 +10810,16 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10646
10810
  return digest;
10647
10811
  registerCron(userId, hit);
10648
10812
  return hit.cleanedText;
10813
+ },
10814
+ goalObjectiveOf: (sessionID) => {
10815
+ const k = goalKickoffs.get(sessionID);
10816
+ if (!k)
10817
+ return;
10818
+ if (Date.now() - k.at > 30 * 60000) {
10819
+ goalKickoffs.delete(sessionID);
10820
+ return;
10821
+ }
10822
+ return k.text;
10649
10823
  }
10650
10824
  });
10651
10825
  function registerCron(userId, hit) {
@@ -10684,6 +10858,27 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10684
10858
  const n = Number(process.env.QQ_INTERACTION_WATCH_SECONDS ?? "12");
10685
10859
  return Number.isFinite(n) && n >= 0 ? Math.floor(n * 1000) : 12000;
10686
10860
  })();
10861
+ const pollFails = new Map;
10862
+ const httpStatusOf = (error) => {
10863
+ const m = error instanceof Error ? error.message : String(error);
10864
+ const hit = /API\s+(\d{3})/.exec(m);
10865
+ return hit ? Number(hit[1]) : undefined;
10866
+ };
10867
+ const notePollResult = (userId, sessionId, ok, status) => {
10868
+ const key = `${userId}|${sessionId}`;
10869
+ if (ok) {
10870
+ pollFails.delete(key);
10871
+ return;
10872
+ }
10873
+ if (status !== 400 && status !== 404)
10874
+ return;
10875
+ const n = (pollFails.get(key) ?? 0) + 1;
10876
+ pollFails.set(key, n);
10877
+ if (n >= 3) {
10878
+ pollFails.delete(key);
10879
+ sessions.evict(userId);
10880
+ }
10881
+ };
10687
10882
  function usersOfSession(sessionID) {
10688
10883
  return sessions.all().filter((e) => e.sessionId === sessionID).map((e) => e.userId);
10689
10884
  }
@@ -10692,9 +10887,14 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10692
10887
  }
10693
10888
  async function interactionTick() {
10694
10889
  try {
10890
+ goalWatchTick().catch(() => {});
10695
10891
  {
10696
10892
  const seen = new Map;
10697
- const lists = await Promise.all(sessions.all().map((entry) => client.permission.forSession(entry.sessionId).catch(() => {
10893
+ const lists = await Promise.all(sessions.all().map((entry) => client.permission.forSession(entry.sessionId).then((res) => {
10894
+ notePollResult(entry.userId, entry.sessionId, true);
10895
+ return res;
10896
+ }, (error) => {
10897
+ notePollResult(entry.userId, entry.sessionId, false, httpStatusOf(error));
10698
10898
  return;
10699
10899
  })));
10700
10900
  for (const res of lists) {
@@ -10717,7 +10917,11 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10717
10917
  }
10718
10918
  {
10719
10919
  for (const entry of sessions.all()) {
10720
- const forms = (await client.form.list({ sessionID: entry.sessionId }).catch(() => {
10920
+ const forms = (await client.form.list({ sessionID: entry.sessionId }).then((res) => {
10921
+ notePollResult(entry.userId, entry.sessionId, true);
10922
+ return res;
10923
+ }, (error) => {
10924
+ notePollResult(entry.userId, entry.sessionId, false, httpStatusOf(error));
10721
10925
  return;
10722
10926
  }))?.data ?? [];
10723
10927
  for (const form of forms) {
@@ -10961,6 +11165,12 @@ ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
10961
11165
  }
10962
11166
  }, ORPHAN_SCAN_MS);
10963
11167
  }
11168
+ startSendRequestConsumer({
11169
+ appId: config.qq.appId,
11170
+ ctxForUser,
11171
+ getToken: () => getAccessToken(config.qq.appId, config.qq.clientSecret),
11172
+ log: (line) => console.log(line)
11173
+ });
10964
11174
  const REAPER_SCAN_MS = (() => {
10965
11175
  const n = Number(process.env.QQ_REAPER_SCAN_SECONDS ?? "60");
10966
11176
  return Number.isFinite(n) && n > 0 ? Math.floor(n * 1000) : 0;
@@ -11198,6 +11408,16 @@ ${box}`;
11198
11408
  if (reply)
11199
11409
  return reply;
11200
11410
  if (name === "goal") {
11411
+ const t = text.trim();
11412
+ if (/^clear/i.test(t)) {
11413
+ goalKickoffs.delete(session.sessionId);
11414
+ goalStates.delete(session.sessionId);
11415
+ } else if (t && !/^(pause|resume|status)?$/i.test(t)) {
11416
+ goalKickoffs.set(session.sessionId, { text: t, at: Date.now() });
11417
+ goalStates.set(session.sessionId, { state: "active", at: Date.now(), notified: false });
11418
+ } else if (/^resume/i.test(t)) {
11419
+ goalStates.set(session.sessionId, { state: "active", at: Date.now(), notified: false });
11420
+ }
11201
11421
  return "✅ goal 已执行(引擎无文本回执)。查状态再发 /goal;控制用 /goal pause|resume|clear。设定目标后会话自主续跑,进展会以普通回复推送到这里";
11202
11422
  }
11203
11423
  return `✅ /${name} 已执行(引擎无文本回执)`;
@@ -11205,15 +11425,12 @@ ${box}`;
11205
11425
  const msg = toErrorMessage2(error);
11206
11426
  if (name === "goal") {
11207
11427
  const full = error.body ?? msg;
11208
- const trimmed = full.trim();
11209
- const jsonText = trimmed.startsWith("{") ? trimmed : /\{[\s\S]*"message"[\s\S]*\}/.exec(full)?.[0] ?? "";
11210
- if (jsonText) {
11211
- try {
11212
- const j = JSON.parse(jsonText);
11213
- if (j.message)
11214
- return `\uD83D\uDCCB 目标状态(goal ${j.command ?? ""}):
11215
- ${j.message}`;
11216
- } catch {}
11428
+ const parsed = parseGoalState(full);
11429
+ if (parsed) {
11430
+ if (parsed.state === "active")
11431
+ goalStates.set(session.sessionId, { state: "active", at: Date.now(), notified: false });
11432
+ return `\uD83D\uDCCB 目标状态(goal):
11433
+ ${parsed.message}`;
11217
11434
  }
11218
11435
  }
11219
11436
  return `引擎命令执行失败(/goal 需 OpenCode ≥ 2.2.1):${msg}`;
@@ -11425,7 +11642,7 @@ ${j.message}`;
11425
11642
  const { text: promptBody, files } = augmentPromptWithAttachments(content, prepared);
11426
11643
  const promptText = (ctx.quoteText ? `> 引用上文:${ctx.quoteText}
11427
11644
 
11428
- ${promptBody}` : promptBody) + QQ_LIST_FORMAT_HINT;
11645
+ ${promptBody}` : promptBody) + qqPromptHints();
11429
11646
  trackId = ctx.msgId || `redispatch-${sessionId}-${turnStart}`;
11430
11647
  inflight.record({ msgId: trackId, userId: ctx.userId, sessionId, text: content.slice(0, 300), at: Date.now() });
11431
11648
  inflight.markStage(trackId, "dispatched", { sessionId });
@@ -11527,7 +11744,7 @@ ${rescuedText}`).catch(() => {});
11527
11744
  } else if (isSessionBusyError(error)) {
11528
11745
  console.error(`[bridge] 会话被占用(active prompt)sid=${shortId(sessionId)}: ${toErrorMessage2(error)}`);
11529
11746
  await safeDeliver(ctx, `⏳ 该会话正有回合在执行(可能是桌面端在跑,或上一轮尚未结束),本轮未重复发起。
11530
- 发 /stop 可中止当前回合后重试。`);
11747
+ 发 /cancel 可中止当前回合后重试。`);
11531
11748
  inflight.settle(trackId, undefined, "error");
11532
11749
  } else {
11533
11750
  const errText = toErrorMessage2(error);
@@ -11765,8 +11982,8 @@ function isAllowedUser(userId, allowedUsers) {
11765
11982
  var WATCH_FILE = storageFile("watch.json");
11766
11983
  function loadWatchedMap(file = WATCH_FILE) {
11767
11984
  try {
11768
- if (existsSync14(file)) {
11769
- const raw = readFileSync16(file, "utf-8");
11985
+ if (existsSync15(file)) {
11986
+ const raw = readFileSync17(file, "utf-8");
11770
11987
  const obj = JSON.parse(raw);
11771
11988
  if (obj && typeof obj === "object" && !Array.isArray(obj)) {
11772
11989
  const out = {};
@@ -11781,7 +11998,7 @@ function loadWatchedMap(file = WATCH_FILE) {
11781
11998
  }
11782
11999
  function saveWatchedMap(m, file = WATCH_FILE) {
11783
12000
  try {
11784
- writeFileSync14(file, JSON.stringify(Object.fromEntries(m), null, 2));
12001
+ writeFileSync15(file, JSON.stringify(Object.fromEntries(m), null, 2));
11785
12002
  } catch (error) {
11786
12003
  console.warn("[watch] 持久化失败:", error instanceof Error ? error.message : error);
11787
12004
  }
@@ -11789,8 +12006,8 @@ function saveWatchedMap(m, file = WATCH_FILE) {
11789
12006
  var GREETED_FILE = storageFile("greeted.json");
11790
12007
  function loadGreetedSet(file = GREETED_FILE) {
11791
12008
  try {
11792
- if (existsSync14(file)) {
11793
- const raw = readFileSync16(file, "utf-8");
12009
+ if (existsSync15(file)) {
12010
+ const raw = readFileSync17(file, "utf-8");
11794
12011
  const arr = JSON.parse(raw);
11795
12012
  if (Array.isArray(arr)) {
11796
12013
  return new Set(arr.filter((x) => typeof x === "string"));
@@ -11801,8 +12018,8 @@ function loadGreetedSet(file = GREETED_FILE) {
11801
12018
  }
11802
12019
  function saveGreetedSet(set, file = GREETED_FILE) {
11803
12020
  try {
11804
- mkdirSync13(join12(homedir7(), ".openqq"), { recursive: true });
11805
- writeFileSync14(file, JSON.stringify([...set]));
12021
+ mkdirSync14(join13(homedir7(), ".openqq"), { recursive: true });
12022
+ writeFileSync15(file, JSON.stringify([...set]));
11806
12023
  } catch (error) {
11807
12024
  console.error("[bridge] 保存 greeted 失败:", error);
11808
12025
  }
@@ -11900,7 +12117,7 @@ async function main() {
11900
12117
  const raw = (process.env.QQ_LOG_FILE ?? "").trim();
11901
12118
  if (!/^(0|off|false|no)$/i.test(raw)) {
11902
12119
  await Promise.resolve().then(() => init_file_log());
11903
- installFileLog(raw || join13(homedir8(), ".openqq", "openqq.log"));
12120
+ installFileLog(raw || join14(homedir8(), ".openqq", "openqq.log"));
11904
12121
  }
11905
12122
  }
11906
12123
  await ensureConfig();
@@ -11933,11 +12150,11 @@ async function main() {
11933
12150
  if (resolvedInitial.source !== "explicit") {
11934
12151
  console.log(`[index] 未配置 OPENCODE_BASE_URL,初始地址=${resolvedInitial.source === "last-discovered" ? "上次自动发现" : "占位"} ${resolvedInitial.url}(失联时自动端口发现纠正)`);
11935
12152
  }
11936
- const heartbeatFile = join13(homedir8(), ".openqq", "heartbeat");
12153
+ const heartbeatFile = join14(homedir8(), ".openqq", "heartbeat");
11937
12154
  const touchHeartbeat = () => {
11938
12155
  try {
11939
- mkdirSync14(join13(homedir8(), ".openqq"), { recursive: true });
11940
- writeFileSync15(heartbeatFile, String(Date.now()));
12156
+ mkdirSync15(join14(homedir8(), ".openqq"), { recursive: true });
12157
+ writeFileSync16(heartbeatFile, String(Date.now()));
11941
12158
  } catch (error) {
11942
12159
  console.error("[index] 心跳写入失败:", error);
11943
12160
  }