@koda-sl/baker-cli 0.119.0 → 0.120.0-dev.3b02f951b

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
@@ -82,7 +82,7 @@ Use `--output` to change format:
82
82
 
83
83
  ### Ad Platforms (`baker ads`)
84
84
 
85
- Multi-platform ad data commands. Currently supports Google Ads, with Meta, LinkedIn, and TikTok coming.
85
+ Multi-platform ad commands. Google, Meta, and LinkedIn support both reads and **staged writes** (create/update campaigns, ad sets/ad groups, ads, creatives, audiences — applied on chat publish); X (Twitter) is read + analytics. TikTok is coming.
86
86
 
87
87
  ---
88
88
 
@@ -883,6 +883,36 @@ baker ads meta pixels --account-id act_123
883
883
  baker ads meta pixels --pixel-id 9988 --stats --days 7
884
884
  ```
885
885
 
886
+ #### Staged writes (`baker ads meta campaigns|adsets|ads|creatives|audiences|media|draft`)
887
+
888
+ Meta writes mirror the Google/LinkedIn model: they **never hit the Graph API when you run them**. Each op is validated at stage time (field shapes, budget rules, page/Instagram identity ownership, CBO/ABO exclusivity, status-transition legality), shows in the dashboard chat as a pending Meta change, and applies only when the chat is published. Meta has no atomic batch mutate, so ops apply **sequentially** on publish — one failure skips its dependents but the publish completes.
889
+
890
+ If the company's `metaAdsWriteEnabled` flag is off (the default), publish runs the identical lifecycle **simulated** — fake `sim_meta_*` ids, zero Meta calls. The stage response and `baker ads meta draft` show `mode: "simulated"`.
891
+
892
+ Chain a full ad from scratch with `meta_temp_*` refs (each create returns one):
893
+
894
+ ```bash
895
+ # 1. (optional) upload creative media from the Baker library → publishes an image hash
896
+ baker ads meta media upload --account-id act_123 --kind image --image-id <bakerImageId> # → meta_temp_img
897
+
898
+ # 2. campaign → ad set → creative → ad
899
+ baker ads meta campaigns create --account-id act_123 --name "Q3 Prospecting" --objective OUTCOME_LEADS --daily-budget 50 # → meta_temp_camp
900
+ baker ads meta adsets create --account-id act_123 --campaign meta_temp_camp --name "US 25-54" \
901
+ --optimization-goal OFFSITE_CONVERSIONS --billing-event IMPRESSIONS --pixel-id 111 --custom-event-type LEAD \
902
+ --targeting-file targeting.json # → meta_temp_as
903
+ baker ads meta creatives create --account-id act_123 --page 555 --instagram-user 777 \
904
+ --message "Save money on pet insurance" --link https://example.com --headline "Best cover" \
905
+ --image-ref meta_temp_img --cta SHOP_NOW --standard-enhancements on # → meta_temp_cr
906
+ baker ads meta ads create --account-id act_123 --name "Ad 1" --adset meta_temp_as --creative meta_temp_cr
907
+
908
+ # review + edit before publish
909
+ baker ads meta draft
910
+ baker ads meta draft remove meta_temp_cr # removing a create cascades to dependents
911
+ baker ads meta draft clear
912
+ ```
913
+
914
+ Status changes are `pause|resume|archive` subcommands on `campaigns`/`adsets`/`ads`. `duplicate` reconstructs a paused copy from the live snapshot (`--replace` also pauses the original once the copy publishes). Carousel/dynamic creatives and complex targeting go via `--file` (creativeType `carousel`/`dynamic`; full Meta targeting spec). Advantage+ Creative enhancements: `--standard-enhancements on|off`, or per-feature toggles via a `--file` `enhancements.features` map.
915
+
886
916
  #### Smart defaults (so agents don't enumerate the API)
887
917
 
888
918
  **`insights`** — the workhorse:
@@ -930,7 +960,7 @@ The HTTP backend exposes more endpoints (catalogs, ad-studies, ad-images, labels
930
960
 
931
961
  - `spend` is a decimal string in account currency, not an integer.
932
962
  - `effective_status` ≠ `status`. The dashboard shows effective_status (e.g. `WITH_ISSUES`, `PENDING_REVIEW`, `DISAPPROVED`, `ADSET_PAUSED`).
933
- - Meta creatives are effectively immutable once attached. Editing copy/image/CTA = create a new creative + reattach (writes are out of scope for now).
963
+ - Meta creatives are effectively immutable once attached. Editing copy/image/CTA = stage a new creative + `ads update <id> --creative <ref>` (or `creatives duplicate`), not an edit of the live creative — see [Staged writes](#staged-writes-baker-ads-meta-campaignsadsetsadscreativesaudiencesmediadraft) above.
934
964
  - Currency offsets are non-uniform (JPY/KRW = 1, KWD/BHD = 1000, most = 100). Read `account.currency` before doing budget math.
935
965
 
936
966
  ---
@@ -2631,6 +2661,17 @@ baker canvas run my-canvas.json
2631
2661
  # single node — that old serial workaround is obsolete.
2632
2662
  baker canvas run my-canvas.json --parallel 8
2633
2663
 
2664
+ # 2c. Runs persist across sandboxes/sessions by default: node results sync to a
2665
+ # company-scoped remote cache (small JSON pointers; bytes stay in R2), so a FRESH
2666
+ # sandbox re-runs an already-computed canvas at zero credits — assets rehydrate
2667
+ # from R2, sha-verified. Every run also posts a durable history record (per-node
2668
+ # outputs, credits, cached/fresh) that powers the dashboard's Creatives
2669
+ # generations timeline. Opt out with --remote-cache off (env
2670
+ # BAKER_CANVAS_REMOTE_CACHE=off) and --no-record. With --remote-cache off,
2671
+ # assets are not uploaded, so a recorded run keeps its stats but has no
2672
+ # browsable outputs — pass --no-record too if you want nothing persisted.
2673
+ baker canvas run my-canvas.json --remote-cache off --no-record
2674
+
2634
2675
  # 3. Inspect a finished run (per-node timing, file list, optional video thumbs)
2635
2676
  baker canvas inspect <run_id>
2636
2677
 
@@ -3942,6 +3983,7 @@ baker canvas run ./reference-ad.video.canvas.json
3942
3983
  | Flag | Default | Effect |
3943
3984
  |---|---|---|
3944
3985
  | `--out <path>` | `<video-dir>/<name>.video.canvas.json` | Where to write the canvas (composition is copied alongside). |
3986
+ | `--slug <slug>` | — | Creative slug (lowercase kebab): writes the canvas to `src/creatives/<slug>/<slug>.canvas.json` — the repo convention that attaches every run to the creative's dashboard generation history. `--out` wins over `--slug`. |
3945
3987
  | `--frames <mode>` | `generate` | `generate` emits ONE recast keyframe per scene (the original frame is dropped so the dropped `el_*` assets drive identity); `reuse` wires the real extracted first+last frames straight into the clips (faithful, cheaper, no recast). |
3946
3988
  | `--ambient` | off | Give silent **b-roll** scenes native diegetic ambient (Seedance `generate_audio`), mixed deep under the music bed. Talking scenes already carry voice; check levels don't muddy the mix before keeping it. |
3947
3989
  | `--max-scenes <n>` | all source scenes | **Cost lever that reduces fidelity** — caps the deconstruct, MERGING away every scene beyond the cap (fewer cuts, lost beats). Prints a warning when set; omit it to reproduce every scene. |
@@ -3983,6 +4025,7 @@ baker canvas run ./static-ad.canvas.json
3983
4025
  |---|---|---|
3984
4026
  | `--context <text>` | — | Known provenance (advertiser, category, market) to ground the describe. |
3985
4027
  | `--out <path>` | `<image-dir>/static-ad.canvas.json` (cwd when `<image>` is a URL) | Where to write the canvas (`prompt.json` is written alongside). |
4028
+ | `--slug <slug>` | — | Creative slug (lowercase kebab): writes the canvas to `src/creatives/<slug>/<slug>.canvas.json` — the repo convention that attaches every run to the creative's dashboard generation history. `--out` wins over `--slug`. |
3986
4029
  | `--describe-model <id>` | registry default (`~google/gemini-pro-latest`) | Override the `image_describe` model. |
3987
4030
  | `--select-model <id>` | registry default (`~google/gemini-flash-latest`) | Override the element-selection `text_generate` model. |
3988
4031
  | `--layout-model <id>` | registry default (`~google/gemini-flash-latest`) | Override the global-layout `text_generate` model. |
@@ -4454,6 +4497,26 @@ import {
4454
4497
  } from "@koda-sl/baker-cli/engine";
4455
4498
  ```
