@letterstory/cli 0.174.2 → 0.174.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
@@ -29,6 +29,7 @@ import {
29
29
  cmdPublished,
30
30
  cmdReviewers,
31
31
  cmdAutomations,
32
+ cmdAutomate,
32
33
  cmdCollections,
33
34
  cmdAuthors,
34
35
  cmdFlows,
@@ -75,7 +76,7 @@ import {
75
76
  } from "./commands.mjs";
76
77
 
77
78
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
78
- export const VERSION = "0.174.2";
79
+ export const VERSION = "0.174.4";
79
80
 
80
81
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
81
82
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -84,6 +85,10 @@ export const EXIT_PAYMENT_REQUIRED = 3;
84
85
  // can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
85
86
  // `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
86
87
  export const BOOLEAN_FLAGS = new Set([
88
+ // automate add/set: on or off; only identified visitors marked hot leads.
89
+ "on",
90
+ "off",
91
+ "hot-leads-only",
87
92
  // admin crm prospect-org: start (or retry) the org prepared for the booked call.
88
93
  "start",
89
94
  // site research-builds: run now even when the stored pass is under an hour old.
@@ -469,6 +474,7 @@ Collections (the content engine as a primitive — one door, 'collection run'):
469
474
  collection run-status <run-id> Status, steps, constraints, verification
470
475
  collection runs [--collection <id>] [--status <s>] [--limit <n>]
471
476
  collection approve <run-id> [--now] Answer the gate (--now publishes immediately)
477
+ collection move <run-id> --date YYYY-MM-DD Move a slot not yet written, or an approved written post, to another day
472
478
  collection cancel <run-id>
473
479
  collection inventory <id> Where every piece is; each finished draft's publish-on-its-own time
474
480
  collection links <id> [--refresh] Internal-link refresh: on/off, posts due (--refresh runs the next batch now)
@@ -547,6 +553,27 @@ Reviewers:
547
553
  automations set <automation-id> --collection <id> [--pace <n>] [--pause | --resume] [--goal <id>]
548
554
  [--brief <text>] [--remap]
549
555
  automations remove <automation-id> --collection <id>
556
+ automate options What an automation can be made of here: triggers,
557
+ actions and what each can be fixed to
558
+ automate list Your automations: an event, what Letter reads it
559
+ for, the action it becomes
560
+ automate show <automation-id>
561
+ automate add --name <n> --trigger competitor_page|visitor_identified|custom
562
+ --action write_post|enroll_in_sequence|build_page [--instruction <text>]
563
+ [--collection <id>|--sequence <id>|--host <site>] [--event <name>] [--kind post|landing]
564
+ [--competitor <host>] [--site <host>] [--hot-leads-only] [--review act|ask] [--off]
565
+ Make one: it starts from now
566
+ automate set <automation-id> [--name <n>] [--instruction <text>] [--review act|ask] [--on|--off] ...
567
+ automate try [<automation-id>] [--trigger <t> --action <a> --instruction <text> ...] [--limit <n>]
568
+ What it would do with the latest events (acts on none)
569
+ automate runs [--automation <id>] [--status proposed|acted|skipped|failed|rejected] [--limit <n>]
570
+ Every event read, what came of it and why
571
+ automate approve <run-id> Make the call a run that asked first proposes
572
+ automate reject <run-id> --reason <why>
573
+ automate send <event-name> --title <what happened> [--key <id>] [--url <u>] [--fact k=v ...]
574
+ [--email <e>] [--person <name>] [--company <c>]
575
+ Send an event from your own systems
576
+ automate remove <automation-id>
550
577
  reviewers invite <article-id> --email <e> [--name <n>]
551
578
  Invite a guest to review one post
552
579
  (emails them a link and a PIN)
@@ -1119,6 +1146,7 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
1119
1146
  | onboard-plan <account-id> [--refresh]
1120
1147
  | prospect-org <account-id> [--start] [--domain acme.com] the org prepared for their booked call
1121
1148
  | prospect-orgs [--status preparing|ready|failed|skipped|parked|converted] [--limit 50]
1149
+ | prospect-org-repost <prospect-org-id> post a ready org's summary to #ready-for-call again
1122
1150
  | payment-link <account-id> [--amount-cents N] [--description "…"] [--plan starter] [--ratio N] [--why "…"] [--first-invoice-credit-cents N]
1123
1151
  The staff CRM's pipeline: bulk-importing a
1124
1152
  CSV of leads, the inbound signal
@@ -1635,8 +1663,9 @@ Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App op
1635
1663
  [--detail full] one row per run by default; full: every field
1636
1664
  repo publish <run-id> Make PR on a preview in review
1637
1665
  repo merge <run-id> Merge its open PR (a squash; the repo's branch rules decide)
1638
- repo revise <run-id> --instructions <text>|--instructions-file <path|->
1639
- Ask for more on a preview; it takes over the preview's link
1666
+ repo revise <run-id> --instructions <text>|--instructions-file <path|-> [--copy-edits-file <path|->]
1667
+ Ask for more on a preview (it takes over the preview's link) or an
1668
+ open PR (one more commit); copy edits: JSON [{ path, before, after }]
1640
1669
  repo cancel <run-id> [--force] Stop it and delete the sandbox; no PR (Discard a preview)
1641
1670
 
1642
1671
  Feedback (tell us what's broken, missing, unclear, or wanted):
@@ -1726,6 +1755,7 @@ const CLIENT_COMMANDS = {
1726
1755
  published: cmdPublished,
1727
1756
  reviewers: cmdReviewers,
1728
1757
  automations: cmdAutomations,
1758
+ automate: cmdAutomate,
1729
1759
  collections: cmdCollections,
1730
1760
  authors: cmdAuthors,
1731
1761
  flows: cmdFlows,
@@ -3822,6 +3822,12 @@ async function cmdAdminCrm(ctx) {
3822
3822
  prospectOrgLines(x.prospectOrg)
3823
3823
  );
3824
3824
  }
3825
+ case "prospect-org-repost": {
3826
+ // admin crm prospect-org-repost <prospect-org-id> — post a ready org's summary to
3827
+ // #ready-for-call again. The key needs crm:write.
3828
+ if (!id) throw new CliError("Usage: admin crm prospect-org-repost <prospect-org-id>");
3829
+ return out(await staffPost(ctx, `${CRM}/prospect-orgs/${id}/repost`, {}), (x) => `Posted to ${x.channel}`);
3830
+ }
3825
3831
  case "prospect-orgs": {
3826
3832
  // admin crm prospect-orgs [--status ready] [--limit 50] — the orgs prepared for booked
3827
3833
  // calls, newest first.
@@ -3878,7 +3884,7 @@ async function cmdAdminCrm(ctx) {
3878
3884
  }
3879
3885
  default:
3880
3886
  throw new CliError(
3881
- "Usage: 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|client-health|case|onboard|onboarding|retry-onboarding|onboard-plan|prospect-org|prospect-orgs|payment-link … (see --help)"
3887
+ "Usage: 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|client-health|case|onboard|onboarding|retry-onboarding|onboard-plan|prospect-org|prospect-orgs|prospect-org-repost|payment-link … (see --help)"
3882
3888
  );
3883
3889
  }
3884
3890
  }
@@ -0,0 +1,162 @@
1
+ // `automate` — Letterpress → Automations (docs/architecture/event-automations.md): an event, read
2
+ // against your instruction, made into an action. options / list / show / add / set / try / runs /
3
+ // approve / reject / send / remove, through the same tools the app uses. (A letterbase's writing
4
+ // automations are `automations`.)
5
+ // Same flag/positional/io conventions as posts.mjs — no commander, no color.
6
+
7
+ import { CliError } from "../client.mjs";
8
+ import { printResult, ok, argsFromFlags, flagList, refuseUnknownFlags } from "./shared.mjs";
9
+
10
+ const TRIGGERS = ["competitor_page", "visitor_identified", "custom"];
11
+ const ACTIONS = ["write_post", "enroll_in_sequence", "build_page"];
12
+ const REVIEW = ["act", "ask"];
13
+ const STATUSES = ["pending", "proposed", "acted", "skipped", "failed", "rejected"];
14
+
15
+ const triggerParams = {
16
+ object: {
17
+ kinds: { flag: "kind", type: "list" },
18
+ competitors: { flag: "competitor", type: "list" },
19
+ hosts: { flag: "site", type: "list" },
20
+ hot_leads_only: { flag: "hot-leads-only", type: "bool" },
21
+ event: { flag: "event" },
22
+ },
23
+ };
24
+ const actionParams = {
25
+ object: {
26
+ collection_id: { flag: "collection" },
27
+ sequence_id: { flag: "sequence" },
28
+ host: { flag: "host" },
29
+ },
30
+ };
31
+ const enabled = { value: (flags) => (flags.off === true ? false : flags.on === true ? true : undefined) };
32
+
33
+ /** --fact plan=team --fact seats=40 → { plan: "team", seats: 40 } (numbers and true/false read as such). */
34
+ function factsOf(flags) {
35
+ const pairs = flagList(flags.fact);
36
+ if (!pairs.length) return undefined;
37
+ const facts = {};
38
+ for (const pair of pairs) {
39
+ const i = pair.indexOf("=");
40
+ if (i <= 0) throw new CliError(`--fact takes key=value, got: ${pair}`);
41
+ const raw = pair.slice(i + 1);
42
+ facts[pair.slice(0, i)] =
43
+ raw === "true"
44
+ ? true
45
+ : raw === "false"
46
+ ? false
47
+ : raw !== "" && !Number.isNaN(Number(raw))
48
+ ? Number(raw)
49
+ : raw;
50
+ }
51
+ return facts;
52
+ }
53
+
54
+ /** See `argsFromFlags` in shared.mjs; `scripts/parity-check.ts` diffs these keys against the tool. */
55
+ export const ARGS = {
56
+ describe_automation_options: {},
57
+ list_event_automations: {},
58
+ get_event_automation: {
59
+ automation_id: { positional: 0, label: "automation-id", required: true },
60
+ },
61
+ create_event_automation: {
62
+ name: { flag: "name", required: true },
63
+ trigger: { flag: "trigger", required: true, enum: TRIGGERS },
64
+ trigger_params: triggerParams,
65
+ instruction: { flag: "instruction" },
66
+ action: { flag: "action", required: true, enum: ACTIONS },
67
+ action_params: actionParams,
68
+ review: { flag: "review", enum: REVIEW },
69
+ enabled,
70
+ },
71
+ update_event_automation: {
72
+ automation_id: { positional: 0, label: "automation-id", required: true },
73
+ name: { flag: "name" },
74
+ trigger_params: triggerParams,
75
+ instruction: { flag: "instruction" },
76
+ action_params: actionParams,
77
+ review: { flag: "review", enum: REVIEW },
78
+ enabled,
79
+ },
80
+ delete_event_automation: {
81
+ automation_id: { positional: 0, label: "automation-id", required: true },
82
+ },
83
+ try_event_automation: {
84
+ automation_id: { positional: 0, label: "automation-id" },
85
+ trigger: { flag: "trigger", enum: TRIGGERS },
86
+ trigger_params: triggerParams,
87
+ instruction: { flag: "instruction" },
88
+ action: { flag: "action", enum: ACTIONS },
89
+ action_params: actionParams,
90
+ limit: { flag: "limit", type: "num" },
91
+ },
92
+ list_automation_runs: {
93
+ automation_id: { flag: "automation" },
94
+ status: { flag: "status", enum: STATUSES },
95
+ limit: { flag: "limit", type: "num" },
96
+ before: { flag: "before" },
97
+ },
98
+ decide_automation_run: {
99
+ run_id: { positional: 0, label: "run-id", required: true },
100
+ decision: { internal: "approve or reject, from the subcommand" },
101
+ reason: { flag: "reason" },
102
+ },
103
+ send_automation_event: {
104
+ event: { positional: 0, label: "event-name", required: true },
105
+ key: { flag: "key" },
106
+ title: { flag: "title", required: true },
107
+ url: { flag: "url" },
108
+ at: { flag: "at" },
109
+ facts: { value: factsOf },
110
+ person: {
111
+ object: {
112
+ email: { flag: "email" },
113
+ name: { flag: "person" },
114
+ company: { flag: "company" },
115
+ },
116
+ },
117
+ },
118
+ };
119
+
120
+ export async function cmdAutomate(ctx) {
121
+ const sub = ctx.positionals[0];
122
+ const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
123
+ switch (sub) {
124
+ case "options":
125
+ return run(rest, "describe_automation_options");
126
+ case "list":
127
+ case "ls":
128
+ return run(rest, "list_event_automations");
129
+ case "show":
130
+ return run(rest, "get_event_automation");
131
+ case "add":
132
+ return run(rest, "create_event_automation", "Added.");
133
+ case "set":
134
+ refuseUnknownFlags(rest, ARGS.update_event_automation);
135
+ return run(rest, "update_event_automation", "Changed.");
136
+ case "try":
137
+ return run(rest, "try_event_automation");
138
+ case "runs":
139
+ return run(rest, "list_automation_runs");
140
+ case "approve":
141
+ return run(rest, "decide_automation_run", "Approved.", { decision: "approve" });
142
+ case "reject":
143
+ return run(rest, "decide_automation_run", "Rejected.", { decision: "reject" });
144
+ case "send":
145
+ return run(rest, "send_automation_event");
146
+ case "remove":
147
+ case "rm":
148
+ return run(rest, "delete_event_automation", "Removed.");
149
+ default:
150
+ throw new CliError(
151
+ `Unknown automate subcommand: ${sub ?? "(none)"}. Try: options, list, show, add, set, try, runs, approve, reject, send, remove`
152
+ );
153
+ }
154
+ }
155
+
156
+ async function run(ctx, tool, said, extra = {}) {
157
+ const { client, flags, io } = ctx;
158
+ const result = await client.callTool(tool, { ...argsFromFlags(ARGS[tool], flags, ctx.positionals), ...extra });
159
+ if (said) ok(ctx, said);
160
+ printResult(io, flags, result);
161
+ return 0;
162
+ }
@@ -133,6 +133,10 @@ export const ARGS = {
133
133
  cancel_collection_run: {
134
134
  run_id: { positional: 0, label: "run-id", required: true },
135
135
  },
136
+ reschedule_collection_run: {
137
+ run_id: { positional: 0, label: "run-id", required: true },
138
+ date: { flag: "date", required: true },
139
+ },
136
140
  get_collection_inventory: {
137
141
  collection_id: { positional: 0, label: "collection-id", required: true },
138
142
  },
@@ -176,6 +180,9 @@ export async function cmdCollection(ctx) {
176
180
  return collectionApprove(rest);
177
181
  case "cancel":
178
182
  return collectionCancel(rest);
183
+ case "move":
184
+ case "reschedule":
185
+ return collectionMove(rest);
179
186
  case "inventory":
180
187
  return collectionInventory(rest);
181
188
  case "overview":
@@ -184,7 +191,7 @@ export async function cmdCollection(ctx) {
184
191
  return collectionLinks(rest);
185
192
  default:
186
193
  throw new CliError(
187
- `Unknown collection subcommand: ${sub ?? "(none)"}. Try: list, overview, new, config, delete, run, add, queue, headline, run-status, runs, approve, cancel, inventory, links`
194
+ `Unknown collection subcommand: ${sub ?? "(none)"}. Try: list, overview, new, config, delete, run, add, queue, headline, run-status, runs, approve, move, cancel, inventory, links`
188
195
  );
189
196
  }
190
197
  }
@@ -382,6 +389,18 @@ async function collectionCancel(ctx) {
382
389
  return 0;
383
390
  }
384
391
 
392
+ // `collection move <run-id> --date YYYY-MM-DD` — a slot not yet written, or a written post
393
+ // already approved, onto another day (reschedule_collection_run).
394
+ async function collectionMove(ctx) {
395
+ const result = await ctx.client.callTool(
396
+ "reschedule_collection_run",
397
+ argsFromFlags(ARGS.reschedule_collection_run, ctx.flags, ctx.positionals)
398
+ );
399
+ ok(ctx, `Moved: goes live ${toolField(result, "scheduled_for") ?? "?"}.`);
400
+ printResult(ctx.io, ctx.flags, result);
401
+ return 0;
402
+ }
403
+
385
404
  // `collection inventory <id>` — where every piece is, and each finished draft's
386
405
  // publish-on-its-own time (the collection room's Work tab + "needs you" strip).
387
406
  function formatInventory(r) {
@@ -5,7 +5,7 @@
5
5
  // repo list → list_repo_changes repo cancel → cancel_repo_change
6
6
  // repo publish → publish_repo_change (Make PR on a preview)
7
7
  // repo merge → merge_repo_change (merge its open PR, as a squash)
8
- // repo revise → revise_repo_change (ask for more on a preview, before the PR)
8
+ // repo revise → revise_repo_change (ask for more on a preview or an open PR; --copy-edits-file for exact copy)
9
9
  // repo say → send_repo_change_message (steer a build while its agent works)
10
10
  // repo repos → list_github_app_repos repo branches → list_repo_branches
11
11
  // repo connect → connect_github (the link a person opens to connect GitHub)
@@ -256,6 +256,7 @@ const ARGS = {
256
256
  revise_repo_change: {
257
257
  run_id: { positional: 0, required: true, label: "run-id" },
258
258
  instructions: { value: (flags) => readTextInput(flags, "instructions", "instructions-file") },
259
+ copy_edits: { value: (flags) => copyEdits(flags) },
259
260
  },
260
261
  list_repo_changes: {
261
262
  status: { flag: "status", enum: ["running", "succeeded", "no_changes", "failed", "cancelled", "sent"] },
@@ -737,11 +738,31 @@ async function repoSay(ctx) {
737
738
  return 0;
738
739
  }
739
740
 
740
- /** `repo revise <run-id> --instructions <text>`: a follow-up on a preview, built on top of it. */
741
+ /**
742
+ * `--copy-edits-file <path|->`: exact copy changes, a JSON array of { path, before, after, context? }
743
+ * (or { copy_edits: [...] }), what the preview panel sends when a reviewer types over the page.
744
+ */
745
+ function copyEdits(flags) {
746
+ const text = readTextInput(flags, "copy-edits", "copy-edits-file");
747
+ if (text === undefined) return undefined;
748
+ let parsed;
749
+ try {
750
+ parsed = JSON.parse(text);
751
+ } catch {
752
+ throw new CliError("--copy-edits-file is not valid JSON.");
753
+ }
754
+ const list = Array.isArray(parsed) ? parsed : parsed?.copy_edits;
755
+ if (!Array.isArray(list)) throw new CliError("--copy-edits-file is a JSON array of { path, before, after }.");
756
+ return list;
757
+ }
758
+
759
+ /** `repo revise <run-id> --instructions <text> [--copy-edits-file <path|->]`: a follow-up, built on top of the change. */
741
760
  async function repoRevise(ctx) {
742
761
  const { client, flags, io } = ctx;
743
762
  const args = argsFromFlags(ARGS.revise_repo_change, flags, ctx.positionals);
744
- if (!args.instructions) throw new CliError("Missing --instructions (or --instructions-file <path|->)");
763
+ if (!args.instructions && !args.copy_edits) {
764
+ throw new CliError("Missing --instructions (or --instructions-file <path|->), or --copy-edits-file <path|->");
765
+ }
745
766
  const result = await client.callTool("revise_repo_change", args);
746
767
  ok(ctx, result.message);
747
768
  printResult(io, flags, result.run, describe);
package/lib/commands.mjs CHANGED
@@ -12,6 +12,7 @@ export * from "./commands/mcp.mjs";
12
12
  export * from "./commands/posts.mjs";
13
13
  export * from "./commands/reviewers.mjs";
14
14
  export * from "./commands/automations.mjs";
15
+ export * from "./commands/automate.mjs";
15
16
  export * from "./commands/collections.mjs";
16
17
  export * from "./commands/authors.mjs";
17
18
  export * from "./commands/flows.mjs";
package/lib/documents.mjs CHANGED
@@ -89,6 +89,8 @@ export const JSON_ARG_FLAG_PAIRS = [
89
89
  ["token", "token-file"],
90
90
  // An enclosure version's script (enclosures.mjs add-version): code, read verbatim.
91
91
  ["script", "script-file"],
92
+ // Exact copy changes for a follow-up, parsed as JSON (repo.mjs `repo revise`).
93
+ ["copy-edits", "copy-edits-file"],
92
94
  ];
93
95
 
94
96
  /** Lower-case extension without the dot. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.174.2",
3
+ "version": "0.174.4",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",