@cad0p/pi-usage 0.11.5 → 0.11.6-20261107.1
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/CHANGELOG.md +22 -0
- package/README.md +102 -52
- package/bin/piquota.js +13 -3
- package/extensions/quota-panel.ts +567 -204
- package/omarchy/cad0p.pi-usage/UsageContent.qml +17 -1
- package/omarchy/cad0p.pi-usage/UsageLogic.js +13 -3
- package/omarchy/cad0p.pi-usage/assets/mistral.svg +18 -0
- package/package.json +3 -2
- package/src/auth/pi-auth.js +13 -0
- package/src/cache.js +128 -31
- package/src/cli/commands/omarchy.js +21 -3
- package/src/cli/explain.js +2 -0
- package/src/engine.js +105 -9
- package/src/local/history.js +29 -8
- package/src/local/pi-sessions.js +30 -3
- package/src/local/stats-worker.js +27 -0
- package/src/local/worker.js +157 -0
- package/src/model.js +39 -5
- package/src/omarchy/assets/mistral.svg +18 -0
- package/src/omarchy/publish.js +9 -8
- package/src/omarchy/record.js +24 -19
- package/src/overlay-keys.js +257 -0
- package/src/providers/antigravity-oauth.js +43 -3
- package/src/providers/antigravity.js +44 -5
- package/src/providers/claude.js +26 -0
- package/src/providers/codex.js +14 -0
- package/src/providers/mistral.js +251 -0
- package/src/providers/opencode-go.js +3 -3
- package/src/refresh.js +4 -1
- package/src/render/panel.js +23 -13
package/src/local/history.js
CHANGED
|
@@ -200,11 +200,11 @@ export function hasMonthFiles(historyDir) {
|
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* @param {string} slot
|
|
203
|
-
* @returns {string} "" for the base entry (
|
|
204
|
-
*
|
|
203
|
+
* @returns {string} "#1" for the base entry (the first account of the family),
|
|
204
|
+
* "#<slot>" for a sibling slot ("#2", "#1-api").
|
|
205
205
|
*/
|
|
206
206
|
export function accountLabel(slot) {
|
|
207
|
-
return slot === "" || slot === null || slot === undefined ? "" : `#${slot}`;
|
|
207
|
+
return slot === "" || slot === null || slot === undefined ? "#1" : `#${slot}`;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
/**
|
|
@@ -521,15 +521,36 @@ export function parseTotals(raw) {
|
|
|
521
521
|
if (entry.accounts && typeof entry.accounts === "object" && !Array.isArray(entry.accounts)) {
|
|
522
522
|
for (const [rawLabel, accountValue] of Object.entries(entry.accounts)) {
|
|
523
523
|
if (!accountValue || typeof accountValue !== "object") continue;
|
|
524
|
-
// Files written
|
|
525
|
-
//
|
|
526
|
-
|
|
524
|
+
// Files written while the base entry was unlabelled carry "" for it;
|
|
525
|
+
// normalize on read so one account never shows up twice.
|
|
526
|
+
// A file frozen across both conventions carries "#1" and "" for the
|
|
527
|
+
// same account: the two halves are summed, never one dropped.
|
|
528
|
+
const label = rawLabel === "" ? "#1" : rawLabel;
|
|
527
529
|
const account = /** @type {Record<string, unknown>} */ (accountValue);
|
|
528
|
-
|
|
530
|
+
const parsed = {
|
|
529
531
|
totalPrompts: count(account.totalPrompts),
|
|
530
532
|
totalSessions: count(account.totalSessions),
|
|
531
533
|
models: modelsFromJson(account.modelUsage),
|
|
532
|
-
}
|
|
534
|
+
};
|
|
535
|
+
const existing = familyTotals.accounts.get(label);
|
|
536
|
+
if (!existing) {
|
|
537
|
+
familyTotals.accounts.set(label, parsed);
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
existing.totalPrompts += parsed.totalPrompts;
|
|
541
|
+
existing.totalSessions += parsed.totalSessions;
|
|
542
|
+
for (const [model, bucket] of parsed.models) {
|
|
543
|
+
const seen = existing.models.get(model);
|
|
544
|
+
if (!seen) {
|
|
545
|
+
existing.models.set(model, bucket);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
seen.input += bucket.input;
|
|
549
|
+
seen.output += bucket.output;
|
|
550
|
+
seen.cacheRead += bucket.cacheRead;
|
|
551
|
+
seen.cacheWrite += bucket.cacheWrite;
|
|
552
|
+
seen.messages += bucket.messages;
|
|
553
|
+
}
|
|
533
554
|
}
|
|
534
555
|
}
|
|
535
556
|
}
|
package/src/local/pi-sessions.js
CHANGED
|
@@ -145,8 +145,22 @@ const RECENT_DAYS = 7;
|
|
|
145
145
|
* @property {number} [now] Report time; decides which local day is "today".
|
|
146
146
|
* @property {number} [budgetMs] Wall-clock budget for this scan.
|
|
147
147
|
* @property {() => number} [clock] Time source; tests inject one to drive the budget.
|
|
148
|
+
* @property {() => boolean} [shouldStop] The host wants the scan to end now (session shutdown, /reload).
|
|
149
|
+
* @property {(lock: { path: string, token: string | null }) => void} [onLock] Receives the lock
|
|
150
|
+
* this scan holds, so a host that has to kill the worker can still release it.
|
|
148
151
|
*/
|
|
149
152
|
|
|
153
|
+
/**
|
|
154
|
+
* The host asked the scan to stop. Thrown out of the scan loop so the `finally`
|
|
155
|
+
* releases the history lock and nothing after the interruption is written.
|
|
156
|
+
*/
|
|
157
|
+
export class LocalScanAbortedError extends Error {
|
|
158
|
+
constructor() {
|
|
159
|
+
super("local token stats scan stopped");
|
|
160
|
+
this.name = "LocalScanAbortedError";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
150
164
|
/**
|
|
151
165
|
* One session file's cache entry.
|
|
152
166
|
*
|
|
@@ -911,8 +925,8 @@ function tokensByModel(models) {
|
|
|
911
925
|
* @returns {number}
|
|
912
926
|
*/
|
|
913
927
|
function labelOrder(label) {
|
|
914
|
-
// "" is the base entry; "
|
|
915
|
-
// totals.json written
|
|
928
|
+
// "#1" is the base entry; "" is the label it had for a while, kept so a
|
|
929
|
+
// totals.json written then still sorts first.
|
|
916
930
|
if (label === "" || label === "#1") return -1;
|
|
917
931
|
const numeric = Number.parseInt(String(label).replace(/^#/, ""), 10);
|
|
918
932
|
return Number.isFinite(numeric) ? numeric : Number.MAX_SAFE_INTEGER;
|
|
@@ -1135,6 +1149,10 @@ export function buildLocalStats(input = {}) {
|
|
|
1135
1149
|
* }>}
|
|
1136
1150
|
*/export async function collectLocalStats(options = {}) {
|
|
1137
1151
|
const clock = options.clock ?? Date.now;
|
|
1152
|
+
const hostStopped = options.shouldStop;
|
|
1153
|
+
const stopNow = () => {
|
|
1154
|
+
if (hostStopped?.() === true) throw new LocalScanAbortedError();
|
|
1155
|
+
};
|
|
1138
1156
|
const startedAt = clock();
|
|
1139
1157
|
const now = options.now ?? Date.now();
|
|
1140
1158
|
const today = localDayKey(now);
|
|
@@ -1164,6 +1182,9 @@ export function buildLocalStats(input = {}) {
|
|
|
1164
1182
|
// delta twice. A run that cannot take it still answers, from what is on disk.
|
|
1165
1183
|
const lockPath = `${cachePath}.lock`;
|
|
1166
1184
|
const lock = acquireHistoryLock({ lockPath, now: clock() });
|
|
1185
|
+
// The host gets the token, not just the path: whoever releases this lock must
|
|
1186
|
+
// prove it is this scan's, never another run's.
|
|
1187
|
+
if (lock.acquired) options.onLock?.({ path: lock.path, token: lock.token });
|
|
1167
1188
|
if (!lock.acquired) {
|
|
1168
1189
|
// Read-only path: `canWrite: false` keeps it from rebuilding or repairing
|
|
1169
1190
|
// anything the run that does hold the lock is writing right now.
|
|
@@ -1277,6 +1298,7 @@ export function buildLocalStats(input = {}) {
|
|
|
1277
1298
|
};
|
|
1278
1299
|
|
|
1279
1300
|
for (const path of listen) {
|
|
1301
|
+
stopNow();
|
|
1280
1302
|
if (!keepLock()) break;
|
|
1281
1303
|
if (!partial && overBudget()) partial = true;
|
|
1282
1304
|
if (partial) break;
|
|
@@ -1373,7 +1395,7 @@ export function buildLocalStats(input = {}) {
|
|
|
1373
1395
|
startOffset,
|
|
1374
1396
|
days,
|
|
1375
1397
|
now,
|
|
1376
|
-
shouldStop: overBudget,
|
|
1398
|
+
shouldStop: () => overBudget() || hostStopped?.() === true,
|
|
1377
1399
|
onUsage: (usage) => {
|
|
1378
1400
|
if (lastFrozenDay && usage.day <= lastFrozenDay) {
|
|
1379
1401
|
// Frozen days are never reconstructed on a rescan. Incremental
|
|
@@ -1465,6 +1487,11 @@ export function buildLocalStats(input = {}) {
|
|
|
1465
1487
|
};
|
|
1466
1488
|
}
|
|
1467
1489
|
|
|
1490
|
+
// A stop that arrived while the last file was being read has to end the run
|
|
1491
|
+
// here: freezing days and writing the cache are the writes a shutdown must
|
|
1492
|
+
// not race. Everything before this point is undoable read-only work.
|
|
1493
|
+
stopNow();
|
|
1494
|
+
|
|
1468
1495
|
const openRows = buildOpenRows(next);
|
|
1469
1496
|
const pendingBeforeApply = pendingLate.size;
|
|
1470
1497
|
const applied = applyDurable({
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
+
|
|
3
|
+
import { LocalScanAbortedError, collectLocalStats } from "./pi-sessions.js";
|
|
4
|
+
|
|
5
|
+
const options = workerData?.options ?? {};
|
|
6
|
+
// A stop request is a flag the scan polls, not a message it has to be idle to
|
|
7
|
+
// receive: a cold scan spends its time inside synchronous reads and hashing.
|
|
8
|
+
const stopFlag = workerData?.stopFlag instanceof Int32Array ? workerData.stopFlag : null;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const result = await collectLocalStats({
|
|
12
|
+
...options,
|
|
13
|
+
shouldStop: () => stopFlag !== null && Atomics.load(stopFlag, 0) === 1,
|
|
14
|
+
// The host keeps this handle: if it has to kill this thread, it can release
|
|
15
|
+
// the lock, and only with the token this scan created.
|
|
16
|
+
onLock: (lock) => parentPort?.postMessage({ type: "lock", path: lock.path, token: lock.token }),
|
|
17
|
+
});
|
|
18
|
+
parentPort?.postMessage({ type: "result", ok: true, result });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
// Do not serialize arbitrary error objects from the scanner into the host.
|
|
21
|
+
parentPort?.postMessage({
|
|
22
|
+
type: "result",
|
|
23
|
+
ok: false,
|
|
24
|
+
aborted: error instanceof LocalScanAbortedError,
|
|
25
|
+
error: "the scan failed",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the potentially large local session scan away from Pi's TUI event loop.
|
|
3
|
+
* The worker runs the plain Node ESM entry point; the extension itself may be
|
|
4
|
+
* loaded through jiti, but this worker never needs that loader.
|
|
5
|
+
*
|
|
6
|
+
* The scan can outlive the surface that asked for it. A cold scan of a
|
|
7
|
+
* multi-gigabyte session store takes seconds, and the user may `/quit` or
|
|
8
|
+
* `/reload` a second later: a thread left behind keeps reading session files
|
|
9
|
+
* after the session is gone and holds `local-sessions.json.lock` until the
|
|
10
|
+
* 120 s stale timeout, so every later scan is read-only with a warning. The
|
|
11
|
+
* handle owns that lifecycle — the host stops it, and the stop always ends with
|
|
12
|
+
* the lock released and no half-written state.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Worker } from "node:worker_threads";
|
|
16
|
+
|
|
17
|
+
import { releaseHistoryLock } from "./history.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* How long a stopping scan gets to notice the flag and release its own lock
|
|
21
|
+
* before the thread is terminated and the parent releases the lock instead.
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_STOP_GRACE_MS = 2_000;
|
|
24
|
+
|
|
25
|
+
/** A scan the host stopped, told apart from a failure by its name. */
|
|
26
|
+
function scanStoppedError() {
|
|
27
|
+
const error = new Error("local token stats scan stopped");
|
|
28
|
+
error.name = "AbortError";
|
|
29
|
+
return error;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Start the scan in a worker thread.
|
|
34
|
+
*
|
|
35
|
+
* The stop request is a shared flag the scan polls rather than a message it has
|
|
36
|
+
* to be idle to receive: a cold scan spends its time inside synchronous reads
|
|
37
|
+
* and hashing, where a queued message would only be seen after the work it is
|
|
38
|
+
* meant to interrupt.
|
|
39
|
+
*
|
|
40
|
+
* @param {import("./pi-sessions.js").LocalStatsOptions} [options]
|
|
41
|
+
* @param {{
|
|
42
|
+
* graceMs?: number,
|
|
43
|
+
* spawn?: () => { on: Function, once: Function, postMessage: Function, terminate: () => Promise<number> },
|
|
44
|
+
* releaseLock?: (lock: { path: string, token: string | null }) => boolean,
|
|
45
|
+
* }} [lifecycle] Test seams: a fake worker and a zero grace period.
|
|
46
|
+
* @returns {{
|
|
47
|
+
* result: Promise<Awaited<ReturnType<typeof import("./pi-sessions.js").collectLocalStats>>>,
|
|
48
|
+
* stop: () => Promise<void>,
|
|
49
|
+
* }}
|
|
50
|
+
*/
|
|
51
|
+
export function startLocalStatsWorker(options = {}, lifecycle = {}) {
|
|
52
|
+
const graceMs = Number.isFinite(lifecycle.graceMs)
|
|
53
|
+
? Math.max(0, /** @type {number} */ (lifecycle.graceMs))
|
|
54
|
+
: DEFAULT_STOP_GRACE_MS;
|
|
55
|
+
const stopFlag = new Int32Array(new SharedArrayBuffer(4));
|
|
56
|
+
const releaseLock = lifecycle.releaseLock ?? releaseHistoryLock;
|
|
57
|
+
const worker = lifecycle.spawn
|
|
58
|
+
? lifecycle.spawn()
|
|
59
|
+
: new Worker(new URL("./stats-worker.js", import.meta.url), { workerData: { options, stopFlag } });
|
|
60
|
+
|
|
61
|
+
/** The lock the scan told us it holds; only its own token may remove it. */
|
|
62
|
+
/** @type {{ path: string, token: string | null } | null} */
|
|
63
|
+
let lock = null;
|
|
64
|
+
/** @type {{ ok: true, result: any } | { ok: false, aborted: boolean, error: string } | null} */
|
|
65
|
+
let outcome = null;
|
|
66
|
+
let stopping = false;
|
|
67
|
+
let settled = false;
|
|
68
|
+
/** @type {(value: any) => void} */
|
|
69
|
+
let resolveResult = () => {};
|
|
70
|
+
/** @type {(error: Error) => void} */
|
|
71
|
+
let rejectResult = () => {};
|
|
72
|
+
const result = new Promise((resolve, reject) => {
|
|
73
|
+
resolveResult = resolve;
|
|
74
|
+
rejectResult = reject;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const finish = () => {
|
|
78
|
+
if (settled) return;
|
|
79
|
+
settled = true;
|
|
80
|
+
const owned = lock;
|
|
81
|
+
lock = null;
|
|
82
|
+
// A scan that ended on its own already released this in its own `finally`;
|
|
83
|
+
// a thread that had to be killed did not, and its token is the only proof
|
|
84
|
+
// the file is still ours.
|
|
85
|
+
if (owned) releaseLock(owned);
|
|
86
|
+
if (outcome?.ok) resolveResult(outcome.result);
|
|
87
|
+
else rejectResult(outcome?.aborted ? scanStoppedError() : new Error(outcome?.error ?? "the worker thread failed"));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
worker.on("message", (message) => {
|
|
91
|
+
if (!message || typeof message !== "object") return;
|
|
92
|
+
if (message.type === "lock") {
|
|
93
|
+
if (typeof message.path === "string") {
|
|
94
|
+
lock = { path: message.path, token: typeof message.token === "string" ? message.token : null };
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (message.type !== "result") return;
|
|
99
|
+
outcome = message.ok
|
|
100
|
+
? { ok: true, result: message.result }
|
|
101
|
+
: {
|
|
102
|
+
ok: false,
|
|
103
|
+
aborted: message.aborted === true,
|
|
104
|
+
error: typeof message.error === "string" ? message.error : "the scan failed",
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
worker.once("error", () => {
|
|
108
|
+
// A thread that died (OOM, a broken entry point) never posts a result.
|
|
109
|
+
if (!outcome) outcome = { ok: false, aborted: stopping, error: "the worker thread failed" };
|
|
110
|
+
});
|
|
111
|
+
const exited = new Promise((resolve) => {
|
|
112
|
+
worker.once("exit", (code) => {
|
|
113
|
+
if (!outcome) {
|
|
114
|
+
outcome = stopping
|
|
115
|
+
? { ok: false, aborted: true, error: "local token stats scan stopped" }
|
|
116
|
+
: { ok: false, aborted: false, error: "the worker thread exited without a result" };
|
|
117
|
+
}
|
|
118
|
+
finish();
|
|
119
|
+
resolve(code);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* End the scan: ask it to stop, terminate the thread if it does not, and
|
|
125
|
+
* leave the report cache and the history exactly as they were found.
|
|
126
|
+
*/
|
|
127
|
+
const stop = async () => {
|
|
128
|
+
if (stopping) return;
|
|
129
|
+
stopping = true;
|
|
130
|
+
Atomics.store(stopFlag, 0, 1);
|
|
131
|
+
if (!settled) {
|
|
132
|
+
const stopped = await Promise.race([
|
|
133
|
+
exited.then(() => true),
|
|
134
|
+
new Promise((resolve) => {
|
|
135
|
+
const timer = setTimeout(() => resolve(false), graceMs);
|
|
136
|
+
timer.unref?.();
|
|
137
|
+
}),
|
|
138
|
+
]);
|
|
139
|
+
if (!stopped) await worker.terminate().catch(() => 0);
|
|
140
|
+
}
|
|
141
|
+
await exited;
|
|
142
|
+
finish();
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
return { result, stop };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Await one scan to completion. The caller that wants the lifecycle uses
|
|
150
|
+
* {@link startLocalStatsWorker} instead.
|
|
151
|
+
*
|
|
152
|
+
* @param {import("./pi-sessions.js").LocalStatsOptions} [options]
|
|
153
|
+
* @returns {Promise<Awaited<ReturnType<typeof import("./pi-sessions.js").collectLocalStats>>>}
|
|
154
|
+
*/
|
|
155
|
+
export function collectLocalStatsInWorker(options = {}) {
|
|
156
|
+
return startLocalStatsWorker(options).result;
|
|
157
|
+
}
|
package/src/model.js
CHANGED
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
* @property {string} source Credential source description.
|
|
34
34
|
* @property {"pi" | "claude-code"} [sourceKind] Which kind of store produced it.
|
|
35
35
|
* @property {string | null} expiresInMin Credential freshness, when known.
|
|
36
|
+
* @property {true} [tokenRenewedInMemory] Present only when the provider renewed
|
|
37
|
+
* this token in memory for this run: the
|
|
38
|
+
* stored credential's freshness then no
|
|
39
|
+
* longer describes the request made.
|
|
36
40
|
*/
|
|
37
41
|
|
|
38
42
|
/**
|
|
@@ -247,6 +251,7 @@ export function humanReset(seconds) {
|
|
|
247
251
|
* source: string,
|
|
248
252
|
* now?: number,
|
|
249
253
|
* expiresInMin?: number | null,
|
|
254
|
+
* tokenRenewedInMemory?: boolean,
|
|
250
255
|
* windows?: QuotaWindow[],
|
|
251
256
|
* }} input
|
|
252
257
|
* @returns {QuotaResult}
|
|
@@ -256,7 +261,7 @@ export function degradedResult(input) {
|
|
|
256
261
|
input.notConfigured ??
|
|
257
262
|
(typeof input.error === "string" && input.error.startsWith("no ") && input.error.includes("credential in the Pi store")),
|
|
258
263
|
);
|
|
259
|
-
|
|
264
|
+
const result = {
|
|
260
265
|
family: input.family,
|
|
261
266
|
label: input.label,
|
|
262
267
|
account: input.account ?? "unknown",
|
|
@@ -270,6 +275,27 @@ export function degradedResult(input) {
|
|
|
270
275
|
sourceKind: input.sourceKind,
|
|
271
276
|
expiresInMin: input.expiresInMin ?? null,
|
|
272
277
|
};
|
|
278
|
+
// Only ever present when a provider renewed the token in memory: a field on
|
|
279
|
+
// every result would be one more thing the JSON feed promises to keep.
|
|
280
|
+
if (input.tokenRenewedInMemory === true) result.tokenRenewedInMemory = true;
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Which field `displayIdentity` would print for this credential.
|
|
286
|
+
*
|
|
287
|
+
* A provider that adds a second identifier of its own (Antigravity's Cloud Code
|
|
288
|
+
* project) needs to know whether the identity already *is* that identifier, or
|
|
289
|
+
* it prints the same value twice.
|
|
290
|
+
*
|
|
291
|
+
* @param {{ email?: string | null, accountId?: string | null, projectId?: string | null, identity?: string }} credential
|
|
292
|
+
* @returns {"email" | "accountId" | "projectId" | "identity" | "none"}
|
|
293
|
+
*/
|
|
294
|
+
export function identityKind(credential) {
|
|
295
|
+
if (credential.email) return "email";
|
|
296
|
+
if (credential.accountId) return "accountId";
|
|
297
|
+
if (credential.projectId) return "projectId";
|
|
298
|
+
return credential.identity ? "identity" : "none";
|
|
273
299
|
}
|
|
274
300
|
|
|
275
301
|
/**
|
|
@@ -279,10 +305,18 @@ export function degradedResult(input) {
|
|
|
279
305
|
* @returns {string}
|
|
280
306
|
*/
|
|
281
307
|
export function displayIdentity(credential) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
308
|
+
switch (identityKind(credential)) {
|
|
309
|
+
case "email":
|
|
310
|
+
return /** @type {string} */ (credential.email);
|
|
311
|
+
case "accountId":
|
|
312
|
+
return `${/** @type {string} */ (credential.accountId).slice(0, 8)}…`;
|
|
313
|
+
case "projectId":
|
|
314
|
+
return `project ${/** @type {string} */ (credential.projectId).slice(0, 8)}…`;
|
|
315
|
+
case "identity":
|
|
316
|
+
return `id ${/** @type {string} */ (credential.identity).slice(0, 8)}…`;
|
|
317
|
+
default:
|
|
318
|
+
return "unknown";
|
|
319
|
+
}
|
|
286
320
|
}
|
|
287
321
|
|
|
288
322
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg viewBox="0 0 10 10" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect x="0" y="0" width="2" height="2" fill="#FFD800"/>
|
|
3
|
+
<rect x="8" y="0" width="2" height="2" fill="#FFD800"/>
|
|
4
|
+
<rect x="0" y="2" width="2" height="2" fill="#FFAF00"/>
|
|
5
|
+
<rect x="2" y="2" width="2" height="2" fill="#FFAF00"/>
|
|
6
|
+
<rect x="6" y="2" width="2" height="2" fill="#FFAF00"/>
|
|
7
|
+
<rect x="8" y="2" width="2" height="2" fill="#FFAF00"/>
|
|
8
|
+
<rect x="0" y="4" width="2" height="2" fill="#FF8205"/>
|
|
9
|
+
<rect x="2" y="4" width="2" height="2" fill="#FF8205"/>
|
|
10
|
+
<rect x="4" y="4" width="2" height="2" fill="#FF8205"/>
|
|
11
|
+
<rect x="6" y="4" width="2" height="2" fill="#FF8205"/>
|
|
12
|
+
<rect x="8" y="4" width="2" height="2" fill="#FF8205"/>
|
|
13
|
+
<rect x="0" y="6" width="2" height="2" fill="#FA500F"/>
|
|
14
|
+
<rect x="4" y="6" width="2" height="2" fill="#FA500F"/>
|
|
15
|
+
<rect x="8" y="6" width="2" height="2" fill="#FA500F"/>
|
|
16
|
+
<rect x="0" y="8" width="2" height="2" fill="#E10500"/>
|
|
17
|
+
<rect x="8" y="8" width="2" height="2" fill="#E10500"/>
|
|
18
|
+
</svg>
|
package/src/omarchy/publish.js
CHANGED
|
@@ -61,7 +61,7 @@ function writeRecord(dir, id, record) {
|
|
|
61
61
|
* no longer present.
|
|
62
62
|
*
|
|
63
63
|
* @param {Array<{ id: string, record: Record<string, unknown> }>} records
|
|
64
|
-
* @param {{ dir?: string, env?: Record<string, string | undefined>, home?: string }} [options]
|
|
64
|
+
* @param {{ dir?: string, env?: Record<string, string | undefined>, home?: string, prune?: boolean }} [options]
|
|
65
65
|
* @returns {{ dir: string, written: string[], removed: string[] }}
|
|
66
66
|
*/
|
|
67
67
|
export function publishRecords(records, options = {}) {
|
|
@@ -74,15 +74,16 @@ export function publishRecords(records, options = {}) {
|
|
|
74
74
|
written.push(writeRecord(dir, id, record));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const keep = new Set(records.map(({ id }) => `${id}.json`));
|
|
78
77
|
const removed = [];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
if (options.prune !== false) {
|
|
79
|
+
const keep = new Set(records.map(({ id }) => `${id}.json`));
|
|
80
|
+
for (const name of readdirSync(dir)) {
|
|
81
|
+
if (!name.startsWith(RECORD_PREFIX) || !name.endsWith(".json")) continue;
|
|
82
|
+
if (!isPiRecordId(name.slice(0, -".json".length)) || keep.has(name)) continue;
|
|
83
|
+
rmSync(join(dir, name), { force: true });
|
|
84
|
+
removed.push(join(dir, name));
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
87
88
|
return { dir, written, removed };
|
|
88
89
|
}
|
package/src/omarchy/record.js
CHANGED
|
@@ -38,6 +38,7 @@ const LOGIN_HINT = {
|
|
|
38
38
|
codex: "Run `/login openai-codex` in Pi to restore usage.",
|
|
39
39
|
antigravity: "Run `/login antigravity` in Pi to restore usage.",
|
|
40
40
|
"opencode-go": "Run `piquota auth opencode` to restore usage.",
|
|
41
|
+
mistral: "Run `/login mistral` in Pi to restore usage.",
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
const HELP_MAX = 200;
|
|
@@ -118,9 +119,11 @@ function mapLimits(windows, provider, prefix = "") {
|
|
|
118
119
|
for (const window of windows ?? []) {
|
|
119
120
|
// A window without a percentage would otherwise read as "0% used".
|
|
120
121
|
if (typeof window.usedPercent !== "number" || !Number.isFinite(window.usedPercent)) continue;
|
|
122
|
+
// Spending past the allowance changes what 100% means, so the title says so.
|
|
123
|
+
const payg = typeof window.note === "string" && /pay-as-you-go/i.test(window.note) ? " · pay-as-you-go" : "";
|
|
121
124
|
limits.push({
|
|
122
125
|
label: redact(`${prefix}${window.label || window.id || "Limit"}`),
|
|
123
|
-
title: redact(`${prefix}${windowTitle(window, provider)}`),
|
|
126
|
+
title: redact(`${prefix}${windowTitle(window, provider)}${payg}`),
|
|
124
127
|
percent: Math.min(1, Math.max(0, window.usedPercent / 100)),
|
|
125
128
|
resetsAt: typeof window.resetsAt === "string" ? window.resetsAt : "",
|
|
126
129
|
});
|
|
@@ -184,20 +187,19 @@ function recordTierLabel(provider) {
|
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
/**
|
|
187
|
-
* Slot label of one account: "" for the base entry
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* the
|
|
190
|
+
* Slot label of one account: "#1" for the base entry, "#<slot>" for a sibling
|
|
191
|
+
* ("#2", "#1-api"). Never the account's identity: a Claude or Codex identity
|
|
192
|
+
* ("id c64efc0f…") is not a slot and does not fit the label column. A report
|
|
193
|
+
* cached while the base was unlabelled says "" for it, which is "#1" again.
|
|
191
194
|
*
|
|
192
195
|
* @param {import("../model.js").QuotaResult} provider
|
|
193
196
|
* @returns {string}
|
|
194
197
|
*/
|
|
195
198
|
function accountLabel(provider) {
|
|
196
|
-
if (typeof provider.slot === "string"
|
|
199
|
+
if (typeof provider.slot === "string" && provider.slot !== "") return `#${provider.slot}`;
|
|
200
|
+
if (provider.slot === null || provider.slot === "") return "#1";
|
|
197
201
|
const account = typeof provider.account === "string" ? provider.account : "";
|
|
198
|
-
|
|
199
|
-
if (/^#\d+$/.test(account)) return account;
|
|
200
|
-
return account;
|
|
202
|
+
return /^#[0-9][\w-]*$/.test(account) ? account : "#1";
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
/**
|
|
@@ -336,11 +338,8 @@ function compactFailureList(failures) {
|
|
|
336
338
|
labels.push(failures[index].label);
|
|
337
339
|
index += 1;
|
|
338
340
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const named = labels.map((label) => (label === "" ? "base" : label));
|
|
342
|
-
const names = compactLabels(named);
|
|
343
|
-
groups.push(named.length === 1 && named[0] === "base" ? reason : `${names} ${reason}`);
|
|
341
|
+
const names = compactLabels(labels);
|
|
342
|
+
groups.push(`${names} ${reason}`);
|
|
344
343
|
}
|
|
345
344
|
const text = redact(groups.join(" · "));
|
|
346
345
|
return text.length <= HELP_MAX ? text : `${text.slice(0, HELP_MAX - 1).trimEnd()}…`;
|
|
@@ -382,9 +381,13 @@ function buildFamilyRecord(family, providers, options = {}) {
|
|
|
382
381
|
if (provider.ok) {
|
|
383
382
|
okCount += 1;
|
|
384
383
|
const window = bindingWindow(provider.windows);
|
|
385
|
-
const mapped = window ? mapLimits([window], provider,
|
|
384
|
+
const mapped = window ? mapLimits([window], provider, `${label} · `)[0] : null;
|
|
386
385
|
if (mapped) limits.push(mapped);
|
|
387
|
-
|
|
386
|
+
const accountLimits = mapLimits(provider.windows, provider);
|
|
387
|
+
// An account that answered without windows (Mistral without the usage
|
|
388
|
+
// permission) says why instead of showing an empty row.
|
|
389
|
+
const quiet = accountLimits.length === 0 && typeof provider.note === "string" ? redact(provider.note).slice(0, HELP_MAX) : "";
|
|
390
|
+
accounts.push({ id: redact(label), ok: true, status: quiet, limits: accountLimits });
|
|
388
391
|
return;
|
|
389
392
|
}
|
|
390
393
|
failures.push({ label, reason: failureReason(provider.error) });
|
|
@@ -481,9 +484,11 @@ export function buildRecord(provider, options = {}) {
|
|
|
481
484
|
|
|
482
485
|
if (failed && errorKind(provider.error) === "missing") return null;
|
|
483
486
|
|
|
484
|
-
const status =
|
|
485
|
-
?
|
|
486
|
-
:
|
|
487
|
+
const status = provider.ok && limits.length === 0 && typeof provider.note === "string" && provider.note !== ""
|
|
488
|
+
? { usageStatusText: "Usage not visible", authHelpText: redact(provider.note).slice(0, HELP_MAX) }
|
|
489
|
+
: failed
|
|
490
|
+
? describeError(provider.family, provider.error ?? "no usage windows")
|
|
491
|
+
: { usageStatusText: "", authHelpText: "" };
|
|
487
492
|
|
|
488
493
|
const id = recordId(provider.family);
|
|
489
494
|
return {
|