Skip to content

Commit f84d63b

Browse files
committed
Merge branch 'main' into base-layers
2 parents aca43ff + 1361894 commit f84d63b

File tree

103 files changed

+2447
-1143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2447
-1143
lines changed

.agents/types/tools.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export type ToolName =
66
| 'code_search'
77
| 'end_turn'
88
| 'find_files'
9+
| 'glob'
10+
| 'list_directory'
911
| 'lookup_agent_info'
1012
| 'read_docs'
1113
| 'read_files'
@@ -27,6 +29,8 @@ export interface ToolParamsMap {
2729
code_search: CodeSearchParams
2830
end_turn: EndTurnParams
2931
find_files: FindFilesParams
32+
glob: GlobParams
33+
list_directory: ListDirectoryParams
3034
lookup_agent_info: LookupAgentInfoParams
3135
read_docs: ReadDocsParams
3236
read_files: ReadFilesParams
@@ -59,7 +63,7 @@ export interface CodeSearchParams {
5963
flags?: string
6064
/** Optional working directory to search within, relative to the project root. Defaults to searching the entire project. */
6165
cwd?: string
62-
/** Maximum number of results to return. Defaults to 30. */
66+
/** Maximum number of results to return per file. Defaults to 15. There is also a global limit of 250 results across all files. */
6367
maxResults?: number
6468
}
6569

@@ -76,6 +80,24 @@ export interface FindFilesParams {
7680
prompt: string
7781
}
7882

83+
/**
84+
* Search for files matching a glob pattern. Returns matching file paths sorted by modification time.
85+
*/
86+
export interface GlobParams {
87+
/** Glob pattern to match files against (e.g., *.js, src/glob/*.ts, glob/test/glob/*.go). */
88+
pattern: string
89+
/** Optional working directory to search within, relative to project root. If not provided, searches from project root. */
90+
cwd?: string
91+
}
92+
93+
/**
94+
* List files and directories in the specified path. Returns information about each entry including name, type, size, and modification time.
95+
*/
96+
export interface ListDirectoryParams {
97+
/** Directory path to list, relative to the project root. */
98+
path: string
99+
}
100+
79101
/**
80102
* Retrieve information about an agent by ID
81103
*/

backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"gpt-tokenizer": "2.8.1",
4343
"ignore": "5.3.2",
4444
"lodash": "*",
45+
"micromatch": "^4.0.8",
4546
"openai": "^4.78.1",
4647
"pino": "9.4.0",
4748
"postgres": "3.4.4",
@@ -56,6 +57,7 @@
5657
"@types/cors": "^2.8.19",
5758
"@types/diff": "^5.0.3",
5859
"@types/express": "^4.17.13",
60+
"@types/micromatch": "^4.0.9",
5961
"@types/ws": "^8.5.5"
6062
}
6163
}

