Skip to content

feat(context-visualizer): add context occupancy analytics plugin - #380

Open
hangtian wants to merge 1 commit into
zai-org:mainfrom
hangtian:feat/context-visualizer
Open

hangtian wants to merge 1 commit into
zai-org:mainfrom
hangtian:feat/context-visualizer

Conversation

@hangtian

@hangtian hangtian commented Dec 3, 2026

Copy link
Copy Markdown

Plugin type (required) / 插件类型(必填)

Select exactly one before requesting review. / 发起评审前必须且只能勾选一项。

  • UI Plugin / 是 UI 插件 — provides MCP Apps interactive pages / 提供 MCP Apps 交互页面
  • Standard plugin / 普通插件(非 UI) — does not provide MCP Apps interactive pages / 不提供 MCP Apps 交互页面
  • Not applicable / 不适用 — repository-only changes; no plugin content changed / 仅仓库级改动,不涉及插件内容

Affected plugin name(s) / 涉及的插件名称:

context-visualizer

Classify the affected plugin, even when only changing its docs or skills. Adding or removing an interactive page also counts as a UI Plugin change. For multiple plugins, list each name and type; select UI Plugin if any is affected.

按涉及的插件判断,即使本次只改它的文档或 skill 也须声明类型。新增或移除交互页面也属于 UI Plugin 改动。涉及多个插件时分别列出名称和类型,只要包含 UI Plugin 就选择 UI Plugin。

ui.surfaces panels and tool-result pages using _meta.ui.resourceUri both count. An MCP server or a skill that generates Gen UI alone does not. This declaration is separate from marketplace category.

ui.surfaces 面板和通过 _meta.ui.resourceUri 展示的工具结果页面都算 UI Plugin。仅有 MCP server 或生成 Gen UI 的 skill 不算。这项声明与市场 category 分类独立。

What / 改动内容

新增 context-visualizer 插件:分析 ZCode 会话的 model-io 日志与本地使用统计库,回答「上下文窗口被什么占用 / 哪些工具从没被调用却占着定义 / 该停用哪个插件 / 装一个插件值多少 token」。

  • 侧栏常驻按钮(nav.primary 插槽,target: surface)一键打开 MCP Apps 交互面板;默认显示跨会话总排行
  • 总排行:全部会话(本地使用统计库 ~/.zcode/cli/db/db.sqlite,含日志已轮转的会话)按真实 usage 排名;工具细分按存活日志聚合,并标注覆盖范围
  • 零调用工具清单:按调用身份(toolCallId)去重后的真实调用计数,定义税照付却从未调用的工具按开销排序、标注来源(内置/插件/MCP)与停用收益
  • 插件停用建议:使用次数 × 定义开销综合排名(推荐停用 / 使用中 / 影响极小 / 内置),直接给出停用后每请求可省 tokens
  • 插件安装成本预览:安装前拉起目标插件的 MCP server 枚举工具 schema 估算每请求开销
  • 窗口自动检测:读取内置 modelConfigRules 按序合并(GLM-5.3 → 1M、glm-5 → 200k 等),无法识别回退 200k 并标注
  • 数据与隐私:纯本地读取(rollout 日志 + db.sqlite),零网络请求;面板数据经资源通道加载,不进入模型上下文

Self-check 附加说明:

  • 面板资源 ui://context-visualizer/panel.html 约 700KB(< 16MiB),全内联、无外链、无 fetch/XHR/WebSocket,默认 CSP 即可运行
  • 构建产物(mcp/server.mjs esbuild bundle、ui/panel.html)随包提交,运行时零依赖;npm install && node build.mjs 可复现
  • python3 scripts/validate.py 与 python3 scripts/build_dist.py 已在本地最小装配中实测通过(validate: OK 1 plugin validated;build_dist: 生成 0.6.3/plugin.zip 469KB)

Self-check / 自查清单

  • Plugin name is unique kebab-case; new external plugin directory is external_plugins/<name>/; existing fixes retain ownership / 插件名唯一且 kebab-case,外部新增插件位于 external_plugins/<name>/,已有插件修复保留原归属
  • Usage category is set independently of publisher ownership / 用途分类 category 已填写,与维护归属分开
  • Plugin type and affected names are declared above / 已在上方声明插件类型与涉及的插件名称
  • version bumped in BOTH plugin.json and marketplace.json (artifacts are immutable) / plugin.json 与 marketplace.json 两处版本号已同步升级(制品不可变)
  • README.md (EN) and README_CN.md (中文) both updated and equivalent / 中英文 README 均已更新且语义一致
  • description_i18n has both en and zh-CN / description_i18n 包含 en 与 zh-CN
  • No secrets, machine-specific paths, or private dependencies / 不含密钥、机器专属路径或私有依赖
  • Model/API/network dependencies documented / 模型、API、网络依赖已写明
  • python3 scripts/validate.py and python3 scripts/build_dist.py pass locally / 本地校验与构建均通过

@panda920

panda920 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

✅ Internal validation passed. A ZCode maintainer will review the change next; after acceptance, release checks run separately and this PR is closed automatically.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants