@letterstory/cli 0.177.85 → 0.177.87

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.85";
93
+ export const VERSION = "0.177.87";
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
@@ -5326,7 +5326,7 @@ const BUILD_FAILURES = "/api/superadmin/build-failures";
5326
5326
  const SUGGESTION_REVIEW = "/api/superadmin/suggestion-review";
5327
5327
  const TURN_ENDINGS = "/api/superadmin/turn-endings";
5328
5328
  const ENGINE_USAGE =
5329
- "Usage: admin letterpress status | gaps | friction [--kind error|exception|rage|step] [--surface s] [--org id] [--limit N] | asks [--days N] [--surface cmd_l|build_chat|slack|terminal|app|signup|letter] [--people | --letter] [--door d] [--whose ours|agent|setup|member] [--org id] [--limit N] | telemetry [--days N] [--harness h] [--all-orgs] | tokens [--days N] [--so-far] [--all-orgs] | prs [--days N | --from YYYY-MM-DD [--to YYYY-MM-DD] | --all-time] [--day YYYY-MM-DD] [--org id] [--state merged|open|closed] [--top N] [--tz zone] [--all-orgs] | failures [--days N | --from YYYY-MM-DD [--to YYYY-MM-DD] | --all-time] [--day YYYY-MM-DD] [--org id] [--failure ours|agent|setup|undelivered] [--cause c] [--stopped-at step] [--repo owner/name] [--slow] [--tz zone] [--all-orgs] | blocked [--days N] [--org id] [--all-orgs] | endings [--days N | --since ISO] [--org id,id] [--no-model] [--top N] [--write-cases [--dir evals/letterpress]] | unblock <org-id> <host> <subject> | decisions <org-id> [--site host] [--surface plan|fix|build|site] | undo <org-id> <host> <decision-id> | runs [--status s] [--error-code c] [--first-review-cause agent|context|setup|unknown] [--pr merged|closed|open|none] [--harness h] [--days N] | beyond [--limit N] [--before ISO] | companies | company <org-id> [--site host] | ideas <org-id> [--site host] [--repo connected|none] | suggestions fix|idea [--day YYYY-MM-DD] [--type key [--org id]] [--all-orgs] | suggestions flag fix|idea <type-key> [--org id --item item-id] [--note …] | suggestions clear <flag-id> | facts <org-id> [--site host] | fits [--recipe id] [--org id] [--site host] [--fits yes|no|unknown|waiting] [--limit N] | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|gap|recipe|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|preflight.off|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5329
+ "Usage: admin letterpress status | gaps | friction [--kind error|exception|rage|step|server|stall|background] [--surface s] [--org id] [--limit N] | tools [--days N] [--org id] [--all-orgs] | checks | frustration [--days N] | health | asks [--days N] [--surface cmd_l|build_chat|slack|terminal|app|signup|letter] [--people | --letter] [--door d] [--whose ours|agent|setup|member] [--org id] [--limit N] | telemetry [--days N] [--harness h] [--all-orgs] | tokens [--days N] [--so-far] [--all-orgs] | prs [--days N | --from YYYY-MM-DD [--to YYYY-MM-DD] | --all-time] [--day YYYY-MM-DD] [--org id] [--state merged|open|closed] [--top N] [--tz zone] [--all-orgs] | failures [--days N | --from YYYY-MM-DD [--to YYYY-MM-DD] | --all-time] [--day YYYY-MM-DD] [--org id] [--failure ours|agent|setup|undelivered] [--cause c] [--stopped-at step] [--repo owner/name] [--slow] [--tz zone] [--all-orgs] | blocked [--days N] [--org id] [--all-orgs] | endings [--days N | --since ISO] [--org id,id] [--no-model] [--top N] [--write-cases [--dir evals/letterpress]] | unblock <org-id> <host> <subject> | decisions <org-id> [--site host] [--surface plan|fix|build|site] | undo <org-id> <host> <decision-id> | runs [--status s] [--error-code c] [--first-review-cause agent|context|setup|unknown] [--pr merged|closed|open|none] [--harness h] [--days N] | beyond [--limit N] [--before ISO] | companies | company <org-id> [--site host] | ideas <org-id> [--site host] [--repo connected|none] | suggestions fix|idea [--day YYYY-MM-DD] [--type key [--org id]] [--all-orgs] | suggestions flag fix|idea <type-key> [--org id --item item-id] [--note …] | suggestions clear <flag-id> | facts <org-id> [--site host] | fits [--recipe id] [--org id] [--site host] [--fits yes|no|unknown|waiting] [--limit N] | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|gap|recipe|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|preflight.off|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
5330
5330
 
5331
5331
  /** One number of the settings from a dotted path and a value: the PUT body save_engine_settings reads. */
