@letterstory/cli 0.158.4 → 0.162.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 +74 -33
- package/lib/commands/admin.mjs +343 -159
- package/lib/commands/ask.mjs +45 -0
- package/lib/commands/org.mjs +51 -1
- package/lib/commands/repo.mjs +48 -11
- 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.162.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",
|
|
@@ -128,6 +131,8 @@ export const BOOLEAN_FLAGS = new Set([
|
|
|
128
131
|
"refresh",
|
|
129
132
|
"preview",
|
|
130
133
|
"with-preview",
|
|
134
|
+
// repo …: the repo is a GitLab project (--repo group/subgroup/project).
|
|
135
|
+
"gitlab",
|
|
131
136
|
"accept",
|
|
132
137
|
"help",
|
|
133
138
|
"version",
|
|
@@ -141,7 +146,7 @@ export const BOOLEAN_FLAGS = new Set([
|
|
|
141
146
|
"enroll",
|
|
142
147
|
"unenroll",
|
|
143
148
|
"clean-slate",
|
|
144
|
-
// admin recipes list --enabled-only, save --enable|--disable, import --retire-missing
|
|
149
|
+
// admin recipes list --tab --enabled-only, save --enable|--disable, import --retire-missing
|
|
145
150
|
"enabled-only",
|
|
146
151
|
"enable",
|
|
147
152
|
"disable",
|
|
@@ -871,21 +876,48 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
871
876
|
read-only SQL across every org; --sql prints
|
|
872
877
|
the queries behind the answer. Needs the
|
|
873
878
|
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
|
-
|
|
879
|
+
admin recipes list [--tab plan|build|fix] [--enabled-only] | show <id|name> | vocab | stats
|
|
880
|
+
Recipes: Letter's one library of direction for
|
|
881
|
+
Letterpress on Plan, Build and Fix (/superadmin/recipes).
|
|
882
|
+
vocab says what a recipe can say (tabs, fields, the
|
|
883
|
+
catalog actions a plan recipe's moves may name, outcomes,
|
|
884
|
+
company types, primitives); stats how each recipe's
|
|
885
|
+
suggestions fare. Needs recipes:read.
|
|
886
|
+
admin recipes export [--tab …] [--out recipes.json] The library as a file import reads back.
|
|
880
887
|
admin recipes import <file> [--dry-run] [--retire-missing]
|
|
881
888
|
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
|
-
|
|
889
|
+
else tab and name, then changed or created. --dry-run
|
|
890
|
+
writes nothing; --retire-missing retires every enabled
|
|
891
|
+
recipe of the file's tabs it leaves out. Exits 1 if any
|
|
892
|
+
row failed.
|
|
893
|
+
admin recipes save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …]
|
|
894
|
+
[--when-not-to-use …] [--example …] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none]
|
|
895
|
+
[--company-types a,b|none] [--enable|--disable] [--position n]
|
|
887
896
|
Create one (no id) or change one. Needs recipes:write.
|
|
888
897
|
admin recipes delete <id> --yes Delete for good (save --disable retires and keeps it).
|
|
898
|
+
admin letterpress status [--customers] Letterpress as it runs now: per lens its mode, bar, recipes,
|
|
899
|
+
runs, model and prompt hash, how often the shadow agreed,
|
|
900
|
+
how runs grounded (full / part / none). Needs recipes:read.
|
|
901
|
+
admin letterpress gaps [--customers] The gaps the numbers show, each with the one call that
|
|
902
|
+
addresses it, pre-filled. Needs recipes:read.
|
|
903
|
+
admin letterpress replay <run-id> A Build or Fix run through today's checks and settings, no
|
|
904
|
+
model: what it would keep, drop and rank against what it
|
|
905
|
+
showed; --json carries the run as an evals case.
|
|
906
|
+
admin letterpress mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …]
|
|
907
|
+
The blind read: mark a shown item; the marks fill the case
|
|
908
|
+
the run exports and the status's agreement. Needs recipes:write.
|
|
909
|
+
admin letterpress settings What steers Letterpress beside the recipes: the one
|
|
910
|
+
judgement's weights per ask and, per lens, its mode (off,
|
|
911
|
+
shadow or live) and bar. Needs recipes:read.
|
|
912
|
+
admin letterpress flip <build|fix|plan> <off|shadow|live>
|
|
913
|
+
Flip a lens (Build, Fix: the one judgement; Plan: the pick
|
|
914
|
+
with recipes as direction). Shadow: both run and are
|
|
915
|
+
recorded on every run, today's shown; live: the new one
|
|
916
|
+
decides. Recorded as yours. Needs recipes:write.
|
|
917
|
+
admin letterpress set <weights.<ask>.<reading>|lenses.<lens>.mode|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|asks.<lens>.ask|asks.<lens>.guidance> <value>
|
|
918
|
+
Change one weight, one bar, or a lens's ask and guidance (the
|
|
919
|
+
opinions Letterpress chooses by, as staff's words); the version
|
|
920
|
+
bumps and the previous body is kept. Needs recipes:write.
|
|
889
921
|
admin demo guide How to run a demo, step by step, and what every knob and
|
|
890
922
|
seed shows on screen. Read it first.
|
|
891
923
|
admin demo list [--enrollable] | show <org-id> [--moves]
|
|
@@ -899,15 +931,6 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
899
931
|
show a scenario: real, fresh_geo, fresh_seo, after_approve
|
|
900
932
|
or a saved one. --clean-slate closes every open PR and
|
|
901
933
|
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
934
|
admin brand-detection <org-id> [--term <t>]... [--exact <t>]... [--exclude <phrase>]... [--note "…"] | --clear [--note "…"]
|
|
912
935
|
How a client's brand is detected in AI answers, with
|
|
913
936
|
every earlier setting; with flags, set the exact set
|
|
@@ -995,6 +1018,12 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
995
1018
|
cover what the app ledger cannot see; a CSV
|
|
996
1019
|
import sums Concentrate's log export.
|
|
997
1020
|
Needs spend:read (reads) / spend:write (writes).
|
|
1021
|
+
admin billing legacy mark <org-id> --why "…" | --all --why "…" [--apply]
|
|
1022
|
+
Mark legacy orgs: free until migrated, never gated
|
|
1023
|
+
by the free paywall (--all: everyone who pays today)
|
|
1024
|
+
admin billing free exposure | backfill --why "…" [--apply]
|
|
1025
|
+
Who the free paywall would stop today; the one-time
|
|
1026
|
+
signup grant for self-serve orgs with none
|
|
998
1027
|
admin billing lago catalog [--apply] [--include-drafts]
|
|
999
1028
|
| 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
1029
|
| reconcile [--org <org-id>] | forward
|
|
@@ -1168,6 +1197,8 @@ Seers (event-driven signals -> drafts):
|
|
|
1168
1197
|
the admins for more
|
|
1169
1198
|
org billing usage This period by product and collection: quantities,
|
|
1170
1199
|
and tokens and dollars when billed by usage
|
|
1200
|
+
org billing rewards [claim <action>] Free tokens for connecting Slack, signing in with the
|
|
1201
|
+
CLI and following Letter; claim one, once per org
|
|
1171
1202
|
org billing invoices Every invoice (paid, open, failed, refunded) and the
|
|
1172
1203
|
next one: when it issues and what it comes to
|
|
1173
1204
|
org linear [teams [--team <id|key>] | set --team <id|key> [--project <id>|none] | disconnect]
|
|
@@ -1421,6 +1452,11 @@ Mail:
|
|
|
1421
1452
|
(any phone format; country as a name or a 2-letter code)
|
|
1422
1453
|
|
|
1423
1454
|
Insights:
|
|
1455
|
+
ask [<words…>] [--outcome geo|seo|…] [--lens fix|build] [--site host]
|
|
1456
|
+
Ask Letterpress what to do next: the plan for an outcome (the
|
|
1457
|
+
Plan tab's box), what's broken (--lens fix, most pressing
|
|
1458
|
+
first), what to build (--lens build), or your own words. Nothing asked:
|
|
1459
|
+
each list's head. The same answer as the console and Slack.
|
|
1424
1460
|
insights summary [--period …] [--part <block>]... Measure Overview: AI named/cited rates, share of voice, search, targets
|
|
1425
1461
|
insights reads [--period …] [--site all|own|phantoms|<key>]... [--path <path>] [--engine <operator>]
|
|
1426
1462
|
Measure → Reads: AI engines and people reading your sites, counted one way
|
|
@@ -1479,8 +1515,9 @@ The Site (one model of your whole marketing site, keyed by host and path):
|
|
|
1479
1515
|
site highlight <domain> [--off] Highlight a competitor; its changes lead the top changes
|
|
1480
1516
|
|
|
1481
1517
|
Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App opens a PR):
|
|
1482
|
-
repo repos
|
|
1483
|
-
|
|
1518
|
+
repo repos [--gitlab [--search <text>] [--page n]] Repos the Letter GitHub App can reach (--gitlab: the GitLab
|
|
1519
|
+
projects the organization's connection can push to)
|
|
1520
|
+
repo connect [--gitlab] Is GitHub (or GitLab) connected; the link a person opens to connect it
|
|
1484
1521
|
repo branches --repo owner/name Branches a change can start from (default first)
|
|
1485
1522
|
repo prs [--repo owner/name] Every open PR (whoever opened it), longest-idle first
|
|
1486
1523
|
repo suggestions Fixes found and not acted on yet, and how to start each
|
|
@@ -1498,7 +1535,7 @@ Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App op
|
|
|
1498
1535
|
actions, and competitors' new pages, each with a channel
|
|
1499
1536
|
repo slack-targets Slack channels and people Send to Slack can use, with ids
|
|
1500
1537
|
repo slack-test Post a test into the Send to Slack channel
|
|
1501
|
-
repo start --repo <owner/name> --instructions <text>|--instructions-file <path|->
|
|
1538
|
+
repo start --repo <owner/name> [--gitlab] --instructions <text>|--instructions-file <path|->
|
|
1502
1539
|
[--branch <base>] [--attach <path>]... [--attach-url <name>=<https url>]...
|
|
1503
1540
|
[--attach-ref <path>]... [--attach-url-ref <name>=<https url>]...
|
|
1504
1541
|
[--action build|build_pr|build_merge|slack|linear] [--with-preview]
|
|
@@ -1509,25 +1546,28 @@ Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App op
|
|
|
1509
1546
|
--harness picks the coding agent (default: the deployment's);
|
|
1510
1547
|
--verifier reviews the change and has the agent fix
|
|
1511
1548
|
what's blocking before it goes out;
|
|
1512
|
-
--wait follows it to the PR
|
|
1549
|
+
--wait follows it to the PR;
|
|
1550
|
+
--gitlab: a GitLab project (--repo group/subgroup/project),
|
|
1551
|
+
through Settings → Integrations → GitLab
|
|
1513
1552
|
repo fix-audit --issue <issue-type>... [--audit <id>] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
|
|
1514
1553
|
One PR fixing site-audit issues (repeat --issue to bundle) on every affected page,
|
|
1515
1554
|
in the repo verified to build the site
|
|
1516
|
-
repo install-letterprove --repo <owner/name> [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
|
|
1555
|
+
repo install-letterprove --repo <owner/name> [--gitlab] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
|
|
1517
1556
|
One PR adding Letterprove's script and identify calls
|
|
1518
1557
|
(pick the repo where users sign in)
|
|
1519
|
-
repo install-visitors [--site <id>] [--repo <owner/name>] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
|
|
1558
|
+
repo install-visitors [--site <id>] [--repo <owner/name> [--gitlab]] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
|
|
1520
1559
|
One PR adding the Visitors script tag and server snippet to the repo that
|
|
1521
1560
|
builds the site (--repo: another repo)
|
|
1522
1561
|
repo sites [--detect [--force]] Which website each repo builds, and the evidence
|
|
1523
|
-
repo set-site --repo <owner/name> --site <host> [--not] [--branch <name>|none]
|
|
1562
|
+
repo set-site --repo <owner/name> [--gitlab] --site <host> [--not] [--branch <name>|none]
|
|
1524
1563
|
Say which site a repo builds (--not: correct a wrong label)
|
|
1525
|
-
repo reset-site --repo <owner/name> --site <host>
|
|
1526
|
-
|
|
1527
|
-
repo
|
|
1564
|
+
repo reset-site --repo <owner/name> [--gitlab] --site <host>
|
|
1565
|
+
Back to automatic detection
|
|
1566
|
+
repo secrets --repo <owner/name> [--gitlab] Preview secrets: names and when set (never values)
|
|
1567
|
+
repo set-secret --repo <owner/name> [--gitlab] --secret <KEY> --value <v> | --value-file <path|->
|
|
1528
1568
|
Set an env var the preview site gets (use test credentials:
|
|
1529
1569
|
the preview URL is public to anyone with the link)
|
|
1530
|
-
repo delete-secret --repo <owner/name> --secret <KEY>
|
|
1570
|
+
repo delete-secret --repo <owner/name> [--gitlab] --secret <KEY>
|
|
1531
1571
|
Delete one
|
|
1532
1572
|
repo status <run-id> Phase, spend, PR link and Claude's summary
|
|
1533
1573
|
repo activity <run-id> [--follow] [--since <iso>] What the sandbox is doing, line by line (--follow: until it stops)
|
|
@@ -1666,6 +1706,7 @@ const CLIENT_COMMANDS = {
|
|
|
1666
1706
|
feedback: cmdFeedback,
|
|
1667
1707
|
repo: cmdRepo,
|
|
1668
1708
|
build: cmdBuild,
|
|
1709
|
+
ask: cmdAsk,
|
|
1669
1710
|
site: cmdSite,
|
|
1670
1711
|
evals: cmdEvals,
|
|
1671
1712
|
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,226 @@ 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> | mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …] | 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
|
+
|
|
5143
5106
|
/**
|
|
5144
|
-
* `admin
|
|
5145
|
-
*
|
|
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 "mark": {
|
|
5172
|
+
const [, id, item, verdict] = positionals;
|
|
5173
|
+
if (!id || !item || !verdict) throw new CliError(ENGINE_USAGE);
|
|
5174
|
+
const r = await staffRequest(ctx, "POST", `${LETTERPRESS}-runs/mark`, {
|
|
5175
|
+
id,
|
|
5176
|
+
marks: [
|
|
5177
|
+
{ item_id: item, verdict: verdict === "clear" ? null : verdict, note: flagStr(flags.note) ?? null },
|
|
5178
|
+
],
|
|
5179
|
+
});
|
|
5180
|
+
printResult(
|
|
5181
|
+
io,
|
|
5182
|
+
flags,
|
|
5183
|
+
r,
|
|
5184
|
+
(x) =>
|
|
5185
|
+
`Run ${x.run.id}: ${x.run.marks.length} marked (${x.run.marks.map((m) => `${m.item_id} ${m.verdict}`).join(", ") || "none"})`
|
|
5186
|
+
);
|
|
5187
|
+
return 0;
|
|
5188
|
+
}
|
|
5189
|
+
case "settings": {
|
|
5190
|
+
const result = await staffRequest(ctx, "GET", ENGINE);
|
|
5191
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5192
|
+
return 0;
|
|
5193
|
+
}
|
|
5194
|
+
case "flip": {
|
|
5195
|
+
const [, lens, mode] = positionals;
|
|
5196
|
+
if (!lens || !mode) throw new CliError(ENGINE_USAGE);
|
|
5197
|
+
const result = await staffRequest(ctx, "PUT", ENGINE, { lenses: { [lens]: { mode } } });
|
|
5198
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5199
|
+
return 0;
|
|
5200
|
+
}
|
|
5201
|
+
case "set": {
|
|
5202
|
+
const [, path, value] = positionals;
|
|
5203
|
+
if (!path || value === undefined) throw new CliError(ENGINE_USAGE);
|
|
5204
|
+
const result = await staffRequest(ctx, "PUT", ENGINE, engineSettingsPatch(path, value));
|
|
5205
|
+
printResult(io, flags, result, engineSettingsText);
|
|
5206
|
+
return 0;
|
|
5207
|
+
}
|
|
5208
|
+
default:
|
|
5209
|
+
throw new CliError(ENGINE_USAGE);
|
|
5210
|
+
}
|
|
5211
|
+
}
|
|
5212
|
+
|
|
5213
|
+
/**
|
|
5214
|
+
* `admin recipes …` — the recipes page (/superadmin/recipes) for an agent: Letter's one library
|
|
5215
|
+
* of direction for Letterpress on Plan, Build and Fix (`--tab`). The loop for building it out is
|
|
5146
5216
|
* `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.
|
|
5217
|
+
* --dry-run` → `import recipes.json`; `stats` says how each recipe's suggestions fare. Reads need
|
|
5218
|
+
* recipes:read on the staff key, writes recipes:write; every write is recorded as the key holder's.
|
|
5149
5219
|
*/
|
|
5150
5220
|
async function cmdAdminRecipes(ctx) {
|
|
5151
5221
|
const { flags, positionals, io } = ctx;
|
|
5152
5222
|
const sub = positionals[0];
|
|
5153
|
-
const
|
|
5223
|
+
const tab = flagStr(flags.tab);
|
|
5224
|
+
const all = async () =>
|
|
5225
|
+
(await staffRequest(ctx, "GET", tab ? `${RECIPES}?tab=${encodeURIComponent(tab)}` : RECIPES)).recipes ?? [];
|
|
5154
5226
|
switch (sub) {
|
|
5227
|
+
case "stats": {
|
|
5228
|
+
const result = await staffRequest(ctx, "GET", `${RECIPES}/stats`);
|
|
5229
|
+
printResult(io, flags, result, (r) =>
|
|
5230
|
+
r.stats.length
|
|
5231
|
+
? r.stats
|
|
5232
|
+
.map(
|
|
5233
|
+
(s) =>
|
|
5234
|
+
`${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(" · ")}` : ""}`
|
|
5235
|
+
)
|
|
5236
|
+
.join("\n")
|
|
5237
|
+
: "No suggestions from the passes yet."
|
|
5238
|
+
);
|
|
5239
|
+
return 0;
|
|
5240
|
+
}
|
|
5155
5241
|
case "list": {
|
|
5156
5242
|
const recipes = (await all()).filter((r) => !flagBool(flags["enabled-only"]) || r.enabled);
|
|
5157
5243
|
printResult(io, flags, { recipes }, (r) =>
|
|
@@ -5172,11 +5258,20 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5172
5258
|
[
|
|
5173
5259
|
...r.how_recipes_are_read.map((line) => `· ${line}`),
|
|
5174
5260
|
"",
|
|
5261
|
+
"Tabs:",
|
|
5262
|
+
...r.tabs.map((t) => ` ${t.id}: reads ${t.reads}`),
|
|
5263
|
+
"",
|
|
5175
5264
|
"Fields:",
|
|
5176
5265
|
...r.fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5177
5266
|
"",
|
|
5178
|
-
"
|
|
5179
|
-
...r.
|
|
5267
|
+
"A move's fields (plan):",
|
|
5268
|
+
...r.move_fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5269
|
+
"",
|
|
5270
|
+
`Actions a move may name: ${r.actions.join(", ")}`,
|
|
5271
|
+
`Evidence the moves can make a plan read: ${r.evidence.join(", ")}`,
|
|
5272
|
+
"",
|
|
5273
|
+
"Outcomes:",
|
|
5274
|
+
...r.outcomes.map((g) => ` ${g.id}${g.available ? "" : " (not available yet)"}: ${g.brief}`),
|
|
5180
5275
|
"",
|
|
5181
5276
|
`Company types: ${r.company_types.map((t) => `${t.id} (${t.label})`).join(", ")}`,
|
|
5182
5277
|
`Primitives: ${r.primitives.map((p) => `${p.id} (${p.label})`).join(", ")}`,
|
|
@@ -5264,9 +5359,99 @@ const LAGO_USAGE = `Usage: admin billing lago <command>
|
|
|
5264
5359
|
changes [--org <org-id>] term changes waiting to take effect (moves, cheaper plans, new ratios)
|
|
5265
5360
|
changes cancel <org-id> take back an org's scheduled change before it takes effect`;
|
|
5266
5361
|
|
|
5362
|
+
const LEGACY_USAGE = `Usage: admin billing legacy mark <org-id> --why "…" mark one org legacy (free until migrated)
|
|
5363
|
+
admin billing legacy mark --all --why "…" [--apply] every org that pays today; a dry run unless --apply`;
|
|
5364
|
+
|
|
5365
|
+
/**
|
|
5366
|
+
* admin billing legacy mark … — legacy orgs (decisions 2026-10-27): free until migrated, never gated
|
|
5367
|
+
* by the free paywall. --all covers the $0 Lago trial, Stripe payers and billing-exempt orgs; it only
|
|
5368
|
+
* reports unless --apply.
|
|
5369
|
+
*/
|
|
5370
|
+
async function cmdAdminBillingLegacy(ctx) {
|
|
5371
|
+
const { flags, positionals, io } = ctx;
|
|
5372
|
+
if (positionals[1] !== "mark") throw new CliError(LEGACY_USAGE);
|
|
5373
|
+
const why = flagStr(flags.why);
|
|
5374
|
+
if (!why) throw new CliError(`Say why (--why "…"): it is kept with the mark.\n${LEGACY_USAGE}`);
|
|
5375
|
+
const all = flagBool(flags.all);
|
|
5376
|
+
const orgId = positionals[2];
|
|
5377
|
+
if (!!orgId === all) throw new CliError(LEGACY_USAGE);
|
|
5378
|
+
const result = await staffPost(
|
|
5379
|
+
ctx,
|
|
5380
|
+
"/api/superadmin/billing/legacy",
|
|
5381
|
+
all ? { all: true, dry: !flagBool(flags.apply), why } : { orgId, dry: flagBool(flags.dry), why }
|
|
5382
|
+
);
|
|
5383
|
+
printResult(io, flags, result, (r) => {
|
|
5384
|
+
const verb = r.dry ? "Would mark" : "Marked";
|
|
5385
|
+
const lines = [`${verb} ${r.marked.length} org(s) legacy; ${r.already.length} already were.`];
|
|
5386
|
+
for (const c of r.candidates ?? []) {
|
|
5387
|
+
if (!r.marked.includes(c.orgId)) continue;
|
|
5388
|
+
lines.push(` ${c.orgId.slice(0, 8)} ${c.name ?? "(no name)"} ${c.basis.join(", ")}`);
|
|
5389
|
+
}
|
|
5390
|
+
if (r.dry && all) lines.push("Nothing written. Run again with --apply to mark them.");
|
|
5391
|
+
return lines.join("\n");
|
|
5392
|
+
});
|
|
5393
|
+
return 0;
|
|
5394
|
+
}
|
|
5395
|
+
|
|
5396
|
+
const FREE_USAGE = `Usage: admin billing free exposure [--json] who the free paywall would stop today
|
|
5397
|
+
admin billing free backfill --why "…" [--apply] signup grant for self-serve orgs with none; a dry run unless --apply`;
|
|
5398
|
+
|
|
5399
|
+
const EXPOSURE_WORDS = {
|
|
5400
|
+
needs_legacy: "pay today: need a legacy mark (admin billing legacy mark --all)",
|
|
5401
|
+
self_serve_no_grant: "self-serve, no grant: blocked at once (admin billing free backfill)",
|
|
5402
|
+
other_no_grant: "free, not paying, not self-serve, no grant: blocked at once (a person decides)",
|
|
5403
|
+
granted: "free with a grant (as designed)",
|
|
5404
|
+
};
|
|
5405
|
+
|
|
5406
|
+
/**
|
|
5407
|
+
* admin billing free … — before LETTERBRACE_FREE_TOKENS is set: who the free paywall would stop
|
|
5408
|
+
* (exposure, reads only) and the one-time signup grant for self-serve orgs that predate it (backfill,
|
|
5409
|
+
* a dry run unless --apply).
|
|
5410
|
+
*/
|
|
5411
|
+
async function cmdAdminBillingFree(ctx) {
|
|
5412
|
+
const { flags, positionals, io } = ctx;
|
|
5413
|
+
if (positionals[1] === "exposure") {
|
|
5414
|
+
const r = await staffRequest(ctx, "GET", "/api/superadmin/billing/free-tokens");
|
|
5415
|
+
printResult(io, flags, r, (x) => {
|
|
5416
|
+
const lines = [`Free orgs today (CRM snapshot ${x.snapshotOn ?? "none"}):`];
|
|
5417
|
+
for (const [group, words] of Object.entries(EXPOSURE_WORDS)) {
|
|
5418
|
+
lines.push(` ${String(x.counts[group]).padStart(5)} ${words}`);
|
|
5419
|
+
if (group === "granted") continue;
|
|
5420
|
+
for (const o of x.orgs.filter((y) => y.group === group))
|
|
5421
|
+
lines.push(
|
|
5422
|
+
` ${o.orgId.slice(0, 8)} ${o.name ?? "(no name)"} origin=${o.origin ?? "-"} revenue=${o.revenueSource ?? "-"}${o.paying ? " paying" : ""}`
|
|
5423
|
+
);
|
|
5424
|
+
}
|
|
5425
|
+
return lines.join("\n");
|
|
5426
|
+
});
|
|
5427
|
+
return 0;
|
|
5428
|
+
}
|
|
5429
|
+
if (positionals[1] === "backfill") {
|
|
5430
|
+
const why = flagStr(flags.why);
|
|
5431
|
+
if (!why) throw new CliError(`Say why (--why "…"): it is kept with each grant.\n${FREE_USAGE}`);
|
|
5432
|
+
const r = await staffPost(ctx, "/api/superadmin/billing/free-tokens/backfill", {
|
|
5433
|
+
dry: !flagBool(flags.apply),
|
|
5434
|
+
why,
|
|
5435
|
+
});
|
|
5436
|
+
printResult(io, flags, r, (x) => {
|
|
5437
|
+
const verb = x.dry ? "Would grant" : "Granted";
|
|
5438
|
+
const lines = [
|
|
5439
|
+
`${verb} ${x.tokens.toLocaleString("en-US")} tokens to ${x.granted.length} self-serve org(s); ${x.already.length} already had them.`,
|
|
5440
|
+
];
|
|
5441
|
+
for (const o of x.orgs) lines.push(` ${o.orgId.slice(0, 8)} ${o.name ?? "(no name)"}`);
|
|
5442
|
+
if (x.dry) lines.push("Nothing written. Run again with --apply to grant them.");
|
|
5443
|
+
return lines.join("\n");
|
|
5444
|
+
});
|
|
5445
|
+
return 0;
|
|
5446
|
+
}
|
|
5447
|
+
throw new CliError(FREE_USAGE);
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5267
5450
|
/** admin billing lago … — staff operations on Lago (docs/billing/lago-integration.md). */
|
|
5268
5451
|
async function cmdAdminBilling(ctx) {
|
|
5269
5452
|
const { flags, positionals, io } = ctx;
|
|
5453
|
+
if (positionals[0] === "legacy") return cmdAdminBillingLegacy(ctx);
|
|
5454
|
+
if (positionals[0] === "free") return cmdAdminBillingFree(ctx);
|
|
5270
5455
|
if (positionals[0] !== "lago") throw new CliError(LAGO_USAGE);
|
|
5271
5456
|
const sub = positionals[1];
|
|
5272
5457
|
switch (sub) {
|
|
@@ -5431,7 +5616,7 @@ async function cmdAdminBilling(ctx) {
|
|
|
5431
5616
|
const p = result.plan;
|
|
5432
5617
|
ok(
|
|
5433
5618
|
ctx,
|
|
5434
|
-
`${result.dryRun ? "Would move" : "Moving"} ${p.orgId} from Stripe ${p.from.stripeSubscriptionId} (${p.from.product ?? "subscription"}) to Lago ${p.to.plan} at its renewal ${p.from.renewsAt}: Stripe stops then, Lago charges $${(p.to.amountCents / 100).toFixed(2)} then (${p.to.includedTokens} tokens included, overage $${p.to.overageUsdPerToken} a token).`
|
|
5619
|
+
`${result.dryRun ? "Would move" : "Moving"} ${p.orgId} from Stripe ${p.from.stripeSubscriptionId} (${p.from.product ?? "subscription"}) to Lago ${p.to.plan} at its renewal ${p.from.renewsAt}: Stripe stops then, Lago charges $${(p.to.amountCents / 100).toFixed(2)} then (${p.to.includedTokens} tokens included, overage $${p.to.overageUsdPerToken} a token). Bonus when it takes effect: ${(p.to.bonusTokens ?? 0).toLocaleString("en-US")} tokens (signup × ${p.to.ratio}x), once.`
|
|
5435
5620
|
);
|
|
5436
5621
|
printResult(io, flags, result);
|
|
5437
5622
|
return 0;
|
|
@@ -5635,11 +5820,10 @@ export async function cmdAdmin(ctx) {
|
|
|
5635
5820
|
if (sub === "brand-detection") return cmdAdminBrandDetection({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5636
5821
|
if (sub === "republish") return cmdAdminRepublish({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5637
5822
|
if (sub === "recipes") return cmdAdminRecipes({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5823
|
+
if (sub === "letterpress") return cmdAdminLetterpress({ ...ctx, positionals: ctx.positionals.slice(1) });
|
|
5638
5824
|
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
5825
|
throw new CliError(
|
|
5642
|
-
'Usage: admin recipes … | admin
|
|
5826
|
+
'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
5827
|
);
|
|
5644
5828
|
}
|
|
5645
5829
|
|
|
@@ -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/repo.mjs
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// repo say → send_repo_change_message (steer a build while its agent works)
|
|
10
10
|
// repo repos → list_github_app_repos repo branches → list_repo_branches
|
|
11
11
|
// repo connect → connect_github (the link a person opens to connect GitHub)
|
|
12
|
+
// repo repos --gitlab → list_gitlab_repos repo connect --gitlab → connect_gitlab
|
|
12
13
|
// repo prs → list_open_pull_requests (every open PR, whoever opened it)
|
|
13
14
|
// repo install-letterprove → letterprove_open_install_pr
|
|
14
15
|
// repo install-visitors → visitors_open_install_pr
|
|
@@ -40,15 +41,29 @@ function secretValue(flags) {
|
|
|
40
41
|
return inline === undefined ? value.replace(/\r?\n$/, "") : value;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* `--repo owner/name` → the two schema keys; --owner/--name also work. With --gitlab the path may
|
|
46
|
+
* nest (`group/subgroup/project`): the owner is everything before the last slash.
|
|
47
|
+
*/
|
|
44
48
|
function splitRepo(flags) {
|
|
45
49
|
const full = flagStr(flags.repo);
|
|
46
50
|
if (full === undefined) return { owner: flagStr(flags.owner), name: flagStr(flags.name) };
|
|
51
|
+
if (flags.gitlab) {
|
|
52
|
+
const at = full.lastIndexOf("/");
|
|
53
|
+
const owner = full.slice(0, at);
|
|
54
|
+
const name = full.slice(at + 1);
|
|
55
|
+
if (at < 1 || !name) throw new CliError("--repo must be group/project (or group/subgroup/project)");
|
|
56
|
+
return { owner, name };
|
|
57
|
+
}
|
|
47
58
|
const [owner, name, ...extra] = full.split("/");
|
|
48
|
-
if (!owner || !name || extra.length)
|
|
59
|
+
if (!owner || !name || extra.length)
|
|
60
|
+
throw new CliError("--repo must be owner/name (add --gitlab for a GitLab group/subgroup/project)");
|
|
49
61
|
return { owner, name };
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
/** `--gitlab`: the repo is a GitLab project; GitHub when left out. */
|
|
65
|
+
const provider = { value: (flags) => (flags.gitlab ? "gitlab" : undefined) };
|
|
66
|
+
|
|
52
67
|
function issueList(flags) {
|
|
53
68
|
return flagList(flags.issue)
|
|
54
69
|
.flatMap((v) => v.split(","))
|
|
@@ -58,6 +73,7 @@ function issueList(flags) {
|
|
|
58
73
|
|
|
59
74
|
const ARGS = {
|
|
60
75
|
start_repo_change: {
|
|
76
|
+
provider,
|
|
61
77
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
62
78
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
63
79
|
base_branch: "branch",
|
|
@@ -81,6 +97,7 @@ const ARGS = {
|
|
|
81
97
|
list_repo_sites: {},
|
|
82
98
|
detect_repo_sites: { force: { flag: "force", type: "bool" } },
|
|
83
99
|
set_repo_site: {
|
|
100
|
+
provider,
|
|
84
101
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
85
102
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
86
103
|
site_host: { flag: "site", required: true },
|
|
@@ -89,21 +106,25 @@ const ARGS = {
|
|
|
89
106
|
branch: { value: (flags) => (flags.branch === "none" ? null : flagStr(flags.branch)) },
|
|
90
107
|
},
|
|
91
108
|
reset_repo_site: {
|
|
109
|
+
provider,
|
|
92
110
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
93
111
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
94
112
|
site_host: { flag: "site", required: true },
|
|
95
113
|
},
|
|
96
114
|
list_repo_preview_secrets: {
|
|
115
|
+
provider,
|
|
97
116
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
98
117
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
99
118
|
},
|
|
100
119
|
set_repo_preview_secret: {
|
|
120
|
+
provider,
|
|
101
121
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
102
122
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
103
123
|
key: { flag: "secret", required: true },
|
|
104
124
|
value: { value: (flags) => secretValue(flags) },
|
|
105
125
|
},
|
|
106
126
|
delete_repo_preview_secret: {
|
|
127
|
+
provider,
|
|
107
128
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
108
129
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
109
130
|
key: { flag: "secret", required: true },
|
|
@@ -118,12 +139,14 @@ const ARGS = {
|
|
|
118
139
|
preview: { flag: "preview", type: "bool" },
|
|
119
140
|
},
|
|
120
141
|
letterprove_open_install_pr: {
|
|
142
|
+
provider,
|
|
121
143
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
122
144
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
123
145
|
base_branch: "branch",
|
|
124
146
|
action: { flag: "action", enum: ["build", "build_pr", "build_merge", "slack", "linear"] },
|
|
125
147
|
},
|
|
126
148
|
visitors_open_install_pr: {
|
|
149
|
+
provider,
|
|
127
150
|
site_id: "site",
|
|
128
151
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
129
152
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
@@ -252,6 +275,8 @@ const ARGS = {
|
|
|
252
275
|
},
|
|
253
276
|
list_github_app_repos: {},
|
|
254
277
|
connect_github: {},
|
|
278
|
+
list_gitlab_repos: { search: "search", page: { flag: "page", type: "num" } },
|
|
279
|
+
connect_gitlab: {},
|
|
255
280
|
list_repo_branches: {
|
|
256
281
|
repo_owner: { value: (flags) => splitRepo(flags).owner },
|
|
257
282
|
repo_name: { value: (flags) => splitRepo(flags).name },
|
|
@@ -409,6 +434,7 @@ async function repoStart(ctx) {
|
|
|
409
434
|
const { client, flags, io } = ctx;
|
|
410
435
|
refuseUnknownFlags(ctx, {}, [
|
|
411
436
|
"repo",
|
|
437
|
+
"gitlab",
|
|
412
438
|
"owner",
|
|
413
439
|
"name",
|
|
414
440
|
"branch",
|
|
@@ -500,7 +526,7 @@ async function repoFixAudit(ctx) {
|
|
|
500
526
|
/** `repo install-letterprove --repo owner/name [--branch b] [--wait]`: Letterprove's script + identify calls → one PR. */
|
|
501
527
|
async function repoInstallLetterprove(ctx) {
|
|
502
528
|
const { client, flags, io } = ctx;
|
|
503
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "branch", "action", "wait"]);
|
|
529
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab", "branch", "action", "wait"]);
|
|
504
530
|
const result = await client.callTool(
|
|
505
531
|
"letterprove_open_install_pr",
|
|
506
532
|
argsFromFlags(ARGS.letterprove_open_install_pr, flags, ctx.positionals)
|
|
@@ -516,7 +542,7 @@ async function repoInstallLetterprove(ctx) {
|
|
|
516
542
|
/** `repo install-visitors [--site id] [--repo owner/name] [--branch b] [--wait]`: the Visitors script tag and server snippet → one PR. */
|
|
517
543
|
async function repoInstallVisitors(ctx) {
|
|
518
544
|
const { client, flags, io } = ctx;
|
|
519
|
-
refuseUnknownFlags(ctx, {}, ["site", "repo", "owner", "name", "branch", "action", "wait"]);
|
|
545
|
+
refuseUnknownFlags(ctx, {}, ["site", "repo", "owner", "name", "gitlab", "branch", "action", "wait"]);
|
|
520
546
|
const result = await client.callTool(
|
|
521
547
|
"visitors_open_install_pr",
|
|
522
548
|
argsFromFlags(ARGS.visitors_open_install_pr, flags, ctx.positionals)
|
|
@@ -551,7 +577,7 @@ async function repoSites(ctx) {
|
|
|
551
577
|
/** `repo set-site --repo owner/name --site acme.com [--not]`: say which site a repo builds (or doesn't). */
|
|
552
578
|
async function repoSetSite(ctx) {
|
|
553
579
|
const { client, flags, io } = ctx;
|
|
554
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "site", "not", "branch"]);
|
|
580
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab", "site", "not", "branch"]);
|
|
555
581
|
const result = await client.callTool("set_repo_site", argsFromFlags(ARGS.set_repo_site, flags));
|
|
556
582
|
ok(ctx, result.message);
|
|
557
583
|
printResult(io, flags, result.site);
|
|
@@ -561,7 +587,7 @@ async function repoSetSite(ctx) {
|
|
|
561
587
|
/** `repo reset-site --repo owner/name --site acme.com`: back to automatic detection. */
|
|
562
588
|
async function repoResetSite(ctx) {
|
|
563
589
|
const { client, flags, io } = ctx;
|
|
564
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "site"]);
|
|
590
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab", "site"]);
|
|
565
591
|
const result = await client.callTool("reset_repo_site", argsFromFlags(ARGS.reset_repo_site, flags));
|
|
566
592
|
ok(ctx, result.message);
|
|
567
593
|
printResult(io, flags, result);
|
|
@@ -571,7 +597,7 @@ async function repoResetSite(ctx) {
|
|
|
571
597
|
/** `repo secrets --repo owner/name`: the repo's preview secrets, names and when each was set (never values). */
|
|
572
598
|
async function repoSecrets(ctx) {
|
|
573
599
|
const { client, flags, io } = ctx;
|
|
574
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name"]);
|
|
600
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab"]);
|
|
575
601
|
const result = await client.callTool(
|
|
576
602
|
"list_repo_preview_secrets",
|
|
577
603
|
argsFromFlags(ARGS.list_repo_preview_secrets, flags)
|
|
@@ -587,7 +613,7 @@ async function repoSecrets(ctx) {
|
|
|
587
613
|
/** `repo set-secret --repo owner/name --secret KEY --value v | --value-file path|-`: set or overwrite one. */
|
|
588
614
|
async function repoSetSecret(ctx) {
|
|
589
615
|
const { client, flags, io } = ctx;
|
|
590
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "secret", "value", "value-file"]);
|
|
616
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab", "secret", "value", "value-file"]);
|
|
591
617
|
const result = await client.callTool("set_repo_preview_secret", argsFromFlags(ARGS.set_repo_preview_secret, flags));
|
|
592
618
|
ok(ctx, result.message);
|
|
593
619
|
printResult(io, flags, result.secret);
|
|
@@ -597,7 +623,7 @@ async function repoSetSecret(ctx) {
|
|
|
597
623
|
/** `repo delete-secret --repo owner/name --secret KEY`: delete one. */
|
|
598
624
|
async function repoDeleteSecret(ctx) {
|
|
599
625
|
const { client, flags, io } = ctx;
|
|
600
|
-
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "secret"]);
|
|
626
|
+
refuseUnknownFlags(ctx, {}, ["repo", "owner", "name", "gitlab", "secret"]);
|
|
601
627
|
const result = await client.callTool(
|
|
602
628
|
"delete_repo_preview_secret",
|
|
603
629
|
argsFromFlags(ARGS.delete_repo_preview_secret, flags)
|
|
@@ -723,6 +749,15 @@ async function repoRevise(ctx) {
|
|
|
723
749
|
|
|
724
750
|
async function repoRepos(ctx) {
|
|
725
751
|
const { client, flags, io } = ctx;
|
|
752
|
+
if (flags.gitlab) {
|
|
753
|
+
const found = await client.callTool("list_gitlab_repos", argsFromFlags(ARGS.list_gitlab_repos, flags));
|
|
754
|
+
printResult(io, flags, found, (r) =>
|
|
755
|
+
r.projects.length
|
|
756
|
+
? r.projects.map((p) => `${p.path} (default ${p.defaultBranch ?? "none"})`).join("\n")
|
|
757
|
+
: r.message
|
|
758
|
+
);
|
|
759
|
+
return 0;
|
|
760
|
+
}
|
|
726
761
|
const result = await client.callTool("list_github_app_repos", argsFromFlags(ARGS.list_github_app_repos, flags));
|
|
727
762
|
printResult(io, flags, result, (r) =>
|
|
728
763
|
r.repos.length
|
|
@@ -732,10 +767,12 @@ async function repoRepos(ctx) {
|
|
|
732
767
|
return 0;
|
|
733
768
|
}
|
|
734
769
|
|
|
735
|
-
/** `repo connect`: whether GitHub is connected, and the link a person opens to connect it. */
|
|
770
|
+
/** `repo connect [--gitlab]`: whether GitHub (or GitLab) is connected, and the link a person opens to connect it. */
|
|
736
771
|
async function repoConnect(ctx) {
|
|
737
772
|
const { client, flags, io } = ctx;
|
|
738
|
-
const result =
|
|
773
|
+
const result = flags.gitlab
|
|
774
|
+
? await client.callTool("connect_gitlab", argsFromFlags(ARGS.connect_gitlab, flags))
|
|
775
|
+
: await client.callTool("connect_github", argsFromFlags(ARGS.connect_github, flags));
|
|
739
776
|
printResult(io, flags, result, (r) => r.message);
|
|
740
777
|
return 0;
|
|
741
778
|
}
|
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";
|