@tsa-group/claude-usage 0.4.3 → 0.4.4
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/dist/health.js +10 -2
- package/dist/install.js +3 -1
- package/package.json +1 -1
package/dist/health.js
CHANGED
|
@@ -22,6 +22,8 @@ export const STATUS_BY_CODE = {
|
|
|
22
22
|
/** 連續失敗幾次 / 幾小時沒成功,就算不健康 */
|
|
23
23
|
export const WARN_FAILURES = 3;
|
|
24
24
|
export const WARN_STALE_HOURS = 6;
|
|
25
|
+
/** 最近這麼多分鐘內成功過,就視為「現在是好的」,蓋過失敗計數器(見 healthWarning) */
|
|
26
|
+
export const RECENT_OK_MIN = 45;
|
|
25
27
|
/** usage_snapshots.jsonl 的最後一行(本機最新一筆快照) */
|
|
26
28
|
export function lastSnapshot() {
|
|
27
29
|
const p = snapPath();
|
|
@@ -77,11 +79,17 @@ export function saveHealth(h) {
|
|
|
77
79
|
* 不會再推一次。
|
|
78
80
|
*/
|
|
79
81
|
export function healthWarning(h) {
|
|
82
|
+
const ok = parseIso(h.last_ok_at);
|
|
83
|
+
const okMinAgo = ok ? (Date.now() - ok.getTime()) / 60_000 : Infinity;
|
|
80
84
|
const cf = h.consecutive_failures ?? 0;
|
|
81
|
-
|
|
85
|
+
// ★ 近期成功過就不看失敗計數器。「現在有沒有在運作」最可靠的答案是「最近有沒有
|
|
86
|
+
// 成功過」,而不是一個可能卡住的計數器 —— 實測(Molly, 0.4.3)出現過快照確實
|
|
87
|
+
// 每 15 分鐘進來、consecutive_failures 卻停在 152 的矛盾狀態:多個 tick 行程
|
|
88
|
+
// 同時 read-modify-write health.json 就會互相蓋掉,計數器因此永遠歸不了零。
|
|
89
|
+
// 那種情況下報「連續 152 次失敗」是錯的,而且會讓人去修一個沒有壞的東西。
|
|
90
|
+
if (cf >= WARN_FAILURES && okMinAgo > RECENT_OK_MIN) {
|
|
82
91
|
return `連續 ${cf} 次採樣失敗 (${h.last_sample_status}) 自 ${h.first_failure_at}`;
|
|
83
92
|
}
|
|
84
|
-
const ok = parseIso(h.last_ok_at);
|
|
85
93
|
if (ok) {
|
|
86
94
|
const hrs = (Date.now() - ok.getTime()) / 3_600_000;
|
|
87
95
|
if (hrs >= WARN_STALE_HOURS) {
|
package/dist/install.js
CHANGED
|
@@ -119,7 +119,9 @@ function winInstall() {
|
|
|
119
119
|
console.error(` 手動執行這行可看到正確訊息: schtasks ${args.map((a) => (a.includes(" ") ? `"${a}"` : a)).join(" ")}`);
|
|
120
120
|
}
|
|
121
121
|
console.log(`uninstall: schtasks /Delete /TN ${WIN_TASK} /F`);
|
|
122
|
-
console.log("!
|
|
122
|
+
console.log("! 憑證與採樣已於 2026-08-28 在 Windows 實機驗證通過(含桌面版加密憑證庫)。\n" +
|
|
123
|
+
" 尚未完整驗證的是背景任務本身(schtasks + VBS 隱藏視窗)——\n" +
|
|
124
|
+
" 裝完請跑 claude-usage status 確認有心跳。");
|
|
123
125
|
return r.status ?? 1;
|
|
124
126
|
}
|
|
125
127
|
function winUninstall() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsa-group/claude-usage",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Per-user Claude usage collector — measures Claude Code token detail and account-level rate-limit utilization locally, reports to your own ingest server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|