Skip to content

Commit 6f21cb9

Browse files
committed
back out non-file related checks
1 parent 544d450 commit 6f21cb9

File tree

8 files changed

+193
-237
lines changed

8 files changed

+193
-237
lines changed

src/core/Cline.ts

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,9 @@ export class Cline {
11401140
const contextWindow = this.api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
11411141
const maxAllowedSize = getMaxAllowedSize(contextWindow)
11421142

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

11471147
let userFeedback: { text?: string; images?: string[] } | undefined
11481148
let didContinue = false
@@ -1188,7 +1188,7 @@ export class Cline {
11881188
// the correct order of messages (although the webview is smart about
11891189
// grouping command_output messages despite any gaps anyways)
11901190
await delay(50)
1191-
// AKF TODO -> investigate failed results
1191+
11921192
result = result.trim()
11931193

11941194
if (userFeedback) {
@@ -2963,16 +2963,6 @@ export class Cline {
29632963
throw new Error("Cline instance aborted")
29642964
}
29652965

2966-
// Log file content being passed to model
2967-
userContent.forEach((block) => {
2968-
if (block.type === "text" && block.text) {
2969-
// Look for file content markers
2970-
if (block.text.includes("<file_content") || block.text.includes("<final_file_content")) {
2971-
console.log(`[MODEL_INPUT] File content being passed to model. Content length: ${block.text.length} chars`)
2972-
}
2973-
}
2974-
})
2975-
29762966
if (this.consecutiveMistakeCount >= 3) {
29772967
if (this.autoApprovalSettings.enabled && this.autoApprovalSettings.enableNotifications) {
29782968
showSystemNotification({
@@ -3442,44 +3432,34 @@ export class Cline {
34423432
if (busyTerminals.length > 0) {
34433433
// terminals are cool, let's retrieve their output
34443434
terminalDetails += "\n\n# Actively Running Terminals"
3445-
const contextWindow = this.api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
3446-
3447-
// Get output from all busy terminals
3448-
const busyOutputs = await Promise.all(
3449-
busyTerminals.map(async (terminal) => {
3450-
const output = await this.terminalManager.getUnretrievedOutput(terminal.id, contextWindow)
3451-
return { terminal, output }
3452-
}),
3453-
)
3454-
3455-
// Add output to details
3456-
for (const { terminal, output } of busyOutputs) {
3457-
terminalDetails += `\n## Original command: \`${terminal.lastCommand}\``
3458-
if (output) {
3459-
terminalDetails += `\n### New Output\n${output}`
3435+
for (const busyTerminal of busyTerminals) {
3436+
terminalDetails += `\n## Original command: \`${busyTerminal.lastCommand}\``
3437+
const newOutput = this.terminalManager.getUnretrievedOutput(busyTerminal.id)
3438+
if (newOutput) {
3439+
terminalDetails += `\n### New Output\n${newOutput}`
3440+
} else {
3441+
// details += `\n(Still running, no new output)` // don't want to show this right after running the command
34603442
}
34613443
}
34623444
}
34633445

34643446
// only show inactive terminals if there's output to show
34653447
if (inactiveTerminals.length > 0) {
3466-
const contextWindow = this.api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
3467-
3468-
// Get output from all inactive terminals
3469-
const inactiveOutputs = await Promise.all(
3470-
inactiveTerminals.map(async (terminal) => {
3471-
const output = await this.terminalManager.getUnretrievedOutput(terminal.id, contextWindow)
3472-
return { terminal, output }
3473-
}),
3474-
)
3475-
3476-
// Filter and add outputs that have content
3477-
const outputsWithContent = inactiveOutputs.filter(({ output }) => output)
3478-
if (outputsWithContent.length > 0) {
3448+
const inactiveTerminalOutputs = new Map<number, string>()
3449+
for (const inactiveTerminal of inactiveTerminals) {
3450+
const newOutput = await this.terminalManager.getUnretrievedOutput(inactiveTerminal.id)
3451+
if (newOutput) {
3452+
inactiveTerminalOutputs.set(inactiveTerminal.id, newOutput)
3453+
}
3454+
}
3455+
if (inactiveTerminalOutputs.size > 0) {
34793456
terminalDetails += "\n\n# Inactive Terminals"
3480-
for (const { terminal, output } of outputsWithContent) {
3481-
terminalDetails += `\n## ${terminal.lastCommand}`
3482-
terminalDetails += `\n### New Output\n${output}`
3457+
for (const [terminalId, newOutput] of inactiveTerminalOutputs) {
3458+
const inactiveTerminal = inactiveTerminals.find((t) => t.id === terminalId)
3459+
if (inactiveTerminal) {
3460+
terminalDetails += `\n## ${inactiveTerminal.lastCommand}`
3461+
terminalDetails += `\n### New Output\n${newOutput}`
3462+
}
34833463
}
34843464
}
34853465
}

src/core/mentions/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ export async function parseMentions(
117117
}
118118
} else if (mention === "terminal") {
119119
try {
120-
const contextWindow = api.getModel().info.contextWindow || 64_000 // minimum context (Deepseek)
121-
const terminalOutput = await getLatestTerminalOutput(contextWindow)
120+
const terminalOutput = await getLatestTerminalOutput()
122121
parsedText += `\n\n<terminal_output>\n${terminalOutput}\n</terminal_output>`
123122
} catch (error) {
124123
parsedText += `\n\n<terminal_output>\nError fetching terminal output: ${error.message}\n</terminal_output>`

src/integrations/misc/extract-text.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import { ContentTooLargeError } from "../../shared/errors"
1616
* @throws ContentTooLargeError if content exceeds size limit
1717
*/
1818
export async function extractTextFromTerminal(content: string | Buffer, contextWindow: number, command: string): Promise<string> {
19-
console.log(`[TERMINAL_SIZE_CHECK] Checking size for command output: ${command}`)
19+
console.debug(`[TERMINAL_SIZE_CHECK] Checking size for command output: ${command}`)
2020

2121
// Convert to string but don't trim yet
2222
const rawContent = content.toString()
23-
console.log(`[TERMINAL_SIZE_CHECK] Raw content length: ${rawContent.length}`)
23+
console.debug(`[TERMINAL_SIZE_CHECK] Raw content length: ${rawContent.length}`)
2424

2525
// Check size before trimming
2626
const sizeEstimate = estimateContentSize(rawContent, contextWindow)
27-
console.log(`[TERMINAL_SIZE_CHECK] Content size: ${sizeEstimate.bytes} bytes`)
28-
console.log(`[TERMINAL_SIZE_CHECK] Estimated tokens: ${sizeEstimate.estimatedTokens}`)
29-
console.log(`[TERMINAL_SIZE_CHECK] Context window: ${contextWindow}`)
27+
console.debug(`[TERMINAL_SIZE_CHECK] Content size: ${sizeEstimate.bytes} bytes`)
28+
console.debug(`[TERMINAL_SIZE_CHECK] Estimated tokens: ${sizeEstimate.estimatedTokens}`)
29+
console.debug(`[TERMINAL_SIZE_CHECK] Context window: ${contextWindow}`)
3030

3131
if (sizeEstimate.wouldExceedLimit) {
32-
console.log(`[TERMINAL_SIZE_CHECK] Output exceeds size limit`)
32+
console.debug(`[TERMINAL_SIZE_CHECK] Output exceeds size limit`)
3333
throw new ContentTooLargeError({
3434
type: "terminal",
3535
command,
@@ -39,8 +39,8 @@ export async function extractTextFromTerminal(content: string | Buffer, contextW
3939

4040
// Only trim after size check passes
4141
const cleanContent = rawContent.trim()
42-
console.log(`[TERMINAL_SIZE_CHECK] Clean content length: ${cleanContent.length}`)
43-
console.log(`[TERMINAL_SIZE_CHECK] Size check passed`)
42+
console.debug(`[TERMINAL_SIZE_CHECK] Clean content length: ${cleanContent.length}`)
43+
console.debug(`[TERMINAL_SIZE_CHECK] Size check passed`)
4444
return cleanContent
4545
}
4646

@@ -51,20 +51,20 @@ export async function extractTextFromFile(filePath: string, contextWindow: numbe
5151
throw new Error(`File not found: ${filePath}`)
5252
}
5353

54-
console.log(`[FILE_READ_CHECK] Checking size for file: ${filePath}`)
54+
console.debug(`[FILE_READ_CHECK] Checking size for file: ${filePath}`)
5555

5656
// Get file stats to check size
5757
const stats = await fs.stat(filePath)
58-
console.log(`[FILE_SIZE_CHECK] File size: ${stats.size} bytes`)
58+
console.debug(`[FILE_SIZE_CHECK] File size: ${stats.size} bytes`)
5959

6060
// Calculate max allowed size from context window
6161
const maxAllowedSize = getMaxAllowedSize(contextWindow)
62-
console.log(`[FILE_SIZE_CHECK] Max allowed size: ${maxAllowedSize} tokens`)
62+
console.debug(`[FILE_SIZE_CHECK] Max allowed size: ${maxAllowedSize} tokens`)
6363

6464
// Check if file size would exceed limit before attempting to read
6565
// This is more efficient than creating a full SizeEstimate object when we just need a boolean check
6666
if (wouldExceedSizeLimit(stats.size, contextWindow)) {
67-
console.log(`[FILE_SIZE_CHECK] File exceeds size limit`)
67+
console.debug(`[FILE_SIZE_CHECK] File exceeds size limit`)
6868
// Only create the full size estimate when we need it for the error
6969
const sizeEstimate = await estimateFileSize(filePath, maxAllowedSize)
7070
throw new ContentTooLargeError({
@@ -73,9 +73,9 @@ export async function extractTextFromFile(filePath: string, contextWindow: numbe
7373
size: sizeEstimate,
7474
})
7575
}
76-
console.log(`[FILE_SIZE_CHECK] File size check passed`)
76+
console.debug(`[FILE_SIZE_CHECK] File size check passed`)
7777
const fileExtension = path.extname(filePath).toLowerCase()
78-
console.log(`[FILE_READ] Reading file: ${filePath}`)
78+
console.debug(`[FILE_READ] Reading file: ${filePath}`)
7979
let content: string
8080
switch (fileExtension) {
8181
case ".pdf":
@@ -95,7 +95,7 @@ export async function extractTextFromFile(filePath: string, contextWindow: numbe
9595
throw new Error(`Cannot read text for file type: ${fileExtension}`)
9696
}
9797
}
98-
console.log(`[FILE_READ_COMPLETE] File read complete. Content length: ${content.length} chars`)
98+
console.debug(`[FILE_READ_COMPLETE] File read complete. Content length: ${content.length} chars`)
9999
return content
100100
}
101101

src/integrations/terminal/TerminalManager.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as vscode from "vscode"
33
import { arePathsEqual } from "../../utils/path"
44
import { mergePromise, TerminalProcess, TerminalProcessResultPromise } from "./TerminalProcess"
55
import { TerminalInfo, TerminalRegistry } from "./TerminalRegistry"
6-
import { extractTextFromTerminal } from "../../integrations/misc/extract-text"
76

87
/*
98
TerminalManager:
@@ -110,7 +109,7 @@ export class TerminalManager {
110109
}
111110
}
112111

113-
runCommand(terminalInfo: TerminalInfo, command: string, contextLimit: number): TerminalProcessResultPromise {
112+
runCommand(terminalInfo: TerminalInfo, command: string): TerminalProcessResultPromise {
114113
terminalInfo.busy = true
115114
terminalInfo.lastCommand = command
116115
const process = new TerminalProcess()
@@ -142,22 +141,22 @@ export class TerminalManager {
142141
// if shell integration is already active, run the command immediately
143142
if (terminalInfo.terminal.shellIntegration) {
144143
process.waitForShellIntegration = false
145-
process.run(terminalInfo.terminal, command, contextLimit)
144+
process.run(terminalInfo.terminal, command)
146145
} else {
147146
// docs recommend waiting 3s for shell integration to activate
148147
pWaitFor(() => terminalInfo.terminal.shellIntegration !== undefined, { timeout: 4000 }).finally(() => {
149148
const existingProcess = this.processes.get(terminalInfo.id)
150149
if (existingProcess && existingProcess.waitForShellIntegration) {
151150
existingProcess.waitForShellIntegration = false
152-
existingProcess.run(terminalInfo.terminal, command, contextLimit)
151+
existingProcess.run(terminalInfo.terminal, command)
153152
}
154153
})
155154
}
156155

157156
return mergePromise(process, promise)
158157
}
159158

160-
async getOrCreateTerminal(cwd: string, contextLimit: number): Promise<TerminalInfo> {
159+
async getOrCreateTerminal(cwd: string): Promise<TerminalInfo> {
161160
const terminals = TerminalRegistry.getAllTerminals()
162161

163162
// Find available terminal from our pool first (created for this task)
@@ -180,7 +179,7 @@ export class TerminalManager {
180179
const availableTerminal = terminals.find((t) => !t.busy)
181180
if (availableTerminal) {
182181
// Navigate back to the desired directory
183-
await this.runCommand(availableTerminal, `cd "${cwd}"`, contextLimit)
182+
await this.runCommand(availableTerminal, `cd "${cwd}"`)
184183
this.terminalIds.add(availableTerminal.id)
185184
return availableTerminal
186185
}
@@ -198,19 +197,12 @@ export class TerminalManager {
198197
.map((t) => ({ id: t.id, lastCommand: t.lastCommand }))
199198
}
200199

201-
async getUnretrievedOutput(terminalId: number, contextLimit: number): Promise<string> {
200+
getUnretrievedOutput(terminalId: number): string {
202201
if (!this.terminalIds.has(terminalId)) {
203202
return ""
204203
}
205204
const process = this.processes.get(terminalId)
206-
if (!process) {
207-
return ""
208-
}
209-
const output = process.getUnretrievedOutput()
210-
if (!output) {
211-
return ""
212-
}
213-
return await extractTextFromTerminal(output, contextLimit, `Terminal ${terminalId} output`)
205+
return process ? process.getUnretrievedOutput() : ""
214206
}
215207

216208
isProcessHot(terminalId: number): boolean {

0 commit comments

Comments
 (0)