@letterstory/cli 0.176.3 → 0.176.5
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/lib/cli.mjs +1 -1
- package/lib/commands/org.mjs +33 -18
- package/lib/commands/shared.mjs +13 -0
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
import { fetchParkedSections, withoutParked } from "./parked.mjs";
|
|
81
81
|
|
|
82
82
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
83
|
-
export const VERSION = "0.176.
|
|
83
|
+
export const VERSION = "0.176.5";
|
|
84
84
|
|
|
85
85
|
/** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
|
|
86
86
|
export const EXIT_PAYMENT_REQUIRED = 3;
|
package/lib/commands/org.mjs
CHANGED
|
@@ -9,7 +9,17 @@
|
|
|
9
9
|
import { mkdirSync, readdirSync, readFileSync, writeFileSync, existsSync, statSync } from "node:fs";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { CliError } from "../client.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
argsFromFlags,
|
|
14
|
+
flagBool,
|
|
15
|
+
flagStr,
|
|
16
|
+
formatCount,
|
|
17
|
+
formatMoney,
|
|
18
|
+
ok,
|
|
19
|
+
printResult,
|
|
20
|
+
refuseUnknownFlags,
|
|
21
|
+
requirePositional,
|
|
22
|
+
} from "./shared.mjs";
|
|
13
23
|
|
|
14
24
|
export const ARGS = {
|
|
15
25
|
export_org_config: {
|
|
@@ -111,7 +121,8 @@ function capFrom(value) {
|
|
|
111
121
|
return usd;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
// Dollars with cents and thousands separators: $2,000.00 (shared.mjs formatMoney).
|
|
125
|
+
const usd = (n) => formatMoney(n, { cents: true });
|
|
115
126
|
|
|
116
127
|
/**
|
|
117
128
|
* `org billing`: the org's plan on Lago, this period against its allowance and spend cap, whether
|
|
@@ -188,8 +199,8 @@ async function orgBilling(ctx) {
|
|
|
188
199
|
);
|
|
189
200
|
printResult(io, flags, result, (r) =>
|
|
190
201
|
r.granted
|
|
191
|
-
? `Claimed: ${r.tokens} free tokens for ${r.action}${r.verified ? "" : " (on your word)"}.`
|
|
192
|
-
: `Already claimed: ${r.action} gave its ${r.tokens} free tokens before.`
|
|
202
|
+
? `Claimed: ${formatCount(r.tokens)} free tokens for ${r.action}${r.verified ? "" : " (on your word)"}.`
|
|
203
|
+
: `Already claimed: ${r.action} gave its ${formatCount(r.tokens)} free tokens before.`
|
|
193
204
|
);
|
|
194
205
|
return 0;
|
|
195
206
|
}
|
|
@@ -233,24 +244,27 @@ export function billingAccountText(r) {
|
|
|
233
244
|
// A free account (no card): its balance, its grants, and whether new work needs a card now.
|
|
234
245
|
...(f
|
|
235
246
|
? [
|
|
236
|
-
`Free tokens: ${Math.max(0, f.availableTokens)} left of ${f.grantedTokens} given (${f.usedTokens} used${f.heldTokens ? `, ${f.heldTokens} held by running work` : ""}).`,
|
|
247
|
+
`Free tokens: ${formatCount(Math.max(0, f.availableTokens))} left of ${formatCount(f.grantedTokens)} given (${formatCount(f.usedTokens)} used${f.heldTokens ? `, ${formatCount(f.heldTokens)} held by running work` : ""}).`,
|
|
237
248
|
...f.grants.map(
|
|
238
249
|
(g) =>
|
|
239
|
-
` +${g.tokens} ${g.source}${g.sourceKey !== g.source ? `: ${g.sourceKey}` : ""}${g.channel === "agent" ? " (an agent signed you up)" : ""} ${g.createdAt.slice(0, 10)}`
|
|
250
|
+
` +${formatCount(g.tokens)} ${g.source}${g.sourceKey !== g.source ? `: ${g.sourceKey}` : ""}${g.channel === "agent" ? " (an agent signed you up)" : ""} ${g.createdAt.slice(0, 10)}`
|
|
240
251
|
),
|
|
241
252
|
f.cardRequired
|
|
242
253
|
? "No free tokens left: new work needs a card. An admin adds one in Settings → Billing."
|
|
243
254
|
: "When they run out, new work needs a card (an admin adds one in Settings → Billing).",
|
|
244
255
|
]
|
|
245
256
|
: []),
|
|
257
|
+
// What an ended plan left owing (earlierPlan): until it is settled a card can't start a new plan, so
|
|
258
|
+
// no plans are listed to pay for.
|
|
259
|
+
...(r.earlierPlan ? [r.earlierPlan.message] : []),
|
|
246
260
|
// Paying by card starts a plan (addCard): every plan offered, as letter.dev/pricing shows them, Growth's
|
|
247
261
|
// "Most teams" and, with usage, "Cheapest for you" (Kaya, 2026-11-02), the same choice Settings →
|
|
248
262
|
// Billing shows; a person enters the card there.
|
|
249
|
-
...(r.addCard
|
|
263
|
+
...(r.addCard && !r.earlierPlan
|
|
250
264
|
? [
|
|
251
265
|
r.addCard.lockedBy
|
|
252
|
-
? `Paying by card starts ${r.addCard.planName}, at ${
|
|
253
|
-
: `Pay by card: an admin picks a plan in Settings → Billing.${r.addCard.tokensPerMonth ? ` At your usage (about ${r.addCard.tokensPerMonth} tokens a month):` : ""}`,
|
|
266
|
+
? `Paying by card starts ${r.addCard.planName}, at ${formatMoney(r.addCard.monthlyUsd)} a month (a signup from ${r.addCard.lockedBy} is in progress): an admin pays in Settings → Billing.`
|
|
267
|
+
: `Pay by card: an admin picks a plan in Settings → Billing.${r.addCard.tokensPerMonth ? ` At your usage (about ${formatCount(r.addCard.tokensPerMonth)} tokens a month):` : ""}`,
|
|
254
268
|
...(r.addCard.lockedBy ? [] : (r.addCard.plans ?? [])).map(
|
|
255
269
|
(p) =>
|
|
256
270
|
` ${p.planName}${[p.badge, p.cheapestForYou ? "Cheapest for you" : null]
|
|
@@ -258,7 +272,7 @@ export function billingAccountText(r) {
|
|
|
258
272
|
.map((b) => ` [${b}]`)
|
|
259
273
|
.join(
|
|
260
274
|
""
|
|
261
|
-
)}: ${
|
|
275
|
+
)}: ${formatMoney(p.monthlyUsd)} a month, ${formatCount(p.includedTokens)} tokens, ${formatMoney(p.usdPer1kTokens, { cents: true })} per 1,000, past the pool ${formatMoney(p.overageUsdPer1kTokens, { cents: true })} per 1,000${p.expectedMonthlyUsd !== null ? `; about ${formatMoney(Math.round(p.expectedMonthlyUsd))} a month at your usage` : ""}${p.savesUsdPerMonth ? `, saves ${formatMoney(Math.round(p.savesUsdPerMonth))} a month` : ""}.${p.tagline ? ` ${p.tagline}` : ""}${p.extras?.length ? ` ${p.extras.join(", ")}.` : ""}`
|
|
262
276
|
),
|
|
263
277
|
]
|
|
264
278
|
: []),
|
|
@@ -266,13 +280,13 @@ export function billingAccountText(r) {
|
|
|
266
280
|
...(r.carryOverArriving ? [`${r.carryOverArriving.words}.`] : []),
|
|
267
281
|
...(u
|
|
268
282
|
? [
|
|
269
|
-
`This period (${u.periodFrom.slice(0, 10)} to ${u.periodTo.slice(0, 10)}): ${u.usedTokens} of ${u.allowanceTokens} tokens included${u.overageUsd > 0 ? `, ${usd(u.overageUsd)} of overage so far${u.overageChargedUsd ? ` (${usd(u.overageChargedUsd)} of it already charged to the card)` : ""}` : ""}${u.runningTokens ? `; ${u.runningTokens} more held by running work${u.runningOverageUsd > 0 ? ` (${usd(u.runningOverageUsd)} against the cap)` : ""}` : ""}.`,
|
|
283
|
+
`This period (${u.periodFrom.slice(0, 10)} to ${u.periodTo.slice(0, 10)}): ${formatCount(u.usedTokens)} of ${formatCount(u.allowanceTokens)} tokens included${u.overageUsd > 0 ? `, ${usd(u.overageUsd)} of overage so far${u.overageChargedUsd ? ` (${usd(u.overageChargedUsd)} of it already charged to the card)` : ""}` : ""}${u.runningTokens ? `; ${formatCount(u.runningTokens)} more held by running work${u.runningOverageUsd > 0 ? ` (${usd(u.runningOverageUsd)} against the cap)` : ""}` : ""}.`,
|
|
270
284
|
]
|
|
271
285
|
: []),
|
|
272
286
|
ended
|
|
273
287
|
? null
|
|
274
288
|
: r.spendCap
|
|
275
|
-
? `Spend cap: ${usd(r.spendCap.usd)} of overage a month${u?.availableTokens != null ? `, ${Math.max(0, u.availableTokens)} tokens left under it` : ""}.`
|
|
289
|
+
? `Spend cap: ${usd(r.spendCap.usd)} of overage a month${u?.availableTokens != null ? `, ${formatCount(Math.max(0, u.availableTokens))} tokens left under it` : ""}.`
|
|
276
290
|
: r.plan
|
|
277
291
|
? "No spend cap: overage is on."
|
|
278
292
|
: null,
|
|
@@ -296,10 +310,10 @@ function tokenRewardsText(r) {
|
|
|
296
310
|
return "Free tokens for actions are for workspaces on free tokens; this one is on a plan.";
|
|
297
311
|
const lines = r.rewards.map(
|
|
298
312
|
(x) =>
|
|
299
|
-
` ${x.claimed ? "✓" : x.ready === false ? "·" : "○"} ${x.action.padEnd(18)} ${
|
|
313
|
+
` ${x.claimed ? "✓" : x.ready === false ? "·" : "○"} ${x.action.padEnd(18)} ${formatCount(x.tokens).padStart(6)} tokens ${x.title}${x.claimed ? " (earned)" : x.auto ? " (granted when done)" : x.ready === false ? " (not done yet)" : ""}`
|
|
300
314
|
);
|
|
301
315
|
return [
|
|
302
|
-
`Free tokens for actions: ${r.claimedTokens} earned, ${r.availableTokens} still to earn.`,
|
|
316
|
+
`Free tokens for actions: ${formatCount(r.claimedTokens)} earned, ${formatCount(r.availableTokens)} still to earn.`,
|
|
303
317
|
...lines,
|
|
304
318
|
"Slack, the CLI, GitHub, GitLab and Search Console are granted on their own once done; the tours once their task is done (a Build answer, a goal's plan, a fix, a page read).",
|
|
305
319
|
"Claim the rest: letterstory org billing rewards claim <action>",
|
|
@@ -333,7 +347,8 @@ function billingInvoicesText(r) {
|
|
|
333
347
|
return lines.join("\n");
|
|
334
348
|
}
|
|
335
349
|
|
|
336
|
-
const tokensOrQty = (p) =>
|
|
350
|
+
const tokensOrQty = (p) =>
|
|
351
|
+
`${formatCount(p.billableQuantity)}${p.tokens === null ? "" : ` ${formatCount(p.tokens)} tokens`}`;
|
|
337
352
|
|
|
338
353
|
/** Every plan at list prices (get_billing's `plans`), this account's marked, as Settings → Billing lists them. */
|
|
339
354
|
function plansText(r) {
|
|
@@ -344,7 +359,7 @@ function plansText(r) {
|
|
|
344
359
|
...r.plans.map((p) =>
|
|
345
360
|
p.contact
|
|
346
361
|
? ` ${p.name} priced on a call: Book a call in Settings → Billing`
|
|
347
|
-
: ` ${p.name} ${
|
|
362
|
+
: ` ${p.name} ${formatMoney(p.monthlyUsd)} a month, ${formatCount(p.includedTokens)} tokens included, then $${Number(p.overageUsdPerToken.toFixed(5))} a token${r.plan?.code === p.code ? " (your plan)" : ""}`
|
|
348
363
|
),
|
|
349
364
|
];
|
|
350
365
|
}
|
|
@@ -356,7 +371,7 @@ function billingUsageText(r) {
|
|
|
356
371
|
];
|
|
357
372
|
if (r.tokens)
|
|
358
373
|
lines.push(
|
|
359
|
-
`Tokens: ${r.tokens.used} used of ${r.tokens.allowance} included${r.tokens.complimentary ? ` (+${r.tokens.complimentary} complimentary)` : ""}${r.tokens.arriving ? ` (${r.tokens.arriving} of them still being counted)` : ""}${r.tokens.running ? `, ${r.tokens.running} held by running work` : ""}.`
|
|
374
|
+
`Tokens: ${formatCount(r.tokens.used)} used of ${formatCount(r.tokens.allowance)} included${r.tokens.complimentary ? ` (+${formatCount(r.tokens.complimentary)} complimentary)` : ""}${r.tokens.arriving ? ` (${formatCount(r.tokens.arriving)} of them still being counted)` : ""}${r.tokens.running ? `, ${formatCount(r.tokens.running)} held by running work` : ""}.`
|
|
360
375
|
);
|
|
361
376
|
else lines.push("Not billed by usage: quantities only.");
|
|
362
377
|
if (r.carryOverArriving) lines.push(`${r.carryOverArriving.words}.`);
|
|
@@ -368,7 +383,7 @@ function billingUsageText(r) {
|
|
|
368
383
|
lines.push("", "By product:", ...r.byProduct.map((p) => ` ${p.label} ${tokensOrQty(p)}`));
|
|
369
384
|
lines.push("", "By collection:");
|
|
370
385
|
for (const c of r.byCollection) {
|
|
371
|
-
lines.push(` ${c.name}${c.tokens === null ? "" : ` ${c.tokens} tokens`}`);
|
|
386
|
+
lines.push(` ${c.name}${c.tokens === null ? "" : ` ${formatCount(c.tokens)} tokens`}`);
|
|
372
387
|
for (const p of c.products) lines.push(` ${p.label} ${tokensOrQty(p)}`);
|
|
373
388
|
}
|
|
374
389
|
return [...lines, ...plansText(r)].join("\n");
|
package/lib/commands/shared.mjs
CHANGED
|
@@ -71,6 +71,19 @@ export function requirePositional(positionals, index, label) {
|
|
|
71
71
|
return v;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// A count as people read it: 10,000, never 10000 (the app's formatNumber, en-US).
|
|
75
|
+
export function formatCount(n) {
|
|
76
|
+
return Math.round(Number(n ?? 0)).toLocaleString("en-US");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Dollars as people read them: $1,000 for whole dollars, $7.69 otherwise; `cents` always shows them
|
|
80
|
+
// ($10.00), as per-1,000 prices are written on letter.dev/pricing.
|
|
81
|
+
export function formatMoney(usd, { cents = false } = {}) {
|
|
82
|
+
const n = Number(usd ?? 0);
|
|
83
|
+
const whole = !cents && Number.isInteger(Math.round(n * 100) / 100);
|
|
84
|
+
return `$${n.toLocaleString("en-US", { minimumFractionDigits: whole ? 0 : 2, maximumFractionDigits: whole ? 0 : 2 })}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
74
87
|
// Drop undefined entries so callTool args only carry fields the user actually set.
|
|
75
88
|
export function compact(obj) {
|
|
76
89
|
const out = {};
|