dsh-fish-soul 0.15.52 → 0.15.53

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  让一个 QQ 小号背后有"同一个人":固定人格、按人记记忆、有自己的生活节奏、会主动开口;同一个"她"同时出现在 QQ、B站、抖音。
4
4
 
5
- DSH 插件(单角色 `feiyu`)。版本 **0.15.52**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.15.53**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
@@ -74,7 +74,7 @@ dsh plugin --profile desktop add dsh-fish-soul
74
74
 
75
75
  **一键回退**:`lib/channels/douyin.js` 的 `DOUYIN_IDENTITY_BLOCKED` 设成 `true` 即恢复成「私信一律不处理、不发送」。
76
76
 
77
- 收件读取前会记录读取意图;读取失败或中断时提示抖音可能已标记已读但消息未入库。收件记录与游标以事务写入;处理中的任务中断后标记为结果未知,同会话后续待处理消息会等待人工核实。身份暂停期间不可重试,可核实后忽略。窗口不重叠时会提示可能有缺口,但无法保证发现所有缺失;上游在入库前可能已标记消息已读,警告不能找回消息,也不能保证完整收取或恰好执行一次。现有接口缓存可能跨会话混入数据,待核实消息的会话名和来源都不可信,不应据此自动关联身份。
77
+ 收件读取前会记录读取意图;读取失败或中断时会记一条缺口(设置页不再展示这类提示,缺口 7 天后自动清理)。收件记录与游标以事务写入;处理中的任务中断后标记为结果未知,同会话后续待处理消息会等它 —— 设置页不再提供人工核实,结果未知超过 24 小时自动作废,那个会话才继续走。窗口不重叠时只记缺口,无法保证发现所有缺失;上游在入库前可能已标记消息已读,缺口记录不能找回消息,也不能保证完整收取或恰好执行一次。现有接口缓存可能跨会话混入数据,待核实消息的会话名和来源都不可信,不应据此自动关联身份。
78
78
 
79
79
  ### 原生视频卡片分享
80
80
 
