@letterstory/cli 0.177.51 → 0.177.52

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
@@ -90,7 +90,7 @@ import {
90
90
  import { fetchParkedSections, withoutParked } from "./parked.mjs";
91
91
 
92
92
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
93
- export const VERSION = "0.177.51";
93
+ export const VERSION = "0.177.52";
94
94
 
95
95
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
96
96
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -472,6 +472,8 @@ export const BOOLEAN_FLAGS = new Set([
472
472
  "train",
473
473
  "keep-rest",
474
474
  "no-train",
475
+ // usage case-study generate --named: name the companies (counts only without it).
476
+ "named",
475
477
  ]);
476
478
 
477
479
  // Tiny argv parser: `--flag value`, `--flag=value`, boolean `--flag`, and positionals.
@@ -2111,6 +2113,11 @@ Refs (Visual Refs: other companies' brands to design something new after, apart
2111
2113
  Usage data (what signed-in people do in your own app):
2112
2114
  usage [--days 7|30|90] [--site <id>] [--limit <n>] People, companies and the features they use
2113
2115
  usage --host <app host> What to add to the app before anyone signed in
2116
+ usage case-study [--days 7|30|90] The patterns in your usage and the latest case study
2117
+ usage case-study generate [--patterns <id,id>] [--named [--companies <a.com,b.com>]]
2118
+ Write a case study (no company named unless --named)
2119
+ usage case-study publish|unpublish <id> Make it public at a link, or take it down
2120
+ usage case-study pr <id> --repo <owner/name> A pull request that puts it on your website
2114
2121
 
2115
2122
  Models (your own writing models, each trained on writing you give it so it writes in your voice):
2116
2123
  models [list] [--archived] Your models: where each stands, its links, its version
@@ -5,10 +5,29 @@
5
5
  // letterstory usage --host app.acme.com what to add to the app before anyone signed in
6
6
  // letterstory usage import-posthog --project <id> --key <phx_…> [--days 90] [--host app.acme.com]
7
7
  // [--feature-urls map.json] [--dry-run] history from your PostHog (import_posthog_usage)
8
+ // letterstory usage case-study [--days 7|30|90] the patterns and the latest case study
9
+ // letterstory usage case-study generate [--days] [--patterns a,b] [--named [--companies x.com,y.com]]
10
+ // letterstory usage case-study publish|unpublish <id>
11
+ // letterstory usage case-study pr <id> --repo <owner/name> [--base <branch>]
8
12
 
9
13
  import { CliError } from "../client.mjs";
10
14
  import { readFileSync } from "node:fs";
11
- import { argsFromFlags, printResult } from "./shared.mjs";
15
+ import { argsFromFlags, flagCsv, printResult } from "./shared.mjs";
16
+
17
+ const csv = (flag) => ({
18
+ value: (flags) => {
19
+ const list = flagCsv(flags[flag]);
20
+ return list.length ? list : undefined;
21
+ },
22
+ });
23
+ const repoPart = (i) => ({
24
+ value: (flags) => {
25
+ const repo = typeof flags.repo === "string" ? flags.repo : "";
26
+ const [owner, name] = repo.split("/");
27
+ if (!owner || !name) throw new CliError("--repo must be <owner/name>.");
28
+ return [owner, name][i];
29
+ },
30
+ });
12
31
 
13
32
  export const ARGS = {
14
33
  get_usage_data: {
@@ -44,8 +63,76 @@ export const ARGS = {
44
63
  },
45
64
  dry_run: { flag: "dry-run", type: "bool" },
46
65
  },
66
+ get_case_study: {
67
+ id: { flag: "id" },
68
+ days: { flag: "days", type: "num" },
69
+ site_id: { flag: "site" },
70
+ },
71
+ generate_case_study: {
72
+ days: { flag: "days", type: "num" },
73
+ site_id: { flag: "site" },
74
+ patterns: csv("patterns"),
75
+ anonymization: { value: (flags) => (flags.named === true ? "companies_named" : "counts_only") },
76
+ named_companies: csv("companies"),
77
+ },
78
+ publish_case_study: { id: { positional: 0, required: true, label: "id" } },
79
+ unpublish_case_study: { id: { positional: 0, required: true, label: "id" } },
80
+ open_case_study_pr: {
81
+ id: { positional: 0, required: true, label: "id" },
82
+ repo_owner: repoPart(0),
83
+ repo_name: repoPart(1),
84
+ base_branch: { flag: "base" },
85
+ provider: { flag: "provider", enum: ["github", "gitlab"] },
86
+ },
47
87
  };
48
88
 
89
+ function printCaseStudy(c) {
90
+ if (!c) return "No case study yet. Write one: letterstory usage case-study generate";
91
+ const lines = [
92
+ `${c.headline} (${c.status}${c.url ? `, ${c.url}` : ""})`,
93
+ "",
94
+ ...c.paragraphs.flatMap((p) => [p, ""]),
95
+ `${c.anonymization === "counts_only" ? "No company named" : `Named: ${c.named_companies.join(", ") || "none"}`}; last ${c.days} days; id ${c.id}`,
96
+ ];
97
+ return lines.join("\n");
98
+ }
99
+
100
+ async function cmdCaseStudy(ctx) {
101
+ const { client, flags, io } = ctx;
102
+ const [, sub, ...rest] = ctx.positionals;
103
+ if (!sub) {
104
+ const result = await client.callTool("get_case_study", argsFromFlags(ARGS.get_case_study, flags, []));
105
+ printResult(io, flags, result, (r) =>
106
+ [
107
+ `Patterns, last ${r.days} days`,
108
+ ...(r.patterns.length
109
+ ? r.patterns.map((p) => ` ${p.id.padEnd(36)} ${p.fact}`)
110
+ : [" Not enough usage yet."]),
111
+ "",
112
+ printCaseStudy(r.case_study),
113
+ ].join("\n")
114
+ );
115
+ return 0;
116
+ }
117
+ if (sub === "generate") {
118
+ const result = await client.callTool("generate_case_study", argsFromFlags(ARGS.generate_case_study, flags, []));
119
+ printResult(io, flags, result, printCaseStudy);
120
+ return 0;
121
+ }
122
+ if (sub === "publish" || sub === "unpublish") {
123
+ const tool = sub === "publish" ? "publish_case_study" : "unpublish_case_study";
124
+ const result = await client.callTool(tool, argsFromFlags(ARGS[tool], flags, rest));
125
+ printResult(io, flags, result, printCaseStudy);
126
+ return 0;
127
+ }
128
+ if (sub === "pr") {
129
+ const result = await client.callTool("open_case_study_pr", argsFromFlags(ARGS.open_case_study_pr, flags, rest));
130
+ printResult(io, flags, result, (r) => r.message);
131
+ return 0;
132
+ }
133
+ throw new CliError(`Unknown: usage case-study ${sub}. Try generate, publish, unpublish or pr.`);
134
+ }
135
+
49
136
  const STEP = {
50
137
  identify: "Letter's script is on the app. Add the identify line to signed-in pages:",
51
138
  add_app: "Put this tag and the identify line on the app:",
@@ -55,6 +142,7 @@ const STEP = {
55
142
 
56
143
  export async function cmdUsage(ctx) {
57
144
  const { client, flags, io } = ctx;
145
+ if (ctx.positionals[0] === "case-study") return cmdCaseStudy(ctx);
58
146
  if (ctx.positionals[0] === "import-posthog") {
59
147
  if (!flags.project || !flags.key) throw new CliError("import-posthog needs --project and --key.");
60
148
  const result = await client.callTool(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.177.51",
3
+ "version": "0.177.52",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",