Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
All notable changes to this project are documented in this file.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]
## [0.5.1] - 2026-11-05

### Changed

Expand Down Expand Up @@ -65,6 +65,18 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- 连带修掉一处会重复计费的隐患:`watermark` 领先于持久化事件数时,原来会被当成「日志变短」
而把整段日志从头重折 —— 重试过的 attempt 会因此被重复计费。现在用「本进程见过的最大
持久化事件数」(`state.persistedCounts`)判断是否真的变短,落后的日志只从水位继续读。
- **设置页导航图标改用官方 `settings.section.icon`**(0.2.2-rc.1 新增:list / inline / root,
由 `@deepseek-ai/dsh-client-ui-settings-general` 的 nav rows 以 `{size, active}` +
`only: row.id` 渲染):注册 id 必须等于 section id(`token-stats`),对不上的 id
**永不渲染、也不报错**。删掉 0.2.1 时代的 DOM 补缺(属性标记 + CSS mask + MutationObserver)——
那正是它自己注释里约定「官方补上就整体删除」的 L2,现在不再碰 React 管理的节点。
**旧内核没有这个槽时 inject 不触发,行内图标退化成官方齿轮,其余一切不变。**
- `@deepseek-ai/cordis`(peer + dev)`~4.0.5` → `~4.1.0`;`@deepseek-ai/schemastery`
`~3.18.5` → `~3.19.0`,与 0.2.2-rc.1 宿主自带的版本一致。
- `dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-settings-general`:图标槽归该模块所有,
静态 bundle 只有声明了才能在运行时拿到它。
- `dsh.verifiedAgainst`:`0.2.1-rc.4` → `0.2.2-rc.1`。`engines.dsh` 不变 ——
0.2.2-rc.1 仍落在 `>=0.2.1-rc.3 <0.3.0` 内(DSH 用 `includePrerelease: true` 判定)。

### Tests

Expand All @@ -84,35 +96,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- 232 → **234**:`tests/scan.test.js` 换成推送路径的门(事件折叠、fork 前缀不重复计费、
重复投递不重复计费、坏事件不抛、落后的持久化日志只从水位续读、真变短的日志才从头重折);
`tests/native-hygiene.test.js` 钉住 `apply` 必须订阅 `session/event` 且不得再出现 `scanLive`。
## [0.4.0] - 2026-10-24

输入区成本 pill:把「今天花了多少」搬到 composer 旁边,并对齐 DSH 0.2.1 的 dock 契约。

### Added

- **输入区成本 pill**(`conversation.composer.dock`,id `usage-cost`,order 2):显示今日
参考成本,今日无调用时不占位;title 里带调用次数与 Token。宿主自己的 `usage` pill
显示的是 token 数(读官方 `tokenUsage` 投影),两者互补。
- 复用了设置页同一条 `usage/query` 通道,**按记录里的 provider/model 精确计价**,没有
用官方投影算钱:投影只有会话内合计、不带模型归因,用它计价会把不同单价混成一个数
(正是 v0.3 修掉的问题类)。
- 口径是「今日」而不是「本会话」:宿主渲染这个 slot 时是
`renderSlot("conversation.composer.dock", {})`,dock 条目拿不到会话标识。
- 币种跟随设置页的 ¥/$ 选择(读宿主动态解析的 `currency.symbol`,不写死符号);
回填(backfill)进行中用 3s 快重试,完成后回到 30s 轮询;页面重新可见时立即刷新。

### Changed
- 234 → **238**。新增 `tests/client-settings-icon.test.js`:图标注册 id 必须等于 section id、
旧 DOM 补缺必须删净(留一条就是同一行画两个字形)、图标按 `size` 渲染且只用 `currentColor`、
`dsh.client.inject` 必须声明槽位归属模块。

- **`dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-conversation`**:dock slot 归该模块
所有,静态 bundle 只有声明了才能在运行时拿到它。
- 兼容性:`engines.dsh` 仍是 `>=0.2.0-rc.2 <0.3.0`;0.2.0 没有这个 slot,注入失败只
告警、不影响设置页(`try/catch` 包住)。
### Verified

