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(im): strip internal citations from background results

Dasha8f22434d583
diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
index f88f705512..4eedc38dfe 100644
--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
@@ -755,6 +755,49 @@ describe('turnRunner 渠道任务后台结果回传', () => {
expect(mocks.slackIm.sendFile).not.toHaveBeenCalled();
});
+ it.each((['rich-card', 'chunked-text'] as const).flatMap((kind) =>
+ [false, true].flatMap((remote) => ['done', 'error'].map((ending) => ({ kind, remote, ending }))),
+ ))('strips background citations across split deltas and final snapshots ($kind, remote=$remote, $ending)', async ({ kind, remote, ending }) => {
+ const stub = streamingHandleStub();
+ mocks.slackIm.startStreamingText.mockResolvedValue(stub);
+ if (kind === 'chunked-text') {
+ runner = createTurnRunner({ ...fakeAdapter, output: {
+ kind, im: fakeAdapter.im, commitFinal: vi.fn(async () => undefined),
+ } }, fakeRepo, fakeCards);
+ }
+ const h = makeSessionHarness('citation-background');
+ if (remote) Object.assign(h.session, { remoteHostId: 'ssh-host' });
+ runner.attachSessionOutput(h.session, 'U1');
+ const turnOrigin = remote
+ ? { kind: 'scheduler' as const, scheduleId: 's', scheduleName: 'daily' }
+ : undefined;
+ for (const text of ['结果\uE200ci', 'te\uE202turn0search0', '\uE201。']) {
+ const previousCalls = stub.replace.mock.calls.length;
+ h.emit({ type: 'text', data: { text }, turnOrigin });
+ if (kind === 'rich-card') {
+ await vi.waitFor(() => expect(stub.replace.mock.calls.length).toBeGreaterThan(previousCalls));
+ expect(stub.replace.mock.calls.at(-1)![0]).not.toMatch(/[\uE200-\uE202]|turn0search0/);
+ }
+ }
+ h.emit({ type: 'text', data: {
+ text: '结果\uE200cite\uE202turn0search0\uE201。[来源](https://example.com)\uE200cite\uE202unfinished',
+ isFinal: true,
+ }, turnOrigin });
+ h.emit(ending === 'done'
+ ? { type: 'done', data: {}, turnOrigin }
+ : { type: 'error', data: { message: 'failed', isTerminal: true }, turnOrigin });
+ const body = `${remote ? '🤖 自动任务「daily」\n\n' : ''}结果。[来源](https://example.com)`;
+ const expected = ending === 'error' ? `${body}\n\n${slackUi.agent.runtimeError('failed')}` : body;
+ if (kind === 'rich-card') {
+ await vi.waitFor(() => expect(stub.finalize).toHaveBeenCalledExactlyOnceWith(expected));
+ } else {
+ await vi.waitFor(() => expect(mocks.slackIm.sendMarkdownText).toHaveBeenCalledExactlyOnceWith(
+ 'U1', expected, { threadTs: undefined },
+ ));
+ }
+ await runner.disposeAllSessions();
+ });
+
it('重启后仅恢复输出监听,不新建会话;重复恢复不会重复回复', async () => {
const h = makeSessionHarness('cold-session');
const stub = streamingHandleStub();
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index 289eacca1c..acb1002b51 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -2648,11 +2648,12 @@ export function createTurnRunner(
/** 转播卡正文:运行中 = 头 + 步骤时间线 + 正文;收口 = 头 + 正文(去步骤)。 */
function composeTranspondView(state: SessionState, t: ScheduledTranspond, final: boolean): string {
const header = t.header;
+ const publicBody = stripInternalWebCitations(t.buffer);
// Rich transports resolve managed refs themselves. A remote session's refs
// must stay text, never reach those host-local file/media resolvers.
const body = state.makerSession.remoteHostId
- ? transformXdtRefs(t.buffer, { image: (ref) => ref.alt, file: (ref) => ref.alt })
- : t.buffer;
+ ? transformXdtRefs(publicBody, { image: (ref) => ref.alt, file: (ref) => ref.alt })
+ : publicBody;
if (final) {
return [header, body].filter(Boolean).join('\n\n');
}
diff --git a/docs/product-rules/telegram-bot-parity.md b/docs/product-rules/telegram-bot-parity.md
index 9d5bbcd9e8..04a0b75329 100644
--- a/docs/product-rules/telegram-bot-parity.md
+++ b/docs/product-rules/telegram-bot-parity.md
@@ -250,6 +250,8 @@ hook 侧既有的逐轮 `[渠道说明]`,两者措辞不同但都向模型说
包括自动任务、其它任务发送消息触发的回复;无需先 `/ctr` 接管。自动任务保留任务名,
其它来源直接显示回复正文,目的地沿用该任务原聊天和话题。正常 IM 入站轮次仍只发送一次;
子代理和旧轮次的后台事件不转播。纯文本渠道通过适配器使用现有有效聊天上下文发送最终结果。
+个人后台正文与普通回复、官方后台结果共用 `stripInternalWebCitations` 清理内部引用标记,
+覆盖流式分段、最终快照及成功/失败收口;普通 Markdown 来源链接保留。
工具结果中的托管图片沿用正常 IM 轮次的解析与去重规则,即使最终正文没有重复引用也会回传;
SSH 任务不把远端路径或托管媒体引用当作本地文件上传;个人渠道的正文引用仅保留标签,
官方渠道在收集工具图片和最终附件之前排除远程执行实例。