@@ -90,6 +90,18 @@ const ProgressBar: React.FC<{
9090 ) ;
9191} ;
9292
93+ /**
94+ * Format percentage for display, showing ">100%" when exceeding limit.
95+ */
96+ function formatPercentage ( tokens : number , contextWindowSize : number ) : string {
97+ if ( contextWindowSize <= 0 ) return '0.0' ;
98+ const percentage = ( tokens / contextWindowSize ) * 100 ;
99+ if ( percentage > 100 ) {
100+ return '>100' ;
101+ }
102+ return percentage . toFixed ( 1 ) ;
103+ }
104+
93105/**
94106 * A row showing a category with its token count and percentage.
95107 */
@@ -99,9 +111,17 @@ const CategoryRow: React.FC<{
99111 tokens : number ;
100112 contextWindowSize : number ;
101113 symbolColor ?: string ;
102- } > = ( { symbol, label, tokens, contextWindowSize, symbolColor } ) => {
103- const percentage = ( ( tokens / contextWindowSize ) * 100 ) . toFixed ( 1 ) ;
104- const tokenStr = `${ formatTokens ( tokens ) } ${ t ( 'tokens' ) } (${ percentage } %)` ;
114+ isOverLimit ?: boolean ;
115+ } > = ( {
116+ symbol,
117+ label,
118+ tokens,
119+ contextWindowSize,
120+ symbolColor,
121+ isOverLimit,
122+ } ) => {
123+ const percentageStr = formatPercentage ( tokens , contextWindowSize ) ;
124+ const tokenStr = `${ formatTokens ( tokens ) } ${ t ( 'tokens' ) } (${ percentageStr } %)` ;
105125
106126 return (
107127 < Box width = { CONTENT_WIDTH } >
@@ -112,7 +132,9 @@ const CategoryRow: React.FC<{
112132 < Text color = { theme . text . primary } > { label } </ Text >
113133 </ Box >
114134 < Box flexGrow = { 1 } justifyContent = "flex-end" >
115- < Text color = { theme . text . secondary } > { tokenStr } </ Text >
135+ < Text color = { isOverLimit ? theme . status . error : theme . text . secondary } >
136+ { tokenStr }
137+ </ Text >
116138 </ Box >
117139 </ Box >
118140 ) ;
@@ -158,6 +180,7 @@ export const ContextUsage: React.FC<ContextUsageProps> = ({
158180} ) => {
159181 const percentage =
160182 contextWindowSize > 0 ? ( totalTokens / contextWindowSize ) * 100 : 0 ;
183+ const isOverLimit = percentage > 100 ;
161184
162185 // Sort detail items by token count (descending) for better readability
163186 const sortedBuiltinTools = [ ...builtinTools ] . sort (
@@ -236,14 +259,23 @@ export const ContextUsage: React.FC<ContextUsageProps> = ({
236259 width = { CONTENT_WIDTH }
237260 />
238261 </ Box >
262+ { /* Warning when context exceeds limit */ }
263+ { isOverLimit && (
264+ < Box marginBottom = { 1 } >
265+ < Text color = { theme . status . error } >
266+ { t ( 'Context exceeds limit! Use /compress or /clear to reduce.' ) }
267+ </ Text >
268+ </ Box >
269+ ) }
239270 < Box height = { 1 } />
240271 { /* Legend — same layout as CategoryRow for alignment */ }
241272 < CategoryRow
242273 symbol = { FILLED }
243274 label = { t ( 'Used' ) }
244275 tokens = { totalTokens }
245276 contextWindowSize = { contextWindowSize }
246- symbolColor = { theme . text . accent }
277+ symbolColor = { isOverLimit ? theme . status . error : theme . text . accent }
278+ isOverLimit = { isOverLimit }
247279 />
248280 < CategoryRow
249281 symbol = { EMPTY }
0 commit comments