Skip to content

Commit ad8e0b1

Browse files
committed
remove usedContext references
1 parent 22b2e50 commit ad8e0b1

File tree

7 files changed

+21
-48
lines changed

7 files changed

+21
-48
lines changed

src/core/Cline.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ export class Cline {
11901190

11911191
const terminalInfo = await this.terminalManager.getOrCreateTerminal(cwd)
11921192
terminalInfo.terminal.show() // weird visual bug when creating new terminals (even manually) where there's an empty space at the top.
1193-
const process = this.terminalManager.runCommand(terminalInfo, command, maxAllowedSize, usedContext)
1193+
const process = this.terminalManager.runCommand(terminalInfo, command, maxAllowedSize)
11941194

11951195
let userFeedback: { text?: string; images?: string[] } | undefined
11961196
let didContinue = false
@@ -2007,11 +2007,8 @@ export class Cline {
20072007
const contextWindow = this.api.getModel().info.contextWindow || 128_000
20082008
const maxAllowedSize = getMaxAllowedSize(contextWindow)
20092009

2010-
// Calculate used context from current conversation
2011-
const usedContext = this.calculateUsedContext()
2012-
20132010
// now execute the tool like normal
2014-
const content = await extractTextFromFile(absolutePath, maxAllowedSize, usedContext)
2011+
const content = await extractTextFromFile(absolutePath, maxAllowedSize)
20152012
pushToolResult(content)
20162013

20172014
break

src/integrations/misc/extract-text.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ContentTooLargeError } from "../../shared/errors"
77
import { calculateMaxAllowedSize } from "../../utils/content-size"
88

99
const CONTEXT_LIMIT = 1000
10-
const USED_CONTEXT = 200
1110

1211
describe("extract-text", () => {
1312
let tempFilePath: string
@@ -23,7 +22,7 @@ describe("extract-text", () => {
2322
it("throws error for non-existent file", async () => {
2423
const nonExistentPath = path.join(os.tmpdir(), "non-existent.txt")
2524
try {
26-
await extractTextFromFile(nonExistentPath, CONTEXT_LIMIT, USED_CONTEXT)
25+
await extractTextFromFile(nonExistentPath, CONTEXT_LIMIT)
2726
throw new Error("Should have thrown error")
2827
} catch (error) {
2928
expect(error.message).to.include("File not found")
@@ -36,7 +35,7 @@ describe("extract-text", () => {
3635
await fs.writeFile(tempFilePath, largeContent)
3736

3837
try {
39-
await extractTextFromFile(tempFilePath, CONTEXT_LIMIT, USED_CONTEXT)
38+
await extractTextFromFile(tempFilePath, CONTEXT_LIMIT)
4039
throw new Error("Should have thrown error")
4140
} catch (error) {
4241
expect(error).to.be.instanceOf(ContentTooLargeError)
@@ -50,7 +49,7 @@ describe("extract-text", () => {
5049
const content = "Hello world"
5150
await fs.writeFile(tempFilePath, content)
5251

53-
const result = await extractTextFromFile(tempFilePath, CONTEXT_LIMIT, USED_CONTEXT)
52+
const result = await extractTextFromFile(tempFilePath, CONTEXT_LIMIT)
5453
expect(result).to.equal(content)
5554
})
5655

@@ -60,7 +59,7 @@ describe("extract-text", () => {
6059
await fs.writeFile(tempFilePath, buffer, { encoding: "binary" })
6160

6261
try {
63-
await extractTextFromFile(tempFilePath, CONTEXT_LIMIT, USED_CONTEXT)
62+
await extractTextFromFile(tempFilePath, CONTEXT_LIMIT)
6463
throw new Error("Should have thrown error")
6564
} catch (error) {
6665
expect(error.message).to.include("Cannot read text for file type")

src/integrations/misc/extract-text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isBinaryFile } from "isbinaryfile"
77
import { estimateFileSize, wouldExceedSizeLimit } from "../../utils/content-size"
88
import { ContentTooLargeError } from "../../shared/errors"
99

10-
export async function extractTextFromFile(filePath: string, contextLimit: number, usedContext: number = 0): Promise<string> {
10+
export async function extractTextFromFile(filePath: string, contextLimit: number): Promise<string> {
1111
try {
1212
await fs.access(filePath)
1313
} catch (error) {
@@ -21,7 +21,7 @@ export async function extractTextFromFile(filePath: string, contextLimit: number
2121
// This is more efficient than creating a full SizeEstimate object when we just need a boolean check
2222
if (wouldExceedSizeLimit(stats.size, contextLimit)) {
2323
// Only create the full size estimate when we need it for the error
24-
const sizeEstimate = await estimateFileSize(filePath, contextLimit, usedContext)
24+
const sizeEstimate = await estimateFileSize(filePath, contextLimit)
2525
throw new ContentTooLargeError({
2626
type: "file",
2727
path: filePath,

src/integrations/terminal/TerminalManager.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ export class TerminalManager {
109109
}
110110
}
111111

112-
runCommand(
113-
terminalInfo: TerminalInfo,
114-
command: string,
115-
contextLimit?: number,
116-
usedContext?: number,
117-
): TerminalProcessResultPromise {
112+
runCommand(terminalInfo: TerminalInfo, command: string, contextLimit?: number): TerminalProcessResultPromise {
118113
terminalInfo.busy = true
119114
terminalInfo.lastCommand = command
120115
const process = new TerminalProcess()
@@ -146,14 +141,14 @@ export class TerminalManager {
146141
// if shell integration is already active, run the command immediately
147142
if (terminalInfo.terminal.shellIntegration) {
148143
process.waitForShellIntegration = false
149-
process.run(terminalInfo.terminal, command, contextLimit, usedContext)
144+
process.run(terminalInfo.terminal, command, contextLimit)
150145
} else {
151146
// docs recommend waiting 3s for shell integration to activate
152147
pWaitFor(() => terminalInfo.terminal.shellIntegration !== undefined, { timeout: 4000 }).finally(() => {
153148
const existingProcess = this.processes.get(terminalInfo.id)
154149
if (existingProcess && existingProcess.waitForShellIntegration) {
155150
existingProcess.waitForShellIntegration = false
156-
existingProcess.run(terminalInfo.terminal, command, contextLimit, usedContext)
151+
existingProcess.run(terminalInfo.terminal, command, contextLimit)
157152
}
158153
})
159154
}

src/integrations/terminal/TerminalProcess.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
2626
private hotTimer: NodeJS.Timeout | null = null
2727
private totalBytes: number = 0
2828
private contextLimit: number = 100000 // Default context window size
29-
private usedContext: number = 0
3029
private lastCommand: string = ""
3130

3231
// constructor() {
3332
// super()
3433

35-
async run(terminal: vscode.Terminal, command: string, contextLimit?: number, usedContext?: number) {
34+
async run(terminal: vscode.Terminal, command: string, contextLimit?: number) {
3635
if (contextLimit) {
3736
this.contextLimit = contextLimit
3837
}
39-
if (usedContext) {
40-
this.usedContext = usedContext
41-
}
4238
this.lastCommand = command
4339
if (terminal.shellIntegration && terminal.shellIntegration.executeCommand) {
4440
const execution = terminal.shellIntegration.executeCommand(command)
@@ -56,11 +52,7 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
5652
// Use wouldExceedSizeLimit to avoid creating unnecessary buffer
5753
if (wouldExceedSizeLimit(this.totalBytes, this.contextLimit)) {
5854
// Create size estimate only when needed for error details
59-
const sizeEstimate = estimateContentSize(
60-
Buffer.alloc(0, this.totalBytes),
61-
this.contextLimit,
62-
this.usedContext,
63-
)
55+
const sizeEstimate = estimateContentSize(Buffer.alloc(0, this.totalBytes), this.contextLimit)
6456
this.emit(
6557
"error",
6658
new ContentTooLargeError({
@@ -225,7 +217,7 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
225217
const newBufferSize = this.buffer.length + chunk.length
226218
if (wouldExceedSizeLimit(newBufferSize, this.contextLimit)) {
227219
// Create size estimate only when needed for error details
228-
const sizeEstimate = estimateContentSize(Buffer.alloc(0, newBufferSize), this.contextLimit, this.usedContext)
220+
const sizeEstimate = estimateContentSize(Buffer.alloc(0, newBufferSize), this.contextLimit)
229221
this.emit(
230222
"error",
231223
new ContentTooLargeError({

src/utils/content-size.test.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import path from "path"
1111
import os from "os"
1212

1313
const CONTEXT_LIMIT = 1000
14-
const USED_CONTEXT = 200
1514

1615
describe("content-size", () => {
1716
describe("calculateMaxAllowedSize", () => {
@@ -39,31 +38,28 @@ describe("content-size", () => {
3938
describe("estimateContentSize", () => {
4039
it("estimates size for string content", () => {
4140
const content = "Hello world" // 11 bytes
42-
const result = estimateContentSize(content, CONTEXT_LIMIT, USED_CONTEXT)
41+
const result = estimateContentSize(content, CONTEXT_LIMIT)
4342

4443
expect(result.bytes).to.equal(11)
4544
expect(result.estimatedTokens).to.equal(3)
46-
expect(result.remainingContextSize).to.equal(800)
4745
expect(result.wouldExceedLimit).to.equal(false)
4846
})
4947

5048
it("estimates size for buffer content", () => {
5149
const content = Buffer.from("Hello world") // 11 bytes
52-
const result = estimateContentSize(content, CONTEXT_LIMIT, USED_CONTEXT)
50+
const result = estimateContentSize(content, CONTEXT_LIMIT)
5351

5452
expect(result.bytes).to.equal(11)
5553
expect(result.estimatedTokens).to.equal(3)
56-
expect(result.remainingContextSize).to.equal(800)
5754
expect(result.wouldExceedLimit).to.equal(false)
5855
})
5956

6057
it("detects when content would exceed half of context limit", () => {
6158
const halfContextLimit = calculateMaxAllowedSize(CONTEXT_LIMIT) // 500 tokens
6259
const largeContent = "x".repeat(halfContextLimit * 4 + 4) // Just over half context limit in tokens
63-
const result = estimateContentSize(largeContent, CONTEXT_LIMIT, USED_CONTEXT)
60+
const result = estimateContentSize(largeContent, CONTEXT_LIMIT)
6461

6562
expect(result.wouldExceedLimit).to.equal(true)
66-
expect(result.remainingContextSize).to.equal(800) // This is still contextLimit - usedContext
6763
})
6864
})
6965

@@ -80,18 +76,17 @@ describe("content-size", () => {
8076
})
8177

8278
it("estimates size for existing file", async () => {
83-
const result = await estimateFileSize(tempFilePath, CONTEXT_LIMIT, USED_CONTEXT)
79+
const result = await estimateFileSize(tempFilePath, CONTEXT_LIMIT)
8480

8581
expect(result.bytes).to.equal(11)
8682
expect(result.estimatedTokens).to.equal(3)
87-
expect(result.remainingContextSize).to.equal(800)
8883
expect(result.wouldExceedLimit).to.equal(false)
8984
})
9085

9186
it("throws error for non-existent file", async () => {
9287
const nonExistentPath = path.join(os.tmpdir(), "non-existent.txt")
9388
try {
94-
await estimateFileSize(nonExistentPath, CONTEXT_LIMIT, USED_CONTEXT)
89+
await estimateFileSize(nonExistentPath, CONTEXT_LIMIT)
9590
throw new Error("Should have thrown error")
9691
} catch (error) {
9792
expect(error).to.be.instanceOf(Error)

src/utils/content-size.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export interface SizeEstimate {
77
bytes: number
88
estimatedTokens: number
99
wouldExceedLimit: boolean
10-
remainingContextSize: number
1110
}
1211

1312
/**
@@ -39,35 +38,31 @@ export function wouldExceedSizeLimit(byteCount: number, contextLimit: number): b
3938
/**
4039
* Estimates size metrics for a string or buffer without loading entire content
4140
*/
42-
export function estimateContentSize(content: string | Buffer, contextLimit: number, usedContext: number = 0): SizeEstimate {
41+
export function estimateContentSize(content: string | Buffer, contextLimit: number): SizeEstimate {
4342
const bytes = Buffer.isBuffer(content) ? content.length : Buffer.from(content).length
4443
const estimatedTokenCount = estimateTokens(bytes)
45-
const remainingContext = contextLimit - usedContext
4644
const maxAllowedSize = calculateMaxAllowedSize(contextLimit)
4745

4846
return {
4947
bytes,
5048
estimatedTokens: estimatedTokenCount,
5149
wouldExceedLimit: estimatedTokenCount >= maxAllowedSize,
52-
remainingContextSize: remainingContext,
5350
}
5451
}
5552

5653
/**
5754
* Gets size metrics for a file without reading its contents
5855
*/
59-
export async function estimateFileSize(filePath: string, contextLimit: number, usedContext: number = 0): Promise<SizeEstimate> {
56+
export async function estimateFileSize(filePath: string, contextLimit: number): Promise<SizeEstimate> {
6057
const stats = await stat(filePath)
6158
const bytes = stats.size
6259
const estimatedTokenCount = estimateTokens(bytes)
63-
const remainingContext = contextLimit - usedContext
6460
const maxAllowedSize = calculateMaxAllowedSize(contextLimit)
6561

6662
return {
6763
bytes,
6864
estimatedTokens: estimatedTokenCount,
6965
wouldExceedLimit: estimatedTokenCount >= maxAllowedSize,
70-
remainingContextSize: remainingContext,
7166
}
7267
}
7368

0 commit comments

Comments
 (0)