feat: context window usage indicator with real agent data
The context indicator in the composer footer now shows real data from the agent's context compressor instead of hardcoded estimates: - last_prompt_tokens / context_length (e.g. '12.4k / 200k (6%)') - Bar color: blue <50%, yellow 50-75%, red >75% - Hover tooltip shows exact numbers + compression threshold - Cost appended when available Backend: streaming.py now reads context_length, threshold_tokens, and last_prompt_tokens from agent.context_compressor after run_conversation() and includes them in the usage dict sent with the 'done' SSE event. This matches the CLI's context window display (the bar that shows current context vs total window). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -310,6 +310,12 @@ def _run_agent_streaming(session_id, msg_text, model, workspace, stream_id, atta
|
||||
break
|
||||
s.save()
|
||||
usage = {'input_tokens': input_tokens, 'output_tokens': output_tokens, 'estimated_cost': estimated_cost}
|
||||
# Include context window data from the agent's compressor for the UI indicator
|
||||
_cc = getattr(agent, 'context_compressor', None)
|
||||
if _cc:
|
||||
usage['context_length'] = getattr(_cc, 'context_length', 0) or 0
|
||||
usage['threshold_tokens'] = getattr(_cc, 'threshold_tokens', 0) or 0
|
||||
usage['last_prompt_tokens'] = getattr(_cc, 'last_prompt_tokens', 0) or 0
|
||||
put('done', {'session': s.compact() | {'messages': s.messages, 'tool_calls': tool_calls}, 'usage': usage})
|
||||
finally:
|
||||
if old_cwd is None: os.environ.pop('TERMINAL_CWD', None)
|
||||
|
||||
Reference in New Issue
Block a user