@letterstory/cli 0.174.0 → 0.174.2

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
@@ -75,7 +75,7 @@ import {
75
75
  } from "./commands.mjs";
76
76
 
77
77
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
78
- export const VERSION = "0.174.0";
78
+ export const VERSION = "0.174.2";
79
79
 
80
80
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
81
81
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -88,10 +88,14 @@ export const BOOLEAN_FLAGS = new Set([
88
88
  "start",
89
89
  // site research-builds: run now even when the stored pass is under an hour old.
90
90
  "fresh",
91
+ // admin letterpress telemetry: every org, test and demo orgs included.
92
+ "all-orgs",
91
93
  // admin letterpress status | gaps: the customers' reading (no test or demo orgs).
92
94
  "customers",
93
95
  // build: repeat an open build's ask; post its progress in the org's Slack channel.
94
96
  "again",
97
+ // ask --web: read the web in the Plan's fit for a recipe the facts can't decide (off by default).
98
+ "web",
95
99
  "notify-slack",
96
100
  "remap",
97
101
  // site observations: each kind noticed, not the observations (keys_only).
@@ -5015,6 +5015,7 @@ const RECIPES = "/api/superadmin/recipes";
5015
5015
  /** The fields a recipe file carries: what import_recipes reads back. */
5016
5016
  const RECIPE_FILE_FIELDS = [
5017
5017
  "id",
5018
+ "kind",
5018
5019
  "name",
5019
5020
  "description",
5020
5021
  "recipe",
@@ -5025,7 +5026,7 @@ const RECIPE_FILE_FIELDS = [
5025
5026
  "variations",
5026
5027
  ];
5027
5028
  const RECIPES_USAGE =
5028
- "Usage: admin recipes list [--approach seo|geo|agent_conviction|inbound_conversion|outbound|other] | show <id|name> | runs <id|name> [--days 1..90] [--limit n] | vocab | stats | export [--out <file>] | import <file> [--dry-run] | save [<id>] [--file <recipe.json>] [--name …] [--description …] [--recipe …] [--when-to-use …] [--when-not-to-use …] [--weight 1..10] [--approaches seo,geo,…] | delete <id> --yes";
5029
+ "Usage: admin recipes list [--kind recipe|known_issue] [--approach seo|geo|agent_conviction|inbound_conversion|outbound|other] | show <id|name> | runs <id|name> [--days 1..90] [--limit n] | vocab | stats | export [--out <file>] | import <file> [--dry-run] | save [<id>] [--file <recipe.json>] [--kind recipe|known_issue] [--name …] [--description …] [--recipe …] [--when-to-use …] [--when-not-to-use …] [--weight 1..10] [--approaches seo,geo,…] | delete <id> --yes";
5029
5030
 
5030
5031
  const recipeForFile = (r) => Object.fromEntries(RECIPE_FILE_FIELDS.map((k) => [k, r[k]]));
5031
5032
 
@@ -5040,7 +5041,8 @@ const recipeVariations = (r) => [
5040
5041
 
5041
5042
  function recipeLine(r) {
5042
5043
  const more = r.variations?.length ? ` ${r.variations.length + 1} variations` : "";
5043
- return `${String(r.weight).padStart(2)}/10 ${r.name} [${recipeApproaches(r)}]${more} ${r.id}`;
5044
+ const kind = r.kind === "known_issue" ? " (known issue)" : "";
5045
+ return `${String(r.weight).padStart(2)}/10 ${r.name}${kind} [${recipeApproaches(r)}]${more} ${r.id}`;
5044
5046
  }
5045
5047
 
5046
5048
  function recipeDetail(r) {
@@ -5053,6 +5055,7 @@ function recipeDetail(r) {
5053
5055
  ];
5054
5056
  return [
5055
5057
  `${r.name} weight ${r.weight}/10 ${r.id}`,
5058
+ ` kind: ${r.kind === "known_issue" ? "known issue (Fix's list)" : "recipe (the Plan's)"}`,
5056
5059
  ` approaches: ${recipeApproaches(r)}`,
5057
5060
  ...(variations.length > 1
5058
5061
  ? variations.flatMap((v, i) => [` variation ${i + 1}: ${v.name}`, ...fields(v, " ")])
@@ -5086,6 +5089,7 @@ function recipeFromFlags(flags) {
5086
5089
  }
5087
5090
  return compact({
5088
5091
  ...compact(recipeForFile(base)),
5092
+ kind: flagStr(flags.kind),
5089
5093
  name: flagStr(flags.name),
5090
5094
  description: flagStr(flags.description),
5091
5095
  recipe: flagStr(flags.recipe),
@@ -5102,8 +5106,9 @@ function recipeFromFlags(flags) {
5102
5106
 
5103
5107
  const ENGINE = "/api/superadmin/engine-settings";
5104
5108
  const LETTERPRESS = "/api/superadmin/letterpress";
5109
+ const CODING_TELEMETRY = "/api/superadmin/coding-telemetry";
5105
5110
  const ENGINE_USAGE =
5106
- "Usage: admin letterpress status | gaps | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5111
+ "Usage: admin letterpress status | gaps | telemetry [--days N] [--harness h] [--all-orgs] | runs [--status s] [--error-code c] [--pr merged|closed|open|none] [--harness h] [--days N] | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5107
5112
 
5108
5113
  /** One number of the settings from a dotted path and a value: the PUT body save_engine_settings reads. */
5109
5114
  function engineSettingsPatch(path, value) {
@@ -5214,10 +5219,73 @@ async function cmdAdminLetterpress(ctx) {
5214
5219
  ? `asks from: ${s.surfaces.map((x) => `${x.surface} ${x.runs}`).join(", ")}`
5215
5220
  : "no runs yet",
5216
5221
  `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]" : ""}`,
5222
+ ...(s.harness_evals ?? []).map(
5223
+ (p) =>
5224
+ `harness eval ${p.at.slice(0, 10)} (${p.version}, ${p.pairs} pairs): ${p.harnesses
5225
+ .map(
5226
+ (h) =>
5227
+ `${h.harness} ${h.checks_passed}/${h.checks_total} checks, ${h.succeeded}/${h.tasks} succeeded${h.median_cost_usd !== null ? `, $${h.median_cost_usd.toFixed(2)}` : ""}${h.median_agent_minutes !== null ? `, ${h.median_agent_minutes.toFixed(1)} min` : ""}`
5228
+ )
5229
+ .join("; ")}; judge ${p.judge.wins}–${p.judge.losses}–${p.judge.ties}`
5230
+ ),
5231
+ ].join("\n")
5232
+ );
5233
+ return 0;
5234
+ }
5235
+ case "telemetry": {
5236
+ // get_coding_telemetry with fleet: the coding agent's numbers (docs/architecture/coding-telemetry.md).
5237
+ const q = new URLSearchParams({ view: "summary", days: String(flags.days ?? 7) });
5238
+ if (flags.harness) q.set("harness", String(flags.harness));
5239
+ if (flagBool(flags["all-orgs"])) q.set("customers", "0");
5240
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5241
+ const pct = (x) => (x.rate == null ? "—" : `${Math.round(100 * x.rate)}% (${x.hits}/${x.n})`);
5242
+ const usd = (v) => (v == null ? "—" : `$${v.toFixed(2)}`);
5243
+ const min = (v) => (v == null ? "—" : `${(v / 60_000).toFixed(1)}m`);
5244
+ printResult(io, flags, r, (t) =>
5245
+ [
5246
+ `Coding agent, last ${t.days} days${t.customer_only ? " (customers only)" : ""}: ${t.all.runs} runs (${t.previous.runs} the period before)`,
5247
+ ...[t.all, ...t.by_harness].map(
5248
+ (h) =>
5249
+ `${h.harness.padEnd(13)} ${String(h.runs).padStart(4)} runs first-try merge ${pct(h.first_try_merge)} failed ${pct(h.failed)} per merged PR ${usd(h.cost.per_merged_pr_usd)} agent ${min(h.time.agent_ms.p50)}`
5250
+ ),
5251
+ t.moved.length
5252
+ ? `moved beyond chance: ${t.moved.map((m) => `${m.measure} ${m.direction}`).join(", ")}`
5253
+ : "nothing moved beyond chance",
5254
+ t.failures.length
5255
+ ? `failures: ${t.failures.map((f) => `${f.error_code} ${f.count} (was ${f.previous}, ${f.fault})`).join(", ")}`
5256
+ : "no failures",
5257
+ `lost to timeouts/memory/crashes: ${pct(t.resilience)}${t.resilience.over_bar ? " OVER 3%" : ""}`,
5217
5258
  ].join("\n")
5218
5259
  );
5219
5260
  return 0;
5220
5261
  }
5262
+ case "runs": {
5263
+ // list_coding_runs with fleet.
5264
+ const q = new URLSearchParams({
5265
+ view: "runs",
5266
+ days: String(flags.days ?? 30),
5267
+ limit: String(flags.limit ?? 50),
5268
+ });
5269
+ for (const [flag, key] of [
5270
+ ["status", "status"],
5271
+ ["error-code", "error_code"],
5272
+ ["harness", "harness"],
5273
+ ["pr", "pr"],
5274
+ ])
5275
+ if (flags[flag]) q.set(key, String(flags[flag]));
5276
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5277
+ printResult(io, flags, r, (x) =>
5278
+ x.runs.length
5279
+ ? x.runs
5280
+ .map(
5281
+ (run) =>
5282
+ `${run.started_at.slice(0, 16)} ${run.harness.padEnd(13)} ${(run.status === "failed" ? (run.error_code ?? "failed") : run.status).padEnd(16)} pr ${run.pr.padEnd(6)} $${run.cost_usd.toFixed(2).padStart(6)} ${run.org_name ?? run.org_id} ${run.id}`
5283
+ )
5284
+ .join("\n")
5285
+ : "No runs match."
5286
+ );
5287
+ return 0;
5288
+ }
5221
5289
  case "gaps": {
5222
5290
  const r = await staffRequest(
5223
5291
  ctx,
@@ -5325,9 +5393,12 @@ async function cmdAdminRecipes(ctx) {
5325
5393
  }
5326
5394
  case "list": {
5327
5395
  const approach = flagStr(flags.approach);
5328
- const recipes = approach
5329
- ? ((await staffRequest(ctx, "GET", `${RECIPES}?approach=${encodeURIComponent(approach)}`)).recipes ??
5330
- [])
5396
+ const kind = flagStr(flags.kind);
5397
+ const query = new URLSearchParams();
5398
+ if (approach) query.set("approach", approach);
5399
+ if (kind) query.set("kind", kind);
5400
+ const recipes = query.size
5401
+ ? ((await staffRequest(ctx, "GET", `${RECIPES}?${query}`)).recipes ?? [])
5331
5402
  : await all();
5332
5403
  printResult(io, flags, { recipes }, (r) =>
5333
5404
  r.recipes.length ? r.recipes.map(recipeLine).join("\n") : "No recipes yet."
@@ -13,13 +13,15 @@ export const ARGS = {
13
13
  outcome: "outcome",
14
14
  lens: "lens",
15
15
  words: { value: (flags, positionals) => flagStr(flags.words) ?? (positionals.join(" ").trim() || undefined) },
16
+ // --web: read the web for a recipe the facts can't decide (off by default: facts only).
17
+ web: { flag: "web", type: "bool" },
16
18
  domain: "site",
17
19
  },
18
20
  };
19
21
 
20
22
  export async function cmdAsk(ctx) {
21
23
  const { client, flags, io } = ctx;
22
- refuseUnknownFlags(ctx, {}, ["outcome", "lens", "words", "site"]);
24
+ refuseUnknownFlags(ctx, {}, ["outcome", "lens", "words", "site", "web"]);
23
25
  const args = argsFromFlags(ARGS.ask_letterpress, flags, ctx.positionals, {});
24
26
  if ([args.outcome, args.lens, args.words].filter(Boolean).length > 1)
25
27
  throw new CliError("One ask at a time: --outcome, --lens fix|build, or your words.");
@@ -26,6 +26,8 @@ const ARGS = {
26
26
  notify_slack: { flag: "notify-slack", type: "bool" },
27
27
  harness: { flag: "harness", enum: ["claude-code", "letterpress-1"] },
28
28
  again: { flag: "again", type: "bool" },
29
+ // --recipe <id>: the recipe the build carries out (a Plan row's), recorded on it.
30
+ recipe: "recipe",
29
31
  },
30
32
  send_build_message: {
31
33
  message: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.174.0",
3
+ "version": "0.174.2",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",