Skip to content
TypeScript

feat(web): make context window indicator opt-in (#9190)

mariaa19f01fc19d2
diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts
index 1d0c1653f02..ef9cf7beef9 100644
--- a/apps/desktop/src/settings/DesktopClientSettings.test.ts
+++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts
@@ -23,6 +23,7 @@ const clientSettings: ClientSettings = {
confirmThreadArchive: true,
confirmThreadDelete: false,
confirmThreadUnpin: false,
+ contextWindowMeterEnabled: false,
dismissedProviderUpdateNotificationKeys: [],
diffIgnoreWhitespace: true,
environmentIdentificationMode: "artwork",
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 3898d886322..d043900841e 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -4339,7 +4339,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
) : null}
<ComposerFooterPrimaryActions
compact={isComposerPrimaryActionsCompact}
- activeContextWindow={activeContextWindow}
+ activeContextWindow={
+ settings.contextWindowMeterEnabled ? activeContextWindow : null
+ }
activeThreadModelDisplayName={activeThreadModelDisplayName}
pendingAction={pendingPrimaryAction}
isRunning={phase === "running"}
diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx
index 2bc748db35a..efa6f87b27c 100644
--- a/apps/web/src/components/settings/SettingsPanels.tsx
+++ b/apps/web/src/components/settings/SettingsPanels.tsx
@@ -522,6 +522,9 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.showSkillsInSlashMenu !== DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu
? ["Show skills in slash menu"]
: []),
+ ...(settings.contextWindowMeterEnabled !== DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled
+ ? ["Context window indicator"]
+ : []),
...(settings.enableLegacyTokenStreaming !==
DEFAULT_UNIFIED_SETTINGS.enableLegacyTokenStreaming
? ["Stream token by token"]
@@ -576,6 +579,7 @@ export function useSettingsRestore(onRestored?: () => void) {
settings.newWorktreesStartFromOrigin,
settings.diffIgnoreWhitespace,
settings.environmentIdentificationMode,
+ settings.contextWindowMeterEnabled,
settings.fontFamilyCode,
settings.fontFamilyComposer,
settings.fontFamilySans,
@@ -668,6 +672,7 @@ export function useSettingsRestore(onRestored?: () => void) {
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
+ contextWindowMeterEnabled: DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled,
environmentIdentificationMode: DEFAULT_UNIFIED_SETTINGS.environmentIdentificationMode,
glassOpacity: DEFAULT_UNIFIED_SETTINGS.glassOpacity,
sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount,
@@ -1750,6 +1755,7 @@ function AutoSettleDaysInput({
// expand the section before its target can mount and scroll.
const LEGACY_FEATURE_TARGET_IDS: ReadonlySet<string> = new Set([
"legacy-plan-mode",
+ "legacy-context-window-indicator",
"legacy-token-streaming",
"legacy-sidebar",
]);
@@ -1826,6 +1832,19 @@ function LegacyFeaturesSection() {
/>
}
/>
+ <SettingsRow
+ {...searchableSetting("legacy-context-window-indicator")}
+ description="Shows context window usage as a circular indicator in the composer."
+ control={
+ <Switch
+ checked={settings.contextWindowMeterEnabled}
+ onCheckedChange={(checked) =>
+ updateSettings({ contextWindowMeterEnabled: Boolean(checked) })
+ }
+ aria-label="Context window indicator (legacy)"
+ />
+ }
+ />
<SettingsRow
serverScoped
{...searchableSetting("legacy-token-streaming")}
diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts
index a3e5cf4b9a6..0d9a7c43bf9 100644
--- a/apps/web/src/components/settings/settingsSearch.ts
+++ b/apps/web/src/components/settings/settingsSearch.ts
@@ -261,6 +261,12 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/general",
searchTerms: ["build plan composer old"],
},
+ {
+ id: "legacy-context-window-indicator",
+ title: "Context window indicator (legacy)",
+ to: "/settings/general",
+ searchTerms: ["composer meter usage tokens circle old"],
+ },
{
id: "legacy-token-streaming",
title: "Stream token by token (legacy)",
diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts
index 6c71a0e4297..43781429fa0 100644
--- a/packages/contracts/src/settings.test.ts
+++ b/packages/contracts/src/settings.test.ts
@@ -191,6 +191,18 @@ describe("ClientSettings sidebar", () => {
});
});
+describe("ClientSettings context window meter", () => {
+ it("defaults off and preserves an explicit legacy opt-in", () => {
+ expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
+ expect(
+ decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
+ ).toBe(true);
+ expect(
+ decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
+ ).toBe(true);
+ });
+});
+
describe("ServerSettings thread settlement", () => {
it("defaults merge settlement on and inactivity settlement to three days", () => {
const settings = decodeServerSettings({});
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index 6ec4df5da1f..68a5c1e874c 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -265,6 +265,9 @@ export const ClientSettingsSchema = Schema.Struct({
// default UI; this beta flag restores it (plus the /plan and /default slash
// commands) for users who still rely on the old workflow.
planModeEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
+ // Legacy context window meter. The composer hides it by default; users who
+ // still want the old usage indicator can restore it from Settings.
+ contextWindowMeterEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
// Legacy sidebar (the original per-project tree). Deliberately a fresh key
// (was `sidebarV2Enabled` + `sidebarV2ConfiguredByUser`): decoding drops the
@@ -990,6 +993,7 @@ export const ClientSettingsPatch = Schema.Struct({
),
),
planModeEnabled: Schema.optionalKey(Schema.Boolean),
+ contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),
showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),