@lobehub/cli 0.0.105 → 0.0.106

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 CHANGED
@@ -18546,7 +18546,7 @@ const DEFAULT_AGENT_CONFIG = {
18546
18546
 
18547
18547
  //#endregion
18548
18548
  //#region ../../package.json
18549
- var version$2 = "2.3.3";
18549
+ var version$2 = "2.3.4";
18550
18550
 
18551
18551
  //#endregion
18552
18552
  //#region ../../packages/const/src/version.ts
@@ -59697,6 +59697,11 @@ const clampPercent = (value) => Math.min(100, Math.max(0, Math.round(value)));
59697
59697
  */
59698
59698
  const hasWindowRolledOver = (reading, now) => reading.resetsAt == null ? now - reading.capturedAt > (reading.windowMinutes == null ? windowSecondsForKind(reading.limitType) : reading.windowMinutes * 60) * 1e3 : reading.resetsAt <= now;
59699
59699
  /**
59700
+ * Utilization of the window that is live *now*: a rolled-over window refilled,
59701
+ * so it reads 0 rather than replaying the spent window's last value.
59702
+ */
59703
+ const currentUtilization = (reading, now) => hasWindowRolledOver(reading, now) ? 0 : clampPercent(reading.utilization);
59704
+ /**
59700
59705
  * Drop the limits the provider has stopped reporting. A sample reports every
59701
59706
  * limit the plan has — an idle window too, against a reset already in the past
59702
59707
  * — so a limit missing from a sample taken after its window ended is one the
@@ -561845,7 +561850,7 @@ const admissionHint = {
561845
561850
  wait_unsettled: "unfinished work must be settled before waiting",
561846
561851
  wait_until_past: "the wait deadline is already in the past"
561847
561852
  };
561848
- const toIso = (value) => value instanceof Date ? value.toISOString() : new Date(value).toISOString();
561853
+ const toIso$1 = (value) => value instanceof Date ? value.toISOString() : new Date(value).toISOString();
561849
561854
  const shortHash = (hash) => hash ? `${hash.slice(0, 12)}…` : "—";
561850
561855
  /**
561851
561856
  * Recorded receipt against what the server computes now. The snapshot a plan is
@@ -561898,7 +561903,7 @@ function printGoalState(graph, context, events) {
561898
561903
  if (context.queue) field("Queue", `${context.queue.unfinishedTasks} unfinished task(s) · ${context.queue.pendingDecisions} pending decision(s)`);
561899
561904
  if (events.length > 0) {
561900
561905
  console.log(`\n ${import_picocolors.default.bold("Recent events")} ${import_picocolors.default.dim(`(newest ${events.length})`)}`);
561901
- for (const event of events) console.log(` ${import_picocolors.default.dim(toIso(event.createdAt))} ${event.entityType} ${event.eventType}${event.reason ? ` ${truncate$2(event.reason, 76)}` : ""}`);
561906
+ for (const event of events) console.log(` ${import_picocolors.default.dim(toIso$1(event.createdAt))} ${event.entityType} ${event.eventType}${event.reason ? ` ${truncate$2(event.reason, 76)}` : ""}`);
561902
561907
  }
561903
561908
  }
561904
561909
  /**
@@ -562213,7 +562218,7 @@ function registerGoalCommand$1(program) {
562213
562218
  if (options.json !== void 0) return outputJson(result.data, options.json);
562214
562219
  if (result.data.events.length === 0) return log$15.info("No events.");
562215
562220
  printTable(result.data.events.map((event) => [
562216
- toIso(event.createdAt),
562221
+ toIso$1(event.createdAt),
562217
562222
  `${event.entityType} ${event.eventType}`,
562218
562223
  event.actorType,
562219
562224
  truncate$2(event.reason ?? "-", 64),
@@ -586714,6 +586719,216 @@ function registerProviderCommand(program) {
586714
586719
  });
586715
586720
  }
586716
586721
 
586722
+ //#endregion
586723
+ //#region src/commands/quota.ts
586724
+ /** At or above this utilization an account is close to being benched. */
586725
+ const WARNING_UTILIZATION = 80;
586726
+ const windowKind = (reading) => {
586727
+ if (isSessionLimit(reading)) return "session";
586728
+ if (isScopedWeeklyLimit(reading)) return `weekly:${reading.scopeKey}`;
586729
+ if (isWeeklyAllLimit(reading)) return "weekly";
586730
+ return reading.scopeKey ? `${reading.limitType}:${reading.scopeKey}` : reading.limitType;
586731
+ };
586732
+ const toIso = (ms) => ms ? new Date(ms).toISOString() : null;
586733
+ /**
586734
+ * Fold an account's latest readings into one status. Any window at 100% benches
586735
+ * the account until the latest of those windows resets — a full weekly blocks
586736
+ * runs just as a full session does.
586737
+ */
586738
+ const buildAccountView = (account, readings, now = Date.now()) => {
586739
+ let status = readings.length ? "ok" : "unknown";
586740
+ let unavailableUntil = null;
586741
+ const windows = readings.map((reading) => {
586742
+ const utilization = currentUtilization(reading, now);
586743
+ if (utilization >= 100 || reading.rateLimited && utilization > 0) {
586744
+ status = "exhausted";
586745
+ if (reading.resetsAt) unavailableUntil = Math.max(unavailableUntil ?? 0, reading.resetsAt);
586746
+ } else if (utilization >= WARNING_UTILIZATION && status !== "exhausted") status = "warning";
586747
+ return {
586748
+ kind: windowKind(reading),
586749
+ limitType: reading.limitType,
586750
+ resetsAt: toIso(reading.resetsAt),
586751
+ scopeKey: reading.scopeKey,
586752
+ utilization
586753
+ };
586754
+ });
586755
+ const newest = readings.reduce((max, r) => Math.max(max, r.capturedAt), 0);
586756
+ return {
586757
+ accountId: account.id,
586758
+ displayName: account.displayName ?? null,
586759
+ email: account.email ?? null,
586760
+ enabled: account.enabled ?? true,
586761
+ label: account.label ?? null,
586762
+ planTier: account.planTier ?? null,
586763
+ provider: account.provider,
586764
+ status,
586765
+ unavailableUntil: toIso(unavailableUntil),
586766
+ updatedAt: toIso(newest),
586767
+ windows
586768
+ };
586769
+ };
586770
+ const loadAccountViews = async (client, accounts) => Promise.all(accounts.map(async (account) => buildAccountView(account, await client.agentQuota.getLatestReadings.query({ accountId: account.id }))));
586771
+ const accountName = (view) => view.label || view.email || view.displayName || view.accountId;
586772
+ const formatStatus = (view) => {
586773
+ switch (view.status) {
586774
+ case "exhausted": return import_picocolors.default.red(view.unavailableUntil ? `exhausted (resets ${timeUntil(view.unavailableUntil)})` : "exhausted");
586775
+ case "warning": return import_picocolors.default.yellow("warning");
586776
+ case "ok": return import_picocolors.default.green("ok");
586777
+ default: return import_picocolors.default.dim("no data");
586778
+ }
586779
+ };
586780
+ const formatWindow = (view, kind) => {
586781
+ const window = view.windows.find((w) => w.kind === kind);
586782
+ if (!window) return "-";
586783
+ const reset = window.resetsAt ? import_picocolors.default.dim(` ${timeUntil(window.resetsAt)}`) : "";
586784
+ return `${window.utilization}%${reset}`;
586785
+ };
586786
+ const formatScopedWeekly = (view) => view.windows.filter((w) => w.kind.startsWith("weekly:")).map((w) => `${w.scopeKey} ${w.utilization}%`).join(", ") || "-";
586787
+ const printAccountTable = (views) => {
586788
+ printTable(views.map((view) => [
586789
+ view.accountId,
586790
+ view.provider,
586791
+ accountName(view),
586792
+ formatWindow(view, "session"),
586793
+ formatWindow(view, "weekly"),
586794
+ formatScopedWeekly(view),
586795
+ formatStatus(view),
586796
+ view.updatedAt ? timeAgo(view.updatedAt) : "-"
586797
+ ]), [
586798
+ "ACCOUNT ID",
586799
+ "PROVIDER",
586800
+ "NAME",
586801
+ "5H",
586802
+ "WEEKLY",
586803
+ "MODEL WEEKLY",
586804
+ "STATUS",
586805
+ "UPDATED"
586806
+ ]);
586807
+ };
586808
+ const emitJson = (data, json) => outputJson(data, typeof json === "string" ? json : void 0);
586809
+ function registerQuotaCommand(program) {
586810
+ const quota = program.command("quota").description("Read subscription quota of agent runtimes (Claude Code / Codex / Kimi Code accounts)");
586811
+ quota.command("list").description("List subscription accounts with their current quota windows").option("--provider <provider>", "Only this provider: claude-code, codex or kimi-code").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").option("--workspace <id|slug>", "Read the workspace's shared accounts").action(async (options) => {
586812
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586813
+ const views = await loadAccountViews(client, (await client.agentQuota.listAccounts.query()).filter((account) => !options.provider || account.provider === options.provider));
586814
+ if (options.json !== void 0) return emitJson(views, options.json);
586815
+ if (views.length === 0) {
586816
+ console.log("No subscription accounts found.");
586817
+ console.log(import_picocolors.default.dim("Accounts appear once a device running Claude Code / Codex / Kimi Code reports quota."));
586818
+ return;
586819
+ }
586820
+ printAccountTable(views);
586821
+ });
586822
+ quota.command("view <accountId>").description("Show one account: every quota window and the agent runs spending it now").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").option("--workspace <id|slug>", "Read the account in this workspace context").action(async (accountId, options) => {
586823
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586824
+ const account = (await client.agentQuota.listAccounts.query()).find((a) => a.id === accountId);
586825
+ if (!account) {
586826
+ log$15.error(`Account "${accountId}" not found. Run 'lh quota list' to see accounts.`);
586827
+ process.exit(1);
586828
+ return;
586829
+ }
586830
+ const [view] = await loadAccountViews(client, [account]);
586831
+ const activeRuns = await client.agentQuota.listActiveRuns.query({ accountId });
586832
+ const result = {
586833
+ ...view,
586834
+ activeRuns
586835
+ };
586836
+ if (options.json !== void 0) return emitJson(result, options.json);
586837
+ console.log(`${import_picocolors.default.bold(accountName(view))} ${import_picocolors.default.dim(`(${view.provider})`)}`);
586838
+ console.log(`Status: ${formatStatus(view)}`);
586839
+ if (view.updatedAt) console.log(import_picocolors.default.dim(`Updated ${timeAgo(view.updatedAt)}`));
586840
+ console.log();
586841
+ if (view.windows.length) printTable(view.windows.map((w) => [
586842
+ w.kind,
586843
+ `${w.utilization}%`,
586844
+ w.resetsAt ? timeUntil(w.resetsAt) : "-"
586845
+ ]), [
586846
+ "WINDOW",
586847
+ "USED",
586848
+ "RESETS"
586849
+ ]);
586850
+ else console.log(import_picocolors.default.dim("No quota readings yet."));
586851
+ if (activeRuns.length) {
586852
+ console.log();
586853
+ console.log(import_picocolors.default.bold("Active runs"));
586854
+ printTable(activeRuns.map((run) => [
586855
+ run.agentTitle ?? run.agentId ?? "-",
586856
+ run.topicTitle ?? run.topicId ?? "-",
586857
+ run.lastTurnAt ? timeAgo(new Date(run.lastTurnAt)) : "-"
586858
+ ]), [
586859
+ "AGENT",
586860
+ "TOPIC",
586861
+ "LAST TURN"
586862
+ ]);
586863
+ }
586864
+ });
586865
+ quota.command("agent <agentId>").description("Quota of the account(s) an agent runs on: the account it would use now, and every bound account").option("--device <deviceId>", "Resolve the account the agent uses on this device").option("--provider <provider>", "Runtime provider: claude-code, codex or kimi-code").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").option("--workspace <id|slug>", "Read the agent in this workspace context").action(async (agentId, options) => {
586866
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586867
+ const [selected, bindings, accounts] = await Promise.all([
586868
+ client.agentQuota.selectAccountForAgent.query({
586869
+ agentId,
586870
+ deviceId: options.device,
586871
+ provider: options.provider
586872
+ }),
586873
+ client.agentQuota.listBindings.query({ agentId }),
586874
+ client.agentQuota.listAccounts.query()
586875
+ ]);
586876
+ const byId = new Map(accounts.map((a) => [a.id, a]));
586877
+ const boundIds = new Set(bindings.filter((b) => b.role !== "disabled").map((b) => b.accountId));
586878
+ if (selected?.accountId) boundIds.add(selected.accountId);
586879
+ const views = await loadAccountViews(client, [...boundIds].map((id) => byId.get(id)).filter(Boolean));
586880
+ const current = views.find((v) => v.accountId === selected?.accountId) ?? null;
586881
+ const result = {
586882
+ agentId,
586883
+ current: current && {
586884
+ ...current,
586885
+ reason: selected?.reason ?? null
586886
+ },
586887
+ accounts: views
586888
+ };
586889
+ if (options.json !== void 0) return emitJson(result, options.json);
586890
+ if (!views.length) {
586891
+ console.log(`No subscription account is bound to agent ${agentId}.`);
586892
+ return;
586893
+ }
586894
+ if (current) {
586895
+ console.log(`Current account: ${import_picocolors.default.bold(accountName(current))} ${import_picocolors.default.dim(`(${selected?.reason})`)} — ${formatStatus(current)}`);
586896
+ console.log();
586897
+ }
586898
+ printAccountTable(views);
586899
+ });
586900
+ quota.command("refresh").description("Sample quota on a device now (codex / kimi-code; Claude Code is reported by the desktop app)").requiredOption("--device <deviceId>", "Device to sample on (see `lh device list`)").requiredOption("--provider <provider>", "codex or kimi-code").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").option("--workspace <id|slug>", "Reach the device through this workspace context").action(async (options) => {
586901
+ if (options.provider !== "codex" && options.provider !== "kimi-code") {
586902
+ log$15.error(`Cannot refresh "${options.provider}" on demand; only codex and kimi-code are sampled through the device.`);
586903
+ process.exit(1);
586904
+ return;
586905
+ }
586906
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586907
+ const input = {
586908
+ deviceId: options.device,
586909
+ force: true
586910
+ };
586911
+ const snapshot = options.provider === "codex" ? await client.agentQuota.refreshCodexQuota.mutate(input) : await client.agentQuota.refreshKimiCodeQuota.mutate(input);
586912
+ if (options.json !== void 0) return emitJson(snapshot, options.json);
586913
+ if (!snapshot) {
586914
+ log$15.error(`Device "${options.device}" is not reachable.`);
586915
+ process.exit(1);
586916
+ return;
586917
+ }
586918
+ if (snapshot.status !== "ok") {
586919
+ log$15.error(`Refresh failed: ${snapshot.error ?? snapshot.status}`);
586920
+ process.exit(1);
586921
+ return;
586922
+ }
586923
+ const who = snapshot.identity?.email ?? snapshot.identity?.externalAccountId ?? "account";
586924
+ console.log(`${import_picocolors.default.green("✓")} Refreshed ${options.provider} quota for ${who}`);
586925
+ for (const reading of snapshot.readings ?? []) {
586926
+ const reset = reading.resetsAt ? import_picocolors.default.dim(` (resets ${timeUntil(new Date(reading.resetsAt))})`) : "";
586927
+ console.log(` ${windowKind(reading)}: ${reading.utilization}%${reset}`);
586928
+ }
586929
+ });
586930
+ }
586931
+
586717
586932
  //#endregion
