deepseek-harness-cost 0.0.0-stage → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jooyan Bagheri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,308 @@
1
- # Temporary Holding Version
1
+ # deepseek-harness-cost
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ![npm version](https://img.shields.io/npm/v/deepseek-harness-cost)
4
+ ![license](https://img.shields.io/npm/l/deepseek-harness-cost)
5
+
6
+ A **chat cost meter for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)**.
7
+ One pill under the composer answers three questions in the currency the chat
8
+ actually spends:
9
+
10
+ 1. **What has this chat cost?** — `¥0.551` on the DeepSeek platform, `$0.0762`
11
+ on OpenCode Go.
12
+ 2. **What is it costing per 1K tokens?** — the realized blended rate, e.g.
13
+ `¥0.0000214/1K` or `$0.00000967/1K`.
14
+ 3. **How much of the subscription allowance is left?** — OpenCode Go only, with
15
+ the 5-hour, weekly and monthly windows and their reset countdowns.
16
+
17
+ A chat that used both providers shows both currencies side by side instead of
18
+ converting one into the other. A chat on a provider with no price card shows no
19
+ money and reports the excluded requests in the panel.
20
+
21
+ ![The chat cost pill under the composer, showing the OpenCode Go allowance windows and the cost of each currency the chat spent](https://raw.githubusercontent.com/JooyanDevs/deepseek-harness-cost/main/docs/preview.png)
22
+
23
+ <sub>Sample values. The pill reads, left to right: allowance windows, then one
24
+ cost reading per currency the chat used.</sub>
25
+
26
+ ## Install with your AI
27
+
28
+ Copy the prompt below into Claude, Codex, Cursor, or any agent that can run
29
+ commands on this machine. It installs the plugin into the DeepSeek Harness
30
+ profile the agent finds running, then checks that it loaded.
31
+
32
+ ```text
33
+ Install the DeepSeek Harness plugin "deepseek-harness-cost" into the DSH profile that
34
+ is running on this machine, then verify it.
35
+
36
+ 1. Find the running DeepSeek Harness profile: Desktop keeps profiles under
37
+ ~/.dsh/profiles/ (use the one the running app uses), and a CLI install reports it
38
+ with `dsh plugin --profile <profile> ...`. Do not create or switch profiles.
39
+ 2. Install through the supported path, in this order:
40
+ a. GUI: Plugins -> Add plugin -> deepseek-harness-cost
41
+ b. CLI: dsh plugin --profile <profile> add deepseek-harness-cost
42
+ c. If the dsh command is not available (Desktop app), install inside the profile
43
+ directory with pnpm: `pnpm add deepseek-harness-cost`, then add
44
+ "deepseek-harness-cost" to dsh.profile.bundles in that profile's package.json.
45
+ 3. Do not edit the plugin's files, do not touch other plugins, and do not modify any
46
+ Session data.
47
+ 4. Verify: the Plugins page lists deepseek-harness-cost with a "chat-cost" row, and
48
+ after reloading the page a cost pill appears under the chat composer showing the
49
+ chat cost and rate per 1K tokens.
50
+ 5. If this machine uses OpenCode Go, check that an OPENCODE_GO_API_KEY credential
51
+ exists in the Harness credential store. Without it the cost still shows; the
52
+ allowance section reports a missing key.
53
+ Report what you changed and which version is installed. If any step is not possible
54
+ on this machine, stop and say which step and why instead of working around it by hand.
55
+ ```
56
+
57
+ Prefer to do it yourself? The two commands are in [Install](#install) below.
58
+
59
+ ## Why this one
60
+
61
+ - **Provider-reported, not estimated.** The numbers are the usage the provider
62
+ already returned and the Session log already stored — not a local token guess.
63
+ - **Two currencies, never mixed.** CNY and USD are separate sums. There is no
64
+ exchange-rate guess anywhere.
65
+ - **Subscription-aware.** OpenCode Go is metered as a subscription: the pill
66
+ shows the 5-hour, weekly and monthly allowance windows, not just a dollar
67
+ figure.
68
+ - **Whole conversation, not one log.** Subagent and workflow children are
69
+ separate Sessions; the meter walks the Session tree and sums every descendant.
70
+ - **Zero token overhead.** It reads the Session log and two account/price
71
+ endpoints. It never adds a prompt section, a tool, or a model request, so it
72
+ cannot inflate the number it displays.
73
+ - **No dependencies, no build step.** Plain ESM; the browser half borrows React
74
+ from the Host module table.
75
+
76
+ ## What you see
77
+
78
+ Click the pill for the full reading: requests, uncached/cached/cache-write input
79
+ and output tokens, the cache-hit rate, the peak/off-peak split, a per-model
80
+ breakdown, and the allowance detail.
81
+
82
+ ![The expanded panel: OpenCode Go allowance windows with reset countdowns, the DeepSeek platform CNY rows, and the OpenCode Go USD rows](https://raw.githubusercontent.com/JooyanDevs/deepseek-harness-cost/main/docs/preview-panel.png)
83
+
84
+ <sub>Sample values. The allowance section only appears for a chat that used
85
+ OpenCode Go; the currency sections appear for every provider the chat billed.</sub>
86
+
87
+ ## Install
88
+
89
+ DeepSeek Harness Desktop or Web, with the plugin manager available.
90
+
91
+ **From the GUI:** open **Plugins**, choose **Add plugin**, and enter:
92
+
93
+ ```
94
+ deepseek-harness-cost
95
+ ```
96
+
97
+ **From a terminal** (CLI installations):
98
+
99
+ ```
100
+ dsh plugin --profile <profile> add deepseek-harness-cost
101
+ ```
102
+
103
+ Pin an exact version when you want reproducible installs:
104
+
105
+ ```
106
+ dsh plugin --profile <profile> add deepseek-harness-cost@1.4.0
107
+ ```
108
+
109
+ The bundle is selected when it installs and the pill appears under the composer
110
+ immediately (the browser half also hot-reloads into an open page).
111
+
112
+ ## Update
113
+
114
+ When a newer version is published, the **Plugins** page shows it next to the
115
+ plugin and offers **Update** — one click replaces the installed version in
116
+ place. Nothing to run in a terminal.
117
+
118
+ Updates are only offered for plugins installed from a registry. If you installed
119
+ a pinned `git+…` spec instead, reinstall it with the new tag or commit.
120
+
121
+ ## Requirements
122
+
123
+ - A DeepSeek Harness profile with the plugin manager (the Desktop or Web
124
+ application profile).
125
+ - For the **allowance** half only: an `OPENCODE_GO_API_KEY` credential in the
126
+ Harness credential store — the same key the OpenCode provider uses.
127
+ - The **cost** half needs nothing: it prices the Session log against published
128
+ list prices.
129
+
130
+ Without the OpenCode key the plugin still shows CNY cost and rate; the allowance
131
+ rows simply report that the key is missing.
132
+
133
+ ## How the numbers are made
134
+
135
+ **Usage.** Every settled model attempt in the Session log carries
136
+ `inputTokens`, `cacheReadTokens`, `cacheWriteTokens` and `outputTokens`. The Host
137
+ half folds those with the same replacement rule the Harness itself uses:
138
+
139
+ - `assistant/message` carries the settled attempt's usage; `assistant/attempt`
140
+ may carry a streaming sample; a later sample for the same `(turn, step)`
141
+ **replaces** the earlier one instead of adding to it.
142
+ - `llm/retry-started` closes the replacement slot, so a retried attempt is
143
+ billed again (it was a second provider request).
144
+ - `request/context` names the provider route a request went to; the assistant
145
+ message's own `source.model` / `source.provider` win when present.
146
+
147
+ **Currency.** The provider route decides the card:
148
+
149
+ | Route | Card | Pill |
150
+ |---|---|---|
151
+ | `deepseek-official`, `deepseek-account` | DeepSeek CNY list prices | `¥total · ¥rate/1K` |
152
+ | `opencode-go` | OpenCode Go USD list prices (live from its models API) | `$total · $rate/1K` + allowance |
153
+ | anything else | none | no money; the panel reports excluded requests |
154
+
155
+ ### Price cards
156
+
157
+ | Card | Cache-miss input | Cache read | Output | Peak |
158
+ |---|---|---|---|---|
159
+ | DeepSeek CNY (per 1M) | ¥1 (`deepseek-flash`) | ¥0.02 | ¥4 | Mon–Fri 09:00–12:00, 14:00–18:00 Beijing, ×2 |
160
+ | OpenCode Go USD (per 1M) | $0.15 (`deepseek-v4.1-flash`) | $0.003 | $0.60 | Mon–Fri 01:00–04:00, 06:00–10:00 UTC, ×2 |
161
+
162
+ The CNY card is static and configurable. The USD card is **fetched from
163
+ `GET https://opencode.ai/zen/go/v1/models`** at startup and refreshed hourly, so
164
+ a price change does not need a plugin release; the built-in table is only the
165
+ offline fallback. Peak windows, peak factor and cache prices all come from that
166
+ reply.
167
+
168
+ ### The per-1K figure
169
+
170
+ `¥0.0000214/1K` is one number: everything the Session paid in that currency,
171
+ divided by every token the provider reported in that currency.
172
+
173
+ ```
174
+ per 1K = total cost ÷ (cache-miss + cache-read + cache-write + output) × 1000
175
+ ```
176
+
177
+ The numerator already contains every rate, so the result is the realized average
178
+ price per token, not a tariff lookup. The panel also shows **per 1M tokens**,
179
+ directly comparable with the cards above, and **cache saved**, which explains why
180
+ a cache-heavy chat runs far below list price.
181
+
182
+ ### The allowance windows
183
+
184
+ OpenCode Go is a subscription: a 5-hour rolling window (20% of the monthly
185
+ limit), a weekly window (50%) and the monthly limit (100%). The Host reads
186
+ `GET https://opencode.ai/zen/go/v1/usage` with the same `OPENCODE_GO_API_KEY` the
187
+ provider uses, caches the reply for 30 seconds, and exposes it on the plugin's
188
+ own Host route. The pill shows the **used** percentage of each window; the panel
189
+ adds the reset countdown.
190
+
191
+ The percentages are authoritative and come straight from OpenCode. The panel
192
+ names the plan and the model's published monthly limit, but it does not turn a
193
+ rounded percentage into a dollar amount that would pretend to more precision than
194
+ the endpoint reports.
195
+
196
+ ## Configure
197
+
198
+ Every option has a working default. To override a rate, a route or the plan, put
199
+ a `config` block on the plugin row in the profile's `cordis.patch.yml` (the same
200
+ row the bundle inserts):
201
+
202
+ ```yaml
203
+ - id: chat-cost
204
+ name: deepseek-harness-cost
205
+ config:
206
+ routes:
207
+ deepseek-official: CNY
208
+ deepseek-account: CNY
209
+ opencode-go: USD
210
+ models:
211
+ deepseek-flash: { cacheHit: 0.02, cacheMiss: 1, cacheWrite: 0, output: 4 }
212
+ deepseek-v4-pro: { cacheHit: 0.15, cacheMiss: 4.5, cacheWrite: 0, output: 13.5 }
213
+ defaultModel: deepseek-flash
214
+ offPeakRatio: 0.5
215
+ peakMode: auto # auto | peak | off-peak
216
+ peak:
217
+ timezoneOffsetMinutes: 480
218
+ days: [1, 2, 3, 4, 5]
219
+ windows: [[9, 12], [14, 18]]
220
+ holidays: []
221
+ usd:
222
+ apiKeyRef: OPENCODE_GO_API_KEY
223
+ baseUrl: https://opencode.ai
224
+ modelsPath: /zen/go/v1/models
225
+ usagePaths: [/zen/go/v1/usage, /inference/go/v1/usage]
226
+ plan: go # go | go-plus | go-teams
227
+ quotaTtlSeconds: 30
228
+ modelsTtlSeconds: 3600
229
+ requestTimeoutMs: 10000
230
+ monthlyLimitUsd: null
231
+ ```
232
+
233
+ | Field | Default | Meaning |
234
+ |---|---|---|
235
+ | `routes` | the three rows above | provider id → `CNY` / `USD`; a route absent here is not priced and is reported as excluded (set a route to `null` to drop a default). |
236
+ | `models` | the two CNY tables | CNY per 1M tokens at peak, per model id. A model without a row is priced with `defaultModel` and marked `≈`. |
237
+ | `defaultModel` | `deepseek-flash` | CNY rates for an unpriced DeepSeek model id. |
238
+ | `offPeakRatio` | `0.5` | CNY off-peak multiplier. |
239
+ | `peakMode` | `auto` | `auto` computes the CNY peak from the clock; `peak` / `off-peak` force one rate. |
240
+ | `peak.*` | Beijing, Mon–Fri | the CNY peak clock and statutory holidays. |
241
+ | `usd.apiKeyRef` | `OPENCODE_GO_API_KEY` | credential reference the allowance and models calls use. |
242
+ | `usd.baseUrl` | `https://opencode.ai` | allowance API origin. |
243
+ | `usd.modelsPath` / `usd.usagePaths` | the published endpoints | origin-relative paths; anything that is not a plain path (`//host`, `@host`) is ignored. |
244
+ | `usd.plan` | `go` | names the plan and its per-model monthly limit in the allowance panel; the percentages do not depend on it. |
245
+ | `usd.monthlyLimitUsd` | `null` | overrides the per-model monthly limit. |
246
+ | `usd.quotaTtlSeconds` / `usd.modelsTtlSeconds` | `30` / `3600` | how long the allowance and price replies are cached. |
247
+
248
+ ## Privacy and network access
249
+
250
+ - Session logs never leave the machine. The meter runs inside the Host process.
251
+ - The only network calls are two `GET`s to the configured OpenCode origin: the
252
+ price sheet (`/zen/go/v1/models`) and the account allowance
253
+ (`/zen/go/v1/usage`). Both carry the `OPENCODE_GO_API_KEY` credential, over
254
+ HTTPS, and nothing else.
255
+ - The credential is resolved on the Host per call and is never stored in the
256
+ projection, logged, put in a URL, or sent to the browser.
257
+ - The browser half only talks to the plugin's own Host route, which sits behind
258
+ the Harness Connection fence: Host/Origin checks plus browser authentication.
259
+ - No telemetry, no analytics, no remote config.
260
+
261
+ ## Compatibility
262
+
263
+ Built and verified against DeepSeek Harness `0.2.2-rc.5`. It uses the public
264
+ Host services (`credentials`, `sessionProjections`, `webServer`, `connection`)
265
+ and the client slot API; it does not patch or monkey-patch the Harness.
266
+
267
+ ## Development
268
+
269
+ The package is plain ESM with no dependencies: no build step, no `node_modules`.
270
+
271
+ ```
272
+ node --check index.js
273
+ node --check client.js
274
+ node test/fold.test.mjs
275
+ node test/real-log.mjs "<session store>/<workspace>/<session>/session.v4.jsonl.zstd"
276
+ node test/audit.mjs --all
277
+ ```
278
+
279
+ `fold.test.mjs` covers the CNY and USD price arithmetic, both peak clocks, the
280
+ replace-don't-double-count rule for streamed usage, route grouping across
281
+ providers, the per-1K identity, the allowance normalization and plan-limit
282
+ mapping, the models-endpoint parser, the client formatters, and the subagent
283
+ combination.
284
+
285
+ `real-log.mjs` folds a real Session log twice — once through the plugin's unit,
286
+ once through an independent reduction — and fails if any bucket or currency
287
+ total disagrees.
288
+
289
+ `audit.mjs` shares no code with the plugin (its own zstd reader, fold, route
290
+ resolution, peak clocks and transcribed price tables), re-prices every Session
291
+ log on the machine, and fails on any difference.
292
+
293
+ Files: `index.js` (Host unit: fold, pricing, allowance route), `client.js`
294
+ (browser pills and panel), `cordis.patch.yml` (the loader row), `locale/*.json`
295
+ (plugin-manager copy).
296
+
297
+ ## Troubleshooting
298
+
299
+ - **No pill under the chat** — the bundle is installed but not enabled: check
300
+ **Plugins** in the sidebar.
301
+ - **Allowance shows “key missing”** — add the `OPENCODE_GO_API_KEY` credential;
302
+ the CNY half keeps working without it.
303
+ - **A provider shows no money** — its route has no price card. Add it under
304
+ `routes` plus a `models` row, or read it as excluded in the panel.
305
+
306
+ ## License
307
+
308
+ MIT © Jooyan Bagheri. Not affiliated with DeepSeek or OpenCode.