@letterstory/cli 0.167.1 → 0.168.0

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
@@ -75,7 +75,7 @@ import {
75
75
  } from "./commands.mjs";
76
76
 
77
77
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
78
- export const VERSION = "0.167.1";
78
+ export const VERSION = "0.168.0";
79
79
 
80
80
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
81
81
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -159,11 +159,6 @@ export const BOOLEAN_FLAGS = new Set([
159
159
  "enroll",
160
160
  "unenroll",
161
161
  "clean-slate",
162
- // admin recipes list --tab --enabled-only, save --enable|--disable, import --retire-missing
163
- "enabled-only",
164
- "enable",
165
- "disable",
166
- "retire-missing",
167
162
  // admin crm record-outcome --draft
168
163
  "draft",
169
164
  // admin crm reach-outs --fresh
@@ -892,28 +887,22 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
892
887
  read-only SQL across every org; --sql prints
893
888
  the queries behind the answer. Needs the
894
889
  fleet:query capability on the staff key.
895
- admin recipes list [--tab plan|build|fix] [--enabled-only] | show <id|name> | vocab | stats
896
- Recipes: Letter's one library of direction for
897
- Letterpress on Plan, Build and Fix (/superadmin/recipes).
898
- vocab says what a recipe can say (tabs, fields, the
899
- catalog actions a plan recipe's moves may name, outcomes,
900
- company types, primitives); stats how each recipe's
901
- suggestions fare. Needs recipes:read.
902
- admin recipes export [--tab …] [--out recipes.json] The library as a file import reads back.
903
- admin recipes import <file> [--dry-run] [--retire-missing]
904
- Write a library in one call: each recipe matched by id,
905
- else tab and name, then changed or created. --dry-run
906
- writes nothing; --retire-missing retires every enabled
907
- recipe of the file's tabs it leaves out. Exits 1 if any
908
- row failed.
909
- admin recipes save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …]
910
- [--when-not-to-use …] [--example …] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none]
911
- [--company-types a,b|none] [--enable|--disable] [--position n]
890
+ admin recipes list | show <id|name> | vocab | stats Recipes: Letter's one library of direction for
891
+ Letterpress on Plan, Build and Fix (/superadmin/recipes),
892
+ five fields each: name, recipe, when to use, when not to
893
+ use, weight. vocab says what each field means; stats how
894
+ each recipe's suggestions fare. Needs recipes:read.
895
+ admin recipes export [--out recipes.json] The library as a file import reads back.
896
+ admin recipes import <file> [--dry-run] Write a library in one call: each recipe matched by id,
897
+ else name, then changed or created. --dry-run writes
898
+ nothing. Exits 1 if any row failed.
899
+ admin recipes save [<id>] [--file <recipe.json>] [--name …] [--recipe …] [--when-to-use …]
900
+ [--when-not-to-use …] [--weight 1..10]
912
901
  Create one (no id) or change one. Needs recipes:write.
913
- admin recipes delete <id> --yes Delete for good (save --disable retires and keeps it).
902
+ admin recipes delete <id> --yes Delete for good.
914
903
  admin letterpress status [--customers] Letterpress as it runs now: per lens its mode, bar, recipes,
915
904
  runs, model and prompt hash, how often the shadow agreed,
916
- how runs grounded (full / part / none). Needs recipes:read.
905
+ how runs grounded (a recipe / none). Needs recipes:read.
917
906
  admin letterpress gaps [--customers] The gaps the numbers show, each with the one call that
918
907
  addresses it, pre-filled. Needs recipes:read.
919
908
  admin letterpress replay <run-id> A Build or Fix run through today's checks and settings, no
@@ -1477,6 +1466,7 @@ Insights:
1477
1466
  Measure → Reads: AI engines and people reading your sites, counted one way
1478
1467
  insights questions [--period 14d|30d|90d] Measure → Questions: every question we ask, named / share / change / cited
1479
1468
  insights pages [--period 14d|30d|90d] [--site own|phantoms|<key>] Measure → Pages: your pages AI answers cited, won questions first
1469
+ insights mentions [--site phantoms|<key>]... Measure → Pages → Naming you: which posts on your phantom sites name you
1480
1470
  insights competitors [--period 14d|30d|90d] GEO → Competitors: share of mentions per brand, is it moving, by engine/question
1481
1471
  insights question <key> [--period 14d|30d|90d] [--filter all|named_you|rival_not_you|no_one] [--limit n]
1482
1472
  One By-question row: the wordings asked and the AI answers
