Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): batch streamed import fingerprints
Chris4377d475a211
diff --git a/apps/desktop/src/main/bot-import/__tests__/files.test.ts b/apps/desktop/src/main/bot-import/__tests__/files.test.tsindex faf001b5ee..6f9d8a9acc 100644--- a/apps/desktop/src/main/bot-import/__tests__/files.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/files.test.ts@@ -173,7 +173,11 @@ it('preserves exact legacy budget bytes and fingerprints across streamed string/{ name: 'binary', bytes: Buffer.alloc(128 * 1024, 255), executable: true }];const items = [{ view: { id: 'fixture', name: text, category: 'memory' as const, selected: true }, files,asset: { name: 'asset', bytes: Buffer.from('fixture') },- credential: { format: 'fixture', value: { when: new Date('2026-09-29T00:00:00Z'), list: [null, false, undefined, 7, Infinity], omitted: undefined, hidden: { toJSON: () => undefined } } }, text }];+ credential: { format: 'fixture', value: {+ when: new Date('2026-09-29T00:00:00Z'), list: [null, false, undefined, 7, Infinity],+ strings: ['', '😀漢\u0000\n"\\\ud800', '\u0000'.repeat(16 * 1024)],+ omitted: undefined, hidden: { toJSON: () => undefined },+ } }, text }];const mapped = items.map(item => ({ ...item, files: item.files.map(file => ({ ...file, bytes: null })), asset: { ...item.asset, bytes: null } }));const expected = Buffer.byteLength(JSON.stringify(mapped)) + files.reduce((total, file) => total + file.bytes.length + 256, 0) + items[0]!.asset.bytes.length + 256;const before = serializeImportSnapshot({ source: {} as never, fingerprint: 'fixture', items });diff --git a/apps/desktop/src/main/bot-import/files.ts b/apps/desktop/src/main/bot-import/files.tsindex 27eab9c50e..25bf3de821 100644--- a/apps/desktop/src/main/bot-import/files.ts+++ b/apps/desktop/src/main/bot-import/files.ts@@ -35,7 +35,14 @@ export function snapshotFingerprint(items: ImportItem[]): string {export async function snapshotFingerprintAsync(items: ImportItem[]): Promise<string> {const hash = createHash('sha256');- await visitSnapshotJson(items, bytes => createHash('sha256').update(bytes).digest('hex'), text => { hash.update(text); });+ // Batch punctuation and short metadata into bounded hash updates. The visitor+ // still accounts for every fragment and yields at its normal byte boundary.+ let chunk = '';+ await visitSnapshotJson(items, bytes => createHash('sha256').update(bytes).digest('hex'), text => {+ chunk += text;+ if (chunk.length >= 16 * 1024) { hash.update(chunk); chunk = ''; }+ });+ if (chunk) hash.update(chunk);return hash.digest('hex');}diff --git a/apps/desktop/src/main/bot-import/snapshotJson.ts b/apps/desktop/src/main/bot-import/snapshotJson.tsindex b1dd4912a7..e9075632ad 100644--- a/apps/desktop/src/main/bot-import/snapshotJson.ts+++ b/apps/desktop/src/main/bot-import/snapshotJson.ts@@ -6,6 +6,9 @@ import type { ImportItem } from './types.js';function* snapshotJson(items: ImportItem[], encodeBytes: (bytes: Buffer) => unknown): Generator<string> {const ancestors = new Set<object>();function* quoted(value: string): Generator<string> {+ // Most metadata consists of short keys/values. Keep them in one bounded+ // fragment instead of visiting separate quotes and contents for each field.+ if (value.length <= 16 * 1024) { yield JSON.stringify(value); return; }yield '"';for (let start = 0; start < value.length;) {let end = Math.min(start + 16 * 1024, value.length);