### Tests
- 0.2.2-rc.1 上 `npm test` 全绿(238)、`verify:typert`(4 端点)与 `verify:remote`(7/7)通过。
- 与 0.2.1-rc.4 逐文件比对:会话持久化 `list()` / `read(offset, length, options)` 签名未变,
`tokenUsage` 投影字段未变(只有 `contextPressure` 多了 `summary: false`),
`settings.section` / `conversation.composer.dock` 槽位契约未变。

- 83 → **87**。新增 `tests/client-dock.test.js`:dock 注册契约(slot 名 / id / order)、
不再注册旧 `stats` 行 ID、`dsh.client.inject` 必须声明 slot 归属模块、pill 的币种符号
必须来自宿主动态解析(防止 USD 视图印出 ¥)。
## [0.5.0] - 2026-10-31

基于 0.4.0(输入区成本 pill)发布;`0.4.1`–`0.4.8` 以及本地标注为 `0.4.0` 的定价改造都是
Expand Down Expand Up @@ -171,6 +165,35 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
`npm run verify:typert`(官方 loader 校验 4 个端点)与 `npm run verify:remote`(7 项)为原生契约门。


## [0.4.0] - 2026-10-24

输入区成本 pill:把「今天花了多少」搬到 composer 旁边,并对齐 DSH 0.2.1 的 dock 契约。

### Added

- **输入区成本 pill**(`conversation.composer.dock`,id `usage-cost`,order 2):显示今日
参考成本,今日无调用时不占位;title 里带调用次数与 Token。宿主自己的 `usage` pill
显示的是 token 数(读官方 `tokenUsage` 投影),两者互补。
- 复用了设置页同一条 `usage/query` 通道,**按记录里的 provider/model 精确计价**,没有
用官方投影算钱:投影只有会话内合计、不带模型归因,用它计价会把不同单价混成一个数
(正是 v0.3 修掉的问题类)。
- 口径是「今日」而不是「本会话」:宿主渲染这个 slot 时是
`renderSlot("conversation.composer.dock", {})`,dock 条目拿不到会话标识。
- 币种跟随设置页的 ¥/$ 选择(读宿主动态解析的 `currency.symbol`,不写死符号);
回填(backfill)进行中用 3s 快重试,完成后回到 30s 轮询;页面重新可见时立即刷新。

### Changed

- **`dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-conversation`**:dock slot 归该模块
所有,静态 bundle 只有声明了才能在运行时拿到它。
- 兼容性:`engines.dsh` 仍是 `>=0.2.0-rc.2 <0.3.0`;0.2.0 没有这个 slot,注入失败只
告警、不影响设置页(`try/catch` 包住)。

### Tests

- 83 → **87**。新增 `tests/client-dock.test.js`:dock 注册契约(slot 名 / id / order)、
不再注册旧 `stats` 行 ID、`dsh.client.inject` 必须声明 slot 归属模块、pill 的币种符号
必须来自宿主动态解析(防止 USD 视图印出 ¥)。
## [0.3.0] - 2026-10-19

