@tsa-group/claude-usage 0.3.4 → 0.3.5
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/daemon.js +22 -4
- package/dist/install.js +6 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
import { statSync, readdirSync } from "node:fs";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
|
-
import { EXIT } from "./creds.js";
|
|
11
|
+
import { EXIT, loadToken } from "./creds.js";
|
|
12
12
|
import { healthWarning, lastSnapshot, loadHealth, saveHealth, } from "./health.js";
|
|
13
13
|
import { devicePath, projectsDir } from "./paths.js";
|
|
14
|
-
import { report } from "./upload.js";
|
|
14
|
+
import { enroll, report } from "./upload.js";
|
|
15
15
|
import { sample } from "./usage.js";
|
|
16
16
|
import { nowIso, parseIso } from "./util.js";
|
|
17
17
|
// ── 自適應策略 ──
|
|
@@ -137,8 +137,26 @@ export function decide() {
|
|
|
137
137
|
* 都只記錄不拋出 —— daemon 絕不能因為上傳失敗就整個死掉。
|
|
138
138
|
*/
|
|
139
139
|
async function flushUploads() {
|
|
140
|
-
if (!existsSync(devicePath()))
|
|
141
|
-
|
|
140
|
+
if (!existsSync(devicePath())) {
|
|
141
|
+
// install 當下 enroll 失敗(幾乎都是憑證還沒好)時,由這裡負責補上。
|
|
142
|
+
// 否則 install 印的「下次會自動重試」就是一句空話 —— 而使用者會合理地以為
|
|
143
|
+
// 自己不用再做什麼。第一台 Windows 機器就是這樣卡住的:憑證修好之後仍然
|
|
144
|
+
// 不會有任何資料,因為沒有人再跑一次 enroll。
|
|
145
|
+
try {
|
|
146
|
+
loadToken();
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// 憑證還是壞的 -> 這次 enroll 必定失敗,安靜跳過,不要每 5 分鐘去騷擾 server
|
|
150
|
+
return "not-enrolled";
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
if ((await enroll([])) !== 0)
|
|
154
|
+
return "enroll-failed";
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return "enroll-failed";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
142
160
|
try {
|
|
143
161
|
return (await report([])) === 0 ? "uploaded" : "upload-failed";
|
|
144
162
|
}
|
package/dist/install.js
CHANGED
|
@@ -230,7 +230,12 @@ async function enrollStep(argv) {
|
|
|
230
230
|
throw new Error("enroll returned non-zero");
|
|
231
231
|
}
|
|
232
232
|
catch (e) {
|
|
233
|
-
|
|
233
|
+
// 這句話必須與 daemon.flushUploads 的實際行為一致。它曾經承諾「會自動重試」
|
|
234
|
+
// 而程式碼並不會,於是卡住的人以為自己不用再做什麼。
|
|
235
|
+
console.error(`enroll: FAILED — ${e.message}`);
|
|
236
|
+
console.error(" hook 與背景任務仍會安裝。憑證問題解決後,背景任務會在 5 分鐘內自動完成註冊," +
|
|
237
|
+
"不需要重跑 install。\n" +
|
|
238
|
+
" 先跑 claude-usage doctor 看是哪一種問題。");
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
241
|
export async function install(argv = []) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsa-group/claude-usage",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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": {
|