@letterstory/cli 0.176.4 → 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 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.4";
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;
@@ -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 { argsFromFlags, flagBool, flagStr, ok, printResult, refuseUnknownFlags, requirePositional } from "./shared.mjs";
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
- const usd = (n) => `$${Number(n).toFixed(2)}`;
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,10 +244,10 @@ 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."
@@ -252,8 +263,8 @@ export function billingAccountText(r) {
252
263
  ...(r.addCard && !r.earlierPlan
253
264
  ? [
254
265
  r.addCard.lockedBy
255
- ? `Paying by card starts ${r.addCard.planName}, at ${usd(r.addCard.monthlyUsd)} a month (a signup from ${r.addCard.lockedBy} is in progress): an admin pays in Settings → Billing.`
256
- : `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):` : ""}`,
257
268
  ...(r.addCard.lockedBy ? [] : (r.addCard.plans ?? [])).map(
258
269
  (p) =>
259
270
  ` ${p.planName}${[p.badge, p.cheapestForYou ? "Cheapest for you" : null]
@@ -261,7 +272,7 @@ export function billingAccountText(r) {
261
272
  .map((b) => ` [${b}]`)
262
273
  .join(
263
274
  ""
264
- )}: ${usd(p.monthlyUsd)} a month, ${p.includedTokens} tokens, ${usd(p.usdPer1kTokens)} per 1,000, past the pool ${usd(p.overageUsdPer1kTokens)} per 1,000${p.expectedMonthlyUsd !== null ? `; about ${usd(p.expectedMonthlyUsd)} a month at your usage` : ""}${p.savesUsdPerMonth ? `, saves ${usd(p.savesUsdPerMonth)} a month` : ""}.${p.tagline ? ` ${p.tagline}` : ""}${p.extras?.length ? ` ${p.extras.join(", ")}.` : ""}`
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(", ")}.` : ""}`
265
276
  ),
266
277
  ]
267
278
  : []),
@@ -269,13 +280,13 @@ export function billingAccountText(r) {
269
280
  ...(r.carryOverArriving ? [`${r.carryOverArriving.words}.`] : []),
270
281
  ...(u
271
282
  ? [
272
- `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)` : ""}` : ""}.`,
273
284
  ]
274
285
  : []),
275
286
  ended
276
287
  ? null
277
288
  : r.spendCap
278
- ? `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` : ""}.`
279
290
  : r.plan
280
291
  ? "No spend cap: overage is on."
281
292
  : null,
@@ -299,10 +310,10 @@ function tokenRewardsText(r) {
299
310
  return "Free tokens for actions are for workspaces on free tokens; this one is on a plan.";
300
311
  const lines = r.rewards.map(
301
312
  (x) =>
302
- ` ${x.claimed ? "✓" : x.ready === false ? "·" : "○"} ${x.action.padEnd(18)} ${String(x.tokens).padStart(6)} tokens ${x.title}${x.claimed ? " (earned)" : x.auto ? " (granted when done)" : x.ready === false ? " (not done yet)" : ""}`
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)" : ""}`
303
314
  );
304
315
  return [
305
- `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.`,
306
317
  ...lines,
307
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).",
308
319
  "Claim the rest: letterstory org billing rewards claim <action>",
@@ -336,7 +347,8 @@ function billingInvoicesText(r) {
336
347
  return lines.join("\n");
337
348
  }
338
349
 
339
- const tokensOrQty = (p) => `${p.billableQuantity}${p.tokens === null ? "" : ` ${p.tokens} tokens`}`;
350
+ const tokensOrQty = (p) =>
351
+ `${formatCount(p.billableQuantity)}${p.tokens === null ? "" : ` ${formatCount(p.tokens)} tokens`}`;
340
352
 
341
353
  /** Every plan at list prices (get_billing's `plans`), this account's marked, as Settings → Billing lists them. */
342
354
  function plansText(r) {
@@ -347,7 +359,7 @@ function plansText(r) {
347
359
  ...r.plans.map((p) =>
348
360
  p.contact
349
361
  ? ` ${p.name} priced on a call: Book a call in Settings → Billing`
350
- : ` ${p.name} ${usd(p.monthlyUsd)} a month, ${p.includedTokens} tokens included, then $${Number(p.overageUsdPerToken.toFixed(5))} a token${r.plan?.code === p.code ? " (your plan)" : ""}`
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)" : ""}`
351
363
  ),
352
364
  ];
353
365
  }
@@ -359,7 +371,7 @@ function billingUsageText(r) {
359
371
  ];
360
372
  if (r.tokens)
361
373
  lines.push(
362
- `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` : ""}.`
363
375
  );
364
376
  else lines.push("Not billed by usage: quantities only.");
365
377
  if (r.carryOverArriving) lines.push(`${r.carryOverArriving.words}.`);
@@ -371,7 +383,7 @@ function billingUsageText(r) {
371
383
  lines.push("", "By product:", ...r.byProduct.map((p) => ` ${p.label} ${tokensOrQty(p)}`));
372
384
  lines.push("", "By collection:");
373
385
  for (const c of r.byCollection) {
374
- lines.push(` ${c.name}${c.tokens === null ? "" : ` ${c.tokens} tokens`}`);
386
+ lines.push(` ${c.name}${c.tokens === null ? "" : ` ${formatCount(c.tokens)} tokens`}`);
375
387
  for (const p of c.products) lines.push(` ${p.label} ${tokensOrQty(p)}`);
376
388
  }
377
389
  return [...lines, ...plansText(r)].join("\n");
@@ -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 = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.176.4",
3
+ "version": "0.176.5",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",