@letterstory/cli 0.177.208 → 0.177.209

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
@@ -93,7 +93,7 @@ import {
93
93
  import { fetchParkedSections, withoutParked } from "./parked.mjs";
94
94
 
95
95
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
96
- export const VERSION = "0.177.208";
96
+ export const VERSION = "0.177.209";
97
97
 
98
98
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
99
99
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -117,8 +117,9 @@ export const BOOLEAN_FLAGS = new Set([
117
117
  // org overview: only what waits on someone (the More menu's closed read).
118
118
  "needs-only",
119
119
  "include-tests",
120
- // visits agent-sites: test orgs too.
120
+ // visits agent-sites: test orgs too; also count what reached the sites in the window.
121
121
  "include-test",
122
+ "figures",
122
123
  // visits transact asks --before: page the team's tests instead of agents' asks.
123
124
  "tests",
124
125
  "as-test",
@@ -162,6 +163,8 @@ export const BOOLEAN_FLAGS = new Set([
162
163
  "presses",
163
164
  // admin lost-posts: held posts back to the rework with the draft unchanged.
164
165
  "rework",
166
+ // admin studies <id> --export: the plan, the rules, one row per attempt and the totals.
167
+ "export",
165
168
  // admin targets check: check every target again, checked or not.
166
169
  "recheck",
167
170
  // build list: also move the builds' open changes along while polling.
@@ -1257,6 +1260,18 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
1257
1260
  never published. Lists what it would requeue; --apply puts
1258
1261
  them back to work. --code held_guard takes a held post
1259
1262
  once its draft was edited. Staff.
1263
+ admin studies [<study-id>] [--export] [--limit <n>]
1264
+ Agent research studies: what ChatGPT, Claude and Google AI
1265
+ Mode did with a website task. No id lists them; an id shows
1266
+ its counts and the task-by-product matrix; --export is the
1267
+ plan, the rules, a row per attempt and the totals. Staff only.
1268
+ admin study-start (--preset acceptance|discovery|site_change | --site <address> --task "<task>" [--expect "<words>"]
1269
+ [--entry address|need] [--repeats <n>] [--products chatgpt,claude,google_ai_mode,gemini]
1270
+ | --manifest-file <plan.json>) [--preview]
1271
+ Start a study: a fresh session per trial on the product
1272
+ itself. --preview saves nothing and prints the estimate.
1273
+ Browser time is Letter's cost; product cost is unknown.
1274
+ admin study-stop <study-id> [--resume] Stop a running study, or take a stopped one up again.
1260
1275
  admin targets check [--org <id>,…] [--recheck] [--limit 10]
1261
1276
  Check ranking targets' phrases (buyer intent, self-named,
1262
1277
  search demand, fit) and store each verdict: --org those
@@ -2168,7 +2183,9 @@ Visits (Visitors: AI agents reading your site, and AI answers sending people to
2168
2183
  visits pages [--since 28d] [--path '/docs/*'] [--agent <id>] [--limit <n>] [--site <id>]
2169
2184
  People and AI agents per page
2170
2185
  visits health --site <id> Staff: how far to trust a site's numbers, each check and its fix
2171
- visits agent-sites [--include-test] Staff: every agent site by stage, waiting on a person first
2186
+ visits agent-sites [--include-test] [--figures] [--from <ISO>] [--to <ISO>]
2187
+ Staff: every agent site by stage, waiting on a person first;
2188
+ --figures counts requests and Asks in the window (7 days)
2172
2189
  visits connect vercel|cloudflare [--site <id>] Send the host's request logs (no code to deploy)
2173
2190
  visits connectors | disconnect <id> The site's host connectors
2174
2191
  visits transact [--site <id>|--host <h>] Transact: cited public corpus answers with website fallback
@@ -91,6 +91,32 @@ export const ARGS = {
91
91
  limit: { flag: "limit", type: "num" },
92
92
  presses: { flag: "presses", type: "bool" },
93
93
  },
94
+ // `admin studies`: every study, one study, or one study's export.
95
+ agent_studies_get: {
96
+ study_id: { positional: 0, label: "study id" },
97
+ export: { flag: "export", type: "bool" },
98
+ limit: { flag: "limit", type: "num" },
99
+ },
100
+ // `admin study-start`: a preset, one task on one site, or a whole plan from a file.
101
+ agent_studies_start: {
102
+ quick: {
103
+ object: {
104
+ site: "site",
105
+ task: "task",
106
+ expect: "expect",
107
+ entry: { flag: "entry", enum: ["address", "need"] },
108
+ products: { value: (flags) => (flags.products ? flagCsv(flags.products) : undefined) },
109
+ repeats: { flag: "repeats", type: "num" },
110
+ },
111
+ },
112
+ preset: { flag: "preset", enum: ["acceptance", "discovery", "site_change"] },
113
+ manifest: { value: (flags) => jsonFile(flags, "manifest") },
114
+ preview: { flag: "preview", type: "bool" },
115
+ },
116
+ agent_studies_stop: {
117
+ study_id: { positional: 0, label: "study id", required: true },
118
+ resume: { flag: "resume", type: "bool" },
119
+ },
94
120
  };
95
121
 
96
122
  const INVARIANT_LIMIT = 30;
@@ -168,6 +194,138 @@ async function cmdAdminLostPosts(ctx) {
168
194
  );
169
195
  return 0;
170
196
  }
197
+ const STUDIES_USAGE = `Usage: admin studies [<study-id>] [--export] [--limit <n>]
198
+ admin study-start (--preset acceptance|discovery|site_change | --site <address> --task "<task>" [--expect "<words>"]
199
+ [--entry address|need] [--repeats <n>] [--products chatgpt,claude,google_ai_mode,gemini]
200
+ | --manifest-file <plan.json>) [--preview]
201
+ admin study-stop <study-id> [--resume]`;
202
+
203
+ /** One run as one character, the same reading as the matrix on /superadmin/agent-sites. */
204
+ const STUDY_MARK = {
205
+ verified: "●",
206
+ partial: "◐",
207
+ not_met: "✕",
208
+ valid_other: "◇",
209
+ ungraded: "◌",
210
+ excluded: "⊘",
211
+ unavailable: "–",
212
+ failed: "!",
213
+ running: "…",
214
+ planned: "○",
215
+ };
216
+ const STUDY_MARK_KEY = Object.entries(STUDY_MARK)
217
+ .map(([mark, sign]) => `${sign} ${mark.replace("_", " ")}`)
218
+ .join(" ");
219
+
220
+ const studyCounts = (c) =>
221
+ `planned ${c.planned} · attempted ${c.attempted} · completed ${c.completed} · graded ${c.graded} · verified ${c.verified} · excluded ${c.excluded} · failed ${c.failed} · unavailable ${c.unavailable}`;
222
+
223
+ const studyEstimate = (e) =>
224
+ [
225
+ `${e.trials} trial(s): ${Object.entries(e.by_product)
226
+ .map(([product, n]) => `${product} ${n}`)
227
+ .join(", ")}`,
228
+ `About ${e.minutes} min, ${e.browser_minutes} browser min. Product cost is unknown.`,
229
+ ...e.skipped.map((s) => `Skipped ${s.task}/${s.condition}: ${s.reason}`),
230
+ ].join("\n");
231
+
232
+ /** One study: its counts, then the matrix a row per task and condition, each product's verified/graded and marks. */
233
+ function formatStudy(study) {
234
+ const lines = [
235
+ study.question,
236
+ `${study.status}${study.imported ? " · imported" : ""} · ${study.id}`,
237
+ studyCounts(study.counts),
238
+ ];
239
+ if (study.finding) lines.push(`Finding: ${study.finding}`);
240
+ lines.push("");
241
+ for (const row of study.matrix) {
242
+ lines.push(`${row.label} (${row.site})`);
243
+ for (const cell of row.cells)
244
+ lines.push(
245
+ ` ${cell.product.padEnd(15)} ${`${cell.verified}/${cell.graded}`.padEnd(5)} ${cell.runs.map((r) => STUDY_MARK[r.mark] ?? "?").join("")}`
246
+ );
247
+ }
248
+ lines.push("", `verified/graded per cell. ${STUDY_MARK_KEY}`);
249
+ if (study.patterns.length) {
250
+ lines.push("", "Recurring:");
251
+ for (const p of study.patterns.slice(0, 8))
252
+ lines.push(` ${p.hits}/${p.of} ${p.kind} ${p.label} (${p.products.join(", ")}) e.g. ${p.example}`);
253
+ }
254
+ const e = study.efficiency;
255
+ lines.push(
256
+ "",
257
+ `Median ${e.median_secs ?? "?"}s a run · ${e.secs_per_verified ?? "?"}s per verified run · cost per verified run ${e.cost_per_verified === null ? "unknown" : `$${e.cost_per_verified.toFixed(4)}`}`
258
+ );
259
+ return lines.join("\n");
260
+ }
261
+
262
+ // `admin studies` / `admin study-start` / `admin study-stop`: agent research studies
263
+ // (docs/architecture/agent-research.md), the same functions Super Admin → Agent sites → Experiments calls.
264
+ // agent_studies_get, agent_studies_start, agent_studies_stop; staff only.
265
+ async function cmdAdminStudies(ctx, sub) {
266
+ const { client, flags, io, positionals } = ctx;
267
+ if (sub === "studies") {
268
+ const result = await client.callTool(
269
+ "agent_studies_get",
270
+ argsFromFlags(ARGS.agent_studies_get, flags, positionals)
271
+ );
272
+ printResult(io, flags, result, (r) => {
273
+ if (r.study) return formatStudy(r.study);
274
+ if (r.export) {
275
+ const a = r.export.aggregates;
276
+ return [
277
+ `${r.export.rows.length} attempt row(s), ${r.export.columns.length} column(s). --json prints the plan, the rules, the rows and the totals.`,
278
+ studyCounts(a.counts),
279
+ `Recomputed from the rows: planned ${a.recomputed.planned} · completed ${a.recomputed.completed} · graded ${a.recomputed.graded} · verified ${a.recomputed.verified} · excluded ${a.recomputed.excluded}`,
280
+ ].join("\n");
281
+ }
282
+ const studies = r.studies ?? [];
283
+ return [
284
+ ...(studies.length ? [] : ["No studies yet."]),
285
+ ...studies.map(
286
+ (s) =>
287
+ `${s.status.padEnd(8)} ${`${s.counts.verified}/${s.counts.graded} verified`.padEnd(15)} ${`${s.counts.completed}/${s.counts.planned} done`.padEnd(12)} ${s.id} ${s.question}`
288
+ ),
289
+ "",
290
+ ...(r.products ?? []).map(
291
+ (p) => `${p.label.padEnd(15)} ${p.unavailable ? `unavailable: ${p.unavailable}` : p.mode}`
292
+ ),
293
+ ].join("\n");
294
+ });
295
+ return 0;
296
+ }
297
+ if (sub === "study-start") {
298
+ const args = argsFromFlags(ARGS.agent_studies_start, flags, positionals);
299
+ if ([args.quick, args.preset, args.manifest].filter((v) => v !== undefined).length !== 1)
300
+ throw new CliError(STUDIES_USAGE);
301
+ const result = await client.callTool("agent_studies_start", args);
302
+ printResult(io, flags, result, (r) =>
303
+ [
304
+ r.study_id ? `Study ${r.study_id} started.` : "Preview: nothing saved.",
305
+ studyEstimate(r.estimate),
306
+ ...(r.study_id ? [`Read it with: admin studies ${r.study_id}`] : []),
307
+ ].join("\n")
308
+ );
309
+ return 0;
310
+ }
311
+ if (sub === "study-stop") {
312
+ const result = await client.callTool(
313
+ "agent_studies_stop",
314
+ argsFromFlags(ARGS.agent_studies_stop, flags, positionals)
315
+ );
316
+ printResult(io, flags, result, (r) =>
317
+ "resumed" in r
318
+ ? r.resumed
319
+ ? "Resumed."
320
+ : "Not resumed: the study isn't stopped."
321
+ : r.stopped
322
+ ? "Stopped. Planned attempts stay planned."
323
+ : "Not stopped: the study isn't running."
324
+ );
325
+ return 0;
326
+ }
327
+ throw new CliError(STUDIES_USAGE);
328
+ }
171
329
  import { watchDomainJob } from "./onboard.mjs";
172
330
 
173
331
  const SEER_MODES = ["suggest", "skip"];
@@ -7833,10 +7991,12 @@ export async function cmdAdmin(ctx) {
7833
7991
  if (sub === "invariants") return cmdAdminInvariants({ ...ctx, positionals: ctx.positionals.slice(1) });
7834
7992
  if (sub === "dropoff") return cmdAdminDropoff({ ...ctx, positionals: ctx.positionals.slice(1) });
7835
7993
  if (sub === "lost-posts") return cmdAdminLostPosts({ ...ctx, positionals: ctx.positionals.slice(1) });
7994
+ if (sub === "studies" || sub === "study-start" || sub === "study-stop")
7995
+ return cmdAdminStudies({ ...ctx, positionals: ctx.positionals.slice(1) }, sub);
7836
7996
  if (sub === "deployments" || sub === "deploys")
7837
7997
  return cmdAdminDeployments({ ...ctx, positionals: ctx.positionals.slice(1) });
7838
7998
  throw new CliError(
7839
- 'Usage: admin recipes … | admin letterpress … | admin demo … | admin targets … | admin invariants … | admin dropoff … | admin lost-posts … | admin deployments … | admin republish … | admin create-org --domain <bare-domain> [--onboard] … | admin ask "<question>" | admin patterns … | admin experiments … | admin fleet-experiments … | admin crm … | admin spend … | admin evals … | admin brand-detection … | admin tuning … | admin tuning-context | admin replays … (see --help)'
7999
+ 'Usage: admin recipes … | admin letterpress … | admin demo … | admin targets … | admin invariants … | admin dropoff … | admin lost-posts … | admin studies … | admin deployments … | admin republish … | admin create-org --domain <bare-domain> [--onboard] … | admin ask "<question>" | admin patterns … | admin experiments … | admin fleet-experiments … | admin crm … | admin spend … | admin evals … | admin brand-detection … | admin tuning … | admin tuning-context | admin replays … (see --help)'
7840
8000
  );
7841
8001
  }
7842
8002
 
@@ -19,7 +19,9 @@
19
19
  // letterstory visits domain composal.com [--site <id>] move the site to a new domain, keeping its key
20
20
  // letterstory visits pages --since 28d [--path '/docs/*'] [--agent openai-crawler]
21
21
  // letterstory visits health --site <id> staff: how far to trust a site's numbers, and what to fix
22
- // letterstory visits agent-sites [--include-test] staff: every agent site by stage, waiting on a person first
22
+ // letterstory visits agent-sites [--include-test] [--figures] [--from <ISO>] [--to <ISO>]
23
+ // staff: every agent site by stage, waiting on a person first;
24
+ // --figures counts what reached them in the window (7 days)
23
25
  // letterstory visits connect vercel|cloudflare send the host's request logs (no code to deploy)
24
26
  // letterstory visits connectors | disconnect <id>
25
27
  // letterstory visits shortcut [mod+e | default] your own key for Letter Edit's card (⌘L by default)
@@ -124,6 +126,9 @@ export const ARGS = {
124
126
  visitors_admin_coverage: { site_id: "site" },
125
127
  visitors_admin_agent_sites: {
126
128
  include_test: { value: (flags) => (flagBool(flags["include-test"]) ? true : undefined) },
129
+ figures: { value: (flags) => (flagBool(flags.figures) ? true : undefined) },
130
+ from: "from",
131
+ to: "to",
127
132
  },
128
133
  visitors_add_connector: {
129
134
  site_id: "site",
@@ -391,6 +396,19 @@ async function visitsAgentSites(ctx) {
391
396
  lines.push(
392
397
  ` ${(AGENT_SITE_STAGE_WORDS[s.stage] ?? s.stage).padEnd(17)} ${s.org_name ?? s.org_id} ${s.address ?? ""}${s.since ? ` (since ${s.since.slice(0, 10)})` : ""}`
393
398
  );
399
+ const a = r.activity;
400
+ if (a) {
401
+ const q = a.requests;
402
+ const k = a.asks;
403
+ lines.push(
404
+ "",
405
+ `${a.window.from} to ${a.window.to}${a.window.clamped ? " (the 90 days kept)" : ""}`,
406
+ ` Requests ${q.total} on Agent Site hosts, ${q.sites} of ${a.population.sites} sites`,
407
+ ` ${q.verified} verified · ${q.claimed} claimed · ${q.unnamed} unnamed · ${q.not_found} not found`,
408
+ ` Asks ${k.counted} counted of ${k.rows} rows (HTTP ${k.http} · MCP ${k.mcp}), ${k.distinct} distinct`,
409
+ ` ${k.corpus} corpus · ${k.website} website · ${k.misses} not in sources · ${k.reused} reused · ${k.cited} cited`
410
+ );
411
+ }
394
412
  return lines.join("\n");
395
413
  });
396
414
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.177.208",
3
+ "version": "0.177.209",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",