@limitry/cli 1.0.0-rc.5 → 1.0.0-rc.7

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 CHANGED
@@ -2,6 +2,41 @@
2
2
 
3
3
  What changed in the Limitry CLI (`@limitry/cli`). Generated from the source on each release; newest first.
4
4
 
5
+ ## 1.0.0-rc.7 (2026-10-19)
6
+
7
+ ### Added
8
+
9
+ - A refused check's `reason` has a `message`: the refusal in one sentence,
10
+ such as "Refused by AI budget: 3 cents left, resets
11
+ 2026-11-01T00:00:00.000Z. Try again in 3600 s." `LimitExceeded` and
12
+ `limitry check` show it as the API writes it, so every client says the
13
+ same. Branch on `allowed` and `reason.code`, never on the message.
14
+
15
+ ### Fixed
16
+
17
+ - - `held.cost()` refuses a cost the API can't commit (not a whole number
18
+ from 0 to 1,000,000,000): TypeScript throws `RangeError`, Python raises
19
+ `ValueError`, in your code. Before, the commit failed silently after
20
+ the work and its usage was never counted.
21
+ - TypeScript's `held.extend()` throws the API's error, such as for an
22
+ expired hold, as Python's already did. Both send the `ttlSeconds` you
23
+ give as it is, so `0` is refused rather than read as the default.
24
+ - Python checks, commits and releases now retry exactly as TypeScript's
25
+ do: a network error, `408`, `429` or `5xx`, at most twice, all within
26
+ the check's `timeout` (1.5 s) or 5 s for a settle. `standing()` retries
27
+ too, and reports an error answer that isn't JSON.
28
+ - `limitry check` and `limitry sync` refuse `--workspace` with an API key,
29
+ as every other command does, instead of ignoring it.
30
+
31
+ ## 1.0.0-rc.6 (2026-10-19)
32
+
33
+ ### Fixed
34
+
35
+ - `login` in the browser no longer shows Safari's "This is a non-secure
36
+ form" warning after **Allow**. The page now hands the new token back to
37
+ the waiting CLI encrypted to a key only that CLI holds, by a redirect
38
+ instead of a form. A CLI from before this change is asked to update.
39
+
5
40
  ## 1.0.0-rc.5 (2026-10-16)
6
41
 
7
42
  No user-facing changes.
