@letterstory/cli 0.176.4 → 0.176.6
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 +24 -2
- package/lib/commands/admin.mjs +57 -1
- package/lib/commands/org.mjs +29 -17
- 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.6";
|
|
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;
|
|
@@ -183,8 +183,12 @@ export const BOOLEAN_FLAGS = new Set([
|
|
|
183
183
|
"moves",
|
|
184
184
|
"enroll",
|
|
185
185
|
"unenroll",
|
|
186
|
-
// admin demo set --release
|
|
186
|
+
// admin demo set --release; bootstrap / set --copy-from --overwrite
|
|
187
187
|
"release",
|
|
188
|
+
"overwrite",
|
|
189
|
+
// admin demo set --clear-baseline (reset --rebuild is listed below)
|
|
190
|
+
"clear-baseline",
|
|
191
|
+
"reread-company",
|
|
188
192
|
"clean-slate",
|
|
189
193
|
// admin crm record-outcome --draft
|
|
190
194
|
"draft",
|
|
@@ -1012,6 +1016,13 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
1012
1016
|
admin demo set <org-id> [--enroll] [--phantom parked] [--search-console hidden] [--inject <key>]... [--save-as n]
|
|
1013
1017
|
Set what a demo org shows (merged); 'shown' puts a thing
|
|
1014
1018
|
back. --file takes a scenario as JSON. Needs demo:write.
|
|
1019
|
+
admin demo set <org-id> --enroll --copy-from <org-id> [--copy-scenarios a,b] [--overwrite]
|
|
1020
|
+
Set an org up from one already set up: its saved scenarios are
|
|
1021
|
+
copied with the answers re-keyed to this org's questions
|
|
1022
|
+
(Search Console queries and pins aren't carried).
|
|
1023
|
+
admin demo bootstrap <org-id>... --from <org-id> [--scenarios a,b] [--overwrite]
|
|
1024
|
+
Enroll several test orgs and copy a template's scenarios to
|
|
1025
|
+
each. Auto-reset stays off: each resets when someone resets it.
|
|
1015
1026
|
admin demo reset <org-id> <scenario> [--clean-slate] [--close-prs since_applied|all_open|none] [--hold <min>]
|
|
1016
1027
|
Undo the last take (its PRs closed, builds archived), then
|
|
1017
1028
|
show a scenario: real, fresh_geo, fresh_seo, after_approve
|
|
@@ -1021,6 +1032,17 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
1021
1032
|
admin demo set <org-id> --auto-reset <scenario>|off [--every <min>] [--release]
|
|
1022
1033
|
Reset on its own every <min> (default 30) once idle 15
|
|
1023
1034
|
min and not held; --release ends a hold.
|
|
1035
|
+
admin demo set <org-id> --baseline <owner/repo>[@sha] | --clear-baseline
|
|
1036
|
+
Record the commit the org's repo is put back to (the default
|
|
1037
|
+
branch as it is now when no sha). Needs demo:write.
|
|
1038
|
+
admin demo reset <org-id> <scenario> [--restore-repo revert|force] [--rebuild] [--reread-company]
|
|
1039
|
+
The exact reset: --restore-repo puts the repo back to its
|
|
1040
|
+
baseline (revert: a merged PR with the baseline's files;
|
|
1041
|
+
force: the exact commit, history rewritten) and deletes the
|
|
1042
|
+
branches left; --rebuild reads the site again (minutes,
|
|
1043
|
+
model credit); --reread-company also forgets the company
|
|
1044
|
+
read (manifesto, positioning, identity, competitors) and
|
|
1045
|
+
reads it again. Merged PRs are undone only by --restore-repo.
|
|
1024
1046
|
admin demo check <org-id> Is it ready to show? Competitors, targets, answers, the
|
|
1025
1047
|
Plan's rows, the issues open, no PR open, GitHub, the
|
|
1026
1048
|
phantom's site. Exits 1 when not ready.
|
package/lib/commands/admin.mjs
CHANGED
|
@@ -6439,7 +6439,7 @@ const DEMO_ITEM_FLAGS = [
|
|
|
6439
6439
|
"setup",
|
|
6440
6440
|
];
|
|
6441
6441
|
const DEMO_USAGE =
|
|
6442
|
-
"Usage: admin demo guide | list [--enrollable] | show <org-id> [--moves] | set <org-id> [--enroll] [--unenroll] [--file <state.json>] [--phantom parked|shown] [--main-blog …] [--visitors …] [--probes not_run|shown] [--cms hidden|shown] [--publish-target …] [--search-console …] [--github …] [--domain …] [--setup fresh|finished] [--domain-cap n] [--inject <key>]... [--hide <key>]... [--save-as <name>] [--auto-reset <scenario>|off] [--every <minutes>] [--release] | reset <org-id> <scenario> [--clean-slate] [--close-prs since_applied|all_open|none] [--hold <minutes>] | check <org-id>";
|
|
6442
|
+
"Usage: admin demo guide | list [--enrollable] | show <org-id> [--moves] | set <org-id> [--enroll] [--unenroll] [--file <state.json>] [--phantom parked|shown] [--main-blog …] [--visitors …] [--probes not_run|shown] [--cms hidden|shown] [--publish-target …] [--search-console …] [--github …] [--domain …] [--setup fresh|finished] [--domain-cap n] [--inject <key>]... [--hide <key>]... [--save-as <name>] [--baseline <owner/repo>[@sha] | --clear-baseline] [--copy-from <org-id> [--copy-scenarios a,b] [--overwrite]] [--auto-reset <scenario>|off] [--every <minutes>] [--release] | bootstrap <org-id>... --from <org-id> [--scenarios a,b] [--overwrite] | reset <org-id> <scenario> [--clean-slate] [--close-prs since_applied|all_open|none] [--hold <minutes>] [--restore-repo revert|force] [--rebuild] [--reread-company] | check <org-id>";
|
|
6443
6443
|
|
|
6444
6444
|
const readinessLines = (r) =>
|
|
6445
6445
|
r
|
|
@@ -6538,6 +6538,20 @@ async function cmdAdminDemo(ctx) {
|
|
|
6538
6538
|
enroll: flagBool(flags.enroll) || undefined,
|
|
6539
6539
|
unenroll: flagBool(flags.unenroll) || undefined,
|
|
6540
6540
|
save_as: flagStr(flags["save-as"]),
|
|
6541
|
+
repo_baseline: flagBool(flags["clear-baseline"])
|
|
6542
|
+
? null
|
|
6543
|
+
: flagStr(flags.baseline)
|
|
6544
|
+
? (([repo, sha]) => compact({ repo, sha }))(flagStr(flags.baseline).split("@"))
|
|
6545
|
+
: undefined,
|
|
6546
|
+
copy_from: flagStr(flags["copy-from"])
|
|
6547
|
+
? compact({
|
|
6548
|
+
org_id: flagStr(flags["copy-from"]),
|
|
6549
|
+
scenarios: flagCsv(flags["copy-scenarios"]).length
|
|
6550
|
+
? flagCsv(flags["copy-scenarios"])
|
|
6551
|
+
: undefined,
|
|
6552
|
+
overwrite: flagBool(flags.overwrite) || undefined,
|
|
6553
|
+
})
|
|
6554
|
+
: undefined,
|
|
6541
6555
|
auto_reset: flagStr(flags["auto-reset"])
|
|
6542
6556
|
? {
|
|
6543
6557
|
scenario: flagStr(flags["auto-reset"]) === "off" ? null : flagStr(flags["auto-reset"]),
|
|
@@ -6551,6 +6565,45 @@ async function cmdAdminDemo(ctx) {
|
|
|
6551
6565
|
printResult(io, flags, result, (r) => r.notes.join("\n") || "No change.");
|
|
6552
6566
|
return 0;
|
|
6553
6567
|
}
|
|
6568
|
+
case "bootstrap": {
|
|
6569
|
+
// Several test orgs set up from one that already is: enrolled, its saved scenarios copied. Never
|
|
6570
|
+
// turns auto-reset on, so each resets only when someone resets it.
|
|
6571
|
+
const from = flagStr(flags.from);
|
|
6572
|
+
const orgIds = positionals.slice(1).flatMap((p) => p.split(",").filter(Boolean));
|
|
6573
|
+
if (!from || !orgIds.length) throw new CliError(DEMO_USAGE);
|
|
6574
|
+
const scenarios = flagCsv(flags.scenarios);
|
|
6575
|
+
const results = [];
|
|
6576
|
+
for (const orgId of orgIds) {
|
|
6577
|
+
try {
|
|
6578
|
+
const r = await staffRequest(
|
|
6579
|
+
ctx,
|
|
6580
|
+
"PATCH",
|
|
6581
|
+
`${DEMO}/${encodeURIComponent(orgId)}`,
|
|
6582
|
+
compact({
|
|
6583
|
+
enroll: true,
|
|
6584
|
+
copy_from: compact({
|
|
6585
|
+
org_id: from,
|
|
6586
|
+
scenarios: scenarios.length ? scenarios : undefined,
|
|
6587
|
+
overwrite: flagBool(flags.overwrite) || undefined,
|
|
6588
|
+
}),
|
|
6589
|
+
})
|
|
6590
|
+
);
|
|
6591
|
+
results.push({ org_id: orgId, ok: true, notes: r.notes });
|
|
6592
|
+
} catch (e) {
|
|
6593
|
+
results.push({ org_id: orgId, ok: false, error: e instanceof Error ? e.message : String(e) });
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
printResult(io, flags, { results }, (r) =>
|
|
6597
|
+
r.results
|
|
6598
|
+
.map((x) =>
|
|
6599
|
+
x.ok
|
|
6600
|
+
? `ok ${x.org_id}\n${x.notes.map((n) => ` ${n}`).join("\n")}`
|
|
6601
|
+
: `FAIL ${x.org_id}: ${x.error}`
|
|
6602
|
+
)
|
|
6603
|
+
.join("\n")
|
|
6604
|
+
);
|
|
6605
|
+
return results.every((x) => x.ok) ? 0 : 1;
|
|
6606
|
+
}
|
|
6554
6607
|
case "reset": {
|
|
6555
6608
|
const orgId = requirePositional(positionals, 1, "org-id");
|
|
6556
6609
|
const scenario = requirePositional(positionals, 2, "scenario");
|
|
@@ -6562,6 +6615,9 @@ async function cmdAdminDemo(ctx) {
|
|
|
6562
6615
|
close_prs: flagStr(flags["close-prs"]),
|
|
6563
6616
|
clean_slate: flagBool(flags["clean-slate"]) || undefined,
|
|
6564
6617
|
hold_minutes: flagNum(flags.hold) ?? undefined,
|
|
6618
|
+
restore_repo: flagStr(flags["restore-repo"]),
|
|
6619
|
+
rebuild: flagBool(flags.rebuild) || undefined,
|
|
6620
|
+
reread_company: flagBool(flags["reread-company"]) || undefined,
|
|
6565
6621
|
})
|
|
6566
6622
|
);
|
|
6567
6623
|
printResult(io, flags, result, (r) => [r.notes.join("\n"), readinessLines(r.readiness)].join("\n"));
|
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,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 ${
|
|
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
|
-
)}: ${
|
|
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)} ${
|
|
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) =>
|
|
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} ${
|
|
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");
|
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 = {};
|