@letterstory/cli 0.158.4 → 0.161.0
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/README.md +8 -16
- package/lib/cli.mjs +54 -22
- package/lib/commands/admin.mjs +324 -158
- package/lib/commands/ask.mjs +45 -0
- package/lib/commands/org.mjs +51 -1
- package/lib/commands/visits.mjs +11 -7
- package/lib/commands.mjs +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -430,30 +430,22 @@ how it was tested, and what we learned and why.
|
|
|
430
430
|
|
|
431
431
|
```bash
|
|
432
432
|
# Needs a STAFF key with recipes:read (reads) and recipes:write (writes): mint it on
|
|
433
|
-
# /superadmin/
|
|
433
|
+
# /superadmin/recipes → "Your agent's key". Recipes are global: one library behind every
|
|
434
434
|
# account's Plan. The same routes and functions as that page.
|
|
435
435
|
export LETTERSTORY_STAFF_API_KEY=<your staff key with recipes:read,recipes:write>
|
|
436
436
|
|
|
437
|
-
letterstory admin recipes vocab # what a recipe can say: fields,
|
|
437
|
+
letterstory admin recipes vocab # what a recipe can say: tabs, fields, moves, outcomes, kinds, primitives
|
|
438
438
|
letterstory admin recipes export --out recipes.json # the library as a file
|
|
439
439
|
letterstory admin recipes import recipes.json --dry-run # what would be created / changed / retired
|
|
440
|
-
letterstory admin recipes import recipes.json # write it (matched by id, else name)
|
|
441
|
-
letterstory admin recipes save --name "
|
|
440
|
+
letterstory admin recipes import recipes.json # write it (matched by id, else tab and name)
|
|
441
|
+
letterstory admin recipes save --tab build --name "Docs it already writes" --look-at "…" --when-to-use "…" --company-types devtools
|
|
442
|
+
letterstory admin letterpress settings # the one judgement's weights per ask; per lens its mode (off / shadow / live) and bar
|
|
443
|
+
letterstory admin letterpress flip fix shadow # run the one judgement beside today's on every Fix pass, recorded, nothing shown changes
|
|
444
|
+
letterstory admin letterpress set weights.fix.prior 0.3 # one weight; the version bumps, the previous body is kept
|
|
445
|
+
letterstory admin recipes stats # per tab and recipe: shown, dismissed, and why
|
|
442
446
|
letterstory admin recipes save <id> --disable # retire one (delete <id> --yes removes it)
|
|
443
447
|
```
|
|
444
448
|
|
|
445
|
-
### Staff: Build's suggestion recipes
|
|
446
|
-
|
|
447
|
-
```bash
|
|
448
|
-
# The same staff key (recipes:read / recipes:write). Build's suggestion recipes are plain-language
|
|
449
|
-
# ways Letterpress finds what a site should build: what to look at, what an obvious yes is, what is
|
|
450
|
-
# not one, an example. Guidance, never rules: each proposal still cites evidence and passes Jev.
|
|
451
|
-
letterstory admin suggestion-recipes export --out suggestion-recipes.json
|
|
452
|
-
letterstory admin suggestion-recipes import suggestion-recipes.json --dry-run
|
|
453
|
-
letterstory admin suggestion-recipes save --name "Docs it already writes" --look-at "…" --obvious-yes "…"
|
|
454
|
-
letterstory admin suggestion-recipes stats # per recipe: shown, dismissed, and why
|
|
455
|
-
```
|
|
456
|
-
|
|
457
449
|
### Staff: the CRM pipeline
|
|
458
450
|
|
|
459
451
|
```bash
|
package/lib/cli.mjs
CHANGED
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
cmdFeedback,
|
|
55
55
|
cmdRepo,
|
|
56
56
|
cmdBuild,
|
|
57
|
+
cmdAsk,
|
|
57
58
|
cmdSite,
|
|
58
59
|
cmdEvals,
|
|
59
60
|
cmdOfferings,
|
|
@@ -66,12 +67,14 @@ import {
|
|
|
66
67
|
|
|
67
68
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
68
69
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
69
|
-
export const VERSION = "0.
|
|
70
|
+
export const VERSION = "0.161.0";
|
|
70
71
|
|
|
71
72
|
// Flags that never take a value. Listing them explicitly means `deploy get --json <id>`
|
|
72
73
|
// can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
|
|
73
74
|
// `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
|
|
74
75
|
export const BOOLEAN_FLAGS = new Set([
|
|
76
|
+
// admin letterpress status | gaps: the customers' reading (no test or demo orgs).
|
|
77
|
+
"customers",
|
|
75
78
|
// build: repeat an open build's ask; post its progress in the org's Slack channel.
|
|
76
79
|
"again",
|
|
77
80
|
"notify-slack",
|
|
@@ -141,7 +144,7 @@ export const BOOLEAN_FLAGS = new Set([
|
|
|
141
144
|
"enroll",
|
|
142
145
|
"unenroll",
|
|
143
146
|
"clean-slate",
|
|
144
|
-
// admin recipes list --enabled-only, save --enable|--disable, import --retire-missing
|
|
147
|
+
// admin recipes list --tab --enabled-only, save --enable|--disable, import --retire-missing
|
|
145
148
|
"enabled-only",
|
|
146
149
|
"enable",
|
|
147
150
|
"disable",
|
|
@@ -871,21 +874,45 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
871
874
|
read-only SQL across every org; --sql prints
|
|
872
875
|
the queries behind the answer. Needs the
|
|
873
876
|
fleet:query capability on the staff key.
|
|
874
|
-
admin recipes list [--enabled-only] | show <id|name> | vocab
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
says what a recipe can say (
|
|
878
|
-
|
|
879
|
-
|
|
877
|
+
admin recipes list [--tab plan|build|fix] [--enabled-only] | show <id|name> | vocab | stats
|
|
878
|
+
Recipes: Letter's one library of direction for
|
|
879
|
+
Letterpress on Plan, Build and Fix (/superadmin/recipes).
|
|
880
|
+
vocab says what a recipe can say (tabs, fields, the
|
|
881
|
+
catalog actions a plan recipe's moves may name, outcomes,
|
|
882
|
+
company types, primitives); stats how each recipe's
|
|
883
|
+
suggestions fare. Needs recipes:read.
|
|
884
|
+
admin recipes export [--tab …] [--out recipes.json] The library as a file import reads back.
|
|
880
885
|
admin recipes import <file> [--dry-run] [--retire-missing]
|
|
881
886
|
Write a library in one call: each recipe matched by id,
|
|
882
|
-
else name, then changed or created. --dry-run
|
|
883
|
-
nothing; --retire-missing retires every enabled
|
|
884
|
-
the file leaves out. Exits 1 if any
|
|
885
|
-
|
|
886
|
-
|
|
887
|
+
else tab and name, then changed or created. --dry-run
|
|
888
|
+
writes nothing; --retire-missing retires every enabled
|
|
889
|
+
recipe of the file's tabs it leaves out. Exits 1 if any
|
|
890
|
+
row failed.
|
|
891
|
+
admin recipes save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …]
|
|
892
|
+
[--when-not-to-use …] [--example …] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none]
|
|
893
|
+
[--company-types a,b|none] [--enable|--disable] [--position n]
|
|
887
894
|
Create one (no id) or change one. Needs recipes:write.
|
|
888
895
|
admin recipes delete <id> --yes Delete for good (save --disable retires and keeps it).
|
|
896
|
+
admin letterpress status [--customers] Letterpress as it runs now: per lens its mode, bar, recipes,
|
|
897
|
+
runs, model and prompt hash, how often the shadow agreed,
|
|
898
|
+
how runs grounded (full / part / none). Needs recipes:read.
|
|
899
|
+
admin letterpress gaps [--customers] The gaps the numbers show, each with the one call that
|
|
900
|
+
addresses it, pre-filled. Needs recipes:read.
|
|
901
|
+
admin letterpress replay <run-id> A Build or Fix run through today's checks and settings, no
|
|
902
|
+
model: what it would keep, drop and rank against what it
|
|
903
|
+
showed; --json carries the run as an evals case.
|
|
904
|
+
admin letterpress settings What steers Letterpress beside the recipes: the one
|
|
905
|
+
judgement's weights per ask and, per lens, its mode (off,
|
|
906
|
+
shadow or live) and bar. Needs recipes:read.
|
|
907
|
+
admin letterpress flip <build|fix|plan> <off|shadow|live>
|
|
908
|
+
Flip a lens (Build, Fix: the one judgement; Plan: the pick
|
|
909
|
+
with recipes as direction). Shadow: both run and are
|
|
910
|
+
recorded on every run, today's shown; live: the new one
|
|
911
|
+
decides. Recorded as yours. Needs recipes:write.
|
|
912
|
+
admin letterpress set <weights.<ask>.<reading>|lenses.<lens>.mode|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|asks.<lens>.ask|asks.<lens>.guidance> <value>
|
|
913
|
+
Change one weight, one bar, or a lens's ask and guidance (the
|
|
914
|
+
opinions Letterpress chooses by, as staff's words); the version
|
|
915
|
+
bumps and the previous body is kept. Needs recipes:write.
|
|
889
916
|
admin demo guide How to run a demo, step by step, and what every knob and
|
|
890
917
|
seed shows on screen. Read it first.
|
|
891
918
|
admin demo list [--enrollable] | show <org-id> [--moves]
|
|
@@ -899,15 +926,6 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
899
926
|
show a scenario: real, fresh_geo, fresh_seo, after_approve
|
|
900
927
|
or a saved one. --clean-slate closes every open PR and
|
|
901
928
|
archives every build.
|
|
902
|
-
admin suggestion-recipes list|export [--out f.json]|import <f.json> [--dry-run] [--retire-missing]|stats
|
|
903
|
-
Build's suggestion recipes: plain-language ways
|
|
904
|
-
Letterpress finds what a site should build (look at,
|
|
905
|
-
obvious yes, not a yes, example). stats: per recipe,
|
|
906
|
-
suggestions shown and dismissed, with the reasons.
|
|
907
|
-
admin suggestion-recipes save [<id>] [--file r.json] [--name …] [--look-at …] [--obvious-yes …] [--not-a-yes …]
|
|
908
|
-
[--example …] [--company-types a,b|none] [--enable|--disable] [--position n]
|
|
909
|
-
Create one (no id) or change one. Needs recipes:write.
|
|
910
|
-
admin suggestion-recipes delete <id> --yes Delete for good (save --disable retires and keeps it).
|
|
911
929
|
admin brand-detection <org-id> [--term <t>]... [--exact <t>]... [--exclude <phrase>]... [--note "…"] | --clear [--note "…"]
|
|
912
930
|
How a client's brand is detected in AI answers, with
|
|
913
931
|
every earlier setting; with flags, set the exact set
|
|
@@ -995,6 +1013,12 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
995
1013
|
cover what the app ledger cannot see; a CSV
|
|
996
1014
|
import sums Concentrate's log export.
|
|
997
1015
|
Needs spend:read (reads) / spend:write (writes).
|
|
1016
|
+
admin billing legacy mark <org-id> --why "…" | --all --why "…" [--apply]
|
|
1017
|
+
Mark legacy orgs: free until migrated, never gated
|
|
1018
|
+
by the free paywall (--all: everyone who pays today)
|
|
1019
|
+
admin billing free exposure | backfill --why "…" [--apply]
|
|
1020
|
+
Who the free paywall would stop today; the one-time
|
|
1021
|
+
signup grant for self-serve orgs with none
|
|
998
1022
|
admin billing lago catalog [--apply] [--include-drafts]
|
|
999
1023
|
| provision <org-id> --plan starter|growth|scale [--ratio 1|2|4|8 (8 needs --why "…")] [--complimentary N] [--stripe-customer cus_…] [--start ISO] [--review D]
|
|
1000
1024
|
| reconcile [--org <org-id>] | forward
|
|
@@ -1168,6 +1192,8 @@ Seers (event-driven signals -> drafts):
|
|
|
1168
1192
|
the admins for more
|
|
1169
1193
|
org billing usage This period by product and collection: quantities,
|
|
1170
1194
|
and tokens and dollars when billed by usage
|
|
1195
|
+
org billing rewards [claim <action>] Free tokens for connecting Slack, signing in with the
|
|
1196
|
+
CLI and following Letter; claim one, once per org
|
|
1171
1197
|
org billing invoices Every invoice (paid, open, failed, refunded) and the
|
|
1172
1198
|
next one: when it issues and what it comes to
|
|
1173
1199
|
org linear [teams [--team <id|key>] | set --team <id|key> [--project <id>|none] | disconnect]
|
|
@@ -1421,6 +1447,11 @@ Mail:
|
|
|
1421
1447
|
(any phone format; country as a name or a 2-letter code)
|
|
1422
1448
|
|
|
1423
1449
|
Insights:
|
|
1450
|
+
ask [<words…>] [--outcome geo|seo|…] [--lens fix|build] [--site host]
|
|
1451
|
+
Ask Letterpress what to do next: the plan for an outcome (the
|
|
1452
|
+
Plan tab's box), what's broken (--lens fix, most pressing
|
|
1453
|
+
first), what to build (--lens build), or your own words. Nothing asked:
|
|
1454
|
+
each list's head. The same answer as the console and Slack.
|
|
1424
1455
|
insights summary [--period …] [--part <block>]... Measure Overview: AI named/cited rates, share of voice, search, targets
|
|
1425
1456
|
insights reads [--period …] [--site all|own|phantoms|<key>]... [--path <path>] [--engine <operator>]
|
|
1426
1457
|
Measure → Reads: AI engines and people reading your sites, counted one way
|
|
@@ -1666,6 +1697,7 @@ const CLIENT_COMMANDS = {
|
|
|
1666
1697
|
feedback: cmdFeedback,
|
|
1667
1698
|
repo: cmdRepo,
|
|
1668
1699
|
build: cmdBuild,
|
|
1700
|
+
ask: cmdAsk,
|
|
1669
1701
|
site: cmdSite,
|
|
1670
1702
|
evals: cmdEvals,
|
|
1671
1703
|
visits: cmdVisits,
|
package/lib/commands/admin.mjs
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
// admin brand-detection <org-id> (fleet:read)
|
|
20
20
|
// admin brand-detection <org-id> [--term t]... [--exact t]... [--exclude p]... [--note "…"] | --clear [--note "…"] (fleet:instrument)
|
|
21
21
|
// admin recipes list|show|vocab|export|import|save|delete … (recipes:read / recipes:write)
|
|
22
|
+
// admin letterpress settings|flip|set … (recipes:read / recipes:write)
|
|
22
23
|
// admin demo guide|list|show|set|reset … (demo:read / demo:write)
|
|
23
24
|
// admin models runs|run|star|unstar|scoreboard|requests|request|sampling … (models:read / models:write)
|
|
24
25
|
// admin replays [--org <id>] [--target <id>] [--status …] [--limit n] (fleet:read)
|
|
@@ -4929,168 +4930,60 @@ async function cmdAdminRepublish(ctx) {
|
|
|
4929
4930
|
return failed.length ? 1 : 0;
|
|
4930
4931
|
}
|
|
4931
4932
|
|
|
4932
|
-
const
|
|
4933
|
-
|
|
4933
|
+
const RECIPES = "/api/superadmin/recipes";
|
|
4934
|
+
/** The fields a recipe file carries: what import_recipes reads back. */
|
|
4935
|
+
const RECIPE_FILE_FIELDS = [
|
|
4934
4936
|
"id",
|
|
4935
4937
|
"name",
|
|
4938
|
+
"tab",
|
|
4939
|
+
"outcomes",
|
|
4940
|
+
"company_types",
|
|
4941
|
+
"fits_when",
|
|
4936
4942
|
"look_at",
|
|
4937
|
-
"
|
|
4938
|
-
"
|
|
4943
|
+
"when_to_use",
|
|
4944
|
+
"when_not_to_use",
|
|
4939
4945
|
"example",
|
|
4940
|
-
"
|
|
4941
|
-
"
|
|
4942
|
-
"position",
|
|
4943
|
-
];
|
|
4944
|
-
const SUGGESTION_RECIPES_USAGE =
|
|
4945
|
-
"Usage: admin suggestion-recipes list | export [--out <file>] | import <file> [--dry-run] [--retire-missing] | save [<id>] [--name …] [--look-at …] [--obvious-yes …] [--not-a-yes …] [--example …] [--company-types a,b|none] [--enable|--disable] [--position n] | delete <id> --yes | stats";
|
|
4946
|
-
|
|
4947
|
-
const suggestionRecipeForFile = (r) => Object.fromEntries(SUGGESTION_RECIPE_FIELDS.map((k) => [k, r[k]]));
|
|
4948
|
-
|
|
4949
|
-
/**
|
|
4950
|
-
* `admin suggestion-recipes …` — the ways Build's suggestion pass looks for what a site should
|
|
4951
|
-
* build (src/lib/suggestion-recipes): guidance Letterpress reads, never rules. The loop is
|
|
4952
|
-
* `export --out recipes.json` → edit → `import recipes.json --dry-run` → `import recipes.json`,
|
|
4953
|
-
* and `stats` says how each recipe's suggestions fare (shown, dismissed, why). Reads need
|
|
4954
|
-
* recipes:read on the staff key, writes recipes:write.
|
|
4955
|
-
*/
|
|
4956
|
-
async function cmdAdminSuggestionRecipes(ctx) {
|
|
4957
|
-
const { flags, positionals, io } = ctx;
|
|
4958
|
-
const all = async () => (await staffRequest(ctx, "GET", SUGGESTION_RECIPES)).recipes ?? [];
|
|
4959
|
-
switch (positionals[0]) {
|
|
4960
|
-
case "list": {
|
|
4961
|
-
const recipes = await all();
|
|
4962
|
-
printResult(io, flags, { recipes }, (r) =>
|
|
4963
|
-
r.recipes.length
|
|
4964
|
-
? r.recipes
|
|
4965
|
-
.map(
|
|
4966
|
-
(x) =>
|
|
4967
|
-
`${String(x.position).padStart(4)} ${x.enabled ? "on " : "off"} ${x.name} [${x.company_types?.length ? x.company_types.join(",") : "every kind"}] ${x.id}`
|
|
4968
|
-
)
|
|
4969
|
-
.join("\n")
|
|
4970
|
-
: "No recipes yet."
|
|
4971
|
-
);
|
|
4972
|
-
return 0;
|
|
4973
|
-
}
|
|
4974
|
-
case "export": {
|
|
4975
|
-
const file = { recipes: (await all()).map(suggestionRecipeForFile) };
|
|
4976
|
-
const out = flagStr(flags.out);
|
|
4977
|
-
if (out) {
|
|
4978
|
-
writeFileSync(out, `${JSON.stringify(file, null, 2)}\n`);
|
|
4979
|
-
ok(ctx, `Wrote ${file.recipes.length} recipe(s) to ${out}.`);
|
|
4980
|
-
} else io.log(JSON.stringify(file, null, 2));
|
|
4981
|
-
return 0;
|
|
4982
|
-
}
|
|
4983
|
-
case "import": {
|
|
4984
|
-
const path = requirePositional(positionals, 1, "file");
|
|
4985
|
-
const parsed = readJson(path);
|
|
4986
|
-
const recipes = Array.isArray(parsed) ? parsed : parsed?.recipes;
|
|
4987
|
-
if (!Array.isArray(recipes)) throw new CliError(`${path}: expected { "recipes": [...] } or an array`);
|
|
4988
|
-
const result = await staffPost(ctx, `${SUGGESTION_RECIPES}/import`, {
|
|
4989
|
-
recipes: recipes.map((r) => compact(suggestionRecipeForFile(r))),
|
|
4990
|
-
dry_run: flagBool(flags["dry-run"]),
|
|
4991
|
-
retire_missing: flagBool(flags["retire-missing"]),
|
|
4992
|
-
});
|
|
4993
|
-
printResult(io, flags, result, (r) =>
|
|
4994
|
-
[
|
|
4995
|
-
...r.results.map(
|
|
4996
|
-
(row) =>
|
|
4997
|
-
`${row.action.padEnd(9)} ${row.name}${row.changed.length && row.action !== "create" ? ` (${row.changed.join(", ")})` : ""}${row.error ? ` → ${row.error}` : ""}`
|
|
4998
|
-
),
|
|
4999
|
-
r.dry_run ? "Nothing was written (--dry-run)." : "",
|
|
5000
|
-
]
|
|
5001
|
-
.filter(Boolean)
|
|
5002
|
-
.join("\n")
|
|
5003
|
-
);
|
|
5004
|
-
return result.results?.some((r) => r.action === "failed") ? 1 : 0;
|
|
5005
|
-
}
|
|
5006
|
-
case "save": {
|
|
5007
|
-
const fields = compact({
|
|
5008
|
-
name: flagStr(flags.name),
|
|
5009
|
-
look_at: flagStr(flags["look-at"]),
|
|
5010
|
-
obvious_yes: flagStr(flags["obvious-yes"]),
|
|
5011
|
-
not_a_yes: flagStr(flags["not-a-yes"]),
|
|
5012
|
-
example: flagStr(flags.example),
|
|
5013
|
-
company_types: recipeListFlag(flags, "company-types"),
|
|
5014
|
-
enabled: flagBool(flags.disable) ? false : flagBool(flags.enable) ? true : undefined,
|
|
5015
|
-
position: flagNum(flags.position),
|
|
5016
|
-
});
|
|
5017
|
-
const id = positionals[1];
|
|
5018
|
-
const result = id
|
|
5019
|
-
? await staffRequest(ctx, "PATCH", `${SUGGESTION_RECIPES}/${encodeURIComponent(id)}`, fields)
|
|
5020
|
-
: await staffPost(ctx, SUGGESTION_RECIPES, fields);
|
|
5021
|
-
ok(ctx, `${result.created ? "Created" : "Saved"} "${result.recipe.name}" (${result.recipe.id}).`);
|
|
5022
|
-
printResult(io, flags, result);
|
|
5023
|
-
return 0;
|
|
5024
|
-
}
|
|
5025
|
-
case "delete": {
|
|
5026
|
-
const id = requirePositional(positionals, 1, "id");
|
|
5027
|
-
if (!flagBool(flags.yes)) {
|
|
5028
|
-
io.error(`Re-run with --yes to delete for good (save ${id} --disable retires one and keeps it).`);
|
|
5029
|
-
return 1;
|
|
5030
|
-
}
|
|
5031
|
-
const result = await staffRequest(ctx, "DELETE", `${SUGGESTION_RECIPES}/${encodeURIComponent(id)}`);
|
|
5032
|
-
ok(ctx, `Deleted ${id}.`);
|
|
5033
|
-
printResult(io, flags, result);
|
|
5034
|
-
return 0;
|
|
5035
|
-
}
|
|
5036
|
-
case "stats": {
|
|
5037
|
-
const result = await staffRequest(ctx, "GET", `${SUGGESTION_RECIPES}/stats`);
|
|
5038
|
-
printResult(io, flags, result, (r) =>
|
|
5039
|
-
r.stats.length
|
|
5040
|
-
? r.stats
|
|
5041
|
-
.map(
|
|
5042
|
-
(s) =>
|
|
5043
|
-
`${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${s.recipe}${s.reasons.length ? `\n why: ${s.reasons.slice(0, 3).join(" · ")}` : ""}`
|
|
5044
|
-
)
|
|
5045
|
-
.join("\n")
|
|
5046
|
-
: "No suggestions from the pass yet."
|
|
5047
|
-
);
|
|
5048
|
-
return 0;
|
|
5049
|
-
}
|
|
5050
|
-
default:
|
|
5051
|
-
throw new CliError(SUGGESTION_RECIPES_USAGE);
|
|
5052
|
-
}
|
|
5053
|
-
}
|
|
5054
|
-
|
|
5055
|
-
const RECIPES = "/api/superadmin/plan-recipes";
|
|
5056
|
-
/** The fields a recipe file carries: what import_plan_recipes reads back. */
|
|
5057
|
-
const RECIPE_FILE_FIELDS = [
|
|
5058
|
-
"id",
|
|
5059
|
-
"name",
|
|
5060
|
-
"audience",
|
|
5061
|
-
"examples",
|
|
5062
|
-
"prompt",
|
|
4946
|
+
"impact",
|
|
4947
|
+
"moves",
|
|
5063
4948
|
"primitives",
|
|
5064
|
-
"goals",
|
|
5065
|
-
"company_types",
|
|
5066
4949
|
"enabled",
|
|
5067
4950
|
"position",
|
|
5068
4951
|
];
|
|
5069
4952
|
const RECIPES_USAGE =
|
|
5070
|
-
"Usage: admin recipes list [--enabled-only] | show <id|name> | vocab | export [--out <file>] | import <file> [--dry-run] [--retire-missing] | save [<id>] [--file <recipe.json>] [--name …] [--
|
|
4953
|
+
"Usage: admin recipes list [--tab plan|build|fix] [--enabled-only] | show <id|name> | vocab | stats | export [--tab …] [--out <file>] | import <file> [--dry-run] [--retire-missing] | save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …] [--when-not-to-use …] [--example …] [--impact 1..10] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none] [--enable|--disable] [--position n] | delete <id> --yes";
|
|
5071
4954
|
|
|
5072
4955
|
const recipeForFile = (r) => Object.fromEntries(RECIPE_FILE_FIELDS.map((k) => [k, r[k]]));
|
|
5073
4956
|
|
|
5074
4957
|
function recipeLine(r) {
|
|
5075
4958
|
const scope = [
|
|
5076
|
-
r.
|
|
4959
|
+
r.outcomes?.length ? `outcomes ${r.outcomes.join(",")}` : "every outcome",
|
|
5077
4960
|
r.company_types?.length ? `kinds ${r.company_types.join(",")}` : "every kind",
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
4961
|
+
r.tab === "plan"
|
|
4962
|
+
? `${r.moves?.length ?? 0} moves · stands up ${r.primitives?.length ? r.primitives.join(",") : "nothing"}`
|
|
4963
|
+
: null,
|
|
4964
|
+
]
|
|
4965
|
+
.filter(Boolean)
|
|
4966
|
+
.join(" · ");
|
|
4967
|
+
return `${String(r.position).padStart(4)} ${r.enabled ? "on " : "off"} ${r.tab.padEnd(5)} ${r.name} v${r.version} [${scope}] ${r.id}`;
|
|
5081
4968
|
}
|
|
5082
4969
|
|
|
5083
4970
|
function recipeDetail(r) {
|
|
5084
4971
|
return [
|
|
5085
|
-
`${r.name} ${r.enabled ? "(enabled)" : "(retired)"} ${r.id}`,
|
|
5086
|
-
` position:
|
|
5087
|
-
`
|
|
5088
|
-
` kinds:
|
|
5089
|
-
` stands up:
|
|
5090
|
-
`
|
|
5091
|
-
`
|
|
5092
|
-
`
|
|
5093
|
-
|
|
4972
|
+
`${r.name} ${r.enabled ? "(enabled)" : "(retired)"} ${r.tab} v${r.version} ${r.id}`,
|
|
4973
|
+
` position: ${r.position}`,
|
|
4974
|
+
` outcomes: ${r.outcomes?.join(", ") || "every outcome"}`,
|
|
4975
|
+
` kinds: ${r.company_types?.join(", ") || "every kind"}`,
|
|
4976
|
+
r.tab === "plan" ? ` stands up: ${r.primitives?.join(", ") || "nothing"}` : null,
|
|
4977
|
+
` look at: ${r.look_at || "—"}`,
|
|
4978
|
+
` when to use: ${r.when_to_use || "—"}`,
|
|
4979
|
+
` when not to use: ${r.when_not_to_use || "—"}`,
|
|
4980
|
+
` example: ${r.example || "—"}`,
|
|
4981
|
+
r.tab === "plan"
|
|
4982
|
+
? ` moves:\n${(r.moves ?? []).map((m) => ` ${m.id}${m.stage ? ` · ${m.stage}` : ""}${m.after?.length ? ` · after ${m.after.join(",")}` : ""}${m.recommend ? " · recommend" : ""}${m.keep ? " · keep" : ""}${m.optional ? " · optional" : ""}${m.required ? " · required" : ""}${m.why ? ` · "${m.why}"` : ""}`).join("\n")}`
|
|
4983
|
+
: null,
|
|
4984
|
+
]
|
|
4985
|
+
.filter(Boolean)
|
|
4986
|
+
.join("\n");
|
|
5094
4987
|
}
|
|
5095
4988
|
|
|
5096
4989
|
function readJson(path) {
|
|
@@ -5125,33 +5018,208 @@ function recipeFromFlags(flags) {
|
|
|
5125
5018
|
if (!base || typeof base !== "object" || Array.isArray(base) || Array.isArray(base.recipes)) {
|
|
5126
5019
|
throw new CliError("--file holds one recipe object; use admin recipes import for several");
|
|
5127
5020
|
}
|
|
5128
|
-
const
|
|
5021
|
+
const movesFlag = flagStr(flags["moves-json"]);
|
|
5022
|
+
let moves;
|
|
5023
|
+
if (movesFlag !== undefined) {
|
|
5024
|
+
try {
|
|
5025
|
+
moves = JSON.parse(movesFlag);
|
|
5026
|
+
} catch (err) {
|
|
5027
|
+
throw new CliError(`--moves-json holds a JSON array of moves: ${err.message}`);
|
|
5028
|
+
}
|
|
5029
|
+
}
|
|
5129
5030
|
return compact({
|
|
5130
5031
|
...compact(recipeForFile(base)),
|
|
5131
5032
|
name: flagStr(flags.name),
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5033
|
+
tab: flagStr(flags.tab),
|
|
5034
|
+
look_at: flagStr(flags["look-at"]),
|
|
5035
|
+
when_to_use: flagStr(flags["when-to-use"]),
|
|
5036
|
+
when_not_to_use: flagStr(flags["when-not-to-use"]),
|
|
5037
|
+
impact: flags.impact !== undefined ? Number(flags.impact) : undefined,
|
|
5038
|
+
example: flagStr(flags.example),
|
|
5039
|
+
moves,
|
|
5135
5040
|
primitives: recipeListFlag(flags, "primitives"),
|
|
5136
|
-
|
|
5041
|
+
outcomes: recipeListFlag(flags, "outcomes"),
|
|
5137
5042
|
company_types: recipeListFlag(flags, "company-types"),
|
|
5138
5043
|
enabled: flagBool(flags.disable) ? false : flagBool(flags.enable) ? true : undefined,
|
|
5139
5044
|
position: flagNum(flags.position),
|
|
5140
5045
|
});
|
|
5141
5046
|
}
|
|
5142
5047
|
|
|
5048
|
+
const ENGINE = "/api/superadmin/engine-settings";
|
|
5049
|
+
const LETTERPRESS = "/api/superadmin/letterpress";
|
|
5050
|
+
const ENGINE_USAGE =
|
|
5051
|
+
"Usage: admin letterpress status | gaps | replay <run-id> | settings | flip <build|fix|plan> <off|shadow|live> | set <weights.<ask>.<reading>|lenses.<lens>.mode|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|asks.<lens>.ask|asks.<lens>.guidance> <value>";
|
|
5052
|
+
|
|
5053
|
+
/** One number of the settings from a dotted path and a value: the PUT body save_engine_settings reads. */
|
|
5054
|
+
function engineSettingsPatch(path, value) {
|
|
5055
|
+
const parts = String(path ?? "").split(".");
|
|
5056
|
+
if (parts[0] === "weights" && parts.length === 3) {
|
|
5057
|
+
const n = Number(value);
|
|
5058
|
+
if (!Number.isFinite(n)) throw new CliError(`${path}: a number 0..1`);
|
|
5059
|
+
return { weights: { [parts[1]]: { [parts[2]]: n } } };
|
|
5060
|
+
}
|
|
5061
|
+
if (parts[0] === "asks" && (parts[2] === "ask" || parts[2] === "guidance") && parts.length === 3)
|
|
5062
|
+
return { asks: { [parts[1]]: { [parts[2]]: String(value) } } };
|
|
5063
|
+
if (parts[0] === "lenses" && parts[2] === "mode" && parts.length === 3)
|
|
5064
|
+
return { lenses: { [parts[1]]: { mode: String(value) } } };
|
|
5065
|
+
if (parts[0] === "lenses" && parts[2] === "bar" && parts.length === 3 && value === "none")
|
|
5066
|
+
return { lenses: { [parts[1]]: { bar: null } } };
|
|
5067
|
+
if (parts[0] === "lenses" && parts[2] === "bar" && parts.length === 4) {
|
|
5068
|
+
const n = Number(value);
|
|
5069
|
+
if (!Number.isFinite(n)) throw new CliError(`${path}: a number 0..1`);
|
|
5070
|
+
return { lenses: { [parts[1]]: { bar: { [parts[3]]: n } } } };
|
|
5071
|
+
}
|
|
5072
|
+
throw new CliError(ENGINE_USAGE);
|
|
5073
|
+
}
|
|
5074
|
+
|
|
5075
|
+
/** The settings as a few lines: each lens's judgement and bar, then the weights per ask. */
|
|
5076
|
+
function engineSettingsText(r) {
|
|
5077
|
+
const s = r.settings;
|
|
5078
|
+
const lenses = Object.entries(s.lenses).map(
|
|
5079
|
+
([lens, l]) =>
|
|
5080
|
+
`${lens.padEnd(6)} mode ${l.mode.padEnd(6)} bar ${
|
|
5081
|
+
l.bar
|
|
5082
|
+
? Object.entries(l.bar)
|
|
5083
|
+
.map(([k, v]) => `${k}≥${v}`)
|
|
5084
|
+
.join(" ")
|
|
5085
|
+
: "none"
|
|
5086
|
+
}`
|
|
5087
|
+
);
|
|
5088
|
+
const keys = ["obvious", "specific", "carries", "one", "serves", "prior"];
|
|
5089
|
+
const weights = [
|
|
5090
|
+
`${"ask".padEnd(6)} ${keys.map((k) => k.padStart(8)).join("")}`,
|
|
5091
|
+
...Object.entries(s.weights).map(
|
|
5092
|
+
([ask, w]) => `${ask.padEnd(6)} ${keys.map((k) => String(w[k]).padStart(8)).join("")}`
|
|
5093
|
+
),
|
|
5094
|
+
];
|
|
5095
|
+
const asks = Object.entries(s.asks ?? {}).flatMap(([lens, a]) => [
|
|
5096
|
+
`${lens.padEnd(6)} ask: ${a.ask}`,
|
|
5097
|
+
...String(a.guidance ?? "")
|
|
5098
|
+
.split("\n")
|
|
5099
|
+
.filter(Boolean)
|
|
5100
|
+
.map((l) => ` · ${l}`),
|
|
5101
|
+
]);
|
|
5102
|
+
const head = `Engine settings v${r.version}${r.defaults_only ? " (the defaults; no row yet)" : ""}${r.updated_by ? ` · by ${r.updated_by}` : ""}${r.changed ? ` · changed: ${r.changed.join(", ") || "nothing"}` : ""}`;
|
|
5103
|
+
return [head, ...lenses, "", ...weights, "", ...asks].join("\n");
|
|
5104
|
+
}
|
|
5105
|
+
|
|
5106
|
+
/**
|
|
5107
|
+
* `admin letterpress …` — what steers Letterpress beside the recipes (get_engine_settings,
|
|
5108
|
+
* save_engine_settings): the one judgement's weights per ask and, per lens, its mode: off,
|
|
5109
|
+
* shadow or live (the flip of docs/architecture/letterpress-iteration-audit.md §4). Reads
|
|
5110
|
+
* need recipes:read, writes recipes:write; every write is recorded as the key holder's.
|
|
5111
|
+
*/
|
|
5112
|
+
async function cmdAdminLetterpress(ctx) {
|
|
5113
|
+
const { flags, positionals, io } = ctx;
|
|
5114
|
+
const sub = positionals[0];
|
|
5115
|
+
switch (sub) {
|
|
5116
|
+
case "status": {
|
|
5117
|
+
const r = await staffRequest(
|
|
5118
|
+
ctx,
|
|
5119
|
+
"GET",
|
|
5120
|
+
`${LETTERPRESS}?view=status${flagBool(flags.customers) ? "&customers=1" : ""}`
|
|
5121
|
+
);
|
|
5122
|
+
printResult(io, flags, r, (s) =>
|
|
5123
|
+
[
|
|
5124
|
+
`Letterpress, last ${s.days} days (settings v${s.settings.version}${s.settings.defaults_only ? ", defaults" : ""}, questions v${s.judgement_version})`,
|
|
5125
|
+
...s.lenses.map(
|
|
5126
|
+
(l) =>
|
|
5127
|
+
`${l.lens.padEnd(6)} ${l.mode.padEnd(6)} ${String(l.runs).padStart(3)} runs recipes ${l.recipes.enabled} on, ${l.recipes.retired} retired, ${l.recipes.conditioned} conditioned followed full ${l.followed.full} / part ${l.followed.part} / none ${l.followed.none}${l.shadow ? ` shadow: top same ${l.shadow.top_same}/${l.shadow.runs}, order same ${l.shadow.order_same}` : ""}${l.drift?.pairs ? ` drift ${l.drift.changed}/${l.drift.pairs}` : ""}${l.prompt_hash ? ` prompt ${l.prompt_hash}` : ""}${l.model ? ` ${l.model}` : ""}`
|
|
5128
|
+
),
|
|
5129
|
+
s.surfaces.length
|
|
5130
|
+
? `asks from: ${s.surfaces.map((x) => `${x.surface} ${x.runs}`).join(", ")}`
|
|
5131
|
+
: "no runs yet",
|
|
5132
|
+
`turns ${s.turns.runs}${s.turns.by_action.length ? ` (${s.turns.by_action.map((a) => `${a.action} ${a.runs}`).join(", ")})` : ""}; builds ${s.turns.merge.builds}, merged ${s.turns.merge.merged}, closed ${s.turns.merge.closed}${s.customer_only ? " [customers only]" : ""}`,
|
|
5133
|
+
].join("\n")
|
|
5134
|
+
);
|
|
5135
|
+
return 0;
|
|
5136
|
+
}
|
|
5137
|
+
case "gaps": {
|
|
5138
|
+
const r = await staffRequest(
|
|
5139
|
+
ctx,
|
|
5140
|
+
"GET",
|
|
5141
|
+
`${LETTERPRESS}?view=gaps${flagBool(flags.customers) ? "&customers=1" : ""}`
|
|
5142
|
+
);
|
|
5143
|
+
printResult(io, flags, r, (g) =>
|
|
5144
|
+
g.gaps.length
|
|
5145
|
+
? g.gaps
|
|
5146
|
+
.map(
|
|
5147
|
+
(x) =>
|
|
5148
|
+
`${x.gap}\n ${x.evidence.join(" · ")}\n → ${x.action.label}: ${x.action.tool} ${JSON.stringify(x.action.args)}`
|
|
5149
|
+
)
|
|
5150
|
+
.join("\n")
|
|
5151
|
+
: "No gaps the numbers show."
|
|
5152
|
+
);
|
|
5153
|
+
return 0;
|
|
5154
|
+
}
|
|
5155
|
+
case "replay": {
|
|
5156
|
+
const id = positionals[1];
|
|
5157
|
+
if (!id) throw new CliError(ENGINE_USAGE);
|
|
5158
|
+
const r = await staffRequest(ctx, "POST", `${LETTERPRESS}-runs/replay`, { id });
|
|
5159
|
+
printResult(io, flags, r, (x) =>
|
|
5160
|
+
[
|
|
5161
|
+
`Run ${x.run_id} (${x.lens}): shown ${x.shown.join(", ") || "nothing"}`,
|
|
5162
|
+
`today would keep ${(x.replay.judged?.kept ?? x.replay.kept).join(", ") || "nothing"}`,
|
|
5163
|
+
x.diff.would_drop.length ? `would drop: ${x.diff.would_drop.join(", ")}` : "would drop nothing",
|
|
5164
|
+
x.diff.would_add.length ? `would add: ${x.diff.would_add.join(", ")}` : "would add nothing",
|
|
5165
|
+
`order ${x.diff.order_same ? "the same" : "different"}`,
|
|
5166
|
+
`as a case: --json and take .case into evals/letterpress/<key>.json (edit its expectation, flip proposed → guarding)`,
|
|
5167
|
+
].join("\n")
|
|
5168
|
+
);
|
|
5169
|
+
return 0;
|
|
5170
|
+
}
|
|
5171
|
+
case "settings": {
|
|
5172
|
+
const result = await staffRequest(ctx, "GET", ENGINE);
|
|
5173
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5174
|
+
return 0;
|
|
5175
|
+
}
|
|
5176
|
+
case "flip": {
|
|
5177
|
+
const [, lens, mode] = positionals;
|
|
5178
|
+
if (!lens || !mode) throw new CliError(ENGINE_USAGE);
|
|
5179
|
+
const result = await staffRequest(ctx, "PUT", ENGINE, { lenses: { [lens]: { mode } } });
|
|
5180
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5181
|
+
return 0;
|
|
5182
|
+
}
|
|
5183
|
+
case "set": {
|
|
5184
|
+
const [, path, value] = positionals;
|
|
5185
|
+
if (!path || value === undefined) throw new CliError(ENGINE_USAGE);
|
|
5186
|
+
const result = await staffRequest(ctx, "PUT", ENGINE, engineSettingsPatch(path, value));
|
|
5187
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5188
|
+
return 0;
|
|
5189
|
+
}
|
|
5190
|
+
default:
|
|
5191
|
+
throw new CliError(ENGINE_USAGE);
|
|
5192
|
+
}
|
|
5193
|
+
}
|
|
5194
|
+
|
|
5143
5195
|
/**
|
|
5144
|
-
* `admin recipes …` — the
|
|
5145
|
-
*
|
|
5196
|
+
* `admin recipes …` — the recipes page (/superadmin/recipes) for an agent: Letter's one library
|
|
5197
|
+
* of direction for Letterpress on Plan, Build and Fix (`--tab`). The loop for building it out is
|
|
5146
5198
|
* `vocab` (what a recipe can say) → `export --out recipes.json` → edit → `import recipes.json
|
|
5147
|
-
* --dry-run` → `import recipes.json
|
|
5148
|
-
* recipes:write; every write is recorded as the key holder's.
|
|
5199
|
+
* --dry-run` → `import recipes.json`; `stats` says how each recipe's suggestions fare. Reads need
|
|
5200
|
+
* recipes:read on the staff key, writes recipes:write; every write is recorded as the key holder's.
|
|
5149
5201
|
*/
|
|
5150
5202
|
async function cmdAdminRecipes(ctx) {
|
|
5151
5203
|
const { flags, positionals, io } = ctx;
|
|
5152
5204
|
const sub = positionals[0];
|
|
5153
|
-
const
|
|
5205
|
+
const tab = flagStr(flags.tab);
|
|
5206
|
+
const all = async () =>
|
|
5207
|
+
(await staffRequest(ctx, "GET", tab ? `${RECIPES}?tab=${encodeURIComponent(tab)}` : RECIPES)).recipes ?? [];
|
|
5154
5208
|
switch (sub) {
|
|
5209
|
+
case "stats": {
|
|
5210
|
+
const result = await staffRequest(ctx, "GET", `${RECIPES}/stats`);
|
|
5211
|
+
printResult(io, flags, result, (r) =>
|
|
5212
|
+
r.stats.length
|
|
5213
|
+
? r.stats
|
|
5214
|
+
.map(
|
|
5215
|
+
(s) =>
|
|
5216
|
+
`${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${String(s.resolved ?? 0).padStart(4)} resolved ${String(s.built ?? 0).padStart(3)} built ${s.tab.padEnd(5)} ${s.recipe}${s.reasons.length ? `\n why: ${s.reasons.slice(0, 3).join(" · ")}` : ""}`
|
|
5217
|
+
)
|
|
5218
|
+
.join("\n")
|
|
5219
|
+
: "No suggestions from the passes yet."
|
|
5220
|
+
);
|
|
5221
|
+
return 0;
|
|
5222
|
+
}
|
|
5155
5223
|
case "list": {
|
|
5156
5224
|
const recipes = (await all()).filter((r) => !flagBool(flags["enabled-only"]) || r.enabled);
|
|
5157
5225
|
printResult(io, flags, { recipes }, (r) =>
|
|
@@ -5172,11 +5240,20 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5172
5240
|
[
|
|
5173
5241
|
...r.how_recipes_are_read.map((line) => `· ${line}`),
|
|
5174
5242
|
"",
|
|
5243
|
+
"Tabs:",
|
|
5244
|
+
...r.tabs.map((t) => ` ${t.id}: reads ${t.reads}`),
|
|
5245
|
+
"",
|
|
5175
5246
|
"Fields:",
|
|
5176
5247
|
...r.fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5177
5248
|
"",
|
|
5178
|
-
"
|
|
5179
|
-
...r.
|
|
5249
|
+
"A move's fields (plan):",
|
|
5250
|
+
...r.move_fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5251
|
+
"",
|
|
5252
|
+
`Actions a move may name: ${r.actions.join(", ")}`,
|
|
5253
|
+
`Evidence the moves can make a plan read: ${r.evidence.join(", ")}`,
|
|
5254
|
+
"",
|
|
5255
|
+
"Outcomes:",
|
|
5256
|
+
...r.outcomes.map((g) => ` ${g.id}${g.available ? "" : " (not available yet)"}: ${g.brief}`),
|
|
5180
5257
|
"",
|
|
5181
5258
|
`Company types: ${r.company_types.map((t) => `${t.id} (${t.label})`).join(", ")}`,
|
|
5182
5259
|
`Primitives: ${r.primitives.map((p) => `${p.id} (${p.label})`).join(", ")}`,
|
|
@@ -5264,9 +5341,99 @@ const LAGO_USAGE = `Usage: admin billing lago <command>
|
|
|
5264
5341
|
changes [--org <org-id>] term changes waiting to take effect (moves, cheaper plans, new ratios)
|
|
5265
5342
|
changes cancel <org-id> take back an org's scheduled change before it takes effect`;
|
|
5266
5343
|
|
|
5344
|
+
const LEGACY_USAGE = `Usage: admin billing legacy mark <org-id> --why "…" mark one org legacy (free until migrated)
|
|
5345
|
+
admin billing legacy mark --all --why "…" [--apply] every org that pays today; a dry run unless --apply`;
|
|
5346
|
+
|
|
5347
|
+
/**
|
|
5348
|
+
* admin billing legacy mark … — legacy orgs (decisions 2026-10-27): free until migrated, never gated
|
|
5349
|
+
* by the free paywall. --all covers the $0 Lago trial, Stripe payers and billing-exempt orgs; it only
|
|
5350
|
+
* reports unless --apply.
|
|
5351
|
+
*/
|
|
5352
|
+
async function cmdAdminBillingLegacy(ctx) {
|
|
5353
|
+
const { flags, positionals, io } = ctx;
|
|
5354
|
+
if (positionals[1] !== "mark") throw new CliError(LEGACY_USAGE);
|
|
5355
|
+
const why = flagStr(flags.why);
|
|
5356
|
+
if (!why) throw new CliError(`Say why (--why "…"): it is kept with the mark.\n${LEGACY_USAGE}`);
|
|
5357
|
+
const all = flagBool(flags.all);
|
|
5358
|
+
const orgId = positionals[2];
|
|
5359
|
+
if (!!orgId === all) throw new CliError(LEGACY_USAGE);
|
|
5360
|
+
const result = await staffPost(
|
|
5361
|
+
ctx,
|
|
5362
|
+
"/api/superadmin/billing/legacy",
|
|
5363
|
+
all ? { all: true, dry: !flagBool(flags.apply), why } : { orgId, dry: flagBool(flags.dry), why }
|
|
5364
|
+
);
|
|
5365
|
+
printResult(io, flags, result, (r) => {
|
|
5366
|
+
const verb = r.dry ? "Would mark" : "Marked";
|
|
5367
|
+
const lines = [`${verb} ${r.marked.length} org(s) legacy; ${r.already.length} already were.`];
|
|
5368
|
+
for (const c of r.candidates ?? []) {
|
|
5369
|
+
if (!r.marked.includes(c.orgId)) continue;
|
|
5370
|
+
lines.push(` ${c.orgId.slice(0, 8)} ${c.name ?? "(no name)"} ${c.basis.join(", ")}`);
|
|
5371
|
+
}
|
|
5372
|
+
if (r.dry && all) lines.push("Nothing written. Run again with --apply to mark them.");
|
|
5373
|
+
return lines.join("\n");
|
|
5374
|
+
});
|
|
5375
|
+
return 0;
|
|
5376
|
+
}
|
|
5377
|
+
|
|
5378
|
+
const FREE_USAGE = `Usage: admin billing free exposure [--json] who the free paywall would stop today
|
|
5379
|
+
admin billing free backfill --why "…" [--apply] signup grant for self-serve orgs with none; a dry run unless --apply`;
|
|
5380
|
+
|
|
5381
|
+
const EXPOSURE_WORDS = {
|
|
5382
|
+
needs_legacy: "pay today: need a legacy mark (admin billing legacy mark --all)",
|
|
5383
|
+
self_serve_no_grant: "self-serve, no grant: blocked at once (admin billing free backfill)",
|
|
5384
|
+
other_no_grant: "free, not paying, not self-serve, no grant: blocked at once (a person decides)",
|
|
5385
|
+
granted: "free with a grant (as designed)",
|
|
5386
|
+
};
|
|
5387
|
+
|
|
5388
|
+
/**
|
|
5389
|
+
* admin billing free … — before LETTERBRACE_FREE_TOKENS is set: who the free paywall would stop
|
|
5390
|
+
* (exposure, reads only) and the one-time signup grant for self-serve orgs that predate it (backfill,
|
|
5391
|
+
* a dry run unless --apply).
|
|
5392
|
+
*/
|
|
5393
|
+
async function cmdAdminBillingFree(ctx) {
|
|
5394
|
+
const { flags, positionals, io } = ctx;
|
|
5395
|
+
if (positionals[1] === "exposure") {
|
|
5396
|
+
const r = await staffRequest(ctx, "GET", "/api/superadmin/billing/free-tokens");
|
|
5397
|
+
printResult(io, flags, r, (x) => {
|
|
5398
|
+
const lines = [`Free orgs today (CRM snapshot ${x.snapshotOn ?? "none"}):`];
|
|
5399
|
+
for (const [group, words] of Object.entries(EXPOSURE_WORDS)) {
|
|
5400
|
+
lines.push(` ${String(x.counts[group]).padStart(5)} ${words}`);
|
|
5401
|
+
if (group === "granted") continue;
|
|
5402
|
+
for (const o of x.orgs.filter((y) => y.group === group))
|
|
5403
|
+
lines.push(
|
|
5404
|
+
` ${o.orgId.slice(0, 8)} ${o.name ?? "(no name)"} origin=${o.origin ?? "-"} revenue=${o.revenueSource ?? "-"}${o.paying ? " paying" : ""}`
|
|
5405
|
+
);
|
|
5406
|
+
}
|
|
5407
|
+
return lines.join("\n");
|
|
5408
|
+
});
|
|
5409
|
+
return 0;
|
|
5410
|
+
}
|
|
5411
|
+
if (positionals[1] === "backfill") {
|
|
5412
|
+
const why = flagStr(flags.why);
|
|
5413
|
+
if (!why) throw new CliError(`Say why (--why "…"): it is kept with each grant.\n${FREE_USAGE}`);
|
|
5414
|
+
const r = await staffPost(ctx, "/api/superadmin/billing/free-tokens/backfill", {
|
|
5415
|
+
dry: !flagBool(flags.apply),
|
|
5416
|
+
why,
|
|
5417
|
+
});
|
|
5418
|
+
printResult(io, flags, r, (x) => {
|
|
5419
|
+
const verb = x.dry ? "Would grant" : "Granted";
|
|
5420
|
+
const lines = [
|
|
5421
|
+
`${verb} ${x.tokens.toLocaleString("en-US")} tokens to ${x.granted.length} self-serve org(s); ${x.already.length} already had them.`,
|
|
5422
|
+
];
|
|
5423
|
+
for (const o of x.orgs) lines.push(` ${o.orgId.slice(0, 8)} ${o.name ?? "(no name)"}`);
|
|
5424
|
+
if (x.dry) lines.push("Nothing written. Run again with --apply to grant them.");
|
|
5425
|
+
return lines.join("\n");
|
|
5426
|
+
});
|
|
5427
|
+
return 0;
|
|
5428
|
+
}
|
|
5429
|
+
throw new CliError(FREE_USAGE);
|
|
5430
|
+
}
|
|
5431
|
+
|
|
5267
5432
|
/** admin billing lago … — staff operations on Lago (docs/billing/lago-integration.md). */
|
|
5268
5433
|
async function cmdAdminBilling(ctx) {
|
|
5269
5434
|
const { flags, positionals, io } = ctx;
|
|
5435
|
+
if (positionals[0] === "legacy") return cmdAdminBillingLegacy(ctx);
|
|
5436
|
+
if (positionals[0] === "free") return cmdAdminBillingFree(ctx);
|
|
5270
5437
|
if (positionals[0] !== "lago") throw new CliError(LAGO_USAGE);
|
|
5271
5438
|
const sub = positionals[1];
|
|
5272
5439
|
switch (sub) {
|
|
@@ -5635,11 +5802,10 @@ export async function cmdAdmin(ctx) {
|
|
|
5635
5802
|
if (sub === "brand-detection") return cmdAdminBrandDetection({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5636
5803
|
if (sub === "republish") return cmdAdminRepublish({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5637
5804
|
if (sub === "recipes") return cmdAdminRecipes({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5805
|
+
if (sub === "letterpress") return cmdAdminLetterpress({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5638
5806
|
if (sub === "demo") return cmdAdminDemo({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5639
|
-
if (sub === "suggestion-recipes")
|
|
5640
|
-
return cmdAdminSuggestionRecipes({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5641
5807
|
throw new CliError(
|
|
5642
|
-
'Usage: admin recipes … | admin
|
|
5808
|
+
'Usage: admin recipes … | admin letterpress … | admin demo … | admin republish … | admin create-org --domain <bare-domain> [--onboard] … | admin ask "<question>" | admin patterns … | admin experiments … | admin fleet-experiments … | admin crm … | admin spend … | admin evals … | admin brand-detection … | admin tuning … | admin tuning-context | admin replays … (see --help)'
|
|
5643
5809
|
);
|
|
5644
5810
|
}
|
|
5645
5811
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// `ask` — ask Letterpress, the one door (docs/architecture/one-recipe-engine.md §9b): what should
|
|
2
|
+
// this account do next. The same answer as the console's Plan, Build and Fix tabs and Slack.
|
|
3
|
+
// ask → each list's head: what's broken, what to build
|
|
4
|
+
// ask --outcome geo|seo|… → the plan for that outcome (the Plan tab's box)
|
|
5
|
+
// ask --lens fix | --lens build → what's broken (most pressing first) | what to build
|
|
6
|
+
// ask "<words…>" → in your own words; what nothing does comes back as unmet
|
|
7
|
+
|
|
8
|
+
import { CliError } from "../client.mjs";
|
|
9
|
+
import { argsFromFlags, flagStr, printResult, refuseUnknownFlags } from "./shared.mjs";
|
|
10
|
+
|
|
11
|
+
export const ARGS = {
|
|
12
|
+
ask_letterpress: {
|
|
13
|
+
outcome: "outcome",
|
|
14
|
+
lens: "lens",
|
|
15
|
+
words: { value: (flags, positionals) => flagStr(flags.words) ?? (positionals.join(" ").trim() || undefined) },
|
|
16
|
+
domain: "site",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function cmdAsk(ctx) {
|
|
21
|
+
const { client, flags, io } = ctx;
|
|
22
|
+
refuseUnknownFlags(ctx, {}, ["outcome", "lens", "words", "site"]);
|
|
23
|
+
const args = argsFromFlags(ARGS.ask_letterpress, flags, ctx.positionals, {});
|
|
24
|
+
if ([args.outcome, args.lens, args.words].filter(Boolean).length > 1)
|
|
25
|
+
throw new CliError("One ask at a time: --outcome, --lens fix|build, or your words.");
|
|
26
|
+
const result = await client.callTool("ask_letterpress", args);
|
|
27
|
+
printResult(io, flags, result, (r) => {
|
|
28
|
+
const lines = [r.message];
|
|
29
|
+
for (const i of r.items) {
|
|
30
|
+
const waits = i.blocked_by?.length ? ` (waits on: ${i.blocked_by.join("; ")})` : "";
|
|
31
|
+
const how = i.action
|
|
32
|
+
? i.action.callable
|
|
33
|
+
? ` → ${i.action.tool}`
|
|
34
|
+
: i.action.href
|
|
35
|
+
? ` → ${i.action.href}`
|
|
36
|
+
: ""
|
|
37
|
+
: "";
|
|
38
|
+
lines.push(` ${i.status.padEnd(7)} ${i.title}${how}${waits}`, ` ${i.why}`);
|
|
39
|
+
}
|
|
40
|
+
if (r.unmet) lines.push(`Not something we do yet: ${r.unmet}`);
|
|
41
|
+
if (r.status === "pending") lines.push("(reading the site; ask again in a few seconds)");
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
});
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
package/lib/commands/org.mjs
CHANGED
|
@@ -30,6 +30,8 @@ export const ARGS = {
|
|
|
30
30
|
get_billing_payments: {},
|
|
31
31
|
get_billing: {},
|
|
32
32
|
get_billing_invoices: {},
|
|
33
|
+
list_token_rewards: {},
|
|
34
|
+
claim_token_reward: { action: { positional: 0, label: "action" } },
|
|
33
35
|
set_billing_spend_cap: {
|
|
34
36
|
cap_usd: { value: (_flags, positionals) => capFrom(requirePositional(positionals, 0, "dollars|off")) },
|
|
35
37
|
reason: { flag: "why" },
|
|
@@ -174,6 +176,25 @@ async function orgBilling(ctx) {
|
|
|
174
176
|
printResult(io, flags, result, (r) => `Asked ${r.emailedTo} admin${r.emailedTo === 1 ? "" : "s"} for more.`);
|
|
175
177
|
return 0;
|
|
176
178
|
}
|
|
179
|
+
if (positionals[0] === "rewards") {
|
|
180
|
+
if (positionals[1] === "claim") {
|
|
181
|
+
refuseUnknownFlags(ctx, ARGS.claim_token_reward, []);
|
|
182
|
+
const result = await client.callTool(
|
|
183
|
+
"claim_token_reward",
|
|
184
|
+
argsFromFlags(ARGS.claim_token_reward, flags, positionals.slice(2))
|
|
185
|
+
);
|
|
186
|
+
printResult(io, flags, result, (r) =>
|
|
187
|
+
r.granted
|
|
188
|
+
? `Claimed: ${r.tokens} free tokens for ${r.action}${r.verified ? "" : " (on your word)"}.`
|
|
189
|
+
: `Already claimed: ${r.action} gave its ${r.tokens} free tokens before.`
|
|
190
|
+
);
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
refuseUnknownFlags(ctx, ARGS.list_token_rewards, []);
|
|
194
|
+
const result = await client.callTool("list_token_rewards", argsFromFlags(ARGS.list_token_rewards, flags, []));
|
|
195
|
+
printResult(io, flags, result, tokenRewardsText);
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
177
198
|
if (positionals[0] === "invoices") {
|
|
178
199
|
refuseUnknownFlags(ctx, ARGS.get_billing_invoices, []);
|
|
179
200
|
const result = await client.callTool(
|
|
@@ -199,10 +220,26 @@ async function orgBilling(ctx) {
|
|
|
199
220
|
export function billingAccountText(r) {
|
|
200
221
|
const ended = r.status === "ended";
|
|
201
222
|
const u = r.usage;
|
|
223
|
+
const f = r.free;
|
|
202
224
|
return [
|
|
203
225
|
r.plan
|
|
204
226
|
? `Plan: ${r.plan.name}${r.plan.ratio !== 1 ? ` (${r.plan.ratio}x)` : ""}${ended ? `, cancelled${r.canceledAt ? ` on ${r.canceledAt.slice(0, 10)}` : ""}.` : ""}`
|
|
205
|
-
:
|
|
227
|
+
: f
|
|
228
|
+
? "On free tokens: no card yet."
|
|
229
|
+
: "Not billed by usage yet.",
|
|
230
|
+
// A free account (no card): its balance, its grants, and whether new work needs a card now.
|
|
231
|
+
...(f
|
|
232
|
+
? [
|
|
233
|
+
`Free tokens: ${Math.max(0, f.availableTokens)} left of ${f.grantedTokens} given (${f.usedTokens} used${f.heldTokens ? `, ${f.heldTokens} held by running work` : ""}).`,
|
|
234
|
+
...f.grants.map(
|
|
235
|
+
(g) =>
|
|
236
|
+
` +${g.tokens} ${g.source}${g.sourceKey !== g.source ? `: ${g.sourceKey}` : ""} ${g.createdAt.slice(0, 10)}`
|
|
237
|
+
),
|
|
238
|
+
f.cardRequired
|
|
239
|
+
? "No free tokens left: new work needs a card. An admin adds one in Settings → Billing."
|
|
240
|
+
: "When they run out, new work needs a card (an admin adds one in Settings → Billing).",
|
|
241
|
+
]
|
|
242
|
+
: []),
|
|
206
243
|
...(u
|
|
207
244
|
? [
|
|
208
245
|
`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)` : ""}` : ""}.`,
|
|
@@ -228,6 +265,19 @@ export function billingAccountText(r) {
|
|
|
228
265
|
.join("\n");
|
|
229
266
|
}
|
|
230
267
|
|
|
268
|
+
/** `org billing rewards` as text: each action, its tokens, claimed or how to claim. */
|
|
269
|
+
function tokenRewardsText(r) {
|
|
270
|
+
const lines = r.rewards.map(
|
|
271
|
+
(x) =>
|
|
272
|
+
` ${x.claimed ? "✓" : x.ready === false ? "·" : "○"} ${x.action.padEnd(18)} ${String(x.tokens).padStart(6)} tokens ${x.title}${x.claimed ? " (claimed)" : x.ready === false ? " (not done yet)" : ""}`
|
|
273
|
+
);
|
|
274
|
+
return [
|
|
275
|
+
`Free tokens for actions: ${r.claimedTokens} claimed, ${r.availableTokens} still to earn.`,
|
|
276
|
+
...lines,
|
|
277
|
+
"Claim one: letterstory org billing rewards claim <action>",
|
|
278
|
+
].join("\n");
|
|
279
|
+
}
|
|
280
|
+
|
|
231
281
|
const INVOICE_KIND = {
|
|
232
282
|
subscription: "plan",
|
|
233
283
|
one_off: "one-off",
|
package/lib/commands/visits.mjs
CHANGED
|
@@ -230,15 +230,19 @@ async function visitsList(ctx) {
|
|
|
230
230
|
}
|
|
231
231
|
const sv = r.served;
|
|
232
232
|
if (sv?.total) {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
`
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
const f = sv.formats;
|
|
234
|
+
const asked = (f.asked_markdown ?? 0) + (f.asked_html ?? 0);
|
|
235
|
+
const parts = [
|
|
236
|
+
`Sent: ${f.markdown} markdown, ${f.html} HTML${f.other ? `, ${f.other} other` : ""}`,
|
|
237
|
+
...(asked ? [`asked for (response not seen): ${f.asked_markdown} markdown, ${f.asked_html} HTML`] : []),
|
|
238
|
+
...(f.unknown ? [`${f.unknown} unknown`] : []),
|
|
239
|
+
...(sv.outcomes.blocked ? [`${sv.outcomes.blocked} blocked`] : []),
|
|
240
|
+
];
|
|
241
|
+
lines.push("", parts.join(" · "));
|
|
242
|
+
if (f.markdown + f.html + f.other + asked)
|
|
239
243
|
for (const a of sv.agents.slice(0, 8))
|
|
240
244
|
lines.push(
|
|
241
|
-
` ${a.agent.padEnd(22)} ${String(a.markdown).padStart(
|
|
245
|
+
` ${a.agent.padEnd(22)} sent ${String(a.markdown).padStart(5)} md ${String(a.html).padStart(5)} html · asked ${String(a.asked_markdown ?? 0).padStart(5)} md ${String(a.asked_html ?? 0).padStart(5)} html`
|
|
242
246
|
);
|
|
243
247
|
}
|
|
244
248
|
if (!r.total) lines.push("No agent visits in this window. Is the server snippet installed? (visits sites)");
|
package/lib/commands.mjs
CHANGED
|
@@ -45,6 +45,7 @@ export * from "./commands/admin.mjs";
|
|
|
45
45
|
export * from "./commands/feedback.mjs";
|
|
46
46
|
export * from "./commands/repo.mjs";
|
|
47
47
|
export * from "./commands/build.mjs";
|
|
48
|
+
export * from "./commands/ask.mjs";
|
|
48
49
|
export * from "./commands/site.mjs";
|
|
49
50
|
export * from "./commands/evals.mjs";
|
|
50
51
|
export * from "./commands/visits.mjs";
|