@letterstory/cli 0.175.10 → 0.175.12

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
@@ -74,10 +74,11 @@ import {
74
74
  cmdVisits,
75
75
  cmdSim,
76
76
  cmdVary,
77
+ cmdBench,
77
78
  } from "./commands.mjs";
78
79
 
79
80
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
80
- export const VERSION = "0.175.10";
81
+ export const VERSION = "0.175.12";
81
82
 
82
83
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
83
84
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -86,6 +87,10 @@ export const EXIT_PAYMENT_REQUIRED = 3;
86
87
  // can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
87
88
  // `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
88
89
  export const BOOLEAN_FLAGS = new Set([
90
+ // sim create / resample / sample-key: keep the customer's sample key, or delete it now.
91
+ "keep-key",
92
+ "delete-key",
93
+ "keep",
89
94
  // automate add/set: on or off; only identified visitors marked hot leads.
90
95
  "on",
91
96
  "off",
@@ -1714,6 +1719,20 @@ Vary (Variationals: A/B tests of a page's words and images on your own site):
1714
1719
  vary start <id> | vary pause <id> | vary end <id> [--winner b]
1715
1720
  vary remove-variant <id> <key> | vary delete <id>
1716
1721
 
1722
+ Bench (Benches: open-source benchmarks on their own domains, kept running; @letterstory.com only):
1723
+ bench [list] Your benches: stage, what each waits on, domain
1724
+ bench create (--prompt "<what it is and how it works>"|--prompt-file <path>) [--name <n>] [--domain <d>]
1725
+ [--letterbase <collection-id>] [--every <days>] [--repo-owner <o>] [--repo-name <r>] [--spec-file <path>]
1726
+ The repo lives on your organization's GitHub
1727
+ bench show <id> Spec, domain, repo, site, results, recent events
1728
+ bench update <id> [--name <n>] [--slug <s>] [--repo-owner <o>] [--repo-name <r>] [--spec-file <path>] [--domain <d>] [--every <days>]
1729
+ bench pause <id> | bench resume <id> | bench archive <id>
1730
+ bench advance <id> [--retry] Move it on now; --retry once blocked_on is done
1731
+ bench run <id> [--note "<what else to do>"] Letterpress-1 runs the benchmark again
1732
+ bench connect <id> <collection-id|none> A letterbase whose posts cite and link it
1733
+ bench cite <id> The reference line a post cites
1734
+ bench replicate <id> REPLICATE.md: how an agent reproduces the results
1735
+
1717
1736
  Evals (how the pipeline is doing on your posts, and the regression cases captured from them):
1718
1737
  evals scoreboard [--collection <id>] [--days N] Every measure by stage: posts, failing, rate
1719
1738
  evals cases [--status open|guarding|proposed|retired|rejected] [--stage research|brief|links|mentions|accuracy|pipeline|shred]
@@ -1817,6 +1836,7 @@ const CLIENT_COMMANDS = {
1817
1836
  visits: cmdVisits,
1818
1837
  sim: cmdSim,
1819
1838
  vary: cmdVary,
1839
+ bench: cmdBench,
1820
1840
  // Platform-scoped (staff key) — the only commands that act BEFORE an org exists.
1821
1841
  admin: cmdAdmin,
1822
1842
  };
@@ -0,0 +1,192 @@
1
+ // `bench` — Benches from a terminal (docs/architecture/benches.md): public, open-source benchmarks
2
+ // on their own domains, kept running by Letter. Staff only: the tools answer only a key an
3
+ // @letterstory.com person made. Thin wrappers over the bench tools (create_bench, list_benches,
4
+ // get_bench, update_bench, advance_bench, start_bench_run, connect_bench_letterbase,
5
+ // get_bench_citation), the same lib functions the app calls.
6
+ //
7
+ // letterstory bench create --prompt "Benchmark Acme's vector search against Pinecone and Qdrant: …"
8
+ // letterstory bench create --prompt-file brief.md --name VectorBench --domain vectorbench.dev --letterbase <collection-id>
9
+ // [--repo-owner <their GitHub account>] [--repo-name <name>]
10
+ // letterstory bench list
11
+ // letterstory bench show <id>
12
+ // letterstory bench update <id> [--name <n>] [--slug <s>] [--repo-owner <o>] [--repo-name <r>] [--spec-file spec.json] [--domain <d>] [--every <days>]
13
+ // letterstory bench pause <id> | resume <id> | archive <id>
14
+ // letterstory bench advance <id> [--retry]
15
+ // letterstory bench run <id> [--note "add Qdrant as a contender"]
16
+ // letterstory bench connect <id> <collection-id|none>
17
+ // letterstory bench cite <id>
18
+ // letterstory bench replicate <id>
19
+
20
+ import { readFileSync } from "node:fs";
21
+ import { CliError } from "../client.mjs";
22
+ import { argsFromFlags, flagStr, printResult, readTextInput, refuseUnknownFlags } from "./shared.mjs";
23
+
24
+ const benchId = { positional: 0, label: "bench-id", required: true };
25
+
26
+ function specFromFile(flags) {
27
+ const path = flagStr(flags["spec-file"]);
28
+ if (!path) return undefined;
29
+ try {
30
+ return JSON.parse(readFileSync(path, "utf8"));
31
+ } catch {
32
+ throw new CliError(`--spec-file must be the spec as JSON (could not parse ${path})`);
33
+ }
34
+ }
35
+
36
+ export const ARGS = {
37
+ create_bench: {
38
+ prompt: {
39
+ value: (flags) => {
40
+ const prompt = readTextInput(flags, "prompt", "prompt-file");
41
+ if (prompt === undefined) throw new CliError("Missing required --prompt (or --prompt-file <path>)");
42
+ return prompt;
43
+ },
44
+ },
45
+ name: "name",
46
+ domain: "domain",
47
+ repo_owner: "repo-owner",
48
+ repo_name: "repo-name",
49
+ collection_id: "letterbase",
50
+ rerun_every_days: { flag: "every", type: "num" },
51
+ spec: { value: specFromFile },
52
+ },
53
+ list_benches: {},
54
+ get_bench: { bench_id: benchId },
55
+ update_bench: {
56
+ bench_id: benchId,
57
+ name: "name",
58
+ slug: "slug",
59
+ repo_owner: "repo-owner",
60
+ repo_name: "repo-name",
61
+ spec: { value: specFromFile },
62
+ domain: "domain",
63
+ rerun_every_days: { flag: "every", type: "num" },
64
+ status: { flag: "status", enum: ["live", "paused", "archived"] },
65
+ },
66
+ advance_bench: { bench_id: benchId, retry: { flag: "retry", type: "bool" } },
67
+ start_bench_run: { bench_id: benchId, note: "note" },
68
+ connect_bench_letterbase: {
69
+ bench_id: benchId,
70
+ collection_id: {
71
+ value: (_flags, positionals) => {
72
+ const v = positionals[1];
73
+ if (v === undefined) throw new CliError("Missing required <collection-id|none>");
74
+ return v === "none" ? null : v;
75
+ },
76
+ },
77
+ },
78
+ get_bench_citation: { bench_id: benchId },
79
+ };
80
+
81
+ function call(ctx, tool) {
82
+ return ctx.client.callTool(tool, argsFromFlags(ARGS[tool], ctx.flags, ctx.positionals));
83
+ }
84
+
85
+ export async function cmdBench(ctx) {
86
+ const sub = ctx.positionals[0];
87
+ const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
88
+ switch (sub) {
89
+ case undefined:
90
+ case "list":
91
+ case "ls":
92
+ return benchList(rest);
93
+ case "create":
94
+ refuseUnknownFlags(rest, ARGS.create_bench, ["prompt", "prompt-file", "spec-file"]);
95
+ return benchShow(rest, await call(rest, "create_bench"));
96
+ case "show":
97
+ return benchShow(rest, await call(rest, "get_bench"));
98
+ case "update":
99
+ refuseUnknownFlags(rest, ARGS.update_bench, ["spec-file"]);
100
+ return benchShow(rest, await call(rest, "update_bench"));
101
+ case "pause":
102
+ case "resume":
103
+ case "archive":
104
+ rest.flags = { ...rest.flags, status: { pause: "paused", resume: "live", archive: "archived" }[sub] };
105
+ return benchShow(rest, await call(rest, "update_bench"));
106
+ case "advance":
107
+ refuseUnknownFlags(rest, ARGS.advance_bench, []);
108
+ return benchShow(rest, await call(rest, "advance_bench"));
109
+ case "run":
110
+ refuseUnknownFlags(rest, ARGS.start_bench_run, []);
111
+ return benchShow(rest, await call(rest, "start_bench_run"));
112
+ case "connect":
113
+ return benchShow(rest, await call(rest, "connect_bench_letterbase"));
114
+ case "cite":
115
+ return benchCite(rest);
116
+ case "replicate":
117
+ return benchReplicate(rest);
118
+ default:
119
+ throw new CliError(
120
+ "Usage: bench [list|create|show|update|pause|resume|archive|advance|run|connect|cite|replicate]"
121
+ );
122
+ }
123
+ }
124
+
125
+ const title = (b) => b.name || "(drafting the spec)";
126
+
127
+ async function benchList(ctx) {
128
+ const result = await call(ctx, "list_benches");
129
+ printResult(ctx.io, ctx.flags, result, (r) => {
130
+ if (!r.benches?.length)
131
+ return 'No benches yet. Start one: bench create --prompt "<what it is and how it works>"';
132
+ return r.benches
133
+ .map(
134
+ (b) =>
135
+ `${b.id} ${title(b).padEnd(24)} ${(b.blocked_on ? "blocked" : b.status).padEnd(10)} ${b.stage.padEnd(7)} ${b.domain ?? ""}`
136
+ )
137
+ .join("\n");
138
+ });
139
+ return 0;
140
+ }
141
+
142
+ function benchShow(ctx, result) {
143
+ printResult(ctx.io, ctx.flags, result, (r) => {
144
+ const b = r.bench;
145
+ const lines = [
146
+ `${title(b)} — ${b.status}, stage ${b.stage}`,
147
+ ...(b.spec ? [` ${b.spec.tagline}`] : []),
148
+ ...(b.blocked_on ? [` Blocked: ${b.blocked_on}`, ` Then: bench advance ${b.id} --retry`] : []),
149
+ ...(b.stage_note && !b.blocked_on ? [` ${b.stage_note}`] : []),
150
+ ...(b.domain
151
+ ? [` Domain ${b.domain}${b.domain_decision?.source === "ai" ? " (chosen and bought)" : ""}`]
152
+ : []),
153
+ ...(b.repo_url ? [` Repo ${b.repo_url}`] : []),
154
+ ...(b.site_url
155
+ ? [` Site ${b.site_url}${b.site_ok === false ? " (not serving at the last check)" : ""}`]
156
+ : []),
157
+ ...(b.run_id ? [` Run ${b.run_id} (repo show ${b.run_id})`] : []),
158
+ ...(b.next_run_at && b.status === "live" ? [` Next run ${b.next_run_at}`] : []),
159
+ ];
160
+ if (b.results) {
161
+ lines.push("", `Results (${b.results.ran_at}): ${b.results.summary}`);
162
+ }
163
+ const board = r.citation?.leaderboard ?? [];
164
+ for (const row of board) {
165
+ lines.push(
166
+ ` ${String(row.rank ?? "–").padStart(2)} ${row.name.padEnd(24)} ${row.value ?? "—"} ${row.status === "ok" ? "" : row.status}`
167
+ );
168
+ }
169
+ if (r.run) lines.push("", `Started run ${r.run.id}: repo show ${r.run.id}`);
170
+ if (typeof r.linked === "boolean") {
171
+ lines.push("", r.linked ? "The letterbase cites and links it now." : "Linked once the bench is live.");
172
+ }
173
+ if (r.events?.length) {
174
+ lines.push("", "Recent:");
175
+ for (const e of r.events.slice(0, 8)) lines.push(` ${e.created_at} ${e.message}`);
176
+ }
177
+ return lines.join("\n");
178
+ });
179
+ return 0;
180
+ }
181
+
182
+ async function benchCite(ctx) {
183
+ const result = await call(ctx, "get_bench_citation");
184
+ printResult(ctx.io, ctx.flags, result, (r) => r.citation.cite_as);
185
+ return 0;
186
+ }
187
+
188
+ async function benchReplicate(ctx) {
189
+ const result = await call(ctx, "get_bench");
190
+ printResult(ctx.io, ctx.flags, result, (r) => r.replication ?? "No instructions yet: the spec isn't drafted.");
191
+ return 0;
192
+ }
@@ -16,6 +16,10 @@
16
16
  // letterstory sim run <run-id> [--watch]
17
17
  // letterstory sim run-start <simulation-id> --task "Find our open deals over $10k" [--truth "..."] [--watch]
18
18
  // letterstory sim run-stop <run-id>
19
+ // letterstory sim create --name "Acme" --spec-url https://acme.com/openapi.json --sample-key-file key.txt
20
+ // letterstory sim create --name "Acme" --mcp-url https://mcp.acme.com --sample-key-file key.txt
21
+ // letterstory sim sample-key <id> --keep | --delete
22
+ // letterstory sim resample <id> [--sample-key-file key.txt]
19
23
  // letterstory sim report <id> --since 7d
20
24
  // letterstory sim sessions <id>
21
25
  // letterstory sim session <session-id>
@@ -28,6 +32,26 @@ import { sinceDays } from "./visits.mjs";
28
32
  const RULES = ["synthesize", "forward", "sink", "refuse", "inferred"];
29
33
  const simulationId = { positional: 0, label: "simulation-id", required: true };
30
34
 
35
+ /** The customer's key from a file, so it never sits in shell history (`--sample-key-file key.txt`). */
36
+ const sampleKey = {
37
+ value: (flags) => {
38
+ const path = flagStr(flags["sample-key-file"]);
39
+ if (!path) return undefined;
40
+ let key;
41
+ try {
42
+ key = readFileSync(path, "utf8").trim();
43
+ } catch {
44
+ throw new CliError(`could not read --sample-key-file ${path}`);
45
+ }
46
+ if (!key) throw new CliError(`--sample-key-file ${path} is empty`);
47
+ return key;
48
+ },
49
+ };
50
+ /** The customer's answer about keeping the sample key: --keep-key, --delete-key, or neither (held an hour). */
51
+ const keepKey = {
52
+ value: (flags) => (flags["keep-key"] === true ? true : flags["delete-key"] === true ? false : undefined),
53
+ };
54
+
31
55
  export const ARGS = {
32
56
  create_simulation: {
33
57
  name: { flag: "name", required: true },
@@ -65,6 +89,11 @@ export const ARGS = {
65
89
  tool_route: "tool-route",
66
90
  live: { flag: "live", type: "bool" },
67
91
  auth_header: "auth-header",
92
+ mcp_url: "mcp-url",
93
+ sample_credential: sampleKey,
94
+ sample_base_url: "sample-base-url",
95
+ sample_auth_header: "sample-header",
96
+ keep_sample_key: keepKey,
68
97
  },
69
98
  list_simulations: {},
70
99
  get_simulation: { simulation_id: simulationId },
@@ -73,6 +102,7 @@ export const ARGS = {
73
102
  daily_call_cap: { flag: "daily-calls", type: "num" },
74
103
  daily_session_cap: { flag: "daily-sessions", type: "num" },
75
104
  status: { flag: "status", enum: ["live", "paused"] },
105
+ keep_sample_key: keepKey,
76
106
  active_seed_id: {
77
107
  value: (flags) => {
78
108
  const v = flagStr(flags.use);
@@ -121,6 +151,7 @@ export const ARGS = {
121
151
  max_turns: { flag: "turns", type: "num" },
122
152
  },
123
153
  stop_simulation_run: { run_id: { positional: 0, label: "run-id", required: true } },
154
+ resample_simulation: { simulation_id: simulationId, sample_credential: sampleKey, keep_sample_key: keepKey },
124
155
  record_simulation_runs: {
125
156
  simulation_id: "simulation",
126
157
  suite: "suite",
@@ -196,7 +227,13 @@ export async function cmdSim(ctx) {
196
227
  case "ls":
197
228
  return simList(rest);
198
229
  case "create":
199
- refuseUnknownFlags(rest, ARGS.create_simulation, ["spec-file", "tools-file"]);
230
+ refuseUnknownFlags(rest, ARGS.create_simulation, [
231
+ "spec-file",
232
+ "tools-file",
233
+ "sample-key-file",
234
+ "keep-key",
235
+ "delete-key",
236
+ ]);
200
237
  return simShow(rest, await call(rest, "create_simulation"));
201
238
  case "show":
202
239
  return simShow(rest, await call(rest, "get_simulation"));
@@ -226,13 +263,30 @@ export async function cmdSim(ctx) {
226
263
  return simRun(rest);
227
264
  case "runs-import":
228
265
  return simRunsImport(rest);
266
+ case "sample-key": {
267
+ refuseUnknownFlags(rest, {}, ["keep", "delete"]);
268
+ if (rest.flags.keep !== true && rest.flags.delete !== true)
269
+ throw new CliError("Usage: sim sample-key <simulation-id> --keep | --delete");
270
+ const id = flagStr(rest.positionals[0]);
271
+ if (!id) throw new CliError("Usage: sim sample-key <simulation-id> --keep | --delete");
272
+ return simShow(
273
+ rest,
274
+ await rest.client.callTool("update_simulation", {
275
+ simulation_id: id,
276
+ keep_sample_key: rest.flags.keep === true,
277
+ })
278
+ );
279
+ }
280
+ case "resample":
281
+ refuseUnknownFlags(rest, ARGS.resample_simulation, ["sample-key-file", "keep-key", "delete-key"]);
282
+ return simShow(rest, await call(rest, "resample_simulation"));
229
283
  case "run-start":
230
284
  return simRunStart(rest);
231
285
  case "run-stop":
232
286
  return simRunStop(rest);
233
287
  default:
234
288
  throw new CliError(
235
- "Usage: sim [list|create|show|rule|pause|resume|limits|seed|key|sessions|session|report|runs|run|run-start|run-stop|runs-import]"
289
+ "Usage: sim [list|create|show|rule|pause|resume|limits|seed|key|sample-key|resample|sessions|session|report|runs|run|run-start|run-stop|runs-import]"
236
290
  );
237
291
  }
238
292
  }
@@ -264,6 +318,18 @@ function simShow(ctx, result) {
264
318
  ...(s.status === "paused"
265
319
  ? [" Paused: review the rules below, then `sim resume <id>` to let agents in."]
266
320
  : []),
321
+ ...(s.sample?.sampled_at
322
+ ? [
323
+ ` Sampled ${s.sample.operations} operations of the real product (${s.sample.calls} read-only calls; structure only, no real values)`,
324
+ ...(s.sample.key === "held"
325
+ ? [
326
+ ` Key held until ${s.sample.key_expires_at}: ask whether to keep it. Keep: \`sim sample-key ${s.id} --keep\`; delete now: \`sim sample-key ${s.id} --delete\`. Unanswered, it's deleted.`,
327
+ ]
328
+ : s.sample.key === "kept"
329
+ ? [` Key kept (encrypted): \`sim resample ${s.id}\` samples again.`]
330
+ : []),
331
+ ]
332
+ : []),
267
333
  "",
268
334
  "Resources (rule · side effect · who set it):",
269
335
  ];
package/lib/commands.mjs CHANGED
@@ -52,3 +52,4 @@ export * from "./commands/evals.mjs";
52
52
  export * from "./commands/visits.mjs";
53
53
  export * from "./commands/sim.mjs";
54
54
  export * from "./commands/vary.mjs";
55
+ export * from "./commands/bench.mjs";
package/lib/documents.mjs CHANGED
@@ -63,6 +63,8 @@ export const DOCUMENT_FLAG_PAIRS = [
63
63
  ["manifesto", "manifesto-file"],
64
64
  // A repo change's brief (repo.mjs `repo start`) — prose, so a .docx or PDF spec is fine.
65
65
  ["instructions", "instructions-file"],
66
+ // A bench's prompt (bench.mjs `bench create`): what the benchmark is and how it works, prose.
67
+ ["prompt", "prompt-file"],
66
68
  ];
67
69
 
68
70
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.175.10",
3
+ "version": "0.175.12",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",