@koda-sl/baker-cli 0.868.0-dev.009dcef7a → 0.868.0-dev.5be0a9a76

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.
Files changed (30) hide show
  1. package/README.md +3 -4
  2. package/dist/{add-ZMOFKHFR.js → add-TKHBYZF6.js} +2 -2
  3. package/dist/{ads-66KVUF35.js → ads-U33JFGCR.js} +3 -3
  4. package/dist/{chunk-LJO3I2W2.js → chunk-BPIHAIWB.js} +11 -20
  5. package/dist/chunk-BPIHAIWB.js.map +1 -0
  6. package/dist/{chunk-MIIY3MVK.js → chunk-TY4MTOTL.js} +22 -1
  7. package/dist/chunk-TY4MTOTL.js.map +1 -0
  8. package/dist/cli.js +3 -3
  9. package/dist/cli.js.map +1 -1
  10. package/dist/{flows-PP6BRBD7.js → flows-FRWZWHXZ.js} +3 -3
  11. package/dist/{linkedin-OZGEZLN5.js → linkedin-EBOTX37R.js} +4 -8
  12. package/dist/{linkedin-OZGEZLN5.js.map → linkedin-EBOTX37R.js.map} +1 -1
  13. package/dist/{meta-C7VHIHDL.js → meta-SPPSYRMC.js} +2 -2
  14. package/dist/{preview-25YWCQBJ.js → preview-4GUQGDBD.js} +47 -130
  15. package/dist/preview-4GUQGDBD.js.map +1 -0
  16. package/dist/preview-HD3QAR53.js +104 -0
  17. package/dist/preview-HD3QAR53.js.map +1 -0
  18. package/dist/{tags-IQ6BCRLE.js → tags-DFCLKJX7.js} +26 -15
  19. package/dist/tags-DFCLKJX7.js.map +1 -0
  20. package/package.json +1 -1
  21. package/dist/chunk-LJO3I2W2.js.map +0 -1
  22. package/dist/chunk-MIIY3MVK.js.map +0 -1
  23. package/dist/preview-25YWCQBJ.js.map +0 -1
  24. package/dist/preview-TTIHEWK6.js +0 -147
  25. package/dist/preview-TTIHEWK6.js.map +0 -1
  26. package/dist/tags-IQ6BCRLE.js.map +0 -1
  27. /package/dist/{add-ZMOFKHFR.js.map → add-TKHBYZF6.js.map} +0 -0
  28. /package/dist/{ads-66KVUF35.js.map → ads-U33JFGCR.js.map} +0 -0
  29. /package/dist/{flows-PP6BRBD7.js.map → flows-FRWZWHXZ.js.map} +0 -0
  30. /package/dist/{meta-C7VHIHDL.js.map → meta-SPPSYRMC.js.map} +0 -0
@@ -122,7 +122,7 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
122
122
  pixels: () => import("./pixels-EX6FHVHW.js").then((m) => m.pixelsCommand),
123
123
  activities: () => import("./activities-LC64DAAK.js").then((m) => m.activitiesCommand),
124
124
  insights: () => import("./insights-QU5A4XBO.js").then((m) => m.insightsCommand),
125
- preview: () => import("./preview-25YWCQBJ.js").then((m) => m.previewCommand),
125
+ preview: () => import("./preview-4GUQGDBD.js").then((m) => m.previewCommand),
126
126
  videos: () => import("./videos-TJG5CA7N.js").then((m) => m.videosCommand),
127
127
  targeting: () => import("./targeting-7T7XHBIX.js").then((m) => m.targetingCommand),
128
128
  "instagram-accounts": () => import("./account-assets-L6BX4YUQ.js").then((m) => m.instagramAccountsCommand),
@@ -149,4 +149,4 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
149
149
  export {
150
150
  metaCommand
151
151
  };
152
- //# sourceMappingURL=meta-C7VHIHDL.js.map
152
+ //# sourceMappingURL=meta-SPPSYRMC.js.map
@@ -2,7 +2,7 @@ import {
2
2
  AD_PREVIEW_DIR,
3
3
  AD_PREVIEW_DIR_LABEL,
4
4
  renderAdPreviews
5
- } from "./chunk-LJO3I2W2.js";
5
+ } from "./chunk-BPIHAIWB.js";
6
6
  import "./chunk-VN3WDB4O.js";
