@tsa-group/claude-usage 0.4.2 → 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/doctor.js +14 -0
- package/dist/health.js +10 -2
- package/dist/install.js +3 -1
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -186,6 +186,20 @@ export async function doctor() {
|
|
|
186
186
|
: ok(`採集狀態正常(上次成功 ${h.last_ok_at ?? "-"})`));
|
|
187
187
|
if (h.last_error)
|
|
188
188
|
out.push(` 上次錯誤: ${h.last_error}`);
|
|
189
|
+
if (warn) {
|
|
190
|
+
// ★ 這行以前漏了:畫面印 [BAD] 但結論說「沒有發現問題」。
|
|
191
|
+
// 一個會自相矛盾的診斷工具,比沒有診斷工具更糟 —— 使用者會學會忽略它。
|
|
192
|
+
if (credOk) {
|
|
193
|
+
// 憑證「現在」讀得到,health 卻說壞掉 —— 那是**背景任務**的環境或版本
|
|
194
|
+
// 與這裡不同,不是憑證問題。這個分辨很重要:兩者的處置完全不同。
|
|
195
|
+
problems.push(`憑證現在讀得到,但背景任務回報失敗(${warn})。代表背景任務跑的環境或版本` +
|
|
196
|
+
`與你現在這個不同 —— 重跑 claude-usage install 讓它指到目前的版本;` +
|
|
197
|
+
`Windows 可用 schtasks /Query /TN ClaudeUsage /V /FO LIST 看它實際執行什麼`);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
problems.push(`採集失敗:${warn}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
189
203
|
}
|
|
190
204
|
else {
|
|
191
205
|
out.push(info("尚無 health 紀錄(背景任務還沒跑過)"));
|
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": {
|