Skip to content

Commit dd81dc1

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@be9ecb0a8d32eaa738ce0747b72f62bb1a82bd79
1 parent a4c36cd commit dd81dc1

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎sdk/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to the @codebuff/sdk package will be documented in this file
44

55
## [Unreleased]
66

7-
- New `skipSymbolIndex` run option: a fresh session builds the file tree but skips the tree-sitter parse of every project file, leaving `fileTokenScores` and `tokenCallers` empty. Set it when your agents do not use the file-picker, `read_subtree` symbols or `read_files`' `referencedBy`.
7+
- New `skipSymbolIndex` run option: the run builds the file tree but skips the tree-sitter parse of every project file, leaving `fileTokenScores` and `tokenCallers` empty. Set it when your agents do not use the file-picker, `read_subtree` symbols or `read_files`' `referencedBy`.
88

99
- `compactRunState` now rewrites a run's history into at most 12k tokens (`MECHANICAL_HISTORY_TOKENS`) of summary plus a working set of file reads, whatever `maxContextLength` allows; it used to fill the budget. The newest read of each file not edited since comes back whole and every other read becomes an outline stub, so expect a much smaller `nextTokens`. The live request and the newest tool results are kept whole on top of the cap.
1010

‎sdk/src/__tests__/initial-session-state.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { z } from 'zod/v4'
77

88
import { getAllFilePaths } from '@codebuff/common/project-file-tree'
99

10-
import { initialSessionState } from '../run-state'
10+
import { applyOverridesToSessionState, initialSessionState } from '../run-state'
1111

1212
import type { MockStatResult } from '@codebuff/common/testing/mock-types'
1313
import type { Logger } from '@codebuff/common/types/contracts/logger'
@@ -198,6 +198,33 @@ describe('Initial Session State', () => {
198198
expect(readFilePaths.some((p) => p.endsWith('.ts'))).toBe(false)
199199
})
200200

201+
test('skipSymbolIndex also holds when a later run passes projectFiles', async () => {
202+
const base = await initialSessionState({
203+
cwd: '/test-project',
204+
projectFiles: {},
205+
fs: mockFs,
206+
logger: mockLogger,
207+
})
208+
const projectFiles = {
209+
'src/utils.ts':
210+
'export function add(a: number, b: number) { return a + b; }',
211+
}
212+
const parsed = await applyOverridesToSessionState('/test-project', base, {
213+
projectFiles,
214+
})
215+
expect(parsed.fileContext.fileTokenScores).not.toEqual({})
216+
217+
const skipped = await applyOverridesToSessionState('/test-project', base, {
218+
projectFiles,
219+
skipSymbolIndex: true,
220+
})
221+
expect(getAllFilePaths(skipped.fileContext.fileTree)).toEqual([
222+
'src/utils.ts',
223+
])
224+
expect(skipped.fileContext.fileTokenScores).toEqual({})
225+
expect(skipped.fileContext.tokenCallers).toEqual({})
226+
})
227+
201228
test('derives knowledgeFiles from projectFiles when not provided', async () => {
202229
const projectFiles = {
203230
'src/index.ts': 'console.log("Hello world");',

‎sdk/src/run-state.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ export async function applyOverridesToSessionState(
11351135
/** Precomputed index for exactly these `projectFiles` (see
11361136
* ComputedProjectIndex). Ignored when `projectFiles` is absent. */
11371137
projectIndex?: ComputedProjectIndex
1138+
/** See InitialSessionStateOptions.skipSymbolIndex. */
1139+
skipSymbolIndex?: boolean
11381140
knowledgeFiles?: Record<string, string>
11391141
agentDefinitions?: AgentDefinition[]
11401142
customToolDefinitions?: CustomToolDefinition[]
@@ -1166,7 +1168,11 @@ export async function applyOverridesToSessionState(
11661168
cwd,
11671169
projectFiles: overrides.projectFiles,
11681170
})
1169-
if (projectIndex) {
1171+
if (projectIndex && overrides.skipSymbolIndex) {
1172+
sessionState.fileContext.fileTree = projectIndex.fileTree
1173+
sessionState.fileContext.fileTokenScores = {}
1174+
sessionState.fileContext.tokenCallers = {}
1175+
} else if (projectIndex) {
11701176
const { fileTree, fileTokenScores, tokenCallers } =
11711177
await computeProjectIndex(projectIndex)
11721178
sessionState.fileContext.fileTree = fileTree

‎sdk/src/run.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ async function runOnce({
649649
customToolDefinitions,
650650
projectFiles,
651651
projectIndex,
652+
skipSymbolIndex,
652653
maxAgentSteps,
653654
},
654655
)

0 commit comments

Comments
 (0)