@letterstory/cli 0.177.50 → 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 +8 -1
- package/lib/commands/usage.mjs +126 -1
- package/package.json +1 -1
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.
|
|
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
|
package/lib/commands/usage.mjs
CHANGED
|
@@ -3,9 +3,31 @@
|
|
|
3
3
|
//
|
|
4
4
|
// letterstory usage [--days 7|30|90] [--site <id>] [--limit <n>] people, companies, features
|
|
5
5
|
// letterstory usage --host app.acme.com what to add to the app before anyone signed in
|
|
6
|
+
// letterstory usage import-posthog --project <id> --key <phx_…> [--days 90] [--host app.acme.com]
|
|
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>]
|
|
6
12
|
|
|
7
13
|
import { CliError } from "../client.mjs";
|
|
8
|
-
import {
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
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
|
+
});
|
|
9
31
|
|
|
10
32
|
export const ARGS = {
|
|
11
33
|
get_usage_data: {
|
|
@@ -21,8 +43,96 @@ export const ARGS = {
|
|
|
21
43
|
host: { flag: "host" },
|
|
22
44
|
limit: { flag: "limit", type: "num" },
|
|
23
45
|
},
|
|
46
|
+
import_posthog_usage: {
|
|
47
|
+
project_id: { flag: "project" },
|
|
48
|
+
personal_api_key: { flag: "key" },
|
|
49
|
+
posthog_host: { flag: "posthog-host" },
|
|
50
|
+
days: { flag: "days", type: "num" },
|
|
51
|
+
site_id: { flag: "site" },
|
|
52
|
+
host: { flag: "host" },
|
|
53
|
+
feature_urls: {
|
|
54
|
+
// A JSON file: [{ "url_contains": "view=plan", "feature": "Ideas" }, …]
|
|
55
|
+
value: (flags) => {
|
|
56
|
+
if (flags["feature-urls"] === undefined) return undefined;
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(readFileSync(String(flags["feature-urls"]), "utf8"));
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw new CliError(`--feature-urls: ${e instanceof Error ? e.message : String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
dry_run: { flag: "dry-run", type: "bool" },
|
|
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
|
+
},
|
|
24
87
|
};
|
|
25
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
|
+
|
|
26
136
|
const STEP = {
|
|
27
137
|
identify: "Letter's script is on the app. Add the identify line to signed-in pages:",
|
|
28
138
|
add_app: "Put this tag and the identify line on the app:",
|
|
@@ -32,6 +142,21 @@ const STEP = {
|
|
|
32
142
|
|
|
33
143
|
export async function cmdUsage(ctx) {
|
|
34
144
|
const { client, flags, io } = ctx;
|
|
145
|
+
if (ctx.positionals[0] === "case-study") return cmdCaseStudy(ctx);
|
|
146
|
+
if (ctx.positionals[0] === "import-posthog") {
|
|
147
|
+
if (!flags.project || !flags.key) throw new CliError("import-posthog needs --project and --key.");
|
|
148
|
+
const result = await client.callTool(
|
|
149
|
+
"import_posthog_usage",
|
|
150
|
+
argsFromFlags(ARGS.import_posthog_usage, flags, [])
|
|
151
|
+
);
|
|
152
|
+
printResult(io, flags, result, (r) =>
|
|
153
|
+
[
|
|
154
|
+
`${r.dry_run ? "Would import" : "Imported"} from PostHog (${r.host}, since ${r.since}):`,
|
|
155
|
+
` ${r.people} people, ${r.companies} companies, ${r.pages} pages, ${r.features} features`,
|
|
156
|
+
].join("\n")
|
|
157
|
+
);
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
35
160
|
const result = await client.callTool("get_usage_data", argsFromFlags(ARGS.get_usage_data, flags, ctx.positionals));
|
|
36
161
|
printResult(io, flags, result, (r) => {
|
|
37
162
|
if (r.step !== "collecting") {
|