feat: integrate learning module
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-08-16 20:52:16 +08:00
parent 26b52d76e3
commit 01bee3188b
107 changed files with 6318 additions and 12063 deletions

View File

@@ -1,5 +1,9 @@
import { describe, expect, it } from 'vitest';
import { applyStreamingPartDeltaToMessage, normalizeOpencodeSessionMessages } from '@/lib/opencode-message';
import {
applyStreamingPartDeltaToMessage,
applyStreamingPartToMessage,
normalizeOpencodeSessionMessages,
} from '@/lib/opencode-message';
describe('opencode message normalization', () => {
it('keeps reasoning deltas as thinking content when the full part has not arrived yet', () => {
@@ -77,6 +81,71 @@ describe('opencode message normalization', () => {
]);
});
it('keeps compaction-only messages out of the visible transcript', () => {
const messages = normalizeOpencodeSessionMessages([
{
info: {
id: 'msg_compaction',
role: 'assistant',
sessionID: 'ses_1',
time: { created: 1747040000000, completed: 1747040001000 },
},
parts: [
{
id: 'part_compaction',
type: 'compaction',
auto: true,
summary: 'PRIVATE COMPACTION SUMMARY',
},
{ id: 'step_finish', type: 'step-finish' },
],
},
{
id: 'legacy_compaction',
role: 'assistant',
content: [{ type: 'compaction', text: 'PRIVATE LEGACY SUMMARY' }],
},
]);
expect(messages).toEqual([]);
expect(JSON.stringify(messages)).not.toContain('PRIVATE COMPACTION SUMMARY');
expect(JSON.stringify(messages)).not.toContain('PRIVATE LEGACY SUMMARY');
});
it('does not leak compaction text through streaming message projections', () => {
const input = {
sessionID: 'ses_1',
messageID: 'msg_compaction',
partID: 'part_compaction',
delta: 'PRIVATE COMPACTION SUMMARY',
part: {
id: 'part_compaction',
type: 'compaction',
},
};
expect(applyStreamingPartToMessage(null, input)).toBeNull();
expect(applyStreamingPartDeltaToMessage(null, input)).toBeNull();
expect(applyStreamingPartDeltaToMessage({
id: 'msg_compaction',
role: 'assistant',
content: [{ type: 'text', text: 'Visible text' }],
}, input)).toEqual({
id: 'msg_compaction',
role: 'assistant',
content: [{ type: 'text', text: 'Visible text' }],
});
expect(applyStreamingPartToMessage({
id: 'msg_compaction',
role: 'assistant',
content: [{ type: 'text', id: 'part_compaction', text: 'PRIVATE COMPACTION SUMMARY' }],
}, input)).toEqual({
id: 'msg_compaction',
role: 'assistant',
content: [],
});
});
it('retains bounded runtime tool evidence without exposing raw tool state', () => {
const messages = normalizeOpencodeSessionMessages([
{