[Feature] 显示当前会话的上下文窗口占用
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- tauri, typescript
Research direction
Start with the usage_update branch in windows/tauri/src/features/ai/services/acp-stream-handler.ts and the AcpUsageUpdate definition in windows/tauri/src/features/ai/types/acp.types.ts. Then read ai-chat-state.ts and chat-header.tsx to follow the existing session state and PaneChip patterns. Done means the current session shows used/size context usage, warns at the chosen threshold, and clears the value when the session ends or changes.
Written by the indexing model from the issue text.
Description
要解决的问题
使用 AI 会话时,无法知道当前上下文窗口已经用了多少、还剩多少。只能在 agent 自己提示「上下文将满」时才发现,此时往往已经触发压缩或截断,之前的对话内容可能已经丢失。
Lithe 其实已经能拿到这个数据,只是把它丢弃了 —— windows/tauri/src/features/ai/services/acp-stream-handler.ts:382-383:
case "usage_update":
break;
事件载荷 AcpUsageUpdate { used: number; size: number }(windows/tauri/src/features/ai/types/acp.types.ts:132-135)从未进入状态。
建议方案
1. 消费事件
在 acp-stream-handler.ts 的 usage_update 分支中消费事件,把 used / size 写入 AI 状态。
2. 状态放置
建议放在 windows/tauri/src/features/ai/stores/ai-chat/ai-chat-state.ts 中与 acpStatus、sessionModeState 并列。这两个字段已经是「当前活动 agent 会话的运行时状态」,上下文占用属于同一类,跟随现有模式即可。
3. 展示位置:agent 面板的头部
windows/tauri/src/features/ai/components/chat/chat-header.tsx
选择面板头部而不是全局状态栏的理由:
- AI 会话本身是一个 pane,带自己的
sessionId(windows/tauri/src/features/panes/types/pane-content.types.ts:93-96的AgentContent { type: "agent"; sessionId: string }),并且可以多开。放在 pane 头部能天然跟随对应会话,不会串到别的会话。 - 全局 footer 是单例,当前承载文件编码、内存占用、Git 分支、调试器状态。多开 agent 面板时,footer 无法表达「这是哪个会话的占用」,会引入歧义。
chat-header.tsx已经在用PaneChip/paneHeaderClassName(features/panes/components/pane-chrome),加一个 chip 就能融入现有模式,基本不需要新的 UI 结构。
4. 展示形式
紧凑的百分比 chip;悬浮或展开时显示 used / size 的实际数值。占用超过阈值(例如 80%)时变色提示,让用户在触发压缩前主动收敛话题或开新会话。
5. 生命周期
会话结束或切换时清理该状态,避免残留到另一个会话。
目标平台
Windows
模块
AI
优先级
P1 / 尽快处理:使用体验大幅下降,但通常仍可继续使用
已考虑的替代方案
- 依赖 agent 自己输出的提示文本:无法量化剩余空间,且提示出现时往往已经太晚。
- 放在全局状态栏 footer:多开 agent 面板时无法区分是哪个会话,见上文理由。
补充信息
- 被丢弃的位置:
windows/tauri/src/features/ai/services/acp-stream-handler.ts:382-383 - 事件类型定义:
windows/tauri/src/features/ai/types/acp.types.ts:132-135、:253-257 - 同位置的
session_info_update(:385)同样被break丢弃,但会话标题已经由ui_action.set_chat_title(:465-472)处理,本次不需要一并改动,避免扩大范围。 - 分层:本改动全部落在
windows/tauri/src/features/ai/,不涉及平台层与rust/lithe-core/。若后续 macOS 端需要对齐,再考虑把窗口归一化逻辑下沉到rust/lithe-core/并补shared/contracts/fixture。 - 该事件仅提供上下文占用,不包含历史 Token 汇总与费用统计,后者如需做应另开 issue。
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 151
- Avg merge
- 7h 51m
- Merged PRs (30d)
- 351
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 1lck/Lithe-IDEA
-
area:editor bug P0 platform:macos review: low
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
1lck/Lithe-IDEA#1118 · 2 comments ·
Maintainers usually reply within 1 day
-
area:editor issue-form:feature P1 platform:windows review: low
Difficulty 3/5 1-2 days Newbie friendliness 52/100
1lck/Lithe-IDEA#1129 ·
Maintainers usually reply within 1 day
-
area:editor issue-form:feature P1 platform:windows review: low
Difficulty 4/5 3-5 days Newbie friendliness 48/100
1lck/Lithe-IDEA#1128 ·
Maintainers usually reply within 1 day
-
[Feature] 修复commit区按钮、弹窗、下拉框样式Possibly taken @arkleselect claimed this today. Openarea:ui enhancement issue-form:feature P1 platform:macos review: medium
1lck/Lithe-IDEA#1125 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Bug] Windows 版本对比重复显示相同内容Possibly taken @puppyben1 claimed this today. Openarea:git bug P0 platform:windows review: low
Difficulty 3/5 1-2 days Newbie friendliness 38/100
1lck/Lithe-IDEA#1123 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
[bug] diagnostics.dumpBody:Buffer 形态请求(透传 lane)跳过 dumps/ 落盘,仅留 raw/-unknown-Possibly taken @ranxianglei claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ranxianglei/billion-context#2421 · 2 comments ·
Maintainers usually reply within 1 day
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
nuxt/test-utils#1842 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MoonshotAI/kimi-code#4146 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
farbenmeer/tapi#531 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day