@goodandready/dsh-usage-guard 0.1.6 → 0.1.9
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/README.md +46 -2
- package/README.ru.md +34 -1
- package/README.zh.md +10 -0
- package/lib/client.js +347 -36
- package/lib/index.js +75 -41
- package/lib/telemetry.js +111 -0
- package/lib/updater.js +266 -0
- package/lib/usage.js +60 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
<a href="README.zh.md"><b>🇨🇳 中文说明</b></a>
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
+
<table align="center">
|
|
25
|
+
<tr>
|
|
26
|
+
<td align="center">
|
|
27
|
+
⭐ <strong>If you like this plugin, please star it on GitHub</strong> — it shows me that the plugin is useful to you and motivates me to keep developing it.
|
|
28
|
+
<br><br>
|
|
29
|
+
🐛 <strong>If you find a bug or would like to request a feature</strong>, open a GitHub issue in any language — I will review your proposal and implement useful suggestions in a future plugin version.
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
</table>
|
|
33
|
+
|
|
24
34
|
</div>
|
|
25
35
|
|
|
26
36
|
---
|
|
@@ -108,11 +118,43 @@ If a counter cannot be resolved from aliases, it is safely initialized to `0`. F
|
|
|
108
118
|
Logs informative diagnostic warnings naming the exact session, turn, step, raw payload, and recovery action (e.g. `inputTokens borrowed from alias` vs `inputTokens zeroed`). Incidents are deduplicated in memory so logs are not flooded during replays, and the cache is bounded to 1,000 entries with O(1) FIFO eviction.
|
|
109
119
|
|
|
110
120
|
### 7. Native Web UI Settings Card (`lib/client.js`)
|
|
111
|
-
* Mounts into the native Settings tab under `Settings → Plugins → Plugin Settings` (`settings.plugin.item`) with real-time status badge, auto-dismissing save feedback, and full localization.
|
|
121
|
+
* Mounts into the native Settings tab under `Settings → Plugins → Plugin Settings` (`settings.plugin.item`) with real-time status badge, auto-dismissing save feedback, and full English / Chinese localization.
|
|
122
|
+
|
|
123
|
+
### 8. Token Spike Clamping (`maxStepTokens`)
|
|
124
|
+
* Restricts abnormally huge step usage counters (e.g. > 1,000,000) before projection calculation to prevent integer overflow and corrupted session summaries. Can be configured in settings or set to `0` to disable.
|
|
125
|
+
|
|
126
|
+
### 9. Live In-Memory Telemetry & Diagnostic Endpoint (`/api/dsh-usage-guard/telemetry`)
|
|
127
|
+
* Tracks rescued malformed samples, total fixed tokens, clamped spikes, and maintains a FIFO circular buffer of recent incidents with exact timestamps and coordinates. Rendered live in the settings UI.
|
|
128
|
+
|
|
129
|
+
### 10. Host-Side One-Click Updater (`/api/dsh-usage-guard/update`)
|
|
130
|
+
* Implements the canonical DSH plugin-updater specification with loopback verification, `same-origin` checks, and `x-dsh-plugin-update: 1` security token. Allows updating the plugin directly from the settings interface.
|
|
112
131
|
|
|
113
132
|
---
|
|
114
133
|
|
|
115
|
-
## 🚀 Changed in v0.1.
|
|
134
|
+
## 🚀 Changed in v0.1.9
|
|
135
|
+
|
|
136
|
+
* **Fix Schemastery Config Validation (`z.natural()`)**:
|
|
137
|
+
- Replaced incompatible Zod chaining `z.number().int().nonnegative()` in `Config` with Cordis Schemastery's native `z.natural()`.
|
|
138
|
+
- Fixes `TypeError: z.number(...).int is not a function` preventing Cordis loader crash upon importing `dsh-usage-guard`.
|
|
139
|
+
- Added regression unit test `test/config.test.mjs`.
|
|
140
|
+
|
|
141
|
+
## 🚀 Changed in v0.1.8
|
|
142
|
+
|
|
143
|
+
* **Canonical Localization Standard (en/zh)**:
|
|
144
|
+
- Client bundle `lib/client.js` now strictly provides canonical `en` (English fallback) and `zh` (Simplified Chinese) dictionaries.
|
|
145
|
+
- Russian localization is fully decoupled from the core bundle and maintained through `@goodandready/dsh-russian-lang` (Issue #196).
|
|
146
|
+
- Enforced zero hardcoded Cyrillic strings in client frontend bundle via automated tests.
|
|
147
|
+
* **Live In-Memory Telemetry & Endpoint (`/api/dsh-usage-guard/telemetry`)**:
|
|
148
|
+
- Real-time tracking of `rescuedEvents`, `fixedTokens`, `clampedSpikes`, and a FIFO circular buffer of recent incidents.
|
|
149
|
+
- Integrated `TelemetrySection` in the Settings Card displaying 3 metric cards and latest incident context.
|
|
150
|
+
* **Host-Side One-Click Plugin Updater (`/api/dsh-usage-guard/update`)**:
|
|
151
|
+
- Built-in updater supporting status checks and in-place updates via DSH CLI.
|
|
152
|
+
- Multi-layer security via `isTrustedUpdateRequest`: loopback IP check, `sec-fetch-site: same-origin`, matching `host`/`origin`, and `x-dsh-plugin-update: 1` header.
|
|
153
|
+
* **Token Spike Clamping (`maxStepTokens`)**:
|
|
154
|
+
- Added configurable ceiling in `Config` and UI to clamp abnormally large step metrics (> 1,000,000) before projection calculation.
|
|
155
|
+
- Distinct diagnostic logging and telemetry tracking for clamped token spikes.
|
|
156
|
+
|
|
157
|
+
## 🚀 Changed in v0.1.7
|
|
116
158
|
|
|
117
159
|
* **Design Alignment with `dsh-clinebot` (#6)**:
|
|
118
160
|
- Idempotent `ensureCss()` outside component render with `<style id="dsh-usage-guard-full-css" data-dsh-plugin="dsh-usage-guard">`.
|
|
@@ -212,12 +254,14 @@ dsh plugin --profile web add @goodandready/dsh-usage-guard
|
|
|
212
254
|
dsh-usage-guard:
|
|
213
255
|
repair: true
|
|
214
256
|
report: true
|
|
257
|
+
maxStepTokens: 1000000
|
|
215
258
|
```
|
|
216
259
|
|
|
217
260
|
| Parameter | Type | Default | Description |
|
|
218
261
|
|---|---|---|---|
|
|
219
262
|
| `repair` | `boolean` | `true` | Replace missing or non-numeric token counters with zero before arithmetic accumulation |
|
|
220
263
|
| `report` | `boolean` | `true` | Log diagnostic warning lines naming turn, step, and raw sample when damaged metrics arrive |
|
|
264
|
+
| `maxStepTokens` | `number` | `0` | Clamp abnormally large step usage values (e.g. > 1,000,000) to prevent integer overflows. Set 0 to disable |
|
|
221
265
|
|
|
222
266
|
---
|
|
223
267
|
|
package/README.ru.md
CHANGED
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
<a href="README.zh.md"><b>🇨🇳 中文说明</b></a>
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
+
<table align="center">
|
|
25
|
+
<tr>
|
|
26
|
+
<td align="center">
|
|
27
|
+
⭐ <strong>Если вам нравится этот плагин, поставьте ему звезду на GitHub</strong> — это покажет мне, что плагин вам полезен, и будет мотивировать меня развивать его дальше.
|
|
28
|
+
<br><br>
|
|
29
|
+
🐛 <strong>Если вы нашли баг или хотите предложить новый функционал</strong>, создайте issue на GitHub на любом языке — я рассмотрю ваше предложение и реализую полезные идеи в одной из следующих версий плагина.
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
</table>
|
|
33
|
+
|
|
24
34
|
</div>
|
|
25
35
|
|
|
26
36
|
---
|
|
@@ -112,7 +122,30 @@ graph LR
|
|
|
112
122
|
|
|
113
123
|
---
|
|
114
124
|
|
|
115
|
-
## 🚀 Изменения в версии v0.1.
|
|
125
|
+
## 🚀 Изменения в версии v0.1.9 (Changed in v0.1.9)
|
|
126
|
+
|
|
127
|
+
* **Исправление валидации схемы Cordis Schemastery (`z.natural()`)**:
|
|
128
|
+
- Заменена несовместимая цепочка Zod `z.number().int().nonnegative()` в схеме `Config` на нативный метод Cordis Schemastery `z.natural()`.
|
|
129
|
+
- Устранена критическая ошибка `TypeError: z.number(...).int is not a function`, вызывавшая аварийную остановку лоадера Cordis при запуске `dsh-web.service`.
|
|
130
|
+
- Добавлен регрессионный юнит-тест `test/config.test.mjs`.
|
|
131
|
+
|
|
132
|
+
## 🚀 Изменения в версии v0.1.8 (Changed in v0.1.8)
|
|
133
|
+
|
|
134
|
+
* **Канонизация локалей (en/zh) и делегирование русского перевода**:
|
|
135
|
+
- Бандл `lib/client.js` поставляет исключительно канонический английский (`en`) и китайский (`zh`) словари.
|
|
136
|
+
- Русская локализация вынесена и поддерживается централизованно через `@goodandready/dsh-russian-lang` (Issue #196).
|
|
137
|
+
- Автотесты строго контролируют отсутствие кириллических строк в клиентском бандле.
|
|
138
|
+
* **Живая телеметрия перехватов (`/api/dsh-usage-guard/telemetry`)**:
|
|
139
|
+
- Накапливает в оперативной памяти счётчики `rescuedEvents`, `fixedTokens`, `clampedSpikes` и кольцевой FIFO-буфер недавних инцидентов.
|
|
140
|
+
- Добавлен блок `TelemetrySection` в карточке настроек с отображением 3 показателей и деталей последнего инцидента.
|
|
141
|
+
* **Встроенный One-Click Updater (`/api/dsh-usage-guard/update`)**:
|
|
142
|
+
- Реализован протокол обновления плагинов DSH (проверка версий и вызов DSH CLI).
|
|
143
|
+
- Защита от SSRF/CSRF через `isTrustedUpdateRequest`: проверка Loopback, Same-Origin, совпадения `host`/`origin` и токена `x-dsh-plugin-update: 1`.
|
|
144
|
+
* **Срезание аномальных спайков токенов (`maxStepTokens`)**:
|
|
145
|
+
- Конфигурируемый порог в схеме ядра и UI для ограничения аномальных счетчиков шага (> 1 000 000).
|
|
146
|
+
- Отдельное логирование и учёт в телеметрии для срезанных спайков.
|
|
147
|
+
|
|
148
|
+
## 🚀 Изменения в версии v0.1.7 (Changed in v0.1.7)
|
|
116
149
|
|
|
117
150
|
* **Единый стиль по референсу `dsh-clinebot` (#6)**:
|
|
118
151
|
- Идемпотентный вызов `ensureCss()` вынесен за пределы цикла рендера (`#dsh-usage-guard-full-css` с атрибутом `data-dsh-plugin="dsh-usage-guard"`).
|
package/README.zh.md
CHANGED
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
<a href="README.zh.md"><b>🇨🇳 中文说明</b></a>
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
+
<table align="center">
|
|
25
|
+
<tr>
|
|
26
|
+
<td align="center">
|
|
27
|
+
⭐ <strong>如果您喜欢这个插件,请在 GitHub 上为它点亮 Star</strong> — 这能让我知道插件对您有用,并鼓励我继续开发和维护它。
|
|
28
|
+
<br><br>
|
|
29
|
+
🐛 <strong>如果您发现 Bug 或希望增加功能</strong>,请使用任意语言在 GitHub 上提交 Issue — 我会评估您的建议,并在后续版本中实现有价值的改进。
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
</table>
|
|
33
|
+
|
|
24
34
|
</div>
|
|
25
35
|
|
|
26
36
|
---
|