7
7
  import {
8
8
  FACEBOOK_PREVIEW_FORMATS,
@@ -15,10 +15,6 @@ import {
15
15
  handleMetaError
16
16
  } from "./chunk-DP76WGDV.js";
17
17
  import "./chunk-QALAJNBG.js";
18
- import {
19
- apiFailure,
20
- eachTarget
21
- } from "./chunk-EMW6TSSB.js";
22
18
  import {
23
19
  NO_CACHE_ARG
24
20
  } from "./chunk-TBT6NWDX.js";
@@ -151,86 +147,10 @@ function previewFileName(target) {
151
147
  if (id) return `meta-${id}`;
152
148
  return `meta-draft-${createHash("sha256").update(target.creative ?? "").digest("hex").slice(0, 12)}`;
153
149
  }
154
- var MAX_PREVIEWS = 24;
155
- function listArg(value) {
156
- if (typeof value !== "string") return [];
157
- return [...new Set(value.split(",").map((item) => item.trim()))].filter(Boolean);
158
- }
159
- function previewSubjects(args) {
160
- const subjects = [
161
- ...listArg(args["creative-id"]).map((creativeId) => ({ creativeId })),
162
- ...listArg(args["ad-id"]).map((adId) => ({ adId }))
163
- ];
164
- if (subjects.length > 0) return subjects;
165
- const text = (value) => typeof value === "string" ? value : void 0;
166
- return [{ accountId: text(args["account-id"]), creative: text(args.creative) }];
167
- }
168
- function previewFormats(placements, args) {
169
- const formats = placements.length > 0 ? placements.map((p) => resolvePlacement(p, args.platform)) : listArg(args["ad-format"]);
170
- if (formats.length === 0) {
171
- failPreviewValidation("pass --ad-format or --placement (see --list-formats)");
172
- }
173
- const invalid = formats.find((adFormat) => !VALID_AD_FORMATS.includes(adFormat));
174
- if (invalid) {
175
- failPreviewValidation(
176
- `Invalid --ad-format "${invalid}". Meta's ad_format values: ${VALID_AD_FORMATS.join(", ")}. To preview a placement you saw in an insights breakdown, pass --placement <platform_position> instead of guessing a format name.`
177
- );
178
- }
179
- return formats;
180
- }
181
- async function fetchPreviews(pairs, skipCache) {
182
- const refusals = [];
183
- const fetched = await eachTarget(
184
- pairs.map((_, i) => String(i)),
185
- (i) => {
186
- const { subject, adFormat } = pairs[Number(i)];
187
- return apiPost("/api/ads/meta/preview", {
188
- ...subject,
189
- adFormat,
190
- ...skipCache ? { skipCache: true } : {}
191
- });
192
- },
193
- (err) => {
194
- refusals.push(err);
195
- return apiFailure(err);
196
- }
197
- );
198
- if (refusals.length === pairs.length) {
199
- handleMetaError(refusals[0]);
200
- }
201
- return fetched;
202
- }
203
- function previewInputs(pairs, fetched, several) {
204
- const inputs = [];
205
- const owners = [];
206
- const refused = [];
207
- for (const [index, outcome] of fetched.entries()) {
208
- const { subject, adFormat } = pairs[index];
209
- const owner = several ? subjectId(subject) : {};
210
- if (!outcome.ok) {
211
- refused.push({ index: inputs.length, entry: { ...owner, placement: adFormat, error: outcome.error.message } });
212
- continue;
213
- }
214
- for (const [i, d] of outcome.data.entries()) {
215
- inputs.push({
216
- placement: outcome.data.length > 1 ? `${adFormat}-${i + 1}` : adFormat,
217
- html: d.body,
218
- name: previewFileName(subject)
219
- });
220
- owners.push(owner);
221
- }
222
- }
223
- return { inputs, owners, refused };
224
- }
225
- function subjectId(subject) {
226
- if ("creativeId" in subject) return { creativeId: subject.creativeId };
227
- if ("adId" in subject) return { adId: subject.adId };
228
- return {};
229
- }
230
150
  var previewCommand = defineCommand({
231
151
  meta: {
232
152
  name: "preview",
233
- description: `See creatives or ads as Meta renders them in one or more placements: shownText (the text people see, in order)
153
+ description: `See a creative or ad as Meta renders it in one placement: shownText (the text people see, in order)
234
154
  plus a picture to Read for what text cannot tell (words in the artwork, cropping, how it looks).
235
155
  --out-file also saves Meta's raw iframe HTML (its URL holds a short-lived access token \u2014 treat as secret).
236
156
 
@@ -239,31 +159,22 @@ image, the button). Start here too when you need to know what a creative looks l
239
159
  Meta's own renderer, so it settles "does my video show as a still image there?" without guessing.
240
160
  Pass the placement straight from an insights breakdown with --placement (a platform_position value),
241
161
  or a Meta ad_format with --ad-format. Run --list-formats to see both sets.
242
- To compare several creatives or placements, pass comma lists in ONE call \u2014 never loop the command:
243
- every creative \xD7 format pair comes back as its own preview, fetched and drawn in parallel (at most ${MAX_PREVIEWS}).
244
162
 
245
163
  Examples:
246
164
  baker ads meta preview --creative-id 6123 --ad-format MOBILE_FEED_STANDARD
247
- baker ads meta preview --creative-id 6123,6124 --ad-format MOBILE_FEED_STANDARD,INSTAGRAM_STORY,INSTAGRAM_REELS
248
165
  baker ads meta preview --creative-id 6123 --placement facebook_reels_overlay --platform facebook
249
166
  baker ads meta preview --ad-id 9988 --ad-format INSTAGRAM_REELS --out-dir /tmp/review
250
167
  baker ads meta preview --account-id act_123 --creative '{"object_story_spec":{...}}' --ad-format MOBILE_FEED_STANDARD`
251
168
  },
252
169
  args: {
253
- "creative-id": {
254
- type: "string",
255
- description: "Existing creative ID, or several comma-separated: --creative-id 6123,6124"
256
- },
257
- "ad-id": { type: "string", description: "Existing ad ID, or several comma-separated: --ad-id 9988,9989" },
170
+ "creative-id": { type: "string", description: "Existing creative ID" },
171
+ "ad-id": { type: "string", description: "Existing ad ID" },
258
172
  "account-id": { type: "string", description: "Required when previewing an unpublished --creative spec" },
259
173
  creative: { type: "string", description: "JSON spec of an unpublished creative (e.g. object_story_spec)" },
260
- "ad-format": {
261
- type: "string",
262
- description: "Meta ad_format value, or several comma-separated: --ad-format MOBILE_FEED_STANDARD,INSTAGRAM_REELS (--list-formats to see them)"
263
- },
174
+ "ad-format": { type: "string", description: "Meta ad_format enum value (--list-formats to see them)" },
264
175
  placement: {
265
176
  type: "string",
266
- description: "platform_position from an insights breakdown (e.g. facebook_reels_overlay), or several comma-separated \u2014 each resolved to an ad_format"
177
+ description: "platform_position from an insights breakdown (e.g. facebook_reels_overlay) \u2014 resolved to an ad_format"
267
178
  },
268
179
  platform: { type: "string", description: "facebook|instagram \u2014 required for --placement feed, which both report" },
269
180
  "list-formats": { type: "boolean", description: "Print the ad_format values and placement mappings, then exit" },
@@ -282,48 +193,54 @@ Examples:
282
193
  });
283
194
  return;
284
195
  }
285
- const placements = listArg(args.placement);
286
- const formats = previewFormats(placements, args);
287
- const subjects = previewSubjects(args);
288
- const pairs = subjects.flatMap((subject) => formats.map((adFormat) => ({ subject, adFormat })));
289
- if (pairs.length > MAX_PREVIEWS) {
196
+ const placement = args.placement;
197
+ const adFormat = placement ? resolvePlacement(placement, args.platform) : args["ad-format"];
198
+ if (!adFormat) {
199
+ failPreviewValidation("pass --ad-format or --placement (see --list-formats)");
200
+ }
201
+ if (!VALID_AD_FORMATS.includes(adFormat)) {
290
202
  failPreviewValidation(
291
- `${subjects.length} ${subjects.length === 1 ? "creative" : "creatives or ads"} \xD7 ${formats.length} formats is ${pairs.length} previews; one call draws at most ${MAX_PREVIEWS}. Split the list.`
203
+ `Invalid --ad-format "${adFormat}". Meta's ad_format values: ${VALID_AD_FORMATS.join(", ")}. To preview a placement you saw in an insights breakdown, pass --placement <platform_position> instead of guessing a format name.`
292
204
  );
293
205
  }
294
- const fetched = await fetchPreviews(pairs, Boolean(args["no-cache"]));
295
- const { inputs, owners, refused } = previewInputs(pairs, fetched, subjects.length > 1);
296
- if (args["out-file"]) {
297
- writeFileSync(args["out-file"], inputs.map((d) => d.html).join("\n"), "utf-8");
206
+ const body = { adFormat };
207
+ if (args["creative-id"]) body.creativeId = args["creative-id"];
208
+ if (args["ad-id"]) body.adId = args["ad-id"];
209
+ if (args["account-id"]) body.accountId = args["account-id"];
210
+ if (args.creative) body.creative = args.creative;
211
+ if (args["no-cache"]) body.skipCache = true;
212
+ try {
213
+ const data = await apiPost("/api/ads/meta/preview", body);
214
+ if (args["out-file"]) {
215
+ writeFileSync(args["out-file"], data.map((d) => d.body).join("\n"), "utf-8");
216
+ }
217
+ const rendered = await renderAdPreviews(
218
+ data.map((d, i) => ({ placement: data.length > 1 ? `${adFormat}-${i + 1}` : adFormat, html: d.body })),
219
+ {
220
+ dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
221
+ name: previewFileName({
222
+ adId: args["ad-id"],
223
+ creativeId: args["creative-id"],
224
+ creative: args.creative
225
+ })
226
+ }
227
+ );
228
+ const hints = placement ? [
229
+ `Rendered ${placement} as ad_format ${adFormat}. Meta does not document what it renders for a creative a placement cannot take, so the picture is the evidence.`,
230
+ ...rendered.hints
231
+ ] : rendered.hints;
232
+ writeJsonEnvelope({
233
+ ok: true,
234
+ data: { adFormat, previews: rendered.previews, ...args["out-file"] ? { file: args["out-file"] } : {} },
235
+ hints
236
+ });
237
+ } catch (err) {
238
+ handleMetaError(err);
298
239
  }
299
- const rendered = await renderAdPreviews(inputs, {
300
- dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
301
- name: "meta"
302
- });
303
- const previews = rendered.previews.map((p, i) => ({ ...owners[i], ...p }));
304
- for (const { index, entry } of refused.reverse()) previews.splice(index, 0, entry);
305
- const hints = [
306
- ...placements.map(
307
- (p, i) => `Rendered ${p} as ad_format ${formats[i]}. Meta does not document what it renders for a creative a placement cannot take, so the picture is the evidence.`
308
- ),
309
- ...rendered.hints,
310
- ...refused.length > 0 ? [
311
- "Meta refused some previews (each says why in its error). Say those could not be checked; the rest are real."
312
- ] : []
313
- ];
314
- writeJsonEnvelope({
315
- ok: true,
316
- data: {
317
- ...formats.length === 1 ? { adFormat: formats[0] } : { adFormats: formats },
318
- previews,
319
- ...args["out-file"] ? { file: args["out-file"] } : {}
320
- },
321
- hints
322
- });
323
240
  }
324
241
  });
325
242
  export {
326
243
  previewCommand,
327
244
  previewFileName
328
245
  };
