hacklab 26.921.4 → 26.922.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/index.js +28 -5
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
// package.json
|
|
6
|
-
var version = "26.
|
|
6
|
+
var version = "26.922.5";
|
|
7
7
|
|
|
8
8
|
// src/auth.ts
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
@@ -152,6 +152,23 @@ async function collectUsage() {
|
|
|
152
152
|
throw new Error("Usage report exceeds 20 MB. Nothing synced.");
|
|
153
153
|
return body;
|
|
154
154
|
}
|
|
155
|
+
var plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
156
|
+
function describeIssues(result) {
|
|
157
|
+
const parts = [
|
|
158
|
+
result.error,
|
|
159
|
+
...(result.issues ?? []).map((i) => `session ${i.index} — ${i.reason}`)
|
|
160
|
+
];
|
|
161
|
+
const detail = parts.filter(Boolean).join(" ");
|
|
162
|
+
return detail && !detail.endsWith(".") ? `${detail}.` : detail;
|
|
163
|
+
}
|
|
164
|
+
async function readResult(response) {
|
|
165
|
+
try {
|
|
166
|
+
const result = await response.json();
|
|
167
|
+
return result && typeof result === "object" ? result : {};
|
|
168
|
+
} catch {
|
|
169
|
+
return {};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
155
172
|
async function uploadUsage(origin, token, body) {
|
|
156
173
|
const response = await fetch(`${origin}/api/token-usage`, {
|
|
157
174
|
method: "POST",
|
|
@@ -160,12 +177,18 @@ async function uploadUsage(origin, token, body) {
|
|
|
160
177
|
redirect: "error",
|
|
161
178
|
signal: AbortSignal.timeout(60000)
|
|
162
179
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
const result = await readResult(response);
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
const detail = describeIssues(result);
|
|
183
|
+
throw new Error(`Hacklab rejected the usage report (HTTP ${response.status}).${detail ? ` ${detail}` : ""} Run hacklab sync to retry.`);
|
|
184
|
+
}
|
|
166
185
|
if (result.ok !== true)
|
|
167
186
|
throw new Error("Hacklab did not confirm the sync. Run hacklab sync to retry.");
|
|
168
|
-
console.log(`Synced ${result.sessions
|
|
187
|
+
console.log(`Synced ${plural(result.sessions ?? 0, "usage session")} to Hacklab.`);
|
|
188
|
+
if (result.duplicates)
|
|
189
|
+
console.log(`Merged ${plural(result.duplicates, "repeated session")}.`);
|
|
190
|
+
if (result.skipped)
|
|
191
|
+
console.log(`Skipped ${plural(result.skipped, "unreadable session")}. ${describeIssues(result)}`.trim());
|
|
169
192
|
if (result.sessions === 0)
|
|
170
193
|
console.log("No usage found. Use your coding agent, then run hacklab sync again.");
|
|
171
194
|
}
|
package/package.json
CHANGED