@letterstory/cli 0.82.3 → 0.82.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
@@ -57,7 +57,7 @@ import {
57
57
  } from "./commands.mjs";
58
58
 
59
59
  // Keep in sync with cli/package.json.
60
- export const VERSION = "0.82.3";
60
+ export const VERSION = "0.82.4";
61
61
 
62
62
  // Flags that never take a value. Listing them explicitly means `deploy get --json <id>`
63
63
  // can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
@@ -639,6 +639,21 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
639
639
  Replay a breakthrough live now (background; poll
640
640
  admin replays). With neither, the client's newest
641
641
  breakthrough. Needs fleet:replay.
642
+ admin fleet-experiments list Fleet experiments (sites, collections, single posts)
643
+ with each arm's rate per AI, before vs after.
644
+ | articles [--experiment <id>] [--org <uuid>] [--filter all|assigned|unassigned] [--arm <arm>] [--q …]
645
+ Posts on independent sites that name the client,
646
+ with the paragraphs that name it and the live URL.
647
+ | mark <experiment-id> <article-id…> --arm <arm> | unmark <experiment-id> <article-id…>
648
+ | new --template sponsor_disclosure_v1|sponsor_disclosure_clients_v1|article_disclosure_v1|mention_degree_v1|citation_shape_v1
649
+ | new --spec-file spec.json A custom experiment ({key, hypothesis, unit, arms, response_var}).
650
+ | assign <experiment-id> <unit-id…> | assign-eligible <experiment-id> | apply <experiment-id>
651
+ | assign-orgs <experiment-id> <org-domain-or-id…>
652
+ Site/collection arms (safe mode: our own sites, or one
653
+ site per named client). A running experiment applies
654
+ each new unit's arm at once; start applies them all.
655
+ | start|stop <experiment-id> | decide <experiment-id> --decision "…"
656
+ Reads need fleet:read; writes fleet:experiment.
642
657
  admin experiments list [--q colons] [--status proposed] [--primitive write] [--stage rarity] | show <id>
643
658
  | new "<what you are investigating>" [--primitive write|research|shred|enhance] [--stages a,b]
644
659
  [--hypothesis …] [--plan-file p.json] [--tags a,b] [--as "<agent>"]
@@ -12,6 +12,7 @@
12
12
  // (feedback-add --fix "…" files the reader's rewrite; the diff is classified and a disposition suggested.
13
13
  // The old names — evals, eval-add, eval-set, proposals, propose-eval, capture-eval, reject-eval — still work.)
14
14
  // admin evals scoreboard|cases|runs|run|triage|guard|retire … (fleet:read / tuning:experiment)
15
+ // admin fleet-experiments list|articles|mark|unmark|new|assign|assign-eligible|assign-orgs|apply|start|stop|decide … (fleet:read / fleet:experiment)
15
16
  // admin crm import|capture|signals|record|signal|accounts|account|score|slack-channels|link-slack|white-glove|set-white-glove|churn|record-churn|undo-churn|onboard|onboarding|retry-onboarding|onboard-plan|payment-link … (crm:read / crm:write)
16
17
  // admin spend summary|reconcile|pnl|entries|add|import|usage|remove|reference|stripe-sync|services|service … (spend:read / spend:write)
17
18
  // admin replays [--org <id>] [--target <id>] [--status …] [--limit n] (fleet:read)
@@ -3346,6 +3347,176 @@ async function cmdAdminSpend(ctx) {
3346
3347
  }
3347
3348
  }
3348
3349
 