329
- //# sourceMappingURL=preview-25YWCQBJ.js.map
246
+ //# sourceMappingURL=preview-4GUQGDBD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/meta/preview.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { writeFileSync } from \"node:fs\";\nimport {\n FACEBOOK_PREVIEW_FORMATS,\n INSTAGRAM_PREVIEW_FORMATS,\n PLATFORM_SCOPED_POSITIONS,\n previewFormatForPosition,\n} from \"@baker/api/ads-meta\";\nimport { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiPost } from \"../../../client.ts\";\nimport { AD_PREVIEW_DIR, AD_PREVIEW_DIR_LABEL, renderAdPreviews } from \"../ad-preview-images.ts\";\nimport { writeAdsJson, writeJsonEnvelope } from \"../output.ts\";\nimport { handleMetaError } from \"./shared.ts\";\n\n/**\n * The `ad_format` enum of `generatepreviews` as Meta's reference lists it (every value rendered live on v26.0, 2026-10-15)\n * (read 2026-10-14), plus INSTAGRAM_SHOP — dropped from that list yet still\n * rendered live the same day, so a format an older answer named keeps working.\n */\nconst VALID_AD_FORMATS = [\n \"AUDIENCE_NETWORK_INSTREAM_VIDEO\",\n \"AUDIENCE_NETWORK_INSTREAM_VIDEO_MOBILE\",\n \"AUDIENCE_NETWORK_OUTSTREAM_VIDEO\",\n \"AUDIENCE_NETWORK_REWARDED_VIDEO\",\n \"BIZ_DISCO_FEED_MOBILE\",\n \"DESKTOP_FEED_STANDARD\",\n \"FACEBOOK_IFU_REELS_MOBILE\",\n \"FACEBOOK_PROFILE_FEED_DESKTOP\",\n \"FACEBOOK_PROFILE_FEED_MOBILE\",\n \"FACEBOOK_PROFILE_REELS_MOBILE\",\n \"FACEBOOK_REELS_BANNER\",\n \"FACEBOOK_REELS_BANNER_DESKTOP\",\n \"FACEBOOK_REELS_BANNER_FEED_ANDROID\",\n \"FACEBOOK_REELS_BANNER_FEED_ANDROID_LARGE\",\n \"FACEBOOK_REELS_BANNER_FULLSCREEN_IOS\",\n \"FACEBOOK_REELS_BANNER_FULLSCREEN_MOBILE\",\n \"FACEBOOK_REELS_MOBILE\",\n \"FACEBOOK_REELS_POSTLOOP\",\n \"FACEBOOK_REELS_POSTLOOP_FEED\",\n \"FACEBOOK_REELS_SIMILAR_PRODUCTS_MOBILE\",\n \"FACEBOOK_REELS_STICKER\",\n \"FACEBOOK_STORY_MOBILE\",\n \"FACEBOOK_STORY_STICKER_MOBILE\",\n \"INSTAGRAM_EXPLORE_CONTEXTUAL\",\n \"INSTAGRAM_EXPLORE_GRID_HOME\",\n \"INSTAGRAM_EXPLORE_IMMERSIVE\",\n \"INSTAGRAM_FEED_WEB\",\n \"INSTAGRAM_FEED_WEB_M_SITE\",\n \"INSTAGRAM_LEAD_GEN_MULTI_SUBMIT_ADS\",\n \"INSTAGRAM_PROFILE_FEED\",\n \"INSTAGRAM_PROFILE_REELS\",\n \"INSTAGRAM_REELS\",\n \"INSTAGRAM_REELS_OVERLAY\",\n \"INSTAGRAM_REELS_WEB\",\n \"INSTAGRAM_REELS_WEB_M_SITE\",\n \"INSTAGRAM_SEARCH_CHAIN\",\n \"INSTAGRAM_SEARCH_GRID\",\n \"INSTAGRAM_SHOP\",\n \"INSTAGRAM_STANDARD\",\n \"INSTAGRAM_STORY\",\n \"INSTAGRAM_STORY_EFFECT_TRAY\",\n \"INSTAGRAM_STORY_WEB\",\n \"INSTAGRAM_STORY_WEB_M_SITE\",\n \"INSTANT_ARTICLE_RECIRCULATION_AD\",\n \"INSTANT_ARTICLE_STANDARD\",\n \"INSTREAM_BANNER_DESKTOP\",\n \"INSTREAM_BANNER_FEED_IOS\",\n \"INSTREAM_BANNER_FULLSCREEN_IOS\",\n \"INSTREAM_BANNER_FULLSCREEN_MOBILE\",\n \"INSTREAM_BANNER_IMMERSIVE_MOBILE\",\n \"INSTREAM_BANNER_MOBILE\",\n \"INSTREAM_VIDEO_DESKTOP\",\n \"INSTREAM_VIDEO_FULLSCREEN_IOS\",\n \"INSTREAM_VIDEO_FULLSCREEN_MOBILE\",\n \"INSTREAM_VIDEO_IMAGE\",\n \"INSTREAM_VIDEO_IMMERSIVE_MOBILE\",\n \"INSTREAM_VIDEO_MOBILE\",\n \"JOB_BROWSER_DESKTOP\",\n \"JOB_BROWSER_MOBILE\",\n \"MARKETPLACE_MOBILE\",\n \"MESSENGER_MOBILE_INBOX_MEDIA\",\n \"MESSENGER_MOBILE_STORY_MEDIA\",\n \"MOBILE_BANNER\",\n \"MOBILE_FEED_BASIC\",\n \"MOBILE_FEED_STANDARD\",\n \"MOBILE_FULLWIDTH\",\n \"MOBILE_INTERSTITIAL\",\n \"MOBILE_MEDIUM_RECTANGLE\",\n \"MOBILE_NATIVE\",\n \"RIGHT_COLUMN_STANDARD\",\n \"SUGGESTED_VIDEO_DESKTOP\",\n \"SUGGESTED_VIDEO_FULLSCREEN_MOBILE\",\n \"SUGGESTED_VIDEO_IMMERSIVE_MOBILE\",\n \"SUGGESTED_VIDEO_MOBILE\",\n \"WATCH_FEED_HOME\",\n \"WATCH_FEED_MOBILE\",\n \"WHATSAPP_STATUS_MEDIA\",\n];\n\n/** A bad flag is not a network failure — mislabelling it invites a retry of the same doomed call. */\nfunction failPreviewValidation(message: string): never {\n writeAdsJson({ ok: false, error: { code: \"VALIDATION_ERROR\", message } });\n process.exit(1);\n}\n\n/**\n * Preview is the free way to see what Meta actually renders for a creative in a\n * given surface — the check that turns \"this placement must be showing a still\"\n * from a claim into an observation. It was being used by guessing format names,\n * so both doors are open now: the Meta `ad_format` enum via `--ad-format`, and\n * the `platform_position` an insights breakdown reports via `--placement`.\n */\nfunction resolvePlacement(position: string, platform: unknown): string {\n const platformArg = typeof platform === \"string\" ? platform.toLowerCase() : undefined;\n if (platformArg && platformArg !== \"facebook\" && platformArg !== \"instagram\") {\n failPreviewValidation(\"--platform must be facebook or instagram\");\n }\n const format = previewFormatForPosition(position, platformArg);\n if (format) {\n return format;\n }\n if (PLATFORM_SCOPED_POSITIONS.has(position) && !platformArg) {\n failPreviewValidation(\n `--placement ${position} names a different surface on Facebook and on Instagram — add --platform facebook or --platform instagram (the breakdown row's publisher_platform)`,\n );\n }\n failPreviewValidation(\n `No Meta preview format is published for placement \"${position}\". Meta does not document one for every placement (facebook_notification among them), so this placement cannot be previewed — report it as unverified rather than inferring what it renders. Pass the platform_position exactly as the insights breakdown spelled it: targeting names a few surfaces differently (story, reels, explore_home) and those names never appear in a breakdown. Previewable placements: ${listPlacements()}`,\n );\n}\n\nfunction listPlacements(): string {\n const facebook = Object.keys(FACEBOOK_PREVIEW_FORMATS).join(\", \");\n const instagram = Object.keys(INSTAGRAM_PREVIEW_FORMATS).join(\", \");\n return `facebook — ${facebook}; instagram — ${instagram}`;\n}\n\n/** File name for a preview's picture. An unpublished spec has no id, so its content names it. */\nexport function previewFileName(target: { adId?: string; creativeId?: string; creative?: string }): string {\n const id = target.adId ?? target.creativeId;\n if (id) return `meta-${id}`;\n return `meta-draft-${createHash(\"sha256\")\n .update(target.creative ?? \"\")\n .digest(\"hex\")\n .slice(0, 12)}`;\n}\n\nexport const previewCommand = defineCommand({\n meta: {\n name: \"preview\",\n description: `See a creative or ad as Meta renders it in one placement: shownText (the text people see, in order)\nplus a picture to Read for what text cannot tell (words in the artwork, cropping, how it looks).\n--out-file also saves Meta's raw iframe HTML (its URL holds a short-lived access token — treat as secret).\n\nStart here before saying anything about how an ad LOOKS (which text shows, the headline under the\nimage, the button). Start here too when you need to know what a creative looks like in one specific placement — this is\nMeta's own renderer, so it settles \"does my video show as a still image there?\" without guessing.\nPass the placement straight from an insights breakdown with --placement (a platform_position value),\nor a Meta ad_format with --ad-format. Run --list-formats to see both sets.\n\nExamples:\n baker ads meta preview --creative-id 6123 --ad-format MOBILE_FEED_STANDARD\n baker ads meta preview --creative-id 6123 --placement facebook_reels_overlay --platform facebook\n baker ads meta preview --ad-id 9988 --ad-format INSTAGRAM_REELS --out-dir /tmp/review\n baker ads meta preview --account-id act_123 --creative '{\"object_story_spec\":{...}}' --ad-format MOBILE_FEED_STANDARD`,\n },\n args: {\n \"creative-id\": { type: \"string\", description: \"Existing creative ID\" },\n \"ad-id\": { type: \"string\", description: \"Existing ad ID\" },\n \"account-id\": { type: \"string\", description: \"Required when previewing an unpublished --creative spec\" },\n creative: { type: \"string\", description: \"JSON spec of an unpublished creative (e.g. object_story_spec)\" },\n \"ad-format\": { type: \"string\", description: \"Meta ad_format enum value (--list-formats to see them)\" },\n placement: {\n type: \"string\",\n description:\n \"platform_position from an insights breakdown (e.g. facebook_reels_overlay) — resolved to an ad_format\",\n },\n platform: { type: \"string\", description: \"facebook|instagram — required for --placement feed, which both report\" },\n \"list-formats\": { type: \"boolean\", description: \"Print the ad_format values and placement mappings, then exit\" },\n \"out-file\": { type: \"string\", description: \"Also save Meta's iframe HTML to this path\" },\n \"out-dir\": { type: \"string\", description: `Folder for the picture (default: ${AD_PREVIEW_DIR_LABEL})` },\n \"no-cache\": NO_CACHE_ARG,\n },\n run: async ({ args }) => {\n if (args[\"list-formats\"]) {\n writeAdsJson({\n ok: true,\n data: {\n adFormats: VALID_AD_FORMATS,\n placements: { facebook: FACEBOOK_PREVIEW_FORMATS, instagram: INSTAGRAM_PREVIEW_FORMATS },\n },\n });\n return;\n }\n\n const placement = args.placement as string | undefined;\n const adFormat = placement ? resolvePlacement(placement, args.platform) : (args[\"ad-format\"] as string);\n if (!adFormat) {\n failPreviewValidation(\"pass --ad-format or --placement (see --list-formats)\");\n }\n if (!VALID_AD_FORMATS.includes(adFormat)) {\n failPreviewValidation(\n `Invalid --ad-format \"${adFormat}\". Meta's ad_format values: ${VALID_AD_FORMATS.join(\", \")}. To preview a placement you saw in an insights breakdown, pass --placement <platform_position> instead of guessing a format name.`,\n );\n }\n const body: Record<string, unknown> = { adFormat };\n if (args[\"creative-id\"]) body.creativeId = args[\"creative-id\"];\n if (args[\"ad-id\"]) body.adId = args[\"ad-id\"];\n if (args[\"account-id\"]) body.accountId = args[\"account-id\"];\n if (args.creative) body.creative = args.creative;\n if (args[\"no-cache\"]) body.skipCache = true;\n\n try {\n const data = await apiPost<Array<{ body: string }>>(\"/api/ads/meta/preview\", body);\n if (args[\"out-file\"]) {\n writeFileSync(args[\"out-file\"] as string, data.map((d) => d.body).join(\"\\n\"), \"utf-8\");\n }\n const rendered = await renderAdPreviews(\n data.map((d, i) => ({ placement: data.length > 1 ? `${adFormat}-${i + 1}` : adFormat, html: d.body })),\n {\n dir: args[\"out-dir\"] ? String(args[\"out-dir\"]) : AD_PREVIEW_DIR,\n name: previewFileName({\n adId: args[\"ad-id\"] as string | undefined,\n creativeId: args[\"creative-id\"] as string | undefined,\n creative: args.creative as string | undefined,\n }),\n },\n );\n const hints = placement\n ? [\n `Rendered ${placement} as ad_format ${adFormat}. Meta does not document what it renders for a creative a placement cannot take, so the picture is the evidence.`,\n ...rendered.hints,\n ]\n : rendered.hints;\n writeJsonEnvelope({\n ok: true,\n data: { adFormat, previews: rendered.previews, ...(args[\"out-file\"] ? { file: args[\"out-file\"] } : {}) },\n hints,\n });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAO9B,SAAS,qBAAqB;AAY9B,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,SAAS,sBAAsB,SAAwB;AACrD,eAAa,EAAE,IAAI,OAAO,OAAO,EAAE,MAAM,oBAAoB,QAAQ,EAAE,CAAC;AACxE,UAAQ,KAAK,CAAC;AAChB;AASA,SAAS,iBAAiB,UAAkB,UAA2B;AACrE,QAAM,cAAc,OAAO,aAAa,WAAW,SAAS,YAAY,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KAAK,IAAI,GAAG,OAAO;AAAA,MACvF;AACA,YAAM,WAAW,MAAM;AAAA,QACrB,KAAK,IAAI,CAAC,GAAG,OAAO,EAAE,WAAW,KAAK,SAAS,IAAI,GAAG,QAAQ,IAAI,IAAI,CAAC,KAAK,UAAU,MAAM,EAAE,KAAK,EAAE;AAAA,QACrG;AAAA,UACE,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,CAAC,IAAI;AAAA,UACjD,MAAM,gBAAgB;AAAA,YACpB,MAAM,KAAK,OAAO;AAAA,YAClB,YAAY,KAAK,aAAa;AAAA,YAC9B,UAAU,KAAK;AAAA,UACjB,CAAC;AAAA,QACH;AAAA,MACF;AACA,YAAM,QAAQ,YACV;AAAA,QACE,YAAY,SAAS,iBAAiB,QAAQ;AAAA,QAC9C,GAAG,SAAS;AAAA,MACd,IACA,SAAS;AACb,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,MAAM,EAAE,UAAU,UAAU,SAAS,UAAU,GAAI,KAAK,UAAU,IAAI,EAAE,MAAM,KAAK,UAAU,EAAE,IAAI,CAAC,EAAG;AAAA,QACvG;AAAA,MACF,CAAC;AAAA,IACH,SAAS,KAAK;AACZ,sBAAgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,104 @@
1
+ import {
2
+ handleLinkedinError,
3
+ resolveAccountIdArg
4
+ } from "./chunk-SBID6GZZ.js";
5
+ import {
6
+ AD_PREVIEW_DIR,
7
+ AD_PREVIEW_DIR_LABEL,
8
+ renderAdPreviews
9
+ } from "./chunk-BPIHAIWB.js";
10
+ import "./chunk-VN3WDB4O.js";
11
+ import {
12
+ writeJsonEnvelope
13
+ } from "./chunk-NX4EB2TK.js";
14
+ import "./chunk-JGXB7NBP.js";
15
+ import "./chunk-RJHGIRU2.js";
16
+ import "./chunk-WCU362Z6.js";
17
+ import "./chunk-P7YPWBEV.js";
18
+ import "./chunk-GIWHHCD6.js";
19
+ import "./chunk-PNGXJPM5.js";
20
+ import "./chunk-SOPVIIUW.js";
21
+ import "./chunk-G4FG5EQO.js";
22
+ import "./chunk-CS4VA3GQ.js";
23
+ import "./chunk-CVAQZO4I.js";
24
+ import {
25
+ apiPost
26
+ } from "./chunk-EHEPW3O2.js";
27
+ import "./chunk-4OF7Q356.js";
28
+ import "./chunk-RNSC5JPH.js";
29
+ import "./chunk-2RTB2DDO.js";
30
+ import "./chunk-YQSBHWOI.js";
31
+
32
+ // src/commands/ads/linkedin/preview.ts
33
+ import { writeFileSync } from "fs";
34
+ import { defineCommand } from "citty";
35
+ var previewCommand = defineCommand({
36
+ meta: {
37
+ name: "preview",
38
+ description: `See an existing LinkedIn ad exactly as people see it in the feed \u2014 LinkedIn's own renderer,
39
+ for desktop and mobile. Returns shownText (the text displayed, in order) and a picture of each;
40
+ Read the picture only for what text cannot tell (words in the artwork, cropping, how it looks).
41
+
42
+ Start here before saying anything about how an ad LOOKS (which text shows, whether the headline
43
+ appears under the image, what the button says): the API fields say what is stored, the preview
44
+ shows what is displayed. Works for single image, carousel, video, event and job ads that already
45
+ exist on LinkedIn; staged (unpublished) ads have no preview yet.
46
+
47
+ Examples:
48
+ baker ads linkedin preview 1611562694 --account-id 503001492
49
+ baker ads linkedin preview 1611562694 --placement mobile
50
+ baker ads linkedin preview 1611562694 --out-dir /tmp/review`
51
+ },
52
+ args: {
53
+ id: { type: "positional", description: "Creative id or urn:li:sponsoredCreative:N", required: true },
54
+ "account-id": { type: "string", description: "Numeric account ID or urn:li:sponsoredAccount:N" },
55
+ "account-urn": { type: "string", description: "Alias for --account-id" },
56
+ placement: { type: "string", description: "desktop|mobile|both (default: both)", default: "both" },
57
+ "out-dir": { type: "string", description: `Folder for the pictures (default: ${AD_PREVIEW_DIR_LABEL})` },
58
+ "html-file": { type: "string", description: "Also save LinkedIn's raw preview iframes to this file" }
59
+ },
60
+ run: async ({ args }) => {
61
+ const accountId = resolveAccountIdArg(args);
62
+ const placement = String(args.placement);
63
+ if (!["desktop", "mobile", "both"].includes(placement)) {
64
+ writeJsonEnvelope({
65
+ ok: false,
66
+ error: { code: "VALIDATION_ERROR", message: "--placement must be desktop, mobile or both" }
67
+ });
68
+ process.exit(1);
69
+ }
70
+ try {
71
+ const body = { accountId, creativeId: String(args.id) };
72
+ const data = await apiPost("/api/ads/linkedin/preview", body);
73
+ const wanted = data.previews.filter((p) => placement === "both" || p.placement === placement);
74
+ if (wanted.length === 0) {
75
+ writeJsonEnvelope({
76
+ ok: true,
77
+ data: { creativeId: data.creativeId, previews: [] },
78
+ hints: [
79
+ "LinkedIn returned no preview for this ad (its format may not support one). Say its look could not be checked; do not describe it from the API fields."
80
+ ]
81
+ });
82
+ return;
83
+ }
84
+ if (args["html-file"]) {
85
+ writeFileSync(String(args["html-file"]), wanted.map((p) => p.html).join("\n"), "utf-8");
86
+ }
87
+ const rendered = await renderAdPreviews(wanted, {
88
+ dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
89
+ name: `linkedin-${data.creativeId}`
90
+ });
91
+ writeJsonEnvelope({
92
+ ok: true,
93
+ data: { creativeId: data.creativeId, previews: rendered.previews },
94
+ hints: rendered.hints
95
+ });
96
+ } catch (err) {
97
+ handleLinkedinError(err);
98
+ }
99
+ }
100
+ });
101
+ export {
102
+ previewCommand
103
+ };
104
+ //# sourceMappingURL=preview-HD3QAR53.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/linkedin/preview.ts"],"sourcesContent":["import { writeFileSync } from \"node:fs\";\nimport type { LinkedinAdPreviewRequest, LinkedinAdPreviewResponse } from \"@baker/api/ads-linkedin/preview\";\nimport { defineCommand } from \"citty\";\nimport { apiPost } from \"../../../client.ts\";\nimport { AD_PREVIEW_DIR, AD_PREVIEW_DIR_LABEL, renderAdPreviews } from \"../ad-preview-images.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport { handleLinkedinError, resolveAccountIdArg } from \"./shared.ts\";\n\nexport const previewCommand = defineCommand({\n meta: {\n name: \"preview\",\n description: `See an existing LinkedIn ad exactly as people see it in the feed — LinkedIn's own renderer,\nfor desktop and mobile. Returns shownText (the text displayed, in order) and a picture of each;\nRead the picture only for what text cannot tell (words in the artwork, cropping, how it looks).\n\nStart here before saying anything about how an ad LOOKS (which text shows, whether the headline\nappears under the image, what the button says): the API fields say what is stored, the preview\nshows what is displayed. Works for single image, carousel, video, event and job ads that already\nexist on LinkedIn; staged (unpublished) ads have no preview yet.\n\nExamples:\n baker ads linkedin preview 1611562694 --account-id 503001492\n baker ads linkedin preview 1611562694 --placement mobile\n baker ads linkedin preview 1611562694 --out-dir /tmp/review`,\n },\n args: {\n id: { type: \"positional\", description: \"Creative id or urn:li:sponsoredCreative:N\", required: true },\n \"account-id\": { type: \"string\", description: \"Numeric account ID or urn:li:sponsoredAccount:N\" },\n \"account-urn\": { type: \"string\", description: \"Alias for --account-id\" },\n placement: { type: \"string\", description: \"desktop|mobile|both (default: both)\", default: \"both\" },\n \"out-dir\": { type: \"string\", description: `Folder for the pictures (default: ${AD_PREVIEW_DIR_LABEL})` },\n \"html-file\": { type: \"string\", description: \"Also save LinkedIn's raw preview iframes to this file\" },\n },\n run: async ({ args }) => {\n const accountId = resolveAccountIdArg(args);\n const placement = String(args.placement);\n if (![\"desktop\", \"mobile\", \"both\"].includes(placement)) {\n writeJsonEnvelope({\n ok: false,\n error: { code: \"VALIDATION_ERROR\", message: \"--placement must be desktop, mobile or both\" },\n });\n process.exit(1);\n }\n try {\n const body: LinkedinAdPreviewRequest = { accountId, creativeId: String(args.id) };\n const data = await apiPost<LinkedinAdPreviewResponse>(\"/api/ads/linkedin/preview\", body);\n const wanted = data.previews.filter((p) => placement === \"both\" || p.placement === placement);\n if (wanted.length === 0) {\n writeJsonEnvelope({\n ok: true,\n data: { creativeId: data.creativeId, previews: [] },\n hints: [\n \"LinkedIn returned no preview for this ad (its format may not support one). Say its look could not be checked; do not describe it from the API fields.\",\n ],\n });\n return;\n }\n if (args[\"html-file\"]) {\n writeFileSync(String(args[\"html-file\"]), wanted.map((p) => p.html).join(\"\\n\"), \"utf-8\");\n }\n const rendered = await renderAdPreviews(wanted, {\n dir: args[\"out-dir\"] ? String(args[\"out-dir\"]) : AD_PREVIEW_DIR,\n name: `linkedin-${data.creativeId}`,\n });\n writeJsonEnvelope({\n ok: true,\n data: { creativeId: data.creativeId, previews: rendered.previews },\n hints: rendered.hints,\n });\n } catch (err) {\n handleLinkedinError(err);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAMvB,IAAM,iBAAiB,cAAc;AAAA,EAC1C,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaf;AAAA,EACA,MAAM;AAAA,IACJ,IAAI,EAAE,MAAM,cAAc,aAAa,6CAA6C,UAAU,KAAK;AAAA,IACnG,cAAc,EAAE,MAAM,UAAU,aAAa,kDAAkD;AAAA,IAC/F,eAAe,EAAE,MAAM,UAAU,aAAa,yBAAyB;AAAA,IACvE,WAAW,EAAE,MAAM,UAAU,aAAa,uCAAuC,SAAS,OAAO;AAAA,IACjG,WAAW,EAAE,MAAM,UAAU,aAAa,qCAAqC,oBAAoB,IAAI;AAAA,IACvG,aAAa,EAAE,MAAM,UAAU,aAAa,wDAAwD;AAAA,EACtG;AAAA,EACA,KAAK,OAAO,EAAE,KAAK,MAAM;AACvB,UAAM,YAAY,oBAAoB,IAAI;AAC1C,UAAM,YAAY,OAAO,KAAK,SAAS;AACvC,QAAI,CAAC,CAAC,WAAW,UAAU,MAAM,EAAE,SAAS,SAAS,GAAG;AACtD,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,OAAO,EAAE,MAAM,oBAAoB,SAAS,8CAA8C;AAAA,MAC5F,CAAC;AACD,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,QAAI;AACF,YAAM,OAAiC,EAAE,WAAW,YAAY,OAAO,KAAK,EAAE,EAAE;AAChF,YAAM,OAAO,MAAM,QAAmC,6BAA6B,IAAI;AACvF,YAAM,SAAS,KAAK,SAAS,OAAO,CAAC,MAAM,cAAc,UAAU,EAAE,cAAc,SAAS;AAC5F,UAAI,OAAO,WAAW,GAAG;AACvB,0BAAkB;AAAA,UAChB,IAAI;AAAA,UACJ,MAAM,EAAE,YAAY,KAAK,YAAY,UAAU,CAAC,EAAE;AAAA,UAClD,OAAO;AAAA,YACL;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AACA,UAAI,KAAK,WAAW,GAAG;AACrB,sBAAc,OAAO,KAAK,WAAW,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI,GAAG,OAAO;AAAA,MACxF;AACA,YAAM,WAAW,MAAM,iBAAiB,QAAQ;AAAA,QAC9C,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,CAAC,IAAI;AAAA,QACjD,MAAM,YAAY,KAAK,UAAU;AAAA,MACnC,CAAC;AACD,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,MAAM,EAAE,YAAY,KAAK,YAAY,UAAU,SAAS,SAAS;AAAA,QACjE,OAAO,SAAS;AAAA,MAClB,CAAC;AAAA,IACH,SAAS,KAAK;AACZ,0BAAoB,GAAG;AAAA,IACzB;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -1,9 +1,11 @@
1
1
  import {
2
+ COLLAPSED_HINT,
2
3
  failApi,
3
4
  failValidation,
5
+ listedTag,
4
6
  renderEffectiveEntry,
5
7
  tagsListHints
6
- } from "./chunk-MIIY3MVK.js";
8
+ } from "./chunk-TY4MTOTL.js";
7
9
  import {
8
10
  CHAT_READ_ARG
9
11
  } from "./chunk-X32MFGWW.js";