@@ -897,13 +897,13 @@ export class DouyinChannel {
897
897
  * @param {[number, number]} [deps.pollRangeMs]
898
898
  * @param {[number, number]} [deps.typingMs] 打字延迟(基础下限 / 上限)
899
899
  */
900
- constructor({ host, db, getConfig, log, onMessage, notify, driver, pollRangeMs = [30_000, 60_000], typingMs = [1500, 3000], firstPollMs = 5000 }) {
900
+ constructor({ host, db, getConfig, log, onMessage, notify, driver, diag, pollRangeMs = [30_000, 60_000], typingMs = [1500, 3000], firstPollMs = 5000 }) {
901
901
  this.host = host;
902
902
  this.db = db;
903
903
  this.getConfig = getConfig;
904
904
  this.log = log ?? (() => {});
905
905
  this.onMessage = onMessage;
906
- this.inbox = new DouyinInbox(db);
906
+ this.inbox = new DouyinInbox(db, diag);
907
907
  this.drainingInbox = false;
908
908
  this.notify = notify ?? (() => {});
909
909
  this.driver = driver ?? pageDriver(host);
@@ -953,11 +953,9 @@ export class DouyinChannel {
953
953
  identityState: {
954
954
  disabledByFlag: DOUYIN_IDENTITY_BLOCKED,
955
955
  knowsSelfUid: this.selfUids().length > 0,
956
- // 🔴 把学到的 uid **显示出来**。以前只给一个布尔值,于是
957
- // 「主人身份」要填的数字 uid,新用户根本无从得知 ——
958
- // 设置页那句「从私信待核实里能看到」在还没收到过私信时是空话。
959
- // 插件其实能从任意一条私信里学到自己是谁(`learnSelfUid`),
960
- // 这里把结果交出去,用户照着复制进「主人身份」就行。
956
+ // 🔴 把学到的 uid **显示出来**。以前只给一个布尔值,用户无从知道
957
+ // 这个抖音号自己是谁。插件能从任意一条私信里学到自己是谁(`learnSelfUid`),
958
+ // 这里把结果交出去 —— 注意这是**机器人自己**的 uid,不是用户的。
961
959
  selfUids: this.selfUids(),
962
960
  conversationIdSupported: true
963
961
  },
@@ -1362,6 +1360,10 @@ export class DouyinChannel {
1362
1360
  // 面板上看着像消息丢了。放这里(每轮轮询一次)而不是 drainInbox 里 ——
1363
1361
  // drainInbox 有自己的队列语义,插一条批量 UPDATE 会打乱 next() 的顺序。
1364
1362
  try { this.inbox.reclaimStuck?.(); } catch { /* 回收失败不影响这一轮轮询 */ }
1363
+ // 设置页不再展示「私信待核实」和「私信可能遗漏」两块提示(主人要求去掉噪音),
1364
+ // 用户没法再逐条核实 ⇒ 超期的 unknown 只能自动作废,否则它会挡住整个会话;
1365
+ // 没人点「已知晓」的缺口记录也定期清掉,免得表单调增长。
1366
+ try { this.inbox.expireStaleUnknown?.(); this.inbox.pruneGaps?.(); } catch { /* 过期失败不影响这一轮轮询 */ }
1365
1367
  const loggedIn = await this.driver.checkLogin();
1366
1368
  this.host.loggedIn = loggedIn;
1367
1369
  if (!loggedIn) {
@@ -1714,10 +1716,10 @@ export class DouyinChannel {
1714
1716
  } catch { /* 记不下来不影响这一轮 */ }
1715
1717
  // 判据保持「这次读到的消息一条都不在上次窗口里」= 窗口对不齐。
1716
1718
  // ⚠️ 这条在「正常来新消息」时也会命中(抖音只返回最近几条,旧的滚出去了),
1717
- // 所以面板上会看到误报的「私信可能遗漏」。曾试着加「窗口变小」条件收紧,
1718
- // 但那会把「上次窗口只有 1 条、这次读到 2 条全新的」这种**真可能漏收**的场景
1719
+ // 所以会**误报**缺口。曾试着加「窗口变小」条件收紧,但那会把
1720
+ // 「上次窗口只有 1 条、这次读到 2 条全新的」这种**真可能漏收**的场景
1719
1721
  // 也一起放过(test/douyin-inbox.mjs 的契约就红在这)。
1720
- // 取舍:宁可误报(面板噪音,一键「已知晓」即可),不能漏报(真丢消息)。
1722
+ // 取舍:宁可误报(只多记一条缺口,7 天后自动清理),不能漏报(真丢消息)。
1721
1723
  const hasWindowGap = st !== null && Array.isArray(st.window) && st.window.length > 0 && prints.length > 0 && !prints.some(p => st.window.includes(p));
1722
1724
  // 游标带上会话身份:以后哪怕昵称变了,也知道这仍是同一个会话。
1723
1725
  const cursor = { name, sig, convId, identity, window: prints.slice(-WINDOW_KEEP), readAt: Date.now(), ...(group ? { group: true, members } : {}) };
@@ -56,8 +56,10 @@ window.__ModuleLoader__.load({
56
56
  if (d.step !== undefined) bits.push(`第 ${d.step} 步${d.name ? `「${d.name}」` : ""}`);
57
57
  if (d.sessionId) bits.push(`会话 ${String(d.sessionId).slice(0, 12)}…`);
58
58
  if (d.channelId) bits.push(`聊天 ${d.channelId}`);
59
+ if (d.count !== undefined) bits.push(`${d.count} 条`);
59
60
  if (d.chars !== undefined) bits.push(`${d.chars} 字${d.budget ? ` / 预算 ${d.budget}` : ""}${d.over80 ? "(超 80%)" : ""}`);
60
61
  if (d.reason) bits.push(String(d.reason).slice(0, 120));
62
+ if (d.error) bits.push(String(d.error).slice(0, 120));
61
63
  if (e.count > 1) bits.push(`重复 ${e.count} 次`);
62
64
  return bits.join(",") || "(没有细节)";
63
65
  };
@@ -148,17 +148,8 @@ window.__ModuleLoader__.load({
148
148
  : Row({ title: "私信按会话认人", desc: `身份用会话 ID 判定(\`0:1:我方:对方\`),昵称只作展示:改名、同名都不会串人。发送前会用会话 ID 校验目标,拿不到就发不出去,不会发给错的人。${(d.channel?.identityState?.selfUids ?? []).length ? `\n这个抖音号自己的 uid:${(d.channel.identityState.selfUids).join(" / ")}(下面「主人身份」要填的就是你自己那个数字 uid)` : ""}` }),
149
149
  Row({ title: "抖音接入" }, poll, sw("抖音接入", d.enabled === true, (v) => save({ top: { enabled: v } }))),
150
150
  Row({ title: "自动回复" }, d.autoReply ? null : Muted("只记不回"), sw("自动回复", d.autoReply === true, (v) => save({ top: { autoReply: v } }))),
151
- ...(d.channel?.inbox?.gaps ?? []).map((g) => Row({ title: `私信可能遗漏 · ${g.channelId}`, desc: g.reason },
152
- Button({ variant: "ghost", disabled: busy, onClick: () => act("/douyin/inbox-gap-ack", { id: g.id }, "已知晓", "操作失败") }, "已知晓"))),
153
- (d.channel?.inbox?.gapCount ?? 0) > 10 ? Row({ title: `另有 ${d.channel.inbox.gapCount - 10} 条遗漏提示`, desc: "列表只显示前 10 条" },
154
- Button({ variant: "ghost", disabled: busy, onClick: () => act("/douyin/inbox-gap-ack", {}, "已全部标记知晓", "操作失败") }, "全部已知晓")) : null,
155
- ...(d.channel?.inbox?.review ?? []).map((m) => Row({ title: `私信待核实 · ${m.channelId}`, desc: `会话名及消息来源均未验证,可能串会话;处理也可能已产生副作用。请先到抖音核实:${m.text}` },
156
- Button({ variant: "ghost", disabled: busy || d.channel?.identityBlocked === true, onClick: () => act("/douyin/inbox-resolve", { id: m.id, action: "retry" }, "已安排下次轮询重新处理", "操作失败") }, "核实未处理,重新处理"),
157
- Button({ variant: "ghost", disabled: busy, onClick: () => act("/douyin/inbox-resolve", { id: m.id, action: "dismiss" }, "已忽略", "操作失败") }, "已核实,忽略"))),
158
- (d.channel?.inbox?.counts?.unknown ?? 0) > 10 ? Row({ title: `另有 ${d.channel.inbox.counts.unknown - 10} 条待核实`, desc: "一条待核实会挡住同会话后面所有消息;身份暂停期间不能重试,核实过就可以全部忽略" },
159
- Button({ variant: "ghost", disabled: busy, onClick: () => act("/douyin/inbox-dismiss-all", {}, "已全部忽略", "操作失败") }, "已核实,全部忽略")) : null,
160
151
  (d.channel?.inbox?.counts?.processing ?? 0) > 0 ? Muted(`正在处理 ${d.channel.inbox.counts.processing} 条;如果长时间不变,重启后核实`) : null,
161
- Row({ title: "主人身份(可选)", desc: `填**你自己**的抖音数字 uid,她就认得出「你是主人」:私聊里标「(主人)」,可以主动给你发视频卡片、把 B站/抖音会话并进你的 QQ 私聊。**不填也能正常收私信、记记忆、回复** —— 认人靠的是会话 ID,不是这个字段。${(d.channel?.identityState?.selfUids ?? []).length ? `\n注意:上面显示的是这个抖音号(机器人自己)的 uid,不是你的。` : ""}拿自己的 uid:用你的账号给这个抖音号发一条私信,然后在下面「私信待核实」里看对方的 uid。昵称可被同名冒充、改名又会对不上,所以不参与授权。只填数字就行,前缀会自动补。` },
152
+ Row({ title: "主人身份(可选)", desc: `填**你自己**的抖音数字 uid,她就认得出「你是主人」:私聊里标「(主人)」,可以主动给你发视频卡片、把 B站/抖音会话并进你的 QQ 私聊。**不填也能正常收私信、记记忆、回复** —— 认人靠的是会话 ID,不是这个字段。${(d.channel?.identityState?.selfUids ?? []).length ? `\n注意:上面显示的是这个抖音号(机器人自己)的 uid,不是你的。` : ""}昵称可被同名冒充、改名又会对不上,所以不参与授权。只填数字就行,前缀会自动补。` },
162
153
  Input({ ...bind("masterUid"), placeholder: "7702399256389125000" })),
163
154
  Row({ title: "主人的名字", desc: "仅作显示(提示词里怎么称呼);不授予任何权限" }, Input({ ...bind("masterName"), placeholder: "她私信列表里你的名字" })),
164
155
  Row({ title: "回所有能私信她的人", desc: d.replyAll ? "建议在抖音隐私设置里把「谁可以私信我」设为互关好友" : null },
package/lib/diag-log.js CHANGED
@@ -27,6 +27,8 @@ const DEDUPE_MS = 60_000;
27
27
  * 每条日志的中文说法。key 是稳定的机器标识,人话在这里查。
28
28
  * 加新 key 时**必须**在这里补一条,否则界面会显示成 key 本身(这是故意的:
29
29
  * 宁可露出机器名,也别悄悄显示成空白让人以为没发生)。
30
+ *
31
+ * key 带会话后缀(`基础:会话名`)时回落到基础那条说法(见 labelOf)。
30
32
  */
31
33
  const LABELS = {
32
34
  'startup-step': '启动到某一步',
@@ -41,9 +43,26 @@ const LABELS = {
41
43
  'image-skip': '图片没送进模型',
42
44
  'sticker-skip': '表情没收藏成功',
43
45
  'turn-no-recall': '这一轮没组装记忆',
44
- 'config-invalid': '配置文件读不懂'
46
+ 'config-invalid': '配置文件读不懂',
47
+ // 抖音私信的两类提示:设置页那块已经删了(主人嫌吵),落到这里来查。
48
+ 'douyin-inbox-gap': '抖音私信可能有遗漏',
49
+ 'douyin-inbox-unknown': '抖音私信待核实'
45
50
  };
46
51
 
52
+ /**
53
+ * 人话:key 精确命中就用它;带会话后缀的(`基础:会话名`)回落到基础那条说法。
54
+ * 都没有就显示机器名 —— 宁可露出机器名,也别让人以为没发生。
55
+ */
56
+ function labelOf(key) {
57
+ if (LABELS[key]) return LABELS[key];
58
+ const i = key.indexOf(':');
59
+ if (i > 0) {
60
+ const base = key.slice(0, i);
61
+ if (LABELS[base]) return LABELS[base];
62
+ }
63
+ return key;
64
+ }
65
+
47
66
  export class DiagLog {
48
67
  /**
49
68
  * @param {{ db: object, log?: Function, now?: () => number }} deps
@@ -102,7 +121,7 @@ export class DiagLog {
102
121
  return [...this.entries].reverse().slice(0, limit).map((e) => ({
103
122
  at: e.at,
104
123
  key: e.key,
105
- label: LABELS[e.key] ?? e.key,
124
+ label: labelOf(e.key),
106
125
  level: e.level,
107
126
  detail: e.detail,
108
127
  count: e.count
@@ -123,8 +142,10 @@ export function describeEntry(entry) {
123
142
  if (d.step !== undefined) bits.push(`第 ${d.step} 步${d.name ? `「${d.name}」` : ''}`);
124
143
  if (d.sessionId) bits.push(`会话 ${String(d.sessionId).slice(0, 12)}…`);
125
144
  if (d.channelId) bits.push(`聊天 ${d.channelId}`);
145
+ if (d.count !== undefined) bits.push(`${d.count} 条`);
126
146
  if (d.chars !== undefined) bits.push(`${d.chars} 字${d.budget ? ` / 预算 ${d.budget}` : ''}${d.over80 ? '(超 80%)' : ''}`);
127
147
  if (d.reason) bits.push(String(d.reason).slice(0, 120));
148
+ if (d.error) bits.push(String(d.error).slice(0, 120));
128
149
  if (entry.count > 1) bits.push(`重复 ${entry.count} 次`);
129
150
  return bits.join(',') || '(没有细节)';
130
151
  }
@@ -1,9 +1,25 @@
1
1
  import { setKv } from './db.js';
2
2
 
3
+ /**
4
+ * 缺口(私信可能遗漏)的固定说法。
5
+ * 设置页那块提示已经删了(主人嫌吵),这些说法落到系统页「运行日志」里。
6
+ */
7
+ const GAP_STALE = '上次读取未完成,抖音可能已标记为已读但消息未入库,请手动检查';
8
+ const GAP_INTERRUPTED = '读取过程中断,抖音可能已标记为已读但消息未入库,请手动检查';
9
+ const GAP_UNREAD_TAIL = '抖音可能已标记为已读但消息未入库,请手动检查';
10
+ /** 重启前卡在 processing 的消息:处理结果不确定,要主人核实。 */
11
+ const UNKNOWN_INTERRUPTED = '处理过程中断,可能已产生回复或其他操作';
12
+
3
13
  /** Durable handoff. Processing interrupted after callback starts is ambiguous. */
4
14
  export class DouyinInbox {
5
- constructor(db) {
15
+ /**
16
+ * @param {object} db
17
+ * @param {{ add: (key: string, detail?: object, level?: string) => void } | null} [diag]
18
+ * 运行日志(可选):设置页不显示缺口 / 待核实了,排查还得查得到,落这儿。
19
+ */
20
+ constructor(db, diag = null) {
6
21
  this.db = db;
22
+ this.diag = diag ?? null;
7
23
  db.exec(`CREATE TABLE IF NOT EXISTS douyin_inbox (
8
24
  id INTEGER PRIMARY KEY AUTOINCREMENT, channel_id TEXT NOT NULL, message_id TEXT NOT NULL,
9
25
  payload TEXT NOT NULL, status TEXT NOT NULL, error TEXT NOT NULL DEFAULT '',
@@ -11,34 +27,77 @@ export class DouyinInbox {
11
27
  ); CREATE INDEX IF NOT EXISTS douyin_inbox_status_id ON douyin_inbox(status,id);
12
28
  CREATE TABLE IF NOT EXISTS douyin_inbox_gap(id INTEGER PRIMARY KEY AUTOINCREMENT, channel_id TEXT NOT NULL, reason TEXT NOT NULL, created_at INTEGER NOT NULL, acknowledged INTEGER NOT NULL DEFAULT 0);
13
29
  CREATE TABLE IF NOT EXISTS douyin_inbox_read_intent (cursor_key TEXT PRIMARY KEY, channel_id TEXT NOT NULL, started_at INTEGER NOT NULL);`);
14
- db.prepare("UPDATE douyin_inbox SET status='unknown',error='处理过程中断,可能已产生回复或其他操作',updated_at=? WHERE status='processing'").run(Date.now());
30
+ // 重启前卡在 processing 的:跟运行时的 reclaimStuck 同一件事,落待核实。
31
+ const stuck = db.prepare("SELECT channel_id FROM douyin_inbox WHERE status='processing'").all();
32
+ db.prepare("UPDATE douyin_inbox SET status='unknown',error=?,updated_at=? WHERE status='processing'").run(UNKNOWN_INTERRUPTED, Date.now());
33
+ if (stuck.length) this.noteUnknown(stuck.map((r) => r.channel_id), UNKNOWN_INTERRUPTED);
15
34
  this.prune();
16
35
  this.recoverReads();
17
36
  }
37
+ /**
38
+ * 记一条「私信可能遗漏」到运行日志。
39
+ *
40
+ * 设置页那块提示删了,但排查「消息怎么没回」还得查得到 —— 落到系统页「运行日志」。
41
+ * key 带会话名:不同会话各记一条,同一会话反复出问题才合并计数 ——
42
+ * 一次驱动挂掉会同时影响好几个会话,合成一条就只看得见最后一个会话漏了消息。
43
+ */
44
+ noteGap(channelId, reason) {
45
+ if (!this.diag) return;
46
+ const ch = String(channelId ?? '');
47
+ this.diag.add(`douyin-inbox-gap:${ch}`, { channelId: ch, reason: String(reason ?? '').slice(0, 200) }, 'warn');
48
+ }
49
+ /**
50
+ * 记一条「私信待核实」到运行日志(一个会话一条)。
51
+ * @param {string[]} channelIds 变成 unknown 的消息分别属于哪些会话
52
+ */
53
+ noteUnknown(channelIds, error) {
54
+ if (!this.diag || !channelIds.length) return;
55
+ const why = String(error || '处理结果不确定,请核实').slice(0, 200);
56
+ const byChannel = new Map();
57
+ for (const c of channelIds) {
58
+ const ch = String(c ?? '');
59
+ byChannel.set(ch, (byChannel.get(ch) ?? 0) + 1);
60
+ }
61
+ for (const [ch, count] of byChannel) {
62
+ this.diag.add(`douyin-inbox-unknown:${ch}`, { channelId: ch, count, error: why }, 'warn');
63
+ }
64
+ }
18
65
  // Persist before opening the conversation: the platform may mark it read before
19
66
  // returning data. A surviving intent proves uncertainty, not actual data loss.
20
67
  recoverReads() {
68
+ let left = [];
21
69
  this.db.exec('BEGIN');
22
70
  try {
71
+ left = this.db.prepare('SELECT DISTINCT channel_id FROM douyin_inbox_read_intent').all();
23
72
  // 同一会话已有未确认的提示就不再插:反复失败会把设置页刷成一长串重复行。
24
- this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,'读取过程中断,抖音可能已标记为已读但消息未入库,请手动检查',? FROM douyin_inbox_read_intent i WHERE NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(Date.now());
73
+ this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,?,? FROM douyin_inbox_read_intent i WHERE NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(GAP_INTERRUPTED, Date.now());
25
74
  this.db.exec('DELETE FROM douyin_inbox_read_intent; COMMIT');
26
75
  } catch(e) { this.db.exec('ROLLBACK'); throw e; }
76
+ for (const r of left) this.noteGap(r.channel_id, GAP_INTERRUPTED);
27
77
  }
28
78
  beginRead(key, channelId) {
29
79
  this.db.exec('BEGIN');
30
80
  try {
31
- this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,'上次读取未完成,抖音可能已标记为已读但消息未入库,请手动检查',? FROM douyin_inbox_read_intent i WHERE i.cursor_key=? AND NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(Date.now(),key);
81
+ // 上一次这个会话没读完(读取意图还留着)→ 可能漏了消息
82
+ const left = this.db.prepare('SELECT channel_id FROM douyin_inbox_read_intent WHERE cursor_key=?').get(key);
83
+ this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,?,? FROM douyin_inbox_read_intent i WHERE i.cursor_key=? AND NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(GAP_STALE, Date.now(), key);
32
84
  this.db.prepare('INSERT OR REPLACE INTO douyin_inbox_read_intent(cursor_key,channel_id,started_at) VALUES(?,?,?)').run(key,channelId,Date.now());
33
85
  this.db.exec('COMMIT');
86
+ if (left) this.noteGap(left.channel_id, GAP_STALE);
34
87
  } catch(e) { this.db.exec('ROLLBACK'); throw e; }
35
88
  }
36
89
  failRead(key, cause = '读取失败') {
90
+ const reason = `${cause},${GAP_UNREAD_TAIL}`;
37
91
  this.db.exec('BEGIN');
38
92
  try {
39
- this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,?,? FROM douyin_inbox_read_intent i WHERE i.cursor_key=? AND NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(`${cause},抖音可能已标记为已读但消息未入库,请手动检查`,Date.now(),key);
93
+ // 读之前记过读取意图:这里拿得到是哪个会话
94
+ const intent = this.db.prepare('SELECT channel_id FROM douyin_inbox_read_intent WHERE cursor_key=?').get(key);
95
+ this.db.prepare("INSERT INTO douyin_inbox_gap(channel_id,reason,created_at) SELECT i.channel_id,?,? FROM douyin_inbox_read_intent i WHERE i.cursor_key=? AND NOT EXISTS (SELECT 1 FROM douyin_inbox_gap g WHERE g.channel_id=i.channel_id AND g.acknowledged=0)").run(reason,Date.now(),key);
40
96
  this.db.prepare('DELETE FROM douyin_inbox_read_intent WHERE cursor_key=?').run(key);
41
97
  this.db.exec('COMMIT');
98
+ // 表里那条提示可能因为「这个会话已经有未确认的提示」而没插进去,
99
+ // 但这次读确实失败了 —— 日志记的是**这件事**,不是表里多了一行。
100
+ if (intent) this.noteGap(intent.channel_id, reason);
42
101
  } catch(e) { this.db.exec('ROLLBACK'); throw e; }
43
102
  }
44
103
  record(key, cursor, messages, gap = null) {
@@ -53,6 +112,8 @@ export class DouyinInbox {
53
112
  setKv(this.db,key,cursor);
54
113
  this.db.prepare('DELETE FROM douyin_inbox_read_intent WHERE cursor_key=?').run(key);
55
114
  this.db.exec('COMMIT');
115
+ // 窗口对不齐这件事本身要记(表里那条可能被「已有未确认的提示」挡掉)
116
+ if (gap) this.noteGap(gap.channelId, gap.reason);
56
117
  } catch(e) { this.db.exec('ROLLBACK'); throw e; }
57
118
  }
58
119
  /**
@@ -64,8 +125,20 @@ export class DouyinInbox {
64
125
  try {
65
126
  this.db.prepare("DELETE FROM douyin_inbox WHERE status IN ('done','dismissed') AND updated_at < ?").run(Date.now() - keepMs);
66
127
  this.db.prepare('DELETE FROM douyin_inbox_gap WHERE acknowledged = 1 AND created_at < ?').run(Date.now() - keepMs);
128
+ this.pruneGaps(keepMs);
67
129
  } catch { /* 卫生工作失败不影响收件 */ }
68
130
  }
131
+ /**
132
+ * 缺口提示的保留期。
133
+ *
134
+ * 设置页不再展示缺口提示(主人要求去掉噪音),于是没人会点「已知晓」——
135
+ * 未确认的缺口会永远留着,表单调增长。超过 maxAgeMs 直接删掉。
136
+ */
137
+ pruneGaps(maxAgeMs = 7 * 86_400_000) {
138
+ try {
139
+ return Number(this.db.prepare('DELETE FROM douyin_inbox_gap WHERE acknowledged=0 AND created_at < ?').run(Date.now() - maxAgeMs).changes);
140
+ } catch { return 0; }
141
+ }
69
142
  next() { return this.db.prepare("SELECT m.id,m.payload FROM douyin_inbox m WHERE m.status='pending' AND NOT EXISTS (SELECT 1 FROM douyin_inbox u WHERE u.channel_id=m.channel_id AND u.id<m.id AND u.status='unknown') ORDER BY m.id LIMIT 1").get() ?? null; }
70
143
  /** 一条 unknown 挡住的同会话待处理消息数(给「全部忽略」用)。 */
71
144
  blockedBehind(id) {
@@ -93,14 +166,44 @@ export class DouyinInbox {
93
166
  * 让用户自己核实 —— 不直接重试,因为那一轮可能已经把话发出去了,重发会刷屏。
94
167
  */
95
168
  reclaimStuck(maxAgeMs = 5 * 60_000) {
169
+ const cut = Date.now() - maxAgeMs;
170
+ const error = '处理卡住超过 '+Math.round(maxAgeMs/60000)+' 分钟,可能已产生回复或其他操作';
171
+ const stuck = this.db.prepare("SELECT channel_id FROM douyin_inbox WHERE status='processing' AND updated_at<?").all(cut);
172
+ const changed = Number(this.db.prepare(
173
+ "UPDATE douyin_inbox SET status='unknown',error=?,updated_at=? WHERE status='processing' AND updated_at<?"
174
+ ).run(error, Date.now(), cut).changes);
175
+ if (changed > 0) this.noteUnknown(stuck.map((r) => r.channel_id), error);
176
+ return changed;
177
+ }
178
+ /**
179
+ * 超期没核实的自动作废。
180
+ *
181
+ * 设置页不再展示「私信待核实」,用户没法再逐条核实 —— 而一条 unknown 会挡住
182
+ * 同会话**后面所有**消息(next() 里的 NOT EXISTS)。不自动过期,那个会话就永久哑掉。
183
+ *
184
+ * 阈值取 24 小时:主人离线一晚回来时、昨天的 unknown 不该还挡着队列。
185
+ */
186
+ expireStaleUnknown(maxAgeMs = 24 * 3600_000) {
96
187
  const cut = Date.now() - maxAgeMs;
97
188
  return Number(this.db.prepare(
98
- "UPDATE douyin_inbox SET status='unknown',error='处理卡住超过 "+Math.round(maxAgeMs/60000)+" 分钟,可能已产生回复或其他操作',updated_at=? WHERE status='processing' AND updated_at<?"
189
+ "UPDATE douyin_inbox SET status='dismissed',error='已自动忽略(超过 "+Math.round(maxAgeMs/3600000)+" 小时未核实)',updated_at=? WHERE status='unknown' AND updated_at<?"
99
190
  ).run(Date.now(), cut).changes);
100
191
  }
101
192
  settle(ids, ok, error='') {
102
193
  const q=this.db.prepare("UPDATE douyin_inbox SET status=?,error=?,updated_at=? WHERE id=? AND status='processing'");
103
- for(const id of ids) q.run(ok?'done':'unknown',ok?'':String(error || '处理结果不确定,请核实').slice(0,300),Date.now(),id);
194
+ const flipped=[];
195
+ for(const id of ids) {
196
+ if (q.run(ok?'done':'unknown',ok?'':String(error || '处理结果不确定,请核实').slice(0,300),Date.now(),id).changes===1) flipped.push(id);
197
+ }
198
+ // 只有「待核实」这条冷路径才回头查是哪个会话;正常收到私信不走这里
199
+ if (!ok && flipped.length) {
200
+ const channels=[];
201
+ for(const id of flipped) {
202
+ const row=this.db.prepare('SELECT channel_id FROM douyin_inbox WHERE id=?').get(id);
203
+ if (row) channels.push(row.channel_id);
204
+ }
205
+ this.noteUnknown(channels, error);
206
+ }
104
207
  }
105
208
  resolve(id, action) {
106
209
  if (!['retry','dismiss'].includes(action)) return false;
package/lib/index.js CHANGED
@@ -358,6 +358,8 @@ async function startup(ctx, config, { log, gate }) {
358
358
  const douyin = new DouyinChannel({
359
359
  host: douyinHost, db, getConfig: douyinCfg, log, notify: notifyMaster,
360
360
  onMessage: (m) => gateway?.onDouyinMessage(m),
361
+ // 「私信可能遗漏 / 私信待核实」设置页不显示了,落到系统页「运行日志」里
362
+ diag,
361
363
  driver: hook.driver?.(douyinHost), pollRangeMs: hook.pollRangeMs, typingMs: hook.typingMs, firstPollMs: hook.firstPollMs
362
364
  });
363
365
  const douyinBrowser = new DouyinBrowser({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.15.52",
3
+ "version": "0.15.53",
4
4
  "description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.15.37)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -64,7 +64,7 @@
64
64
  }
65
65
  },
66
66
  "scripts": {
67
- "test": "node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs",
67
+ "test": "node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs",
68
68
  "eval": "node test/eval/persona-eval.mjs"
69
69
  }
70
70
  }