jbc-dssi 1.1.51 → 1.1.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/index.js
CHANGED
|
@@ -1064,7 +1064,8 @@ function activate(ctx, config) {
|
|
|
1064
1064
|
* 缓冲最近 N 条事件(补自增 seq),手机重连时按原顺序重放,避免断线跨过
|
|
1065
1065
|
* room_line/round_end 后实时态永久卡住。手机侧按 seq 去重(老客户端忽略新字段)。
|
|
1066
1066
|
*/
|
|
1067
|
-
|
|
1067
|
+
// boot = 本次进程启动时间:插件重启后 seq 归零,手机侧据此重置去重游标
|
|
1068
|
+
const groupsEventBuffer = createGroupsEventBuffer({ boot: `boot-${Date.now()}` });
|
|
1068
1069
|
|
|
1069
1070
|
function pushGroupsEvent(payload) {
|
|
1070
1071
|
const event = groupsEventBuffer.record(payload);
|
|
@@ -21,8 +21,16 @@ export const GROUPS_EVENT_BUFFER_MAX = 200;
|
|
|
21
21
|
* @param {object} [opts]
|
|
22
22
|
* @param {number} [opts.max] 缓冲上限
|
|
23
23
|
* @param {Function} [opts.now] 时钟(默认 Date.now,仅用于测试可控性)
|
|
24
|
+
* @param {string|number} [opts.boot] 进程代际标识(默认随机串)。
|
|
25
|
+
* 为什么需要:seq 是**进程内自增**,插件重启后从 1 重新开始;而手机侧的去重游标
|
|
26
|
+
* 还停在上一次的高位 → 重启后所有事件都会被当成"重复"丢掉(群聊卡在"正在思考",
|
|
27
|
+
* 重进群靠快照才恢复)。带上 boot,手机一看到 boot 变了就重置游标(2026-11-04 真事故)。
|
|
24
28
|
*/
|
|
25
|
-
export function createGroupsEventBuffer({
|
|
29
|
+
export function createGroupsEventBuffer({
|
|
30
|
+
max = GROUPS_EVENT_BUFFER_MAX,
|
|
31
|
+
now = () => Date.now(),
|
|
32
|
+
boot = `${now()}-${Math.random().toString(36).slice(2, 10)}`,
|
|
33
|
+
} = {}) {
|
|
26
34
|
const events = [];
|
|
27
35
|
let seq = 0;
|
|
28
36
|
|
|
@@ -30,7 +38,12 @@ export function createGroupsEventBuffer({ max = GROUPS_EVENT_BUFFER_MAX, now = (
|
|
|
30
38
|
/** 记一条事件(补 seq),返回带 seq 的副本,供实时广播用。 */
|
|
31
39
|
record(payload) {
|
|
32
40
|
seq += 1;
|
|
33
|
-
const event = {
|
|
41
|
+
const event = {
|
|
42
|
+
...payload,
|
|
43
|
+
seq,
|
|
44
|
+
boot,
|
|
45
|
+
at: Number.isFinite(Number(payload?.at)) ? payload.at : now(),
|
|
46
|
+
};
|
|
34
47
|
events.push(event);
|
|
35
48
|
while (events.length > max) events.shift();
|
|
36
49
|
return event;
|
package/package.json
CHANGED
|
@@ -113,3 +113,34 @@ export async function buildTurnCards({ members, fetchImpl = fetch }) {
|
|
|
113
113
|
clearTimeout(timer);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 把「对方最近 N 轮卡片」渲染成一段注入文本(2026-11-04:两人沟通双向注入)。
|
|
119
|
+
*
|
|
120
|
+
* 口径(老谢定稿):
|
|
121
|
+
* · 只在**本轮恰好两人对话**时使用(A↔B 互读对方最近 3–5 轮);
|
|
122
|
+
* · 3 人及以上本轮**不注入**(避免 n²;多人协作方案暂不做);
|
|
123
|
+
* · 预算:最多 5 条 / 1200 字,超了从最旧开始丢,最近的在最后。
|
|
124
|
+
*
|
|
125
|
+
* @param {Array<object>} cards 对方卡片(按时间升序)
|
|
126
|
+
* @param {string} counterpartName 对方名字(用于标题)
|
|
127
|
+
* @returns {string} 注入文本;没有卡片返回空串(调用方据此跳过注入)
|
|
128
|
+
*/
|
|
129
|
+
export function renderCounterpartContext(cards, counterpartName = '对方') {
|
|
130
|
+
const list = (cards ?? []).filter((c) => c && (c.title || c.conclusion || c.description));
|
|
131
|
+
if (list.length === 0) return '';
|
|
132
|
+
const picked = list.slice(-5);
|
|
133
|
+
const lines = picked.map((c) => {
|
|
134
|
+
const head = c.title || c.description || '';
|
|
135
|
+
const body = c.conclusion || c.description || '';
|
|
136
|
+
const when = c.at ? new Date(Number(c.at)).toTimeString().slice(0, 5) : '';
|
|
137
|
+
return `- ${when ? when + ' ' : ''}${head}${body && body !== head ? ':' + body : ''}`;
|
|
138
|
+
});
|
|
139
|
+
let text = lines.join('\n');
|
|
140
|
+
if (text.length > 1200) text = text.slice(text.length - 1200);
|
|
141
|
+
return [
|
|
142
|
+
`【协作上下文:${counterpartName} 最近 ${picked.length} 轮的记录摘要(来自群内记忆卡)】`,
|
|
143
|
+
text,
|
|
144
|
+
'(需要更早细节请直接问对方;以上摘要可能不完整)',
|
|
145
|
+
].join('\n');
|
|
146
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { mentionsIn } from '../mentions.js';
|
|
10
10
|
import { buildManagerPrompt, buildMemberPrompt } from '../prompt.js';
|
|
11
|
+
import { renderCounterpartContext } from './turncard.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 轮次上限(最高红线,用户定稿):
|
|
@@ -34,22 +35,50 @@ const MAX_REFUSALS = 2;
|
|
|
34
35
|
* @param {Function} deps.budgetFor (taskText) => number
|
|
35
36
|
* @param {Function} deps.recentLinesOf (group) => object[]
|
|
36
37
|
*/
|
|
37
|
-
export function createRoundRunner({
|
|
38
|
+
export function createRoundRunner({
|
|
39
|
+
deliver,
|
|
40
|
+
emitLine,
|
|
41
|
+
emitReplyLine,
|
|
42
|
+
now,
|
|
43
|
+
budgetFor,
|
|
44
|
+
recentLinesOf,
|
|
45
|
+
/**
|
|
46
|
+
* (groupId, memberId) => 该成员最近的记忆卡数组(升序)。
|
|
47
|
+
* 用于「两人沟通双向注入」;缺省返回空(老插件/无卡片时不注入)。
|
|
48
|
+
*/
|
|
49
|
+
cardsOf = () => [],
|
|
50
|
+
}) {
|
|
38
51
|
/**
|
|
39
52
|
* 用户直接 @ 成员:被点名的成员直接回答,不经主管(用户定稿:直接 @ 生效)。
|
|
40
53
|
* 不算「分发→反馈」轮次,也不触发任何接力。
|
|
41
54
|
*/
|
|
42
55
|
async function runDirect(group, round, targets, members, text, attachments, onProgress) {
|
|
56
|
+
/*
|
|
57
|
+
* 两人沟通:双向注入(2026-11-04 老谢定稿)。
|
|
58
|
+
* · 只在 targets.length === 2 时启用:A 读 B 最近几轮卡片,B 读 A 的;
|
|
59
|
+
* · 3 人及以上**不注入**(避免 n²,多人协作方案暂不做)。
|
|
60
|
+
*/
|
|
61
|
+
const mutual = targets.length === 2;
|
|
62
|
+
const cardsCache = mutual
|
|
63
|
+
? targets.map((m) => cardsOf(group.id, m.id))
|
|
64
|
+
: [];
|
|
43
65
|
for (const member of targets) {
|
|
44
66
|
if (round.stopped) return;
|
|
45
67
|
round.currentMemberId = member.id;
|
|
46
68
|
onProgress?.({ breakpoint: `已分派给 ${member.name},等待反馈` });
|
|
69
|
+
let task = text;
|
|
70
|
+
if (mutual) {
|
|
71
|
+
const otherIndex = targets.findIndex((m) => m.id === member.id) === 0 ? 1 : 0;
|
|
72
|
+
const other = targets[otherIndex];
|
|
73
|
+
const contextText = renderCounterpartContext(cardsCache[otherIndex], other.name);
|
|
74
|
+
if (contextText) task = `${text}\n\n${contextText}`;
|
|
75
|
+
}
|
|
47
76
|
const prompt = buildMemberPrompt({
|
|
48
77
|
group,
|
|
49
78
|
members,
|
|
50
79
|
selfId: member.id,
|
|
51
80
|
recentLines: recentLinesOf(group),
|
|
52
|
-
task
|
|
81
|
+
task,
|
|
53
82
|
mode: 'user-direct',
|
|
54
83
|
rules: group.rules,
|
|
55
84
|
});
|
|
@@ -112,6 +112,8 @@ export function createRoundEngine({ ctx, state, dssAgent, log, save, broadcast,
|
|
|
112
112
|
now,
|
|
113
113
|
budgetFor,
|
|
114
114
|
recentLinesOf,
|
|
115
|
+
// 两人沟通时注入对方最近几轮卡片(2026-11-04);数据来自本机 turnCards 副本
|
|
116
|
+
cardsOf: (groupId, memberId) => ((state.turnCards?.[groupId] ?? {})[memberId] ?? []),
|
|
115
117
|
});
|
|
116
118
|
|
|
117
119
|
/**
|
|
@@ -273,6 +275,15 @@ export function createRoundEngine({ ctx, state, dssAgent, log, save, broadcast,
|
|
|
273
275
|
}));
|
|
274
276
|
const cards = await buildTurnCards({ members });
|
|
275
277
|
if (cards.length === 0) return;
|
|
278
|
+
// 本机副本(注入用):追加到 state.turnCards[groupId][memberId],每人最多留 20 条
|
|
279
|
+
state.turnCards ??= {};
|
|
280
|
+
const perGroup = (state.turnCards[group.id] ??= {});
|
|
281
|
+
for (const card of cards) {
|
|
282
|
+
const list = (perGroup[card.memberId] ??= []);
|
|
283
|
+
list.push({ ...card, at: now() });
|
|
284
|
+
if (list.length > 20) list.splice(0, list.length - 20);
|
|
285
|
+
}
|
|
286
|
+
void save?.();
|
|
276
287
|
broadcast?.({ type: 'turn_cards', groupId: group.id, cards, at: now() });
|
|
277
288
|
} catch (error) {
|
|
278
289
|
log?.(`群 ${group.id} 记忆卡生成失败(不影响本轮):${error?.message ?? error}`);
|
|
@@ -18,6 +18,9 @@ export function emptyState() {
|
|
|
18
18
|
groups: [],
|
|
19
19
|
rooms: {},
|
|
20
20
|
groupSessions: {},
|
|
21
|
+
// 契约化轮次记忆卡(2026-11-04):groupId -> memberId -> [{title,description,conclusion,importance,trigger,at}]
|
|
22
|
+
// 本机副本用于"两人沟通时互相注入对方最近几轮";服务端 group_turns 是跨设备权威副本。
|
|
23
|
+
turnCards: {},
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -47,6 +50,7 @@ export async function loadState(stateFile, log) {
|
|
|
47
50
|
version: GROUPS_STATE_VERSION,
|
|
48
51
|
groups: parsed.groups ?? [],
|
|
49
52
|
rooms: parsed.rooms ?? {},
|
|
53
|
+
turnCards: parsed.turnCards ?? {},
|
|
50
54
|
groupSessions: parsed.groupSessions ?? {},
|
|
51
55
|
};
|
|
52
56
|
}
|