conversation-monitor
by LEFTX1
README.md
<div align="center">
<img src="assets/logo.svg" width="84" height="84" alt="Antigravity 对话状态监控 Logo" />
# Antigravity 对话状态监控 (`conversation-monitor`)
**轻量、专注的 Google Antigravity 对话运行与异常中断状态监控插件(MCP App)**
**Lightweight status monitor for Google Antigravity: auto-pins running chats with `🟢` and marks quota/network interruptions with `🟡` (auto-clears on resume).**
[](https://github.com/LEFTX1/antigravity-conversation-monitor)
[](https://modelcontextprotocol.io)
[](pyproject.toml)
[](#privacy--security)
[](LICENSE)
</div>
---
## 一键安装 / One-Line Install
### Antigravity CLI (`agy`)
```bash
agy plugin install https://github.com/LEFTX1/antigravity-conversation-monitor
python -m pip install mcp
```
### Windows (PowerShell)
```powershell
irm https://raw.githubusercontent.com/LEFTX1/antigravity-conversation-monitor/main/install.ps1 | iex
```
### macOS / Linux (Bash)
```bash
curl -fsSL https://raw.githubusercontent.com/LEFTX1/antigravity-conversation-monitor/main/install.sh | bash
```
> 安装脚本会自动将插件安装至 `~/.gemini/config/plugins/conversation-monitor`,自动检测并安装 `mcp>=1.2.0` 依赖,且升级覆盖时保留原有本地状态数据。安装后重启 Antigravity(或在 **Customizations > Installed** 开关重载插件)即可生效。
---
## 核心特性 / Key Features
- **运行中自动置顶与 `🟢` 状态标**:对话处于 `RUN_STATE_RUNNING` 时自动置顶到左侧栏顶部并加 `🟢 ` 前缀;运行结束后自动取消自动置顶并还原原标题(绝不覆盖用户手动置顶)。
- **额度 / 网络中断 `🟡` 标记**:当任务因配额耗尽(`RESOURCE_EXHAUSTED`、`429`、`503`、`MAX_TOKEN_BUDGET_EXCEEDED` 等)或网络/流异常(`EOF`、`timeout`、`wsarecv`、`500`/`502`、`stream was interrupted` 等)中断时,自动在标题旁打上黄色圆点 `🟡`。
- **支持左侧 / 右侧自由切换**:可在交互面板或通过 MCP 工具将 `🟡` 位置切换为左侧(`🟡 标题`,默认)或右侧(`标题 🟡`),立即同步至左侧栏。
- **重新运行自动消失**:中断的对话一旦重新开始运行,`🟡` 会立即自动移除并切换为 `🟢`(正常结束后恢复干净标题);也支持手动一键清除单个或全部 `🟡`。
- **零冗余、极简专注**:无任何 Token/上下文全量扫描、无桌面弹窗打扰;彻底忽略子代理(Subagent)会话与用户主动取消(`USER_CANCELED` / `RUN_STATE_CANCELLING`)。
---
## 状态流转机制 / Status Lifecycle
```mermaid
stateDiagram-v2
[*] --> Idle: 新建/空闲对话
Idle --> Running: "SessionStart / PreInvocation / RUN_STATE_RUNNING"
Running --> Idle: "Stop (正常完成 / USER_CANCELED)"
Running --> Interrupted: "Stop (额度耗尽 / 网络中断 / 流异常)"
Interrupted --> Running: "重新运行 (🟡 立即消失 → 🟢)"
Interrupted --> Idle: "手动 clear_interrupted / restore_all"
note right of Running: "自动置顶 + 🟢 标题标"
note right of Interrupted: "取消自动置顶 + 左/右侧 🟡 标"
note right of Idle: "恢复原标题,保留手动置顶"
```
---
## 可用 MCP 工具 / MCP Tools (`conversation-monitor_status`)
| 工具名 | 说明 |
| :--- | :--- |
| `open_conversation_monitor` | 打开「对话状态监控」交互式面板(支持右侧辅助栏与全局视图) |
| `sync_now` | 立即扫描并同步全部对话的置顶、`🟢` 运行标与 `🟡` 中断标 |
| `set_monitor_config` | 配置 `auto_pin`、`title_badge`、`interrupted_badge` 及 `interrupted_badge_pos`(`left` / `right`) |
| `clear_interrupted` | 清除指定对话(传入 `conversation_id`)或全部对话的 `🟡` 中断标记 |
| `restore_all` | 还原所有由本插件管理的自动置顶并清除全部 `🟢`/`🟡` 标题标识 |
---
## 配置项说明 / Configuration
| 配置键 | 类型 | 默认值 | 说明 |
| :--- | :--- | :--- | :--- |
| `auto_pin` | `bool` | `true` | 运行中是否自动置顶到左侧栏顶部 |
| `title_badge` | `bool` | `true` | 运行中是否在标题前加 `🟢 ` |
| `interrupted_badge` | `bool` | `true` | 额度/网络中断时是否显示 `🟡` |
| `interrupted_badge_pos` | `"left" \| "right"` | `"left"` | `🟡` 显示在标题左侧(`🟡 标题`)还是右侧(`标题 🟡`) |
| `poll_interval` | `float` | `2.5` | 后台轮询兜底间隔(秒,最小 `2.0`) |
---
## 项目结构 / Project Architecture
```text
conversation-monitor/
├── plugin.json # Antigravity 原生插件清单
├── mcp_config.json # MCP stdio 服务配置
├── hooks.json # SessionStart / PreInvocation / Stop 生命周期钩子
├── pyproject.toml # Python 项目元数据与 Ruff 规范配置
├── requirements.txt # 运行依赖 (mcp>=1.2.0)
├── install.ps1 / install.sh # Windows / macOS / Linux 一键安装脚本
├── assets/
│ └── logo.svg # 插件矢量图标
├── skills/conversation-monitor/
│ └── SKILL.md # Agent Skill 使用说明
├── scripts/
│ ├── sync_status.py # Hook 与 CLI 轻量入口
│ ├── mcp_server.py # FastMCP 服务端与后台同步线程
│ └── monitor/ # 核心业务包
│ ├── __init__.py # 公共 API 导出
│ ├── config.py # 常量、日志轮转、跨平台文件锁与原子状态存储
│ ├── rpc.py # Language Server 自动发现与 Connect RPC 封装
│ ├── classifier.py # 标题徽标解析、额度/网络中断分类与尾部切片读取
│ └── engine.py # 状态同步引擎、快照构建与 Hook 处理
├── ui/
│ └── app.html # 精简交互式 MCP App 面板
└── tests/
├── test_classifier.py # 分类器、徽标与尾部读取单元测试
└── test_engine.py # 完整生命周期与状态迁移单元测试
```
---
## 本地开发与测试 / Development & Testing
```bash
# 运行 Python 单元测试
python -m unittest discover -s tests -v
# 语法编译检查
python -m py_compile scripts/sync_status.py scripts/mcp_server.py scripts/monitor/*.py
# 手动执行一次状态同步或导出快照
python scripts/sync_status.py
python scripts/sync_status.py --snapshot
```
---
## 隐私与安全 / Privacy & Security
- **100% 本地运行**:仅连接本机 Antigravity Language Server 接口,并按需读取本地 `transcript.jsonl` 尾部最后数 KB 片段用于识别中断错误;**不扫描 Token 用量,不上传任何数据到外部服务器**。
- **状态隔离**:运行时状态保存在 Antigravity 的 `${PLUGIN_DATA}`(或本地 `data/` 目录),已被 `.gitignore` 严格排除,不会进入版本库。
---
## 卸载 / Uninstall
在 Antigravity 的 **Customizations > Installed** 中卸载 **对话状态监控 (`conversation-monitor`)**,或先还原状态再删除目录:
```powershell
# Windows
python "$env:USERPROFILE\.gemini\config\plugins\conversation-monitor\scripts\sync_status.py" --restore
Remove-Item -Recurse -Force "$env:USERPROFILE\.gemini\config\plugins\conversation-monitor"
```
```bash
# macOS / Linux
python3 ~/.gemini/config/plugins/conversation-monitor/scripts/sync_status.py --restore
rm -rf ~/.gemini/config/plugins/conversation-monitor
```
---
## License
[MIT](./LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues