Skip to content

Commit 62fea22

Browse files
committed
More tweaks
1 parent afd0ca2 commit 62fea22

File tree

9 files changed

+252
-171
lines changed

9 files changed

+252
-171
lines changed

src/core/Cline.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,11 +2025,12 @@ export class Cline extends EventEmitter<ClineEvents> {
20252025
details += "\n(No open tabs)"
20262026
}
20272027

2028-
// Get task-specific and background terminals
2028+
// Get task-specific and background terminals.
20292029
const busyTerminals = [
20302030
...TerminalRegistry.getTerminals(true, this.taskId),
20312031
...TerminalRegistry.getBackgroundTerminals(true),
20322032
]
2033+
20332034
const inactiveTerminals = [
20342035
...TerminalRegistry.getTerminals(false, this.taskId),
20352036
...TerminalRegistry.getBackgroundTerminals(false),
@@ -2069,34 +2070,37 @@ export class Cline extends EventEmitter<ClineEvents> {
20692070
}
20702071
}
20712072

2072-
// First check if any inactive terminals in this task have completed processes with output
2073+
// First check if any inactive terminals in this task have completed
2074+
// processes with output.
20732075
const terminalsWithOutput = inactiveTerminals.filter((terminal) => {
20742076
const completedProcesses = terminal.getProcessesWithOutput()
20752077
return completedProcesses.length > 0
20762078
})
20772079