4456
4499
 
4500
+ ## Creatives
4501
+
4502
+ Publish an approved canvas render as a first-class Baker creative. The image uploads to the Baker image library (tagged `creative`), a creative record is created/updated, and the command prints the creative reference JSON the dashboard renders in chat.
4503
+
4504
+ ```bash
4505
+ baker creatives publish ./canvas/<run_id>/<final>.png --title "Spring Offer 4x5" \
4506
+ --slug spring-offer-4x5 --run-id r_01JXYZ... \
4507
+ --source-reference-url "https://www.facebook.com/ads/library/?id=..."
4508
+ ```
4509
+
4510
+ | Flag | Effect |
4511
+ |---|---|
4512
+ | `--title <text>` | Required. Human title for the creative. |
4513
+ | `--slug <slug>` | Creative slug (`src/creatives/<slug>/`) — attaches the image to that creative's row, marks it `published`. |
4514
+ | `--run-id <r_…>` | Pins the approved generation from the creative's run history as the published one. |
4515
+ | `--source-reference-url <url>` | Original reference ad URL, recorded on the creative. |
4516
+ | `--context <text>` | Optional describe context for the uploaded image asset. |
4517
+
4518
+ Without `--slug` the command behaves as before (one creative record per published image). With `--slug` it upserts the repo-convention row — the same one the dashboard's Creatives tab and the `src/creatives/{slug}/` folder describe — so publish, repo sync, and run history all land on a single record regardless of order.
4519
+
4457
4520
  ## Help & Discovery