@@ -34,26 +36,32 @@ import "./chunk-YQSBHWOI.js";
34
36
 
35
37
  // src/commands/tags/index.ts
36
38
  import { defineCommand } from "citty";
39
+ var LIST_OUTPUT_DESCRIPTION = "Output format: json|md. Default: json (the envelope); md prints one readable block per tag";
40
+ var LIST_FULL_DESCRIPTION = "Print every config value whole, a custom `code` script included (by default a long value shows as its size)";
41
+ var LIST_JSON_DESCRIPTION = "Same as the default: the JSON envelope (kept for older calls)";
37
42
  registerSchema({
38
43
  command: "tags.list",
39
- description: "Effective marketing tags for this chat: production tags overlaid with the changes staged in this chat. Prints each tag's readable config in full (secrets are never included) \u2014 e.g. the Clarity projectId, GA4 measurementId, or the entire custom `code` snippet \u2014 so reuse a stored value to pre-fill a follow-up change instead of asking the user for something we already have. The printed refs (tag ids or tag_temp_*) are exactly what flow side-effect tagIds should reference. Read-only \u2014 every tag change (create, edit, delete) goes through the request_tag_input approval tool; `baker tags unstage` takes back one this chat staged.",
44
+ description: "Effective marketing tags for this chat: production tags overlaid with the changes staged in this chat, as the JSON envelope (`data` is one row per tag; `--output md` for a readable block per tag). Each tag's readable config is included (secrets are never included) \u2014 e.g. the Clarity projectId or GA4 measurementId \u2014 so reuse a stored value to pre-fill a follow-up change instead of asking the user for something we already have. A long value (a custom `code` script) shows as its size under `collapsed`; `--full` prints it whole. The printed refs (tag ids or tag_temp_*) are exactly what flow side-effect tagIds should reference. Read-only \u2014 every tag change (create, edit, delete) goes through the request_tag_input approval tool; `baker tags unstage` takes back one this chat staged.",
40
45
  args: {
41
- json: { type: "boolean", description: "Print the raw JSON envelope instead of the readable list", required: false }
46
+ output: { type: "string", description: LIST_OUTPUT_DESCRIPTION, required: false, default: "json" },
47
+ full: { type: "boolean", description: LIST_FULL_DESCRIPTION, required: false },
48
+ json: { type: "boolean", description: LIST_JSON_DESCRIPTION, required: false }
42
49
  }
43
50
  });
