@zaofan/dsh-qqbot 1.13.29 → 1.13.36
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/dist/channel-tools.d.ts +2 -1
- package/dist/channel-tools.d.ts.map +1 -1
- package/dist/channel-tools.js +108 -24
- package/dist/channel-tools.js.map +1 -1
- package/dist/features/auto-recall.d.ts.map +1 -1
- package/dist/features/auto-recall.js +2 -3
- package/dist/features/auto-recall.js.map +1 -1
- package/dist/features/ext-tool-interaction.d.ts.map +1 -1
- package/dist/features/ext-tool-interaction.js +2 -3
- package/dist/features/ext-tool-interaction.js.map +1 -1
- package/dist/features/image-aggregate.d.ts +7 -4
- package/dist/features/image-aggregate.d.ts.map +1 -1
- package/dist/features/image-aggregate.js +46 -19
- package/dist/features/image-aggregate.js.map +1 -1
- package/dist/features/md-media-rewrite.d.ts.map +1 -1
- package/dist/features/md-media-rewrite.js +2 -3
- package/dist/features/md-media-rewrite.js.map +1 -1
- package/dist/features/msg-history.d.ts +9 -9
- package/dist/features/msg-history.d.ts.map +1 -1
- package/dist/features/msg-history.js +80 -53
- package/dist/features/msg-history.js.map +1 -1
- package/dist/gateway/bootstrap.js +2 -2
- package/dist/gateway/bootstrap.js.map +1 -1
- package/dist/gateway/middleware-setup.js +1 -1
- package/dist/gateway/middleware-setup.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/middleware/attribution.d.ts +1 -1
- package/dist/middleware/attribution.d.ts.map +1 -1
- package/dist/middleware/attribution.js +3 -3
- package/dist/middleware/attribution.js.map +1 -1
- package/dist/model/model-resolver.d.ts +12 -0
- package/dist/model/model-resolver.d.ts.map +1 -1
- package/dist/model/model-resolver.js +23 -4
- package/dist/model/model-resolver.js.map +1 -1
- package/dist/model/prefs-store.d.ts +26 -0
- package/dist/model/prefs-store.d.ts.map +1 -1
- package/dist/model/prefs-store.js +66 -0
- package/dist/model/prefs-store.js.map +1 -1
- package/dist/model/settings-reader.js +3 -3
- package/dist/model/settings-reader.js.map +1 -1
- package/dist/model/types.d.ts +9 -0
- package/dist/model/types.d.ts.map +1 -1
- package/dist/model/types.js +9 -1
- package/dist/model/types.js.map +1 -1
- package/dist/session/session-manager.d.ts +58 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +230 -45
- package/dist/session/session-manager.js.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/reply-gate-reason.d.ts +34 -0
- package/dist/shared/reply-gate-reason.d.ts.map +1 -0
- package/dist/shared/reply-gate-reason.js +86 -0
- package/dist/shared/reply-gate-reason.js.map +1 -0
- package/dist/shared/utils.d.ts +31 -0
- package/dist/shared/utils.d.ts.map +1 -1
- package/dist/shared/utils.js +54 -1
- package/dist/shared/utils.js.map +1 -1
- package/dist/transport/inbound.d.ts.map +1 -1
- package/dist/transport/inbound.js +6 -6
- package/dist/transport/inbound.js.map +1 -1
- package/dist/transport/outbound.d.ts +11 -9
- package/dist/transport/outbound.d.ts.map +1 -1
- package/dist/transport/outbound.js +22 -10
- package/dist/transport/outbound.js.map +1 -1
- package/package.json +1 -1
package/dist/channel-tools.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export declare const inject: string[];
|
|
|
13
13
|
export declare function instanceTagOfManager(m: unknown): string;
|
|
14
14
|
export declare function setContextlessSmartGlobal(v: boolean): void;
|
|
15
15
|
/** 读登记(session-manager 的 pre-step 用) */
|
|
16
|
-
export declare function readContextPending(dataRoot: string, sessionKey: string): {
|
|
16
|
+
export declare function readContextPending(dataRoot: string, sessionKey: string, expectSessionId?: string): {
|
|
17
17
|
mode?: string;
|
|
18
18
|
keep?: number;
|
|
19
|
+
sessionId?: string;
|
|
19
20
|
} | undefined;
|
|
20
21
|
export declare function clearContextPending(dataRoot: string, sessionKey: string): void;
|
|
21
22
|
export declare function setChannelBridge(b: QQChannel | undefined): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-tools.d.ts","sourceRoot":"","sources":["../src/channel-tools.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"channel-tools.d.ts","sourceRoot":"","sources":["../src/channel-tools.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAMnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AA8FlE,6DAA6D;AAC7D,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,eAAO,MAAM,IAAI,wBAAwB,CAAC;AAI1C,eAAO,MAAM,MAAM,UAAY,CAAC;AA2ChC,oDAAoD;AACpD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAIvD;AA+LD,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAAiC;AA+D5F,wCAAwC;AACxC,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAkBlE;AACD,wBAAgB,mBAAmB,CAA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IAAI,CA0K7D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAwCjE;AAuGD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE;IACJ,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,GACA,IAAI,CAqDN;AAID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAsC1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA0CnI"}
|
package/dist/channel-tools.js
CHANGED
|
@@ -13,8 +13,9 @@ import { uploadMarkdownImage, listMarkdownImages, deleteMarkdownImage } from './
|
|
|
13
13
|
import { setMaterialTargetFactory } from './features/md-media-rewrite.js';
|
|
14
14
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import { join, dirname, resolve } from 'node:path';
|
|
16
|
+
import { dshHomePath } from './shared/utils.js';
|
|
17
|
+
import { isContradictoryReplyFalse } from './shared/reply-gate-reason.js';
|
|
16
18
|
import { dataRootOf } from './gateway/data-root.js';
|
|
17
|
-
import { homedir } from 'node:os';
|
|
18
19
|
import { getStickerStore } from './features/sticker-store.js';
|
|
19
20
|
import { autoTagImage } from './features/sticker-tagger.js';
|
|
20
21
|
import { isStickerGateDenied } from './features/sticker-gate.js';
|
|
@@ -381,8 +382,23 @@ let ctxSmartGlobal = false;
|
|
|
381
382
|
export function setContextlessSmartGlobal(v) { ctxSmartGlobal = v === true; }
|
|
382
383
|
function getContextlessSmartGlobal() { return ctxSmartGlobal; }
|
|
383
384
|
/** 无上下文·智能判断:取当前会话的 dataRoot + sessionKey */
|
|
385
|
+
/**
|
|
386
|
+
* 从工具执行上下文里取**当前会话 id**(取不到返回空串)。
|
|
387
|
+
*
|
|
388
|
+
* 用途:`context_compact` / `context_drop` 只「登记」请求,真正执行在下一回合的 pre-step。
|
|
389
|
+
* 登记时把目标会话 id 一起写进 pending 文件 —— 否则**历史会话**(`/bot-new` 之后,
|
|
390
|
+
* 它的 id 仍能经派生反查映射回同一个 sessionKey)会把这条请求当成自己的,裁掉自己的历史。
|
|
391
|
+
*/
|
|
392
|
+
function execSessionId(exec) {
|
|
393
|
+
try {
|
|
394
|
+
const a = exec?.agent;
|
|
395
|
+
return String(a?.session?.id ?? '').trim();
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
return '';
|
|
399
|
+
}
|
|
400
|
+
}
|
|
384
401
|
async function resolveCtxMemoEnv(exec) {
|
|
385
|
-
// ★ 优先用注册时记住的会话坐标(工具里的 exec.agent 与 pre-step 的 agent 是两个不同对象,反查常失败)
|
|
386
402
|
// ⚠️ 必须要求 sessionKey 非空:备忘/压缩都按会话分文件存,空 key 会让所有会话串到同一份。
|
|
387
403
|
const cached = ctxEnvOf(exec);
|
|
388
404
|
if (cached && cached.sessionKey)
|
|
@@ -431,9 +447,23 @@ function writeContextPending(dataRoot, sessionKey, o) {
|
|
|
431
447
|
catch { /* ignore */ }
|
|
432
448
|
}
|
|
433
449
|
/** 读登记(session-manager 的 pre-step 用) */
|
|
434
|
-
export function readContextPending(dataRoot, sessionKey) {
|
|
450
|
+
export function readContextPending(dataRoot, sessionKey, expectSessionId) {
|
|
435
451
|
try {
|
|
436
|
-
|
|
452
|
+
const o = JSON.parse(readFileSync(ctxPendingPath(dataRoot, sessionKey), 'utf8'));
|
|
453
|
+
if (!o)
|
|
454
|
+
return undefined;
|
|
455
|
+
// ★★ 2026-11-28(CodeRabbit:按会话键登记的历史派生会话会误消费)
|
|
456
|
+
// pending 文件是按 **sessionKey** 命名的,而 `/bot-new` 之后**历史会话**的 id 仍能经
|
|
457
|
+
// 派生反查映射回同一个 key(`derive(key)` 是确定性的)。于是"打开历史会话"会让它
|
|
458
|
+
// 读走**当前会话**登记的压缩请求,把历史会话自己的历史裁掉,而当前会话的请求被吞掉。
|
|
459
|
+
// 这条裁剪不可逆,只有 note 里的要点留得下。
|
|
460
|
+
// 兜法:登记时记下目标会话 id,读取时对不上就当作没有(**不删**,留给真正的主人)。
|
|
461
|
+
// 旧格式(没有 sessionId)不拦,保持向后兼容。
|
|
462
|
+
const want = String(expectSessionId ?? '').trim();
|
|
463
|
+
const got = String(o.sessionId ?? '').trim();
|
|
464
|
+
if (want && got && got !== want)
|
|
465
|
+
return undefined;
|
|
466
|
+
return o;
|
|
437
467
|
}
|
|
438
468
|
catch {
|
|
439
469
|
return undefined;
|
|
@@ -1212,7 +1242,9 @@ export async function apply(ctx, opts) {
|
|
|
1212
1242
|
description: '回复闸门(**只在你不回复时**才调用): 每轮先自己判断"这一轮该不该说话"——判断要回,就**直接回复**,不要调用本工具; 判断这一轮不该说话(没@你、话题与你无关、没必要插嘴),就调用它传 reply:false,本回合立即静默终止,你不会再输出任何内容(这条消息就像没发生过)。默认行为是"正常回复",所以不调用它 = 照常说话。' +
|
|
1213
1243
|
'\n✅ **收到 reply:false 后,你会看到一条 `tool call aborted` 之类的"报错" —— 那正是「静默成功」本身**(本工具就是靠中断输出实现的,设计如此),不是工具坏了、也不是调用失败。看到它请直接收手,什么都不用做、也不用重试。' +
|
|
1214
1244
|
'\n⛔ **不要为了"想安静"去动别的开关**(例如把出站模式切成 silent/静默):那会影响**后续所有回合**,而你要的只是"这一轮别说话"。要静默,只走本工具。' +
|
|
1215
|
-
'\n⚠️ 传 reply:false 后**不要再调用任何工具**(包括记笔记、记喜好、发表情包): 本回合已经关闭, 那些调用会被直接中止 —— 想记录的话, 留到下一次开口的回合里做。'
|
|
1245
|
+
'\n⚠️ 传 reply:false 后**不要再调用任何工具**(包括记笔记、记喜好、发表情包): 本回合已经关闭, 那些调用会被直接中止 —— 想记录的话, 留到下一次开口的回合里做。' +
|
|
1246
|
+
'\n🚫 **私聊(c2c)里、或被 @ 时,永远不要调用本工具**:私聊是主人一对一找你说话,静默等于不回话;被 @ 是明确在叫你。这两种情况直接回,闸门只用于群里「旁观」的回合。' +
|
|
1247
|
+
'\n⚠️ **reply 语义只看布尔值**:reply:false = 这一轮静默;reply:true = 继续回复。reason 必须与 reply 一致 —— 如果 reason 里明确写着"该回/必须回/需要回",就不要传 reply:false;而「不需要回复」「已经有群友回答了」这类是**否定/已答语境**,传 reply:false 是**对的**,不会被拦。',
|
|
1216
1248
|
parameters: {
|
|
1217
1249
|
reply: { type: 'boolean', required: true, description: 'false=静默终止本回合(不再输出任何内容); true=正常继续(一般用不到 —— 想说话就直接说, 不必调本工具)' },
|
|
1218
1250
|
reason: { type: 'string', required: true, description: '为什么这一轮不说话, 如"未@且话题无关" / "只是别人在聊天" / "已经问过她了"' },
|
|
@@ -1223,10 +1255,11 @@ export async function apply(ctx, opts) {
|
|
|
1223
1255
|
properties: {
|
|
1224
1256
|
ok: { type: 'boolean', required: true },
|
|
1225
1257
|
stopped: { type: 'boolean', required: true },
|
|
1258
|
+
note: { type: 'string', description: '被私聊拦下时的回执说明(此时 stopped=false,本回合照常开口)' },
|
|
1226
1259
|
},
|
|
1227
1260
|
},
|
|
1228
1261
|
render: (_a, v) => [
|
|
1229
|
-
{ type: 'text', text: v.stopped
|
|
1262
|
+
{ type: 'text', text: v.note ? String(v.note) : v.stopped
|
|
1230
1263
|
? '(已静默: 本回合终止, 不再回复)'
|
|
1231
1264
|
// ★ 2026-10-29(issue #28):原来是「(继续回复)」—— 括号舞台提示体,天然被读成"接着演",
|
|
1232
1265
|
// 而闸门把回合劈成两段后,待回的那条消息已被挤到上下文中间,末尾只剩这句提示 ⇒
|
|
@@ -1236,6 +1269,43 @@ export async function apply(ctx, opts) {
|
|
|
1236
1269
|
},
|
|
1237
1270
|
async execute(args, exec) {
|
|
1238
1271
|
if (args.reply === false) {
|
|
1272
|
+
let sessionKey = '';
|
|
1273
|
+
try {
|
|
1274
|
+
sessionKey = (await resolveCtxMemoEnv(exec))?.sessionKey ?? '';
|
|
1275
|
+
}
|
|
1276
|
+
catch { /* ignore */ }
|
|
1277
|
+
// ★ 2026-11-27(实测事故):私聊里闸门恒开 —— 私聊是主人一对一找它说话,静默等于不回话。
|
|
1278
|
+
// 本地 27B 在无思考档位下会把本工具当成"开口开关",连传 reply:false(reason 里却写着"要回复"),
|
|
1279
|
+
// cancel 掉整个回合 ⇒ 用户只看到 tool call aborted、一个字都没收到(11-27 夜里连续复现)。
|
|
1280
|
+
// 所以在真正取消之前先判会话类型:c2c 一律放行(stopped:false + 回执说清楚),不 cancel。
|
|
1281
|
+
// ⚠️ c2c 判定要**与出站侧同源**(那边用 `record.scope`):只嗅 sessionKey 字符串不够稳 ——
|
|
1282
|
+
// `resolveCtxMemoEnv` 拿不到时会回空串,而 `''.includes(':c2c:') === false`
|
|
1283
|
+
// ⇒ 私聊被当成群聊 ⇒ 照旧 cancel(本 bug 原样复活)。所以优先取记录里的 scope。
|
|
1284
|
+
let scopeOfSession = '';
|
|
1285
|
+
try {
|
|
1286
|
+
const gotOf = findSessionRec(channelOf(exec), exec);
|
|
1287
|
+
scopeOfSession = String(gotOf?.rec?.scope ?? '');
|
|
1288
|
+
}
|
|
1289
|
+
catch { /* ignore */ }
|
|
1290
|
+
const isC2c = scopeOfSession === 'c2c' || (!!sessionKey && sessionKey.includes(':c2c:'));
|
|
1291
|
+
if (isC2c) {
|
|
1292
|
+
return { ok: true, stopped: false, note: '(私聊必须开口:闸门在私聊恒开 —— 直接写你要说的那句话,不要静默)' };
|
|
1293
|
+
}
|
|
1294
|
+
// ★ 2026-11-28(实测事故):小傻龙群里 @ 提问,模型传 reply:false 且 reason="用户直接@我提问,需要回复",
|
|
1295
|
+
// 闸门照单 cancel ⇒ turn/end aborted(hook reply_gate: 本轮静默),用户只看到 tool call aborted。
|
|
1296
|
+
// 这是 27B 无思考档位下的布尔语义反转:reason 说要回,reply 却传了 false。
|
|
1297
|
+
// 命中矛盾时不 cancel,返回明确回执让模型直接开口;正常静默仍走原 cancel 路径。
|
|
1298
|
+
// ⚠️ 判定**不能**按"整串里有没有某几个词"—— 否定是**分句局部**的:
|
|
1299
|
+
// 「未@我,不需要回复」「已经有群友回答了」都是正常静默,
|
|
1300
|
+
// 而「群友已经@我了,必须回复」是矛盾 —— 三者都含"已经/回答"类词,
|
|
1301
|
+
// 只有**逐处就近判否定**才分得开(见 shared/reply-gate-reason.ts)。
|
|
1302
|
+
const reason = typeof args.reason === 'string' ? args.reason : '';
|
|
1303
|
+
// ⚠️ 判定收在 `shared/reply-gate-reason.ts` —— 与 outbound 的出站静默**共用一份**,
|
|
1304
|
+
// 别在这里再写一条正则(两处不同步就是"工具放行了、出站还在静默"这类怪象)。
|
|
1305
|
+
// 否定 / 已答语境优先:「未@我,不需要回复」「已经有群友回答了」都**不算**矛盾。
|
|
1306
|
+
if (isContradictoryReplyFalse(reason)) {
|
|
1307
|
+
return { ok: true, stopped: false, note: '(自相矛盾:reason 说要回复却传 reply=false —— 直接写你要说的那句话,不要再调本工具,也不要静默)' };
|
|
1308
|
+
}
|
|
1239
1309
|
try {
|
|
1240
1310
|
const agent = exec.agent;
|
|
1241
1311
|
if (agent && typeof agent.cancel === 'function') {
|
|
@@ -2274,7 +2344,8 @@ export async function apply(ctx, opts) {
|
|
|
2274
2344
|
const ga = groupAdminOf(exec);
|
|
2275
2345
|
if (!ga)
|
|
2276
2346
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2277
|
-
const
|
|
2347
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2348
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2278
2349
|
if (!gid)
|
|
2279
2350
|
return { ok: false, msg: '当前不是群会话且未指定 gid, 无法确定目标群' };
|
|
2280
2351
|
const r = await ga.client.getMuteState(gid);
|
|
@@ -2313,14 +2384,15 @@ export async function apply(ctx, opts) {
|
|
|
2313
2384
|
const ga = groupAdminOf(exec);
|
|
2314
2385
|
if (!ga)
|
|
2315
2386
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2316
|
-
const
|
|
2387
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2388
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2317
2389
|
if (!gid)
|
|
2318
2390
|
return { ok: false, msg: '当前不是群会话且未指定 gid, 无法确定目标群' };
|
|
2319
2391
|
let msgId = String(args.msg_id ?? '').trim();
|
|
2320
2392
|
let who = '';
|
|
2321
2393
|
if (msgId === '') {
|
|
2322
2394
|
const member = String(args.member ?? '').trim();
|
|
2323
|
-
const rec = latestMsgHistory('group', gid, { senderId: member || undefined, withinMs: 120_000 });
|
|
2395
|
+
const rec = latestMsgHistory('group', gid, { senderId: member || undefined, withinMs: 120_000 }, ctxRoot);
|
|
2324
2396
|
if (!rec) {
|
|
2325
2397
|
return {
|
|
2326
2398
|
ok: false,
|
|
@@ -2364,7 +2436,8 @@ export async function apply(ctx, opts) {
|
|
|
2364
2436
|
const ga = groupAdminOf(exec);
|
|
2365
2437
|
if (!ga)
|
|
2366
2438
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2367
|
-
const
|
|
2439
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2440
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2368
2441
|
if (!gid)
|
|
2369
2442
|
return { ok: false, msg: '当前不是群会话且未指定 gid' };
|
|
2370
2443
|
const list = readMsgHistory('group', gid, {
|
|
@@ -2372,9 +2445,9 @@ export async function apply(ctx, opts) {
|
|
|
2372
2445
|
kind: (args.kind ? String(args.kind) : undefined),
|
|
2373
2446
|
fromSelf: typeof args.from_self === 'boolean' ? args.from_self : undefined,
|
|
2374
2447
|
limit: Number(args.limit) || 20,
|
|
2375
|
-
});
|
|
2448
|
+
}, ctxRoot);
|
|
2376
2449
|
if (list.length === 0)
|
|
2377
|
-
return { ok: true, msg: '台账里没有命中的消息(默认只查最近 2 小时)。' + historyDebug('group', gid) };
|
|
2450
|
+
return { ok: true, msg: '台账里没有命中的消息(默认只查最近 2 小时)。' + historyDebug('group', gid, ctxRoot) };
|
|
2378
2451
|
const lines = list.map((m, i) => `${i + 1}. ${m.me ? '🤖' : '👤'}${m.n || m.s} [${m.k ?? 'text'}] ${m.x || '(无正文)'}|id=${String(m.id).slice(0, 16)}…|${new Date(m.t).toLocaleTimeString('zh-CN')}`);
|
|
2379
2452
|
return {
|
|
2380
2453
|
ok: true,
|
|
@@ -2413,7 +2486,7 @@ export async function apply(ctx, opts) {
|
|
|
2413
2486
|
execute: async (args) => {
|
|
2414
2487
|
try {
|
|
2415
2488
|
const prof = process.env.DSH_PROFILE || 'web';
|
|
2416
|
-
const base =
|
|
2489
|
+
const base = dshHomePath('qqbot-settings', prof);
|
|
2417
2490
|
let file = join(base, 'im-qqbot-2.json');
|
|
2418
2491
|
if (!existsSync(file)) {
|
|
2419
2492
|
const cands = existsSync(base) ? readdirSync(base).filter((f) => /^im-qqbot-.*\.json$/.test(f)) : [];
|
|
@@ -2498,7 +2571,8 @@ export async function apply(ctx, opts) {
|
|
|
2498
2571
|
const ga = groupAdminOf(exec);
|
|
2499
2572
|
if (!ga)
|
|
2500
2573
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2501
|
-
const
|
|
2574
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2575
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2502
2576
|
if (!gid)
|
|
2503
2577
|
return { ok: false, msg: '当前不是群会话且未指定 gid' };
|
|
2504
2578
|
const ids = (Array.isArray(args.member_openids) ? args.member_openids : [])
|
|
@@ -2643,7 +2717,8 @@ export async function apply(ctx, opts) {
|
|
|
2643
2717
|
const ga = groupAdminOf(exec);
|
|
2644
2718
|
if (!ga)
|
|
2645
2719
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2646
|
-
const
|
|
2720
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2721
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2647
2722
|
if (!gid)
|
|
2648
2723
|
return { ok: false, msg: '当前不是群会话且未指定 gid' };
|
|
2649
2724
|
const brief = (m) => `${m.me ? '🤖' : '👤'}${m.n || m.s} [${m.k ?? 'text'}] ${(m.x ?? '').slice(0, 24)}`;
|
|
@@ -2654,11 +2729,11 @@ export async function apply(ctx, opts) {
|
|
|
2654
2729
|
keyword: args.keyword ? String(args.keyword) : undefined,
|
|
2655
2730
|
kind: (args.kind ? String(args.kind) : undefined),
|
|
2656
2731
|
limit: 20,
|
|
2657
|
-
}).map((r) => ({ me: r.me, s: r.s, n: r.n, k: r.k, x: r.x, msgId: r.id }));
|
|
2732
|
+
}, ctxRoot).map((r) => ({ me: r.me, s: r.s, n: r.n, k: r.k, x: r.x, msgId: r.id }));
|
|
2658
2733
|
ids = picked.map((p) => p.msgId);
|
|
2659
2734
|
}
|
|
2660
2735
|
else {
|
|
2661
|
-
const all = readMsgHistory('group', gid, { withinMs: 120_000, limit: 200 }).map((r) => ({ me: r.me, s: r.s, n: r.n, k: r.k, x: r.x, msgId: r.id }));
|
|
2736
|
+
const all = readMsgHistory('group', gid, { withinMs: 120_000, limit: 200 }, ctxRoot).map((r) => ({ me: r.me, s: r.s, n: r.n, k: r.k, x: r.x, msgId: r.id }));
|
|
2662
2737
|
picked = all.filter((p) => ids.includes(p.msgId));
|
|
2663
2738
|
}
|
|
2664
2739
|
ids = ids.slice(0, 20);
|
|
@@ -2726,7 +2801,8 @@ export async function apply(ctx, opts) {
|
|
|
2726
2801
|
const ga = groupAdminOf(exec);
|
|
2727
2802
|
if (!ga)
|
|
2728
2803
|
return { ok: false, msg: '群管理未开启或非群会话' };
|
|
2729
|
-
const
|
|
2804
|
+
const ctxRoot = await resolveCtxDataRoot(exec);
|
|
2805
|
+
const gid = String(args.gid ?? '').trim() || ga.gid || latestGroupId(ctxRoot);
|
|
2730
2806
|
if (!gid)
|
|
2731
2807
|
return { ok: false, msg: '当前不是群会话且未指定 gid, 无法确定目标群' };
|
|
2732
2808
|
const secs = Math.max(1, Math.min(30 * 86400, Math.round(Number(args.seconds ?? 600))));
|
|
@@ -3834,7 +3910,7 @@ var contextCompactTool = defineTool({
|
|
|
3834
3910
|
const a = (args ?? {});
|
|
3835
3911
|
if (a.note)
|
|
3836
3912
|
appendContextMemo(r.dataRoot, r.sessionKey, String(a.note));
|
|
3837
|
-
writeContextPending(r.dataRoot, r.sessionKey, { mode: 'compact', keep: Number(a.keep) || 3, at: Date.now() });
|
|
3913
|
+
writeContextPending(r.dataRoot, r.sessionKey, { mode: 'compact', keep: Number(a.keep) || 3, at: Date.now(), sessionId: execSessionId(exec) || undefined });
|
|
3838
3914
|
return { ok: true, msg: '已登记压缩:下一个回合开始时执行'
|
|
3839
3915
|
+ (a.note ? '(要点已存进你的备忘)' : '(本次没写要点;若压缩后有需要记住的,请带上 note)') };
|
|
3840
3916
|
},
|
|
@@ -3862,7 +3938,7 @@ var contextDropTool = defineTool({
|
|
|
3862
3938
|
const a = (args ?? {});
|
|
3863
3939
|
if (a.note)
|
|
3864
3940
|
appendContextMemo(r.dataRoot, r.sessionKey, String(a.note));
|
|
3865
|
-
writeContextPending(r.dataRoot, r.sessionKey, { mode: 'drop', keep: 0, at: Date.now() });
|
|
3941
|
+
writeContextPending(r.dataRoot, r.sessionKey, { mode: 'drop', keep: 0, at: Date.now(), sessionId: execSessionId(exec) || undefined });
|
|
3866
3942
|
return { ok: true, msg: '已登记丢弃:下一个回合开始时执行'
|
|
3867
3943
|
+ (a.note ? '(要点已存进你的备忘)' : '(本次没写要点;丢弃后这些历史就找不回来了,建议带 note)') };
|
|
3868
3944
|
},
|
|
@@ -4301,7 +4377,19 @@ export function applyExtToolVisibility(agentCtx, selfTag) {
|
|
|
4301
4377
|
return;
|
|
4302
4378
|
const prevTag = extSeenCtx.get(ctx) ?? '';
|
|
4303
4379
|
const tag = selfTag !== undefined ? String(selfTag) : prevTag;
|
|
4380
|
+
// ★ 2026-11-28(复审 Y31):**先判空、再登记**。
|
|
4381
|
+
// 反过来(先 `set` 再判空)会把 `extSeenCtx` 里这个 ctx 的 tag 抹成 `''` ——
|
|
4382
|
+
// `extSeenCtx` 是**模块级、全实例共享**的。多开实例同 cwd 时,B 对"本不该碰的 A 的 ctx"
|
|
4383
|
+
// 调一次本函数(传空 tag)就会踩掉 A 的记录;之后 A 那边 `gain_qq_tools.enable(...)` 的
|
|
4384
|
+
// 补注册(不传 selfTag、靠 prevTag 回落)与整表重放都会因拿不到 tag 直接 return
|
|
4385
|
+
// ⇒ 表现成「enable 了却调不到」,极难查。
|
|
4386
|
+
if (!tag) {
|
|
4387
|
+
traceToolReg('[ext-vis] 跳过(拿不到 selfTag)');
|
|
4388
|
+
return;
|
|
4389
|
+
}
|
|
4304
4390
|
extSeenCtx.set(ctx, tag);
|
|
4391
|
+
// ⚠️ `''` 的语义是**「不碰」**,不是「清空这个 ctx 的记录」—— 判空在登记之前,
|
|
4392
|
+
// 所以传空 tag 不会把已有记录抹掉。要"撤销某个 ctx 的 tag"得另加 API(目前没有这需求)。
|
|
4305
4393
|
// ★★★ 2026-10-31(主人实测后的最终结论):**改成 per-agent 注册**。
|
|
4306
4394
|
// 实测对照:同一次运行里
|
|
4307
4395
|
// · ensureExtToolsGlobal 注册到 apply(ctx) → QQ 会话调不到(unknown tool)
|
|
@@ -4310,10 +4398,6 @@ export function applyExtToolVisibility(agentCtx, selfTag) {
|
|
|
4310
4398
|
// 该 agent 应有的 = 本实例自己的(__selfTag)+ 已领取的,逐个注册到它的 ctx;
|
|
4311
4399
|
// 既不用 deny,也不用 root —— 非 QQ agent 不走这段,天然零泄漏。
|
|
4312
4400
|
// ⚠️ 拿不到 tag 就什么都不做(否则会把"自己实例那份"也漏掉)。
|
|
4313
|
-
if (!tag) {
|
|
4314
|
-
traceToolReg('[ext-vis] 跳过(拿不到 selfTag)');
|
|
4315
|
-
return;
|
|
4316
|
-
}
|
|
4317
4401
|
const all = [...extToolIndex.values()];
|
|
4318
4402
|
if (!all.length)
|
|
4319
4403
|
return; // 还没扫到东西:先不动
|