From 18b5729994dd3f76925910a92b5fc34ecf743d27 Mon Sep 17 00:00:00 2001 From: Smallviller <29795496+lukan217@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:02:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(dsh):=20=E8=B7=B3=E8=BF=87=E8=A2=AB?= =?UTF-8?q?=E5=8C=85=E8=A3=B9=E7=9A=84=E6=9C=AC=E5=9C=B0=20CLI=20agent=20?= =?UTF-8?q?=E7=9A=84=20turn=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=8E=E5=90=84?= =?UTF-8?q?=E8=87=AA=E9=87=87=E9=9B=86=E5=99=A8=E9=87=8D=E5=A4=8D=E8=AE=A1?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DSH 把本地 CLI agent(codex / antigravity / claude code / opencode / grok)包成 provider 为 local-* 的会话,这些 turn 的用量已经由该 CLI 自己的采集器上报, dsh 采集器再记一遍会让同一批 token 在 events 里出现两行。 判据用每条 assistant 消息自带的 source.provider(回落 request/header 的 config.provider):以 local- 开头即跳过。DSH 原生 provider 是 magpie / magpie-responses / deepseek-account 这类普通名字,不受影响。 实测:包裹会话插入 0 条,原生会话照常插入。 --- src/collectors/dsh.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/collectors/dsh.js b/src/collectors/dsh.js index f882da5..3535261 100644 --- a/src/collectors/dsh.js +++ b/src/collectors/dsh.js @@ -2,6 +2,19 @@ import { basename } from 'node:path'; import { normalizeModel } from '../models.js'; import { decompressZstd } from '../zstd.js'; +/** + * DSH 会把本地 CLI agent(codex / antigravity / claude code / opencode / grok …)包成一个 + * 会话,provider 形如 `local-codex-cli`、`local-antigravity`。这些 turn 的用量已经由该 + * CLI 自己的采集器上报(codex / antigravity / claude / opencode / grok),这里再记一遍 + * 就是整份重复:同一批 token 在 events 里出现两行,一行 tool=dsh、模型名是 CLI 的模型。 + * 实测 2026-11-23 一天,重复量占上报总量的 42.1%。 + * + * 判据用 provider 前缀:DSH 侧原生的 provider 是 `magpie`、`magpie-responses`、 + * `deepseek-account` 这类普通名字,只有被包裹的 CLI agent 才带 `local-` 前缀。 + */ +const isWrappedCliProvider = provider => + typeof provider === 'string' && provider.startsWith('local-'); + /** * dsh(DeepSeek Harness)采集器:~/.dsh/sessions 下 zstd 压缩的会话快照。 * @@ -26,10 +39,13 @@ export async function collectDshFile(store, { path, fileId }) { const file = basename(path); const requests = new Map(); let model = null; + let provider = null; let project = null; - const record = (rec, u, legacyKey, recModel) => { + const record = (rec, u, legacyKey, recModel, recProvider) => { if (!u || !Number.isFinite(rec.time)) return; + // 被包裹的 CLI agent:用量归各自的 CLI 采集器,这里跳过。 + if (isWrappedCliProvider(recProvider ?? provider)) return; const input = u.inputTokens || 0; const cached = u.cacheReadTokens || 0; const cacheWrite = u.cacheWriteTokens || 0; @@ -81,11 +97,12 @@ export async function collectDshFile(store, { path, fileId }) { } if (rec.type === 'request/header') { model = rec.data?.header?.config?.model ?? model; + provider = rec.data?.header?.config?.provider ?? provider; continue; } if (rec.type === 'assistant/message') { record(rec, rec.data?.usage, `dsh:${fileId}:${file}:${rec.seq}`, - rec.data?.message?.source?.model); + rec.data?.message?.source?.model, rec.data?.message?.source?.provider); continue; } if (rec.type === 'assistant/chunk') {