From 9409490cf7bf62f0259eb0b4bedea1fb07c74893 Mon Sep 17 00:00:00 2001 From: hannesrudolph Date: Mon, 16 Jun 2025 12:21:26 -0600 Subject: [PATCH] feat: add truncate file URIs opt-in setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add new global setting `truncateFileUris` to control URI truncation - Add checkbox UI in Context Management settings section - Handle setting updates through webview message handler - Add English translations for the new setting This allows users to opt into truncating long file paths in the context display to save tokens while showing full paths on hover. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- packages/types/src/global-settings.ts | 2 ++ src/core/webview/webviewMessageHandler.ts | 4 ++++ src/shared/WebviewMessage.ts | 1 + .../settings/ContextManagementSettings.tsx | 17 +++++++++++++++++ .../src/components/settings/SettingsView.tsx | 3 +++ webview-ui/src/i18n/locales/en/settings.json | 4 ++++ 6 files changed, 31 insertions(+) diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index e0eeb70a33..1dbec0a7ca 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -68,6 +68,7 @@ export const globalSettingsSchema = z.object({ maxWorkspaceFiles: z.number().optional(), showRooIgnoredFiles: z.boolean().optional(), maxReadFileLine: z.number().optional(), + truncateFileUris: z.boolean().optional(), terminalOutputLineLimit: z.number().optional(), terminalShellIntegrationTimeout: z.number().optional(), @@ -154,6 +155,7 @@ export const GLOBAL_SETTINGS_KEYS = keysOf()([ "maxWorkspaceFiles", "showRooIgnoredFiles", "maxReadFileLine", + "truncateFileUris", "terminalOutputLineLimit", "terminalShellIntegrationTimeout", diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 6568b4aaee..70e22b922a 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -1001,6 +1001,10 @@ export const webviewMessageHandler = async ( await updateGlobalState("maxReadFileLine", message.value) await provider.postStateToWebview() break + case "truncateFileUris": + await updateGlobalState("truncateFileUris", message.bool ?? false) + await provider.postStateToWebview() + break case "maxConcurrentFileReads": const valueToSave = message.value // Capture the value intended for saving await updateGlobalState("maxConcurrentFileReads", valueToSave) diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index d27b931f10..3b70ebb716 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -137,6 +137,7 @@ export interface WebviewMessage { | "remoteBrowserEnabled" | "language" | "maxReadFileLine" + | "truncateFileUris" | "maxConcurrentFileReads" | "searchFiles" | "toggleApiConfigPin" diff --git a/webview-ui/src/components/settings/ContextManagementSettings.tsx b/webview-ui/src/components/settings/ContextManagementSettings.tsx index 6b558bdfbd..847871865b 100644 --- a/webview-ui/src/components/settings/ContextManagementSettings.tsx +++ b/webview-ui/src/components/settings/ContextManagementSettings.tsx @@ -61,6 +61,7 @@ type ContextManagementSettingsProps = HTMLAttributes & { maxWorkspaceFiles: number showRooIgnoredFiles?: boolean maxReadFileLine?: number + truncateFileUris?: boolean setCachedStateField: SetCachedStateField< | "autoCondenseContext" | "autoCondenseContextPercent" @@ -70,6 +71,7 @@ type ContextManagementSettingsProps = HTMLAttributes & { | "maxWorkspaceFiles" | "showRooIgnoredFiles" | "maxReadFileLine" + | "truncateFileUris" > } @@ -84,6 +86,7 @@ export const ContextManagementSettings = ({ showRooIgnoredFiles, setCachedStateField, maxReadFileLine, + truncateFileUris, className, ...props }: ContextManagementSettingsProps) => { @@ -185,6 +188,20 @@ export const ContextManagementSettings = ({ {t("settings:contextManagement.maxReadFile.description")} + +
+ setCachedStateField("truncateFileUris", e.target.checked)} + data-testid="truncate-file-uris-checkbox"> + + +
+ {t("settings:contextManagement.truncateFileUris.description")} +
+
diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index d3d6e89dad..4af025a727 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -164,6 +164,7 @@ const SettingsView = forwardRef(({ onDone, t showRooIgnoredFiles, remoteBrowserEnabled, maxReadFileLine, + truncateFileUris, terminalCompressProgressBar, maxConcurrentFileReads, condensingApiConfigId, @@ -290,6 +291,7 @@ const SettingsView = forwardRef(({ onDone, t vscode.postMessage({ type: "maxWorkspaceFiles", value: maxWorkspaceFiles ?? 200 }) vscode.postMessage({ type: "showRooIgnoredFiles", bool: showRooIgnoredFiles }) vscode.postMessage({ type: "maxReadFileLine", value: maxReadFileLine ?? -1 }) + vscode.postMessage({ type: "truncateFileUris", bool: truncateFileUris }) vscode.postMessage({ type: "maxConcurrentFileReads", value: cachedState.maxConcurrentFileReads ?? 15 }) vscode.postMessage({ type: "currentApiConfigName", text: currentApiConfigName }) vscode.postMessage({ type: "updateExperimental", values: experiments }) @@ -627,6 +629,7 @@ const SettingsView = forwardRef(({ onDone, t maxWorkspaceFiles={maxWorkspaceFiles ?? 200} showRooIgnoredFiles={showRooIgnoredFiles} maxReadFileLine={maxReadFileLine} + truncateFileUris={truncateFileUris} setCachedStateField={setCachedStateField} /> )} diff --git a/webview-ui/src/i18n/locales/en/settings.json b/webview-ui/src/i18n/locales/en/settings.json index 37a22bdca5..7af3073ac1 100644 --- a/webview-ui/src/i18n/locales/en/settings.json +++ b/webview-ui/src/i18n/locales/en/settings.json @@ -389,6 +389,10 @@ "description": "Roo reads this number of lines when the model omits start/end values. If this number is less than the file's total, Roo generates a line number index of code definitions. Special cases: -1 instructs Roo to read the entire file (without indexing), and 0 instructs it to read no lines and provides line indexes only for minimal context. Lower values minimize initial context usage, enabling precise subsequent line-range reads. Explicit start/end requests are not limited by this setting.", "lines": "lines", "always_full_read": "Always read entire file" + }, + "truncateFileUris": { + "label": "Truncate long file URIs", + "description": "When enabled, long file paths in the context window will be truncated to save tokens. The full path is shown on hover." } }, "terminal": {