Skip to content

feat(session-stats): add session statistics plugin - #147

Open
huantest2024 wants to merge 13 commits into
zai-org:mainfrom
huantest2024:main
Open

huantest2024 wants to merge 13 commits into
zai-org:mainfrom
huantest2024:main

Conversation

@huantest2024

@huantest2024 huantest2024 commented Oct 31, 2026 •

Copy link
Copy Markdown

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

  • UI Plugin / 是 UI 插件 — provides MCP Apps interactive pages(ui.surfaces 会话侧栏面板)
  • Standard plugin / 普通插件(非 UI)
  • Not applicable / 不适用

Affected plugin name(s) / 涉及插件:session-stats

What / 改动内容

Adds a new community plugin session-stats (v0.2.7) under external_plugins/:
session statistics for ZCode — turns/steps, model vs tool time, TTFT, TPS (average +
latest-request), token usage, cache hit ratio and per-model breakdown. Components:
MCP tool get_stats + MCP Apps side panel (ui.surfaces) + /stats command +
SessionStart hook. Source of truth: https://github.com/huantest2024/zcode-session-stats

Why / 解决什么问题

ZCode 的用量事实已经在本地会话数据库里(model_usage / turn_usage / tool_usage,
含 time_to_first_token_ms 与四类 token 计数),缺的只是面向用户的呈现层。本插件
零第三方依赖(stdio MCP 服务器为 Python 标准库实现),只读打开数据库,不写任何宿主状态。

How tested / 如何验证

  • MCP 握手/工具冒烟;统计数字与同一 db 的手工 SQL 逐项对账一致(轮次/步数/token/缓存命中)。
  • 侧栏面板渲染、5 秒轮询、会话切换跟随(DOM data-session-id + SessionStart hook,
    线上实测 session_source=hook 链路成立)。
  • 只读打开(mode=ro + busy_timeout)与 WAL 并发读实测无锁冲突。
  • 本地按 scripts/validate.py 的规则自检:kebab-case、source 路径约定、manifest↔marketplace
    版本/描述一致、ui.surfaces 各项(id/server/resourceUri/availability)、i18n en+zh、无符号链接。

Version / 版本与登记

  • 插件 manifest 与根 marketplace.json 条目均为 0.2.7,source 为
    ./external_plugins/session-stats(社区插件约定路径)。
  • server/pills.js 是面板/输入条统计组件的动态下发副本,随插件版本走。

Dependencies & side effects / 依赖与副作用

  • Python 3.10+ 标准库,无 pip 依赖;无网络访问、无凭证、无遥测。
  • 只读打开 ~/.zcode/cli/db/db.sqlite(mode=ro + busy_timeout,WAL 并发安全)。
  • 本地回环 HTTP 服务 127.0.0.1:31710:向 ZCode 渲染层(file:// 页面)提供统计 JSON
    与面板脚本,仅响应无跨域 Origin 的请求,其余 403。
  • SessionStart hook 在插件数据目录写一个小文件(current_session)。
  • README(EN/CN)均已按「副作用说明」如实描述以上内容。

License / 许可

MIT;无第三方代码/资源引入。

@panda920

Copy link
Copy Markdown
Collaborator

❌ Internal validation failed:

FAIL: 1 problem(s)
  - marketplace.json plugins[0] (session-stats): plugin.json description_i18n does not match marketplace entry

Please fix it and push again; the check re-runs automatically.

🤖 Copy this prompt into Claude Code / Codex to fix it
You are updating my pull request #147 to github.com/zai-org/zcode-plugins (the ZCode plugin marketplace).
The maintainers' automated intake reported: `python scripts/validate.py` failed

Validator output:
FAIL: 1 problem(s)
  - marketplace.json plugins[0] (session-stats): plugin.json description_i18n does not match marketplace entry

Fix it in this repository:
- New external plugins belong under external_plugins/<my-plugin>/; keep existing plugins in their current directory;
  never modify .github/, scripts/, tests/, .gitignore, .gitattributes or AGENTS.md.
- Follow CONTRIBUTING.md and AGENTS.md: the manifest lives at <plugin-directory>/.zcode-plugin/plugin.json,
  its name/version must match marketplace.json, names are kebab-case, keep the required i18n fields.
- Fetch the latest main of zai-org/zcode-plugins and rebase onto it; if marketplace.json conflicts,
  keep every existing entry and re-add mine.
- Run `python scripts/validate.py` until it passes, then force-push my PR branch.

@panda920

Copy link
Copy Markdown
Collaborator

❌ Internal validation failed:

FAIL: 1 problem(s)
  - marketplace.json plugins[0] (session-stats): plugin.json description_i18n does not match marketplace entry

Please fix it and push again; the check re-runs automatically.

🤖 Copy this prompt into Claude Code / Codex to fix it
You are updating my pull request #147 to github.com/zai-org/zcode-plugins (the ZCode plugin marketplace).
The maintainers' automated intake reported: `python scripts/validate.py` failed

Validator output:
FAIL: 1 problem(s)
  - marketplace.json plugins[0] (session-stats): plugin.json description_i18n does not match marketplace entry

Fix it in this repository:
- New external plugins belong under external_plugins/<my-plugin>/; keep existing plugins in their current directory;
  never modify .github/, scripts/, tests/, .gitignore, .gitattributes or AGENTS.md.
- Follow CONTRIBUTING.md and AGENTS.md: the manifest lives at <plugin-directory>/.zcode-plugin/plugin.json,
  its name/version must match marketplace.json, names are kebab-case, keep the required i18n fields.
- Fetch the latest main of zai-org/zcode-plugins and rebase onto it; if marketplace.json conflicts,
  keep every existing entry and re-add mine.
- Run `python scripts/validate.py` until it passes, then force-push my PR branch.

@panda920

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.

@panda920

panda920 commented Nov 1, 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.

@panda920

panda920 commented Nov 1, 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.

@panda920

panda920 commented Nov 1, 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.

@panda920

panda920 commented Nov 2, 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.

@panda920

panda920 commented Nov 2, 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