@koda-sl/baker-cli 0.896.0 → 0.898.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/README.md CHANGED
@@ -1512,8 +1512,8 @@ baker ads meta audiences --account-id act_123
1512
1512
 
1513
1513
  # "Is the pixel firing?"
1514
1514
  baker ads meta pixels --account-id act_123 # id, name, last fired, owner; --full adds the install code
1515
- baker ads meta pixels --pixel-id 9988 --stats --days 7 # events received per day (date, weekday, event, count)
1516
- baker ads meta pixels --pixel-id 9988 --stats --event Lead --by total # one event: count, first and last seen; --full = raw hourly buckets
1515
+ baker ads meta pixels --pixel-id 9988 --stats --days 7 # the 25 most received events: count, first and last seen; --by total = every one
1516
+ baker ads meta pixels --pixel-id 9988 --stats --event Lead # one event per day (date, weekday, event, count); --by day = every event; --full = raw hourly buckets
1517
1517
 
1518
1518
  # "Why isn't it using MY conversions?"
1519
1519
  baker ads meta custom-conversions --account-id act_123 # id, event category, pixel, and the rule as a phrase
@@ -6,10 +6,10 @@ import {
6
6
  readForms,
7
7
  readLandings,
8
8
  readReports
9
- } from "./chunk-ESGANKHR.js";
9
+ } from "./chunk-XJE4JH7C.js";
10
10
  import {
11
11
  rulesView
12
- } from "./chunk-OLIEY4WM.js";
12
+ } from "./chunk-JROQOOUR.js";
13
13
  import {
14
14
  fetchRunRecord
15
15
  } from "./chunk-LDMF7X32.js";
@@ -659,4 +659,4 @@ export {
659
659
  savedHint,
660
660
  widenedRule
661
661
  };
662
- //# sourceMappingURL=add-XRXV4JYO.js.map
662
+ //# sourceMappingURL=add-SK4RUEEM.js.map
@@ -34,7 +34,7 @@ Full guides: __tooling__/docs/tools/baker/ads-<platform>.md (google|meta|linkedi
34
34
  },
35
35
  subCommands: {
36
36
  google: () => import("./google-T63TXQTL.js").then((m) => m.googleCommand),
37
- meta: () => import("./meta-BJDKNWJA.js").then((m) => m.metaCommand),
37
+ meta: () => import("./meta-GOPN63QP.js").then((m) => m.metaCommand),
38
38
  linkedin: () => import("./linkedin-AJMDNPUD.js").then((m) => m.linkedinCommand),
39
39
  x: () => import("./x-WRK34GQD.js").then((m) => m.xCommand),
40
40
  chatgpt: () => import("./chatgpt-2UCND7NY.js").then((m) => m.chatgptCommand),
@@ -45,4 +45,4 @@ Full guides: __tooling__/docs/tools/baker/ads-<platform>.md (google|meta|linkedi
45
45
  export {
46
46
  adsCommand
47
47
  };
48
- //# sourceMappingURL=ads-WMP6S4FN.js.map
48
+ //# sourceMappingURL=ads-MTUBTBJV.js.map
@@ -5,8 +5,8 @@ import {
5
5
  checkLandings,
6
6
  checkReports,
7
7
  checkSurface
8
- } from "./chunk-ESGANKHR.js";
9
- import "./chunk-OLIEY4WM.js";
8
+ } from "./chunk-XJE4JH7C.js";
9
+ import "./chunk-JROQOOUR.js";
10
10
  import "./chunk-AQFSRSJ4.js";
11
11
  import "./chunk-DD44EMGP.js";
12
12
  import "./chunk-HJI3W6HQ.js";
@@ -52,4 +52,4 @@ export {
52
52
  checkReports,
53
53
  checkSurface
54
54
  };
55
- //# sourceMappingURL=check-3B4HE6HI.js.map
55
+ //# sourceMappingURL=check-YRRQ5ZEZ.js.map
@@ -65,7 +65,13 @@ async function readCreativeSpecs(root) {
65
65
  );
66
66
  return specs.filter((s) => s !== null);
67
67
  }
