Skip to content

Commit e11ad16

Browse files
committed
pass less data between functions
1 parent 0afa4c4 commit e11ad16

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/core/Cline.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,6 @@ export class Cline {
11611161
// Tools
11621162

11631163
async executeCommandTool(command: string): Promise<[boolean, ToolResponse]> {
1164-
const contextWindow = this.api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
1165-
const maxAllowedSize = getMaxAllowedSize(contextWindow)
1166-
11671164
const terminalInfo = await this.terminalManager.getOrCreateTerminal(cwd)
11681165
terminalInfo.terminal.show() // weird visual bug when creating new terminals (even manually) where there's an empty space at the top.
11691166
const process = this.terminalManager.runCommand(terminalInfo, command)
@@ -2003,7 +2000,7 @@ export class Cline {
20032000
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
20042001
}
20052002
// Get context window and used context from API model
2006-
const contextWindow = this.api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
2003+
const contextWindow = this.api.getModel().info.contextWindow
20072004

20082005
// Pass the raw context window size - extractTextFromFile will calculate the appropriate limit
20092006
const content = await extractTextFromFile(absolutePath, contextWindow)
@@ -3379,9 +3376,10 @@ export class Cline {
33793376
block.text.includes("<task>") ||
33803377
block.text.includes("<user_message>")
33813378
) {
3379+
let contextWindow = this.api.getModel().info.contextWindow
33823380
return {
33833381
...block,
3384-
text: await parseMentions(block.text, cwd, this.urlContentFetcher, this.api),
3382+
text: await parseMentions(block.text, cwd, this.urlContentFetcher, contextWindow),
33853383
}
33863384
}
33873385
}

src/core/mentions/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function parseMentions(
4242
text: string,
4343
cwd: string,
4444
urlContentFetcher: UrlContentFetcher,
45-
api: { getModel: () => { info: { contextWindow?: number } } },
45+
contextWindow?: number,
4646
): Promise<string> {
4747
const mentions: Set<string> = new Set()
4848
let parsedText = text.replace(mentionRegexGlobal, (match, mention) => {
@@ -95,7 +95,7 @@ export async function parseMentions(
9595
} else if (mention.startsWith("/")) {
9696
const mentionPath = mention.slice(1)
9797
try {
98-
const content = await getFileOrFolderContent(mentionPath, cwd, api)
98+
const content = await getFileOrFolderContent(mentionPath, cwd, contextWindow)
9999
if (mention.endsWith("/")) {
100100
parsedText += `\n\n<folder_content path="${mentionPath}">\n${content}\n</folder_content>`
101101
} else {
@@ -150,11 +150,7 @@ export async function parseMentions(
150150
return parsedText
151151
}
152152

153-
async function getFileOrFolderContent(
154-
mentionPath: string,
155-
cwd: string,
156-
api: { getModel: () => { info: { contextWindow?: number } } },
157-
): Promise<string> {
153+
async function getFileOrFolderContent(mentionPath: string, cwd: string, contextWindow?: number): Promise<string> {
158154
const absPath = path.resolve(cwd, mentionPath)
159155

160156
try {
@@ -165,7 +161,6 @@ async function getFileOrFolderContent(
165161
if (isBinary) {
166162
return "(Binary file, unable to display content)"
167163
}
168-
const contextWindow = api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
169164
const content = await extractTextFromFile(absPath, contextWindow)
170165
return content
171166
} else if (stats.isDirectory()) {
@@ -187,7 +182,6 @@ async function getFileOrFolderContent(
187182
if (isBinary) {
188183
return undefined
189184
}
190-
const contextWindow = api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
191185
const content = await extractTextFromFile(absoluteFilePath, contextWindow)
192186
return `<file_content path="${filePath.toPosix()}">\n${content}\n</file_content>`
193187
} catch (error) {

src/integrations/misc/extract-text.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export async function extractTextFromTerminal(content: string | Buffer, contextW
4444
return cleanContent
4545
}
4646

47-
export async function extractTextFromFile(filePath: string, contextWindow: number): Promise<string> {
47+
export async function extractTextFromFile(
48+
filePath: string,
49+
contextWindow: number = 64_000 /* minimum context (Deepseek) */,
50+
): Promise<string> {
4851
try {
4952
await fs.access(filePath)
5053
} catch (error) {

0 commit comments

Comments
 (0)