Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge upstream/main into bot-checkpoint-fresh
zqchris6005c3ec3a74
diff --cc apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.tsindex 0990d57ffa,a7ffb3c0af..c47717f5a0--- a/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts@@@ -398,53 -408,10 +408,55 @@@ describe('createContextOverflowRolloverfailing.getSessionRow.mockResolvedValue({ ...await failing.getSessionRow(), source: 'bot', botRole: 'canonical', contextTokens: 180_000 });await expect(createContextOverflowRollover(failing).prepareUnhealthySession('s1')).resolves.toBe(true);expect(failing.setPendingHandoff.mock.calls[0]![1] as string).not.toContain('Working memory');+ // 自有会话清单读失败:只认当前对话,照样换窗。+ expect(failing.setPendingHandoff.mock.calls[0]![1] as string).toContain('"session_ids":["s1"]}');});+ it('checkpoints a companion at 70% only when the working memory is fresh, and keeps the 90% line otherwise', async () => {+ const source = [msg('user', 'Keep going', 'u1'), msg('assistant', 'On it', 'a1')];+ const bot = async (deps: ReturnType<typeof makeDeps>, contextTokens: number) =>+ deps.getSessionRow.mockResolvedValue({ ...await deps.getSessionRow(), source: 'bot', botRole: 'canonical', contextTokens });++ // 新鲜且能渲染账本:70%(窗口 200K → 140K)即换窗,账本段只读一次并原样进交接。+ const ledger = '== Working memory (host-maintained summary; not authorization) ==\n- 周五前改完周报模板';+ const fresh = { ...makeDeps(source), isWorkingMemoryFresh: vi.fn(async () => true), readWorkingMemoryNote: vi.fn(async () => ledger) };+ await bot(fresh, 140_000);+ await expect(createContextOverflowRollover(fresh).prepareUnhealthySession('s1')).resolves.toBe(true);+ expect(fresh.isWorkingMemoryFresh).toHaveBeenCalledWith('s1');+ expect(fresh.readWorkingMemoryNote).toHaveBeenCalledTimes(1);+ expect(fresh.setPendingHandoff.mock.calls[0]![1] as string).toContain('周五前改完周报模板');++ // 新鲜但账本段渲染不出来(读取失败 / 空账本):不提前换窗,维持 90%。+ const unrendered = { ...makeDeps(source), isWorkingMemoryFresh: vi.fn(async () => true), readWorkingMemoryNote: vi.fn(async (): Promise<string | null> => null) };+ await bot(unrendered, 150_000);+ await expect(createContextOverflowRollover(unrendered).prepareUnhealthySession('s1')).resolves.toBe(false);+ expect(unrendered.closeSession).not.toHaveBeenCalled();++ // 不新鲜:75% 不换窗;到 90% 不问账本照旧换窗。+ const stale = { ...makeDeps(source), isWorkingMemoryFresh: vi.fn(async () => false) };+ await bot(stale, 150_000);+ await expect(createContextOverflowRollover(stale).prepareUnhealthySession('s1')).resolves.toBe(false);+ expect(stale.closeSession).not.toHaveBeenCalled();+ stale.isWorkingMemoryFresh.mockClear();+ await bot(stale, 180_000);+ await expect(createContextOverflowRollover(stale).prepareUnhealthySession('s1')).resolves.toBe(true);+ expect(stale.isWorkingMemoryFresh).not.toHaveBeenCalled();++ // 70% 以下不读账本。+ const below = { ...makeDeps(source), isWorkingMemoryFresh: vi.fn(async () => true) };+ await bot(below, 139_999);+ await expect(createContextOverflowRollover(below).prepareUnhealthySession('s1')).resolves.toBe(false);+ expect(below.isWorkingMemoryFresh).not.toHaveBeenCalled();++ // 判据抛错按不新鲜;没接判据的调用方维持 90%。+ const failing = { ...makeDeps(source), isWorkingMemoryFresh: vi.fn(async (): Promise<boolean> => { throw new Error('disk'); }) };+ await bot(failing, 150_000);+ await expect(createContextOverflowRollover(failing).prepareUnhealthySession('s1')).resolves.toBe(false);+ const legacy = makeDeps(source);+ await bot(legacy, 150_000);+ await expect(createContextOverflowRollover(legacy).prepareUnhealthySession('s1')).resolves.toBe(false);+ });+it.each([['desktop', null, 180_000], ['bot', 'delegation', 180_000], ['bot', 'group', 180_000],['bot', null, 180_000], ['bot', 'canonical', 179_999], ['bot', 'canonical', 0],diff --cc apps/desktop/src/main/maker-ipc/contextOverflowRollover.tsindex 0c8721ac65,d601d3ea78..3790195553--- a/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts+++ b/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts@@@ -413,11 -408,12 +413,17 @@@ export interface ContextOverflowRollove* 非伙伴主对话或无账本返回 null;读取失败也按 null,账本不能挡住换窗。*/readWorkingMemoryNote?(sessionId: string): Promise<string | null>;+ /**+ * 账本是否已覆盖最近一条完成回复(botWorkingMemory.isWorkingMemoryFreshForSession)。+ * true 时伙伴换窗线提前到 70%;缺省 / false / 抛错都按不新鲜,维持 90%。+ */+ isWorkingMemoryFresh?(sessionId: string): Promise<boolean>;+ /**+ * 伙伴自己的会话清单(botHistoryScope.listBotRecallSessionIds:私聊优先、后台任务补足,+ * 并告知私聊是否没放全),写进回忆指引让 history 工具按 session_ids 限定到自己的历史。+ * 非伙伴返回空清单;失败也按空清单,不挡换窗。+ */+ listCompanionSessionIds?(sessionId: string): Promise<{ sessionIds: string[]; chatsTruncated: boolean }>;/** 不受 handoff 窗口限制的最近 user,避免工具密集 turn 把身份扫丢。 */findLatestUser?(sessionId: string): Promise<OverflowSourceMessage | null>;findLatestRebuildMeta(@@@ -557,13 -553,20 +563,27 @@@ export function createContextOverflowRoreturn null;}};+ const isWorkingMemoryFresh = async (sessionId: string): Promise<boolean> => {+ try {+ return (await deps.isWorkingMemoryFresh?.(sessionId)) === true;+ } catch {+ return false;+ }+ };+ // 伙伴自有会话清单同样是增强:非伙伴不查,读不到按只认当前对话。+ const companionRecall = async (+ sessionId: string,+ companion: boolean,+ ): Promise<{ companionSessionIds: string[]; companionSessionIdsTruncated: boolean }> => {+ const none = { companionSessionIds: [], companionSessionIdsTruncated: false };+ if (!companion) return none;+ try {+ const own = await deps.listCompanionSessionIds?.(sessionId);+ return own ? { companionSessionIds: own.sessionIds, companionSessionIdsTruncated: own.chatsTruncated } : none;+ } catch {+ return none;+ }+ };const runRecover = async (sessionId: string,errorData: unknown,@@@ -955,7 -953,9 +979,9 @@@sessionId,reason: companion || isOversizedHistoryErrorData(lastError) ? 'native-session-recovery' : rebuildReason,includeToolResults: companion || isOversizedHistoryErrorData(lastError),+ companion,+ ...(await companionRecall(sessionId, companion)),- workingMemory: await readWorkingMemoryNote(sessionId),+ workingMemory: earlyWorkingMemory ?? (await readWorkingMemoryNote(sessionId)),});await deps.commitRebuild(sessionId, handoff, {reason: rebuildReason,diff --cc apps/desktop/src/main/maker-ipc/register.tsindex f77b704f1a,a1c11431a5..d61e8a1d9a--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@@ -16441,7 -16447,8 +16448,9 @@@ export function registerMakerIpc(maker},listMessages: (sessionId) => listMessagesForAgentHandoff(sessionId, 400),readWorkingMemoryNote,+ isWorkingMemoryFresh: (sessionId) => isWorkingMemoryFreshForSession(sessionId, ownerScopedUserDataPath()),+ // 伙伴自有会话(当前 + 恢复前旧对话整体优先,后台任务补足),写进回忆指引限定 history 工具范围。+ listCompanionSessionIds: (sessionId) => listBotRecallSessionIds(sessionId, COMPANION_SESSION_IDS_LIMIT),findLatestUser: findLatestUserMessageForRebuild,findLatestRebuildMeta: findLatestContextRebuildMeta,getLiveSession: (sessionId) => maker.getSession(sessionId),