dsh-onebot-genji 0.17.1 → 0.17.2

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
@@ -23,7 +23,7 @@ dsh plugin --profile web add dsh-onebot-genji
23
23
  | **表情包库** | 一套完整的表情包管理:新图自动收进「未审核」,审核时才让模型看图写描述和标签,不点不跑、不占显存;已审核的图可一键「重新识别」重跑识别,描述和标签点一下就能改 |
24
24
  | **主动搭话** | 内置在插件里(`lib/proactive.js`),按空闲时长、间隔、每日上限、安静时段自己找话题;开关和阈值全在设置页「行为 → 私聊」,生成走当前会话模型 |
25
25
  | **回合形式掷骰** | 每个回合按概率决定这一轮用文字、语音条还是表情包;语音/表情的开关与概率都是设置项(默认 10% / 39%) |
26
- | **气泡切分** | 正文按换行 / 句末标点自动切成多条气泡,条与条之间按字数算随机停顿(0.4–2.2 秒);编号列表一行一条,不被切碎 |
26
+ | **气泡切分** | 正文按换行 / 句末标点自动切成多条气泡,条与条之间按字数算随机停顿(0.4–2.2 秒);列表项(`1.` `2、` `3)` 或 `-` `•` `*`)一行一条,不封顶;提问卡和命令卡片整段发一条 |
27
27
  | **自带语音转写桥** | `lib/stt_cli.py` 打进包里,`sttEngine: auto` 探不到 whisper 时自动用它(只要 Python + `faster-whisper`),不用自己配脚本 |
28
28
  | **群聊上下文** | 被 @ 或叫到唤醒词时,自动带上群里最近 N 条消息(「参考上下文条数」,默认 3,0 = 不带),被门控挡下的消息不会丢 |
29
29
  | **QQ 空间说说** | 「QQ空间」页签里开关 + 每日上限 + 安静时段 + 可见范围;到点自己挑当天的事写一条说说发出去(默认关)。也可以让机器人手动发,带图 |
