@letterstory/cli 0.175.2 → 0.175.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.mjs CHANGED
@@ -73,10 +73,11 @@ import {
73
73
  cmdTargets,
74
74
  cmdVisits,
75
75
  cmdSim,
76
+ cmdVary,
76
77
  } from "./commands.mjs";
77
78
 
78
79
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
79
- export const VERSION = "0.175.2";
80
+ export const VERSION = "0.175.4";
80
81
 
81
82
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
82
83
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -1698,6 +1699,17 @@ Sim (Simulations: a free, simulated copy of your API for agents, and what they d
1698
1699
  sim session <session-id> One session, call by call
1699
1700
  sim report <id> [--since 30d] Funnel, missing operations, argument errors, loops, by agent
1700
1701
 
1702
+ Vary (Variationals: A/B tests of a page's words and images on your own site):
1703
+ vary [list] [--status running] [--site <id>] Your variationals and how many visitors each has seen
1704
+ vary create --page <url> [--name <n>] [--goals-file <path>]
1705
+ vary get <id> Variants, their changes, and the results against the original
1706
+ vary page <id> The page's copy as changes need it, and whether each variant still applies
1707
+ vary save-variant <id> --deltas-file <path> [--key b] [--name <n>]
1708
+ vary weights <id> a=50,b=50 How visitors are split (whole percent, adding to 100)
1709
+ vary goals <id> --goals-file <path> What counts as a conversion (the first is primary)
1710
+ vary start <id> | vary pause <id> | vary end <id> [--winner b]
1711
+ vary remove-variant <id> <key> | vary delete <id>
1712
+
1701
1713
  Evals (how the pipeline is doing on your posts, and the regression cases captured from them):
1702
1714
  evals scoreboard [--collection <id>] [--days N] Every measure by stage: posts, failing, rate
1703
1715
  evals cases [--status open|guarding|proposed|retired|rejected] [--stage research|brief|links|mentions|accuracy|pipeline|shred]
@@ -1800,6 +1812,7 @@ const CLIENT_COMMANDS = {
1800
1812
  evals: cmdEvals,
1801
1813
  visits: cmdVisits,
1802
1814
  sim: cmdSim,
1815
+ vary: cmdVary,
1803
1816
  // Platform-scoped (staff key) — the only commands that act BEFORE an org exists.
1804
1817
  admin: cmdAdmin,
1805
1818
  };
@@ -4,6 +4,7 @@
4
4
  // ask --outcome geo|seo|… → the plan for that outcome (the Plan tab's box)
5
5
  // ask --lens fix | --lens build → what's broken (most pressing first) | what to build
6
6
  // ask "<words…>" → in your own words; what nothing does comes back as unmet
7
+ // ask "<words…>" --found "<…>" → with what you read outside the account for them (a case study)
7
8
 
8
9
  import { CliError } from "../client.mjs";
9
10
  import { argsFromFlags, flagStr, printResult, refuseUnknownFlags } from "./shared.mjs";
@@ -13,6 +14,8 @@ export const ARGS = {
13
14
  outcome: "outcome",
14
15
  lens: "lens",
15
16
  words: { value: (flags, positionals) => flagStr(flags.words) ?? (positionals.join(" ").trim() || undefined) },
17
+ // --found: what was read outside the account for the words (a case study, a competitor), as findings.
18
+ found: "found",
16
19
  // --refresh: decide every strategy again from the facts as they are now (the standing fit is read otherwise).
17
20
  refresh: { flag: "refresh", type: "bool" },
18
21
  domain: "site",
@@ -21,7 +24,7 @@ export const ARGS = {
21
24
 
22
25
  export async function cmdAsk(ctx) {
23
26
  const { client, flags, io } = ctx;
24
- refuseUnknownFlags(ctx, {}, ["outcome", "lens", "words", "site", "refresh"]);
27
+ refuseUnknownFlags(ctx, {}, ["outcome", "lens", "words", "found", "site", "refresh"]);
25
28
  const args = argsFromFlags(ARGS.ask_letterpress, flags, ctx.positionals, {});
26
29
  if ([args.outcome, args.lens, args.words].filter(Boolean).length > 1)
27
30
  throw new CliError("One ask at a time: --outcome, --lens fix|build, or your words.");
@@ -0,0 +1,211 @@
1
+ // `vary` — Variationals from a terminal: A/B tests of a page's words and images on your own site
2
+ // (docs/architecture/variationals.md). Thin wrappers over the variationals tools (list_variationals,
3
+ // get_variational, create_variational, update_variational, save_variational_variant,
4
+ // remove_variational_variant, delete_variational), the same lib functions the app calls.
5
+ //
6
+ // letterstory vary list [--status running]
7
+ // letterstory vary create --page https://acme.com/pricing [--name "Pricing headline"] [--goals-file goals.json]
8
+ // letterstory vary get <id>
9
+ // letterstory vary page <id> the page's blocks, as a change's tag/before/occurrence
10
+ // letterstory vary save-variant <id> --deltas-file b.json [--key b] [--name "Shorter headline"]
11
+ // b.json: [{ "kind": "text", "tag": "h1", "before": "Ship faster", "after": "Ship today" },
12
+ // { "kind": "image", "before": "https://acme.com/hero.png", "after": "/hero-team.png" }]
13
+ // letterstory vary weights <id> a=50,b=50
14
+ // letterstory vary goals <id> --goals-file goals.json
15
+ // letterstory vary start <id> | pause <id> | end <id> [--winner b]
16
+ // letterstory vary remove-variant <id> <key>
17
+ // letterstory vary delete <id>
18
+
19
+ import { readFileSync } from "node:fs";
20
+ import { CliError } from "../client.mjs";
21
+ import { flagStr, printResult, argsFromFlags, refuseUnknownFlags } from "./shared.mjs";
22
+
23
+ const variationalId = { positional: 0, label: "variational-id", required: true };
24
+
25
+ function jsonFile(flag, what) {
26
+ return {
27
+ value: (flags) => {
28
+ const path = flagStr(flags[flag]);
29
+ if (!path) return undefined;
30
+ try {
31
+ return JSON.parse(readFileSync(path, "utf8"));
32
+ } catch {
33
+ throw new CliError(`--${flag} must be a JSON file of ${what} (could not parse ${path})`);
34
+ }
35
+ },
36
+ };
37
+ }
38
+
39
+ /** a=50,b=50 → { a: 50, b: 50 } */
40
+ function weightsArg() {
41
+ return {
42
+ value: (_flags, positionals) => {
43
+ const raw = positionals[1];
44
+ if (raw === undefined) return undefined;
45
+ const out = {};
46
+ for (const part of String(raw).split(",")) {
47
+ const [key, value] = part.split("=").map((s) => s.trim());
48
+ const n = Number(value);
49
+ if (!/^[a-f]$/.test(key ?? "") || !Number.isInteger(n)) {
50
+ throw new CliError(`Weights are key=percent pairs, e.g. a=50,b=50 (got "${part}")`);
51
+ }
52
+ out[key] = n;
53
+ }
54
+ return out;
55
+ },
56
+ };
57
+ }
58
+
59
+ export const ARGS = {
60
+ list_variationals: {
61
+ with_results: { internal: "the list shows each test's visitors, so it always reads results" },
62
+ site_id: "site",
63
+ status: { flag: "status", enum: ["draft", "running", "paused", "ended"] },
64
+ },
65
+ get_variational: { variational_id: variationalId },
66
+ read_variational_page: { variational_id: variationalId },
67
+ create_variational: {
68
+ page_url: { flag: "page", required: true },
69
+ site_id: "site",
70
+ name: "name",
71
+ goals: jsonFile("goals-file", "goals"),
72
+ },
73
+ update_variational: {
74
+ variational_id: variationalId,
75
+ name: "name",
76
+ goals: jsonFile("goals-file", "goals"),
77
+ weights: weightsArg(),
78
+ status: { flag: "status", enum: ["running", "paused", "ended"] },
79
+ winner: "winner",
80
+ },
81
+ save_variational_variant: {
82
+ variational_id: variationalId,
83
+ key: "key",
84
+ name: "name",
85
+ deltas: { ...jsonFile("deltas-file", "text and image changes"), required: true },
86
+ },
87
+ remove_variational_variant: {
88
+ variational_id: variationalId,
89
+ key: { positional: 1, label: "key", required: true },
90
+ },
91
+ delete_variational: { variational_id: variationalId },
92
+ };
93
+
94
+ function call(ctx, tool) {
95
+ return ctx.client.callTool(tool, argsFromFlags(ARGS[tool], ctx.flags, ctx.positionals));
96
+ }
97
+
98
+ export async function cmdVary(ctx) {
99
+ const sub = ctx.positionals[0];
100
+ const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
101
+ switch (sub) {
102
+ case undefined:
103
+ case "list":
104
+ case "ls":
105
+ refuseUnknownFlags(rest, ARGS.list_variationals);
106
+ return varyList(rest);
107
+ case "get":
108
+ case "show":
109
+ return varyShow(rest, await call(rest, "get_variational"));
110
+ case "page": {
111
+ const result = await call(rest, "read_variational_page");
112
+ printResult(rest.io, rest.flags, result, (r) =>
113
+ [
114
+ ...r.blocks.map(
115
+ (b) =>
116
+ `${b.tag.padEnd(8)} ${b.occurrence ? `#${b.occurrence} ` : ""}${b.before.replace(/\n/g, " / ")}`
117
+ ),
118
+ ...r.images.map((i) => `img ${i.before}${i.alt ? ` (${i.alt})` : ""}`),
119
+ ...r.variants.map(
120
+ (v) => `variant ${v.key.toUpperCase()}: ${v.found} of ${v.changes} changes find their block`
121
+ ),
122
+ ].join("\n")
123
+ );
124
+ return 0;
125
+ }
126
+ case "create":
127
+ refuseUnknownFlags(rest, ARGS.create_variational, ["goals-file"]);
128
+ return varyShow(rest, await call(rest, "create_variational"));
129
+ case "update":
130
+ case "weights":
131
+ case "goals":
132
+ refuseUnknownFlags(rest, ARGS.update_variational, ["goals-file"]);
133
+ return varyShow(rest, await call(rest, "update_variational"));
134
+ case "start":
135
+ case "pause":
136
+ case "end": {
137
+ refuseUnknownFlags(rest, ARGS.update_variational, []);
138
+ const status = sub === "start" ? "running" : sub === "pause" ? "paused" : "ended";
139
+ rest.flags = { ...rest.flags, status };
140
+ return varyShow(rest, await call(rest, "update_variational"));
141
+ }
142
+ case "save-variant": {
143
+ refuseUnknownFlags(rest, ARGS.save_variational_variant, ["deltas-file"]);
144
+ if (!flagStr(rest.flags["deltas-file"]))
145
+ throw new CliError("Usage: vary save-variant <id> --deltas-file <path>");
146
+ const result = await call(rest, "save_variational_variant");
147
+ return varyShow(rest, result);
148
+ }
149
+ case "remove-variant":
150
+ return varyShow(rest, await call(rest, "remove_variational_variant"));
151
+ case "delete": {
152
+ const result = await call(rest, "delete_variational");
153
+ printResult(rest.io, rest.flags, result, (r) => `Deleted ${r.deleted}.`);
154
+ return 0;
155
+ }
156
+ default:
157
+ throw new CliError(
158
+ "Usage: vary [list|get|page|create|update|weights|goals|start|pause|end|save-variant|remove-variant|delete]"
159
+ );
160
+ }
161
+ }
162
+
163
+ const pct = (r) => (r === null || r === undefined ? "—" : `${(r * 100).toFixed(1)}%`);
164
+
165
+ async function varyList(ctx) {
166
+ const result = await call(ctx, "list_variationals");
167
+ printResult(ctx.io, ctx.flags, result, (r) => {
168
+ if (!r.variationals?.length) {
169
+ return "No variationals yet. Make one: vary create --page https://<your site>/<page>";
170
+ }
171
+ return r.variationals
172
+ .map((v) => {
173
+ const visitors = (v.results?.variants ?? []).reduce((n, x) => n + x.visitors, 0);
174
+ return `${v.id} ${v.status.padEnd(7)} ${v.page_path.padEnd(28)} ${String(v.variants.length).padStart(2)} variants ${String(visitors).padStart(6)} visitors ${v.name}`;
175
+ })
176
+ .join("\n");
177
+ });
178
+ return 0;
179
+ }
180
+
181
+ function varyShow(ctx, result) {
182
+ printResult(ctx.io, ctx.flags, result, (r) => {
183
+ const v = r.variational;
184
+ const lines = [
185
+ `${v.name} — ${v.status}${v.winner ? `, winner ${v.winner.toUpperCase()}` : ""}`,
186
+ ` Page ${v.page_url}`,
187
+ ` Edit ${v.edit_url}`,
188
+ ` Goals ${v.goals.length ? v.goals.map((g) => `${g.label} (${g.kind})`).join("; ") : "none: time on page decides"}`,
189
+ "",
190
+ "Variants (weight · changes):",
191
+ ];
192
+ for (const x of v.variants) {
193
+ lines.push(
194
+ ` ${x.key.toUpperCase()} ${String(x.weight).padStart(3)}% ${x.deltas.length} changes ${x.name}`
195
+ );
196
+ }
197
+ if (v.results) {
198
+ lines.push("", v.results.summary, "", "Results (people · seconds · scroll · conversion):");
199
+ for (const x of v.results.variants) {
200
+ const call = x.versus_default ? ` ${x.versus_default.call}` : "";
201
+ lines.push(
202
+ ` ${x.key.toUpperCase()} ${String(x.visitors).padStart(6)} visitors ${x.seconds.mean === null ? "—" : `${Math.round(x.seconds.mean)}s`} ${x.scroll.mean === null ? "—" : `${Math.round(x.scroll.mean)}%`} ${pct(x.goals[0]?.rate)}${call}`
203
+ );
204
+ }
205
+ }
206
+ if (r.revised)
207
+ lines.push("", `Saved ${String(r.variant).toUpperCase()}: its results start again from this revision.`);
208
+ return lines.join("\n");
209
+ });
210
+ return 0;
211
+ }
package/lib/commands.mjs CHANGED
@@ -51,3 +51,4 @@ export * from "./commands/site.mjs";
51
51
  export * from "./commands/evals.mjs";
52
52
  export * from "./commands/visits.mjs";
53
53
  export * from "./commands/sim.mjs";
54
+ export * from "./commands/vary.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.175.2",
3
+ "version": "0.175.4",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",