5332
5332
  function engineSettingsPatch(path, value) {
@@ -5488,10 +5488,10 @@ async function cmdAdminLetterpress(ctx) {
5488
5488
  const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5489
5489
  printResult(io, flags, r, (f) =>
5490
5490
  [
5491
- `Seen by members this week${f.computed_at ? ` (read ${f.computed_at}${f.stale ? ", stale" : ""})` : ""}: ${f.totals.kinds} kinds of trouble in ${f.totals.orgs} organizations, ${f.totals.new} new, ${f.totals.spiking} spiking`,
5491
+ `Got in the way this week${f.computed_at ? ` (read ${f.computed_at}${f.stale ? ", stale" : ""})` : ""}: ${f.totals.kinds} kinds of trouble in ${f.totals.orgs} organizations, ${f.totals.new} new, ${f.totals.spiking} spiking`,
5492
5492
  ...f.rows.map(
5493
5493
  (x) =>
5494
- `${String(x.people).padStart(4)} people ${x.kind.padEnd(9)} ${x.is_new ? "NEW " : x.spiking ? "UP " : " "}${x.message.slice(0, 90)} ${x.pages[0] ?? ""} ${x.orgs
5494
+ `${String(x.people).padStart(4)} ${["server", "stall", "background"].includes(x.kind) ? "orgs " : "people"} ${x.kind.padEnd(10)} ${x.is_new ? "NEW " : x.spiking ? "UP " : " "}${x.message.slice(0, 90)} ${x.pages[0] ?? ""} ${x.orgs
5495
5495
  .map((o) => o.name)
5496
5496
  .slice(0, 3)
5497
5497
  .join(", ")}${x.replays[0] ? ` ${x.replays[0]}` : ""}`
@@ -5500,6 +5500,69 @@ async function cmdAdminLetterpress(ctx) {
5500
5500
  );
5501
5501
  return 0;
5502
5502
  }
5503
+ case "tools": {
5504
+ // get_tool_failures: each Letterpress tool's failures inside turns.
5505
+ const q = new URLSearchParams({ view: "tools", days: String(flags.days ?? 7) });
5506
+ if (flagBool(flags["all-orgs"])) q.set("customers", "0");
5507
+ if (flags.org) q.set("org_id", String(flags.org));
5508
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5509
+ printResult(io, flags, r, (t) =>
5510
+ [
5511
+ `Tools that failed, last ${t.days} days (${t.turns} turns)`,
5512
+ ...t.rows.map(
5513
+ (x) =>
5514
+ `${String(x.failed).padStart(4)} of ${String(x.calls).padEnd(5)} ${x.tool.padEnd(32)} ${x.orgs} orgs ${x.top_reason ?? ""}`
5515
+ ),
5516
+ ].join("\n")
5517
+ );
5518
+ return 0;
5519
+ }
5520
+ case "checks": {
5521
+ // get_ideas_checks: what the newest hourly Ideas checks found.
5522
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?view=ideas_checks`);
5523
+ printResult(io, flags, r, (c) =>
5524
+ [
5525
+ c.checked_at
5526
+ ? `Ideas checks ${c.checked_at}: ${c.total} broken on ${c.accounts} accounts, ${c.unread} unread, ${c.undecided_fits} fits undecided`
5527
+ : `No Ideas check has run yet; ${c.undecided_fits} fits undecided`,
5528
+ ...c.checks.map(
5529
+ (g) =>
5530
+ `${String(g.count).padStart(4)} ${g.invariant.padEnd(22)} ${g.owner.padEnd(10)} ${g.examples[0] ? `${g.examples[0].host}: ${g.examples[0].evidence}` : ""}`
5531
+ ),
5532
+ ].join("\n")
5533
+ );
5534
+ return 0;
5535
+ }
5536
+ case "frustration": {
5537
+ // get_frustration_flags: the frustration watch's flags.
5538
+ const q = new URLSearchParams({ view: "frustration", days: String(flags.days ?? 7) });
5539
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?${q}`);
5540
+ printResult(io, flags, r, (f) =>
5541
+ [
5542
+ `Frustration watch, last ${f.days} days: ${f.flags.length} flags from ${f.runs} runs${f.failed_runs ? `, ${f.failed_runs} failed` : ""}`,
5543
+ ...f.flags.map(
5544
+ (x) =>
5545
+ `${x.at.slice(0, 16)} ${x.severity.padEnd(6)} ${x.company}: ${x.happened}${x.next_step ? ` → ${x.next_step}` : ""}`
5546
+ ),
5547
+ ].join("\n")
5548
+ );
5549
+ return 0;
5550
+ }
5551
+ case "health": {
5552
+ // get_customer_health: the Status checks stopping customer work right now.
5553
+ const r = await staffRequest(ctx, "GET", `${CODING_TELEMETRY}?view=health`);
5554
+ printResult(io, flags, r, (h) =>
5555
+ h.stopping.length
5556
+ ? h.stopping
5557
+ .map(
5558
+ (c) =>
5559
+ `${c.state.padEnd(5)} ${c.title}: ${c.headline ?? ""}${c.since ? ` (since ${c.since})` : ""}`
5560
+ )
5561
+ .join("\n")
5562
+ : "Nothing is stopping customer work."
5563
+ );
5564
+ return 0;
5565
+ }
5503
5566
  case "asks": {
5504
5567
  // get_ask_outcomes: did each ask end with what was asked (docs/architecture/failure-visibility.md).
5505
5568
  const q = new URLSearchParams({ view: "asks", days: String(flags.days ?? 7) });
@@ -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.85",
3
+ "version": "0.177.87",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",