@@ -4932,58 +4932,23 @@ async function cmdAdminRepublish(ctx) {
4932
4932
 
4933
4933
  const RECIPES = "/api/superadmin/recipes";
4934
4934
  /** The fields a recipe file carries: what import_recipes reads back. */
4935
- const RECIPE_FILE_FIELDS = [
4936
- "id",
4937
- "name",
4938
- "tab",
4939
- "outcomes",
4940
- "company_types",
4941
- "fits_when",
4942
- "look_at",
4943
- "when_to_use",
4944
- "when_not_to_use",
4945
- "example",
4946
- "impact",
4947
- "moves",
4948
- "primitives",
4949
- "enabled",
4950
- "position",
4951
- ];
4935
+ const RECIPE_FILE_FIELDS = ["id", "name", "recipe", "when_to_use", "when_not_to_use", "weight"];
4952
4936
  const RECIPES_USAGE =
4953
- "Usage: admin recipes list [--tab plan|build|fix] [--enabled-only] | show <id|name> | vocab | stats | export [--tab …] [--out <file>] | import <file> [--dry-run] [--retire-missing] | save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …] [--when-not-to-use …] [--example …] [--impact 1..10] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none] [--enable|--disable] [--position n] | delete <id> --yes";
4937
+ "Usage: admin recipes list | show <id|name> | vocab | stats | export [--out <file>] | import <file> [--dry-run] | save [<id>] [--file <recipe.json>] [--name …] [--recipe …] [--when-to-use …] [--when-not-to-use …] [--weight 1..10] | delete <id> --yes";
4954
4938
 
4955
4939
  const recipeForFile = (r) => Object.fromEntries(RECIPE_FILE_FIELDS.map((k) => [k, r[k]]));
4956
4940
 
4957
4941
  function recipeLine(r) {
4958
- const scope = [
4959
- r.outcomes?.length ? `outcomes ${r.outcomes.join(",")}` : "every outcome",
4960
- r.company_types?.length ? `kinds ${r.company_types.join(",")}` : "every kind",
4961
- r.tab === "plan"
4962
- ? `${r.moves?.length ?? 0} moves · stands up ${r.primitives?.length ? r.primitives.join(",") : "nothing"}`
4963
- : null,
4964
- ]
4965
- .filter(Boolean)
4966
- .join(" · ");
4967
- return `${String(r.position).padStart(4)} ${r.enabled ? "on " : "off"} ${r.tab.padEnd(5)} ${r.name} v${r.version} [${scope}] ${r.id}`;
4942
+ return `${String(r.weight).padStart(2)}/10 ${r.name} ${r.id}`;
4968
4943
  }
4969
4944
 
4970
4945
  function recipeDetail(r) {
4971
4946
  return [
4972
- `${r.name} ${r.enabled ? "(enabled)" : "(retired)"} ${r.tab} v${r.version} ${r.id}`,
4973
- ` position: ${r.position}`,
4974
- ` outcomes: ${r.outcomes?.join(", ") || "every outcome"}`,
4975
- ` kinds: ${r.company_types?.join(", ") || "every kind"}`,
4976
- r.tab === "plan" ? ` stands up: ${r.primitives?.join(", ") || "nothing"}` : null,
4977
- ` look at: ${r.look_at || "—"}`,
4978
- ` when to use: ${r.when_to_use || "—"}`,
4979
- ` when not to use: ${r.when_not_to_use || "—"}`,
4980
- ` example: ${r.example || "—"}`,
4981
- r.tab === "plan"
4982
- ? ` moves:\n${(r.moves ?? []).map((m) => ` ${m.id}${m.stage ? ` · ${m.stage}` : ""}${m.after?.length ? ` · after ${m.after.join(",")}` : ""}${m.recommend ? " · recommend" : ""}${m.keep ? " · keep" : ""}${m.optional ? " · optional" : ""}${m.required ? " · required" : ""}${m.why ? ` · "${m.why}"` : ""}`).join("\n")}`
4983
- : null,
4984
- ]
4985
- .filter(Boolean)
4986
- .join("\n");
4947
+ `${r.name} weight ${r.weight}/10 ${r.id}`,
4948
+ ` recipe: ${r.recipe || "—"}`,
4949
+ ` when to use: ${r.when_to_use || "—"}`,
4950
+ ` when not to use: ${r.when_not_to_use || "—"}`,
4951
+ ].join("\n");
4987
4952
  }
4988
4953
 
