@letterstory/cli 0.151.0 → 0.154.0

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/README.md CHANGED
@@ -473,6 +473,7 @@ letterstory admin crm record --source twitter --kind social_engagement \
473
473
  --title "Liked our launch tweet" --name "Pat" --linkedin https://linkedin.com/in/pat
474
474
  letterstory admin crm signal <signal-id> qualify # link/create the account
475
475
  letterstory admin crm signal <signal-id> dismiss # the easy delete (kept, marked)
476
+ letterstory admin crm add "Acme" --domain acme.com # quick-add; an existing account says "already exists as <name> (<domain>)"
476
477
  letterstory admin crm accounts --stage demo_scheduled # with likelihood
477
478
  letterstory admin crm score <account-id> # recompute; prints the factors
478
479
  letterstory admin crm slack-channels [--all] # Watchdog channels + the account each is linked to
package/lib/cli.mjs CHANGED
@@ -66,7 +66,7 @@ import {
66
66
 
67
67
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
68
68
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
69
- export const VERSION = "0.151.0";
69
+ export const VERSION = "0.154.0";
70
70
 
71
71
  // Flags that never take a value. Listing them explicitly means `deploy get --json <id>`
72
72
  // can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
@@ -113,6 +113,7 @@ export const BOOLEAN_FLAGS = new Set([
113
113
  "force-map",
114
114
  "force-audit",
115
115
  "skip-observe",
116
+ "skip-suggest",
116
117
  "ignore-budget",
117
118
  // lede library update / lede proposals accept: clear or drop the line's condition.
118
119
  "no-condition",
@@ -986,6 +987,7 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
986
987
  | record --title "…" [--source bookface] [--kind other] [--intent qualified]
987
988
  [--name …] [--email …] [--company …] [--domain …] [--linkedin …] [--detail …]
988
989
  | signal <id> qualify|dismiss|link [--account <id>]
990
+ | add "<name>" [--domain acme.com] [--stage lead] [--source …] [--owner <user-id>]
989
991
  | accounts [--stage lead] [--q acme] | account <id> | score <account-id>
990
992
  | slack-channels [--all] | link-slack <account-id> <channel-id|none>
991
993
  | white-glove [--suggested] | set-white-glove <account-id> on|off [--note "…"]
@@ -1421,7 +1423,7 @@ The Site (one model of your whole marketing site, keyed by host and path):
1421
1423
  site list Mapped hosts, and hosts you already have elsewhere
1422
1424
  site map <host> [--sitemap <url>] [--max-pages <n>] [--no-audit] [--relation owned|watched]
1423
1425
  Map a host from its sitemap; starts an audit if it has none
1424
- site refresh <host> [--force-map] [--force-audit] [--skip-observe]
1426
+ site refresh <host> [--force-map] [--force-audit] [--skip-observe] [--skip-suggest]
1425
1427
  Run the daily loop now: re-map, re-audit, signals, Jev
1426
1428
  site unmap <host> Remove a host and everything hanging off it
1427
1429
  site tree <host> [path] [--depth <n>] [--unfold] [--since <iso>]
@@ -1500,6 +1502,7 @@ Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App op
1500
1502
  repo say <run-id> <message…> Tell a running build something; it carries on with it
1501
1503
  repo list [--status running|succeeded|no_changes|failed|cancelled] [--limit n] [--audit <id>]
1502
1504
  [--source site_audit_issue|site_quick_check|letterprove_install|visitors_install]
1505
+ [--detail full] one row per run by default; full: every field
1503
1506
  repo publish <run-id> Make PR on a preview in review
1504
1507
  repo merge <run-id> Merge its open PR (a squash; the repo's branch rules decide)
1505
1508
  repo revise <run-id> --instructions <text>|--instructions-file <path|->
@@ -1,6 +1,6 @@
1
1
  // `admin` — the PLATFORM-scoped commands, for staff. Everything else in this CLI is
2
2
  // org-scoped and rides the MCP endpoint with an org API key; these ride a STAFF API key
3
- // (`x-staff-api-key`, minted at Settings → Staff keys) against the superadmin REST
3
+ // (`x-staff-api-key`, minted at Super Admin → Staff keys) against the superadmin REST
4
4
  // routes, because they exist precisely to act BEFORE an org exists.
5
5
  //
6
6
  // admin ask "which kernels are hooked up to the most clients?" [--sql] [--json]
@@ -14,7 +14,7 @@
14
14
  // The old names — evals, eval-add, eval-set, proposals, propose-eval, capture-eval, reject-eval — still work.)
15
15
  // admin evals scoreboard|cases|runs|run|triage|guard|retire … (fleet:read / tuning:experiment)
16
16
  // admin fleet-experiments list|articles|clients|mark|unmark|new|assign|assign-eligible|assign-orgs|spin-up|apply|start|stop|decide … (fleet:read / fleet:experiment)
17
- // admin crm import|capture|outreach|signals|record|signal|accounts|account|score|slack-channels|link-slack|white-glove|set-white-glove|churn|revenue|reach-outs|replies|record-churn|draft-churn-reason|undo-churn|outcomes|record-outcome|renewals|track-record|weekly-note|at-risk|expansion-signals|collections|delivery-flags|pulse|case|onboard|onboarding|retry-onboarding|onboard-plan|payment-link … (crm:read / crm:write)
17
+ // admin crm import|capture|outreach|signals|record|signal|add|accounts|account|score|slack-channels|link-slack|white-glove|set-white-glove|churn|revenue|reach-outs|replies|record-churn|draft-churn-reason|undo-churn|outcomes|record-outcome|renewals|track-record|weekly-note|at-risk|expansion-signals|collections|delivery-flags|pulse|case|onboard|onboarding|retry-onboarding|onboard-plan|payment-link … (crm:read / crm:write)
18
18
  // admin spend summary|reconcile|pnl|margin|pricing|entries|add|import|usage|remove|reference|stripe-sync|services|service … (spend:read / spend:write)
19
19
  // admin brand-detection <org-id> (fleet:read)
20
20
  // admin brand-detection <org-id> [--term t]... [--exact t]... [--exclude p]... [--note "…"] | --clear [--note "…"] (fleet:instrument)
@@ -63,12 +63,22 @@ import { watchDomainJob } from "./onboard.mjs";
63
63
  const SEER_MODES = ["suggest", "skip"];
64
64
  const CMS_PROVIDERS = ["webflow", "framer", "sanity", "contentful", "github"];
65
65
 
66
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
67
+
66
68
  function staffKeyFrom(flags) {
67
69
  const key = flagStr(flags["staff-key"]) || process.env.LETTERSTORY_STAFF_API_KEY || null;
68
70
  if (!key) {
69
71
  throw new CliError(
70
72
  "admin commands need a STAFF API key: pass --staff-key <key> or set LETTERSTORY_STAFF_API_KEY " +
71
- "(mint one at Settings → Staff keys with the org:create capability)."
73
+ "(mint one at Super Admin → Staff keys, or POST /api/staff/keys, and save its plainKey)."
74
+ );
75
+ }
76
+ // The mint answers { key: <the row>, plainKey: <the secret> }; key.id is the easy thing to
77
+ // save by mistake. Say so before the server's 401 does (lib/staff-auth.ts says the same).
78
+ if (UUID_PATTERN.test(key.trim())) {
79
+ throw new CliError(
80
+ "the staff key (--staff-key / LETTERSTORY_STAFF_API_KEY) looks like a key id, not the key — " +
81
+ "use plainKey from the mint response, not key.id."
72
82
  );
73
83
  }
74
84
  return key;
@@ -2580,6 +2590,19 @@ function accountLine(a) {
2580
2590
  return `${a.id} [${a.stage}] ${score} ${a.name}${a.domain ? ` (${a.domain})` : ""}${a.isYc ? " · YC" : ""}`;
2581
2591
  }
2582
2592
 
2593
+ /**
2594
+ * `admin crm add`'s line: "created" for a new account; for an existing one, its OWN
2595
+ * name and domain ("already exists as Letterstory (letterstory.com)"), since a
2596
+ * subdomain is answered by its parent company's account.
2597
+ */
2598
+ export function crmAddLine(r, requestedName) {
2599
+ if (r.created) return `created: ${requestedName} ${r.id}`;
2600
+ const m = r.matched;
2601
+ if (!m) return `already exists ${r.id}`;
2602
+ const why = m.reason === "registrable_domain" ? ", matched on its company domain" : "";
2603
+ return `already exists as ${m.name}${m.domain ? ` (${m.domain})` : ""}${why} ${r.id}`;
2604
+ }
2605
+
2583
2606
  /* ------------------------------------------------------ CRM lead import (CSV) */
2584
2607
 
2585
2608
  /** RFC 4180-ish: quoted fields, doubled quotes, CRLF/LF, a BOM. Returns rows of cells. */
@@ -3246,6 +3269,25 @@ async function cmdAdminCrm(ctx) {
3246
3269
  );
3247
3270
  return out(r, (x) => signalLine(x.signal));
3248
3271
  }
3272
+ case "add": {
3273
+ // admin crm add "<name>" [--domain acme.com] [--stage lead] [--source referral] [--owner <user-id>]
3274
+ // The CRM's quick-add (POST /api/superadmin/crm/accounts). An existing account
3275
+ // answers with its own name and domain, never as if it were the one asked for.
3276
+ const name = ctx.positionals.slice(1).join(" ").trim();
3277
+ if (!name)
3278
+ throw new CliError(
3279
+ 'Usage: admin crm add "<company name>" [--domain acme.com] [--stage lead] [--source …] [--owner <user-id>]'
3280
+ );
3281
+ const body = compact({
3282
+ name,
3283
+ domain: flagStr(flags.domain),
3284
+ stage: flagStr(flags.stage),
3285
+ source: flagStr(flags.source),
3286
+ owner_id: flagStr(flags.owner),
3287
+ });
3288
+ const r = await staffPost(ctx, `${CRM}/accounts`, body);
3289
+ return out(r, (x) => crmAddLine(x, name));
3290
+ }
3249
3291
  case "accounts": {
3250
3292
  const params = new URLSearchParams(compact({ stage: flagStr(flags.stage), q: flagStr(flags.q) }));
3251
3293
  return out(await staffRequest(ctx, "GET", `${CRM}/accounts?${params}`), (r) =>
@@ -25,6 +25,7 @@ export const ARGS = {
25
25
  get_campaign_build: { build_id: { positional: 0, label: "build-id", required: true } },
26
26
  list_campaign_builds: { limit: { flag: "limit", type: "num" } },
27
27
  cancel_campaign_build: { build_id: { positional: 0, label: "build-id", required: true } },
28
+ remove_campaign_build: { build_id: { positional: 0, label: "build-id", required: true } },
28
29
  suggest_campaigns: {},
29
30
  };
30
31
 
@@ -33,6 +34,7 @@ const USAGE = `Usage:
33
34
  campaigns show <build-id> [--watch] Its stage, what it built, and what it is doing
34
35
  campaigns list [--limit <n>] This org's builds, newest first
35
36
  campaigns cancel <build-id> Stop it; what it built is kept
37
+ campaigns remove <build-id> Remove it and what it made (sent copies stay sent)
36
38
  campaigns suggest Three campaigns to build in one step`;
37
39
 
38
40
  const STAGES = { who: "Who", picture: "The picture", test: "Tested on 3", email: "The email", desk: "On the desk" };
@@ -51,6 +53,8 @@ export async function cmdCampaigns(ctx) {
51
53
  return campaignsList(rest);
52
54
  case "cancel":
53
55
  return campaignsCancel(rest);
56
+ case "remove":
57
+ return campaignsRemove(rest);
54
58
  case "suggest":
55
59
  return campaignsSuggest(rest);
56
60
  default:
@@ -149,6 +153,30 @@ async function campaignsCancel(ctx) {
149
153
  return 0;
150
154
  }
151
155
 
156
+ async function campaignsRemove(ctx) {
157
+ const { client, flags, positionals, io } = ctx;
158
+ const result = await client.callTool(
159
+ "remove_campaign_build",
160
+ argsFromFlags(ARGS.remove_campaign_build, flags, positionals)
161
+ );
162
+ const r = result.removal ?? {};
163
+ ok(
164
+ ctx,
165
+ `Removed. ${r.copies_removed ?? 0} unsent ${r.copies_removed === 1 ? "copy" : "copies"} left the desk; sent copies stay sent.`
166
+ );
167
+ printResult(io, flags, result, () =>
168
+ [
169
+ r.sequence && `sequence: ${r.sequence}`,
170
+ r.desk && `desk: ${r.desk}`,
171
+ r.list && `list: ${r.list}${r.list === "deleted" ? " (its people stay in Prospects)" : ""}`,
172
+ r.enclosure && `enclosure: ${r.enclosure}`,
173
+ ]
174
+ .filter(Boolean)
175
+ .join("\n")
176
+ );
177
+ return 0;
178
+ }
179
+
152
180
  async function campaignsSuggest(ctx) {
153
181
  const { client, flags, io } = ctx;
154
182
  const result = await client.callTool("suggest_campaigns", {});
@@ -248,6 +248,7 @@ const ARGS = {
248
248
  ],
249
249
  },
250
250
  site_host: "site",
251
+ detail: { flag: "detail", enum: ["brief", "full"] },
251
252
  },
252
253
  list_github_app_repos: {},
253
254
  connect_github: {},
@@ -293,6 +294,16 @@ function describe(run) {
293
294
  return lines.join("\n");
294
295
  }
295
296
 
297
+ /** A list row (list_repo_changes' brief default): what was asked, where it is, its PR and preview. */
298
+ function describeBrief(run) {
299
+ if (!("title" in run)) return describe(run);
300
+ const lines = [`${run.id} ${run.repo} ${run.status} (${run.phase}) $${run.costUsd.toFixed(2)} ${run.title}`];
301
+ if (run.previewUrl) lines.push(` Preview: ${run.previewUrl}`);
302
+ if (run.prUrl) lines.push(` PR: ${run.prUrl} (${run.prState ?? "state unknown"})`);
303
+ if (run.errorCode) lines.push(` Error: ${run.errorCode}`);
304
+ return lines.join("\n");
305
+ }
306
+
296
307
  export async function cmdRepo(ctx) {
297
308
  const sub = ctx.positionals[0];
298
309
  const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
@@ -647,7 +658,7 @@ async function repoList(ctx) {
647
658
  argsFromFlags(ARGS.list_repo_changes, flags, ctx.positionals)
648
659
  );
649
660
  printResult(io, flags, result.runs, (runs) =>
650
- runs.length ? runs.map(describe).join("\n") : "No repo changes yet."
661
+ runs.length ? runs.map(describeBrief).join("\n") : "No repo changes yet."
651
662
  );
652
663
  return 0;
653
664
  }
@@ -63,6 +63,7 @@ const ARGS = {
63
63
  force_map: { flag: "force-map", type: "bool" },
64
64
  force_audit: { flag: "force-audit", type: "bool" },
65
65
  skip_observe: { flag: "skip-observe", type: "bool" },
66
+ skip_suggest: { flag: "skip-suggest", type: "bool" },
66
67
  },
67
68
  unmap_site: { host: { positional: 0, required: true, label: "host" } },
68
69
  get_site_tree: {
@@ -522,15 +523,24 @@ async function siteObservations(ctx) {
522
523
  "list_site_observations",
523
524
  argsFromFlags(ARGS.list_site_observations, flags, ctx.positionals)
524
525
  );
525
- printResult(
526
- io,
527
- flags,
528
- result,
529
- (r) =>
526
+ printResult(io, flags, result, (r) => {
527
+ // --keys, or a whole site with more than 50: one line per kind, then one key at a time.
528
+ if (r.keys)
529
+ return r.keys.length
530
+ ? [
531
+ ...r.keys.map(
532
+ (k) =>
533
+ `${GLYPH[k.tone].padEnd(2)} ${k.key} ${k.summary} (${k.count} on ${k.paths.length} pages)`
534
+ ),
535
+ `${r.total} in all. Read one kind with --key <key>.`,
536
+ ].join("\n")
537
+ : "Nothing noticed.";
538
+ return (
530
539
  r.observations
531
540
  .map((o) => `${GLYPH[o.tone].padEnd(2)} ${o.path} ${o.summary} [${o.status}] ${o.id}`)
532
541
  .join("\n") || "Nothing noticed."
533
- );
542
+ );
543
+ });
534
544
  return 0;
535
545
  }
536
546
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.151.0",
3
+ "version": "0.154.0",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",