4458
4521
 
4459
4522
  Every command supports `--help` for usage info:
@@ -0,0 +1,31 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ export {
28
+ __commonJS,
29
+ __toESM
30
+ };
31
+ //# sourceMappingURL=chunk-5WRI5ZAA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,97 @@
1
+ import {
2
+ handleConnectionError,
3
+ writeAdsJson
4
+ } from "./chunk-ISFSUDEQ.js";
5
+ import {
6
+ ApiError
7
+ } from "./chunk-K47Q73CK.js";
8
+ import {
9
+ getEnv
10
+ } from "./chunk-YTEAWSEM.js";
11
+
12
+ // src/commands/ads/meta/shared.ts
13
+ var DAY_MS = 864e5;
14
+ function handleMetaError(err) {
15
+ if (err instanceof ApiError) {
16
+ if (err.code === "UNAUTHORIZED" || err.code === "NOT_FOUND") {
17
+ handleConnectionError("meta_ads", err.message);
18
+ }
19
+ const envelope = {
20
+ ok: false,
21
+ error: {
22
+ code: err.code,
23
+ message: err.message,
24
+ fix: { action: "reject", explanation: err.message },
25
+ retryable: err.code === "RATE_LIMITED" || err.code === "INTERNAL_ERROR"
26
+ }
27
+ };
28
+ writeAdsJson(envelope);
29
+ process.exit(1);
30
+ }
31
+ const message = err instanceof Error ? err.message : "Unexpected error";
32
+ writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message } });
33
+ process.exit(1);
34
+ }
35
+ var ACCOUNT_ID_RE = /^(act_)?[0-9]+$/;
36
+ function resolveAccountIdArg(args) {
37
+ const fromArgs = args["account-id"];
38
+ const id = fromArgs || getEnv().BAKER_META_AD_ACCOUNT_ID;
39
+ if (!id) {
40
+ writeAdsJson({
41
+ ok: false,
42
+ error: {
43
+ code: "MISSING_ACCOUNT_ID",
44
+ message: "Pass --account-id or set BAKER_META_AD_ACCOUNT_ID. Run `baker ads meta accounts` to find IDs."
45
+ }
46
+ });
47
+ process.exit(1);
48
+ }
49
+ if (!ACCOUNT_ID_RE.test(id)) {
50
+ writeAdsJson({
51
+ ok: false,
52
+ error: {
53
+ code: "INVALID_ACCOUNT_ID",
54
+ message: `Invalid account ID "${id}". Expected numeric ID, optionally prefixed with "act_".`
55
+ }
56
+ });
57
+ process.exit(1);
58
+ }
59
+ return id.startsWith("act_") ? id : `act_${id}`;
60
+ }
61
+ function getDateRange(args) {
62
+ const datePreset = args["date-preset"];
63
+ const since = args.since;
64
+ const until = args.until;
65
+ if (since && until) return { since, until };
66
+ return { datePreset: datePreset ?? "last_7d" };
67
+ }
68
+ function todayIso() {
69
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
70
+ }
71
+ function daysAgoIso(days) {
72
+ return new Date(Date.now() - days * DAY_MS).toISOString().slice(0, 10);
73
+ }
74
+ function csvOrJson(args) {
75
+ return args.output ?? "json";
76
+ }
77
+ function resolveEffectiveStatus(args) {
78
+ if (args["all-statuses"]) {
79
+ return void 0;
80
+ }
81
+ const explicit = args["effective-status"];
82
+ if (explicit) {
83
+ return explicit;
84
+ }
85
+ return "ACTIVE";
86
+ }
87
+
88
+ export {
89
+ handleMetaError,
90
+ resolveAccountIdArg,
91
+ getDateRange,
92
+ todayIso,
93
+ daysAgoIso,
94
+ csvOrJson,
95
+ resolveEffectiveStatus
96
+ };
97
+ //# sourceMappingURL=chunk-AVJ3B6LC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/meta/shared.ts"],"sourcesContent":["import { ApiError } from \"../../../client.ts\";\nimport { getEnv } from \"../../../env.ts\";\nimport { handleConnectionError } from \"../../../error-handler.ts\";\nimport { writeAdsJson } from \"../output.ts\";\nimport type { AdsErrorEnvelope } from \"../types.ts\";\n\nconst DAY_MS = 86_400_000;\n\nexport function handleMetaError(err: unknown): never {\n if (err instanceof ApiError) {\n if (err.code === \"UNAUTHORIZED\" || err.code === \"NOT_FOUND\") {\n handleConnectionError(\"meta_ads\", err.message);\n }\n const envelope: AdsErrorEnvelope = {\n ok: false,\n error: {\n code: err.code,\n message: err.message,\n fix: { action: \"reject\", explanation: err.message },\n retryable: err.code === \"RATE_LIMITED\" || err.code === \"INTERNAL_ERROR\",\n },\n };\n writeAdsJson(envelope);\n process.exit(1);\n }\n const message = err instanceof Error ? err.message : \"Unexpected error\";\n writeAdsJson({ ok: false, error: { code: \"NETWORK_ERROR\", message } });\n process.exit(1);\n}\n\nconst ACCOUNT_ID_RE = /^(act_)?[0-9]+$/;\n\n/** Pull the default Meta ad account ID from `--account-id` arg or `BAKER_META_AD_ACCOUNT_ID` env. */\nexport function resolveAccountIdArg(args: Record<string, unknown>): string {\n const fromArgs = args[\"account-id\"] as string | undefined;\n const id = fromArgs || getEnv().BAKER_META_AD_ACCOUNT_ID;\n if (!id) {\n writeAdsJson({\n ok: false,\n error: {\n code: \"MISSING_ACCOUNT_ID\",\n message: \"Pass --account-id or set BAKER_META_AD_ACCOUNT_ID. Run `baker ads meta accounts` to find IDs.\",\n },\n });\n process.exit(1);\n }\n if (!ACCOUNT_ID_RE.test(id)) {\n writeAdsJson({\n ok: false,\n error: {\n code: \"INVALID_ACCOUNT_ID\",\n message: `Invalid account ID \"${id}\". Expected numeric ID, optionally prefixed with \"act_\".`,\n },\n });\n process.exit(1);\n }\n return id.startsWith(\"act_\") ? id : `act_${id}`;\n}\n\nexport function getDateRange(args: Record<string, unknown>): { datePreset?: string; since?: string; until?: string } {\n const datePreset = args[\"date-preset\"] as string | undefined;\n const since = args.since as string | undefined;\n const until = args.until as string | undefined;\n if (since && until) return { since, until };\n return { datePreset: datePreset ?? \"last_7d\" };\n}\n\nexport function todayIso(): string {\n return new Date().toISOString().slice(0, 10);\n}\n\nexport function daysAgoIso(days: number): string {\n return new Date(Date.now() - days * DAY_MS).toISOString().slice(0, 10);\n}\n\nexport function csvOrJson(args: Record<string, unknown>): string {\n return (args.output as string | undefined) ?? \"json\";\n}\n\n/**\n * Default to ACTIVE-only on listings — that's almost always what an AI agent or\n * a human glance wants. Pass `--effective-status ACTIVE,PAUSED` to override, or\n * `--all-statuses` to drop the filter entirely.\n */\nexport function resolveEffectiveStatus(args: Record<string, unknown>): string | undefined {\n if (args[\"all-statuses\"]) {\n return undefined;\n }\n const explicit = args[\"effective-status\"] as string | undefined;\n if (explicit) {\n return explicit;\n }\n return \"ACTIVE\";\n}\n"],"mappings":";;;;;;;;;;;;AAMA,IAAM,SAAS;AAER,SAAS,gBAAgB,KAAqB;AACnD,MAAI,eAAe,UAAU;AAC3B,QAAI,IAAI,SAAS,kBAAkB,IAAI,SAAS,aAAa;AAC3D,4BAAsB,YAAY,IAAI,OAAO;AAAA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