44
- async function listTags(json) {
51
+ async function listTags(output, full) {
45
52
  try {
46
53
  const chatId = requireChatId();
47
54
  const response = await apiPost("/api/tags/list", { chatId });
48
- const hints = tagsListHints();
49
- if (json) {
50
- writeJson({ ok: true, ...rowsAsData(response, "tags"), hints });
55
+ const tags = full ? response.tags : response.tags.map(listedTag);
56
+ const hints = [...tagsListHints(), ...tags.some((tag) => tag.collapsed) ? [COLLAPSED_HINT] : []];
57
+ if (output !== "md") {
58
+ writeJson({ ok: true, ...rowsAsData({ tags }, "tags"), hints });
51
59
  return;
52
60
  }
53
- if (response.tags.length === 0) {
61
+ if (tags.length === 0) {
54
62
  process.stdout.write("No tags configured.\n");
55
63
  } else {
56
- process.stdout.write(`${response.tags.map(renderEffectiveEntry).join("\n")}
64
+ process.stdout.write(`${tags.map(renderEffectiveEntry).join("\n")}
57
65
  `);
58
66
  }
59
67
  for (const hint of hints) {
@@ -65,16 +73,18 @@ async function listTags(json) {
65
73
  }
66
74
  }
67
75
  var listArgs = {
68
- json: { type: "boolean", description: "Print the raw JSON envelope instead of the readable list" }
76
+ output: { type: "string", description: LIST_OUTPUT_DESCRIPTION, default: "json" },
77
+ full: { type: "boolean", description: LIST_FULL_DESCRIPTION },
78
+ json: { type: "boolean", description: LIST_JSON_DESCRIPTION }
69
79
  };
70
80
  var listCommand = defineCommand({
71
81
  meta: {
72
82
  name: "list",
73
- description: "Effective tags for this chat (production + staged), with each tag's full readable config (secrets excluded) \u2014 reuse a stored value to pre-fill a change rather than asking the user. Refs printed here are what flow side-effect tagIds should use. Example: baker tags list"
83
+ description: "Effective tags for this chat (production + staged) as the JSON envelope, with each tag's readable config (secrets excluded) \u2014 reuse a stored value to pre-fill a change rather than asking the user. Refs printed here are what flow side-effect tagIds should use. A custom `code` script shows as its size; --full prints it. Start here: baker tags list | baker tags list --output md"
74
84
  },
75
85
  args: listArgs,
76
86
  run: async ({ args }) => {
77
- await listTags(args.json === true);
87
+ await listTags(args.output, args.full === true);
78
88
  }
79
89
  });
80
90
  async function listDraft(chat) {
@@ -154,12 +164,13 @@ Every tag change \u2014 create, edit, or delete \u2014 goes through the request_
154
164
 
155
165
  Refs: \`baker tags list\` prints each tag's ref \u2014 a real tag id, or tag_temp_* for creates staged in this chat. Use these refs as flow side-effect tagIds; they keep resolving after publish.
156
166
 
157
- \`baker tags list\` prints each tag's readable config in full (secrets excluded) \u2014 the Clarity projectId, GA4 measurementId, the whole custom \`code\` snippet, etc. Reuse a stored value to pre-fill a follow-up change instead of asking the user for something already installed.
167
+ \`baker tags list\` prints the JSON envelope (\`--output md\` to read it), with each tag's readable config (secrets excluded) \u2014 the Clarity projectId, GA4 measurementId, etc.; a custom \`code\` script shows as its size until \`--full\`. Reuse a stored value to pre-fill a follow-up change instead of asking the user for something already installed.
158
168
 
159
169
  To take back a change this chat staged (before Publish), \`baker tags unstage <ref>\` \u2014 the ref \`baker tags draft\` prints \u2014 or \`--all\`. It never touches a live tag.
160
170
 
161
171
  Examples:
162
- baker tags list # production + staged, full readable config + secret status
172
+ baker tags list # production + staged, config + secret status, as the JSON envelope
173
+ baker tags list --output md --full # readable, custom code scripts whole
163
174
  baker tags draft # review the staged changes awaiting publish
164
175
  baker tags unstage tag_temp_abc123 # take back one staged change
165
176
  Full guide: __tooling__/docs/tools/baker/tags.md`
@@ -180,4 +191,4 @@ export {
180
191
  tagsCommand,
181
192
  unstageBody
182
193
  };
183
- //# sourceMappingURL=tags-IQ6BCRLE.js.map
194
+ //# sourceMappingURL=tags-DFCLKJX7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/tags/index.ts"],"sourcesContent":["import type { TagsDraftListResponse, TagsListResponse, TagsUnstageRequest, TagsUnstageResponse } from \"@baker/api\";\nimport { defineCommand } from \"citty\";\nimport { apiPost } from \"../../client.ts\";\nimport { requireChatId, resolveChatId } from \"../../env.ts\";\nimport { rowsAsData, writeJson } from \"../../output.ts\";\nimport { registerSchema } from \"../../schemas.ts\";\nimport { CHAT_READ_ARG } from \"../chat-arg.ts\";\nimport {\n COLLAPSED_HINT,\n failApi,\n failValidation,\n type ListedTag,\n listedTag,\n renderEffectiveEntry,\n tagsListHints,\n} from \"./shared.ts\";\n\nconst LIST_OUTPUT_DESCRIPTION =\n \"Output format: json|md. Default: json (the envelope); md prints one readable block per tag\";\nconst LIST_FULL_DESCRIPTION =\n \"Print every config value whole, a custom `code` script included (by default a long value shows as its size)\";\nconst LIST_JSON_DESCRIPTION = \"Same as the default: the JSON envelope (kept for older calls)\";\n\nregisterSchema({\n command: \"tags.list\",\n description:\n \"Effective marketing tags for this chat: production tags overlaid with the changes staged in this chat, as the JSON envelope (`data` is one row per tag; `--output md` for a readable block per tag). Each tag's readable config is included (secrets are never included) — e.g. the Clarity projectId or GA4 measurementId — so reuse a stored value to pre-fill a follow-up change instead of asking the user for something we already have. A long value (a custom `code` script) shows as its size under `collapsed`; `--full` prints it whole. The printed refs (tag ids or tag_temp_*) are exactly what flow side-effect tagIds should reference. Read-only — every tag change (create, edit, delete) goes through the request_tag_input approval tool; `baker tags unstage` takes back one this chat staged.\",\n args: {\n output: { type: \"string\", description: LIST_OUTPUT_DESCRIPTION, required: false, default: \"json\" },\n full: { type: \"boolean\", description: LIST_FULL_DESCRIPTION, required: false },\n json: { type: \"boolean\", description: LIST_JSON_DESCRIPTION, required: false },\n },\n});\n\nasync function listTags(output: unknown, full: boolean): Promise<void> {\n try {\n const chatId = requireChatId();\n const response = await apiPost<TagsListResponse>(\"/api/tags/list\", { chatId });\n const tags: ListedTag[] = full ? response.tags : response.tags.map(listedTag);\n const hints = [...tagsListHints(), ...(tags.some((tag) => tag.collapsed) ? [COLLAPSED_HINT] : [])];\n if (output !== \"md\") {\n writeJson({ ok: true, ...rowsAsData({ tags }, \"tags\"), hints });\n return;\n }\n if (tags.length === 0) {\n process.stdout.write(\"No tags configured.\\n\");\n } else {\n process.stdout.write(`${tags.map(renderEffectiveEntry).join(\"\\n\")}\\n`);\n }\n // stdout stays the list and nothing else, so a reader piping it keeps\n // parsing it; the hints go to stderr, where the agent still reads them.\n for (const hint of hints) {\n process.stderr.write(`${hint}\\n`);\n }\n } catch (err) {\n failApi(err);\n }\n}\n\nconst listArgs = {\n output: { type: \"string\", description: LIST_OUTPUT_DESCRIPTION, default: \"json\" },\n full: { type: \"boolean\", description: LIST_FULL_DESCRIPTION },\n json: { type: \"boolean\", description: LIST_JSON_DESCRIPTION },\n} as const;\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"Effective tags for this chat (production + staged) as the JSON envelope, with each tag's readable config (secrets excluded) — reuse a stored value to pre-fill a change rather than asking the user. Refs printed here are what flow side-effect tagIds should use. A custom `code` script shows as its size; --full prints it. Start here: baker tags list | baker tags list --output md\",\n },\n args: listArgs,\n run: async ({ args }) => {\n await listTags(args.output, args.full === true);\n },\n});\n\nasync function listDraft(chat?: unknown): Promise<void> {\n try {\n const chatId = resolveChatId(chat);\n const response = await apiPost<TagsDraftListResponse>(\"/api/tags/draft\", { chatId });\n writeJson({ ok: true, data: response, hints: tagsListHints() });\n } catch (err) {\n failApi(err);\n }\n}\n\nconst draftCommand = defineCommand({\n meta: {\n name: \"draft\",\n description:\n \"Review the tag changes staged in this chat (read-only). Staged changes were approved via request_tag_input and apply when the chat is published. To drop one, `baker tags unstage <ref>` with the ref printed here (or --all); to amend one, propose a follow-up change through the same tool. Takes --chat <id> to read an earlier chat's staged changes instead.\",\n },\n args: { chat: CHAT_READ_ARG },\n run: async ({ args }) => {\n await listDraft(args.chat);\n },\n});\n\nregisterSchema({\n command: \"tags.unstage\",\n description:\n \"Take back a tag change this chat staged, before Publish — the same as discarding its row in the change review. Pass the ref `baker tags draft` prints (a tag id, or tag_temp_* for a staged create), or --all for every staged tag change. Taking back a staged create also drops the secrets the user entered for it. Never touches a live tag: to change or remove one, propose the change through request_tag_input.\",\n args: {\n ref: { type: \"string\", description: \"The staged change's ref, from `baker tags draft`\", required: false },\n all: { type: \"boolean\", description: \"Take back every tag change staged in this chat\", required: false },\n },\n});\n\n/** The request for one unstage, checked before the round trip. */\nexport function unstageBody(args: { ref?: string; all?: boolean }, chatId: string): TagsUnstageRequest {\n const ref = args.ref?.trim();\n if (args.all === true && ref) {\n failValidation(\"Pass one ref to take back that change, or --all for every staged tag change — not both.\");\n }\n if (args.all === true) {\n return { chatId, all: true };\n }\n if (!ref) {\n failValidation(\"Pass the ref of the staged change (from `baker tags draft`), or --all.\");\n }\n return { chatId, ref };\n}\n\nconst unstageCommand = defineCommand({\n meta: {\n name: \"unstage\",\n description:\n \"Take back a tag change this chat staged, before Publish. Examples: baker tags unstage tag_temp_abc123 | baker tags unstage --all\",\n },\n args: {\n ref: { type: \"positional\", description: \"The staged change's ref, from `baker tags draft`\", required: false },\n all: { type: \"boolean\", description: \"Take back every tag change staged in this chat\", required: false },\n },\n run: async ({ args }) => {\n try {\n const body = unstageBody(\n {\n ...(typeof args.ref === \"string\" ? { ref: args.ref } : {}),\n ...(args.all === true ? { all: true } : {}),\n },\n requireChatId(),\n );\n const response = await apiPost<TagsUnstageResponse>(\"/api/tags/draft-op/remove\", body);\n writeJson({\n ...response,\n hints: [\"Taken back: it does not apply when the chat is published. Live tags are unchanged.\"],\n });\n } catch (err) {\n failApi(err);\n }\n },\n});\n\nexport const tagsCommand = defineCommand({\n meta: {\n name: \"tags\",\n description: `Read the client's marketing/analytics tags (Meta pixel, GA4, Google Ads, GTM, Clarity, Hotjar, …) — production tags plus the changes staged in this chat.\n\nEvery tag change — create, edit, or delete — goes through the request_tag_input tool (baker_ui MCP server): propose one or more changes (each becomes a tab in one approval form), pre-fill the non-secret fields you know, and the user reviews, fills secrets, and approves or skips each. Secret values (accessToken, apiSecret, authorizationToken, apiKey, conversionToken, OAuth connections) never pass through the CLI or the chat.\n\nRefs: \\`baker tags list\\` prints each tag's ref — a real tag id, or tag_temp_* for creates staged in this chat. Use these refs as flow side-effect tagIds; they keep resolving after publish.\n\n\\`baker tags list\\` prints the JSON envelope (\\`--output md\\` to read it), with each tag's readable config (secrets excluded) — the Clarity projectId, GA4 measurementId, etc.; a custom \\`code\\` script shows as its size until \\`--full\\`. Reuse a stored value to pre-fill a follow-up change instead of asking the user for something already installed.\n\nTo take back a change this chat staged (before Publish), \\`baker tags unstage <ref>\\` — the ref \\`baker tags draft\\` prints — or \\`--all\\`. It never touches a live tag.\n\nExamples:\n baker tags list # production + staged, config + secret status, as the JSON envelope\n baker tags list --output md --full # readable, custom code scripts whole\n baker tags draft # review the staged changes awaiting publish\n baker tags unstage tag_temp_abc123 # take back one staged change\nFull guide: __tooling__/docs/tools/baker/tags.md`,\n },\n subCommands: {\n list: listCommand,\n draft: draftCommand,\n unstage: unstageCommand,\n },\n // Bare `baker tags` lists the effective tags. `args` stays so citty knows this\n // command's flags when it scans rawArgs for a subcommand name, and `default` (not\n // `run`) dispatches the bare invocation — citty falls through to `run` after a\n // subcommand, so a `run` here would also list on every `baker tags draft`.\n args: listArgs,\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,qBAAqB;AAgB9B,IAAM,0BACJ;AACF,IAAM,wBACJ;AACF,IAAM,wBAAwB;AAE9B,eAAe;AAAA,EACb,SAAS;AAAA,EACT,aACE;AAAA,EACF,MAAM;AAAA,IACJ,QAAQ,EAAE,MAAM,UAAU,aAAa,yBAAyB,UAAU,OAAO,SAAS,OAAO;AAAA,IACjG,MAAM,EAAE,MAAM,WAAW,aAAa,uBAAuB,UAAU,MAAM;AAAA,IAC7E,MAAM,EAAE,MAAM,WAAW,aAAa,uBAAuB,UAAU,MAAM;AAAA,EAC/E;AACF,CAAC;AAED,eAAe,SAAS,QAAiB,MAA8B;AACrE,MAAI;AACF,UAAM,SAAS,cAAc;AAC7B,UAAM,WAAW,MAAM,QAA0B,kBAAkB,EAAE,OAAO,CAAC;AAC7E,UAAM,OAAoB,OAAO,SAAS,OAAO,SAAS,KAAK,IAAI,SAAS;AAC5E,UAAM,QAAQ,CAAC,GAAG,cAAc,GAAG,GAAI,KAAK,KAAK,CAAC,QAAQ,IAAI,SAAS,IAAI,CAAC,cAAc,IAAI,CAAC,CAAE;AACjG,QAAI,WAAW,MAAM;AACnB,gBAAU,EAAE,IAAI,MAAM,GAAG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Q,GAAG;AAAA,IACb;AAAA,EACF;AACF,CAAC;AAEM,IAAM,cAAc,cAAc;AAAA,EACvC,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBf;AAAA,EACA,aAAa;AAAA,IACX,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM;AAAA,EACN,SAAS;AACX,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koda-sl/baker-cli",
3
- "version": "0.868.0-dev.009dcef7a",
3
+ "version": "0.868.0-dev.5be0a9a76",
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/ads/ad-preview-images.ts"],"sourcesContent":["import { mkdirSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { launchBrowser } from \"../../engine/landing-library/browser.ts\";\n\n/**\n * Opens a platform's preview iframe and returns what it displays: the text\n * people read (`shownText`) and a picture for questions text cannot answer.\n *\n * The API's fields say what is stored, not what shows. A Session paused seven\n * live ads because a stored headline read like an internal code, with no way to\n * check whether the feed showed it. The rendered text settles that; the picture\n * covers what is not text — words drawn into the artwork, cropping, layout.\n */\n\nexport interface AdPreviewInput {\n placement: string;\n /** Where the platform shows it (LinkedIn FEED, …) when one placement renders on several surfaces. */\n surface?: string;\n html: string;\n /** The picture's file-name prefix when it differs from the call's `name` (one call previewing several ads). */\n name?: string;\n}\n\ntype AdPreviewWhere = { placement: string; surface?: string };\nexport type AdPreviewResult =\n | (AdPreviewWhere & { shownText: string[]; image: string })\n | (AdPreviewWhere & { error: string });\n\n/** Render `html` (a platform iframe): save a PNG at `file`, return the text it displays. */\nexport type DrawPreview = (html: string, file: string) => Promise<{ text: string }>;\n\nexport const AD_PREVIEW_DIR = join(tmpdir(), \"baker-ad-previews\");\n\n/**\n * The same folder as a sentence, for an arg description.\n *\n * `AD_PREVIEW_DIR` itself must never reach one: it is `tmpdir()` RESOLVED, which is\n * `/tmp/baker-ad-previews` on Linux and `/var/folders/<random>/T/baker-ad-previews` on a Mac — so\n * `catalog:export` wrote whichever machine ran it into `cli-catalog/families/ads-meta.json`, and\n * `catalog.test.ts` then failed for everyone else. The catalog is committed, so a description in it\n * has to be the same on every machine.\n */\nexport const AD_PREVIEW_DIR_LABEL = \"your system temp folder, under baker-ad-previews\";\n\n/** Pictures drawn at once. Each opens its own Chromium, so a long list must not open one per preview. */\nconst DRAW_CONCURRENCY = 4;\n\nexport async function renderAdPreviews(\n inputs: readonly AdPreviewInput[],\n target: { dir: string; name: string },\n draw: DrawPreview = drawPreviewInChromium,\n): Promise<{ previews: AdPreviewResult[]; hints: string[] }> {\n mkdirSync(target.dir, { recursive: true });\n const taken = new Map<string, number>();\n const jobs = inputs.map((input) => {\n const where: AdPreviewWhere = input.surface\n ? { placement: input.placement, surface: input.surface }\n : { placement: input.placement };\n // One file per rendering: a shared name would leave two results pointing at the last picture drawn.\n const base = [input.name ?? target.name, input.placement, input.surface?.toLowerCase()].filter(Boolean).join(\"-\");\n const seen = (taken.get(base) ?? 0) + 1;\n taken.set(base, seen);\n return { where, html: input.html, file: join(target.dir, `${seen > 1 ? `${base}-${seen}` : base}.png`) };\n });\n const previews: AdPreviewResult[] = new Array(jobs.length);\n let next = 0;\n const worker = async (): Promise<void> => {\n while (next < jobs.length) {\n const index = next++;\n const { where, html, file } = jobs[index] as (typeof jobs)[number];\n try {\n const { text } = await draw(html, file);\n previews[index] = { ...where, shownText: shownLines(text), image: file };\n } catch (err) {\n previews[index] = { ...where, error: err instanceof Error ? err.message : String(err) };\n }\n }\n };\n await Promise.all(Array.from({ length: Math.min(DRAW_CONCURRENCY, jobs.length) }, worker));\n return { previews, hints: previewHints(previews) };\n}\n\nfunction shownLines(text: string): string[] {\n return text\n .split(\"\\n\")\n .map((line) => line.replace(/\\s+/g, \" \").trim())\n .filter(Boolean);\n}\n\nfunction previewHints(previews: readonly AdPreviewResult[]): string[] {\n const hints: string[] = [];\n if (previews.some((p) => \"image\" in p)) {\n hints.push(\n \"shownText is what people see on the ad, in order — rendered by the platform itself, so it settles which text is displayed (headline under the image, button, cut-off intro). The API fields only say what is stored. Words drawn into the artwork are not in shownText: Read the image for those, and for cropping or how the ad looks.\",\n );\n }\n if (previews.some((p) => \"error\" in p)) {\n hints.push(\n \"Some previews could not be drawn. Do not describe how those look — say they could not be checked, and carry on with the rest.\",\n );\n }\n return hints;\n}\n\n/**\n * The platforms' iframes have a fixed window (Meta's 335×450) and scroll the rest,\n * which cuts the headline and button off a picture. The frame is grown to its\n * content's height first, so the picture holds the whole ad.\n */\nexport async function drawPreviewInChromium(html: string, file: string): Promise<{ text: string }> {\n const browser = await launchBrowser();\n try {\n const context = await browser.newContext({ viewport: { width: 900, height: 1200 }, deviceScaleFactor: 2 });\n const page = await context.newPage();\n await page.setContent(`<!doctype html><body style=\"margin:0;background:#fff\">${html}</body>`, {\n waitUntil: \"load\",\n timeout: 30_000,\n });\n await page.waitForLoadState(\"networkidle\", { timeout: 15_000 }).catch(() => undefined);\n const iframe = await page.$(\"iframe\");\n if (!iframe) throw new Error(\"the platform returned no preview frame\");\n const frame = await iframe.contentFrame();\n if (frame) {\n const height = await frame.evaluate(() =>\n Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight ?? 0),\n );\n if (height > 0) {\n await iframe.evaluate((node, h) => {\n node.removeAttribute(\"height\");\n (node as HTMLElement).style.height = `${h}px`;\n }, height);\n await frame.waitForLoadState(\"networkidle\", { timeout: 10_000 }).catch(() => undefined);\n }\n }\n await iframe.screenshot({ path: file });\n // innerText follows the layout: hidden elements drop out, line breaks stay.\n const text = frame ? await frame.evaluate(() => document.body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SAAS,MAAM,MAAM;AAAA,QAAS,MAClC,KAAK,IAAI,SAAS,gBAAgB,cAAc,SAAS,MAAM,gBAAgB,CAAC;AAAA,MAClF;AACA,UAAI,SAAS,GAAG;AACd,cAAM,OAAO,SAAS,CAAC,MAAM,MAAM;AACjC,eAAK,gBAAgB,QAAQ;AAC7B,UAAC,KAAqB,MAAM,SAAS,GAAG,CAAC;AAAA,QAC3C,GAAG,MAAM;AACT,cAAM,MAAM,iBAAiB,eAAe,EAAE,SAAS,IAAO,CAAC,EAAE,MAAM,MAAM,MAAS;AAAA,MACxF;AAAA,IACF;AACA,UAAM,OAAO,WAAW,EAAE,MAAM,KAAK,CAAC;AAEtC,UAAM,OAAO,QAAQ,MAAM,MAAM,SAAS,MAAM,SAAS,MAAM,aAAa,EAAE,IAAI;AAClF,WAAO,EAAE,KAAK;AAAA,EAChB,UAAE;AACA,UAAM,QAAQ,MAAM;AAAA,EACtB;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/tags/shared.ts"],"sourcesContent":["import { TAG_IDENTIFYING_FIELD, type TagsEffectiveEntry } from \"@baker/api\";\nimport { ApiError } from \"../../client.ts\";\nimport { writeJson } from \"../../output.ts\";\n\nexport function failApi(err: unknown): never {\n if (err instanceof ApiError) {\n writeJson({ ok: false, error: { code: err.code, message: err.message } });\n process.exit(1);\n }\n if (err instanceof Error) {\n writeJson({ ok: false, error: { code: \"INTERNAL_ERROR\", message: err.message } });\n process.exit(1);\n }\n writeJson({ ok: false, error: { code: \"INTERNAL_ERROR\", message: \"Unexpected error\" } });\n process.exit(1);\n}\n\nexport function failValidation(message: string): never {\n writeJson({ ok: false, error: { code: \"VALIDATION_ERROR\", message } });\n process.exit(1);\n}\n\n/** Indent a possibly multi-line config value so long snippets (the `code` tag) stay readable. */\nfunction renderConfigValue(value: string): string {\n return value.includes(\"\\n\") ? value.replace(/\\n/g, \"\\n \") : value;\n}\n\nexport function renderEffectiveEntry(entry: TagsEffectiveEntry): string {\n const parts = [entry.ref, entry.type];\n if (entry.identifier !== undefined) {\n parts.push(entry.identifier);\n }\n if (entry.staged !== undefined) {\n parts.push(`[staged: ${entry.staged}]`);\n }\n const secretBits = [\n ...entry.secretsSet.map((field) => `${field} ✓ set`),\n ...entry.secretsPending.map((field) => `${field} ⏳ pending`),\n ];\n if (secretBits.length > 0) {\n parts.push(`[secrets: ${secretBits.join(\", \")}]`);\n }\n const header = parts.join(\" \");\n // All config values here are already redacted server-side (secrets stripped),\n // so every field printed is safe to read and reuse. Printing them in full lets\n // the agent auto-populate a follow-up change (e.g. the Clarity projectId or the\n // whole custom `code` snippet) instead of asking the user for a value we store.\n // Skip the identifying field — it's already on the header line as `identifier`.\n const identifyingField = TAG_IDENTIFYING_FIELD[entry.type];\n const configLines = Object.entries(entry.config)\n .filter(([key]) => key !== identifyingField)\n .map(([key, value]) => ` ${key}: ${renderConfigValue(value)}`);\n return configLines.length > 0 ? `${header}\\n${configLines.join(\"\\n\")}` : header;\n}\n\n/**\n * The write path, restated on every read.\n *\n * This family is read-only, so `list` is where a chat decides what to do about\n * a tag — and a production chat decided, from its tool list alone, that the\n * approval form did not exist, never called it, and filed the change as a Task\n * the user had to carry out by hand. The form is attached to every turn\n * (`baker_ui` rides along on each query), so \"it isn't there\" is a conclusion\n * only a failed call may reach.\n */\nexport function tagsListHints(): string[] {\n return [\n \"To create, edit or delete a tag, call the `request_tag_input` approval form (tool `mcp__baker_ui__request_tag_input`, server `baker_ui`) — it is attached to every turn of this chat and collects any secret values itself.\",\n \"Don't conclude the form is unavailable from your tool list: call it, and report what it returns. And never file a tag change as a Task — a Task hands the user work this chat can stage in one call.\",\n ];\n}\n"],"mappings":";;;;;;;;;;;AAIO,SAAS,QAAQ,KAAqB;AAC3C,MAAI,eAAe,UAAU;AAC3B,cAAU,EAAE,IAAI,OAAO,OAAO,EAAE,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,EAAE,CAAC;AACxE,YAAQ,KAAK,CAAC;AAAA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