设置页仪表盘的可用性与观感版本:修掉两处「看着正常其实不能用」的交互,补上
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ id 只要表里有这一行就是精确、按它自己的价(促销期就是 0

## 兼容性

- DSH `>=0.2.1-rc.3 <0.3.0`(`engines.dsh`;在 `0.2.1-rc.4` 上验证过两个原生契约门),Node ≥ 22
- DSH `>=0.2.1-rc.3 <0.3.0`(`engines.dsh`;在 `0.2.2-rc.1` 上验证过两个原生契约门与 228 项单测),Node ≥ 22
- 设置页导航图标走官方 `settings.section.icon`(0.2.2-rc.1 新增):注册 id 必须等于 section id(`token-stats`);
更早的内核没有这个槽,行内图标退化成官方齿轮,其余功能不变
- 输入区成本 pill 依赖 0.2.1 的 `conversation.composer.dock`:0.2.0 没有这个 slot,注入失败只告警,不影响设置页
- 更早的宿主保留 `Session.events` / `readFrom` 回退路径

Expand Down
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dsh-plugin-usage",
"description": "Token usage statistics for DeepSeek Harness — daily/custom-range views, model filters, call counts and cost, inspired by CC Switch statistics.",
"version": "0.5.0",
"version": "0.5.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -46,7 +46,7 @@
},
"dsh": {
"manifestVersion": 1,
"verifiedAgainst": "0.2.1-rc.4",
"verifiedAgainst": "0.2.2-rc.1",
"bundle": {
"patch": "./cordis.patch.yml"
},
Expand All @@ -55,19 +55,20 @@
"@deepseek-ai/dsh-client-runtime",
"@deepseek-ai/dsh-client-ui-settings",
"@deepseek-ai/dsh-client-locale",
"@deepseek-ai/dsh-client-ui-conversation"
"@deepseek-ai/dsh-client-ui-conversation",
"@deepseek-ai/dsh-client-ui-settings-general"
],
"platform": "web"
}
},
"dependencies": {
"@deepseek-ai/schemastery": "~3.18.5"
"@deepseek-ai/schemastery": "~3.19.0"
},
"peerDependencies": {
"@deepseek-ai/cordis": "~4.0.5"
"@deepseek-ai/cordis": "~4.1.0"
},
"devDependencies": {
"@deepseek-ai/cordis": "~4.0.5",
"@deepseek-ai/cordis": "~4.1.0",
"@types/react": "~18.3.1",
"react": "^18.2.0",
"typescript": "^5.5.0"
Expand Down
107 changes: 29 additions & 78 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4412,86 +4412,27 @@ function StatsDashboard(props) {
}

/* ---------------------------------------------------------------------------
* 设置页导航图标
* 设置页导航图标(官方槽位)
*
* 原生确实没有这个插口 —— 取证过的,不是"我觉得":
* · 官方设置页把 `settings.section` 的条目投影成 `{id, order, label}` 三字段,
* 没有 icon(`@deepseek-ai/dsh-client-ui-settings-general` 的 nav rows
* getSnapshot:`ctx.slots.entries("settings.section").map(e => ({id, order,
* label: resolveSlotLabel(e.options.label)}))`);
* · 图标由该包自己的 `navIcon(id)` 按 id 白名单选,未列出的 id 回落到设置齿轮
* (同包 `function navIcon(id)`,其注释原文 "unknown ids fall back to the
* settings gear")。
* 所以第三方只能给自己的那一行打属性标记、用 CSS mask 换字形:不替换节点、不碰
* React 管的 svg(替换会让 React 卸载时抛 NotFoundError),只加属性、只用 ::before
* 画字形。官方一旦给 `settings.section` 加上 icon 字段,这个模块应整体删除 ——
* 那时它是可引用的 L0,不该再留 L2 补缺。
* DSH 0.2.2-rc.1 起,设置页自带 `settings.section.icon`(list / inline / root,
* 声明在 `@deepseek-ai/dsh-client-ui-settings-general` 的 slots 契约里):nav rows
* 用 `renderSlot("settings.section.icon", { size, active }, { only: row.id })`
* 渲染,**注册 id 必须等于目标 section 的 id**,对不上的 id 永不渲染,没有注册的
* id 回落到官方齿轮。
*
* 认行只能按可见文本:类名是 CSS Modules 哈希,账号行还会条件出现。
* 官方一旦给 settings.section 加上 icon 字段,这个模块应整体删除。
* 0.2.1 及更早没有这个槽位,本插件用「属性标记 + CSS mask」改字形(DOM 补缺);
* 官方补上后按当时的约定整体删除 —— 它现在是可以引用的 L0,不该再留 L2。
* 旧内核没有这个槽时 inject 不触发,行内图标退化成齿轮,其余一切不变。
* ------------------------------------------------------------------------- */
const NAV_ICON_MASK = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">'
+ '<rect x="2.5" y="9" width="2.5" height="5" rx="1"/>'
+ '<rect x="6.75" y="5.5" width="2.5" height="8.5" rx="1"/>'
+ '<rect x="11" y="2.5" width="2.5" height="11.5" rx="1"/></svg>',
)
// mask 只读 alpha 通道,所以字形必须是纯色实心(icon.svg 的渐变与半透明在这里会丢)
const NAV_ICON_CSS = [
'[data-tsd-nav] > svg { display: none; }',
'[data-tsd-nav]::before {',
" content: '';",
' flex: none;',
' width: 16px;',
' height: 16px;',
' background: currentColor;',
' -webkit-mask-image: url("' + NAV_ICON_MASK + '");',
' mask-image: url("' + NAV_ICON_MASK + '");',
' -webkit-mask-size: 16px 16px;',
' mask-size: 16px 16px;',
' -webkit-mask-repeat: no-repeat;',
' mask-repeat: no-repeat;',
'}',
].join('\n')

