Skip to content

Commit 056be74

Browse files
committed
move run-agent-step to agent-runtime
1 parent 480af9e commit 056be74

27 files changed

+136
-196
lines changed

backend/src/main-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { loopAgentSteps } from '@codebuff/agent-runtime/run-agent-step'
12
import { getAgentTemplate } from '@codebuff/agent-runtime/templates/agent-registry'
23
import { expireMessages } from '@codebuff/agent-runtime/util/messages'
34
import { AgentTemplateTypes } from '@codebuff/common/types/session-state'
45
import { generateCompactId } from '@codebuff/common/util/string'
56
import { uniq } from 'lodash'
67

78
import { checkTerminalCommand } from './check-terminal-command'
8-
import { loopAgentSteps } from './run-agent-step'
99

1010
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
1111
import type { ClientAction } from '@codebuff/common/actions'

backend/src/tools/handlers/list.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

evals/scaffolding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventEmitter } from 'events'
33
import fs from 'fs'
44
import path from 'path'
55

6+
import { runAgentStep } from '@codebuff/agent-runtime/run-agent-step'
67
import { assembleLocalAgentTemplates } from '@codebuff/agent-runtime/templates/agent-registry'
78
import {
89
handleStepsLogChunkWs,
@@ -13,7 +14,6 @@ import {
1314
sendActionWs,
1415
sendSubagentChunkWs,
1516
} from '@codebuff/backend/client-wrapper'
16-
import { runAgentStep } from '@codebuff/backend/run-agent-step'
1717
import { getFileTokenScores } from '@codebuff/code-map/parse'
1818
import { TEST_USER_ID } from '@codebuff/common/old-constants'
1919
import { mockModule } from '@codebuff/common/testing/mock-modules'

backend/src/__tests__/cost-aggregation.test.ts renamed to packages/agent-runtime/src/__tests__/cost-aggregation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as agentRegistry from '@codebuff/agent-runtime/templates/agent-registry'
21
import {
32
TEST_AGENT_RUNTIME_IMPL,
43
TEST_AGENT_RUNTIME_SCOPED_IMPL,
@@ -17,6 +16,7 @@ import {
1716
mock,
1817
} from 'bun:test'
1918

19+
import * as agentRegistry from '../templates/agent-registry'
2020
import * as spawnAgentUtils from '../tools/handlers/tool/spawn-agent-utils'
2121
import { handleSpawnAgents } from '../tools/handlers/tool/spawn-agents'
2222

backend/src/__tests__/loop-agent-steps.test.ts renamed to packages/agent-runtime/src/__tests__/loop-agent-steps.test.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { disableLiveUserInputCheck } from '@codebuff/agent-runtime/live-user-inputs'
21
import * as analytics from '@codebuff/common/analytics'
32
import db from '@codebuff/common/db'
43
import { TEST_USER_ID } from '@codebuff/common/old-constants'
@@ -25,18 +24,17 @@ import {
2524
} from 'bun:test'
2625
import { z } from 'zod/v4'
2726

28-
import { withAppContext } from '../context/app-context'
27+
import { disableLiveUserInputCheck } from '../live-user-inputs'
2928
import { loopAgentSteps } from '../run-agent-step'
3029
import { clearAgentGeneratorCache } from '../run-programmatic-step'
3130
import { mockFileContext } from './test-utils'
3231

33-
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
32+
import type { AgentTemplate } from '../templates/types'
3433
import type { StepGenerator } from '@codebuff/common/types/agent-template'
3534
import type {
3635
AgentRuntimeDeps,
3736
AgentRuntimeScopedDeps,
3837
} from '@codebuff/common/types/contracts/agent-runtime'
39-
import type { ParamsOf } from '@codebuff/common/types/function-params'
4038
import type { AgentState } from '@codebuff/common/types/session-state'
4139

4240
describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => {
@@ -46,22 +44,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
4644
let agentRuntimeImpl: AgentRuntimeDeps
4745
let agentRuntimeScopedImpl: AgentRuntimeScopedDeps
4846

49-
const runLoopAgentStepsWithContext = async (
50-
options: ParamsOf<typeof loopAgentSteps>,
51-
) => {
52-
return await withAppContext(
53-
{
54-
userId: options.userId,
55-
clientSessionId: options.clientSessionId,
56-
},
57-
{
58-
currentUserId: options.userId,
59-
processedRepoId: 'test-repo',
60-
},
61-
async () => loopAgentSteps(options),
62-
)
63-
}
64-
6547
beforeAll(() => {
6648
disableLiveUserInputCheck()
6749

@@ -181,7 +163,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
181163
'test-agent': mockTemplate,
182164
}
183165

184-
const result = await runLoopAgentStepsWithContext({
166+
const result = await loopAgentSteps({
185167
...agentRuntimeImpl,
186168
...agentRuntimeScopedImpl,
187169
repoId: undefined,
@@ -229,7 +211,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
229211
'test-agent': mockTemplate,
230212
}
231213

232-
const result = await runLoopAgentStepsWithContext({
214+
const result = await loopAgentSteps({
233215
...agentRuntimeImpl,
234216
...agentRuntimeScopedImpl,
235217
repoId: undefined,
@@ -279,7 +261,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
279261
'test-agent': mockTemplate,
280262
}
281263

282-
const result = await runLoopAgentStepsWithContext({
264+
const result = await loopAgentSteps({
283265
...agentRuntimeImpl,
284266
...agentRuntimeScopedImpl,
285267
repoId: undefined,
@@ -328,7 +310,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
328310
'test-agent': mockTemplate,
329311
}
330312

331-
const result = await runLoopAgentStepsWithContext({
313+
const result = await loopAgentSteps({
332314
...agentRuntimeImpl,
333315
...agentRuntimeScopedImpl,
334316
repoId: undefined,
@@ -370,7 +352,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
370352
'test-agent': mockTemplate,
371353
}
372354

373-
const result = await runLoopAgentStepsWithContext({
355+
const result = await loopAgentSteps({
374356
...agentRuntimeImpl,
375357
...agentRuntimeScopedImpl,
376358
repoId: undefined,
@@ -404,7 +386,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
404386
'test-agent': llmOnlyTemplate,
405387
}
406388

407-
const result = await runLoopAgentStepsWithContext({
389+
const result = await loopAgentSteps({
408390
...agentRuntimeImpl,
409391
...agentRuntimeScopedImpl,
410392
repoId: undefined,
@@ -440,7 +422,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
440422
'test-agent': mockTemplate,
441423
}
442424

443-
const result = await runLoopAgentStepsWithContext({
425+
const result = await loopAgentSteps({
444426
...agentRuntimeImpl,
445427
...agentRuntimeScopedImpl,
446428
repoId: undefined,
@@ -493,7 +475,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
493475
'test-agent': mockTemplate,
494476
}
495477

496-
const result = await runLoopAgentStepsWithContext({
478+
const result = await loopAgentSteps({
497479
...agentRuntimeImpl,
498480
...agentRuntimeScopedImpl,
499481
repoId: undefined,
@@ -523,7 +505,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
523505

524506
// Mock runProgrammaticStep module to capture calls and verify stepsComplete parameter
525507
const mockedRunProgrammaticStep = await mockModule(
526-
'@codebuff/backend/run-programmatic-step',
508+
'@codebuff/agent-runtime/run-programmatic-step',
527509
() => ({
528510
runProgrammaticStep: async (params: any) => {
529511
runProgrammaticStepCalls.push(params)
@@ -551,7 +533,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
551533
'test-agent': mockTemplate,
552534
}
553535

554-
await runLoopAgentStepsWithContext({
536+
await loopAgentSteps({
555537
...agentRuntimeImpl,
556538
...agentRuntimeScopedImpl,
557539
repoId: undefined,
@@ -623,7 +605,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
623605
return `mock-message-id-${promptCallCount}`
624606
}
625607

626-
await runLoopAgentStepsWithContext({
608+
await loopAgentSteps({
627609
...agentRuntimeImpl,
628610
...agentRuntimeScopedImpl,
629611
repoId: undefined,
@@ -708,7 +690,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
708690
mockAgentState.output = undefined
709691
capturedAgentState = mockAgentState
710692

711-
const result = await runLoopAgentStepsWithContext({
693+
const result = await loopAgentSteps({
712694
...agentRuntimeImpl,
713695
...agentRuntimeScopedImpl,
714696
repoId: undefined,
@@ -783,7 +765,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
783765
mockAgentState.output = undefined
784766
capturedAgentState = mockAgentState
785767

786-
const result = await runLoopAgentStepsWithContext({
768+
const result = await loopAgentSteps({
787769
...agentRuntimeImpl,
788770
...agentRuntimeScopedImpl,
789771
repoId: undefined,
@@ -831,7 +813,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
831813
return 'mock-message-id'
832814
}
833815

834-
const result = await runLoopAgentStepsWithContext({
816+
const result = await loopAgentSteps({
835817
...agentRuntimeImpl,
836818
...agentRuntimeScopedImpl,
837819
repoId: undefined,
@@ -901,7 +883,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
901883
mockAgentState.output = undefined
902884
capturedAgentState = mockAgentState
903885

904-
const result = await runLoopAgentStepsWithContext({
886+
const result = await loopAgentSteps({
905887
...agentRuntimeImpl,
906888
...agentRuntimeScopedImpl,
907889
repoId: undefined,

backend/src/__tests__/malformed-tool-call.test.ts renamed to packages/agent-runtime/src/__tests__/malformed-tool-call.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { mockFileContext } from './test-utils'
2222
import { processStreamWithTools } from '../tools/stream-parser'
2323

24-
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
24+
import type { AgentTemplate } from '../templates/types'
2525
import type {
2626
AgentRuntimeDeps,
2727
AgentRuntimeScopedDeps,

backend/src/__tests__/prompt-caching-subagents.test.ts renamed to packages/agent-runtime/src/__tests__/prompt-caching-subagents.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { disableLiveUserInputCheck } from '@codebuff/agent-runtime/live-user-inputs'
21
import { TEST_USER_ID } from '@codebuff/common/old-constants'
32
import {
43
TEST_AGENT_RUNTIME_IMPL,
54
TEST_AGENT_RUNTIME_SCOPED_IMPL,
65
} from '@codebuff/common/testing/impl/agent-runtime'
76
import { getInitialSessionState } from '@codebuff/common/types/session-state'
8-
import { spyOn, beforeEach, describe, expect, it, beforeAll } from 'bun:test'
7+
import { beforeEach, describe, expect, it, beforeAll } from 'bun:test'
98

9+
import { disableLiveUserInputCheck } from '../live-user-inputs'
1010
import { loopAgentSteps } from '../run-agent-step'
1111

12-
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
12+
import type { AgentTemplate } from '../templates/types'
1313
import type {
1414
AgentRuntimeDeps,
1515
AgentRuntimeScopedDeps,
@@ -133,10 +133,6 @@ describe('Prompt Caching for Subagents with inheritParentSystemPrompt', () => {
133133
},
134134
],
135135
})
136-
137-
// Mock live user input
138-
const liveUserInputs = require('@codebuff/agent-runtime/live-user-inputs')
139-
spyOn(liveUserInputs, 'checkLiveUserInput').mockImplementation(() => true)
140136
})
141137

142138
it('should inherit parent system prompt when inheritParentSystemPrompt is true', async () => {

backend/src/__tests__/read-docs-tool.test.ts renamed to packages/agent-runtime/src/__tests__/read-docs-tool.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { disableLiveUserInputCheck } from '@codebuff/agent-runtime/live-user-inputs'
2-
import * as context7Api from '@codebuff/agent-runtime/llm-api/context7-api'
3-
import { assembleLocalAgentTemplates } from '@codebuff/agent-runtime/templates/agent-registry'
41
import * as bigquery from '@codebuff/bigquery'
52
import * as analytics from '@codebuff/common/analytics'
63
import { TEST_USER_ID } from '@codebuff/common/old-constants'
@@ -21,9 +18,12 @@ import {
2118
test,
2219
} from 'bun:test'
2320

21+
import { disableLiveUserInputCheck } from '../live-user-inputs'
2422
import { mockFileContext } from './test-utils'
25-
import researcherAgent from '../../../.agents/researcher/researcher'
23+
import researcherAgent from '../../../../.agents/researcher/researcher'
24+
import * as context7Api from '../llm-api/context7-api'
2625
import { runAgentStep } from '../run-agent-step'
26+
import { assembleLocalAgentTemplates } from '../templates/agent-registry'
2727

2828
import type {
2929
AgentRuntimeDeps,

backend/src/__tests__/run-agent-step-tools.test.ts renamed to packages/agent-runtime/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { disableLiveUserInputCheck } from '@codebuff/agent-runtime/live-user-inputs'
2-
import { asUserMessage } from '@codebuff/agent-runtime/util/messages'
31
import * as bigquery from '@codebuff/bigquery'
42
import * as analytics from '@codebuff/common/analytics'
53
import db from '@codebuff/common/db'
@@ -22,10 +20,12 @@ import {
2220
spyOn,
2321
} from 'bun:test'
2422

23+
import { disableLiveUserInputCheck } from '../live-user-inputs'
2524
import { runAgentStep } from '../run-agent-step'
2625
import { clearAgentGeneratorCache } from '../run-programmatic-step'
26+
import { asUserMessage } from '../util/messages'
2727

28-
import type { AgentTemplate } from '@codebuff/agent-runtime/templates/types'
28+
import type { AgentTemplate } from '../templates/types'
2929
import type {
3030
AgentRuntimeDeps,
3131
AgentRuntimeScopedDeps,

backend/src/__tests__/run-programmatic-step.test.ts renamed to packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ import {
2121
} from '../run-programmatic-step'
2222
import { mockFileContext } from './test-utils'
2323
import * as toolExecutor from '../tools/tool-executor'
24-
import * as requestContext from '../websockets/request-context'
2524

26-
import type {
27-
AgentTemplate,
28-
StepGenerator,
29-
} from '@codebuff/agent-runtime/templates/types'
25+
import type { AgentTemplate, StepGenerator } from '../templates/types'
3026
import type { PublicAgentState } from '@codebuff/common/types/agent-template'
3127
import type {
3228
AgentRuntimeDeps,
@@ -83,14 +79,6 @@ describe('runProgrammaticStep', () => {
8379
'executeToolCall',
8480
).mockImplementation(async () => {})
8581

86-
// Mock getRequestContext
87-
getRequestContextSpy = spyOn(
88-
requestContext,
89-
'getRequestContext',
90-
).mockImplementation(() => ({
91-
processedRepoId: 'test-repo-id',
92-
}))
93-
9482
// Mock crypto.randomUUID
9583
spyOn(crypto, 'randomUUID').mockImplementation(
9684
() =>

0 commit comments

Comments
 (0)