3350
+ const FLEET_EXPERIMENTS = "/api/superadmin/experiments";
3351
+
3352
+ function pct(rate) {
3353
+ return rate && rate.asks > 0 ? `${Math.round(rate.point * 100)}% (${rate.hits}/${rate.asks})` : "no answers yet";
3354
+ }
3355
+
3356
+ function signedPoints(value) {
3357
+ if (value === null || value === undefined) return "not enough yet";
3358
+ const r = Number((value * 100).toFixed(1));
3359
+ return `${r > 0 ? "+" : r < 0 ? "-" : ""}${Math.abs(r).toFixed(1)} pts`;
3360
+ }
3361
+
3362
+ const READOUT_OUTCOMES = [
3363
+ ["cited", "cited when probed"],
3364
+ ["namedWhenCited", "client named when cited"],
3365
+ ["reads", "read by the AI"],
3366
+ ];
3367
+
3368
+ function fleetExperimentLines(e) {
3369
+ const lines = [`${e.id} ${e.key} [${e.status}] per ${e.unit} → ${e.responseVar}`, ` ${e.hypothesis}`];
3370
+ for (const arm of e.armStats ?? []) {
3371
+ const live = arm.live !== undefined ? `, ${arm.live} live` : "";
3372
+ lines.push(` ${arm.arm}: ${arm.units} unit${arm.units === 1 ? "" : "s"}${live} · after ${pct(arm.rate)}`);
3373
+ }
3374
+ const r = e.articleReadout;
3375
+ if (r) {
3376
+ for (const s of r.surfaces) {
3377
+ lines.push(` ${s.label}:`);
3378
+ for (const [key, title] of READOUT_OUTCOMES) {
3379
+ const arms = s.arms.map((a) => `${a.arm} ${pct(a[key].before)} → ${pct(a[key].after)}`).join("; ");
3380
+ const effects = s.effects
3381
+ .map((x) => `${x.arm} vs ${r.referenceArm} ${signedPoints(x[key])}`)
3382
+ .join("; ");
3383
+ lines.push(` ${title}: ${arms}${effects ? ` | ${effects}` : ""}`);
3384
+ }
3385
+ }
3386
+ }
3387
+ if (e.decision) lines.push(` decision: ${e.decision}`);
3388
+ return lines.join("\n");
3389
+ }
3390
+
3391
+ function mentionedArticleLines(a) {
3392
+ const state = a.assignment
3393
+ ? a.assignment.changedSinceApplied
3394
+ ? ", republished mid-test"
3395
+ : a.assignment.appliedAt
3396
+ ? `, live since ${a.assignment.appliedAt.slice(0, 10)}`
3397
+ : ", starts with the experiment"
3398
+ : "";
3399
+ const arm = a.assignment
3400
+ ? ` [${a.assignment.arm}${state}]`
3401
+ : a.ineligible
3402
+ ? ` [can't join: ${a.ineligible}]`
3403
+ : "";
3404
+ const lines = [
3405
+ `${a.articleId} ${a.orgName} · ${a.title}${arm}`,
3406
+ ` ${a.url ?? "(no live URL)"} · ${a.mentionCount} mention${a.mentionCount === 1 ? "" : "s"} · cited in ${a.citedAnswers} answer${a.citedAnswers === 1 ? "" : "s"}${a.probed ? " · page-probed" : ""}`,
3407
+ ];
3408
+ for (const p of a.passages) lines.push(` > ${p.text}`);
3409
+ if (a.passageTotal > a.passages.length) lines.push(` … ${a.passageTotal - a.passages.length} more`);
3410
+ return lines.join("\n");
3411
+ }
3412
+
3413
+ /**
3414
+ * `admin fleet-experiments …` — the fleet experiment registry and the client-mention
3415
+ * worklist: the headless half of /superadmin/experiments. Reads need `fleet:read` on the
3416
+ * staff key, writes `fleet:experiment`. (`admin experiments` is the kernel tuning ledger.)
3417
+ */
3418
+ async function cmdAdminFleetExperiments(ctx) {
3419
+ const [sub, id, ...rest] = ctx.positionals;
3420
+ const { flags, io } = ctx;
3421
+ const json = flagBool(flags.json);
3422
+ const out = (result, line) => (json ? printResult(io, flags, result) : io.log(line(result)));
3423
+ const action = (body) => staffRequest(ctx, "POST", FLEET_EXPERIMENTS, body);
3424
+ switch (sub) {
3425
+ case "list":
3426
+ return out(await staffRequest(ctx, "GET", FLEET_EXPERIMENTS), (r) =>
3427
+ r.experiments.length ? r.experiments.map(fleetExperimentLines).join("\n\n") : "(no experiments)"
3428
+ );
3429
+ case "articles": {
3430
+ const params = new URLSearchParams(
3431
+ compact({
3432
+ experiment_id: flagStr(flags.experiment),
3433
+ org_id: flagStr(flags.org),
3434
+ filter: flagStr(flags.filter),
3435
+ arm: flagStr(flags.arm),
3436
+ q: flagStr(flags.q),
3437
+ limit: flagStr(flags.limit),
3438
+ offset: flagStr(flags.offset),
3439
+ })
3440
+ );
3441
+ return out(await staffRequest(ctx, "GET", `${FLEET_EXPERIMENTS}/articles?${params}`), (r) => {
3442
+ const head = `${r.total} post${r.total === 1 ? "" : "s"} name the client (showing ${r.articles.length} from ${r.offset})${r.unaudited ? `; ${r.unaudited} unaudited` : ""}`;
3443
+ return [head, ...r.articles.map(mentionedArticleLines)].join("\n\n");
3444
+ });
3445
+ }
3446
+ case "mark":
3447
+ case "unmark": {
3448
+ const articleIds = rest.filter(Boolean);
3449
+ const arm = sub === "unmark" ? null : flagStr(flags.arm);
3450
+ if (!id || articleIds.length === 0 || (sub === "mark" && !arm))
3451
+ throw new CliError(
3452
+ `Usage: admin fleet-experiments ${sub} <experiment-id> <article-id> [<article-id> …]${sub === "mark" ? " --arm <arm>" : ""}`
3453
+ );
3454
+ const result = await staffRequest(ctx, "PATCH", `${FLEET_EXPERIMENTS}/articles`, {
3455
+ experiment_id: id,
3456
+ article_ids: articleIds,
3457
+ arm,
3458
+ });
3459
+ return out(
3460
+ result,
3461
+ (r) => `assigned ${r.assigned}, moved ${r.moved}, unchanged ${r.unchanged}, cleared ${r.cleared}`
3462
+ );
3463
+ }
3464
+ case "new": {
3465
+ const template = flagStr(flags.template);
3466
+ const specFile = flagStr(flags["spec-file"]);
3467
+ if (!template && !specFile)
3468
+ throw new CliError(
3469
+ "Usage: admin fleet-experiments new --template sponsor_disclosure_v1|sponsor_disclosure_clients_v1|article_disclosure_v1|mention_degree_v1|citation_shape_v1 | --spec-file spec.json"
3470
+ );
3471
+ const body = template
3472
+ ? { action: "create_template", template }
3473
+ : { action: "create", experiment: JSON.parse(readFileSync(specFile, "utf8")) };
3474
+ return out(await action(body), (r) => `created ${r.experiment_id}`);
3475
+ }
3476
+ case "assign":
3477
+ case "assign-eligible":
3478
+ case "assign-orgs":
3479
+ case "apply": {
3480
+ const ids = rest.filter(Boolean);
3481
+ if (!id || ((sub === "assign" || sub === "assign-orgs") && ids.length === 0))
3482
+ throw new CliError(
3483
+ `Usage: admin fleet-experiments ${sub} <experiment-id>${sub === "assign" ? " <unit-id…>" : sub === "assign-orgs" ? " <org-domain-or-id…>" : ""}`
3484
+ );
3485
+ const body =
3486
+ sub === "assign"
3487
+ ? { action: "assign", experiment_id: id, unit_ids: ids }
3488
+ : sub === "assign-orgs"
3489
+ ? { action: "assign_orgs", experiment_id: id, orgs: ids }
3490
+ : { action: sub === "apply" ? "apply" : "assign_eligible", experiment_id: id };
3491
+ return out(await action(body), (r) => {
3492
+ const lines = [];
3493
+ if (r.assigned !== undefined) lines.push(`assigned ${r.assigned}, already in ${r.skipped}`);
3494
+ if (r.applied)
3495
+ lines.push(
3496
+ `applied ${r.applied.applied}, unchanged ${r.applied.unchanged}, failed ${r.applied.failed.length}`
3497
+ );
3498
+ for (const f of r.applied?.failed ?? []) lines.push(` ${f.unitId} (${f.arm}): ${f.message}`);
3499
+ for (const k of r.skippedOrgs ?? []) lines.push(` skipped ${k.orgId}: ${k.reason}`);
3500
+ return lines.join("\n") || "ok";
3501
+ });
3502
+ }
3503
+ case "start":
3504
+ case "stop":
3505
+ if (!id) throw new CliError(`Usage: admin fleet-experiments ${sub} <experiment-id>`);
3506
+ return out(await action({ action: sub, experiment_id: id }), (r) => `${id} is ${r.status}`);
3507
+ case "decide": {
3508
+ const decision = flagStr(flags.decision);
3509
+ if (!id || !decision)
3510
+ throw new CliError('Usage: admin fleet-experiments decide <experiment-id> --decision "<readout>"');
3511
+ return out(await action({ action: "decide", experiment_id: id, decision }), (r) => `${id} is ${r.status}`);
3512
+ }
3513
+ default:
3514
+ throw new CliError(
3515
+ 'Usage: admin fleet-experiments list | articles [--experiment <id>] [--org <id>] [--filter all|assigned|unassigned] [--arm <arm>] [--q …] [--limit n] [--offset n] | mark <experiment-id> <article-id…> --arm <arm> | unmark <experiment-id> <article-id…> | new --template <key> | start|stop <experiment-id> | decide <experiment-id> --decision "…"'
3516
+ );
3517
+ }
3518
+ }
3519
+
3349
3520
  export async function cmdAdmin(ctx) {
3350
3521
  const sub = ctx.positionals[0];
3351
3522
  if (sub === "replays" || sub === "replay")
@@ -3355,11 +3526,12 @@ export async function cmdAdmin(ctx) {
3355
3526
  if (sub === "create-org") return cmdAdminCreateOrg({ ...ctx, positionals: ctx.positionals.slice(1) });
3356
3527
  if (sub === "ask") return cmdAdminAsk({ ...ctx, positionals: ctx.positionals.slice(1) });
3357
3528
  if (sub === "experiments") return cmdAdminExperiments({ ...ctx, positionals: ctx.positionals.slice(1) });
3529
+ if (sub === "fleet-experiments") return cmdAdminFleetExperiments({ ...ctx, positionals: ctx.positionals.slice(1) });
3358
3530
  if (sub === "tuning-context") return cmdAdminTuningContext({ ...ctx, positionals: ctx.positionals.slice(1) });
3359
3531
  if (sub === "tuning-import") return cmdAdminTuningImport({ ...ctx, positionals: ctx.positionals.slice(1) });
3360
3532
  if (sub === "tuning") return cmdAdminTuning({ ...ctx, positionals: ctx.positionals.slice(1) });
3361
3533
  if (sub === "evals") return cmdAdminEvals({ ...ctx, positionals: ctx.positionals.slice(1) });
3362
3534
  throw new CliError(
3363
- 'Usage: admin create-org --domain <bare-domain> [--onboard] … | admin ask "<question>" | admin experiments … | admin crm … | admin spend … | admin evals … | admin tuning … | admin tuning-context | admin replays … (see --help)'
3535
+ 'Usage: admin create-org --domain <bare-domain> [--onboard] … | admin ask "<question>" | admin experiments … | admin fleet-experiments … | admin crm … | admin spend … | admin evals … | admin tuning … | admin tuning-context | admin replays … (see --help)'
3364
3536
  );
3365
3537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.82.3",
3
+ "version": "0.82.4",
4
4
  "description": "Spin up and manage Letterstory phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",