package/README.md CHANGED
@@ -57,9 +57,12 @@ agents.
57
57
  - [Discord](https://limitry.com/discord)
58
58
  - [Report a security issue](https://limitry.com/security/)
59
59
 
60
- ## About this package
60
+ ## Contributing
61
61
 
62
62
  This repository is generated from Limitry's source on each
63
63
  release, so pull requests are ported there and credited (see
64
64
  [CONTRIBUTING.md](https://github.com/limitry/limitry-cli/blob/main/CONTRIBUTING.md)).
65
+
66
+ ## License
67
+
65
68
  Licensed under the Apache License 2.0.
package/dist/limitry.mjs CHANGED
@@ -13,7 +13,6 @@ var brand_default = {
13
13
  legalName: "Omsome L.L.C-FZ",
14
14
  releaseMirrors: true,
15
15
  mirrorProfile: {
16
- tagline: "limits, credits and budgets, checked in one call before each costly request",
17
16
  topics: [
18
17
  "rate-limiting",
19
18
  "usage-limits",
@@ -692,6 +691,13 @@ function apiErrorFrom(error, response) {
692
691
  }
693
692
 
694
693
  // node_modules/@limitry/sdk/dist/product/limits.js
694
+ var MAX_COST = 1e9;
695
+ function checkedCost(units) {
696
+ if (!Number.isInteger(units) || units < 0 || units > MAX_COST) {
697
+ throw new RangeError(`held.cost(${units}): the cost must be a whole number from 0 to ${MAX_COST}`);
698
+ }
699
+ return units;
700
+ }
695
701
  var LimitExceeded = class extends Error {
696
702
  reason;
697
703
  /** The limit that refused; null when unavailable or too many holds. */
@@ -700,7 +706,10 @@ var LimitExceeded = class extends Error {
700
706
  decision;
701
707
  constructor(decision) {
702
708
  const reason = decision?.reason?.code ?? "unavailable";
703
- super(reason === "unavailable" ? "Limitry could not be reached and a limit denies when unreachable" : reason === "too_many_reservations" ? "Too many open reservations for this subject" : `Limit ${decision?.reason?.limit ?? ""} exceeded`.trim());
709
+ super(reason === "unavailable" ? "Limitry could not be reached and a limit denies when unreachable" : (
710
+ // The API's own sentence (reason.message), one wording everywhere.
711
+ decision?.reason?.message ?? "Refused"
712
+ ));
704
713
  this.name = "LimitExceeded";
705
714
  this.reason = reason;
706
715
  this.limit = decision?.reason?.limit ?? null;
@@ -842,9 +851,13 @@ function createLimits(client, options = {}) {
842
851
  };
843
852
  const idempotencyKey = crypto.randomUUID();
844
853
  const decision = await check(body, idempotencyKey);
845
- const unmetered = { cost: () => {
846
- }, extend: async () => {
847
- } };
854
+ const unmetered = {
855
+ // Checked even unmetered: the mistake shows whether or not
856
+ // Limitry answered.
857
+ cost: (units) => void checkedCost(units),
858
+ extend: async () => {
859
+ }
860
+ };
848
861
  if (decision === UNREACHABLE || decision === TIMED_OUT) {
849
862
  const unheard = () => decision === TIMED_OUT ? releaseUnheard(body, idempotencyKey) : Promise.resolve();
850
863
  if (failMode(request.subject, request.action) === "closed") {
@@ -865,14 +878,16 @@ function createLimits(client, options = {}) {
865
878
  let used = estimate;
866
879
  const held = {
867
880
  cost(units) {
868
- used = units;
881
+ used = checkedCost(units);
869
882
  },
870
883
  async extend(ttlSeconds) {
871
- await client.POST("/reservations/{reservationId}/extend", {
884
+ const { error, response } = await client.POST("/reservations/{reservationId}/extend", {
872
885
  params: { path: { reservationId: id } },
873
- body: ttlSeconds ? { ttlSeconds } : {},
886
+ body: ttlSeconds === void 0 ? {} : { ttlSeconds },
874
887
  signal: AbortSignal.timeout(timeoutMs)
875
888
  });
889
+ if (error !== void 0)
890
+ throw apiErrorFrom(error, response);
876
891
  }
877
892
  };
878
893
  let result;
@@ -4703,12 +4718,35 @@ function useColor() {
4703
4718
  var program = new Command();
4704
4719
 
4705
4720
  // src/browser-login.ts
4706
- import { randomBytes } from "node:crypto";
4721
+ import {
4722
+ constants,
4723
+ generateKeyPairSync,
4724
+ privateDecrypt,
4725
+ randomBytes
4726
+ } from "node:crypto";
4707
4727
  import { createServer } from "node:http";
4708
4728
  var PAGE = (title, body) => `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title><meta name="viewport" content="width=device-width, initial-scale=1"></head><body style="font-family:system-ui,sans-serif;max-width:32rem;margin:4rem auto;padding:0 1rem"><h1 style="font-size:1.25rem">${title}</h1><p>${body}</p></body></html>`;
4709
- var MAX_BODY = 16 * 1024;
4729
+ var MAX_URL = 16 * 1024;
4710
4730
  function browserLogin(options) {
4711
4731
  const state = randomBytes(24).toString("base64url");
4732
+ const { publicKey, privateKey } = generateKeyPairSync("rsa", {
4733
+ modulusLength: 2048
4734
+ });
4735
+ const key = publicKey.export({ type: "spki", format: "der" }).toString("base64url");
4736
+ const decrypt = (sealed) => {
4737
+ try {
4738
+ return privateDecrypt(
4739
+ {
4740
+ key: privateKey,
4741
+ padding: constants.RSA_PKCS1_OAEP_PADDING,
4742
+ oaepHash: "sha256"
4743
+ },
4744
+ Buffer.from(sealed, "base64url")
4745
+ ).toString("utf8");
4746
+ } catch {
4747
+ return null;
4748
+ }
4749
+ };
4712
4750
  return new Promise((resolve2, reject) => {
4713
4751
  let settled = false;
4714
4752
  const finish = (outcome) => {
@@ -4719,44 +4757,41 @@ function browserLogin(options) {
4719
4757
  outcome();
4720
4758
  };
4721
4759
  const server = createServer((req, res) => {
4722
- if (req.method !== "POST" || req.url !== "/callback") {
4760
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
4761
+ if (req.method !== "GET" || url.pathname !== "/callback" || (req.url ?? "").length > MAX_URL) {
4723
4762
  res.writeHead(404).end();
4724
4763
  return;
4725
4764
  }
4726
- let body = "";
4727
- req.setEncoding("utf8");
4728
- req.on("data", (chunk) => {
4729
- body += chunk;
4730
- if (body.length > MAX_BODY) req.destroy();
4731
- });
4732
- req.on("end", () => {
4733
- const fields = new URLSearchParams(body);
4734
- const send = (status, title, text) => res.writeHead(status, { "content-type": "text/html; charset=utf-8" }).end(PAGE(title, text));
4735
- if (fields.get("state") !== state) {
4736
- send(
4737
- 400,
4738
- "Not this login",
4739
- "This sign-in did not come from the terminal that is waiting. Run login again."
4740
- );
4741
- return;
4742
- }
4743
- if (fields.get("error")) {
4744
- send(200, "Sign-in cancelled", "You can close this tab.");
4745
- finish(() => reject(new Error("sign-in was denied in the browser")));
4746
- return;
4747
- }
4748
- const token = fields.get("token");
4749
- if (!token) {
4750
- send(400, "Something went wrong", "Run login again.");
4751
- return;
4752
- }
4765
+ const fields = url.searchParams;
4766
+ const send = (status, title, text) => res.writeHead(status, {
4767
+ "content-type": "text/html; charset=utf-8",
4768
+ "cache-control": "no-store",
4769
+ "referrer-policy": "no-referrer"
4770
+ }).end(PAGE(title, text));
4771
+ if (fields.get("state") !== state) {
4753
4772
  send(
4754
- 200,
4755
- "You are signed in",
4756
- "Return to your terminal \u2014 you can close this tab."
4773
+ 400,
4774
+ "Not this login",
4775
+ "This sign-in did not come from the terminal that is waiting. Run login again."
4757
4776
  );
4758
- finish(() => resolve2(token));
4759
- });
4777
+ return;
4778
+ }
4779
+ if (fields.get("error")) {
4780
+ send(200, "Sign-in cancelled", "You can close this tab.");
4781
+ finish(() => reject(new Error("sign-in was denied in the browser")));
4782
+ return;
4783
+ }
4784
+ const token = decrypt(fields.get("token") ?? "");
4785
+ if (!token) {
4786
+ send(400, "Something went wrong", "Run login again.");
4787
+ return;
4788
+ }
4789
+ send(
4790
+ 200,
4791
+ "You are signed in",
4792
+ "Return to your terminal \u2014 you can close this tab."
4793
+ );
4794
+ finish(() => resolve2(token));
4760
4795
  });
4761
4796
  const timer = setTimeout(
4762
4797
  () => finish(
@@ -4773,6 +4808,7 @@ function browserLogin(options) {
4773
4808
  const url = `${options.webOrigin}/cli/authorize?${new URLSearchParams({
4774
4809
  port: String(port),
4775
4810
  state,
4811
+ key,
4776
4812
  name: options.computer
4777
4813
  })}`;
4778
4814
  options.onUrl(url);
@@ -7868,6 +7904,53 @@ function print(ctx, data, asJson) {
7868
7904
  ctx.io.stdout(String(data));
7869
7905
  }
7870
7906
 
7907
+ // src/product/check.ts
7908
+ var checkCommand = (program2, ctx) => {
7909
+ program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:usr_123)").argument("<action>", "what they want to do (ai-call)").option("--cost <n>", "units it would use (default 1)").option(
7910
+ "--shared <kind:id>",
7911
+ "a shared subject it also draws from (a team's pool); repeat for more",
7912
+ (value, previous = []) => [...previous, value]
7913
+ ).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
7914
+ "after",
7915
+ `
7916
+ Example: ${brand.name} check user:usr_123 ai-call --cost 5
7917
+ A refusal exits 0: it's an answer. Errors exit 1.`
7918
+ ).action(
7919
+ async (subject, action, options) => {
7920
+ const cost = options.cost === void 0 ? void 0 : Number(options.cost);
7921
+ if (cost !== void 0 && !Number.isInteger(cost)) {
7922
+ throw new Error("--cost must be a whole number");
7923
+ }
7924
+ const decision = await ctx.client({ workspace: options.workspace }).checks.create(
7925
+ {
7926
+ subject: parseSubject(subject),
7927
+ action,
7928
+ ...cost !== void 0 ? { cost } : {},
7929
+ ...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
7930
+ },
7931
+ { idempotencyKey: crypto.randomUUID() }
7932
+ );
7933
+ ctx.io.stdout(options.json ? json(decision) : answer(decision));
7934
+ }
7935
+ );
7936
+ };
7937
+ function parseSubject(value) {
7938
+ const at = value.indexOf(":");
7939
+ if (at <= 0 || at === value.length - 1) {
7940
+ throw new Error(
7941
+ `"${value}": write a subject as kind:id, e.g. user:usr_123`
7942
+ );
7943
+ }
7944
+ return { kind: value.slice(0, at), id: value.slice(at + 1) };
7945
+ }
7946
+ var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
7947
+ function answer(decision) {
7948
+ if (decision.allowed) {
7949
+ return decision.remaining.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.remaining.map(left).join("; ")}`;
7950
+ }
7951
+ return decision.reason?.message ?? "Refused.";
7952
+ }
7953
+
7871
7954
  // src/product/limits-sync.ts
7872
7955
  import { readFileSync as readFileSync4 } from "node:fs";
7873
7956
  import { resolve } from "node:path";
@@ -7887,12 +7970,6 @@ Shortcut: \`${brand.name} sync\`, the same command.`
7887
7970
  ""
7888
7971
  );
7889
7972
  };
7890
- function clientFor(ctx, workspace2) {
7891
- const token = ctx.settings().token ?? "";
7892
- return ctx.client({
7893
- workspace: token.startsWith("pat_") ? workspace2 : false
7894
- });
7895
- }
7896
7973
  function syncCommand(command, ctx, description, more) {
7897
7974
  command.description(description).argument("[file]", "the file to read", "limitry.json").option("--dry-run", "show what would change, and change nothing").option("--limits <json>", "the limits as a JSON array, instead of a file").option(
7898
7975
  "--archive-missing",
@@ -7903,7 +7980,7 @@ function syncCommand(command, ctx, description, more) {
7903
7980
  ).action(
7904
7981
  async (file, options) => {
7905
7982
  const limits = options.limits === void 0 ? readLimitsFile(file) : parseLimits(options.limits, "--limits");
7906
- const result = await clientFor(ctx, options.workspace).limits.sync(
7983
+ const result = await ctx.client({ workspace: options.workspace }).limits.sync(
7907
7984
  {
7908
7985
  limits,
7909
7986
  archiveMissing: options.archiveMissing ?? false,
@@ -7981,60 +8058,6 @@ function summary(result) {
7981
8058
  return lines;
7982
8059
  }
7983
8060
 
7984
- // src/product/check.ts
7985
- var checkCommand = (program2, ctx) => {
7986
- program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:usr_123)").argument("<action>", "what they want to do (ai-call)").option("--cost <n>", "units it would use (default 1)").option(
7987
- "--shared <kind:id>",
7988
- "a shared subject it also draws from (a team's pool); repeat for more",
7989
- (value, previous = []) => [...previous, value]
7990
- ).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
7991
- "after",
7992
- `
7993
- Example: ${brand.name} check user:usr_123 ai-call --cost 5
7994
- A refusal exits 0: it's an answer. Errors exit 1.`
7995
- ).action(
7996
- async (subject, action, options) => {
7997
- const cost = options.cost === void 0 ? void 0 : Number(options.cost);
7998
- if (cost !== void 0 && !Number.isInteger(cost)) {
7999
- throw new Error("--cost must be a whole number");
8000
- }
8001
- const decision = await clientFor(ctx, options.workspace).checks.create(
8002
- {
8003
- subject: parseSubject(subject),
8004
- action,
8005
- ...cost !== void 0 ? { cost } : {},
8006
- ...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
8007
- },
8008
- { idempotencyKey: crypto.randomUUID() }
8009
- );
8010
- ctx.io.stdout(options.json ? json(decision) : answer(decision));
8011
- }
8012
- );
8013
- };
8014
- function parseSubject(value) {
8015
- const at = value.indexOf(":");
8016
- if (at <= 0 || at === value.length - 1) {
8017
- throw new Error(
8018
- `"${value}": write a subject as kind:id, e.g. user:usr_123`
8019
- );
8020
- }
8021
- return { kind: value.slice(0, at), id: value.slice(at + 1) };
8022
- }
8023
- var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
8024
- function answer(decision) {
8025
- if (decision.allowed) {
8026
- return decision.remaining.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.remaining.map(left).join("; ")}`;
8027
- }
8028
- const retry = decision.retryAfterSeconds !== null ? ` Try again in ${decision.retryAfterSeconds} s.` : "";
8029
- if (decision.reason?.code === "too_many_reservations") {
8030
- return `Refused: too many open reservations for this subject.${retry}`;
8031
- }
8032
- const limit = decision.remaining.find(
8033
- (r) => r.limit === decision.reason?.limit
8034
- );
8035
- return limit ? `Refused by ${left(limit)}.${retry}` : `Refused: a limit is used up.${retry}`;
8036
- }
8037
-
8038
8061
  // src/product/index.ts
8039
8062
  var productCommands = [limitsSyncCommand, checkCommand];
8040
8063
 
@@ -8052,7 +8075,7 @@ function tokenEnvVar() {
8052
8075
  function build(io) {
8053
8076
  let actedIn = null;
8054
8077
  let sending;
8055
- const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.5").addHelpText(
8078
+ const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.7").addHelpText(
8056
8079
  "after",
8057
8080
  `
8058
8081
  Token: \`${brand.name} login\` stores it in ~/.config/${brand.name}/; ${tokenEnvVar()} overrides.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limitry/cli",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.7",
4
4
  "description": "Limitry command line",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "typecheck": "tsc --noEmit"
18
18
  },
19
19
  "devDependencies": {
20
- "@limitry/sdk": "1.0.0-rc.5",
20
+ "@limitry/sdk": "1.0.0-rc.7",
21
21
  "@types/node": "26.6.5",
22
22
  "commander": "15.0.0",
23
23
  "esbuild": "0.28.2",