2078-
// Only add the header if there are terminals with output
2080+
// Only add the header if there are terminals with output.
20792081
if (terminalsWithOutput.length > 0) {
20802082
terminalDetails += "\n\n# Inactive Terminals with Completed Process Output"
20812083

2082-
// Process each terminal with output
2084+
// Process each terminal with output.
20832085
for (const inactiveTerminal of terminalsWithOutput) {
20842086
let terminalOutputs: string[] = []
20852087

2086-
// Get output from completed processes queue
2088+
// Get output from completed processes queue.
20872089
const completedProcesses = inactiveTerminal.getProcessesWithOutput()
2090+
20882091
for (const process of completedProcesses) {
20892092
let output = process.getUnretrievedOutput()
2093+
20902094
if (output) {
20912095
output = Terminal.compressTerminalOutput(output, terminalOutputLineLimit)
20922096
terminalOutputs.push(`Command: \`${process.command}\`\n${output}`)
20932097
}
20942098
}
20952099

2096-
// Clean the queue after retrieving output
2100+
// Clean the queue after retrieving output.
20972101
inactiveTerminal.cleanCompletedProcessQueue()
20982102

2099-
// Add this terminal's outputs to the details
2103+
// Add this terminal's outputs to the details.
21002104
if (terminalOutputs.length > 0) {
21012105
terminalDetails += `\n## Terminal ${inactiveTerminal.id}`
21022106
terminalOutputs.forEach((output) => {
@@ -2106,15 +2110,11 @@ export class Cline extends EventEmitter<ClineEvents> {
21062110
}
21072111
}
21082112

2109-
// details += "\n\n# VSCode Workspace Errors"
2110-
// if (diagnosticsDetails) {
2111-
// details += diagnosticsDetails
2112-
// } else {
2113-
// details += "\n(No errors detected)"
2114-
// }
2113+
console.log(`[Cline#getEnvironmentDetails] terminalDetails: ${terminalDetails}`)
21152114

2116-
// Add recently modified files section
2115+
// Add recently modified files section.
21172116
const recentlyModifiedFiles = this.fileContextTracker.getAndClearRecentlyModifiedFiles()
2117+
21182118
if (recentlyModifiedFiles.length > 0) {
21192119
details +=
21202120
"\n\n# Recently Modified Files\nThese files have been modified since you last accessed them (file was just edited so you may need to re-read it before editing):"
@@ -2127,8 +2127,9 @@ export class Cline extends EventEmitter<ClineEvents> {
21272127
details += terminalDetails
21282128
}
21292129

2130-
// Add current time information with timezone
2130+
// Add current time information with timezone.
21312131
const now = new Date()
2132+
21322133
const formatter = new Intl.DateTimeFormat(undefined, {
21332134
year: "numeric",
21342135
month: "numeric",
@@ -2138,22 +2139,26 @@ export class Cline extends EventEmitter<ClineEvents> {
21382139
second: "numeric",
21392140
hour12: true,
21402141
})
2142+
21412143
const timeZone = formatter.resolvedOptions().timeZone
21422144
const timeZoneOffset = -now.getTimezoneOffset() / 60 // Convert to hours and invert sign to match conventional notation
21432145
const timeZoneOffsetHours = Math.floor(Math.abs(timeZoneOffset))
21442146
const timeZoneOffsetMinutes = Math.abs(Math.round((Math.abs(timeZoneOffset) - timeZoneOffsetHours) * 60))
21452147
const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : "-"}${timeZoneOffsetHours}:${timeZoneOffsetMinutes.toString().padStart(2, "0")}`
21462148
details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})`
21472149

2148-
// Add context tokens information
2150+
// Add context tokens information.
21492151
const { contextTokens, totalCost } = getApiMetrics(this.clineMessages)
21502152
const modelInfo = this.api.getModel().info
21512153
const contextWindow = modelInfo.contextWindow
2154+
21522155
const contextPercentage =
21532156
contextTokens && contextWindow ? Math.round((contextTokens / contextWindow) * 100) : undefined
2157+
21542158
details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? `${contextTokens.toLocaleString()} (${contextPercentage}%)` : "(Not available)"}`
21552159
details += `\n\n# Current Cost\n${totalCost !== null ? `$${totalCost.toFixed(2)}` : "(Not available)"}`
2156-
// Add current mode and any mode-specific warnings
2160+
2161+
// Add current mode and any mode-specific warnings.
21572162
const {
21582163
mode,
21592164
customModes,
@@ -2163,28 +2168,31 @@ export class Cline extends EventEmitter<ClineEvents> {
21632168
customInstructions: globalCustomInstructions,
21642169
language,
21652170
} = (await this.providerRef.deref()?.getState()) ?? {}
2171+
21662172
const currentMode = mode ?? defaultModeSlug
2173+
21672174
const modeDetails = await getFullModeDetails(currentMode, customModes, customModePrompts, {
21682175
cwd: this.cwd,
21692176
globalCustomInstructions,
21702177
language: language ?? formatLanguage(vscode.env.language),
21712178
})
2179+
21722180
details += `\n\n# Current Mode\n`
21732181
details += `<slug>${currentMode}</slug>\n`
21742182
details += `<name>${modeDetails.name}</name>\n`
21752183
details += `<model>${apiModelId}</model>\n`
2184+
21762185
if (Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.POWER_STEERING)) {
21772186
details += `<role>${modeDetails.roleDefinition}</role>\n`
2187+
21782188
if (modeDetails.customInstructions) {
21792189
details += `<custom_instructions>${modeDetails.customInstructions}</custom_instructions>\n`
21802190
}
21812191
}
21822192

2183-
// Add warning if not in code mode
2193+
// Add warning if not in code mode.
21842194
if (
2185-
!isToolAllowedForMode("write_to_file", currentMode, customModes ?? [], {
2186-
apply_diff: this.diffEnabled,
2187-
}) &&
2195+
!isToolAllowedForMode("write_to_file", currentMode, customModes ?? [], { apply_diff: this.diffEnabled }) &&
21882196
!isToolAllowedForMode("apply_diff", currentMode, customModes ?? [], { apply_diff: this.diffEnabled })
21892197
) {
21902198
const currentModeName = getModeBySlug(currentMode, customModes)?.name ?? currentMode
@@ -2195,20 +2203,24 @@ export class Cline extends EventEmitter<ClineEvents> {
21952203
if (includeFileDetails) {
21962204
details += `\n\n# Current Workspace Directory (${this.cwd.toPosix()}) Files\n`
21972205
const isDesktop = arePathsEqual(this.cwd, path.join(os.homedir(), "Desktop"))
2206+
21982207
if (isDesktop) {
2199-
// don't want to immediately access desktop since it would show permission popup
2208+
// Don't want to immediately access desktop since it would show
2209+
// permission popup.
22002210
details += "(Desktop files not shown automatically. Use list_files to explore if needed.)"
22012211
} else {
22022212
const maxFiles = maxWorkspaceFiles ?? 200
22032213
const [files, didHitLimit] = await listFiles(this.cwd, true, maxFiles)
22042214
const { showRooIgnoredFiles = true } = (await this.providerRef.deref()?.getState()) ?? {}
2215+
22052216
const result = formatResponse.formatFilesList(
22062217
this.cwd,
22072218
files,
22082219
didHitLimit,
22092220
this.rooIgnoreController,
22102221
showRooIgnoredFiles,
22112222
)
2223+
22122224
details += result
22132225
}
22142226
}

src/integrations/terminal/ExecaTerminal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export class ExecaTerminal extends BaseTerminal {
88
super("execa", id, cwd)
99
}
1010

11+
/**
12+
* Unlike the VSCode terminal, this is never closed.
13+
*/
1114
public override isClosed(): boolean {
1215
return false
1316
}

src/integrations/terminal/ExecaTerminalProcess.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
3636
cancelSignal: this.controller.signal,
3737
})`${command}`
3838

39+
this.terminal.setActiveStream(subprocess)
3940
this.emit("line", "")
4041

4142
for await (const line of subprocess) {
@@ -64,6 +65,7 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
6465
}
6566
}
6667

68+
this.terminal.setActiveStream(undefined)
6769
this.emitRemainingBufferIfListening()
6870
this.stopHotTimer()
6971
this.emit("completed", this.fullOutput)
@@ -85,28 +87,33 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
8587
}
8688

8789
public override getUnretrievedOutput() {
88-
let outputToProcess = this.fullOutput.slice(this.lastRetrievedIndex)
89-
let endIndex = outputToProcess.lastIndexOf("\n")
90+
let output = this.fullOutput.slice(this.lastRetrievedIndex)
91+
let index = output.lastIndexOf("\n")
9092

91-
if (endIndex === -1) {
93+
if (index === -1) {
9294
return ""
9395
}
9496

95-
endIndex++
97+
index++
98+
this.lastRetrievedIndex += index
9699

97-
this.lastRetrievedIndex += endIndex
98-
return outputToProcess.slice(0, endIndex)
100+
// console.log(
101+
// `[ExecaTerminalProcess#getUnretrievedOutput] fullOutput.length=${this.fullOutput.length} lastRetrievedIndex=${this.lastRetrievedIndex}`,
102+
// output.slice(0, index),
103+
// )
104+
105+
return output.slice(0, index)
99106
}
100107

101108
private emitRemainingBufferIfListening() {
102109
if (!this.isListening) {
103110
return
104111
}
105112

106-
const remainingBuffer = this.getUnretrievedOutput()
113+
const output = this.getUnretrievedOutput()
107114

108-
if (remainingBuffer !== "") {
109-
this.emit("line", remainingBuffer)
115+
if (output !== "") {
116+
this.emit("line", output)
110117
}
111118
}
112119
}

src/integrations/terminal/TerminalProcess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ export class TerminalProcess extends BaseTerminalProcess {
205205
this.startHotTimer(data)
206206
}
207207

208-
// Set streamClosed immediately after stream ends
208+
// Set streamClosed immediately after stream ends.
209209
this.terminal.setActiveStream(undefined)
210210

211-
// Wait for shell execution to complete
211+
// Wait for shell execution to complete.
212212
await shellExecutionComplete
213213

214214
this.isHot = false

0 commit comments

Comments
 (0)