@lobehub/cli 0.0.105 → 0.0.107

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
@@ -63610,7 +63615,8 @@ const createCodexAgentHandle = async (options) => {
63610
63615
  get sessionId() {
63611
63616
  return nativeSessionId;
63612
63617
  },
63613
- stderr
63618
+ stderr,
63619
+ supportsSteerImageAttachments: true
63614
63620
  };
63615
63621
  };
63616
63622
 
@@ -561845,7 +561851,7 @@ const admissionHint = {
561845
561851
  wait_unsettled: "unfinished work must be settled before waiting",
561846
561852
  wait_until_past: "the wait deadline is already in the past"
561847
561853
  };
561848
- const toIso = (value) => value instanceof Date ? value.toISOString() : new Date(value).toISOString();
561854
+ const toIso$1 = (value) => value instanceof Date ? value.toISOString() : new Date(value).toISOString();
561849
561855
  const shortHash = (hash) => hash ? `${hash.slice(0, 12)}…` : "—";
561850
561856
  /**
561851
561857
  * Recorded receipt against what the server computes now. The snapshot a plan is
@@ -561898,7 +561904,7 @@ function printGoalState(graph, context, events) {
561898
561904
  if (context.queue) field("Queue", `${context.queue.unfinishedTasks} unfinished task(s) · ${context.queue.pendingDecisions} pending decision(s)`);
561899
561905
  if (events.length > 0) {
561900
561906
  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)}` : ""}`);
561907
+ 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
561908
  }
561903
561909
  }
561904
561910
  /**
@@ -562213,7 +562219,7 @@ function registerGoalCommand$1(program) {
562213
562219
  if (options.json !== void 0) return outputJson(result.data, options.json);
562214
562220
  if (result.data.events.length === 0) return log$15.info("No events.");
562215
562221
  printTable(result.data.events.map((event) => [
562216
- toIso(event.createdAt),
562222
+ toIso$1(event.createdAt),
562217
562223
  `${event.entityType} ${event.eventType}`,
562218
562224
  event.actorType,
562219
562225
  truncate$2(event.reason ?? "-", 64),
@@ -582548,6 +582554,7 @@ async function* withHeteroSteer(handle, context) {
582548
582554
  try {
582549
582555
  const res = await client.aiAgent.waitHeteroSteer.mutate({
582550
582556
  ...acceptsControl && { acceptsControl: true },
582557
+ ...handle.supportsSteerImageAttachments && { acceptsImageAttachments: true },
582551
582558
  acceptsImages: true,
582552
582559
  ...!answered && { blockMs: 1 },
582553
582560
  ...waitingForUser() && { holdSteer: true },
@@ -582578,7 +582585,7 @@ async function* withHeteroSteer(handle, context) {
582578
582585
  const steer = message;
582579
582586
  const options = { uuid: steer.messageId };
582580
582587
  if (await send(buildSteerPrompt(steer), options).catch(async (error) => {
582581
- if (!steer.imageList?.length) return false;
582588
+ if (steer.requiresImages || !steer.imageList?.length) return false;
582582
582589
  log$15.debug("Steer images failed, sending the text: %s", String(error));
582583
582590
  return send(steer.content, options).catch(() => false);
582584
582591
  })) {
@@ -586714,6 +586721,216 @@ function registerProviderCommand(program) {
586714
586721
  });
586715
586722
  }
586716
586723
 
586724
+ //#endregion
586725
+ //#region src/commands/quota.ts
586726
+ /** At or above this utilization an account is close to being benched. */
586727
+ const WARNING_UTILIZATION = 80;
586728
+ const windowKind = (reading) => {
586729
+ if (isSessionLimit(reading)) return "session";
586730
+ if (isScopedWeeklyLimit(reading)) return `weekly:${reading.scopeKey}`;
586731
+ if (isWeeklyAllLimit(reading)) return "weekly";
586732
+ return reading.scopeKey ? `${reading.limitType}:${reading.scopeKey}` : reading.limitType;
586733
+ };
586734
+ const toIso = (ms) => ms ? new Date(ms).toISOString() : null;
586735
+ /**
586736
+ * Fold an account's latest readings into one status. Any window at 100% benches
586737
+ * the account until the latest of those windows resets — a full weekly blocks
586738
+ * runs just as a full session does.
586739
+ */
586740
+ const buildAccountView = (account, readings, now = Date.now()) => {
586741
+ let status = readings.length ? "ok" : "unknown";
586742
+ let unavailableUntil = null;
586743
+ const windows = readings.map((reading) => {
586744
+ const utilization = currentUtilization(reading, now);
586745
+ if (utilization >= 100 || reading.rateLimited && utilization > 0) {
586746
+ status = "exhausted";
586747
+ if (reading.resetsAt) unavailableUntil = Math.max(unavailableUntil ?? 0, reading.resetsAt);
586748
+ } else if (utilization >= WARNING_UTILIZATION && status !== "exhausted") status = "warning";
586749
+ return {
586750
+ kind: windowKind(reading),
586751
+ limitType: reading.limitType,
586752
+ resetsAt: toIso(reading.resetsAt),
586753
+ scopeKey: reading.scopeKey,
586754
+ utilization
586755
+ };
586756
+ });
586757
+ const newest = readings.reduce((max, r) => Math.max(max, r.capturedAt), 0);
586758
+ return {
586759
+ accountId: account.id,
586760
+ displayName: account.displayName ?? null,
586761
+ email: account.email ?? null,
586762
+ enabled: account.enabled ?? true,
586763
+ label: account.label ?? null,
586764
+ planTier: account.planTier ?? null,
586765
+ provider: account.provider,
586766
+ status,
586767
+ unavailableUntil: toIso(unavailableUntil),
586768
+ updatedAt: toIso(newest),
586769
+ windows
586770
+ };
586771
+ };
586772
+ const loadAccountViews = async (client, accounts) => Promise.all(accounts.map(async (account) => buildAccountView(account, await client.agentQuota.getLatestReadings.query({ accountId: account.id }))));
586773
+ const accountName = (view) => view.label || view.email || view.displayName || view.accountId;
586774
+ const formatStatus = (view) => {
586775
+ switch (view.status) {
586776
+ case "exhausted": return import_picocolors.default.red(view.unavailableUntil ? `exhausted (resets ${timeUntil(view.unavailableUntil)})` : "exhausted");
586777
+ case "warning": return import_picocolors.default.yellow("warning");
586778
+ case "ok": return import_picocolors.default.green("ok");
586779
+ default: return import_picocolors.default.dim("no data");
586780
+ }
586781
+ };
586782
+ const formatWindow = (view, kind) => {
586783
+ const window = view.windows.find((w) => w.kind === kind);
586784
+ if (!window) return "-";
586785
+ const reset = window.resetsAt ? import_picocolors.default.dim(` ${timeUntil(window.resetsAt)}`) : "";
586786
+ return `${window.utilization}%${reset}`;
586787
+ };
586788
+ const formatScopedWeekly = (view) => view.windows.filter((w) => w.kind.startsWith("weekly:")).map((w) => `${w.scopeKey} ${w.utilization}%`).join(", ") || "-";
586789
+ const printAccountTable = (views) => {
586790
+ printTable(views.map((view) => [
586791
+ view.accountId,
586792
+ view.provider,
586793
+ accountName(view),
586794
+ formatWindow(view, "session"),
586795
+ formatWindow(view, "weekly"),
586796
+ formatScopedWeekly(view),
586797
+ formatStatus(view),
586798
+ view.updatedAt ? timeAgo(view.updatedAt) : "-"
586799
+ ]), [
586800
+ "ACCOUNT ID",
586801
+ "PROVIDER",
586802
+ "NAME",
586803
+ "5H",
586804
+ "WEEKLY",
586805
+ "MODEL WEEKLY",
586806
+ "STATUS",
586807
+ "UPDATED"
586808
+ ]);
586809
+ };
586810
+ const emitJson = (data, json) => outputJson(data, typeof json === "string" ? json : void 0);
586811
+ function registerQuotaCommand(program) {
586812
+ const quota = program.command("quota").description("Read subscription quota of agent runtimes (Claude Code / Codex / Kimi Code accounts)");
586813
+ 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) => {
586814
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586815
+ const views = await loadAccountViews(client, (await client.agentQuota.listAccounts.query()).filter((account) => !options.provider || account.provider === options.provider));
586816
+ if (options.json !== void 0) return emitJson(views, options.json);
586817
+ if (views.length === 0) {
586818
+ console.log("No subscription accounts found.");
586819
+ console.log(import_picocolors.default.dim("Accounts appear once a device running Claude Code / Codex / Kimi Code reports quota."));
586820
+ return;
586821
+ }
586822
+ printAccountTable(views);
586823
+ });
586824
+ 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) => {
586825
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586826
+ const account = (await client.agentQuota.listAccounts.query()).find((a) => a.id === accountId);
586827
+ if (!account) {
586828
+ log$15.error(`Account "${accountId}" not found. Run 'lh quota list' to see accounts.`);
586829
+ process.exit(1);
586830
+ return;
586831
+ }
586832
+ const [view] = await loadAccountViews(client, [account]);
586833
+ const activeRuns = await client.agentQuota.listActiveRuns.query({ accountId });
586834
+ const result = {
586835
+ ...view,
586836
+ activeRuns
586837
+ };
586838
+ if (options.json !== void 0) return emitJson(result, options.json);
586839
+ console.log(`${import_picocolors.default.bold(accountName(view))} ${import_picocolors.default.dim(`(${view.provider})`)}`);
586840
+ console.log(`Status: ${formatStatus(view)}`);
586841
+ if (view.updatedAt) console.log(import_picocolors.default.dim(`Updated ${timeAgo(view.updatedAt)}`));
586842
+ console.log();
586843
+ if (view.windows.length) printTable(view.windows.map((w) => [
586844
+ w.kind,
586845
+ `${w.utilization}%`,
586846
+ w.resetsAt ? timeUntil(w.resetsAt) : "-"
586847
+ ]), [
586848
+ "WINDOW",
586849
+ "USED",
586850
+ "RESETS"
586851
+ ]);
586852
+ else console.log(import_picocolors.default.dim("No quota readings yet."));
586853
+ if (activeRuns.length) {
586854
+ console.log();
586855
+ console.log(import_picocolors.default.bold("Active runs"));
586856
+ printTable(activeRuns.map((run) => [
586857
+ run.agentTitle ?? run.agentId ?? "-",
586858
+ run.topicTitle ?? run.topicId ?? "-",
586859
+ run.lastTurnAt ? timeAgo(new Date(run.lastTurnAt)) : "-"
586860
+ ]), [
586861
+ "AGENT",
586862
+ "TOPIC",
586863
+ "LAST TURN"
586864
+ ]);
586865
+ }
586866
+ });
586867
+ 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) => {
586868
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586869
+ const [selected, bindings, accounts] = await Promise.all([
586870
+ client.agentQuota.selectAccountForAgent.query({
586871
+ agentId,
586872
+ deviceId: options.device,
586873
+ provider: options.provider
586874
+ }),
586875
+ client.agentQuota.listBindings.query({ agentId }),
586876
+ client.agentQuota.listAccounts.query()
586877
+ ]);
586878
+ const byId = new Map(accounts.map((a) => [a.id, a]));
586879
+ const boundIds = new Set(bindings.filter((b) => b.role !== "disabled").map((b) => b.accountId));
586880
+ if (selected?.accountId) boundIds.add(selected.accountId);
586881
+ const views = await loadAccountViews(client, [...boundIds].map((id) => byId.get(id)).filter(Boolean));
586882
+ const current = views.find((v) => v.accountId === selected?.accountId) ?? null;
586883
+ const result = {
586884
+ agentId,
586885
+ current: current && {
586886
+ ...current,
586887
+ reason: selected?.reason ?? null
586888
+ },
586889
+ accounts: views
586890
+ };
586891
+ if (options.json !== void 0) return emitJson(result, options.json);
586892
+ if (!views.length) {
586893
+ console.log(`No subscription account is bound to agent ${agentId}.`);
586894
+ return;
586895
+ }
586896
+ if (current) {
586897
+ console.log(`Current account: ${import_picocolors.default.bold(accountName(current))} ${import_picocolors.default.dim(`(${selected?.reason})`)} — ${formatStatus(current)}`);
586898
+ console.log();
586899
+ }
586900
+ printAccountTable(views);
586901
+ });
586902
+ 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) => {
586903
+ if (options.provider !== "codex" && options.provider !== "kimi-code") {
586904
+ log$15.error(`Cannot refresh "${options.provider}" on demand; only codex and kimi-code are sampled through the device.`);
586905
+ process.exit(1);
586906
+ return;
586907
+ }
586908
+ const client = await getTrpcClient(await resolveWorkspaceRef(options.workspace));
586909
+ const input = {
586910
+ deviceId: options.device,
586911
+ force: true
586912
+ };
586913
+ const snapshot = options.provider === "codex" ? await client.agentQuota.refreshCodexQuota.mutate(input) : await client.agentQuota.refreshKimiCodeQuota.mutate(input);
586914
+ if (options.json !== void 0) return emitJson(snapshot, options.json);
586915
+ if (!snapshot) {
586916
+ log$15.error(`Device "${options.device}" is not reachable.`);
586917
+ process.exit(1);
586918
+ return;
586919
+ }
586920
+ if (snapshot.status !== "ok") {
586921
+ log$15.error(`Refresh failed: ${snapshot.error ?? snapshot.status}`);
586922
+ process.exit(1);
586923
+ return;
586924
+ }
586925
+ const who = snapshot.identity?.email ?? snapshot.identity?.externalAccountId ?? "account";
586926
+ console.log(`${import_picocolors.default.green("✓")} Refreshed ${options.provider} quota for ${who}`);
586927
+ for (const reading of snapshot.readings ?? []) {
586928
+ const reset = reading.resetsAt ? import_picocolors.default.dim(` (resets ${timeUntil(new Date(reading.resetsAt))})`) : "";
586929
+ console.log(` ${windowKind(reading)}: ${reading.utilization}%${reset}`);
586930
+ }
586931
+ });
586932
+ }
586933
+
586717
586934
  //#endregion
586718
586935
  //#region src/commands/read.ts
586719
586936
  /** Extract the share id from a `.../share/t/<id>[/llm.txt]` URL. */
@@ -591761,6 +591978,7 @@ function createProgram() {
591761
591978
  registerManCommand(program);
591762
591979
  registerConnectCommand(program);
591763
591980
  registerDeviceCommand(program);
591981
+ registerQuotaCommand(program);
591764
591982
  registerStatusCommand(program);
591765
591983
  registerDoctorCommand(program);
591766
591984
  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.107" "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.107",
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": "4a55123c9510d17e51b8071da43e6873ec30c22b"
87
87
  }