package/lib/bridge.js CHANGED
@@ -843,7 +843,7 @@ export class ChatBridge {
843
843
  * T2-B2 adds onQuestionCall to record the outstanding batch. */
844
844
  get cardRelayCtx() {
845
845
  return {
846
- sendToChat: (chatId, text) => this.sendToChat(chatId, text),
846
+ sendToChat: (chatId, text, options) => this.sendToChat(chatId, text, options),
847
847
  log: (level, message) => this.deps.log(level, message),
848
848
  onQuestionCall: (chatId, call) => {
849
849
  this.activeQuestion.set(chatId, { ...call, askedAt: Date.now() });
@@ -1069,7 +1069,9 @@ export class ChatBridge {
1069
1069
  get commandCtx() {
1070
1070
  const bridge = this;
1071
1071
  return {
1072
- sendToChat: (chatId, text) => bridge.sendToChat(chatId, text),
1072
+ // 命令输出都是排版好的卡片(/help、/doctor、/workspace 列表…),
1073
+ // 整段原样发一条:按句末标点切会把卡片拆散,也没法再断言整段文案。
1074
+ sendToChat: (chatId, text) => bridge.sendToChat(chatId, text, { noBubbleSplit: true }),
1073
1075
  log: (level, message) => bridge.deps.log(level, message),
1074
1076
  // T1 (#27): /steer 的命令确认文案取 notices.steerAccepted(自定义时)。
1075
1077
  notices: bridge.deps.config.notices,
package/lib/card-relay.js CHANGED
@@ -7,9 +7,10 @@ export function relayHostCards(ctx, chatId, content) {
7
7
  if (call.type !== 'tool-call')
8
8
  continue;
9
9
  if (call.name === 'exit_plan_mode') {
10
- const text = renderPlanCard(call.arguments, ctx.log);
11
- if (text !== undefined) {
12
- ctx.sendToChat(chatId, text).catch((error) => {
10
+ const planText = renderPlanCard(call.arguments, ctx.log);
11
+ if (planText !== undefined) {
12
+ // 计划书同样按行排版,整张一条发。
13
+ ctx.sendToChat(chatId, planText, { noBubbleSplit: true }).catch((error) => {
13
14
  ctx.log('warn', 'plan card relay failed: ' + String(error));
14
15
  });
15
16
  }
@@ -26,7 +27,8 @@ export function relayHostCards(ctx, chatId, content) {
26
27
  ctx.log('debug', 'question state update failed: ' + String(error));
27
28
  }
28
29
  }
29
- ctx.sendToChat(chatId, renderQuestionCard(parsed)).catch((error) => {
30
+ // 提问卡整张一条发(卡是按行排版的,切开会把选项和标题拆散)。
31
+ ctx.sendToChat(chatId, renderQuestionCard(parsed), { noBubbleSplit: true }).catch((error) => {
30
32
  ctx.log('warn', 'question card relay failed: ' + String(error));
31
33
  });
32
34
  }
package/lib/outbound.js CHANGED
@@ -228,72 +228,40 @@ export function stripTrailingPeriod(text) {
228
228
  return body;
229
229
  return body.replace(/。\s*$/u, '');
230
230
  }
231
- export function splitIntoBubbles(text, maxBubbles = 4, sentenceCut = 35) {
231
+ // 2026-11-24 主人口述的最终规则:
232
+ // 1. 换行则分条
233
+ // 2. 遇到**句末**的标点(。!?… / ...)则分条(逗号顿号冒号分号都不切)
234
+ // 3. 遇到列表项(「1. 」「2、」「3) 」或「- 」「• 」「* 」开头)则分条
235
+ // 4. 去掉每条末尾的「。」
236
+ // 5. 相邻气泡之间按上一条的字数停顿 420~2200ms(见 bubbleGapMs)
237
+ // 原来那套「35 字以内不切」「不足 6 字的碎片吸附」「条数上限」全部取消:
238
+ // 上限一取消,就不再出现 join(' ') 把好几行拼成一坨的情况。
239
+ export function splitIntoBubbles(text) {
232
240
  const raw = String(text ?? '');
233
241
  if (raw.trim() === '')
234
242
  return [];
235
243
  const punctOnlyRe = /^[\p{P}\p{S}\s]+$/u;
236
- // 1. 换行初切
237
- const rawParts = raw.split(/\r?\n+/).map((s) => s.trim()).filter(Boolean);
238
- // 2026-11-20:编号列表(「1. …」「2、…」)本身就是一条一条的,**一行一条**,
239
- // 行内不再按句号拆,也不许被末尾的 4 条上限合并掉——主人抓到过「2、3 点被并
240
- // 成一条」。列表时把上限抬到列表项数量(封顶 8)。
241
- const itemRe = /^\s*\d+\s*[.、).]/;
242
- // 编号可能独占一行,也可能挤在一段里(「…。2. 自省复盘…3. 记忆图衰减…」),
243
- // 两种都算列表,上限按编号个数放宽。
244
- const inlineItemRe = /(?:^|\s)\d{1,2}\s*[.、).]\s/g;
245
- const listCount = Math.max(rawParts.filter((s) => itemRe.test(s)).length, (raw.match(inlineItemRe) ?? []).length);
246
- const merged = [];
247
- const shortMerge = (last, s) => punctOnlyRe.test(s)
248
- || ([...last].length < 6 && [...last].length + [...s].length <= 24);
249
- for (const part of rawParts) {
250
- const isItem = listCount >= 2 && itemRe.test(part);
251
- // 2. 行内断句(列表项整行成一条)
252
- const pieces = isItem || [...part].length <= sentenceCut
253
- ? [part]
254
- : (() => {
255
- // `~` 只在后面不是「路径/数字/英文」时才算句末:
256
- // - `420~2200` 是范围(2026-11-20 主人抓过一次)
257
- // - `~/.dsh/memory-daily/` 是家目录路径(2026-11-20 第二次抓到,
258
- // 正文被从路径中间切成两条气泡),后面跟 / \ . _ - 或字母数字都不算句末。
259
- // 行内还可能挤着「…。2. 自省复盘…3. 记忆图衰减…」这种编号(主人抓到过
260
- // 「2、3 点没分条」),编号标记前也切一刀:`\s\d{1,2}[.、).]\s`。
261
- const segs = part.split(/(?<=[。!?!?…])\s*|(?<=~)\s*(?![0-9A-Za-z/\\._-])|(?<=\s)(?=\d{1,2}\s*[.、).]\s)/)
262
- .map((s) => s.trim()).filter(Boolean);
263
- return segs.length > 0 ? segs : [part];
264
- })();
265
- // 3. 行内吸附合并(换行是硬边界,不跨行合并普通句子)
266
- const line = [];
267
- for (const s of pieces) {
268
- const lastInLine = line[line.length - 1];
269
- if (lastInLine !== undefined && shortMerge(lastInLine, s)) {
270
- line[line.length - 1] = lastInLine + s;
244
+ const out = [];
245
+ // 1. 换行是硬边界
246
+ for (const line of raw.split(/\r?\n+/).map((s) => s.trim()).filter(Boolean)) {
247
+ // 2/3. 行内按**句末**标点切一刀(。!?!?… 以及英文省略号 ... 或 …);
248
+ // 逗号、顿号、冒号、分号不算句末,不切。行内挤着编号(「…。2. 自省复盘…
249
+ // 3. 记忆图衰减…」)时编号标记前也切一刀。
250
+ const segs = line
251
+ .split(/(?<=[。!?!?…])\s*|(?<=\.{2,})\s*|(?<=\s)(?=\d{1,2}\s*[.、).]\s)/)
252
+ .map((s) => s.trim())
253
+ .filter(Boolean);
254
+ for (const seg of segs.length > 0 ? segs : [line]) {
255
+ // 纯标点段(单独一个「!」)并到上一条,免得发出空气泡
256
+ if (out.length > 0 && punctOnlyRe.test(seg)) {
257
+ out[out.length - 1] += seg;
271
258
  }
272
259
  else {
273
- line.push(s);
260
+ out.push(seg);
274
261
  }
275
262
  }
276
- // 4. 跨行只吸附纯标点行(「真的假的」+「!」)
277
- if (line.length > 0 && merged.length > 0 && punctOnlyRe.test(line[0])) {
278
- merged[merged.length - 1] += line.shift();
279
- }
280
- merged.push(...line);
281
263
  }
282
- if (merged.length === 0)
283
- return [];
284
- // 4. 上限控制
285
- // 2026-11-23 主人抓到的 bug:「两句说明 + 1~4 四个编号 + 一句收尾」一共 7 行,
286
- // 却只按 listCount=4 放宽到 4 条 —— 超出的 2、3、4 和收尾被 join(' ') 拼成
287
- // 一条。列表演示里说明行常常比编号项多,所以把实际行数(merged.length)
288
- // 也纳入判据。
289
- // 2026-11-23 晚 主人第二次要求:**编号列表不封顶**(之前封 8,我写 10 条
290
- // 对比项被压成 8 条,他又看到「没分条」)。带编号的列表一律一行一条,
291
- // 有几行出几条;不带编号的普通聊天照旧只有 maxBubbles(避免一句话刷屏)。
292
- const limit = listCount >= 2 ? merged.length : maxBubbles;
293
- const out = merged.length > limit
294
- ? [...merged.slice(0, limit - 1), merged.slice(limit - 1).join(' ')]
295
- : merged;
296
- // 2026-11-22 主人要求:每条气泡末尾的「。」剥掉(问号叹号不动);剥成空的丢掉。
264
+ // 4. 每条末尾的「。」剥掉(问号叹号不动);剥成空的丢掉。
297
265
  return out.map(stripTrailingPeriod).filter((s) => s.trim() !== '');
298
266
  }
299
267
  /** 气泡停顿:按字数算的基准参数(2026-11-20 主人要求「按每条字数来,别固定 1500ms」)。 */
@@ -572,7 +540,7 @@ export class OutboundPipeline {
572
540
  // 气泡切分(2026-11-19 按 issue #6):换行/长句 → 多条独立气泡,
573
541
  // 最多 4 条。首条立即发,其后按 800–1500ms 随机停顿营造打字呼吸感;
574
542
  // 引用只挂在第一条。
575
- const bubbles = splitIntoBubbles(plain);
543
+ const bubbles = options.noBubbleSplit === true ? [plain] : splitIntoBubbles(plain);
576
544
  for (let i = 0; i < bubbles.length; i += 1) {
577
545
  if (i > 0)
578
546
  await new Promise((resolve) => setTimeout(resolve, bubbleGapMs(bubbles[i - 1])));
@@ -14,8 +14,10 @@ import type { ChatId } from './chat.js';
14
14
  * bridge log (render failures are debug lines, relay failures warn lines).
15
15
  * T2-B2 adds the optional onQuestionCall hook for the answer-bridge state. */
16
16
  export interface CardRelayContext {
17
- /** Outbound pipeline send (bridge facade). */
18
- sendToChat(chatId: ChatId, text: string): Promise<string[]>;
17
+ /** Outbound pipeline send (bridge facade). `noBubbleSplit` 让卡片原样一条发出去。 */
18
+ sendToChat(chatId: ChatId, text: string, options?: {
19
+ noBubbleSplit?: boolean;
20
+ }): Promise<string[]>;
19
21
  /** Bridge log line callback. */
20
22
  log(level: 'info' | 'warn' | 'error' | 'debug', message: string): void;
21
23
  /** T2-B2: called once per relayed ask_user_question call with the parsed batch. */
@@ -82,7 +82,7 @@ export declare function splitAtSegments(text: string): OutboundSegment[];
82
82
  * 整条只有标点的不处理(免得把「。」自己清成空串)。
83
83
  */
84
84
  export declare function stripTrailingPeriod(text: string): string;
85
- export declare function splitIntoBubbles(text: string, maxBubbles?: number, sentenceCut?: number): string[];
85
+ export declare function splitIntoBubbles(text: string): string[];
86
86
  /** 气泡停顿:按字数算的基准参数(2026-11-20 主人要求「按每条字数来,别固定 1500ms」)。 */
87
87
  export declare const BUBBLE_GAP_BASE_MS = 380;
88
88
  export declare const BUBBLE_GAP_PER_CHAR_MS = 68;
@@ -98,6 +98,9 @@ export declare function bubbleGapMs(prevText?: string, random?: () => number): n
98
98
  /** Options for an explicit outbound send (from tools). */
99
99
  export interface SendOptions {
100
100
  replyTo?: string;
101
+ /** 2026-11-24:整段原样发一条,不切气泡。给结构化卡片(提问卡/计划书)用——
102
+ * 它们靠换行排版,切开会把「a) 选项」和标题拆散。 */
103
+ noBubbleSplit?: boolean;
101
104
  /** Queue the send for resend on reconnect instead of failing while the
102
105
  * connection is down. Only for model final replies; interim sends carry
103
106
  * recall timers + bookkeeping and must never be replayed. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-onebot-genji",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "description": "由 InsaneGenji 维护的 QQ 通道分叉(fork 自 dsh-onebot-qq@0.11.0):在 OneBot 11 / NapCat 通道基础上加了表情包库(未审核/已审核、模型看图写标签、重新识别)、主动搭话、QQ 空间说说、回合形式掷骰(语音条、表情包概率)、正文气泡切分、群聊上下文与自带语音转写桥。仓库 github.com/InsaneGenji/dsh-onebot-genji,上游 github.com/mario841859784/dsh-onebot .",
5
5
  "keywords": [
6
6
  "dsh",