Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(x): 从引用消息快照中排除当前请求

Cindyb7d603e25795
diff --git a/apps/desktop/src/main/hook-control/__tests__/dispatcher.test.ts b/apps/desktop/src/main/hook-control/__tests__/dispatcher.test.ts
index e7895feb42..70df30cda6 100644
--- a/apps/desktop/src/main/hook-control/__tests__/dispatcher.test.ts
+++ b/apps/desktop/src/main/hook-control/__tests__/dispatcher.test.ts
@@ -404,6 +404,21 @@ describe('buildHookSessionTitle', () => {
});
describe('normalizeTaskSource', () => {
+ it('excludes the X trigger from references without mutating the wire chain', () => {
+ const current = { messageId: 'current', author: '@user', text: '@bot request' };
+ const source = {
+ im: 'x' as const, triggerMessageId: 'current', userText: 'request',
+ threadContext: [current],
+ };
+ expect(normalizeTaskSource(source).threadContext).toEqual([]);
+ expect(source.threadContext).toEqual([current]);
+ expect(normalizeTaskSource({ ...source, userText: undefined }).threadContext).toEqual([current]);
+ expect(normalizeTaskSource({ ...source, im: 'slack' }).threadContext).toEqual([current]);
+ expect(normalizeTaskSource({ ...source, triggerMessageId: undefined }).threadContext).toEqual([current]);
+ const legacy = { author: '@user', text: 'request' };
+ expect(normalizeTaskSource({ ...source, threadContext: [legacy] }).threadContext).toEqual([legacy]);
+ });
+
it('bounds server-controlled display metadata before session persistence', async () => {
const source = normalizeTaskSource({
im: 'telegram',
@@ -712,6 +727,9 @@ describe('dispatcher 核心语义', () => {
expect(fr.calls[0]?.source).toMatchObject({
userText: '查看 PR', triggerMessageId: '2', xContext: { requesterId: 'u' },
});
+ expect(fr.calls[0]?.source?.threadContext).toEqual([
+ expect.objectContaining({ messageId: '1', author: '@other', text: longText.slice(0, 4000) }),
+ ]);
});
it('标题用 source.userText, 不吃 prompt 里 server 挂的 thread 上下文块', async () => {
diff --git a/apps/desktop/src/main/hook-control/dispatcher.ts b/apps/desktop/src/main/hook-control/dispatcher.ts
index a1809668d3..ab857423d1 100644
--- a/apps/desktop/src/main/hook-control/dispatcher.ts
+++ b/apps/desktop/src/main/hook-control/dispatcher.ts
@@ -496,7 +496,13 @@ export function normalizeTaskSource(source: TaskSource): TaskSource {
const channelName = boundedNullable(source.channelName, SOURCE_CHANNEL_NAME_MAX);
const teamId = boundedNullable(source.teamId, SOURCE_TEAM_ID_MAX);
const teamName = boundedNullable(source.teamName, SOURCE_TEAM_NAME_MAX);
- const threadContext = source.threadContext?.slice(0, SOURCE_THREAD_CONTEXT_MAX).map((entry) => ({
+ // The X wire chain includes the trigger for prompt assembly. Display it only
+ // as userText, not again among referenced messages. Match the original ID
+ // before bounding the snapshot; legacy entries without IDs stay untouched.
+ const displayContext = source.im === 'x' && source.triggerMessageId && source.userText?.trim()
+ ? source.threadContext?.filter((entry) => entry.messageId !== source.triggerMessageId)
+ : source.threadContext;
+ const threadContext = displayContext?.slice(0, SOURCE_THREAD_CONTEXT_MAX).map((entry) => ({
...(entry.messageId !== undefined ? { messageId: entry.messageId.slice(0, SOURCE_TRIGGER_MESSAGE_ID_MAX) } : {}),
...(entry.authorId !== undefined ? { authorId: entry.authorId.slice(0, SOURCE_THREAD_AUTHOR_MAX) } : {}),
...(entry.replyToMessageId !== undefined ? { replyToMessageId: entry.replyToMessageId?.slice(0, SOURCE_TRIGGER_MESSAGE_ID_MAX) ?? null } : {}),
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 5dfbd543f3..eb6b454c08 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -47,7 +47,9 @@
新客户端在展示元数据截短前校验当前消息身份及相邻回复关系,并组装一次模型 prompt:
顶部请求者、按序历史、链尾当前请求。沿用历史随机栅栏、逐行作者与缺失提示;排队及恢复
直接复用已组装结果,不重复拼接。展示沿用原有有界快照,不拿其截短正文重建模型输入。
-这里只改变每条消息的文本组装,不修改主 Agent system prompt、权限或 UI。
+X 快照有请求正文时,按原始 triggerMessageId 排除引用列表中的当前请求,避免与卡片正文
+重复显示;模型组装仍读取完整 wire 回复链。旧条目缺少消息 ID 时保留,不按正文猜测去重。
+这里只改变每条消息的文本组装与展示元数据,不修改主 Agent system prompt、权限或 UI 结构。
新服务端继续发送兼容 `prompt` 给旧客户端;新客户端遇到旧服务端、旧持久任务或不完整
结构化字段时原样使用该 prompt。两仓可独立升级,无数据库迁移、Mobile 冷更或部署顺序要求。