jbc-dssi 1.1.51 → 1.1.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.51",
3
+ "version": "1.1.52",
4
4
  "type": "module",
5
5
  "description": "鲸编程 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [
@@ -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({ deliver, emitLine, emitReplyLine, now, budgetFor, recentLinesOf }) {
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: text,
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
  }