@letterstory/cli 0.177.84 → 0.177.86

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.84";
93
+ export const VERSION = "0.177.86";
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;
@@ -99,6 +99,8 @@ export const EXIT_PAYMENT_REQUIRED = 3;
99
99
  // can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
100
100
  // `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
101
101
  export const BOOLEAN_FLAGS = new Set([
102
+ // visits transact add folder|page: leave it out of the set.
103
+ "uncheck",
102
104
  "clear-choice",
103
105
  // models list: say whether each trained model's server is up now.
104
106
  "serving",
@@ -2061,6 +2063,10 @@ Visits (Visitors: AI agents reading your site, and AI answers sending people to
2061
2063
  visits health --site <id> Staff: how far to trust a site's numbers, each check and its fix
2062
2064
  visits connect vercel|cloudflare [--site <id>] Send the host's request logs (no code to deploy)
2063
2065
  visits connectors | disconnect <id> The site's host connectors
2066
+ visits transact [on|off] [--site <id>|--host <h>] Transact: agents' questions answered from your sources, cited
2067
+ visits transact add folder <path> [--uncheck] | page <url> [--uncheck] | site <host> | file <path> | text --title <t> --text <t>
2068
+ visits transact source <source-id>|--folder <path> | remove <id> | test "<question>"
2069
+ visits transact asks [--since 7d] [--limit <n>] What agents asked, answered, and asks per agent visit
2064
2070
 
2065
2071
  Sim (Simulations: a free, simulated copy of your API for agents, and what they did with it):
2066
2072
  sim [list] Your simulations and their URLs
@@ -6,6 +6,7 @@
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
8
  // letterstory usage posthog connect --project <id> --key <phx_…> [--posthog-host eu.posthog.com] [--host app.acme.com]
9
+ // [--internal-accounts accounts.json] confirmed account IDs for new Proofs suggestions
9
10
  // connect PostHog for good: 90 days now, then daily
10
11
  // letterstory usage posthog [status]|sync [--days 7]|disconnect the connection (never its key), sync now, remove it
11
12
  // letterstory usage case-study [--days 7|30|90] the patterns and the latest case study
@@ -40,6 +41,12 @@ export const ARGS = {
40
41
  reset: { flag: "clear-choice", type: "bool" },
41
42
  },
42
43
  connect_proof_database: {
44
+ known_internal_accounts: {
45
+ value: (flags) =>
46
+ flags["internal-accounts"]
47
+ ? JSON.parse(readFileSync(String(flags["internal-accounts"]), "utf8"))
48
+ : undefined,
49
+ },
43
50
  project_ref: { flag: "project" },
44
51
  host: { flag: "host" },
45
52
  access_token: { flag: "key" },
@@ -62,12 +69,18 @@ export const ARGS = {
62
69
  focus: { flag: "focus" },
63
70
  source: { flag: "source" },
64
71
  },
72
+ compare_proof_actions: {
73
+ previous_choice_id: { flag: "previous-choice-id" },
74
+ choice_id: { flag: "choice-id" },
75
+ window: { value: (flags) => ({ since: flags.since, until: flags.until }) },
76
+ },
65
77
  refresh_proof_actions: {},
66
78
  get_proof_actions: { id: { flag: "id" } },
67
79
  decide_proof_action: {
68
80
  analysis_id: { flag: "analysis-id" },
69
81
  card_id: { flag: "card-id" },
70
82
  decision: { flag: "decision" },
83
+ replace_choice_id: { flag: "replace-choice-id" },
71
84
  },
72
85
  instrument_proof_action: {
73
86
  action: { flag: "action" },
@@ -121,6 +134,12 @@ export const ARGS = {
121
134
  dry_run: { flag: "dry-run", type: "bool" },
122
135
  },
123
136
  connect_posthog_usage: {
137
+ known_internal_accounts: {
138
+ value: (flags) =>
139
+ flags["internal-accounts"]
140
+ ? JSON.parse(readFileSync(String(flags["internal-accounts"]), "utf8"))
141
+ : undefined,
142
+ },
124
143
  project_id: { flag: "project" },
125
144
  // --key, or POSTHOG_PERSONAL_API_KEY so the key stays out of the shell's history.
126
145
  personal_api_key: {
@@ -278,9 +297,10 @@ export async function cmdUsage(ctx) {
278
297
  printResult(io, flags, await client.callTool(tool, argsFromFlags(ARGS[tool], flags, [])));
279
298
  return 0;
280
299
  }
281
- if (["proofs", "find-proofs", "review-proof", "refresh-proofs"].includes(ctx.positionals[0])) {
300
+ if (["proofs", "find-proofs", "review-proof", "refresh-proofs", "compare-proofs"].includes(ctx.positionals[0])) {
282
301
  const tool = {
283
302
  proofs: "get_proof_actions",
303
+ "compare-proofs": "compare_proof_actions",
284
304
  "refresh-proofs": "refresh_proof_actions",
285
305
  "find-proofs": "generate_proof_actions",
286
306
  "review-proof": "decide_proof_action",
@@ -19,7 +19,16 @@
19
19
  // letterstory visits connect vercel|cloudflare send the host's request logs (no code to deploy)
20
20
  // letterstory visits connectors | disconnect <id>
21
21
  // letterstory visits shortcut [mod+e | default] your own key for Letter Edit's card (⌘L by default)
22
+ // letterstory visits transact [on|off] [--host acme.com] Transact: agents' questions answered from your sources, cited
23
+ // letterstory visits transact add folder /blog [--uncheck] | page <url> [--uncheck] | site docs.acme.com
24
+ // letterstory visits transact add file ./faq.pdf | text --title Support --text "…"
25
+ // letterstory visits transact source <source-id> | --folder /docs
26
+ // letterstory visits transact remove <source-id>
27
+ // letterstory visits transact test "What does it cost?"
28
+ // letterstory visits transact asks [--since 7d] [--limit 50]
22
29
 
30
+ import { readFileSync } from "node:fs";
31
+ import { basename } from "node:path";
23
32
  import { CliError } from "../client.mjs";
24
33
  import { flagStr, printResult, argsFromFlags } from "./shared.mjs";
25
34
 
@@ -86,6 +95,62 @@ export const ARGS = {
86
95
  path: "path",
87
96
  purpose: { flag: "purpose", enum: PURPOSES },
88
97
  },
98
+ visitors_set_modules: {
99
+ site_id: "site",
100
+ agent_visitors: { internal: "visits transact on|off switches transact only" },
101
+ editor: { internal: "visits transact on|off switches transact only" },
102
+ transact: { value: (flags, positionals) => ({ on: true, off: false })[positionals[0]] },
103
+ },
104
+ visitors_get_transact: { site_id: "site", host: "host" },
105
+ visitors_add_transact_source: {
106
+ site_id: "site",
107
+ kind: {
108
+ positional: 0,
109
+ label: "kind (folder | page | site | file | text)",
110
+ required: true,
111
+ enum: ["folder", "page", "site", "file", "text"],
112
+ },
113
+ path: {
114
+ value: (flags, positionals) =>
115
+ positionals[0] === "folder" || (positionals[0] === "page" && !/^https?:/i.test(positionals[1] ?? ""))
116
+ ? positionals[1]
117
+ : undefined,
118
+ },
119
+ url: {
120
+ value: (flags, positionals) =>
121
+ positionals[0] === "page" && /^https?:/i.test(positionals[1] ?? "") ? positionals[1] : undefined,
122
+ },
123
+ host: {
124
+ value: (flags, positionals) => (positionals[0] === "site" ? positionals[1] : flagStr(flags.host)),
125
+ },
126
+ checked: { flag: "uncheck", type: "bool", invert: true },
127
+ title: "title",
128
+ text: "text",
129
+ file_name: {
130
+ value: (flags, positionals) => (positionals[0] === "file" ? basename(positionals[1] ?? "") : undefined),
131
+ },
132
+ content_base64: {
133
+ value: (flags, positionals) =>
134
+ positionals[0] === "file" && positionals[1]
135
+ ? readFileSync(positionals[1]).toString("base64")
136
+ : undefined,
137
+ },
138
+ },
139
+ visitors_get_transact_source: {
140
+ site_id: "site",
141
+ source_id: { positional: 0, label: "source id" },
142
+ folder: "folder",
143
+ limit: { flag: "limit", type: "num" },
144
+ },
145
+ visitors_test_transact: {
146
+ site_id: "site",
147
+ question: { positional: 0, label: "question", required: true },
148
+ },
149
+ visitors_remove_transact_source: {
150
+ site_id: "site",
151
+ source_id: { positional: 0, label: "source id", required: true },
152
+ },
153
+ visitors_list_transact_asks: { site_id: "site", days, limit: { flag: "limit", type: "num" } },
89
154
  visitors_export: {
90
155
  site_id: "site",
91
156
  days,
@@ -147,9 +212,11 @@ export async function cmdVisits(ctx) {
147
212
  return visitsDisconnect(rest);
148
213
  case "shortcut":
149
214
  return visitsShortcut(rest);
215
+ case "transact":
216
+ return visitsTransact(rest);
150
217
  default:
151
218
  throw new CliError(
152
- "Usage: visits [list|citations|people|who|compare|export|sites|domain|pages|health|connect|connectors|disconnect|shortcut]"
219
+ "Usage: visits [list|citations|people|who|compare|export|sites|domain|pages|health|connect|connectors|disconnect|shortcut|transact]"
153
220
  );
154
221
  }
155
222
  }
@@ -237,6 +304,89 @@ async function visitsDisconnect(ctx) {
237
304
  return 0;
238
305
  }
239
306
 
307
+ /** Transact on a site, as the CLI prints it: its state and URL, the folders, then everything else chosen. */
308
+ function transactLines(t) {
309
+ const state = { off: "off", unproven: "on, served once the site is proven", on: "on" }[t.state] ?? t.state;
310
+ const lines = [`Transact: ${state}`];
311
+ if (t.url) lines.push(` ${t.url}`, ` MCP ${t.mcp_url}`);
312
+ lines.push("", `${t.host ?? "This site"} (${t.read} of ${t.in_set} pages read):`);
313
+ if (!t.folders.length) lines.push(" no pages mapped yet");
314
+ for (const f of t.folders)
315
+ lines.push(
316
+ ` [${f.checked ? "x" : " "}] ${f.path === "/" ? "/ (home)" : f.path} ${f.pages} ${f.pages === 1 ? "page" : "pages"} cited ${f.times_cited}${f.failed ? ` ${f.failed} failed` : ""}${f.by_default ? "" : " (yours)"}${f.id ? ` ${f.id}` : ""}`
317
+ );
318
+ if (t.sources.length) lines.push("", "Added:");
319
+ for (const s of t.sources) {
320
+ const what = s.snapshot ? `snapshot, ${s.chars} characters` : `${s.pages} ${s.pages === 1 ? "page" : "pages"}`;
321
+ lines.push(` ${s.id} ${s.kind} ${s.title} ${what} cited ${s.times_cited}`);
322
+ }
323
+ return lines;
324
+ }
325
+
326
+ /** `visits transact`: read it; `on` / `off`; `add <kind> …`; `source <id>`; `remove <id>`; `test "…"`; `asks`. */
327
+ async function visitsTransact(ctx) {
328
+ const { flags, io } = ctx;
329
+ const sub = ctx.positionals[0];
330
+ const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
331
+ if (sub === "on" || sub === "off") {
332
+ const result = await call(ctx, "visitors_set_modules");
333
+ printResult(io, flags, result, (r) => `Transact ${r.modules.transact ? "on" : "off"}`);
334
+ return 0;
335
+ }
336
+ if (sub === "add") {
337
+ const result = await call(rest, "visitors_add_transact_source");
338
+ printResult(io, flags, result, (r) => `Saved: ${r.source_id}`);
339
+ return 0;
340
+ }
341
+ if (sub === "source") {
342
+ const result = await call(rest, "visitors_get_transact_source");
343
+ printResult(io, flags, result, (r) =>
344
+ [
345
+ `${r.total} pages`,
346
+ ...r.pages.map(
347
+ (p) =>
348
+ ` [${p.in_set ? "x" : " "}] ${p.path} ${p.error ? `failed: ${p.error}` : p.read_at ? `read ${p.read_at.slice(0, 16)}` : "not read"}`
349
+ ),
350
+ ].join("\n")
351
+ );
352
+ return 0;
353
+ }
354
+ if (sub === "remove") {
355
+ const result = await call(rest, "visitors_remove_transact_source");
356
+ printResult(io, flags, result, () => "Removed");
357
+ return 0;
358
+ }
359
+ if (sub === "test") {
360
+ const result = await call(rest, "visitors_test_transact");
361
+ printResult(io, flags, result, (r) =>
362
+ [
363
+ r.answer,
364
+ ...r.citations.map((c) => ` [${c.n}] ${c.title}${c.url ? ` ${c.url}` : ""}: "${c.quote}"`),
365
+ ].join("\n")
366
+ );
367
+ return 0;
368
+ }
369
+ if (sub === "asks") {
370
+ const result = await call(rest, "visitors_list_transact_asks");
371
+ printResult(io, flags, result, (r) => {
372
+ const c = r.counts;
373
+ const visits = c.agent_visits === null ? "" : `, ${c.agent_visits} AI agent visits`;
374
+ const lines = [
375
+ `${c.asks} asks since ${r.since.slice(0, 10)}: ${c.answered} answered, ${c.agents} agents${visits}`,
376
+ ];
377
+ for (const a of r.asks)
378
+ lines.push(` ${a.created_at.slice(0, 16)} ${a.test ? "test" : a.agent} ${a.outcome} ${a.question}`);
379
+ return lines.join("\n");
380
+ });
381
+ return 0;
382
+ }
383
+ if (sub !== undefined)
384
+ throw new CliError("Usage: visits transact [on|off|add <kind>|source <id>|remove <id>|test|asks]");
385
+ const result = await call(ctx, "visitors_get_transact");
386
+ printResult(io, flags, result, (t) => transactLines(t).join("\n"));
387
+ return 0;
388
+ }
389
+
240
390
  const PURPOSE_LABELS = {
241
391
  live: "answering a user",
242
392
  index: "search index",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.177.84",
3
+ "version": "0.177.86",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",