68
- function rulesHints(active, waived) {
68
+ var PROMPT_OF = {
69
+ creatives: "ad's",
70
+ landings: "landing's",
71
+ documents: "document's",
72
+ reports: "report's"
73
+ };
74
+ function rulesHints(active, waived, longest) {
69
75
  const hints = [];
70
76
  for (const rule of active) {
71
77
  const times = waived.get(rule.id) ?? 0;
@@ -75,9 +81,9 @@ function rulesHints(active, waived) {
75
81
  );
76
82
  }
77
83
  }
78
- if (active.length > MANY_RULES) {
84
+ if (longest.count > MANY_RULES) {
79
85
  hints.push(
80
- `${active.length} active rules: every prompt carries them all. Ask the person whether some can be retired or merged.`
86
+ `${longest.count} active rules: every ${PROMPT_OF[longest.output]} prompt carries them all. Ask the person whether some can be retired or merged.`
81
87
  );
82
88
  }
83
89
  return hints;
@@ -90,4 +96,4 @@ export {
90
96
  readCreativeSpecs,
91
97
  rulesHints
92
98
  };
93
- //# sourceMappingURL=chunk-OLIEY4WM.js.map
99
+ //# sourceMappingURL=chunk-JROQOOUR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/rules/view.ts"],"sourcesContent":["/**\n * The company's rules as the agent reads them in `baker rules list`: what each is for (creatives, landings, documents, reports or all), each one's id, strength and words, the person's own words when\n * they taught it, and where it came from; and which ones ads keep waiving. Pure, but for the read\n * of the ads' waivers.\n */\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { CreativeRule } from \"../../engine/creative-rules/schema.ts\";\n\nexport const SURFACES = [\"creatives\", \"landings\", \"documents\", \"reports\"] as const;\nexport type Surface = (typeof SURFACES)[number];\n\n/** What `--for` names on the commands that read rules or pieces: one output (`ads` is creatives' old name), {} when left out, null for anything else. Pure. */\nexport function readSurface(value: unknown): { surface?: Surface } | null {\n if (value === undefined) return {};\n const surface = SURFACES.find((s) => s === (value === \"ads\" ? \"creatives\" : value));\n return surface ? { surface } : null;\n}\n\n/** A rule cut to this in the compact view: the whole is behind `--full`. */\nconst RULE_CHARS = 200;\nconst QUOTE_CHARS = 160;\n/** Waived this often, a rule may no longer hold. */\nconst RETIRE_AFTER = 3;\n/** Past this many active rules in one prompt, it carries a long list: worth a look. */\nconst MANY_RULES = 40;\n\nconst cut = (text: string, max: number) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);\n\n/** Where a rule came from, in a few words. */\nfunction fromOf(rule: CreativeRule): string {\n if (rule.origin === \"declared\") return \"BRAND.md\";\n const when = rule.source.date ? ` ${rule.source.date}` : \"\";\n const where = rule.source.slug ? ` on ${rule.source.slug}` : \"\";\n return `taught${when}${where}`;\n}\n\nexport type RuleView = {\n id: string;\n strength: CreativeRule[\"strength\"];\n /** landings, documents, reports or all; absent, the rule is for creatives. */\n for?: CreativeRule[\"for\"];\n applies: CreativeRule[\"applies\"];\n rule: string;\n their_words?: string;\n from: string;\n /** The words it bans in an ad's words, and the phrases that may still hold them. */\n bans?: string[];\n except?: string[];\n /** Words every ad must say. */\n requires?: string[];\n /** Only real people may appear. */\n people?: \"real\";\n scope?: CreativeRule[\"scope\"];\n status?: \"retired\";\n retired_by?: string;\n};\n\n/** What code checks of a rule, as the agent reads it. Pure. */\nfunction checkView(check: CreativeRule[\"check\"]): Pick<RuleView, \"bans\" | \"except\" | \"requires\" | \"people\"> {\n return {\n ...(check?.forbid ? { bans: check.forbid } : {}),\n ...(check?.allow ? { except: check.allow } : {}),\n ...(check?.require ? { requires: check.require } : {}),\n ...(check?.people ? { people: check.people } : {}),\n };\n}\n\n/** Each rule as the agent reads it. Pure. */\nexport function rulesView(rules: readonly CreativeRule[], opts: { full?: boolean } = {}): RuleView[] {\n const max = opts.full ? Number.POSITIVE_INFINITY : RULE_CHARS;\n const quoteMax = opts.full ? Number.POSITIVE_INFINITY : QUOTE_CHARS;\n return rules.map((r) => ({\n id: r.id,\n strength: r.strength,\n ...(r.for ? { for: r.for } : {}),\n applies: r.applies,\n rule: cut(r.text, max),\n ...(r.source.quote ? { their_words: cut(r.source.quote, quoteMax) } : {}),\n from: fromOf(r),\n ...checkView(r.check),\n ...(Object.keys(r.scope).length > 0 ? { scope: r.scope } : {}),\n ...(r.status === \"retired\" ? { status: \"retired\" as const } : {}),\n ...(r.retiredBy ? { retired_by: r.retiredBy } : {}),\n }));\n}\n\n/** How many ads waive each rule (`waive: [{rule, why}]` in their prompt.json). Pure. */\nexport function waiverCounts(specs: readonly unknown[]): Map<string, number> {\n const counts = new Map<string, number>();\n for (const spec of specs) {\n const waive = (spec as { waive?: unknown } | null)?.waive;\n if (!Array.isArray(waive)) continue;\n for (const entry of waive) {\n const id = (entry as { rule?: unknown } | null)?.rule;\n if (typeof id === \"string\" && id) counts.set(id, (counts.get(id) ?? 0) + 1);\n }\n }\n return counts;\n}\n\n/** Every creative's prompt.json, parsed; one that cannot be read is left out. */\nexport async function readCreativeSpecs(root: string): Promise<unknown[]> {\n const dir = path.join(root, \"src\", \"creatives\");\n const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);\n const specs = await Promise.all(\n entries\n .filter((e) => e.isDirectory() && !e.name.startsWith(\"_\"))\n .map((e) =>\n readFile(path.join(dir, e.name, \"prompt.json\"), \"utf8\")\n .then((raw): unknown => JSON.parse(raw))\n .catch(() => null),\n ),\n );\n return specs.filter((s) => s !== null);\n}\n\n/** What one prompt of each output is called in the count hint. */\nconst PROMPT_OF: Record<Surface, string> = {\n creatives: \"ad's\",\n landings: \"landing's\",\n documents: \"document's\",\n reports: \"report's\",\n};\n\n/**\n * What the rules say to do next: retire one ads keep waiving, look at a list grown long. `longest` is the\n * output whose one prompt carries the most active rules, and how many. Pure.\n */\nexport function rulesHints(\n active: readonly CreativeRule[],\n waived: ReadonlyMap<string, number>,\n longest: { output: Surface; count: number },\n): string[] {\n const hints: string[] = [];\n for (const rule of active) {\n const times = waived.get(rule.id) ?? 0;\n if (times >= RETIRE_AFTER) {\n hints.push(\n `${rule.id} was waived by ${times} ads: ask the person whether it still holds, and \\`baker rules retire ${rule.id}\\` if not.`,\n );\n }\n }\n if (longest.count > MANY_RULES) {\n hints.push(\n `${longest.count} active rules: every ${PROMPT_OF[longest.output]} prompt carries them all. Ask the person whether some can be retired or merged.`,\n );\n }\n return hints;\n}\n"],"mappings":";AAKA,SAAS,SAAS,gBAAgB;AAClC,OAAO,UAAU;AAGV,IAAM,WAAW,CAAC,aAAa,YAAY,aAAa,SAAS;AAIjE,SAAS,YAAY,OAA8C;AACxE,MAAI,UAAU,OAAW,QAAO,CAAC;AACjC,QAAM,UAAU,SAAS,KAAK,CAAC,MAAM,OAAO,UAAU,QAAQ,cAAc,MAAM;AAClF,SAAO,UAAU,EAAE,QAAQ,IAAI;AACjC;AAGA,IAAM,aAAa;AACnB,IAAM,cAAc;AAEpB,IAAM,eAAe;AAErB,IAAM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B,aAAW,QAAQ,QAAQ;AACzB,UAAM,QAAQ,OAAO,IAAI,KAAK,EAAE,KAAK;AACrC,QAAI,SAAS,cAAc;AACzB,YAAM;AAAA,QACJ,GAAG,KAAK,EAAE,kBAAkB,KAAK,yEAAyE,KAAK,EAAE;AAAA,MACnH;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,QAAQ,YAAY;AAC9B,UAAM;AAAA,MACJ,GAAG,QAAQ,KAAK,wBAAwB,UAAU,QAAQ,MAAM,CAAC;AAAA,IACnE;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readSurface
3
- } from "./chunk-OLIEY4WM.js";
3
+ } from "./chunk-JROQOOUR.js";
4
4
  import {
5
5
  readAdWords,
6
6
  ruleRefusal
@@ -502,4 +502,4 @@ export {
502
502
  checkSurface,
503
503
  checkCommand
504
504
  };
505
- //# sourceMappingURL=chunk-ESGANKHR.js.map
505
+ //# sourceMappingURL=chunk-XJE4JH7C.js.map
package/dist/cli.js CHANGED
@@ -625,7 +625,7 @@ Introspection: Run 'baker schema <command>' to inspect argument schemas.`
625
625
  capabilities: () => import("./capabilities-AV7CIS6N.js").then((m) => m.capabilitiesCommand),
626
626
  actions: () => import("./actions-DKJPTQWC.js").then((m) => m.actionsCommand),
627
627
  "scheduled-agents": () => import("./scheduled-agents-VT7SYKOC.js").then((m) => m.scheduledAgentsCommand),
628
- ads: () => import("./ads-WMP6S4FN.js").then((m) => m.adsCommand),
628
+ ads: () => import("./ads-MTUBTBJV.js").then((m) => m.adsCommand),
629
629
  brand: () => import("./brand-CMKT6D25.js").then((m) => m.brandCommand),
630
630
  analytics: () => import("./analytics-7NPD2T2W.js").then((m) => m.analyticsCommand),
631
631
  experiment: () => import("./experiment-FMMX57VR.js").then((m) => m.experimentCommand),
@@ -636,7 +636,7 @@ Introspection: Run 'baker schema <command>' to inspect argument schemas.`
636
636
  data: () => import("./data-CIPG3EOP.js").then((m) => m.dataCommand),
637
637
  knowledge: () => import("./knowledge-S6QL4LX5.js").then((m) => m.knowledgeCommand),
638
638
  creatives: () => import("./creatives-U4VUGNQJ.js").then((m) => m.creativesCommand),
639
- rules: () => import("./rules-M5SXLUDN.js").then((m) => m.rulesCommand),
639
+ rules: () => import("./rules-PCGXXGIK.js").then((m) => m.rulesCommand),
640
640
  files: () => import("./files-SPBLE3DV.js").then((m) => m.filesCommand),
641
641
  flows: () => import("./flows-HMIPOFMC.js").then((m) => m.flowsCommand),
642
642
  funnel: () => import("./funnel-UUGNLCXG.js").then((m) => m.funnelCommand),
@@ -119,7 +119,7 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
119
119
  creatives: () => import("./creatives-LW6UNC2G.js").then((m) => m.creativesCommand),
120
120
  audiences: () => import("./audiences-JVKPNJ2W.js").then((m) => m.audiencesCommand),
121
121
  "custom-conversions": () => import("./custom-conversions-WBP2QMW3.js").then((m) => m.customConversionsCommand),
122
- pixels: () => import("./pixels-I7S5N76B.js").then((m) => m.pixelsCommand),
122
+ pixels: () => import("./pixels-VFHS3QIF.js").then((m) => m.pixelsCommand),
123
123
  activities: () => import("./activities-6H2SSVS6.js").then((m) => m.activitiesCommand),
124
124
  insights: () => import("./insights-PBJODKMY.js").then((m) => m.insightsCommand),
125
125
  preview: () => import("./preview-5CK5INGO.js").then((m) => m.previewCommand),
@@ -149,4 +149,4 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
149
149
  export {
150
150
  metaCommand
151
151
  };
152
- //# sourceMappingURL=meta-BJDKNWJA.js.map
152
+ //# sourceMappingURL=meta-GOPN63QP.js.map
@@ -34,13 +34,13 @@ var pixelsCommand = defineCommand({
34
34
 
35
35
  The list prints each pixel's id, name, last_fired_time and owner (unavailable: true when Meta marks it so); --full adds the install code and the setup fields.
36
36
 
37
- --stats prints one row per day per event (date, weekday, event, count) by default, in the ad account's time zone; --by hour or --by total change the grain, --full returns Meta's raw hourly buckets.
37
+ --stats prints each event's total over the window (event, count, first_seen, last_seen) by default, the 25 most received (--by total prints every one); --event narrows it to one row per day per event (date, weekday, event, count), in the ad account's time zone, and --by day|hour|total sets the grain outright. --full returns Meta's raw hourly buckets.
38
38
 
39
39
  Examples:
40
40
  baker ads meta pixels --account-id act_123
41
- baker ads meta pixels --pixel-id 9876 --stats --days 7 # per day per event
42
- baker ads meta pixels --pixel-id 9876 --stats --days 7 --event Lead,Purchase # only those events
43
- baker ads meta pixels --pixel-id 9876 --stats --days 30 --by total # each event's count, first and last seen`
41
+ baker ads meta pixels --pixel-id 9876 --stats --days 7 # each event's count, first and last seen
42
+ baker ads meta pixels --pixel-id 9876 --stats --days 7 --event Lead,Purchase # those events, per day
43
+ baker ads meta pixels --pixel-id 9876 --stats --days 7 --by day # every event, per day`
44
44
  },
45
45
  args: {
46
46
  "account-id": LISTING_ACCOUNT_ARG,
@@ -54,7 +54,7 @@ Examples:
54
54
  days: { type: "string", description: "Lookback days for --stats (default 7)" },
55
55
  by: {
56
56
  type: "string",
57
- description: "--stats grain: day (default; one row per day per value, with its weekday), hour (one row per hour per value), total (one row per value with first_seen/last_seen)"
57
+ description: "--stats grain: total (default without --event; one row per value with first_seen/last_seen), day (default with --event; one row per day per value, with its weekday), hour (one row per hour per value)"
58
58
  },
59
59
  event: {
60
60
  type: "string",
@@ -95,7 +95,8 @@ async function runStats(args) {
95
95
  "end-time": todayIso()
96
96
  };
97
97
  if (args["no-cache"]) params["skip-cache"] = "true";
98
- const by = args.by ?? "day";
98
+ const events = typeof args.event === "string" ? args.event.split(",").map((e) => e.trim()).filter(Boolean) : [];
99
+ const by = args.by ?? (events.length > 0 ? "day" : "total");
99
100
  if (!isStatsGrain(by)) {
100
101
  writeAdsJson({
101
102
  ok: false,
@@ -108,11 +109,25 @@ async function runStats(args) {
108
109
  emit(buckets, args);
109
110
  return;
110
111
  }
111
- const events = typeof args.event === "string" ? args.event.split(",").map((e) => e.trim()).filter(Boolean) : [];
112
112
  const window = { start: `${params["start-time"]}T00:00:00Z`, end: `${params["end-time"]}T00:00:00Z` };
113
- const { rows, hints } = rollUpPixelStats(buckets, { aggregation: params.aggregation ?? "event", by, events, window });
113
+ const aggregation = params.aggregation ?? "event";
114
+ const { rows, hints } = rollUpPixelStats(buckets, { aggregation, by, events, window });
115
+ if (args.by === void 0 && by === "total" && rows.length > 0) {
116
+ const kept = rows.slice(0, DEFAULT_TOTALS_CAP);
117
+ hints.push(defaultTotalsHint(kept.length, rows.length, aggregation));
118
+ writeAdsOutput(kept, csvOrJson(args), void 0, hints);
119
+ return;
120
+ }
114
121
  writeAdsOutput(rows, csvOrJson(args), void 0, hints);
115
122
  }
123
+ function defaultTotalsHint(kept, total, aggregation) {
124
+ if (kept === total) {
125
+ return "Each value's total over the window. For one row per day, add --event <name> (or --by day).";
126
+ }
127
+ const noun = aggregation === "event" ? "events" : `${aggregation} values`;
128
+ return `Each value's total over the window: the ${kept} most received of ${total} ${noun}. For every one, add --by total; for one per day, --event <name>.`;
129
+ }
130
+ var DEFAULT_TOTALS_CAP = 25;
116
131
  var STATS_GRAINS = ["day", "hour", "total"];
117
132
  function isStatsGrain(value) {
118
133
  return STATS_GRAINS.includes(value);
@@ -241,4 +256,4 @@ export {
241
256
  pixelWarnings,
242
257
  pixelsCommand
243
258
  };
244
- //# sourceMappingURL=pixels-I7S5N76B.js.map
259
+ //# sourceMappingURL=pixels-VFHS3QIF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/meta/pixels.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { DateTime } from \"luxon\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { writeAdsJson, writeAdsOutput } from \"../output.ts\";\nimport type { AdsWarning } from \"../types.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n daysAgoIso,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n readEachAccount,\n todayIso,\n withAccountColumn,\n} from \"./shared.ts\";\n\nexport const pixelsCommand = defineCommand({\n meta: {\n name: \"pixels\",\n description: `List Meta Pixels for an ad account, or count what one pixel received — the firing read, not ad-attributed conversions.\n\nThe list prints each pixel's id, name, last_fired_time and owner (unavailable: true when Meta marks it so); --full adds the install code and the setup fields.\n\n--stats prints each event's total over the window (event, count, first_seen, last_seen) by default, the 25 most received (--by total prints every one); --event narrows it to one row per day per event (date, weekday, event, count), in the ad account's time zone, and --by day|hour|total sets the grain outright. --full returns Meta's raw hourly buckets.\n\nExamples:\n baker ads meta pixels --account-id act_123\n baker ads meta pixels --pixel-id 9876 --stats --days 7 # each event's count, first and last seen\n baker ads meta pixels --pixel-id 9876 --stats --days 7 --event Lead,Purchase # those events, per day\n baker ads meta pixels --pixel-id 9876 --stats --days 7 --by day # every event, per day`,\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"pixel-id\": { type: \"string\", description: \"Pixel ID for --stats\" },\n stats: { type: \"boolean\", description: \"Fetch firing stats for the pixel\" },\n aggregation: {\n type: \"string\",\n description: \"stats aggregation: event|browser_type|host|pixel_fire\",\n default: \"event\",\n },\n days: { type: \"string\", description: \"Lookback days for --stats (default 7)\" },\n by: {\n type: \"string\",\n description:\n \"--stats grain: total (default without --event; one row per value with first_seen/last_seen), day (default with --event; one row per day per value, with its weekday), hour (one row per hour per value)\",\n },\n event: {\n type: \"string\",\n description: \"--stats: keep only these values, comma-separated and exact (e.g. --event Lead,Purchase)\",\n },\n full: {\n type: \"boolean\",\n description:\n \"The list: every field, the install code included. --stats: Meta's raw hourly buckets, every value, instead of the rows\",\n },\n \"no-cache\": NO_CACHE_ARG,\n output: { type: \"string\", description: \"Output format: json|csv|jsonl|md\", default: \"json\" },\n },\n run: async ({ args }) => {\n try {\n if (args.stats) {\n await runStats(args);\n return;\n }\n await runList(args);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nasync function runStats(args: Record<string, unknown>): Promise<void> {\n const pixelId = args[\"pixel-id\"] as string | undefined;\n if (!pixelId) {\n handleMetaError(new Error(\"--pixel-id is required when --stats is set\"));\n }\n const days = args.days ? Number(args.days) : 7;\n if (!Number.isInteger(days) || days <= 0 || days > 90) {\n handleMetaError(new Error(\"--days must be a positive integer ≤ 90\"));\n }\n const params: Record<string, string> = {\n \"pixel-id\": pixelId,\n aggregation: (args.aggregation as string) ?? \"event\",\n \"start-time\": daysAgoIso(days),\n \"end-time\": todayIso(),\n };\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const events =\n typeof args.event === \"string\"\n ? args.event\n .split(\",\")\n .map((e) => e.trim())\n .filter(Boolean)\n : [];\n // Totals unless --event narrows the read: on a pixel shared with an app, a row per day\n // per event grew with every app event (BAKER-4822), and a truncated per-day read left\n // the reader to sum what survived (BAKER-4782).\n const by = (args.by as string | undefined) ?? (events.length > 0 ? \"day\" : \"total\");\n if (!isStatsGrain(by)) {\n writeAdsJson({\n ok: false,\n error: { code: \"INVALID_ARGS\", message: `--by must be one of ${STATS_GRAINS.join(\", \")}` },\n });\n process.exit(1);\n }\n const buckets = await apiGet<PixelStatBucket[]>(\"/api/ads/meta/pixel-stats\", params);\n if (args.full) {\n emit(buckets as Array<Record<string, unknown>>, args);\n return;\n }\n const window = { start: `${params[\"start-time\"]}T00:00:00Z`, end: `${params[\"end-time\"]}T00:00:00Z` };\n const aggregation = params.aggregation ?? \"event\";\n const { rows, hints } = rollUpPixelStats(buckets, { aggregation, by, events, window });\n if (args.by === undefined && by === \"total\" && rows.length > 0) {\n const kept = rows.slice(0, DEFAULT_TOTALS_CAP);\n hints.push(defaultTotalsHint(kept.length, rows.length, aggregation));\n writeAdsOutput(kept, csvOrJson(args), undefined, hints);\n return;\n }\n writeAdsOutput(rows, csvOrJson(args), undefined, hints);\n}\n\nfunction defaultTotalsHint(kept: number, total: number, aggregation: string): string {\n if (kept === total) {\n return \"Each value's total over the window. For one row per day, add --event <name> (or --by day).\";\n }\n const noun = aggregation === \"event\" ? \"events\" : `${aggregation} values`;\n return `Each value's total over the window: the ${kept} most received of ${total} ${noun}. For every one, add --by total; for one per day, --event <name>.`;\n}\n\n/**\n * Rows the default totals read prints, most received first: a pixel shared with\n * an app sends 100+ events, and the default read stays under 5 KB (BAKER-4822).\n */\nconst DEFAULT_TOTALS_CAP = 25;\n\n/** One time bucket as Meta's `/{pixel}/stats` returns it; `start_time` carries the ad account's offset. */\ninterface PixelStatBucket {\n start_time?: string;\n data?: Array<{ value?: string; count?: number }>;\n}\n\nconst STATS_GRAINS = [\"day\", \"hour\", \"total\"] as const;\ntype StatsGrain = (typeof STATS_GRAINS)[number];\n\nfunction isStatsGrain(value: string): value is StatsGrain {\n return (STATS_GRAINS as readonly string[]).includes(value);\n}\n\ninterface RollUp {\n aggregation: string;\n by: StatsGrain;\n events: string[];\n /** The UTC instants the read asked Meta for. */\n window: { start: string; end: string };\n}\n\n/**\n * Meta answers with one bucket per hour, each a nested list of values, so \"how\n * many Leads a day\" was a script over hundreds of rows at every call site. The\n * day is the one Meta wrote on `start_time` — the ad account's own day.\n */\nfunction rollUpPixelStats(\n buckets: PixelStatBucket[],\n { aggregation, by, events, window }: RollUp,\n): { rows: Array<Record<string, string | number>>; hints: string[] } {\n const { folded, seen } = foldBuckets(buckets, by, new Set(events));\n const rows = [...folded.values()]\n .sort((a, b) => a.key.localeCompare(b.key) || b.count - a.count)\n .map((row): Record<string, string | number> => {\n if (by === \"total\") {\n return { [aggregation]: row.value, count: row.count, first_seen: row.first, last_seen: row.last };\n }\n if (by === \"hour\") return { hour: row.key, [aggregation]: row.value, count: row.count };\n return { date: row.key, weekday: accountWeekday(row.first), [aggregation]: row.value, count: row.count };\n });\n const hints: string[] = [];\n const missing = events.filter((event) => !seen.has(event));\n if (missing.length > 0) {\n const received = [...seen].sort().join(\", \") || \"nothing\";\n hints.push(`No ${missing.join(\", \")} received in this window (names are exact). The pixel received: ${received}.`);\n }\n const partialDays = by === \"day\" && rows.length > 0 ? daysCutByWindow(buckets, window) : [];\n if (partialDays.length > 0) {\n hints.push(\n `${partialDays.join(\" and \")} ${partialDays.length === 1 ? \"is a partial day\" : \"are partial days\"}: the read covers ${window.start} → ${window.end}, so compare only the full days between them.`,\n );\n }\n return { rows, hints };\n}\n\ninterface FoldedRow {\n key: string;\n value: string;\n count: number;\n first: string;\n last: string;\n}\n\nconst ROW_KEY: Record<StatsGrain, (time: string) => string> = {\n day: (time) => accountDay(time),\n hour: (time) => time,\n total: () => \"\",\n};\n\nfunction foldBuckets(\n buckets: PixelStatBucket[],\n by: StatsGrain,\n wanted: Set<string>,\n): { folded: Map<string, FoldedRow>; seen: Set<string> } {\n const entries = buckets.flatMap((bucket) =>\n (bucket.data ?? []).map((entry) => ({\n time: bucket.start_time ?? \"\",\n value: entry.value ?? \"(unnamed)\",\n count: entry.count ?? 0,\n })),\n );\n const folded = new Map<string, FoldedRow>();\n for (const { time, value, count } of entries) {\n if (wanted.size > 0 && !wanted.has(value)) continue;\n const key = ROW_KEY[by](time);\n const id = `${key}\\u0000${value}`;\n const row = folded.get(id) ?? { key, value, count: 0, first: time, last: time };\n row.count += count;\n if (instant(time) < instant(row.first)) row.first = time;\n if (instant(time) > instant(row.last)) row.last = time;\n folded.set(id, row);\n }\n return { folded, seen: new Set(entries.map((entry) => entry.value)) };\n}\n\n/** The account-local days the window starts after or ends before, oldest first. */\nfunction daysCutByWindow(buckets: PixelStatBucket[], window: { start: string; end: string }): string[] {\n const cut = new Set<string>();\n for (const { start_time: time } of buckets) {\n if (time && dayOverhangsWindow(time, window)) cut.add(accountDay(time));\n }\n return [...cut].sort();\n}\n\n/** Whether the account-local day `time` falls on starts before or ends after the window read. */\nfunction dayOverhangsWindow(time: string, window: { start: string; end: string }): boolean {\n const dayStart = bucketTime(time).startOf(\"day\");\n if (!dayStart.isValid) return false;\n return dayStart < DateTime.fromISO(window.start) || dayStart.plus({ days: 1 }) > DateTime.fromISO(window.end);\n}\n\n/** A bucket's `start_time` in the offset Meta wrote on it — the ad account's. */\nfunction bucketTime(time: string): DateTime {\n return DateTime.fromISO(time, { setZone: true });\n}\n\nfunction accountDay(time: string): string {\n return bucketTime(time).toISODate() ?? \"\";\n}\n\n/** Written out so a reader never works the weekday out from the date, and gets it wrong. */\nfunction accountWeekday(time: string): string {\n return bucketTime(time).setLocale(\"en-US\").toFormat(\"ccc\");\n}\n\n/** Compared as instants: across a clock change, the same local hour carries two offsets. */\nfunction instant(time: string): number {\n return bucketTime(time).toMillis();\n}\n\nasync function runList(args: Record<string, unknown>): Promise<void> {\n const accounts = await accountsInScope(args);\n const params: Record<string, string> = {};\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const restricted = new Set<string>();\n const read = await readEachAccount(accounts, async (accountId) => {\n const { pixels, restrictedFields } = await apiGet<{\n pixels: MetaPixel[];\n restrictedFields: string[];\n }>(\"/api/ads/meta/pixels\", { ...params, \"account-id\": accountId });\n for (const field of restrictedFields) restricted.add(field);\n return pixels;\n });\n const rows = args.full ? read.rows : read.rows.map(compactPixel);\n emit(withAccountColumn(rows, read.accountOf), args, pixelWarnings([...restricted]), read.hints);\n}\n\n/** A pixel as the backend lists it; the setup fields are passed through whole under --full. */\ninterface MetaPixel extends Record<string, unknown> {\n id: string;\n name?: string;\n last_fired_time?: string;\n owner_business?: { id?: string; name?: string };\n is_unavailable?: boolean;\n}\n\n/**\n * What picks a pixel and says whether it fires. The install snippet and the\n * setup fields were most of every listing (BAKER-3691) and sit behind --full.\n */\nfunction compactPixel(pixel: MetaPixel): Record<string, unknown> {\n return {\n id: pixel.id,\n name: pixel.name,\n last_fired_time: pixel.last_fired_time,\n ...(pixel.owner_business?.name ? { owner: pixel.owner_business.name } : {}),\n // Kept on every row: the md and csv tables take their columns from the first one.\n unavailable: pixel.is_unavailable ? true : undefined,\n };\n}\n\n/**\n * A listing Meta trimmed is still a listing — IDs, names and firing times are\n * complete. Say which setup fields are missing and how to get them, so the gap\n * reads as a client-side access grant rather than as a pixel that isn't there.\n */\nexport function pixelWarnings(restrictedFields: string[]): AdsWarning[] {\n if (restrictedFields.length === 0) {\n return [];\n }\n return [\n {\n code: \"PIXEL_FIELDS_RESTRICTED\",\n message:\n `Meta withheld ${restrictedFields.join(\", \")} for these pixels — the connected user holds no role in the Business that owns them. ` +\n \"IDs, names, creation and last-fired times are complete; install code and setup details are not. \" +\n \"To get them, the client assigns the pixel to the connected user in Meta Business settings → Data sources → Datasets.\",\n },\n ];\n}\n\nfunction emit(\n data: Array<Record<string, unknown>>,\n args: Record<string, unknown>,\n warnings: AdsWarning[] = [],\n hints: string[] = [],\n): void {\n const fmt = csvOrJson(args);\n if (fmt !== \"json\") {\n writeAdsOutput(data, fmt, undefined, hints);\n return;\n }\n writeAdsJson({\n ok: true,\n data,\n ...(warnings.length > 0 ? { warnings } : {}),\n ...(hints.length > 0 ? { hints } : {}),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAgBlB,IAAM,gBAAgB,cAAc;AAAA,EACzC,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWf;AAAA,EACA,MAAM;AAAA,IACJ,cAAc;AAAA,IACd,YAAY,EAAE,MAAM,UAAU,aAAa,uBAAuB;AAAA,IAClE,OAAO,EAAE,MAAM,WAAW,aAAa,mCAAmC;AAAA,IAC1E,aAAa;AAAA,MACX,MAAM;AAAA,MACN,aAAa;AAAA,MACb,SAAS;AAAA,IACX;AAAA,IACA,MAAM,EAAE,MAAM,UAAU,aAAa,wCAAwC;AAAA,IAC7E,IAAI;AAAA,MACF,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,QAAQ,EAAE,MAAM,UAAU,aAA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AC;AAAA,IAGhD;AAAA,EACF;AACF;AAEA,SAAS,KACP,MACA,MACA,WAAyB,CAAC,GAC1B,QAAkB,CAAC,GACb;AACN,QAAM,MAAM,UAAU,IAAI;AAC1B,MAAI,QAAQ,QAAQ;AAClB,mBAAe,MAAM,KAAK,QAAW,KAAK;AAC1C;AAAA,EACF;AACA,eAAa;AAAA,IACX,IAAI;AAAA,IACJ;AAAA,IACA,GAAI,SAAS,SAAS,IAAI,EAAE,SAAS,IAAI,CAAC;AAAA,IAC1C,GAAI,MAAM,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC;AAAA,EACtC,CAAC;AACH;","names":[]}
@@ -4,7 +4,7 @@ import {
4
4
  rulesHints,
5
5
  rulesView,
6
6
  waiverCounts
7
- } from "./chunk-OLIEY4WM.js";
7
+ } from "./chunk-JROQOOUR.js";
8
8
  import {
9
9
  readAllRules
10
10
  } from "./chunk-XGGKDAE3.js";
@@ -93,6 +93,17 @@ function listedRules(rules, on) {
93
93
  );
94
94
  return [...forCreatives, ...others];
95
95
  }
96
+ function longestPrompt(rules, on) {
97
+ if (on.surface && on.surface !== "creatives") {
98
+ return { output: on.surface, count: rulesForOutput(rules, on.surface).length };
99
+ }
100
+ const creatives = {
101
+ output: "creatives",
102
+ count: selectRules(rules, { ...on.kind ? { kind: on.kind } : {}, ...on.product ? { product: on.product } : {} }).length
103
+ };
104
+ if (on.surface === "creatives" || on.kind || on.product) return creatives;
105
+ return ["landings", "documents", "reports"].map((output) => ({ output, count: rulesForOutput(rules, output).length })).reduce((most, next) => next.count > most.count ? next : most, creatives);
106
+ }
96
107
  function unmovedHints(conflicts) {
97
108
  if (conflicts.length === 0) return [];
98
109
  return [
@@ -119,11 +130,11 @@ var rulesListCommand = defineCommand({
119
130
  const kind = args.kind === "static" || args.kind === "video" ? args.kind : void 0;
120
131
  const product = typeof args.product === "string" && args.product ? args.product : void 0;
121
132
  const [rules, specs] = await Promise.all([readAllRules(root), readCreativeSpecs(root)]);
122
- const forAds = selectRules(rules, { ...kind ? { kind } : {}, ...product ? { product } : {} });
123
- const active = listedRules(rules, { ...target, ...kind ? { kind } : {}, ...product ? { product } : {} });
133
+ const on = { ...target, ...kind ? { kind } : {}, ...product ? { product } : {} };
134
+ const active = listedRules(rules, on);
124
135
  const shown = args.all === true ? rules : active;
125
136
  const hints = [
126
- ...rulesHints(forAds, waiverCounts(specs)),
137
+ ...rulesHints(active, waiverCounts(specs), longestPrompt(rules, on)),
127
138
  ...unmovedHints((await moveLegacyRules(root)).conflicts)
128
139
  ];
129
140
  const meta = { count: shown.length, active: active.length, total: rules.length };
@@ -152,13 +163,13 @@ Full guide: __tooling__/docs/tools/baker/rules.md`
152
163
  subCommands: {
153
164
  // Loaded with the family: `baker rules --for landings` runs it, and its flags are read before it runs.
154
165
  list: rulesListCommand,
155
- add: () => import("./add-XRXV4JYO.js").then((m) => m.rulesAddCommand),
156
- retire: () => import("./add-XRXV4JYO.js").then((m) => m.rulesRetireCommand),
157
- check: () => import("./check-3B4HE6HI.js").then((m) => m.checkCommand)
166
+ add: () => import("./add-SK4RUEEM.js").then((m) => m.rulesAddCommand),
167
+ retire: () => import("./add-SK4RUEEM.js").then((m) => m.rulesRetireCommand),
168
+ check: () => import("./check-YRRQ5ZEZ.js").then((m) => m.checkCommand)
158
169
  },
159
170
  default: "list"
160
171
  });
161
172
  export {
162
173
  rulesCommand
163
174
  };
164
- //# sourceMappingURL=rules-M5SXLUDN.js.map
175
+ //# sourceMappingURL=rules-PCGXXGIK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/rules/index.ts","../src/commands/rules/list.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { rulesListCommand } from \"./list.ts\";\n\nexport const rulesCommand = defineCommand({\n meta: {\n name: \"rules\",\n description: `The company's standing rules: what every creative, landing (forms included), document or report, or all of them, may say or show. The brand's own come from BRAND.md; the ones a person taught are one file each in src/content/rules/, saved only after they said yes. Every ad is made and checked against the ones for creatives; an edit to a page, form, creative, document or report shows its own.\n\nStart here:\n baker rules list [--for creatives|landings|documents|reports]\n baker rules add --for landings --text \"No prices on landings.\" --strength never --applies copy --quote \"<their words>\" # only after the person agreed\n baker rules check [--for creatives|landings|reports] # after a rule changes: which ads, pages or reports already made break it\n baker rules retire <id>\nFull guide: __tooling__/docs/tools/baker/rules.md`,\n },\n subCommands: {\n // Loaded with the family: `baker rules --for landings` runs it, and its flags are read before it runs.\n list: rulesListCommand,\n add: () => import(\"./add.ts\").then((m) => m.rulesAddCommand),\n retire: () => import(\"./add.ts\").then((m) => m.rulesRetireCommand),\n check: () => import(\"./check.ts\").then((m) => m.checkCommand),\n },\n default: \"list\",\n});\n","/** `baker rules list`: the company's standing rules, for creatives, landings, documents, reports or all, as they stand now. */\nimport { defineCommand } from \"citty\";\nimport { readAllRules } from \"../../engine/creative-context/index.ts\";\nimport { moveLegacyRules } from \"../../engine/creative-rules/move-rules.ts\";\nimport type { CreativeRule } from \"../../engine/creative-rules/schema.ts\";\nimport { rulesForOutput, selectRules } from \"../../engine/creative-rules/select.ts\";\nimport { writeJson } from \"../../output.ts\";\nimport { registerSchema } from \"../../schemas.ts\";\nimport { findWorkspaceRoot } from \"../canvas/normalize-paths.ts\";\nimport { readCreativeSpecs, readSurface, rulesHints, rulesView, type Surface, waiverCounts } from \"./view.ts\";\n\nconst LIST_DESCRIPTION = `The company's standing rules for every ad, landing, document and report: the brand's own (BRAND.md) and the ones a person taught, each with its id, strength (never | must | prefer), what it holds for (\\`for\\`: landings, documents, reports or all; absent, creatives), what it is about, its words, the person's own words and where it came from. Read the ones for an output before planning it (\\`--for creatives\\`, \\`--for landings\\`, …); an edit to a page, form, creative, document or report shows that output's.\nStart here: baker rules list\n baker rules list --for creatives # the rules every creative is held to\n baker rules list --for landings # the rules every page and form is held to\n baker rules list --for documents # the rules every document is held to\n baker rules list --kind video --product cubbo-engage # the rules one ad is held to\n baker rules list --all # retired ones and every scope too`;\n\nconst LIST_ARGS = {\n for: {\n type: \"string\",\n description:\n \"creatives | landings | documents | reports: only the rules that output is held to (a form is a landing)\",\n required: false,\n },\n kind: {\n type: \"string\",\n description: \"static | video: only the rules an ad of this kind is held to\",\n required: false,\n },\n product: {\n type: \"string\",\n description: \"A product slug (src/content/products/<slug>.md): only the rules an ad of it is held to\",\n required: false,\n },\n all: {\n type: \"boolean\",\n description: \"Every rule, retired ones and every scope included\",\n required: false,\n default: false,\n },\n full: { type: \"boolean\", description: \"Each rule and the person's words whole\", required: false, default: false },\n} as const;\n\nregisterSchema({ command: \"rules.list\", description: LIST_DESCRIPTION, args: LIST_ARGS });\n\n/**\n * The active rules `rules list` shows: the ones for one output (creatives: one kind or product's when\n * narrowed), or with none named, the creatives' and the ones only for each other output, unless a kind\n * or product names one ad. Pure.\n */\nexport function listedRules(\n rules: readonly CreativeRule[],\n on: { surface?: Surface; kind?: \"static\" | \"video\"; product?: string },\n): CreativeRule[] {\n if (on.surface && on.surface !== \"creatives\") return rulesForOutput(rules, on.surface);\n const forCreatives = selectRules(rules, {\n ...(on.kind ? { kind: on.kind } : {}),\n ...(on.product ? { product: on.product } : {}),\n });\n if (on.surface === \"creatives\" || on.kind || on.product) return forCreatives;\n const others = ([\"landings\", \"documents\", \"reports\"] as const).flatMap((output) =>\n rulesForOutput(rules, output).filter((r) => r.for === output),\n );\n return [...forCreatives, ...others];\n}\n\n/**\n * The output whose one prompt carries the most of the rules `rules list` shows, and how many: the one\n * named, or with none named, the longest of the creatives' and each other output's. Pure.\n */\nexport function longestPrompt(\n rules: readonly CreativeRule[],\n on: { surface?: Surface; kind?: \"static\" | \"video\"; product?: string },\n): { output: Surface; count: number } {\n if (on.surface && on.surface !== \"creatives\") {\n return { output: on.surface, count: rulesForOutput(rules, on.surface).length };\n }\n const creatives = {\n output: \"creatives\" as const,\n count: selectRules(rules, { ...(on.kind ? { kind: on.kind } : {}), ...(on.product ? { product: on.product } : {}) })\n .length,\n };\n if (on.surface === \"creatives\" || on.kind || on.product) return creatives;\n return ([\"landings\", \"documents\", \"reports\"] as const)\n .map((output) => ({ output, count: rulesForOutput(rules, output).length }))\n .reduce((most, next) => (next.count > most.count ? next : most), creatives as { output: Surface; count: number });\n}\n\n/** What stayed in the old rules folder when the rules moved: no ad or page is held to it. Pure. */\nexport function unmovedHints(conflicts: readonly string[]): string[] {\n if (conflicts.length === 0) return [];\n return [\n `Not moved to src/content/rules/, so nothing is held to it: ${conflicts.join(\", \")} (a different rule of the same name is already there, or the company keeps its own rules collection). Never merge them by hand: tell the Baker team with \\`baker feedback report\\`.`,\n ];\n}\n\nexport const rulesListCommand = defineCommand({\n meta: { name: \"list\", description: LIST_DESCRIPTION },\n args: LIST_ARGS,\n async run({ args }) {\n const target = readSurface(args.for);\n if (!target) {\n writeJson({\n ok: false,\n error: {\n code: \"VALIDATION_ERROR\",\n message: `--for: creatives, landings, documents or reports, not \"${String(args.for)}\" (a form counts as a landing).`,\n fix: \"Leave --for out to list the rules for every output together.\",\n },\n });\n process.exit(1);\n }\n const root = findWorkspaceRoot(process.cwd()) ?? process.cwd();\n const kind: \"static\" | \"video\" | undefined =\n args.kind === \"static\" || args.kind === \"video\" ? args.kind : undefined;\n const product = typeof args.product === \"string\" && args.product ? args.product : undefined;\n const [rules, specs] = await Promise.all([readAllRules(root), readCreativeSpecs(root)]);\n const on = { ...target, ...(kind ? { kind } : {}), ...(product ? { product } : {}) };\n const active = listedRules(rules, on);\n const shown = args.all === true ? rules : active;\n const hints = [\n ...rulesHints(active, waiverCounts(specs), longestPrompt(rules, on)),\n ...unmovedHints((await moveLegacyRules(root)).conflicts),\n ];\n const meta = { count: shown.length, active: active.length, total: rules.length };\n writeJson({\n ok: true,\n data: rulesView(shown, { full: args.full === true }),\n meta,\n ...(hints.length > 0 ? { hints } : {}),\n });\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAAA,sBAAqB;;;ACC9B,SAAS,qBAAqB;AAU9B,IAAM,mBA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6 @@
1
1
  {
2
2
  "name": "@koda-sl/baker-cli",
3
- "version": "0.896.0",
3
+ "version": "0.898.0",
4
4
  "description": "AI-agent-first CLI for interacting with Baker, including the Baker creative canvas.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/rules/view.ts"],"sourcesContent":["/**\n * The company's rules as the agent reads them in `baker rules list`: what each is for (creatives, landings, documents, reports or all), each one's id, strength and words, the person's own words when\n * they taught it, and where it came from; and which ones ads keep waiving. Pure, but for the read\n * of the ads' waivers.\n */\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { CreativeRule } from \"../../engine/creative-rules/schema.ts\";\n\nexport const SURFACES = [\"creatives\", \"landings\", \"documents\", \"reports\"] as const;\nexport type Surface = (typeof SURFACES)[number];\n\n/** What `--for` names on the commands that read rules or pieces: one output (`ads` is creatives' old name), {} when left out, null for anything else. Pure. */\nexport function readSurface(value: unknown): { surface?: Surface } | null {\n if (value === undefined) return {};\n const surface = SURFACES.find((s) => s === (value === \"ads\" ? \"creatives\" : value));\n return surface ? { surface } : null;\n}\n\n/** A rule cut to this in the compact view: the whole is behind `--full`. */\nconst RULE_CHARS = 200;\nconst QUOTE_CHARS = 160;\n/** Waived this often, a rule may no longer hold. */\nconst RETIRE_AFTER = 3;\n/** Past this many active rules, every prompt carries a long list: worth a look. */\nconst MANY_RULES = 40;\n\nconst cut = (text: string, max: number) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);\n\n/** Where a rule came from, in a few words. */\nfunction fromOf(rule: CreativeRule): string {\n if (rule.origin === \"declared\") return \"BRAND.md\";\n const when = rule.source.date ? ` ${rule.source.date}` : \"\";\n const where = rule.source.slug ? ` on ${rule.source.slug}` : \"\";\n return `taught${when}${where}`;\n}\n\nexport type RuleView = {\n id: string;\n strength: CreativeRule[\"strength\"];\n /** landings, documents, reports or all; absent, the rule is for creatives. */\n for?: CreativeRule[\"for\"];\n applies: CreativeRule[\"applies\"];\n rule: string;\n their_words?: string;\n from: string;\n /** The words it bans in an ad's words, and the phrases that may still hold them. */\n bans?: string[];\n except?: string[];\n /** Words every ad must say. */\n requires?: string[];\n /** Only real people may appear. */\n people?: \"real\";\n scope?: CreativeRule[\"scope\"];\n status?: \"retired\";\n retired_by?: string;\n};\n\n/** What code checks of a rule, as the agent reads it. Pure. */\nfunction checkView(check: CreativeRule[\"check\"]): Pick<RuleView, \"bans\" | \"except\" | \"requires\" | \"people\"> {\n return {\n ...(check?.forbid ? { bans: check.forbid } : {}),\n ...(check?.allow ? { except: check.allow } : {}),\n ...(check?.require ? { requires: check.require } : {}),\n ...(check?.people ? { people: check.people } : {}),\n };\n}\n\n/** Each rule as the agent reads it. Pure. */\nexport function rulesView(rules: readonly CreativeRule[], opts: { full?: boolean } = {}): RuleView[] {\n const max = opts.full ? Number.POSITIVE_INFINITY : RULE_CHARS;\n const quoteMax = opts.full ? Number.POSITIVE_INFINITY : QUOTE_CHARS;\n return rules.map((r) => ({\n id: r.id,\n strength: r.strength,\n ...(r.for ? { for: r.for } : {}),\n applies: r.applies,\n rule: cut(r.text, max),\n ...(r.source.quote ? { their_words: cut(r.source.quote, quoteMax) } : {}),\n from: fromOf(r),\n ...checkView(r.check),\n ...(Object.keys(r.scope).length > 0 ? { scope: r.scope } : {}),\n ...(r.status === \"retired\" ? { status: \"retired\" as const } : {}),\n ...(r.retiredBy ? { retired_by: r.retiredBy } : {}),\n }));\n}\n\n/** How many ads waive each rule (`waive: [{rule, why}]` in their prompt.json). Pure. */\nexport function waiverCounts(specs: readonly unknown[]): Map<string, number> {\n const counts = new Map<string, number>();\n for (const spec of specs) {\n const waive = (spec as { waive?: unknown } | null)?.waive;\n if (!Array.isArray(waive)) continue;\n for (const entry of waive) {\n const id = (entry as { rule?: unknown } | null)?.rule;\n if (typeof id === \"string\" && id) counts.set(id, (counts.get(id) ?? 0) + 1);\n }\n }\n return counts;\n}\n\n/** Every creative's prompt.json, parsed; one that cannot be read is left out. */\nexport async function readCreativeSpecs(root: string): Promise<unknown[]> {\n const dir = path.join(root, \"src\", \"creatives\");\n const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);\n const specs = await Promise.all(\n entries\n .filter((e) => e.isDirectory() && !e.name.startsWith(\"_\"))\n .map((e) =>\n readFile(path.join(dir, e.name, \"prompt.json\"), \"utf8\")\n .then((raw): unknown => JSON.parse(raw))\n .catch(() => null),\n ),\n );\n return specs.filter((s) => s !== null);\n}\n\n/** What the rules say to do next: retire one ads keep waiving, look at a list grown long. Pure. */\nexport function rulesHints(active: readonly CreativeRule[], waived: ReadonlyMap<string, number>): string[] {\n const hints: string[] = [];\n for (const rule of active) {\n const times = waived.get(rule.id) ?? 0;\n if (times >= RETIRE_AFTER) {\n hints.push(\n `${rule.id} was waived by ${times} ads: ask the person whether it still holds, and \\`baker rules retire ${rule.id}\\` if not.`,\n );\n }\n }\n if (active.length > MANY_RULES) {\n hints.push(\n `${active.length} active rules: every prompt carries them all. Ask the person whether some can be retired or merged.`,\n );\n }\n return hints;\n}\n"],"mappings":";AAKA,SAAS,SAAS,gBAAgB;AAClC,OAAO,UAAU;AAGV,IAAM,WAAW,CAAC,aAAa,YAAY,aAAa,SAAS;AAIjE,SAAS,YAAY,OAA8C;AACxE,MAAI,UAAU,OAAW,QAAO,CAAC;AACjC,QAAM,UAAU,SAAS,KAAK,CAAC,MAAM,OAAO,UAAU,QAAQ,cAAc,MAAM;AAClF,SAAO,UAAU,EAAE,QAAQ,IAAI;AACjC;AAGA,IAAM,aAAa;AACnB,IAAM,cAAc;AAEpB,IAAM,eAAe;AAErB,IAAM,aAAa;AAEnB,IAAM,MAAM,CAAC,MAAc,QAAiB,KAAK,SAAS,MAAM,GAAG,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC,WAAM;AAG/F,SAAS,OAAO,MAA4B;AAC1C,MAAI,KAAK,WAAW,WAAY,QAAO;AACvC,QAAM,OAAO,KAAK,OAAO,OAAO,IAAI,KAAK,OAAO,IAAI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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/ads/meta/pixels.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { DateTime } from \"luxon\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { writeAdsJson, writeAdsOutput } from \"../output.ts\";\nimport type { AdsWarning } from \"../types.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n daysAgoIso,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n readEachAccount,\n todayIso,\n withAccountColumn,\n} from \"./shared.ts\";\n\nexport const pixelsCommand = defineCommand({\n meta: {\n name: \"pixels\",\n description: `List Meta Pixels for an ad account, or count what one pixel received — the firing read, not ad-attributed conversions.\n\nThe list prints each pixel's id, name, last_fired_time and owner (unavailable: true when Meta marks it so); --full adds the install code and the setup fields.\n\n--stats prints one row per day per event (date, weekday, event, count) by default, in the ad account's time zone; --by hour or --by total change the grain, --full returns Meta's raw hourly buckets.\n\nExamples:\n baker ads meta pixels --account-id act_123\n baker ads meta pixels --pixel-id 9876 --stats --days 7 # per day per event\n baker ads meta pixels --pixel-id 9876 --stats --days 7 --event Lead,Purchase # only those events\n baker ads meta pixels --pixel-id 9876 --stats --days 30 --by total # each event's count, first and last seen`,\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"pixel-id\": { type: \"string\", description: \"Pixel ID for --stats\" },\n stats: { type: \"boolean\", description: \"Fetch firing stats for the pixel\" },\n aggregation: {\n type: \"string\",\n description: \"stats aggregation: event|browser_type|host|pixel_fire\",\n default: \"event\",\n },\n days: { type: \"string\", description: \"Lookback days for --stats (default 7)\" },\n by: {\n type: \"string\",\n description:\n \"--stats grain: day (default; one row per day per value, with its weekday), hour (one row per hour per value), total (one row per value with first_seen/last_seen)\",\n },\n event: {\n type: \"string\",\n description: \"--stats: keep only these values, comma-separated and exact (e.g. --event Lead,Purchase)\",\n },\n full: {\n type: \"boolean\",\n description:\n \"The list: every field, the install code included. --stats: Meta's raw hourly buckets, every value, instead of the rows\",\n },\n \"no-cache\": NO_CACHE_ARG,\n output: { type: \"string\", description: \"Output format: json|csv|jsonl|md\", default: \"json\" },\n },\n run: async ({ args }) => {\n try {\n if (args.stats) {\n await runStats(args);\n return;\n }\n await runList(args);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nasync function runStats(args: Record<string, unknown>): Promise<void> {\n const pixelId = args[\"pixel-id\"] as string | undefined;\n if (!pixelId) {\n handleMetaError(new Error(\"--pixel-id is required when --stats is set\"));\n }\n const days = args.days ? Number(args.days) : 7;\n if (!Number.isInteger(days) || days <= 0 || days > 90) {\n handleMetaError(new Error(\"--days must be a positive integer ≤ 90\"));\n }\n const params: Record<string, string> = {\n \"pixel-id\": pixelId,\n aggregation: (args.aggregation as string) ?? \"event\",\n \"start-time\": daysAgoIso(days),\n \"end-time\": todayIso(),\n };\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const by = (args.by as string | undefined) ?? \"day\";\n if (!isStatsGrain(by)) {\n writeAdsJson({\n ok: false,\n error: { code: \"INVALID_ARGS\", message: `--by must be one of ${STATS_GRAINS.join(\", \")}` },\n });\n process.exit(1);\n }\n const buckets = await apiGet<PixelStatBucket[]>(\"/api/ads/meta/pixel-stats\", params);\n if (args.full) {\n emit(buckets as Array<Record<string, unknown>>, args);\n return;\n }\n const events =\n typeof args.event === \"string\"\n ? args.event\n .split(\",\")\n .map((e) => e.trim())\n .filter(Boolean)\n : [];\n const window = { start: `${params[\"start-time\"]}T00:00:00Z`, end: `${params[\"end-time\"]}T00:00:00Z` };\n const { rows, hints } = rollUpPixelStats(buckets, { aggregation: params.aggregation ?? \"event\", by, events, window });\n writeAdsOutput(rows, csvOrJson(args), undefined, hints);\n}\n\n/** One time bucket as Meta's `/{pixel}/stats` returns it; `start_time` carries the ad account's offset. */\ninterface PixelStatBucket {\n start_time?: string;\n data?: Array<{ value?: string; count?: number }>;\n}\n\nconst STATS_GRAINS = [\"day\", \"hour\", \"total\"] as const;\ntype StatsGrain = (typeof STATS_GRAINS)[number];\n\nfunction isStatsGrain(value: string): value is StatsGrain {\n return (STATS_GRAINS as readonly string[]).includes(value);\n}\n\ninterface RollUp {\n aggregation: string;\n by: StatsGrain;\n events: string[];\n /** The UTC instants the read asked Meta for. */\n window: { start: string; end: string };\n}\n\n/**\n * Meta answers with one bucket per hour, each a nested list of values, so \"how\n * many Leads a day\" was a script over hundreds of rows at every call site. The\n * day is the one Meta wrote on `start_time` — the ad account's own day.\n */\nfunction rollUpPixelStats(\n buckets: PixelStatBucket[],\n { aggregation, by, events, window }: RollUp,\n): { rows: Array<Record<string, string | number>>; hints: string[] } {\n const { folded, seen } = foldBuckets(buckets, by, new Set(events));\n const rows = [...folded.values()]\n .sort((a, b) => a.key.localeCompare(b.key) || b.count - a.count)\n .map((row): Record<string, string | number> => {\n if (by === \"total\") {\n return { [aggregation]: row.value, count: row.count, first_seen: row.first, last_seen: row.last };\n }\n if (by === \"hour\") return { hour: row.key, [aggregation]: row.value, count: row.count };\n return { date: row.key, weekday: accountWeekday(row.first), [aggregation]: row.value, count: row.count };\n });\n const hints: string[] = [];\n const missing = events.filter((event) => !seen.has(event));\n if (missing.length > 0) {\n const received = [...seen].sort().join(\", \") || \"nothing\";\n hints.push(`No ${missing.join(\", \")} received in this window (names are exact). The pixel received: ${received}.`);\n }\n const partialDays = by === \"day\" && rows.length > 0 ? daysCutByWindow(buckets, window) : [];\n if (partialDays.length > 0) {\n hints.push(\n `${partialDays.join(\" and \")} ${partialDays.length === 1 ? \"is a partial day\" : \"are partial days\"}: the read covers ${window.start} → ${window.end}, so compare only the full days between them.`,\n );\n }\n return { rows, hints };\n}\n\ninterface FoldedRow {\n key: string;\n value: string;\n count: number;\n first: string;\n last: string;\n}\n\nconst ROW_KEY: Record<StatsGrain, (time: string) => string> = {\n day: (time) => accountDay(time),\n hour: (time) => time,\n total: () => \"\",\n};\n\nfunction foldBuckets(\n buckets: PixelStatBucket[],\n by: StatsGrain,\n wanted: Set<string>,\n): { folded: Map<string, FoldedRow>; seen: Set<string> } {\n const entries = buckets.flatMap((bucket) =>\n (bucket.data ?? []).map((entry) => ({\n time: bucket.start_time ?? \"\",\n value: entry.value ?? \"(unnamed)\",\n count: entry.count ?? 0,\n })),\n );\n const folded = new Map<string, FoldedRow>();\n for (const { time, value, count } of entries) {\n if (wanted.size > 0 && !wanted.has(value)) continue;\n const key = ROW_KEY[by](time);\n const id = `${key}\\u0000${value}`;\n const row = folded.get(id) ?? { key, value, count: 0, first: time, last: time };\n row.count += count;\n if (instant(time) < instant(row.first)) row.first = time;\n if (instant(time) > instant(row.last)) row.last = time;\n folded.set(id, row);\n }\n return { folded, seen: new Set(entries.map((entry) => entry.value)) };\n}\n\n/** The account-local days the window starts after or ends before, oldest first. */\nfunction daysCutByWindow(buckets: PixelStatBucket[], window: { start: string; end: string }): string[] {\n const cut = new Set<string>();\n for (const { start_time: time } of buckets) {\n if (time && dayOverhangsWindow(time, window)) cut.add(accountDay(time));\n }\n return [...cut].sort();\n}\n\n/** Whether the account-local day `time` falls on starts before or ends after the window read. */\nfunction dayOverhangsWindow(time: string, window: { start: string; end: string }): boolean {\n const dayStart = bucketTime(time).startOf(\"day\");\n if (!dayStart.isValid) return false;\n return dayStart < DateTime.fromISO(window.start) || dayStart.plus({ days: 1 }) > DateTime.fromISO(window.end);\n}\n\n/** A bucket's `start_time` in the offset Meta wrote on it — the ad account's. */\nfunction bucketTime(time: string): DateTime {\n return DateTime.fromISO(time, { setZone: true });\n}\n\nfunction accountDay(time: string): string {\n return bucketTime(time).toISODate() ?? \"\";\n}\n\n/** Written out so a reader never works the weekday out from the date, and gets it wrong. */\nfunction accountWeekday(time: string): string {\n return bucketTime(time).setLocale(\"en-US\").toFormat(\"ccc\");\n}\n\n/** Compared as instants: across a clock change, the same local hour carries two offsets. */\nfunction instant(time: string): number {\n return bucketTime(time).toMillis();\n}\n\nasync function runList(args: Record<string, unknown>): Promise<void> {\n const accounts = await accountsInScope(args);\n const params: Record<string, string> = {};\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const restricted = new Set<string>();\n const read = await readEachAccount(accounts, async (accountId) => {\n const { pixels, restrictedFields } = await apiGet<{\n pixels: MetaPixel[];\n restrictedFields: string[];\n }>(\"/api/ads/meta/pixels\", { ...params, \"account-id\": accountId });\n for (const field of restrictedFields) restricted.add(field);\n return pixels;\n });\n const rows = args.full ? read.rows : read.rows.map(compactPixel);\n emit(withAccountColumn(rows, read.accountOf), args, pixelWarnings([...restricted]), read.hints);\n}\n\n/** A pixel as the backend lists it; the setup fields are passed through whole under --full. */\ninterface MetaPixel extends Record<string, unknown> {\n id: string;\n name?: string;\n last_fired_time?: string;\n owner_business?: { id?: string; name?: string };\n is_unavailable?: boolean;\n}\n\n/**\n * What picks a pixel and says whether it fires. The install snippet and the\n * setup fields were most of every listing (BAKER-3691) and sit behind --full.\n */\nfunction compactPixel(pixel: MetaPixel): Record<string, unknown> {\n return {\n id: pixel.id,\n name: pixel.name,\n last_fired_time: pixel.last_fired_time,\n ...(pixel.owner_business?.name ? { owner: pixel.owner_business.name } : {}),\n // Kept on every row: the md and csv tables take their columns from the first one.\n unavailable: pixel.is_unavailable ? true : undefined,\n };\n}\n\n/**\n * A listing Meta trimmed is still a listing — IDs, names and firing times are\n * complete. Say which setup fields are missing and how to get them, so the gap\n * reads as a client-side access grant rather than as a pixel that isn't there.\n */\nexport function pixelWarnings(restrictedFields: string[]): AdsWarning[] {\n if (restrictedFields.length === 0) {\n return [];\n }\n return [\n {\n code: \"PIXEL_FIELDS_RESTRICTED\",\n message:\n `Meta withheld ${restrictedFields.join(\", \")} for these pixels — the connected user holds no role in the Business that owns them. ` +\n \"IDs, names, creation and last-fired times are complete; install code and setup details are not. \" +\n \"To get them, the client assigns the pixel to the connected user in Meta Business settings → Data sources → Datasets.\",\n },\n ];\n}\n\nfunction emit(\n data: Array<Record<string, unknown>>,\n args: Record<string, unknown>,\n warnings: AdsWarning[] = [],\n hints: string[] = [],\n): void {\n const fmt = csvOrJson(args);\n if (fmt !== \"json\") {\n writeAdsOutput(data, fmt, undefined, hints);\n return;\n }\n writeAdsJson({\n ok: true,\n data,\n ...(warnings.length > 0 ? { warnings } : {}),\n ...(hints.length > 0 ? { hints } : {}),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAgBlB,IAAM,gBAAgB,cAAc;AAAA,EACzC,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWf;AAAA,EACA,MAAM;AAAA,IACJ,cAAc;AAAA,IACd,YAAY,EAAE,MAAM,UAAU,aAAa,uBAAuB;AAAA,IAClE,OAAO,EAAE,MAAM,WAAW,aAAa,mCAAmC;AAAA,IAC1E,aAAa;AAAA,MACX,MAAM;AAAA,MACN,aAAa;AAAA,MACb,SAAS;AAAA,IACX;AAAA,IACA,MAAM,EAAE,MAAM,UAAU,aAAa,wCAAwC;AAAA,IAC7E,IAAI;AAAA,MACF,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,QAAQ,EAAE,MAAM,UAAU,aAAa,oCAAoC,SAAS,OAAO;AAAA,EAC7F;AAAA,EACA,KAAK,OAAO,EAAE,KAAK,MAAM;AACvB,QAAI;AACF,UAAI,KAAK,OAAO;AACd,cAAM,SAAS,IAAI;AACnB;AAAA,MACF;AACA,YAAM,QAAQ,IAAI;AAAA,IACpB,SAAS,KAAK;AACZ,sBAAgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAED,eAAe,SAAS,MAA8C;AACpE,QAAM,UAAU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,KAAK;AAChG;AAeA,SAAS,aAAa,OAA2C;AAC/D,SAAO;AAAA,IACL,IAAI,MAAM;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,iBAAiB,MAAM;AAAA,IACvB,GAAI,MAAM,gBAAgB,OAAO,EAAE,OAAO,MAAM,eAAe,KAAK,IAAI,CAAC;AAAA;AAAA,IAEzE,aAAa,MAAM,iBAAiB,OAAO;AAAA,EAC7C;AACF;AAOO,SAAS,cAAc,kBAA0C;AACtE,MAAI,iBAAiB,WAAW,GAAG;AACjC,WAAO,CAAC;AAAA,EACV;AACA,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,SACE,iBAAiB,iBAAiB,KAAK,IAAI,CAAC;AAAA,IAGhD;AAAA,EACF;AACF;AAEA,SAAS,KACP,MACA,MACA,WAAyB,CAAC,GAC1B,QAAkB,CAAC,GACb;AACN,QAAM,MAAM,UAAU,IAAI;AAC1B,MAAI,QAAQ,QAAQ;AAClB,mBAAe,MAAM,KAAK,QAAW,KAAK;AAC1C;AAAA,EACF;AACA,eAAa;AAAA,IACX,IAAI;AAAA,IACJ;AAAA,IACA,GAAI,SAAS,SAAS,IAAI,EAAE,SAAS,IAAI,CAAC;AAAA,IAC1C,GAAI,MAAM,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC;AAAA,EACtC,CAAC;AACH;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/rules/index.ts","../src/commands/rules/list.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { rulesListCommand } from \"./list.ts\";\n\nexport const rulesCommand = defineCommand({\n meta: {\n name: \"rules\",\n description: `The company's standing rules: what every creative, landing (forms included), document or report, or all of them, may say or show. The brand's own come from BRAND.md; the ones a person taught are one file each in src/content/rules/, saved only after they said yes. Every ad is made and checked against the ones for creatives; an edit to a page, form, creative, document or report shows its own.\n\nStart here:\n baker rules list [--for creatives|landings|documents|reports]\n baker rules add --for landings --text \"No prices on landings.\" --strength never --applies copy --quote \"<their words>\" # only after the person agreed\n baker rules check [--for creatives|landings|reports] # after a rule changes: which ads, pages or reports already made break it\n baker rules retire <id>\nFull guide: __tooling__/docs/tools/baker/rules.md`,\n },\n subCommands: {\n // Loaded with the family: `baker rules --for landings` runs it, and its flags are read before it runs.\n list: rulesListCommand,\n add: () => import(\"./add.ts\").then((m) => m.rulesAddCommand),\n retire: () => import(\"./add.ts\").then((m) => m.rulesRetireCommand),\n check: () => import(\"./check.ts\").then((m) => m.checkCommand),\n },\n default: \"list\",\n});\n","/** `baker rules list`: the company's standing rules, for creatives, landings, documents, reports or all, as they stand now. */\nimport { defineCommand } from \"citty\";\nimport { readAllRules } from \"../../engine/creative-context/index.ts\";\nimport { moveLegacyRules } from \"../../engine/creative-rules/move-rules.ts\";\nimport type { CreativeRule } from \"../../engine/creative-rules/schema.ts\";\nimport { rulesForOutput, selectRules } from \"../../engine/creative-rules/select.ts\";\nimport { writeJson } from \"../../output.ts\";\nimport { registerSchema } from \"../../schemas.ts\";\nimport { findWorkspaceRoot } from \"../canvas/normalize-paths.ts\";\nimport { readCreativeSpecs, readSurface, rulesHints, rulesView, type Surface, waiverCounts } from \"./view.ts\";\n\nconst LIST_DESCRIPTION = `The company's standing rules for every ad, landing, document and report: the brand's own (BRAND.md) and the ones a person taught, each with its id, strength (never | must | prefer), what it holds for (\\`for\\`: landings, documents, reports or all; absent, creatives), what it is about, its words, the person's own words and where it came from. Read the ones for an output before planning it (\\`--for creatives\\`, \\`--for landings\\`, …); an edit to a page, form, creative, document or report shows that output's.\nStart here: baker rules list\n baker rules list --for creatives # the rules every creative is held to\n baker rules list --for landings # the rules every page and form is held to\n baker rules list --for documents # the rules every document is held to\n baker rules list --kind video --product cubbo-engage # the rules one ad is held to\n baker rules list --all # retired ones and every scope too`;\n\nconst LIST_ARGS = {\n for: {\n type: \"string\",\n description:\n \"creatives | landings | documents | reports: only the rules that output is held to (a form is a landing)\",\n required: false,\n },\n kind: {\n type: \"string\",\n description: \"static | video: only the rules an ad of this kind is held to\",\n required: false,\n },\n product: {\n type: \"string\",\n description: \"A product slug (src/content/products/<slug>.md): only the rules an ad of it is held to\",\n required: false,\n },\n all: {\n type: \"boolean\",\n description: \"Every rule, retired ones and every scope included\",\n required: false,\n default: false,\n },\n full: { type: \"boolean\", description: \"Each rule and the person's words whole\", required: false, default: false },\n} as const;\n\nregisterSchema({ command: \"rules.list\", description: LIST_DESCRIPTION, args: LIST_ARGS });\n\n/**\n * The active rules `rules list` shows: the ones for one output (creatives: one kind or product's when\n * narrowed), or with none named, the creatives' and the ones only for each other output, unless a kind\n * or product names one ad. Pure.\n */\nexport function listedRules(\n rules: readonly CreativeRule[],\n on: { surface?: Surface; kind?: \"static\" | \"video\"; product?: string },\n): CreativeRule[] {\n if (on.surface && on.surface !== \"creatives\") return rulesForOutput(rules, on.surface);\n const forCreatives = selectRules(rules, {\n ...(on.kind ? { kind: on.kind } : {}),\n ...(on.product ? { product: on.product } : {}),\n });\n if (on.surface === \"creatives\" || on.kind || on.product) return forCreatives;\n const others = ([\"landings\", \"documents\", \"reports\"] as const).flatMap((output) =>\n rulesForOutput(rules, output).filter((r) => r.for === output),\n );\n return [...forCreatives, ...others];\n}\n\n/** What stayed in the old rules folder when the rules moved: no ad or page is held to it. Pure. */\nexport function unmovedHints(conflicts: readonly string[]): string[] {\n if (conflicts.length === 0) return [];\n return [\n `Not moved to src/content/rules/, so nothing is held to it: ${conflicts.join(\", \")} (a different rule of the same name is already there, or the company keeps its own rules collection). Never merge them by hand: tell the Baker team with \\`baker feedback report\\`.`,\n ];\n}\n\nexport const rulesListCommand = defineCommand({\n meta: { name: \"list\", description: LIST_DESCRIPTION },\n args: LIST_ARGS,\n async run({ args }) {\n const target = readSurface(args.for);\n if (!target) {\n writeJson({\n ok: false,\n error: {\n code: \"VALIDATION_ERROR\",\n message: `--for: creatives, landings, documents or reports, not \"${String(args.for)}\" (a form counts as a landing).`,\n fix: \"Leave --for out to list the rules for every output together.\",\n },\n });\n process.exit(1);\n }\n const root = findWorkspaceRoot(process.cwd()) ?? process.cwd();\n const kind = args.kind === \"static\" || args.kind === \"video\" ? args.kind : undefined;\n const product = typeof args.product === \"string\" && args.product ? args.product : undefined;\n const [rules, specs] = await Promise.all([readAllRules(root), readCreativeSpecs(root)]);\n const forAds = selectRules(rules, { ...(kind ? { kind } : {}), ...(product ? { product } : {}) });\n const active = listedRules(rules, { ...target, ...(kind ? { kind } : {}), ...(product ? { product } : {}) });\n const shown = args.all === true ? rules : active;\n const hints = [\n ...rulesHints(forAds, waiverCounts(specs)),\n ...unmovedHints((await moveLegacyRules(root)).conflicts),\n ];\n const meta = { count: shown.length, active: active.length, total: rules.length };\n writeJson({\n ok: true,\n data: rulesView(shown, { full: args.full === true }),\n meta,\n ...(hints.length > 0 ? { hints } : {}),\n });\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAAA,sBAAqB;;;ACC9B,SAAS,qBAAqB;AAU9B,IAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQzB,IAAM,YAAY;AAAA,EAChB,KAAK;AAAA,IACH,MAAM;AAAA,IACN,aACE;AAAA,IACF,UAAU;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA,KAAK;AAAA,IACH,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,SAAS;AAAA,EACX;AAAA,EACA,MAAM,EAAE,MAAM,WAAW,aAAa,0CAA0C,UAAU,OAAO,SAAS,MAAM;AAClH;AAEA,eAAe,EAAE,SAAS,cAAc,aAAa,kBAAkB,MAAM,UAAU,CAAC;AAOjF,SAAS,YACd,OACA,IACgB;AAChB,MAAI,GAAG,WAAW,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