@limitry/cli 1.0.0-rc.6 → 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 +26 -0
- package/dist/limitry.mjs +72 -69
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
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
|
+
|
|
5
31
|
## 1.0.0-rc.6 (2026-10-19)
|
|
6
32
|
|
|
7
33
|
### Fixed
|
package/dist/limitry.mjs
CHANGED
|
@@ -691,6 +691,13 @@ function apiErrorFrom(error, response) {
|
|
|
691
691
|
}
|
|
692
692
|
|
|
693
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
|
+
}
|
|
694
701
|
var LimitExceeded = class extends Error {
|
|
695
702
|
reason;
|
|
696
703
|
/** The limit that refused; null when unavailable or too many holds. */
|
|
@@ -699,7 +706,10 @@ var LimitExceeded = class extends Error {
|
|
|
699
706
|
decision;
|
|
700
707
|
constructor(decision) {
|
|
701
708
|
const reason = decision?.reason?.code ?? "unavailable";
|
|
702
|
-
super(reason === "unavailable" ? "Limitry could not be reached and a limit denies when unreachable" :
|
|
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
|
+
));
|
|
703
713
|
this.name = "LimitExceeded";
|
|
704
714
|
this.reason = reason;
|
|
705
715
|
this.limit = decision?.reason?.limit ?? null;
|
|
@@ -841,9 +851,13 @@ function createLimits(client, options = {}) {
|
|
|
841
851
|
};
|
|
842
852
|
const idempotencyKey = crypto.randomUUID();
|
|
843
853
|
const decision = await check(body, idempotencyKey);
|
|
844
|
-
const unmetered = {
|
|
845
|
-
|
|
846
|
-
|
|
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
|
+
};
|
|
847
861
|
if (decision === UNREACHABLE || decision === TIMED_OUT) {
|
|
848
862
|
const unheard = () => decision === TIMED_OUT ? releaseUnheard(body, idempotencyKey) : Promise.resolve();
|
|
849
863
|
if (failMode(request.subject, request.action) === "closed") {
|
|
@@ -864,14 +878,16 @@ function createLimits(client, options = {}) {
|
|
|
864
878
|
let used = estimate;
|
|
865
879
|
const held = {
|
|
866
880
|
cost(units) {
|
|
867
|
-
used = units;
|
|
881
|
+
used = checkedCost(units);
|
|
868
882
|
},
|
|
869
883
|
async extend(ttlSeconds) {
|
|
870
|
-
await client.POST("/reservations/{reservationId}/extend", {
|
|
884
|
+
const { error, response } = await client.POST("/reservations/{reservationId}/extend", {
|
|
871
885
|
params: { path: { reservationId: id } },
|
|
872
|
-
body: ttlSeconds ? {
|
|
886
|
+
body: ttlSeconds === void 0 ? {} : { ttlSeconds },
|
|
873
887
|
signal: AbortSignal.timeout(timeoutMs)
|
|
874
888
|
});
|
|
889
|
+
if (error !== void 0)
|
|
890
|
+
throw apiErrorFrom(error, response);
|
|
875
891
|
}
|
|
876
892
|
};
|
|
877
893
|
let result;
|
|
@@ -7888,6 +7904,53 @@ function print(ctx, data, asJson) {
|
|
|
7888
7904
|
ctx.io.stdout(String(data));
|
|
7889
7905
|
}
|
|
7890
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
|
+
|
|
7891
7954
|
// src/product/limits-sync.ts
|
|
7892
7955
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7893
7956
|
import { resolve } from "node:path";
|
|
@@ -7907,12 +7970,6 @@ Shortcut: \`${brand.name} sync\`, the same command.`
|
|
|
7907
7970
|
""
|
|
7908
7971
|
);
|
|
7909
7972
|
};
|
|
7910
|
-
function clientFor(ctx, workspace2) {
|
|
7911
|
-
const token = ctx.settings().token ?? "";
|
|
7912
|
-
return ctx.client({
|
|
7913
|
-
workspace: token.startsWith("pat_") ? workspace2 : false
|
|
7914
|
-
});
|
|
7915
|
-
}
|
|
7916
7973
|
function syncCommand(command, ctx, description, more) {
|
|
7917
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(
|
|
7918
7975
|
"--archive-missing",
|
|
@@ -7923,7 +7980,7 @@ function syncCommand(command, ctx, description, more) {
|
|
|
7923
7980
|
).action(
|
|
7924
7981
|
async (file, options) => {
|
|
7925
7982
|
const limits = options.limits === void 0 ? readLimitsFile(file) : parseLimits(options.limits, "--limits");
|
|
7926
|
-
const result = await
|
|
7983
|
+
const result = await ctx.client({ workspace: options.workspace }).limits.sync(
|
|
7927
7984
|
{
|
|
7928
7985
|
limits,
|
|
7929
7986
|
archiveMissing: options.archiveMissing ?? false,
|
|
@@ -8001,60 +8058,6 @@ function summary(result) {
|
|
|
8001
8058
|
return lines;
|
|
8002
8059
|
}
|
|
8003
8060
|
|
|
8004
|
-
// src/product/check.ts
|
|
8005
|
-
var checkCommand = (program2, ctx) => {
|
|
8006
|
-
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(
|
|
8007
|
-
"--shared <kind:id>",
|
|
8008
|
-
"a shared subject it also draws from (a team's pool); repeat for more",
|
|
8009
|
-
(value, previous = []) => [...previous, value]
|
|
8010
|
-
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
|
|
8011
|
-
"after",
|
|
8012
|
-
`
|
|
8013
|
-
Example: ${brand.name} check user:usr_123 ai-call --cost 5
|
|
8014
|
-
A refusal exits 0: it's an answer. Errors exit 1.`
|
|
8015
|
-
).action(
|
|
8016
|
-
async (subject, action, options) => {
|
|
8017
|
-
const cost = options.cost === void 0 ? void 0 : Number(options.cost);
|
|
8018
|
-
if (cost !== void 0 && !Number.isInteger(cost)) {
|
|
8019
|
-
throw new Error("--cost must be a whole number");
|
|
8020
|
-
}
|
|
8021
|
-
const decision = await clientFor(ctx, options.workspace).checks.create(
|
|
8022
|
-
{
|
|
8023
|
-
subject: parseSubject(subject),
|
|
8024
|
-
action,
|
|
8025
|
-
...cost !== void 0 ? { cost } : {},
|
|
8026
|
-
...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
|
|
8027
|
-
},
|
|
8028
|
-
{ idempotencyKey: crypto.randomUUID() }
|
|
8029
|
-
);
|
|
8030
|
-
ctx.io.stdout(options.json ? json(decision) : answer(decision));
|
|
8031
|
-
}
|
|
8032
|
-
);
|
|
8033
|
-
};
|
|
8034
|
-
function parseSubject(value) {
|
|
8035
|
-
const at = value.indexOf(":");
|
|
8036
|
-
if (at <= 0 || at === value.length - 1) {
|
|
8037
|
-
throw new Error(
|
|
8038
|
-
`"${value}": write a subject as kind:id, e.g. user:usr_123`
|
|
8039
|
-
);
|
|
8040
|
-
}
|
|
8041
|
-
return { kind: value.slice(0, at), id: value.slice(at + 1) };
|
|
8042
|
-
}
|
|
8043
|
-
var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
|
|
8044
|
-
function answer(decision) {
|
|
8045
|
-
if (decision.allowed) {
|
|
8046
|
-
return decision.remaining.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.remaining.map(left).join("; ")}`;
|
|
8047
|
-
}
|
|
8048
|
-
const retry = decision.retryAfterSeconds !== null ? ` Try again in ${decision.retryAfterSeconds} s.` : "";
|
|
8049
|
-
if (decision.reason?.code === "too_many_reservations") {
|
|
8050
|
-
return `Refused: too many open reservations for this subject.${retry}`;
|
|
8051
|
-
}
|
|
8052
|
-
const limit = decision.remaining.find(
|
|
8053
|
-
(r) => r.limit === decision.reason?.limit
|
|
8054
|
-
);
|
|
8055
|
-
return limit ? `Refused by ${left(limit)}.${retry}` : `Refused: a limit is used up.${retry}`;
|
|
8056
|
-
}
|
|
8057
|
-
|
|
8058
8061
|
// src/product/index.ts
|
|
8059
8062
|
var productCommands = [limitsSyncCommand, checkCommand];
|
|
8060
8063
|
|
|
@@ -8072,7 +8075,7 @@ function tokenEnvVar() {
|
|
|
8072
8075
|
function build(io) {
|
|
8073
8076
|
let actedIn = null;
|
|
8074
8077
|
let sending;
|
|
8075
|
-
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.
|
|
8078
|
+
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.7").addHelpText(
|
|
8076
8079
|
"after",
|
|
8077
8080
|
`
|
|
8078
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.
|
|
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.
|
|
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",
|