feat: Add context tokens to environment details

Adds the current conversation's context token count to the environment details section by:
- Using existing getApiMetrics() to retrieve contextTokens from the last API request
- Adding a new "Context Tokens" section between "Current Time" and "Current Mode"
- Formatting the token count with toLocaleString() for better readability
- Showing "(Not available)" when no context tokens are present

This provides visibility into the current conversation's token usage directly in the environment details, helping track context window utilization.
This commit is contained in:
MFPires
2025-01-28 15:49:36 -03:00
parent f2ac56917c
commit f7cf08c607

View File

@@ -3041,6 +3041,10 @@ export class Cline {
const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : ""}${timeZoneOffset}:00`
details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})`
// Add context tokens information
const { contextTokens } = getApiMetrics(this.clineMessages)
details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? contextTokens.toLocaleString() : "(Not available)"}`
// Add current mode and any mode-specific warnings
const { mode, customModes } = (await this.providerRef.deref()?.getState()) ?? {}
const currentMode = mode ?? defaultModeSlug