@letterstory/cli 0.177.49 → 0.177.51

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
@@ -85,11 +85,12 @@ import {
85
85
  cmdDeploy,
86
86
  cmdRefs,
87
87
  cmdModels,
88
+ cmdUsage,
88
89
  } from "./commands.mjs";
89
90
  import { fetchParkedSections, withoutParked } from "./parked.mjs";
90
91
 
91
92
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
92
- export const VERSION = "0.177.49";
93
+ export const VERSION = "0.177.51";
93
94
 
94
95
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
95
96
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -262,6 +263,8 @@ export const BOOLEAN_FLAGS = new Set([
262
263
  "dry-run",
263
264
  // domains buy --no-spend: only when it buys nothing.
264
265
  "no-spend",
266
+ // repo install-letterprove --identify-only: the identify line alone (Usage data's identify step).
267
+ "identify-only",
265
268
  // admin demo list --enrollable, show --moves, set --enroll|--unenroll
266
269
  "enrollable",
267
270
  "moves",
@@ -1978,10 +1981,11 @@ Repo changes (Claude Code edits your repo in a sandbox; the Letter GitHub App op
1978
1981
  repo fix-audit --issue <issue-type>... [--audit <id>] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
1979
1982
  One PR fixing site-audit issues (repeat --issue to bundle) on every affected page,
1980
1983
  in the repo verified to build the site
1981
- repo install-letterprove --repo <owner/name> [--gitlab] [--host <domain>] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
1982
- One PR adding Proofs to your product: Letter's script on signed-in
1984
+ repo install-letterprove --repo <owner/name> [--gitlab] [--host <domain>] [--identify-only] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
1985
+ One PR adding Letter to your app: the script on signed-in
1983
1986
  pages (identification off) and the identify call
1984
- (pick the repo where users sign in; --host: where they do)
1987
+ (pick the repo where users sign in; --host: where they do;
1988
+ --identify-only: the call alone, the script already there)
1985
1989
  repo install-visitors [--site <id> | --host <domain>] [--repo <owner/name> [--gitlab]] [--branch <base>] [--action build|build_pr|build_merge|slack|linear] [--wait]
1986
1990
  One PR adding the Visitors script tag and server snippet to the repo that
1987
1991
  builds the site (--repo: another repo)
@@ -2104,6 +2108,10 @@ Refs (Visual Refs: other companies' brands to design something new after, apart
2104
2108
  Every brand's direction for it, as one file
2105
2109
  refs brief-show <brief-id> The brief, once ready
2106
2110
 
2111
+ Usage data (what signed-in people do in your own app):
2112
+ usage [--days 7|30|90] [--site <id>] [--limit <n>] People, companies and the features they use
2113
+ usage --host <app host> What to add to the app before anyone signed in
2114
+
2107
2115
  Models (your own writing models, each trained on writing you give it so it writes in your voice):
2108
2116
  models [list] [--archived] Your models: where each stands, its links, its version
2109
2117
  models create "<name>" [--budget <usd>] [--description <d>]
@@ -2277,6 +2285,7 @@ const CLIENT_COMMANDS = {
2277
2285
  deploy: cmdDeploy,
2278
2286
  refs: cmdRefs,
2279
2287
  models: cmdModels,
2288
+ usage: cmdUsage,
2280
2289
  // Platform-scoped (staff key) — the only commands that act BEFORE an org exists.
2281
2290
  admin: cmdAdmin,
2282
2291
  };
@@ -182,6 +182,8 @@ const ARGS = {
182
182
  letterprove_open_install_pr: {
183
183
  provider,
184
184
  host: "host",
185
+ // --identify-only: the identify line alone, when the script is already on the app (usage's identify step).
186
+ identify_only: { flag: "identify-only", type: "bool" },
185
187
  repo_owner: { value: (flags) => splitRepo(flags).owner },
186
188
  repo_name: { value: (flags) => splitRepo(flags).name },
187
189
  base_branch: "branch",
@@ -0,0 +1,117 @@
1
+ // `usage` — Usage data from a terminal (docs/architecture/usage-data.md): what Letter's script counts on your own
2
+ // app where it says who is signed in. A thin wrapper over get_usage_data, the function the app's Usage data calls.
3
+ //
4
+ // letterstory usage [--days 7|30|90] [--site <id>] [--limit <n>] people, companies, features
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
+
9
+ import { CliError } from "../client.mjs";
10
+ import { readFileSync } from "node:fs";
11
+ import { argsFromFlags, printResult } from "./shared.mjs";
12
+
13
+ export const ARGS = {
14
+ get_usage_data: {
15
+ days: {
16
+ value: (flags) => {
17
+ if (flags.days === undefined) return undefined;
18
+ const n = Number(flags.days);
19
+ if (![7, 30, 90].includes(n)) throw new CliError("--days takes 7, 30 or 90.");
20
+ return n;
21
+ },
22
+ },
23
+ site_id: { flag: "site" },
24
+ host: { flag: "host" },
25
+ limit: { flag: "limit", type: "num" },
26
+ },
27
+ import_posthog_usage: {
28
+ project_id: { flag: "project" },
29
+ personal_api_key: { flag: "key" },
30
+ posthog_host: { flag: "posthog-host" },
31
+ days: { flag: "days", type: "num" },
32
+ site_id: { flag: "site" },
33
+ host: { flag: "host" },
34
+ feature_urls: {
35
+ // A JSON file: [{ "url_contains": "view=plan", "feature": "Ideas" }, …]
36
+ value: (flags) => {
37
+ if (flags["feature-urls"] === undefined) return undefined;
38
+ try {
39
+ return JSON.parse(readFileSync(String(flags["feature-urls"]), "utf8"));
40
+ } catch (e) {
41
+ throw new CliError(`--feature-urls: ${e instanceof Error ? e.message : String(e)}`);
42
+ }
43
+ },
44
+ },
45
+ dry_run: { flag: "dry-run", type: "bool" },
46
+ },
47
+ };
48
+
49
+ const STEP = {
50
+ identify: "Letter's script is on the app. Add the identify line to signed-in pages:",
51
+ add_app: "Put this tag and the identify line on the app:",
52
+ install: "Put this tag and the identify line on the app:",
53
+ pick_app: "Name your app's host: letterstory usage --host app.example.com",
54
+ };
55
+
56
+ export async function cmdUsage(ctx) {
57
+ const { client, flags, io } = ctx;
58
+ if (ctx.positionals[0] === "import-posthog") {
59
+ if (!flags.project || !flags.key) throw new CliError("import-posthog needs --project and --key.");
60
+ const result = await client.callTool(
61
+ "import_posthog_usage",
62
+ argsFromFlags(ARGS.import_posthog_usage, flags, [])
63
+ );
64
+ printResult(io, flags, result, (r) =>
65
+ [
66
+ `${r.dry_run ? "Would import" : "Imported"} from PostHog (${r.host}, since ${r.since}):`,
67
+ ` ${r.people} people, ${r.companies} companies, ${r.pages} pages, ${r.features} features`,
68
+ ].join("\n")
69
+ );
70
+ return 0;
71
+ }
72
+ const result = await client.callTool("get_usage_data", argsFromFlags(ARGS.get_usage_data, flags, ctx.positionals));
73
+ printResult(io, flags, result, (r) => {
74
+ if (r.step !== "collecting") {
75
+ const lines = [`${r.app.host ?? "Your app"}: nobody signed in yet.`, STEP[r.step]];
76
+ if (r.install?.tag) lines.push("", r.install.tag);
77
+ if (r.install) lines.push("", r.install.identify);
78
+ if (r.step !== "pick_app")
79
+ lines.push(
80
+ "",
81
+ `Or open a PR: letterstory repo install-letterprove --repo <owner/name> --host ${r.app.host}${r.step === "identify" ? " --identify-only" : ""}`
82
+ );
83
+ return lines.join("\n");
84
+ }
85
+ const t = r.totals;
86
+ const lines = [
87
+ `${r.app.host ?? "Your app"}, last ${r.days} days: ${t.people} people, ${t.companies} companies, ${t.pages} pages`,
88
+ "",
89
+ "Features",
90
+ ...r.features
91
+ .slice(0, 20)
92
+ .map(
93
+ (f) =>
94
+ ` ${f.label.slice(0, 40).padEnd(42)} ${String(f.people).padStart(5)} people ${String(f.companies).padStart(4)} companies`
95
+ ),
96
+ "",
97
+ "Companies",
98
+ ...r.companies
99
+ .slice(0, 20)
100
+ .map(
101
+ (c) =>
102
+ ` ${c.domain.padEnd(32)} ${String(c.people).padStart(4)} people ${String(c.features).padStart(4)} features ${c.last_seen ?? ""}`
103
+ ),
104
+ "",
105
+ "People",
106
+ ...r.people
107
+ .slice(0, 20)
108
+ .map(
109
+ (p) =>
110
+ ` ${p.id} ${(p.company ?? "").padEnd(28)} ${String(p.features).padStart(4)} features ${String(p.pages).padStart(4)} pages ${p.last_seen ?? ""}`
111
+ ),
112
+ ];
113
+ if (r.left_out.length) lines.push("", `Left out: ${r.left_out.join(", ")}`);
114
+ return lines.join("\n");
115
+ });
116
+ return 0;
117
+ }
package/lib/commands.mjs CHANGED
@@ -55,6 +55,7 @@ export * from "./commands/visits.mjs";
55
55
  export * from "./commands/sim.mjs";
56
56
  export * from "./commands/vary.mjs";
57
57
  export * from "./commands/domains.mjs";
58
+ export * from "./commands/usage.mjs";
58
59
  export * from "./commands/proofs.mjs";
59
60
  export * from "./commands/bench.mjs";
60
61
  export * from "./commands/replicate.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.177.49",
3
+ "version": "0.177.51",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",