backend/src/__tests__/auto-topup.test.ts

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import {
88
afterAll,
99
afterEach,
10+
beforeAll,
1011
beforeEach,
1112
describe,
1213
expect,
@@ -15,26 +16,23 @@ import {
1516
spyOn,
1617
} from 'bun:test'
1718

19+
import type { Logger } from '@codebuff/types/logger'
20+
1821
describe('Auto Top-up System', () => {
1922
describe('checkAndTriggerAutoTopup', () => {
2023
// Create fresh mocks for each test
2124
let dbMock: ReturnType<typeof mock>
2225
let balanceMock: ReturnType<typeof mock>
2326
let validateAutoTopupMock: ReturnType<typeof mock>
2427
let grantCreditsMock: ReturnType<typeof mock>
25-
26-
beforeEach(() => {
27-
// Mock logger for auto-topup functionality
28-
mockModule('@codebuff/common/util/logger', () => ({
29-
logger: {
30-
debug: () => {},
31-
error: () => {},
32-
info: () => {},
33-
warn: () => {},
34-
},
35-
withLoggerContext: async (context: any, fn: () => Promise<any>) => fn(),
36-
}))
37-
28+
const logger: Logger = {
29+
debug: () => {},
30+
error: () => {},
31+
info: () => {},
32+
warn: () => {},
33+
}
34+
35+
beforeAll(() => {
3836
// Set up default mocks
3937
dbMock = mock(() =>
4038
Promise.resolve({
@@ -46,6 +44,38 @@ describe('Auto Top-up System', () => {
4644
}),
4745
)
4846

47+
// Mock the database
48+
mockModule('@codebuff/common/db', () => ({
49+
default: {
50+
query: {
51+
user: {
52+
findFirst: dbMock,
53+
},
54+
},
55+
update: mock(() => ({
56+
set: () => ({
57+
where: () => Promise.resolve(),
58+
}),
59+
})),
60+
},
61+
}))
62+
63+
// Mock Stripe payment intent creation
64+
mockModule('@codebuff/common/util/stripe', () => ({
65+
stripeServer: {
66+
paymentIntents: {
67+
create: mock(() =>
68+
Promise.resolve({
69+
status: 'succeeded',
70+
id: 'pi_123',
71+
}),
72+
),
73+
},
74+
},
75+
}))
76+
})
77+
78+
beforeEach(() => {
4979
balanceMock = mock(() =>
5080
Promise.resolve({
5181
usageThisCycle: 0,
@@ -74,43 +104,17 @@ describe('Auto Top-up System', () => {
74104

75105
grantCreditsMock = mock(() => Promise.resolve())
76106

77-
// Mock the database
78-
mockModule('@codebuff/common/db', () => ({
79-
default: {
80-
query: {
81-
user: {
82-
findFirst: dbMock,
83-
},
84-
},
85-
update: mock(() => ({
86-
set: () => ({
87-
where: () => Promise.resolve(),
88-
}),
89-
})),
90-
},
91-
}))
92-
93107
spyOn(billing, 'calculateUsageAndBalance').mockImplementation(balanceMock)
94108
spyOn(billing, 'validateAutoTopupStatus').mockImplementation(
95109
validateAutoTopupMock,
96110
)
97111
spyOn(billing, 'processAndGrantCredit').mockImplementation(
98112
grantCreditsMock,
99113
)
114+
})
100115

101-
// Mock Stripe payment intent creation
102-
mockModule('@codebuff/common/util/stripe', () => ({
103-
stripeServer: {
104-
paymentIntents: {
105-
create: mock(() =>
106-
Promise.resolve({
107-
status: 'succeeded',
108-
id: 'pi_123',
109-
}),
110-
),
111-
},
112-
},
113-
}))
116+
afterEach(() => {
117+
mock.restore()
114118
})
115119

116120
afterAll(() => {
@@ -119,7 +123,10 @@ describe('Auto Top-up System', () => {
119123

120124
it('should trigger top-up when balance below threshold', async () => {
121125
// Replace direct call with capture of returned amount
122-
const amount = await checkAndTriggerAutoTopup('test-user')
126+
const amount = await checkAndTriggerAutoTopup({
127+
userId: 'test-user',
128+
logger,
129+
})
123130

124131
// Should check user settings
125132
expect(dbMock).toHaveBeenCalled()
@@ -158,7 +165,10 @@ describe('Auto Top-up System', () => {
158165
)
159166

160167
// Capture return value (should be undefined)
161-
const amount = await checkAndTriggerAutoTopup('test-user')
168+
const amount = await checkAndTriggerAutoTopup({
169+
userId: 'test-user',
170+
logger,
171+
})
162172

163173
// Should still check settings and balance
164174
expect(dbMock).toHaveBeenCalled()
@@ -195,7 +205,10 @@ describe('Auto Top-up System', () => {
195205
)
196206

197207
// Capture the returned amount and assert debt coverage
198-
const amount = await checkAndTriggerAutoTopup('test-user')
208+
const amount = await checkAndTriggerAutoTopup({
209+
userId: 'test-user',
210+
logger,
211+
})
199212

200213
expect(amount).toBe(600)
201214
})
@@ -214,9 +227,12 @@ describe('Auto Top-up System', () => {
214227
validateAutoTopupMock,
215228
)
216229

217-
await expect(checkAndTriggerAutoTopup('test-user')).rejects.toThrow(
218-
'No valid payment method found',
219-
)
230+
await expect(
231+
checkAndTriggerAutoTopup({
232+
userId: 'test-user',
233+
logger,
234+
}),
235+
).rejects.toThrow('No valid payment method found')
220236

221237
// Should have called validation
222238
expect(validateAutoTopupMock).toHaveBeenCalled()

backend/src/__tests__/cost-aggregation.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ describe('Cost Aggregation Integration Tests', () => {
237237

238238
// Mock file reading
239239
spyOn(websocketAction, 'requestFiles').mockImplementation(
240-
async (ws, paths) => {
240+
async (params: { ws: any; filePaths: string[] }) => {
241241
const results: Record<string, string | null> = {}
242-
paths.forEach((path) => {
242+
params.filePaths.forEach((path) => {
243243
results[path] = path === 'hello.txt' ? 'Hello, World!' : null
244244
})
245245
return results

backend/src/__tests__/fast-rewrite.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ describe.skip('rewriteWithOpenAI', () => {
4343
const editSnippet = await Bun.file(`${testDataDir}/edit-snippet.go`).text()
4444
const expectedResult = await Bun.file(`${testDataDir}/expected.go`).text()
4545

46-
const result = await rewriteWithOpenAI(
47-
originalContent,
46+
const result = await rewriteWithOpenAI({
47+
oldContent: originalContent,
4848
editSnippet,
49-
'taskruntoolcall.go',
50-
'clientSessionId',
51-
'fingerprintId',
52-
'userInputId',
53-
TEST_USER_ID,
54-
undefined,
55-
)
49+
filePath: 'taskruntoolcall.go',
50+
clientSessionId: 'clientSessionId',
51+
fingerprintId: 'fingerprintId',
52+
userInputId: 'userInputId',
53+
userId: TEST_USER_ID,
54+
userMessage: undefined,
55+
})
5656

5757
const patch = createPatch('test.ts', expectedResult, result)
5858
const patchLines = patch.split('\n').slice(4)

0 commit comments

Comments
 (0)