@letterstory/cli 0.176.7 → 0.176.9

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
@@ -80,7 +80,7 @@ import {
80
80
  import { fetchParkedSections, withoutParked } from "./parked.mjs";
81
81
 
82
82
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
83
- export const VERSION = "0.176.7";
83
+ export const VERSION = "0.176.9";
84
84
 
85
85
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
86
86
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -994,6 +994,12 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
994
994
  how runs grounded (a recipe / none). Needs recipes:read.
995
995
  admin letterpress gaps [--customers] The gaps the numbers show, each with the one call that
996
996
  addresses it, pre-filled. Needs recipes:read.
997
+ admin letterpress decisions <org-id> [--site <host>] [--surface plan|fix|build|site]
998
+ Everything set aside on one account's site: what Letter
999
+ withheld (it cannot do it here) and what a person dismissed,
1000
+ each with who, when, until when and its id. Needs recipes:read.
1001
+ admin letterpress undo <org-id> <host> <decision-id> Take one decision back: a withhold shown anyway, a dismissal
1002
+ undone. Needs recipes:write.
997
1003
  admin letterpress replay <run-id> A Build or Fix run through today's checks and settings, no
998
1004
  model: what it would keep, drop and rank against what it
999
1005
  showed; --json carries the run as an evals case.
@@ -5144,7 +5144,7 @@ const ENGINE = "/api/superadmin/engine-settings";
5144
5144
  const LETTERPRESS = "/api/superadmin/letterpress";
5145
5145
  const CODING_TELEMETRY = "/api/superadmin/coding-telemetry";
5146
5146
  const ENGINE_USAGE =
5147
- "Usage: admin letterpress status | gaps | telemetry [--days N] [--harness h] [--all-orgs] | blocked [--days N] [--org id] [--all-orgs] | unblock <org-id> <host> <subject> | runs [--status s] [--error-code c] [--first-review-cause agent|context|setup|unknown] [--pr merged|closed|open|none] [--harness h] [--days N] | beyond [--limit N] [--before ISO] | companies | company <org-id> [--site host] | facts <org-id> [--site host] | fits [--recipe id] [--org id] [--site host] [--fits yes|no|unknown|waiting] [--limit N] | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|gap|recipe|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|preflight.off|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5147
+ "Usage: admin letterpress status | gaps | telemetry [--days N] [--harness h] [--all-orgs] | blocked [--days N] [--org id] [--all-orgs] | unblock <org-id> <host> <subject> | decisions <org-id> [--site host] [--surface plan|fix|build|site] | undo <org-id> <host> <decision-id> | runs [--status s] [--error-code c] [--first-review-cause agent|context|setup|unknown] [--pr merged|closed|open|none] [--harness h] [--days N] | beyond [--limit N] [--before ISO] | companies | company <org-id> [--site host] | facts <org-id> [--site host] | fits [--recipe id] [--org id] [--site host] [--fits yes|no|unknown|waiting] [--limit N] | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|gap|recipe|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|preflight.off|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5148
5148
 
5149
5149
  /** One number of the settings from a dotted path and a value: the PUT body save_engine_settings reads. */
5150
5150
  function engineSettingsPatch(path, value) {
@@ -5349,6 +5349,44 @@ async function cmdAdminLetterpress(ctx) {
5349
5349
  );
5350
5350
  return 0;
5351
5351
  }
5352
+ case "decisions": {
5353
+ // list_decisions: everything set aside on one account's site (docs/architecture/decisions.md).
5354
+ const [orgId] = positionals.slice(1);
5355
+ if (!orgId) throw new CliError("Usage: admin letterpress decisions <org-id> [--site host] [--surface s]");
5356
+ const q = new URLSearchParams({ view: "decisions", org_id: orgId });
5357
+ if (flags.site) q.set("host", String(flags.site));
5358
+ if (flags.surface) q.set("surface", String(flags.surface));
5359
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5360
+ printResult(io, flags, r, (d) =>
5361
+ !d.host
5362
+ ? "No site: the organization has no website yet."
5363
+ : d.decisions.length
5364
+ ? [
5365
+ `Set aside on ${d.host}: ${d.decisions.length}`,
5366
+ ...d.decisions.map(
5367
+ (x) =>
5368
+ ` ${x.id}
5369
+ ${x.kind === "withheld" ? "Letter set aside" : "Dismissed"} (${x.surface}${x.code ? `, ${x.code}` : ""}) ${x.title}
5370
+ ${x.say}${x.next ? ` ${x.next}` : ""}${x.at ? ` since ${x.at.slice(0, 10)}` : ""}${x.until ? `, lifts ${x.until.slice(0, 10)}` : ""}`
5371
+ ),
5372
+ "",
5373
+ `Take one back: admin letterpress undo ${orgId} ${d.host} <decision-id>`,
5374
+ ].join("\n")
5375
+ : `Nothing is set aside on ${d.host}.`
5376
+ );
5377
+ return 0;
5378
+ }
5379
+ case "undo": {
5380
+ // undo_decision: one decision back, by its id.
5381
+ const [orgId, host, id] = positionals.slice(1);
5382
+ if (!orgId || !host || !id)
5383
+ throw new CliError("Usage: admin letterpress undo <org-id> <host> <decision-id>");
5384
+ const r = await staffRequest(ctx, "POST", CODING_TELEMETRY, { org_id: orgId, host, id });
5385
+ printResult(io, flags, r, (x) =>
5386
+ x.undone ? "Taken back: it is offered and allowed to start again." : "Nothing was holding."
5387
+ );
5388
+ return 0;
5389
+ }
5352
5390
  case "runs": {
5353
5391
  // list_coding_runs with fleet.
5354
5392
  const q = new URLSearchParams({
@@ -314,10 +314,8 @@ async function buildFollow(ctx) {
314
314
  );
315
315
  }
316
316
  }
317
- const working =
318
- build.status === "building" ||
319
- build.steps.some((s) => s.run_id && !ended.has(s.run_id) && s.lane === "building");
320
- return { done: !working, value: build };
317
+ // Still at work is the server's reading of the build (rowStateOf), never worked out from lanes here.
318
+ return { done: build.reading?.state !== "building", value: build };
321
319
  };
322
320
  let { done, value: build } = await tick();
323
321
  if (!done) ({ value: build } = await followJob(io, tick, { intervalMs: 5000, ceilingMs: 2 * 60 * 60 * 1000 }));
@@ -283,12 +283,12 @@ function autoMergeHours(value) {
283
283
  return Number(match[1]) * (match[2]?.startsWith("d") ? 24 : 1);
284
284
  }
285
285
 
286
- const TERMINAL = new Set(["succeeded", "no_changes", "failed", "cancelled"]);
286
+ /** Where a change stands, in the word every surface shows (the server's `state`, changeStateOf). */
287
+ const stateWord = (run) => run.state?.label ?? "Unknown";
287
288
 
288
289
  function describe(run) {
289
- const lines = [
290
- `${run.id} ${run.repo}@${run.baseBranch} ${run.status} (${run.phase}) $${run.costUsd.toFixed(2)}`,
291
- ];
290
+ const lines = [`${run.id} ${run.repo}@${run.baseBranch} ${stateWord(run)} $${run.costUsd.toFixed(2)}`];
291
+ if (run.state?.detail) lines.push(` ${run.state.detail}`);
292
292
  if (run.preview?.url) lines.push(` Preview: ${run.preview.url}`);
293
293
  for (const [i, change] of (run.preview?.changes ?? []).entries())
294
294
  lines.push(` ${i + 1}. ${change.path} ${change.note}${change.url ? ` ${change.url}` : ""}`);
@@ -298,8 +298,8 @@ function describe(run) {
298
298
  lines.push(` Make PR: letterstory repo publish ${run.id}`);
299
299
  lines.push(` Ask for more: letterstory repo revise ${run.id} --instructions "…"`);
300
300
  }
301
- if (run.prUrl) lines.push(` PR: ${run.prUrl} (${run.prState ?? "state unknown"})`);
302
- if (run.prState === "open") lines.push(` Merge: letterstory repo merge ${run.id}`);
301
+ if (run.prUrl) lines.push(` PR: ${run.prUrl}`);
302
+ if (run.state?.phase === "pr_open") lines.push(` Merge: letterstory repo merge ${run.id}`);
303
303
  if (run.errorCode) lines.push(` Error (${run.errorCode}): ${run.errorDetail ?? ""}`);
304
304
  if (run.summary) lines.push(...run.summary.split("\n").map((l) => ` ${l}`));
305
305
  return lines.join("\n");
@@ -308,9 +308,9 @@ function describe(run) {
308
308
  /** A list row (list_repo_changes' brief default): what was asked, where it is, its PR and preview. */
309
309
  function describeBrief(run) {
310
310
  if (!("title" in run)) return describe(run);
311
- const lines = [`${run.id} ${run.repo} ${run.status} (${run.phase}) $${run.costUsd.toFixed(2)} ${run.title}`];
311
+ const lines = [`${run.id} ${run.repo} ${stateWord(run)} $${run.costUsd.toFixed(2)} ${run.title}`];
312
312
  if (run.previewUrl) lines.push(` Preview: ${run.previewUrl}`);
313
- if (run.prUrl) lines.push(` PR: ${run.prUrl} (${run.prState ?? "state unknown"})`);
313
+ if (run.prUrl) lines.push(` PR: ${run.prUrl}`);
314
314
  if (run.errorCode) lines.push(` Error: ${run.errorCode}`);
315
315
  return lines.join("\n");
316
316
  }
@@ -462,19 +462,19 @@ async function repoStart(ctx) {
462
462
  io,
463
463
  async () => {
464
464
  const polled = await client.callTool("get_repo_change", { run_id: started.run.id });
465
- ok(ctx, `… ${polled.run.status} (${polled.run.phase})`);
465
+ ok(ctx, `… ${stateWord(polled.run)}`);
466
466
  return { done: settledFor(polled.run), value: polled.run };
467
467
  },
468
468
  { intervalMs: 30000, ceilingMs: 60 * 60 * 1000 }
469
469
  );
470
470
  if (!settled) ok(ctx, `Still running; check later with: letterstory repo status ${started.run.id}`);
471
471
  printResult(io, flags, value, describe);
472
- return value.status === "failed" ? 1 : 0;
472
+ return value.state?.phase === "failed" ? 1 : 0;
473
473
  }
474
474
 
475
- /** --wait stops at a terminal state, or at review: a preview waits on a person, not on time. */
475
+ /** --wait stops once nothing is being built: a preview or a PR waits on a person, not on time. */
476
476
  function settledFor(run) {
477
- return TERMINAL.has(run.status) || run.phase === "review";
477
+ return !!run.state && run.state.phase !== "building";
478
478
  }
479
479
 
480
480
  async function followRun(ctx, run) {
@@ -483,14 +483,14 @@ async function followRun(ctx, run) {
483
483
  io,
484
484
  async () => {
485
485
  const polled = await client.callTool("get_repo_change", { run_id: run.id });
486
- ok(ctx, `… ${polled.run.status} (${polled.run.phase})`);
486
+ ok(ctx, `… ${stateWord(polled.run)}`);
487
487
  return { done: settledFor(polled.run), value: polled.run };
488
488
  },
489
489
  { intervalMs: 30000, ceilingMs: 60 * 60 * 1000 }
490
490
  );
491
491
  if (!settled) ok(ctx, `Still running; check later with: letterstory repo status ${run.id}`);
492
492
  printResult(io, flags, value, describe);
493
- return value.status === "failed" ? 1 : 0;
493
+ return value.state?.phase === "failed" ? 1 : 0;
494
494
  }
495
495
 
496
496
  /** `repo fix-audit --issue <type> [--audit <id>] [--wait]`: one audit issue → one PR, in the repo verified to build the site. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.176.7",
3
+ "version": "0.176.9",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",