4989
4954
  function readJson(path) {
@@ -5002,46 +4967,21 @@ function readRecipesFile(path) {
5002
4967
  return recipes.map((r) => compact(recipeForFile(r)));
5003
4968
  }
5004
4969
 
5005
- /** A list flag for save: `a,b` (repeatable), `none` to clear it; a bare flag is a mistake. */
5006
- function recipeListFlag(flags, name) {
5007
- const v = flags[name];
5008
- if (v === undefined) return undefined;
5009
- if (v === true) throw new CliError(`--${name} needs a value: a,b or none`);
5010
- return flagStr(v) === "none" ? [] : flagCsv(v);
5011
- }
5012
-
5013
4970
  /** The fields `admin recipes save` sets: one recipe from --file (or show --json's output), then flags over it. */
5014
4971
  function recipeFromFlags(flags) {
5015
4972
  const path = flagStr(flags.file);
5016
4973
  const parsed = path ? readJson(path) : {};
5017
- const base = parsed?.recipe ?? parsed;
4974
+ const base = parsed?.recipe && typeof parsed.recipe === "object" ? parsed.recipe : parsed;
5018
4975
  if (!base || typeof base !== "object" || Array.isArray(base) || Array.isArray(base.recipes)) {
5019
4976
  throw new CliError("--file holds one recipe object; use admin recipes import for several");
5020
4977
  }
5021
- const movesFlag = flagStr(flags["moves-json"]);
5022
- let moves;
5023
- if (movesFlag !== undefined) {
5024
- try {
5025
- moves = JSON.parse(movesFlag);
5026
- } catch (err) {
5027
- throw new CliError(`--moves-json holds a JSON array of moves: ${err.message}`);
5028
- }
5029
- }
5030
4978
  return compact({
5031
4979
  ...compact(recipeForFile(base)),
5032
4980
  name: flagStr(flags.name),
5033
- tab: flagStr(flags.tab),
5034
- look_at: flagStr(flags["look-at"]),
4981
+ recipe: flagStr(flags.recipe),
5035
4982
  when_to_use: flagStr(flags["when-to-use"]),
5036
4983
  when_not_to_use: flagStr(flags["when-not-to-use"]),
5037
- impact: flags.impact !== undefined ? Number(flags.impact) : undefined,
5038
- example: flagStr(flags.example),
5039
- moves,
5040
- primitives: recipeListFlag(flags, "primitives"),
5041
- outcomes: recipeListFlag(flags, "outcomes"),
5042
- company_types: recipeListFlag(flags, "company-types"),
5043
- enabled: flagBool(flags.disable) ? false : flagBool(flags.enable) ? true : undefined,
5044
- position: flagNum(flags.position),
4984
+ weight: flagNum(flags.weight),
5045
4985
  });
5046
4986
  }
5047
4987
 
@@ -5153,7 +5093,7 @@ async function cmdAdminLetterpress(ctx) {
5153
5093
  `Letterpress, last ${s.days} days (settings v${s.settings.version}${s.settings.defaults_only ? ", defaults" : ""}, questions v${s.judgement_version})`,
5154
5094
  ...s.lenses.map(
5155
5095
  (l) =>
5156
- `${l.lens.padEnd(6)} ${l.mode.padEnd(6)} ${String(l.runs).padStart(3)} runs recipes ${l.recipes.enabled} on, ${l.recipes.retired} retired, ${l.recipes.conditioned} conditioned followed full ${l.followed.full} / part ${l.followed.part} / none ${l.followed.none}${l.shadow ? ` shadow: top same ${l.shadow.top_same}/${l.shadow.runs}, order same ${l.shadow.order_same}` : ""}${l.drift?.pairs ? ` drift ${l.drift.changed}/${l.drift.pairs}` : ""}${l.prompt_hash ? ` prompt ${l.prompt_hash}` : ""}${l.model ? ` ${l.model}` : ""}`
5096
+ `${l.lens.padEnd(6)} ${l.mode.padEnd(6)} ${String(l.runs).padStart(3)} runs recipes ${l.recipes} followed a recipe ${l.followed.recipe} / none ${l.followed.none}${l.shadow ? ` shadow: top same ${l.shadow.top_same}/${l.shadow.runs}, order same ${l.shadow.order_same}` : ""}${l.drift?.pairs ? ` drift ${l.drift.changed}/${l.drift.pairs}` : ""}${l.prompt_hash ? ` prompt ${l.prompt_hash}` : ""}${l.model ? ` ${l.model}` : ""}`
5157
5097
  ),
5158
5098
  s.surfaces.length
5159
5099
  ? `asks from: ${s.surfaces.map((x) => `${x.surface} ${x.runs}`).join(", ")}`
@@ -5234,7 +5174,7 @@ async function cmdAdminLetterpress(ctx) {
5234
5174
 
5235
5175
  /**
5236
5176
  * `admin recipes …` — the recipes page (/superadmin/recipes) for an agent: Letter's one library
5237
- * of direction for Letterpress on Plan, Build and Fix (`--tab`). The loop for building it out is
5177
+ * of direction for Letterpress on Plan, Build and Fix, five fields each. The loop for building it out is
5238
5178
  * `vocab` (what a recipe can say) → `export --out recipes.json` → edit → `import recipes.json
5239
5179
  * --dry-run` → `import recipes.json`; `stats` says how each recipe's suggestions fare. Reads need
5240
5180
  * recipes:read on the staff key, writes recipes:write; every write is recorded as the key holder's.
@@ -5242,9 +5182,7 @@ async function cmdAdminLetterpress(ctx) {
5242
5182
  async function cmdAdminRecipes(ctx) {
5243
5183
  const { flags, positionals, io } = ctx;
5244
5184
  const sub = positionals[0];
5245
- const tab = flagStr(flags.tab);
5246
- const all = async () =>
5247
- (await staffRequest(ctx, "GET", tab ? `${RECIPES}?tab=${encodeURIComponent(tab)}` : RECIPES)).recipes ?? [];
5185
+ const all = async () => (await staffRequest(ctx, "GET", RECIPES)).recipes ?? [];
5248
5186
  switch (sub) {
5249
5187
  case "stats": {
5250
5188
  const result = await staffRequest(ctx, "GET", `${RECIPES}/stats`);
@@ -5253,7 +5191,7 @@ async function cmdAdminRecipes(ctx) {
5253
5191
  ? r.stats
5254
5192
  .map(
5255
5193
  (s) =>
5256
- `${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${String(s.resolved ?? 0).padStart(4)} resolved ${String(s.built ?? 0).padStart(3)} built ${s.tab.padEnd(5)} ${s.recipe}${s.reasons.length ? `\n why: ${s.reasons.slice(0, 3).join(" · ")}` : ""}`
5194
+ `${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${String(s.resolved ?? 0).padStart(4)} resolved ${String(s.built ?? 0).padStart(3)} built ${s.lens.padEnd(5)} ${s.recipe}${s.reasons.length ? `\n why: ${s.reasons.slice(0, 3).join(" · ")}` : ""}`
5257
5195
  )
5258
5196
  .join("\n")
5259
5197
  : "No suggestions from the passes yet."
@@ -5261,7 +5199,7 @@ async function cmdAdminRecipes(ctx) {
5261
5199
  return 0;
5262
5200
  }
5263
5201
  case "list": {
5264
- const recipes = (await all()).filter((r) => !flagBool(flags["enabled-only"]) || r.enabled);
5202
+ const recipes = await all();
5265
5203
  printResult(io, flags, { recipes }, (r) =>
5266
5204
  r.recipes.length ? r.recipes.map(recipeLine).join("\n") : "No recipes yet."
5267
5205
  );
@@ -5280,23 +5218,11 @@ async function cmdAdminRecipes(ctx) {
5280
5218
  [
5281
5219
  ...r.how_recipes_are_read.map((line) => `· ${line}`),
5282
5220
  "",
5283
- "Tabs:",
5284
- ...r.tabs.map((t) => ` ${t.id}: reads ${t.reads}`),
5221
+ "Lenses (each reads the whole library):",
5222
+ ...r.lenses.map((t) => ` ${t.id}: reads ${t.reads}`),
5285
5223
  "",
5286
5224
  "Fields:",
5287
5225
  ...r.fields.map((f) => ` ${f.name}: ${f.description}`),
5288
- "",
5289
- "A move's fields (plan):",
5290
- ...r.move_fields.map((f) => ` ${f.name}: ${f.description}`),
5291
- "",
5292
- `Actions a move may name: ${r.actions.join(", ")}`,
5293
- `Evidence the moves can make a plan read: ${r.evidence.join(", ")}`,
5294
- "",
5295
- "Outcomes:",
5296
- ...r.outcomes.map((g) => ` ${g.id}${g.available ? "" : " (not available yet)"}: ${g.brief}`),
5297
- "",
5298
- `Company types: ${r.company_types.map((t) => `${t.id} (${t.label})`).join(", ")}`,
5299
- `Primitives: ${r.primitives.map((p) => `${p.id} (${p.label})`).join(", ")}`,
5300
5226
  ].join("\n")
5301
5227
  );
5302
5228
  return 0;
@@ -5315,13 +5241,11 @@ async function cmdAdminRecipes(ctx) {
5315
5241
  const result = await staffPost(ctx, `${RECIPES}/import`, {
5316
5242
  recipes: readRecipesFile(path),
5317
5243
  dry_run: flagBool(flags["dry-run"]),
5318
- retire_missing: flagBool(flags["retire-missing"]),
5319
5244
  });
5320
5245
  const verb = {
5321
5246
  create: "create",
5322
5247
  update: "update",
5323
5248
  unchanged: "same ",
5324
- retire: "retire",
5325
5249
  failed: "FAILED",
5326
5250
  };
5327
5251
  printResult(io, flags, result, (r) =>
@@ -5330,7 +5254,7 @@ async function cmdAdminRecipes(ctx) {
5330
5254
  (row) =>
5331
5255
  `${verb[row.action] ?? row.action} ${row.name}${row.changed.length && row.action !== "create" ? ` (${row.changed.join(", ")})` : ""}${row.error ? ` → ${row.error}` : ""}`
5332
5256
  ),
5333
- `${r.dry_run ? "Would create" : "Created"} ${r.counts.created}, ${r.dry_run ? "update" : "updated"} ${r.counts.updated}, retire${r.dry_run ? "" : "d"} ${r.counts.retired}; ${r.counts.unchanged} unchanged, ${r.counts.failed} failed.${r.dry_run ? " Nothing was written (--dry-run)." : ""}`,
5257
+ `${r.dry_run ? "Would create" : "Created"} ${r.counts.created}, ${r.dry_run ? "update" : "updated"} ${r.counts.updated}; ${r.counts.unchanged} unchanged, ${r.counts.failed} failed.${r.dry_run ? " Nothing was written (--dry-run)." : ""}`,
5334
5258
  ].join("\n")
5335
5259
  );
5336
5260
  return result.counts?.failed ? 1 : 0;
@@ -5349,9 +5273,7 @@ async function cmdAdminRecipes(ctx) {
5349
5273
  case "delete": {
5350
5274
  const id = requirePositional(positionals, 1, "id");
5351
5275
  if (!flagBool(flags.yes)) {
5352
- io.error(
5353
- `Re-run with --yes to delete for good: ${ctx.bin} admin recipes delete ${id} --yes (save --disable retires one and keeps it)`
5354
- );
5276
+ io.error(`Re-run with --yes to delete for good: ${ctx.bin} admin recipes delete ${id} --yes`);
5355
5277
  return 1;
5356
5278
  }
5357
5279
  const result = await staffRequest(ctx, "DELETE", `${RECIPES}/${encodeURIComponent(id)}`);
@@ -2,7 +2,7 @@
2
2
  // network, single-post, and top-posts levels (ported from phantomstory-cli's
3
3
  // insights.ts); plus Measure's Overview (`summary`), GEO → Competitors
4
4
  // (`competitors`), AI Visibility Bank (`bank`) and phantom Page Access (`access`);
5
- // Measure → Reads (`reads`), Questions (`questions`) and Pages (`pages`), and the live feed of what
5
+ // Measure → Reads (`reads`), Questions (`questions`), Pages (`pages`) and the posts naming you (`mentions`), and the live feed of what
6
6
  // is reading the phantom sites (`activity`) — the same reads the web app renders.
7
7
 
8
8
  import { CliError } from "../client.mjs";
@@ -42,6 +42,9 @@ export const ARGS = {
42
42
  period: { flag: "period", enum: PERIODS },
43
43
  sites: { flag: "site", type: "list" },
44
44
  },
45
+ list_site_mentions: {
46
+ sites: { flag: "site", type: "list" },
47
+ },
45
48
  get_recent_activity: {
46
49
  phantom_id: { flag: "phantom" },
47
50
  limit: { flag: "limit", type: "num" },
@@ -82,11 +85,13 @@ export async function cmdInsights(ctx) {
82
85
  return call(rest, "list_measure_questions");
83
86
  case "pages":
84
87
  return call(rest, "list_cited_pages");
88
+ case "mentions":
89
+ return call(rest, "list_site_mentions");
85
90
  case "activity":
86
91
  return call(rest, "get_recent_activity");
87
92
  default:
88
93
  throw new CliError(
89
- `Unknown insights subcommand: ${sub ?? "(none)"}. Try: summary, reads, questions, pages, competitors, question, detection, activity, site, post, top, bank, access`
94
+ `Unknown insights subcommand: ${sub ?? "(none)"}. Try: summary, reads, questions, pages, mentions, competitors, question, detection, activity, site, post, top, bank, access`
90
95
  );
91
96
  }
92
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.167.1",
3
+ "version": "0.168.0",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",