Skip to content

Commit d57cb6f

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@fb6a058503604724e7c933d57209bbf20ea5d0cc
1 parent b2ee01f commit d57cb6f

14 files changed

Lines changed: 926 additions & 115 deletions

‎bun.lock‎

Lines changed: 43 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎common/src/util/__tests__/axiom-only-log.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ describe('getAxiomOnlyLogEvent', () => {
326326
context_token_count: 212_000,
327327
summary_estimated_tokens: 13_000,
328328
preserved_fresh_messages: 2,
329+
working_set_files: 3,
330+
working_set_stubs: 9,
329331
post_tokens: 41_000,
330332
// Not in the allowlist: user content.
331333
summaryText: '[USER]\nsecret',
@@ -338,6 +340,8 @@ describe('getAxiomOnlyLogEvent', () => {
338340
context_token_count: 212_000,
339341
summary_estimated_tokens: 13_000,
340342
preserved_fresh_messages: 2,
343+
working_set_files: 3,
344+
working_set_stubs: 9,
341345
post_tokens: 41_000,
342346
},
343347
})

‎common/src/util/axiom-only-log.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ const CONTEXT_COMPACTION_COMPLETED_FIELDS = {
290290
summary_estimated_tokens: 'number',
291291
budget_dropped_summary_parts: 'number',
292292
preserved_fresh_messages: 'number',
293+
/** Files re-provided whole, files left as an outline stub, and their size. */
294+
working_set_files: 'number',
295+
working_set_stubs: 'number',
296+
working_set_tokens: 'number',
293297
post_tokens: 'number',
294298
} as const satisfies AxiomOnlyFieldSchema
295299

‎packages/agent-runtime/src/__tests__/compact-history-now.test.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ const assistant = (text: string): Message => ({
3030
const call = (id: string, paths: unknown[] = ['file.ts']): Message => ({
3131
role: 'assistant',
3232
content: [
33-
{ type: 'tool-call', toolCallId: id, toolName: 'read_files', input: { paths } },
33+
{
34+
type: 'tool-call',
35+
toolCallId: id,
36+
toolName: 'read_files',
37+
input: { paths },
38+
},
3439
],
3540
})
3641
const tool = (id: string, value: JSONValue): Message => ({
@@ -42,15 +47,38 @@ const tool = (id: string, value: JSONValue): Message => ({
4247
const read = (id: string, content: string, path = 'file.ts') =>
4348
tool(id, [{ path, content, referencedBy: {} }])
4449

45-
/** A settled conversation: several exchanges, then a final assistant answer. */
50+
const edit = (id: string, path: string): Message[] => [
51+
{
52+
role: 'assistant',
53+
content: [
54+
{
55+
type: 'tool-call',
56+
toolCallId: id,
57+
toolName: 'str_replace',
58+
input: { path, replacements: [] },
59+
},
60+
],
61+
},
62+
{
63+
role: 'tool',
64+
toolCallId: id,
65+
toolName: 'str_replace',
66+
content: [{ type: 'json', value: { file: path, message: 'Updated' } }],
67+
},
68+
]
69+
70+
/** A settled conversation: several exchanges, then a final assistant answer.
71+
* Each file was edited after it was read, so no working set carries it. */
4672
const settledHistory = (): Message[] => [
4773
user('Add a retry to the uploader.'),
4874
call('a', ['uploader.ts']),
4975
read('a', 'export const upload = () => {}\n'.repeat(400), 'uploader.ts'),
76+
...edit('a-edit', 'uploader.ts'),
5077
assistant('Added the retry.'),
5178
user('Now document it.'),
5279
call('b', ['README.md']),
5380
read('b', '# docs\n'.repeat(400), 'README.md'),
81+
...edit('b-edit', 'README.md'),
5482
assistant('Documented.'),
5583
]
5684

@@ -72,8 +100,9 @@ describe('compactHistoryNow', () => {
72100
expect(forced).not.toBeNull()
73101
expect(forced!.nextTokens).toBeLessThan(forced!.previousTokens)
74102
expect(countTokensMessages(forced!.messages)).toBe(forced!.nextTokens)
103+
// Edited after it was read, so it comes back as an outline, not a body.
75104
expect(JSON.stringify(forced!.messages)).not.toContain(
76-
'export const upload',
105+
JSON.stringify('export const upload = () => {}\nexport const').slice(1, -1),
77106
)
78107
})
79108

‎packages/agent-runtime/src/__tests__/compact-request-budget.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ describe('request-sized compaction', () => {
121121
content: [{ type: 'text', text: 'I used those contents.' }],
122122
},
123123
])
124-
expect(output.some((message) => message.role === 'tool')).toBe(false)
124+
// Not preserved as a fresh result. Too big for this window's working set,
125+
// it comes back only as a stub.
126+
expect(
127+
output
128+
.filter((message) => message.role === 'tool')
129+
.every((message) => message.tags?.includes('COMPACTION_WORKING_SET')),
130+
).toBe(true)
125131
expect(JSON.stringify(output)).not.toContain('ALREADY_CONSUMED')
126132
})
127133

‎packages/agent-runtime/src/__tests__/compaction-followup.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
measureCompactionWindow,
66
openCompactionWindow,
77
} from '../compaction-followup'
8+
import { COMPACTED_READ_MARKER } from '../compaction-working-set'
89

910
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
1011

@@ -24,7 +25,18 @@ const read = (id: string, paths: unknown[]): Message[] => [
2425
role: 'tool',
2526
toolCallId: id,
2627
toolName: 'read_files',
27-
content: [{ type: 'json', value: [{ path: 'x', content: 'BODY' }] }],
28+
content: [
29+
{
30+
type: 'json',
31+
value: paths.map((entry) => ({
32+
path:
33+
typeof entry === 'string'
34+
? entry
35+
: (entry as { path: string }).path,
36+
content: 'BODY',
37+
})),
38+
},
39+
],
2840
},
2941
]
3042

@@ -52,6 +64,34 @@ describe('compaction follow-up window', () => {
5264
expect([...window.elidedPaths]).toEqual(['a.ts'])
5365
})
5466

67+
it('a working-set stub names a file without carrying it', () => {
68+
const stubbed: Message[] = [
69+
summary,
70+
{
71+
role: 'tool',
72+
toolCallId: 'ws',
73+
toolName: 'read_files',
74+
content: [
75+
{
76+
type: 'json',
77+
value: [
78+
{ path: 'b.ts', content: 'BODY' },
79+
{ path: 'a.ts', content: `${COMPACTED_READ_MARKER}. 3 lines.]` },
80+
],
81+
},
82+
],
83+
},
84+
]
85+
const window = openCompactionWindow({
86+
before,
87+
after: stubbed,
88+
mode: 'mechanical',
89+
trigger: 'context_limit',
90+
now: 0,
91+
})
92+
expect([...window.elidedPaths]).toEqual(['a.ts'])
93+
})
94+
5595
it('a re-read of a dropped file is a re-read; a carried one is not new', () => {
5696
const window = openCompactionWindow({
5797
before,

0 commit comments

Comments
 (0)