586718
586933
  //#region src/commands/read.ts
586719
586934
  /** Extract the share id from a `.../share/t/<id>[/llm.txt]` URL. */
@@ -591761,6 +591976,7 @@ function createProgram() {
591761
591976
  registerManCommand(program);
591762
591977
  registerConnectCommand(program);
591763
591978
  registerDeviceCommand(program);
591979
+ registerQuotaCommand(program);
591764
591980
  registerStatusCommand(program);
591765
591981
  registerDoctorCommand(program);
591766
591982
  registerDocCommand(program);
package/man/man1/lh.1 CHANGED
@@ -1,6 +1,6 @@
1
1
  .\" Code generated by `npm run man:generate`; DO NOT EDIT.
2
2
  .\" Manual command details come from the Commander command tree.
3
- .TH LH 1 "" "@lobehub/cli 0.0.105" "User Commands"
3
+ .TH LH 1 "" "@lobehub/cli 0.0.106" "User Commands"
4
4
  .SH NAME
5
5
  lh \- LobeHub CLI \- manage and connect to LobeHub services
6
6
  .SH SYNOPSIS
@@ -50,6 +50,9 @@ Disconnect from the device gateway (alias for `connect stop`)
50
50
  .B device
51
51
  Manage connected devices
52
52
  .TP
53
+ .B quota
54
+ Read subscription quota of agent runtimes (Claude Code / Codex / Kimi Code accounts)
55
+ .TP
53
56
  .B status
54
57
  Check if gateway connection can be established
55
58
  .TP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/cli",
3
- "version": "0.0.105",
3
+ "version": "0.0.106",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/lobehub/lobehub",
@@ -83,5 +83,5 @@
83
83
  "access": "public",
84
84
  "registry": "https://registry.npmjs.org"
85
85
  },
86
- "gitHead": "ccdcdcf9f63b335135ae75ca4ac6e82c7c628687"
86
+ "gitHead": "d3118e13395dccac892746716843c6b0c8eedd18"
87
87
  }