/** 认不出行、拿不到 DOM,都只是退化成齿轮,绝不抛出。返回 disposer。 */
function installSettingsNavIcon(label) {
if (typeof document === 'undefined' || typeof MutationObserver !== 'function') return null
let styleEl = null
try {
styleEl = document.createElement('style')
styleEl.setAttribute('data-plugin', 'dsh-plugin-usage')
styleEl.textContent = NAV_ICON_CSS
document.head.appendChild(styleEl)
} catch (e) {
logWarn('[usage] settings nav icon: styles unavailable')
return null
}
const mark = () => {
const rows = document.querySelectorAll('[role="dialog"] button')
const want = label()
for (let i = 0; i < rows.length; i++) {
const row = rows[i]
if (row.getAttribute('data-tsd-nav') !== null) continue
if (!row.querySelector('svg')) continue // 只标带图标的导航行,别误标普通按钮
if ((row.textContent || '').trim() !== want) continue
row.setAttribute('data-tsd-nav', '')
}
}
let observer = null
try {
mark()
observer = new MutationObserver(() => { try { mark() } catch (e) {} })
observer.observe(document.body, { childList: true, subtree: true })
} catch (e) {
logWarn('[usage] settings nav icon: observer unavailable', e)
}
return () => {
if (observer) observer.disconnect()
if (styleEl) styleEl.remove()
const marked = document.querySelectorAll('[data-tsd-nav]')
for (let i = 0; i < marked.length; i++) marked[i].removeAttribute('data-tsd-nav')
}
function SettingsNavIcon(props) {
const size = props && typeof props.size === 'number' ? props.size : 16
return h('svg', {
width: size, height: size, viewBox: '0 0 16 16',
'aria-hidden': 'true', focusable: 'false',
},
h('rect', { x: 2.5, y: 9, width: 2.5, height: 5, rx: 1, fill: 'currentColor' }),
h('rect', { x: 6.75, y: 5.5, width: 2.5, height: 8.5, rx: 1, fill: 'currentColor' }),
h('rect', { x: 11, y: 2.5, width: 2.5, height: 11.5, rx: 1, fill: 'currentColor' }))
}

/* ---------------------------------------------------------------------------
Expand Down Expand Up @@ -4608,7 +4549,6 @@ function apply(ctx) {
}, 'usage: styles')
ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'usage: dictionaries')
const t0 = ctx.locale ? ctx.locale.bind(NS) : fallbackT
ctx.effect(() => installSettingsNavIcon(() => t0('nav')), 'usage: nav-icon')
// cordis ctx is a strict proxy: DIRECT property access on an un-injected
// service throws ("cannot get property X without inject"), so a bare
// `ctx.slots ?? ...` would throw and skip the fallback. Probe via the safe
Expand Down Expand Up @@ -4636,6 +4576,17 @@ function apply(ctx) {
(props) => h(StatsDashboard, props),
))

// 导航图标:官方 0.2.2-rc.1 的 settings.section.icon,按 section id 对齐。
// 旧内核没有这个槽,inject 不触发(退化成官方齿轮),不能拖垮设置页。
try {
slots.inject('settings.section.icon', () => slots.register(
{ name: 'settings.section.icon', id: 'token-stats', order: 0, locale: NS },
(props) => h(SettingsNavIcon, props),
))
} catch (e) {
console.warn('[usage] settings nav icon slot unavailable', e)
}

// 输入区成本 pill。0.2.1 的 composer dock 是 list slot,宿主自己占了 activity(0)
// 与 usage(1),插件排在它们之后;0.2.0 没有这个 slot,注入失败不能拖垮设置页。
try {
Expand Down
Loading
Loading