@brunobracaioli/aibrain 0.3.0-beta.7 → 0.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ import { register as registerContext } from './context-compaction.ts';
2
+
3
+ export function register(on: Parameters<typeof registerContext>[0]): void {
4
+ return registerContext(on, {
5
+ enabled: true,
6
+ disclosed: true,
7
+ policyVersion: 2,
8
+ compactAtPercent: 60,
9
+ keepThreshold: 0.5,
10
+ preserveRecentMessages: 6,
11
+ minReductionRatio: 0.25,
12
+ truncateHeadChars: 300,
13
+ maxStateTokens: 25_000,
14
+ maxRequestTokens: 30_000,
15
+ compactionStrategy: 'native_summary_notes',
16
+ preservationMode: 'upstream_compatible',
17
+ });
18
+ }
@@ -0,0 +1,51 @@
1
+ import { expect, test } from 'claude-code/testing';
2
+
3
+ const contractTest: Parameters<typeof test>[2] = async ($, on) => {
4
+ const monotonicStart = globalThis.performance?.now?.();
5
+ expect(Number.isFinite(monotonicStart)).toBe(true);
6
+ on('prompt.submit', () => ({ text: 'native-host-contract-ok' }));
7
+ on('tool.call', () => ({ result: { content: 'native-host-tool-ok' } }));
8
+ on('session.messages', () => ({ value: [] }));
9
+ let usageCalls = 0;
10
+ on('session.usage', () => ({
11
+ value: (() => {
12
+ usageCalls += 1;
13
+ return { context: { percent: 90, tokens: 900, window: 1_000 } };
14
+ })(),
15
+ }));
16
+ on('ui.log', () => ({ value: undefined }));
17
+ on('ui.toast', () => ({ value: undefined }));
18
+ let compactCalls = 0;
19
+ on('session.compact', () => {
20
+ compactCalls += 1;
21
+ return {
22
+ messages: [{ role: 'assistant', text: 'native-summary-contract-ok', toolUses: [] }],
23
+ };
24
+ });
25
+ on('turn.complete', () => ({ text: '' }));
26
+ const prompt = await $.prompt.submit({ text: 'native-host-contract-input' });
27
+ const tool = await $.tool.call({ tool: 'Read', file_path: 'native-host-contract.txt' });
28
+ await $.turn.complete({
29
+ turnId: 'native-contract-turn',
30
+ answer: 'native-turn-contract-ok',
31
+ durationMs: 1,
32
+ isAborted: false,
33
+ usage: null,
34
+ });
35
+ expect(prompt.text).toBe('native-host-contract-ok');
36
+ expect(tool.result.content).toBe('native-host-tool-ok');
37
+ expect(usageCalls).toBe(1);
38
+ expect(compactCalls).toBe(1);
39
+ const monotonicEnd = globalThis.performance?.now?.();
40
+ expect(Number.isFinite(monotonicEnd)).toBe(true);
41
+ expect(
42
+ typeof monotonicStart === 'number' &&
43
+ typeof monotonicEnd === 'number' &&
44
+ monotonicEnd >= monotonicStart,
45
+ ).toBe(true);
46
+ };
47
+
48
+ test(
49
+ 'AI Brain enabled host contract invokes usage and native compaction through the dispatcher',
50
+ contractTest,
51
+ );