@metabase/cli 0.1.8 → 0.1.9

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 (207) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +26 -236
  3. package/dist/{add-collection-CwrbKmC1.mjs → add-collection-CoP-6FZR.mjs} +5 -5
  4. package/dist/add-collection-EPp89tcs.mjs +10 -0
  5. package/dist/{archive-DqUtqRut.mjs → archive-BY8nrgnq.mjs} +5 -6
  6. package/dist/{archive-BzvqQd34.mjs → archive-BeslLaal.mjs} +5 -6
  7. package/dist/{archive-BpKZsGAm.mjs → archive-Blt0TxxA.mjs} +6 -7
  8. package/dist/{archive-ZnnJc2iT.mjs → archive-BxwGVDpd.mjs} +6 -7
  9. package/dist/{archive-BAjGIzhn.mjs → archive-C17qIvFW.mjs} +6 -7
  10. package/dist/{archive-BO3DOWI4.mjs → archive-CPLXsrzD.mjs} +5 -6
  11. package/dist/auth-CCUDM9Sv.mjs +19 -0
  12. package/dist/{body-DDYKoyMt.mjs → body-2jl-YSxT.mjs} +2 -2
  13. package/dist/{branches-DjiGsjAz.mjs → branches-Vlu44J51.mjs} +5 -6
  14. package/dist/{cancel-BwtDQ2MR.mjs → cancel-D0aBPUhs.mjs} +4 -5
  15. package/dist/{cancel-task-uJp18RvR.mjs → cancel-task-DoL2bqs1.mjs} +5 -6
  16. package/dist/{render-0_GsapXa.mjs → capabilities-7L9GVMd_.mjs} +45 -4
  17. package/dist/{card-ezYiriML.mjs → card-DnIeMmUn.mjs} +18 -2
  18. package/dist/card-UwczcLjq.mjs +20 -0
  19. package/dist/{cards-z68PANDD.mjs → cards-6MTreYAo.mjs} +5 -6
  20. package/dist/cli.mjs +23 -34
  21. package/dist/{collection-Bcy8cWYH.mjs → collection-BPTlcFw5.mjs} +8 -2
  22. package/dist/collection-Cexywhlj.mjs +20 -0
  23. package/dist/collection-namespace-BdqQJb7j.mjs +12 -0
  24. package/dist/{create-4EAGYVyp.mjs → create-BWD8H6yw.mjs} +12 -10
  25. package/dist/{create-GVfCQU3B.mjs → create-BZRA7nPu.mjs} +7 -8
  26. package/dist/{create-7JOWFxqu.mjs → create-BsOdn1Q1.mjs} +10 -11
  27. package/dist/{create-CQ4Vg4Ge.mjs → create-C_Z3IDrW.mjs} +9 -10
  28. package/dist/{create-Dd_Gyg_F.mjs → create-DNYFXAsy.mjs} +7 -8
  29. package/dist/{create-BzK59YlR.mjs → create-DcoF52Kx.mjs} +11 -12
  30. package/dist/{create-branch-CdWGiREu.mjs → create-branch-40Xm4DN7.mjs} +5 -6
  31. package/dist/create-dVmIemXi.mjs +52 -0
  32. package/dist/{create-DHWfmO2L.mjs → create-k59K2qf1.mjs} +9 -10
  33. package/dist/{current-task-nPs-iCLi.mjs → current-task-BN_XEFSX.mjs} +5 -6
  34. package/dist/dashboard-B_CuVbMX.mjs +21 -0
  35. package/dist/{database-BXiue1in.mjs → database-Dsv4QBs0.mjs} +20 -10
  36. package/dist/db-DULi5MOr.mjs +22 -0
  37. package/dist/{delete-Do1agSiL.mjs → delete-DEFgs5LE.mjs} +6 -7
  38. package/dist/{delete-runtime-uuYbd4k2.mjs → delete-runtime-DVb-Pkzp.mjs} +2 -2
  39. package/dist/{delete-CJqLgr6w.mjs → delete-tPjicYO4.mjs} +6 -7
  40. package/dist/{delete-table-ZiJDpMFT.mjs → delete-table-CDj19Qn6.mjs} +6 -7
  41. package/dist/{dirty-BnTG7w7v.mjs → dirty-DGCa6W1F.mjs} +5 -6
  42. package/dist/{eid-CwQ_smOD.mjs → eid-3v5MAKNA.mjs} +6 -7
  43. package/dist/{error-CTVL5CdB.mjs → error-BndUmcwS.mjs} +1 -1
  44. package/dist/{export-DR2cC4rL.mjs → export-BIZ-UR_M.mjs} +7 -8
  45. package/dist/field-CfrrLetM.mjs +18 -0
  46. package/dist/{fields-Ck31lDz9.mjs → fields-9lOrO8UH.mjs} +6 -7
  47. package/dist/{get-BFJ3VBPa.mjs → get-6Cj360cH.mjs} +5 -6
  48. package/dist/{get-CyG_P55z.mjs → get-BIH72g0v.mjs} +6 -7
  49. package/dist/{get-CICzGFSW.mjs → get-BSJN5TwW.mjs} +6 -7
  50. package/dist/{get-DyArILlF.mjs → get-BYSj7tMP.mjs} +5 -6
  51. package/dist/{get-DauAF3sm.mjs → get-Bk81meka.mjs} +5 -6
  52. package/dist/{get-GWRprk7k.mjs → get-BpWjLkKT.mjs} +5 -7
  53. package/dist/{get-F338MOK-.mjs → get-BuM6QPjZ.mjs} +5 -6
  54. package/dist/{get-C71ypFQk.mjs → get-CHaIVT6Y.mjs} +5 -6
  55. package/dist/{get-pO0wiy1e.mjs → get-CRa-h69C.mjs} +5 -6
  56. package/dist/{get-BPOd0Rm8.mjs → get-DFe2WoJ2.mjs} +5 -6
  57. package/dist/{get-DxqzDKKK.mjs → get-DlGlnciR.mjs} +5 -6
  58. package/dist/{get-BNKsNCcx.mjs → get-LI2xsRoT.mjs} +5 -6
  59. package/dist/{get-run-DhM_PyVy.mjs → get-run-hCZaw8-h.mjs} +5 -6
  60. package/dist/{get-BZiu-u-9.mjs → get-w-WqpjKy.mjs} +7 -8
  61. package/dist/git-sync-BpRstrZo.mjs +28 -0
  62. package/dist/{has-remote-changes-Ca0exJmb.mjs → has-remote-changes-DcpW1_KX.mjs} +5 -6
  63. package/dist/{import-DjclIzGP.mjs → import-CTQT1atq.mjs} +7 -8
  64. package/dist/{is-dirty-Cke0a1ie.mjs → is-dirty-DGrmt1ss.mjs} +4 -4
  65. package/dist/is-dirty-DuWCgrz2.mjs +9 -0
  66. package/dist/{items-BSpapmCU.mjs → items-Kr0oN2V7.mjs} +7 -8
  67. package/dist/{list-CEE9yKNp.mjs → list-Bz2ej0Cl.mjs} +4 -5
  68. package/dist/{list-V5IuMr_5.mjs → list-CCtYVgPN.mjs} +4 -5
  69. package/dist/{list-Brt4oKO7.mjs → list-CLvlEVQo.mjs} +6 -7
  70. package/dist/{list-Br77Mw6U.mjs → list-Ccj8-vb5.mjs} +5 -6
  71. package/dist/{list-Fjjtpghb.mjs → list-Cj3v4Lgv.mjs} +6 -7
  72. package/dist/{list-bVlCwg8g.mjs → list-Cl_O4_U4.mjs} +4 -5
  73. package/dist/{list-BRXGDSMo.mjs → list-D2D5Mw1E.mjs} +5 -6
  74. package/dist/{list-DUyWON1F.mjs → list-DNmekF2B.mjs} +4 -5
  75. package/dist/{list-fIV-P6wP.mjs → list-DaESiI72.mjs} +4 -5
  76. package/dist/{list-DWWGcUTg.mjs → list-DzKKdfCI.mjs} +5 -7
  77. package/dist/{list-BI1PfPjn.mjs → list-jcgK0thu.mjs} +5 -6
  78. package/dist/{list-D1qhCQn0.mjs → list-tklIxo38.mjs} +6 -7
  79. package/dist/{list-DmO4ADQq.mjs → list-zRQsvrH6.mjs} +4 -5
  80. package/dist/{login-BJGhZLgZ.mjs → login-BMKBmgeQ.mjs} +9 -10
  81. package/dist/{logout-BAGLqtnV.mjs → logout-C5pod937.mjs} +4 -5
  82. package/dist/{manifest-BNh0Lw6p.mjs → manifest-Cmu--CG5.mjs} +1 -2
  83. package/dist/measure-BkwFsP44.mjs +19 -0
  84. package/dist/{metadata-B-GOcWqL.mjs → metadata-CG4VZ5NW.mjs} +6 -7
  85. package/dist/{metadata-DJAdsOoh.mjs → metadata-DIEbyQeS.mjs} +7 -8
  86. package/dist/{parse-id-D1LTTt9L.mjs → parse-id-Boqc4wn4.mjs} +1 -1
  87. package/dist/{path-D5kX-msX.mjs → path-ur3NsMFr.mjs} +4 -6
  88. package/dist/{poll-DxpnK1wW.mjs → poll-BMjCkDaj.mjs} +1 -1
  89. package/dist/{poll-task-D8mG49IN.mjs → poll-task-CiRA0ER9.mjs} +2 -2
  90. package/dist/{preflight-Df_FqJ6o.mjs → preflight-CSqcIlbX.mjs} +3 -3
  91. package/dist/{query-zWFRDH3T.mjs → query-B8JzsQ_I.mjs} +7 -8
  92. package/dist/{query-OIuumiXN.mjs → query-CG0rEMS-.mjs} +11 -12
  93. package/dist/{query-result-ABPLz6I4.mjs → query-result-B4kTRid7.mjs} +1 -1
  94. package/dist/{remove-collection-BxmiXWKz.mjs → remove-collection-Clwz3EHQ.mjs} +7 -8
  95. package/dist/{rescan-values-M7g81KIl.mjs → rescan-values-DuHBnFjK.mjs} +8 -11
  96. package/dist/run-JXRivkfH.mjs +136 -0
  97. package/dist/{runs-CqfJIuh_.mjs → runs-FxgbXvax.mjs} +6 -7
  98. package/dist/{runtime-B40L_bj8.mjs → runtime-Ck8KKQe-.mjs} +11 -78
  99. package/dist/{schema-tables-CjBRF0_0.mjs → schema-tables-izDPI4f5.mjs} +6 -7
  100. package/dist/{schemas-GIIbek2O.mjs → schemas-CyzplnXl.mjs} +4 -5
  101. package/dist/{search-h78uOYec.mjs → search-BeuoOEQV.mjs} +4 -5
  102. package/dist/segment-ChYmSM0p.mjs +19 -0
  103. package/dist/{set-BRDxcLcQ.mjs → set-ClzB_5Jk.mjs} +7 -8
  104. package/dist/{setting-mKzZJpQY.mjs → setting-CBJVEx7_.mjs} +3 -3
  105. package/dist/{setup-WTIT2WbM.mjs → setup-vKXEUMM7.mjs} +6 -7
  106. package/dist/skills-1Z5Wj7Kp.mjs +18 -0
  107. package/dist/{skills-BkregMyb.mjs → skills-BDPVoBWU.mjs} +33 -2
  108. package/dist/snippet-De70ayL1.mjs +19 -0
  109. package/dist/{stash-DxoAJzcK.mjs → stash-DLtVf4_D.mjs} +7 -8
  110. package/dist/{status-B1dc3bbQ.mjs → status-AnPzI1f7.mjs} +4 -5
  111. package/dist/{status-D0Ukfodl.mjs → status-DHFYn9kO.mjs} +6 -7
  112. package/dist/{summary-3qOMUcEX.mjs → summary-DDed1LOz.mjs} +5 -6
  113. package/dist/sync-schema-BGQVq2JA.mjs +55 -0
  114. package/dist/table-C_bP2ao-.mjs +19 -0
  115. package/dist/{table-qDD2kApF.mjs → table-CkWja2UH.mjs} +1 -1
  116. package/dist/transform-B4RZfm6A.mjs +24 -0
  117. package/dist/{transform-BKahefz_.mjs → transform-DyWCoiO-.mjs} +1 -0
  118. package/dist/transform-job-C4pZcrIF.mjs +19 -0
  119. package/dist/{tree-DsnIPFyE.mjs → tree-BlYgJOn9.mjs} +4 -5
  120. package/dist/{update-Baya6OkO.mjs → update-B0z-2zqC.mjs} +12 -13
  121. package/dist/{update-BEtl9LpG.mjs → update-BHtliIr_.mjs} +8 -9
  122. package/dist/{update-CLsqoEJ8.mjs → update-CdfAogO2.mjs} +8 -9
  123. package/dist/{update-DPouQi4U.mjs → update-CgOPxKXK.mjs} +13 -11
  124. package/dist/{update-UaPqSfPN.mjs → update-CilTW98H.mjs} +10 -11
  125. package/dist/{update-DWn-nLPo.mjs → update-CoVvsU-I.mjs} +8 -9
  126. package/dist/{update-CZEd_Eej.mjs → update-DBN7yfAk.mjs} +9 -10
  127. package/dist/{update-BRLcnSwK.mjs → update-DqSG5_Ie.mjs} +10 -11
  128. package/dist/{update-BsgHRoZ8.mjs → update-DykqQLfo.mjs} +11 -12
  129. package/dist/{update-dashcard-DK9X91ha.mjs → update-dashcard-DZ8oV8up.mjs} +8 -9
  130. package/dist/{upgrade-UqdvTikR.mjs → upgrade-B8sEEQdQ.mjs} +34 -7
  131. package/dist/{uuid-BWCaWG4O.mjs → uuid-lLVnEoBN.mjs} +3 -4
  132. package/dist/{validate-dPEOnOf8.mjs → validate-B62TRDGV.mjs} +1 -1
  133. package/dist/{validate-query-CYvOP8Ld.mjs → validate-query-BpiN1CFu.mjs} +2 -2
  134. package/dist/{values-D_wycrcr.mjs → values-oD72EtRq.mjs} +5 -6
  135. package/dist/{verify-D7hb6VMy.mjs → verify-Bg6F0oFN.mjs} +1 -1
  136. package/dist/{wait-B5IpNFCG.mjs → wait-BtzuqQC3.mjs} +6 -7
  137. package/dist/{wait-flags-CNIeSq0_.mjs → wait-flags-DyFfZeav.mjs} +2 -2
  138. package/package.json +1 -1
  139. package/skill-data/core/SKILL.md +19 -32
  140. package/skill-data/git-sync/SKILL.md +8 -63
  141. package/skill-data/mbql/SKILL.md +95 -28
  142. package/skill-data/mbql/references/operators.md +13 -13
  143. package/skill-data/transform/SKILL.md +18 -7
  144. package/skills/metabase-cli/SKILL.md +1 -1
  145. package/dist/add-collection-DxtuNxeP.mjs +0 -11
  146. package/dist/auth-B9B4pUaH.mjs +0 -19
  147. package/dist/capabilities-7e9MgquN.mjs +0 -29
  148. package/dist/card-D54unw6r.mjs +0 -20
  149. package/dist/collection-B5kIKRTL.mjs +0 -20
  150. package/dist/create-6XE7GYxk.mjs +0 -45
  151. package/dist/create-C8gA-XP2.mjs +0 -54
  152. package/dist/credentials-CFA9iGZG.mjs +0 -88
  153. package/dist/dashboard-lw6IFfOs.mjs +0 -21
  154. package/dist/database-BPT6BrmF.mjs +0 -17
  155. package/dist/db-CBCj8sBg.mjs +0 -22
  156. package/dist/delete-CiV6f69N.mjs +0 -104
  157. package/dist/deprovision-C-qEnh-P.mjs +0 -67
  158. package/dist/docker-B-QQWThD.mjs +0 -515
  159. package/dist/field-DJmQ2pul.mjs +0 -18
  160. package/dist/git-sync-rmjYOGFK.mjs +0 -28
  161. package/dist/is-dirty-DFGgGLDi.mjs +0 -10
  162. package/dist/license-j0tDQLKI.mjs +0 -17
  163. package/dist/list-evetBTcH.mjs +0 -36
  164. package/dist/logs-jx5b_YDk.mjs +0 -60
  165. package/dist/measure-BfgxqewH.mjs +0 -19
  166. package/dist/parse-schemas-DDK9nXuh.mjs +0 -12
  167. package/dist/process-CM7Uu5q_.mjs +0 -105
  168. package/dist/provision-BJd6zO1D.mjs +0 -83
  169. package/dist/ps-CpyHEvv7.mjs +0 -11
  170. package/dist/ps-dEqRGeB3.mjs +0 -80
  171. package/dist/remove-BNQ1c6hB.mjs +0 -64
  172. package/dist/run-DTsx8bLb.mjs +0 -96
  173. package/dist/segment-CoElN2b-.mjs +0 -19
  174. package/dist/set-Dclba9xF.mjs +0 -68
  175. package/dist/skills-tMYd5d9v.mjs +0 -18
  176. package/dist/snippet-B84H3tfp.mjs +0 -19
  177. package/dist/start-B7ByBicB.mjs +0 -414
  178. package/dist/status-DAzD1Cn_.mjs +0 -34
  179. package/dist/stop-Cvexagxh.mjs +0 -87
  180. package/dist/sync-schema-CrmVX1cy.mjs +0 -44
  181. package/dist/table-B0fRQv91.mjs +0 -19
  182. package/dist/transform-K_kp6Rdm.mjs +0 -24
  183. package/dist/transform-job-CuNN8zgv.mjs +0 -19
  184. package/dist/update-hiJdbbsb.mjs +0 -78
  185. package/dist/url-LMJZRDv4.mjs +0 -56
  186. package/dist/wait-DHjXk3jD.mjs +0 -19
  187. package/dist/workspace-Bt8n3ojY.mjs +0 -25
  188. package/dist/workspace-D8HtUN0y.mjs +0 -72
  189. package/dist/workspace-credentials-8CBMQJFz.mjs +0 -100
  190. package/dist/yaml-Gv6wRFMF.mjs +0 -43
  191. package/skill-data/workspace/SKILL.md +0 -390
  192. /package/dist/{body-flags-D7q87Btw.mjs → body-flags-D78h_-Ua.mjs} +0 -0
  193. /package/dist/{dashboard-B4bn3z6t.mjs → dashboard-FY5UzJ_Z.mjs} +0 -0
  194. /package/dist/{field-E0IBy4Uw.mjs → field-MGxpNQUH.mjs} +0 -0
  195. /package/dist/{input-cMSEqISy.mjs → input-xewHccej.mjs} +0 -0
  196. /package/dist/{key-vkNkH82H.mjs → key-C2XG394c.mjs} +0 -0
  197. /package/dist/{measure-Bt3InQsA.mjs → measure-ClESGxIb.mjs} +0 -0
  198. /package/dist/{paginate-BexjkjbY.mjs → paginate-Dfm9eO9A.mjs} +0 -0
  199. /package/dist/{parse-enum-CrEWOhuY.mjs → parse-enum-Dr7ACrTR.mjs} +0 -0
  200. /package/dist/{parse-ref-DKag6a6I.mjs → parse-ref-BiETXmvm.mjs} +0 -0
  201. /package/dist/{prompt-CFKoys7k.mjs → prompt-u4WhE4T5.mjs} +0 -0
  202. /package/dist/{render-khznBlla.mjs → render-BQHJhSP1.mjs} +0 -0
  203. /package/dist/{revision-message-flag-DY29-cgz.mjs → revision-message-flag-WmsIzUOM.mjs} +0 -0
  204. /package/dist/{segment-DhBmcr_E.mjs → segment-Be2v4ilr.mjs} +0 -0
  205. /package/dist/{setting-BzCng1Ub.mjs → setting-oL97SNeO.mjs} +0 -0
  206. /package/dist/{snippet-bi_0XbNT.mjs → snippet-xh42tYly.mjs} +0 -0
  207. /package/dist/{transform-job-DjhoJbiV.mjs → transform-job-DpDGoqQt.mjs} +0 -0
@@ -1,28 +1,26 @@
1
1
  ---
2
2
  name: core
3
- description: Drive a Metabase instance from the terminal via the `mb` CLI — auth, databases, cards, dashboards, collections, transforms, queries, search, git-sync, Enterprise workspaces. Use for any `mb <verb>` task.
3
+ description: Drive a Metabase instance from the terminal via the `mb` CLI — auth, databases, cards, dashboards, collections, transforms, queries, search, git-sync. Use for any `mb <verb>` task.
4
4
  allowed-tools: Read, Write, Edit, Bash, AskUserQuestion
5
5
  ---
6
6
 
7
7
  # metabase-cli (core)
8
8
 
9
- The official Metabase CLI (`mb`) drives a Metabase instance over its REST API. It covers auth, list/get/create/update/delete on every resource, query and transform execution, content search, git-sync (representations ↔ instance), Enterprise workspaces, and entity-id translation.
9
+ The official Metabase CLI (`mb`) drives a Metabase instance over its REST API. It covers auth, list/get/create/update/delete on every resource, query and transform execution, content search, git-sync (representations ↔ instance), and entity-id translation.
10
10
 
11
11
  Top-level command groups (run `mb <group> --help` to discover verbs):
12
12
 
13
13
  ```
14
14
  auth | db | table | field | query | card | dashboard | snippet | segment | measure | collection
15
- transform | transform-job | setting | search | git-sync | workspace | setup | eid | uuid | upgrade | skills
15
+ transform | transform-job | setting | search | git-sync | setup | eid | uuid | upgrade | skills
16
16
  ```
17
17
 
18
- The patterns below — auth, flag conventions, output flags, body input — apply across **every** group. Per-command flags, examples, and output schemas live in `mb __manifest` (see below). A few flows have their own specialized skills; load them on demand (see "Specialized skills"). Authoring any query body (cards, transforms, measures, segments, ad-hoc `mb query`) is one — load `mbql` whenever you build MBQL by hand.
18
+ The patterns below — auth, flag conventions, output flags, body input — apply across **every** group. Per-command flags, examples, and output schemas live in `mb __manifest` (see below). A few flows have their own specialized skills; load them on demand (see "Specialized skills"). Authoring any query body (cards, transforms, measures, segments, ad-hoc `mb query`) is one — load `mbql` whenever you build MBQL by hand. When a **question** (card) needs a query, prefer MBQL over native SQL — it's portable across warehouse engines and the CLI pre-flight-validates it. Try it first, but don't force it: fall back to native SQL when MBQL can't express the query, or when an MBQL body keeps failing server-side and you can't resolve it.
19
19
 
20
20
  ## Auth & profiles
21
21
 
22
22
  **The agent does not log in for the user.** Authentication is the human's job — they pick the base URL, paste credentials, and store them as a named profile. The agent's role is to _check_ what profiles exist, _ask_ which to use, and pass `--profile <name>` through every command.
23
23
 
24
- **The one exception** is a freshly bootstrapped workspace child: its API key is minted by the parent the human already authorized, so the agent reads it via `mb workspace credentials <ws-id>` and saves it with `auth login` — piping the key on **stdin** (`printf '%s' "$KEY" | mb auth login …`), never on an `--api-key` flag (the CLI rejects the flag form). See the `workspace` skill, step 4.
25
-
26
24
  ### Discover what's already configured
27
25
 
28
26
  ```bash
@@ -35,17 +33,7 @@ mb auth status --profile <name> --json # → status of a specific profile
35
33
 
36
34
  ### Pick the profile to use
37
35
 
38
- If exactly one profile is configured and the user's intent doesn't disambiguate, use it. If multiple profiles exist and the user hasn't named one, ask via `AskUserQuestion`, presenting the names from `auth list`. Once a name is established, pass `--profile <name>` to **every** subsequent command. Profile names are arbitrary local labels — `prod`, `staging`, the workspace name — let the user pick.
39
-
40
- ### Other secrets (license, warehouse passwords)
41
-
42
- Same rule: the human runs the storing command. To check whether a license is present:
43
-
44
- ```bash
45
- mb workspace license status --json # → {present: bool}
46
- ```
47
-
48
- If `present: false`, ask the user to run `echo "<your-token>" | mb workspace license set` from their terminal — don't paste the token in chat.
36
+ If exactly one profile is configured and the user's intent doesn't disambiguate, use it. If multiple profiles exist and the user hasn't named one, ask via `AskUserQuestion`, presenting the names from `auth list`. Once a name is established, pass `--profile <name>` to **every** subsequent command. Profile names are arbitrary local labels — `prod`, `staging` — let the user pick.
49
37
 
50
38
  ## Flag conventions
51
39
 
@@ -56,21 +44,21 @@ If `present: false`, ask the user to run `echo "<your-token>" | mb workspace lic
56
44
  ❌ mb --profile prod table list # → error: "Unknown command prod"
57
45
  ```
58
46
 
59
- `--profile` attaches **after** the full verb chain (`table list`, `card get`, `workspace start`).
47
+ `--profile` attaches **after** the full verb chain (`table list`, `card get`, `git-sync export`).
60
48
 
61
49
  ### `--wait` for async operations
62
50
 
63
- `workspace start`, `workspace database provision`, `transform run`, and similar async verbs return immediately by default. Pass `--wait` for any interactive flow where the next step depends on completion. Without it you'll race the operation and see "not ready" / `state: starting` / transient connection refusals.
51
+ `transform run`, `git-sync import`, and similar async verbs return immediately by default. Pass `--wait` for any interactive flow where the next step depends on completion. Without it you'll race the operation and see "not ready" / transient connection refusals.
64
52
 
65
53
  ### Some outputs are JSON envelopes, not bare strings
66
54
 
67
- A handful of "lookup" verbs return a JSON object even when you only want a single field. `mb workspace url <id>` returns `{"workspace_id": ..., "url": "http://..."}`, not `"http://..."`. Don't drop them raw into another flag — extract:
55
+ A handful of "lookup" verbs return a JSON object even when you only want a single field. `mb setting get <key>` returns `{"key": "...", "value": ...}`, not the bare value. Don't drop them raw into another flag — extract:
68
56
 
69
57
  ```bash
70
- WS_URL=$(mb workspace url <id> --json | jq -r '.url')
58
+ VALUE=$(mb setting get <key> --json | jq -r '.value')
71
59
  ```
72
60
 
73
- If you find yourself writing `--url $(mb ...)` and the receiving command rejects it with "URL must start with http://", this is what happened.
61
+ If you find yourself piping a `--json` envelope straight into another flag and the receiving command rejects it, this is what happened.
74
62
 
75
63
  ## Output
76
64
 
@@ -78,7 +66,7 @@ Every list/get verb supports the same output flags:
78
66
 
79
67
  - `--json` — emit the full JSON envelope, safe for `jq`. Default is human-readable text.
80
68
  - `--full` — include every field (compact projection is the default for list/get).
81
- - `--fields a,b.c.d` — project specific dot-paths. Mutually exclusive with `--full`.
69
+ - `--fields a,b.c.d` — project specific dot-paths. Mutually exclusive with `--full`. **Paths are relative to each `data[]` item on list verbs, and to the root on single-item verbs.** So it's `--fields id,name` on `… list` / `database schema-tables` (the projection runs per row) — `data.id` and `data[].id` both fail with `unknown field path: "data.id"`. On single-object verbs the path is root-relative: `--fields id,name,display` on `card get`, and `--fields data.rows` on `mb query` (whose `data` is an object, not an array).
82
70
  - `--max-bytes <n>` — cap **list** output size (drops trailing items, sets `truncated`). Default 65 536; `0` disables. Single-item commands (`get`, `metadata`) never truncate — they emit a stderr advisory when over the cap.
83
71
 
84
72
  List envelope shape:
@@ -140,28 +128,27 @@ Use it to (a) enumerate verbs, (b) validate flag names before constructing a com
140
128
 
141
129
  Routine verb shapes (list / get / create / update), every flag, and output JSON Schemas live in `mb __manifest` — pull them on demand. Below is only what the manifest does _not_ tell you: the footguns and non-obvious behaviors.
142
130
 
143
- - **db traversal vs. rollup.** Default to granular: `database list` → `database schemas <db-id>` → `database schema-tables <db-id> <schema>` → `table get <table-id> --include fields`. The rollup endpoints (`database get --include tables.fields`, `database metadata <db-id>`) pull megabytes and blow the context window on any real warehouse — use them only on a small/dev db. `sync-schema` / `rescan-values` queue async work and return `{status:"ok"}` immediately.
131
+ - **db traversal vs. rollup.** Default to granular: `database list` → `database schemas <db-id>` → `database schema-tables <db-id> <schema>` → `table get <table-id> --include fields`. The rollup endpoints (`database get --include tables.fields`, `database metadata <db-id>`) pull megabytes and blow the context window on any real warehouse — use them only on a small/dev db. `sync-schema` / `rescan-values` queue async work and return `{status:"ok"}` immediately; `sync-schema --wait` blocks until `initial_sync_status: complete`.
144
132
  - **table fields.** `table get` never returns fields on its own — pass `--include fields` (compact) or use `table fields <id>` (list envelope). `table metadata <id>` adds FKs + dimensions (heavier). `table update` patches table-level metadata only; physical columns aren't editable here.
145
133
  - **field has no `list`.** Fields are per-table — get them via `table get <id> --include fields`. Never enumerate fields across a whole db (context blow-up). `field summary` is live cardinality `{field_id, count, distincts}`; `field values` is the cached distinct set (`has_more_values: true` ⇒ truncated cache). `field update` patches metadata only; `base_type` isn't editable.
146
134
  - **card.** `dataset_query` is the **flat** `mbql/query` value, not a legacy `{type:"query",query:…}` envelope (→ `mbql` skill). `--export-format csv|xlsx` streams the raw export (pipe to a file), bypassing the JSON envelope. `archive` is the only delete; unarchive with `update --body '{"archived":false}'`. `visualization_settings` keys are scoped by `display` and aren't pre-flighted — see the `viz` skill.
147
- - **dashboard.** Dashcards round-trip through `PUT /api/dashboard/:id` (no per-dashcard endpoint): `update-dashcard <dash-id> <dashcard-id>` patches one safely; `update --body '{"dashcards":[…]}'` replaces the whole set (omitted ids are deleted server-side; use negative ids for new cards). `create`/`update` pre-flight every positive `card_id` against live server state and exit **2** with `{ok:false,errors:[…]}` on a bad ref — non-bypassable (no `--skip-validate`). `dashboard get <id>` (or `--full`) hydrates dashcards/tabs; `list` omits them.
135
+ - **dashboard.** Dashcards round-trip through `PUT /api/dashboard/:id` (no per-dashcard endpoint): `update-dashcard <dash-id> <dashcard-id>` patches one safely; `update --body '{"dashcards":[…]}'` replaces the whole set (omitted ids are deleted server-side; use negative ids for new cards). `create` accepts the **same** `dashcards` array in its initial body, so you can lay out the whole dashboard in one call — negative ids for new cards, and `card_id:null` plus a `visualization_settings.virtual_card` block (`{display:"text"|"heading"|"link"|…}`) for non-question cards. `create`/`update` pre-flight every positive `card_id` against live server state and exit **2** with `{ok:false,errors:[…]}` on a bad ref — non-bypassable (no `--skip-validate`). `dashboard get <id>` (or `--full`) hydrates dashcards/tabs; `list` omits them. **Dashcard geometry: the grid is 24 columns wide.** Each dashcard's `{col, row, size_x, size_y}` is in grid units — `col` (0-indexed, left edge) and `size_x` are columns, `row`/`size_y` are rows; **full-width is `size_x: 24`** (`size_x: 12` is half a row — the usual cause of a card that only fills half the width, since it's a common per-chart default). Keep `col + size_x ≤ 24`, start each card's `col` at 0 for a full-width stack, and don't overlap cards (the server stores whatever you send — it won't auto-fix collisions).
148
136
  - **snippet `--archived` is a swap, not a union** — list returns _either_ active _or_ archived rows, never both. (Same shape for `--filter archived` on dashboard/collection.)
149
137
  - **segment / measure** `update` and `archive` require a non-blank `revision_message` (audit-logged); the CLI does not synthesize it on `update`. `archive` defaults to `"Archived via mb CLI"` — override with `--revision-message`. `definition` is a flat MBQL clause (→ `mbql` skill): segment = a filter, measure = exactly one aggregation.
150
138
  - **collection `<ref>`** accepts four forms only — positive int, `root`, `trash`, or a 21-char entity_id — anything else is a client-side `ConfigError`. `collection items` auto-paginates (cap with `--limit`, which then omits `total`). `collection tree` is **JSON-only** — `--format text` is rejected.
151
139
  - **setting set** parses the value as **strict JSON**: a string is `'"value"'` (inner quotes), booleans `true`/`false`, numbers bare. Wrong quoting silently errors — confirm with `setting get <key>` after. `setting get --json` works on every value type (it wraps bare-text responses into `{key, value}`).
152
140
  - **search vs. list.** For plain enumeration of cards/dashboards/collections use the dedicated `… list` verbs; reach for `search --models <kind>` only for ranking against a query string or a cross-resource lookup.
153
- - **transform.** Iterate with `transform update <id>`, never `delete` + `create` — keeps the row, `entity_id`, materialized table, and YAML filename (avoids `_2` suffixes and noisy git history). `transform run` needs `--wait` or you get only `{run_id, final:null}`. (→ `transform` skill.)
141
+ - **transform.** Iterate with `transform update <id>`, never `delete` + `create` — keeps the row, `entity_id`, materialized table, and YAML filename (avoids `_2` suffixes and noisy git history). `transform run` needs `--wait` (or `--sync`, which also waits for the run's output table to register and returns `target_table_id`) or you get only `{run_id, final:null}`. (→ `transform` skill.)
154
142
  - **setup is one-shot.** `mb setup` walks `/api/setup` for a **fresh** instance only — it errors against an already-configured one. Mostly for bootstrapping local / e2e instances.
155
- - **eid** translates a string entity id → numeric id: `mb eid --model <model> <eid1,eid2> --json` (EIDs are a positional used with `--model`; or pass `--body '{"entity_ids":{"card":["…"]}}'`). Useful when an external system hands you an entity id and a verb needs the numeric one.
143
+ - **eid** translates a string entity id → numeric id: `mb eid --model <model> <eid1,eid2> --json` (EIDs are a positional used with `--model`; or pass `--body '{"entity_ids":{"card":["…"]}}'`). Entity ids are NanoIDs that can start with `-`, which the positional form misreads as a flag (shell quotes don't help — the `-` survives into argv). For an id that may start with `-`, use `--body` — the id is a JSON string value, immune to flag parsing: `mb eid --body '{"entity_ids":{"card":["-…"]}}'`. Useful when an external system hands you an entity id and a verb needs the numeric one.
156
144
  - **query / uuid.** `mb query` is the ad-hoc MBQL surface (`--print-schema` → `--dry-run` → run); `mb uuid --count <n>` mints the `lib/uuid` values every MBQL 5 clause needs. Both workflows live in the `mbql` skill.
157
145
 
158
146
  ## Specialized skills (load on demand)
159
147
 
160
- This core file is enough for any single-command task. Load the relevant skill **proactively** when intent matches — don't wing an MBQL body, the workspace lifecycle, a transform body, or the git-sync workflow from this overview alone. Load each via `mb skills get <name>`.
148
+ This core file is enough for any single-command task. Load the relevant skill **proactively** when intent matches — don't wing an MBQL body, a transform body, or the git-sync workflow from this overview alone. Load each via `mb skills get <name>`.
161
149
 
162
150
  - **`mbql`** — authoring or fixing any MBQL query body: `mb query`, a card `dataset_query`, a transform `source.query`, a measure/segment `definition`, "aggregate and group by", reading `--dry-run` errors. The query-body reference.
163
151
  - **`viz`** — choosing a card's `display` and authoring `visualization_settings`: "make it a bar chart", "set the pie dimension/metric", "format this column as currency", "the card renders as a table instead of a chart". The presentation counterpart to `mbql`.
164
- - **`workspace`** — "spin up a workspace", "provision", "start a local Metabase against my prod", anything `mb workspace …`. **Mandatory** before `workspace start` — ask the user about Remote Sync up front (the bind mount is create-time only).
165
152
  - **`transform`** — "create a transform", "run a transform", authoring transform body JSON, run inspection.
166
153
  - **`git-sync`** — "import the latest changes", "export to git", "git sync", "dirty check", "stash before pulling".
167
154
 
@@ -169,9 +156,9 @@ If a task spans more than one, load each. Specialized skills assume the conventi
169
156
 
170
157
  ## Don't
171
158
 
172
- - **Don't run `mb auth login` for the user** — authentication is theirs (see §Auth). The only exception is saving a workspace child's credentials, and even there pipe the key on stdin.
173
- - Don't paste credentials, license tokens, or warehouse passwords in chat. Have the user run the storing command.
159
+ - **Don't run `mb auth login` for the user** — authentication is theirs (see §Auth).
160
+ - Don't paste credentials or warehouse passwords in chat. Have the user run the storing command.
174
161
  - Don't put `--profile` before the verb chain — the CLI parses it as a subcommand and errors out.
175
- - Don't omit `--wait` on `workspace start` / `transform run` / `workspace database provision` for interactive flows; the next step will race the operation.
162
+ - Don't omit `--wait` on `transform run` / `git-sync import` for interactive flows; the next step will race the operation.
176
163
  - Don't drop a JSON-envelope verb's output raw into another flag. Extract with `--json | jq -r '.<field>'`.
177
164
  - Don't add a third-party HTTP library or shell into `curl` against `/api/...` when a `mb <verb>` exists — that bypasses retries, schema validation, and credential redaction.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: git-sync
3
- description: Round-trip Metabase content (cards, dashboards, transforms, snippets, collections) between an instance and a git remote via `mb git-sync …` — status, dirty / has-remote-changes checks, import (with first-fresh-workspace exception), export (with branch guard + working-tree drift), branches, stash, add/remove a collection from sync. Load when the user wants to "import the latest changes", "export to git", "git sync", "dirty check", "stash before pulling", "add a collection to sync", or anything `mb git-sync …`.
3
+ description: Round-trip Metabase content (cards, dashboards, transforms, snippets, collections) between an instance and a git remote via `mb git-sync …` — status, dirty / has-remote-changes checks, import, export (with branch guard), branches, stash, add/remove a collection from sync. Load when the user wants to "import the latest changes", "export to git", "git sync", "dirty check", "stash before pulling", "add a collection to sync", or anything `mb git-sync …`.
4
4
  allowed-tools: Read, Write, Edit, Bash, AskUserQuestion
5
5
  ---
6
6
 
@@ -75,25 +75,6 @@ Workflow:
75
75
  2. `git-sync has-remote-changes` — confirm there's actually something to import.
76
76
  3. `git-sync import --branch <branch>` — runs to terminal status by default.
77
77
 
78
- ### First import on a fresh workspace
79
-
80
- After `workspace start --repo …` brings up a brand-new workspace, the repo content **must be applied** before any other work — without it the instance has none of the repo content and subsequent edits will diverge from what's on disk.
81
-
82
- The container runs a boot-time auto-import on first start, so in most cases the import has already completed by the time `workspace start --wait` returns. Check `git-sync status` first — if `current_task.sync_task_type == "import"` with `status == "successful"` and `.branch` matches the host's branch, you're done; skip the explicit call (it's a wasted round-trip). Only run the explicit `git-sync import` when the auto-import hasn't landed yet.
83
-
84
- When you do need the explicit import, the first one on a fresh instance can report `status: conflict` (typically `conflicts: ["Transforms"]`) even when nothing is dirty — the boot-time auto-import sometimes leaves a stale task record that the first explicit import collides with. Retry the same command once; the second call usually succeeds. If it keeps reporting conflict, `git-sync import --force` is safe in this specific case because the workspace is empty — there's no instance-side work for `--force` to discard. (This is a narrow exception to the usual "confirm with the user before `--force`" rule.)
85
-
86
- ```bash
87
- HOST_BRANCH=$(git -C <repo-path> symbolic-ref --short HEAD)
88
- SYNC_STATUS=$(mb git-sync status --profile <ws-name> --json)
89
- if ! echo "$SYNC_STATUS" | jq -e --arg b "$HOST_BRANCH" \
90
- '.current_task.sync_task_type == "import" and .current_task.status == "successful" and (.branch == $b)' >/dev/null; then
91
- mb git-sync import --branch "$HOST_BRANCH" --profile <ws-name> --json \
92
- || mb git-sync import --branch "$HOST_BRANCH" --profile <ws-name> --json \
93
- || mb git-sync import --branch "$HOST_BRANCH" --force --profile <ws-name> --json
94
- fi
95
- ```
96
-
97
78
  ## Export (instance → remote)
98
79
 
99
80
  ```bash
@@ -111,61 +92,26 @@ Pushes Metabase-side changes back to the configured remote. `-m` is the commit m
111
92
 
112
93
  Workflow:
113
94
 
114
- 1. **Branch guard** (below) — confirm the workspace isn't tracking `main`/`master`, or that the user has explicitly accepted exporting to it.
95
+ 1. **Branch guard** (below) — confirm the instance isn't tracking `main`/`master`, or that the user has explicitly accepted exporting to it.
115
96
  2. `git-sync is-dirty` — confirm there's something to export.
116
97
  3. `git-sync export -m "..."` — pushes and polls.
117
98
  4. (Optional) `git-sync status` — verify `dirty: false` after.
118
- 5. **Working-tree drift** (below) — if this is a `--repo` bind-mount workspace, the host repo's working tree + index will lag behind the new HEAD. Surface this and offer to realign.
119
99
 
120
100
  ### Branch guard: don't export to main/master without confirmation
121
101
 
122
- Workspace work is conventionally done on a feature branch — exporting to `main` (or `master`) commits team-shared content directly. Before `git-sync export`, check the tracked branch and if it's `main`/`master`, ask the user whether to switch first.
123
-
124
- Reading the current branch:
102
+ Sync work is conventionally done on a feature branch — exporting to `main` (or `master`) commits team-shared content directly. Before `git-sync export`, check the tracked branch and if it's `main`/`master`, ask the user whether to switch first.
125
103
 
126
- - For a `--repo` bind-mount workspace, `git -C <repo-path> symbolic-ref --short HEAD` is the most reliable read — that's what the workspace's `remote-sync-branch` was bound to at start time.
127
- - Otherwise: `mb git-sync status --profile <n> --json | jq -r '.branch'`.
104
+ Read the current branch with `mb git-sync status --profile <n> --json | jq -r '.branch'`.
128
105
 
129
106
  If the branch is `main` or `master`, prompt with `AskUserQuestion`:
130
107
 
131
- > "The workspace is tracking `<branch>` — exporting commits straight to it. Switch to a feature branch first?"
108
+ > "The instance is tracking `<branch>` — exporting commits straight to it. Switch to a feature branch first?"
132
109
  >
133
- > 1. **Create a feature branch via the workspace** — agent suggests a name (e.g., `agent/<task>`); run `mb git-sync create-branch <name> --profile <n>`. This exports current dirty state to the new branch and switches the workspace's tracked branch to it; subsequent `git-sync export` calls go to that branch.
134
- > 2. **Switch the host's branch first (bind-mount workspaces)** — `git -C <repo> checkout -b <name>` on the host, then pass `--branch <name>` on the next `git-sync export` so the export targets the new branch (the workspace's `remote-sync-branch` setting won't auto-update from a host-side checkout).
135
- > 3. **Proceed on `main`/`master`** — explicitly accepted; surface the resulting commit (`git -C <repo> log --oneline -1`) afterwards so the user can amend or revert.
110
+ > 1. **Create a feature branch** — agent suggests a name (e.g., `agent/<task>`); run `mb git-sync create-branch <name> --profile <n>`. This exports current dirty state to the new branch and switches the instance's tracked branch to it; subsequent `git-sync export` calls go to that branch.
111
+ > 2. **Proceed on `main`/`master`** — explicitly accepted.
136
112
 
137
113
  Skip the prompt only if the user's instructions already specified the branch (e.g., they explicitly said "export to main" or named a feature branch). Don't silently default to whatever `remote-sync-branch` happens to point at.
138
114
 
139
- ### Post-export: working-tree drift on `--repo` bind-mount workspaces
140
-
141
- When the workspace exports against a host bind mount, the in-container serializer writes the new commit object directly into the bind-mounted `.git/` (creating tree/blob objects and advancing the branch ref) but **does not update the host's working tree or index**. After a successful export, the host repo state is:
142
-
143
- - HEAD: the new export commit.
144
- - Index: still matches the _previous_ HEAD (whatever the user had staged before).
145
- - Working tree: still matches the _previous_ HEAD.
146
-
147
- `git status` then shows "Changes to be committed" that look like the export's content reverting back — purely a display artifact, not an actual revert. The container does this on purpose to avoid clobbering work-in-progress on the host. **Realigning is _applying_ the new HEAD's content to your worktree, not discarding work** — the new commit was written by the exporter, not by your local edits, and your tree/index are stale relative to the new HEAD until you realign.
148
-
149
- **Surface this to the user** after an export against a `--repo` workspace — don't leave them staring at a confusing `git status`. Offer to realign.
150
-
151
- **Prefer `git restore` over `git reset --hard`.** When the only "changes" are the drift artifact (no real local edits), `git restore` does the same job and isn't classified as a destructive operation by Claude Code's permission system — `git reset --hard` is, and gets blocked even after a user-confirmation dialog:
152
-
153
- ```bash
154
- git -C <repo> restore --staged --worktree . # non-destructive; aligns index + working tree to HEAD
155
- ```
156
-
157
- This is the right default after a `git-sync export` realignment when the user had nothing else staged. If `git status` shows a mix of drift artifacts and real pending work, fall back to the stash sequence:
158
-
159
- ```bash
160
- git -C <repo> stash --include-untracked
161
- git -C <repo> restore --staged --worktree .
162
- git -C <repo> stash pop
163
- ```
164
-
165
- `git reset --hard HEAD` is the canonical equivalent and still valid — but **confirm with the user** before running it, and expect Claude Code to gate it as destructive even after the dialog. `git restore --staged --worktree .` produces the same end-state with less friction.
166
-
167
- Or pull in the new files selectively with `git -C <repo> checkout HEAD -- <path>`. Quick check that this is what you're seeing: `git -C <repo> diff --cached HEAD~1 --stat` returns empty (the index matches the parent commit, not the new HEAD).
168
-
169
115
  ## Branches
170
116
 
171
117
  ```bash
@@ -191,6 +137,5 @@ Use `wait` after `import --no-wait` / `export --no-wait`. Use `cancel-task` if a
191
137
  - Don't drive `git-sync` against a Metabase instance that doesn't have remote-sync configured — every verb returns an error pointing at the missing `remote-sync-*` settings. To check: `mb setting get remote-sync-url --profile <n> --json`.
192
138
  - Don't author content directly via `card create` / `transform create` and then assume `git-sync export` will commit it cleanly — the instance and repo can drift if you mix direct API writes with sync-tracked changes. If you do, follow direct writes immediately with `git-sync export -m "..."` to keep them in step.
193
139
  - Don't omit `-m` on `export` if the user wants a meaningful commit message — the default server-generated message is generic.
194
- - Don't `git-sync export` to `main`/`master` without explicit user confirmation — workspace work is conventionally on a feature branch. See "Branch guard" above.
195
- - Don't pretend the host's `git status` is clean after `git-sync export` against a `--repo` bind mount — the export advances HEAD but leaves the working tree + index behind. See "Working-tree drift" above.
140
+ - Don't `git-sync export` to `main`/`master` without explicit user confirmation — sync work is conventionally on a feature branch. See "Branch guard" above.
196
141
  - Don't reach for `mb setting set` to mark a collection as remote-synced — that endpoint writes single-key settings, not the bulk `collections` map. Use `mb git-sync add-collection <id>` / `mb git-sync remove-collection <id>` (see "Adding / removing a directory (collection) to sync" above), and remember the toggle cascades to descendants.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: mbql
3
- description: Author Metabase MBQL 5 query bodies for the `mb` CLI — the only hand-authorable query format. Covers the JSON shape (lib/type mbql/query, flat stages, numeric ids), the "options object always second" clause rule, lib/uuid minting, the print-schema → dry-run → run validation loop, where MBQL 5 is consumed (mb query, card dataset_query, transform source.query, measure/segment definition), the flat-vs-legacy-envelope footgun, and naming aggregation output columns. Load whenever building or fixing an MBQL query by hand — "write an MBQL query", "create a card from MBQL", "the dataset_query is wrong", "fix the validation errors", "aggregate and group by", "order by the count", or any `--dry-run` / `mb query` work.
3
+ description: Author Metabase MBQL 5 query bodies for the `mb` CLI — the only hand-authorable query format. Covers the JSON shape (lib/type mbql/query, flat stages, numeric ids), the "options object always second" clause rule, when lib/uuid is needed (it's optional — only to reference a clause), the print-schema → dry-run → run validation loop, where MBQL 5 is consumed (mb query, card dataset_query, transform source.query, measure/segment definition), the flat-vs-legacy-envelope footgun, joins and FK traversal, multi-stage pipelines, and naming aggregation output columns. Load whenever building or fixing an MBQL query by hand — "write an MBQL query", "create a card from MBQL", "the dataset_query is wrong", "fix the validation errors", "aggregate and group by", "order by the count", "join two tables", "month-over-month", or any `--dry-run` / `mb query` work.
4
4
  allowed-tools: Read, Write, Edit, Bash, AskUserQuestion
5
5
  ---
6
6
 
@@ -8,7 +8,7 @@ allowed-tools: Read, Write, Edit, Bash, AskUserQuestion
8
8
 
9
9
  MBQL 5 is the **only query format you can author by hand** with confidence — it has a bundled JSON Schema, so the CLI pre-flight-validates it before sending. Legacy MBQL 4 and native SQL are accepted but **not** schema-validated (see "Other formats" below).
10
10
 
11
- Prefer MBQL over native SQL: MBQL is portable across warehouse engines and the CLI can validate it. Reach for native only when the query needs something MBQL can't express.
11
+ Prefer MBQL over native SQL: it's portable across warehouse engines and the CLI pre-flight-validates it. Try it first, but don't force it — fall back to native SQL when MBQL can't express what you need, or when an MBQL body keeps failing server-side and you can't resolve it.
12
12
 
13
13
  The general flag conventions, body-input precedence, and output flags live in the `core` skill (`mb skills get core`).
14
14
 
@@ -24,8 +24,8 @@ A query is a flat object — `lib/type`, a numeric `database` id, and an ordered
24
24
  {
25
25
  "lib/type": "mbql.stage/mbql",
26
26
  "source-table": 7,
27
- "aggregation": [["count", { "lib/uuid": "<mint via mb uuid>" }]],
28
- "breakout": [["field", { "temporal-unit": "month", "lib/uuid": "<mint>" }, 22]]
27
+ "aggregation": [["count", {}]],
28
+ "breakout": [["field", { "temporal-unit": "month" }, 22]]
29
29
  }
30
30
  ]
31
31
  }
@@ -33,43 +33,42 @@ A query is a flat object — `lib/type`, a numeric `database` id, and an ordered
33
33
 
34
34
  - **Numeric ids only.** `database`, `source-table`, and field ids are integers from `mb database list` / `mb table get <id> --include fields`. (The portable YAML representation under git-sync uses _names_ like `[Sample Database, PUBLIC, ORDERS]`; the CLI's `/api/dataset` form uses numeric ids — don't mix them.)
35
35
  - **First stage** carries `source-table` (a table id) or `source-card` (a saved card). Later stages omit both and read the previous stage's output columns by name.
36
- - `source-card` references a saved card by entity id; downstream fields are referenced by column name (string), not a field id.
36
+ - `source-card` references a saved card by its **numeric id** (from `mb card list`), not its string entity id; downstream fields are referenced by column name (string), not a field id.
37
37
 
38
38
  ## The one rule that trips everyone: options object is **second**
39
39
 
40
40
  Every clause is `[op, {options}, ...args]`. The options object is element **1**, args follow.
41
41
 
42
42
  ```json
43
- ["field", { "base-type": "type/Text", "lib/uuid": "<mint>" }, 1779] // field id is THIRD
44
- ["count", { "lib/uuid": "<mint>" }] // no args
45
- ["sum", { "lib/uuid": "<mint>" }, ["field", { "lib/uuid": "<mint>" }, 42]]
46
- ["=", { "lib/uuid": "<mint>" }, ["field", { "lib/uuid": "<mint>" }, 1779], "delivered"]
47
- ["asc", { "lib/uuid": "<mint>" }, ["field", { "lib/uuid": "<mint>" }, 42]]
43
+ ["field", { "base-type": "type/Text" }, 1779] // field id is THIRD; options may be empty {}
44
+ ["count", {}] // no args
45
+ ["sum", {}, ["field", {}, 42]]
46
+ ["=", {}, ["field", {}, 1779], "delivered"]
47
+ ["asc", {}, ["field", {}, 42]]
48
48
  ```
49
49
 
50
50
  The legacy MBQL 4 field shape `["field", id, opts]` (id second) is **rejected** here. A slot-1 violation surfaces from `--dry-run` as `must be the field options object` / `must be the clause options object` at `/stages/0/<verb>/<n>/1`.
51
51
 
52
52
  The same `[op, {options}, …]` rule holds for `aggregation`, `breakout` (a list of field refs), `filters` (implicitly ANDed; nest an explicit `["or", {}, …]` for OR), `order-by`, `expressions`, and join `conditions`.
53
53
 
54
- ## UUIDs: mint them, never invent them
54
+ ## UUIDs: optional — mint only to reference a clause
55
55
 
56
- Every clause options object carries a `lib/uuid` (UUID v4). The schema enforces RFC 4122 strictly, so placeholders (`"a1"`, `"uuid-1"`, `"agg-uuid-001"`) fail pre-flight with `must be a UUID v4 (RFC 4122) — run \`mb uuid\` …`. The same applies to native template-tag ids and any other `format: "uuid"` slot.
56
+ `lib/uuid` is **optional — leave it out whenever you can.** Omit it and the server generates a unique one for every clause as the query comes in; an empty options object `{}` is the normal, preferred case. Don't add a UUID per clause: it's needless work, and the more UUIDs you hand-manage the easier it is to trip the server's "all `lib/uuid`s must be unique" check — a duplicated UUID passes pre-flight, then fails server-side.
57
57
 
58
- ```bash
59
- mb uuid --count 5 --json # → ["…","…","…","…","…"] — mint exactly what you need, in one call
60
- ```
61
-
62
- Workflow: count the slots (one per clause options object), `mb uuid --count <N> --json`, substitute each minted value as you build the JSON. Never copy a UUID from docs, a prior query, or another session.
63
-
64
- **Aggregation/expression refs are the only legitimate reuse.** To reference an aggregation downstream (in `order-by` or a later stage), use `["aggregation", {options}, "<uuid>"]` where the third arg is the **string** `lib/uuid` of the target aggregation — the same minted value, by string equality. A numeric position fails with `must be the target aggregation's lib/uuid (string), not a numeric position`. Expression refs work the same way but key off the expression's name string.
58
+ Set an explicit `lib/uuid` only when you must **reference a clause from elsewhere in the query** — the one thing the server can't do for you, since you have to know the value to point at. The case that needs it: **ordering by (or otherwise reusing) an aggregation.** `["aggregation", {…}, "<uuid>"]`'s third arg is the **string** `lib/uuid` of the target aggregation, so give that aggregation an explicit `lib/uuid` and point the ref at the same string. A numeric position fails with `must be the target aggregation's lib/uuid (string), not a numeric position`.
65
59
 
66
60
  ```json
67
61
  "aggregation": [["count", { "lib/uuid": "AGG_UUID" }]],
68
- "order-by": [["desc", { "lib/uuid": "ORDER_UUID" },
69
- ["aggregation", { "lib/uuid": "REF_UUID" }, "AGG_UUID"]]]
62
+ "order-by": [["desc", {}, ["aggregation", {}, "AGG_UUID"]]]
70
63
  ```
71
64
 
72
- (`AGG_UUID` appears twice and must be the _same_ minted value; `ORDER_UUID` and `REF_UUID` are distinct.)
65
+ (`AGG_UUID` is both the aggregation's own `lib/uuid` and the string the ref points at — one value, by string equality. Every other clause omits its UUID. Expression refs work the same way but key off the expression's `lib/expression-name` string, so expressions rarely need an explicit `lib/uuid`.)
66
+
67
+ On the rare occasion you do need one, **always mint it with `mb uuid` — never write, guess, or copy a UUID yourself.** A hand-authored value is either rejected pre-flight as not-a-v4 (`"a1"`, `"uuid-1"`, `"agg-uuid-001"` → `must be a UUID v4 (RFC 4122) — run \`mb uuid\``) or, if it happens to look valid, risks colliding with another clause. Only `mb uuid`gives you genuine, unique v4s — mint just the few you reference (this also covers native template-tag ids and any other`format: "uuid"` slot):
68
+
69
+ ```bash
70
+ mb uuid --count 2 --json # mint only the clauses you actually reference
71
+ ```
73
72
 
74
73
  ## Authoring loop: print-schema → dry-run → run
75
74
 
@@ -87,6 +86,15 @@ mb query --file q.json --profile <n> --json # 3. validate +
87
86
 
88
87
  `path` is a JSON Pointer into the body (`/stages/0/aggregation/0`); `message` is the validator error. Exit codes: `0` valid + ran, `2` validation failed / malformed body, `1` server-side error after a valid pre-flight.
89
88
 
89
+ **Pre-flight is a lightweight shape check, not the full backend validator.** It checks JSON shape, `lib/uuid` format, and enum values — not operator names, the first-stage source rule, or whether a reference resolves. A clean `--dry-run` is necessary but not sufficient: a body can pass pre-flight and still fail on the server (exit `1`). The Metabase server is the authority — when a run fails, read its error and fix the body. The common ones and what they mean:
90
+
91
+ - `not a known MBQL clause` → a misspelled or unsupported **operator**. Check the vocabulary in `operators.md` (`mb skills get mbql --full`).
92
+ - `Initial MBQL stage must have either :source-table or :source-card` → the **first stage** is missing its source (a numeric table or card id); only the first stage takes one, later stages read the previous stage's columns.
93
+ - `Invalid :expression reference: no expression named "X"` (or an invalid `:aggregation` reference) → a **ref** points to an expression name / aggregation `lib/uuid` that isn't defined in the query; fix the target string.
94
+ - `Duplicate :lib/uuid` → you reused a `lib/uuid`. Omit them (the server mints unique ones) or give each clause a distinct value.
95
+
96
+ A successful run emits the compact envelope by default: `data.rows` + slim `data.cols` (`name`, `display_name`, `base_type`, `semantic_type`). Pass `--full` for the raw `/api/dataset` envelope (`results_metadata`, `native_form`, per-column fingerprints/`field_ref`) only when you need that metadata; `--fields data.rows` narrows to rows alone. `mb query` also runs a **native** body — `{database, type:"native", native:{query:"SELECT …"}}` — which skips pre-flight; the quickest way to eyeball warehouse data.
97
+
90
98
  `--skip-validate` bypasses the pre-flight and sends as-is — use only when the bundled schema disagrees with what the server actually accepts (drift / false negative). Mutually exclusive with `--dry-run`. The same flag exists on `card create/update` and `transform create/update`.
91
99
 
92
100
  ## Where MBQL 5 is consumed
@@ -110,7 +118,7 @@ The most common mistake. The legacy MBQL 4 shape `{ "type": "query", "database":
110
118
  "lib/type": "mbql/query",
111
119
  "database": 2,
112
120
  "stages": [{ "lib/type": "mbql.stage/mbql", "source-table": 190,
113
- "aggregation": [["count", { "lib/uuid": "<mint>" }]] }]
121
+ "aggregation": [["count", {}]] }]
114
122
  }
115
123
  ```
116
124
 
@@ -125,15 +133,74 @@ Anything that is not `lib/type: "mbql/query"` is sent as-is and normalized serve
125
133
 
126
134
  `mb query --file probe.json` runs these directly; `--dry-run` on them returns `{ ok: true, errors: [] }`. Don't author MBQL 4 by hand — if you need a legacy or complex query, build it in the Metabase UI and pull the body with `mb card get <id> --full --json` / `mb transform get <id> --full --json`.
127
135
 
136
+ ## Joins and FK traversal
137
+
138
+ Two ways to read columns from a related table.
139
+
140
+ **Explicit join.** A stage's `joins` array holds join objects, each with three required keys: `stages` (the joined source as its own one-stage array carrying `source-table`/`source-card`), `conditions` (the ON clause — `[op, {}, leftRef, rightRef]`, slot-1 rule and all), and `alias` (the string name you address joined columns by). Optional `strategy` (`left-join` default; also `right-join` / `inner-join` / `full-join`) and `fields` (`"all"` | `"none"` | an array of refs — which joined columns to select). Reference a joined column anywhere downstream by putting **`join-alias`** in the field options:
141
+
142
+ ```json
143
+ "joins": [
144
+ {
145
+ "alias": "Customers",
146
+ "strategy": "left-join",
147
+ "stages": [{ "lib/type": "mbql.stage/mbql", "source-table": 170 }],
148
+ "conditions": [
149
+ ["=", {}, ["field", {}, 1711], ["field", { "join-alias": "Customers" }, 1684]]
150
+ ],
151
+ "fields": "none"
152
+ }
153
+ ],
154
+ "breakout": [["field", { "join-alias": "Customers" }, 1682]]
155
+ ```
156
+
157
+ The condition's left ref is a column of the stage's own source (`1711` = orders.customer_id); the right ref carries `join-alias` and points at the joined table's key (`1684` = customers.id). Every later reference to a joined column (`1682` = customers.plan) needs that same `join-alias`. Stack multiple objects in `joins` for multiple joins, each with its own `alias`.
158
+
159
+ **Implicit FK join via `source-field`.** For a single-hop FK lookup, skip the join — put the FK column's id in the target field's `source-field` option and Metabase traverses the relationship:
160
+
161
+ ```json
162
+ ["field", { "source-field": 1711 }, 1682] // orders.customer_id → customers.plan
163
+ ```
164
+
165
+ `source-field` is the **FK field id** (orders.customer_id); the third element is the **target field id** in the related table (customers.plan). Use it for "show a column from the table this FK points at"; reach for an explicit join when you need a non-FK condition, a non-default strategy, or control over which joined columns return.
166
+
167
+ ## Multi-stage pipelines
168
+
169
+ Stages run in order; each reads the **previous stage's output columns** — the breakouts and aggregations it produced — referenced by **string name + `base-type`**, not a numeric field id. Only the first stage takes a `source-table`/`source-card`. The reason to add a stage is to operate on an aggregate (you can't filter or order by an aggregation within the stage that computes it): aggregate, then filter the aggregate, then order + limit.
170
+
171
+ ```json
172
+ "stages": [
173
+ { "lib/type": "mbql.stage/mbql", "source-table": 175,
174
+ "aggregation": [["sum", { "name": "total" }, ["field", {}, 1715]]],
175
+ "breakout": [["field", {}, 1711]] },
176
+ { "lib/type": "mbql.stage/mbql",
177
+ "filters": [[">", {}, ["field", { "base-type": "type/BigInteger" }, "total"], 0]] },
178
+ { "lib/type": "mbql.stage/mbql",
179
+ "order-by": [["desc", {}, ["field", { "base-type": "type/BigInteger" }, "total"]]],
180
+ "limit": 3 }
181
+ ]
182
+ ```
183
+
184
+ Later stages address the first stage's aggregation by the `name` you gave it (`"total"`) — set that `name`, or the column lands as the default `sum` / `count` / … and you reference that string instead.
185
+
186
+ **Window functions** sit in `aggregation` next to ordinary aggregates. `offset` reads a value from another breakout row — month-over-month is `offset` of a sum by `-1` against a monthly breakout:
187
+
188
+ ```json
189
+ "aggregation": [
190
+ ["sum", { "name": "revenue" }, ["field", {}, 1715]],
191
+ ["offset", { "name": "prev_month" }, ["sum", {}, ["field", {}, 1715]], -1]
192
+ ],
193
+ "breakout": [["field", { "temporal-unit": "month" }, 1717]]
194
+ ```
195
+
196
+ **Binning** is a breakout-level field option — bucket a numeric column into ranges with `["field", { "binning": { "strategy": "num-bins", "num-bins": 5 } }, 1715]`, the numeric counterpart to the `temporal-unit` bucket. Strategies (`num-bins` / `bin-width` / `default`) are in the operator reference.
197
+
128
198
  ## Naming aggregation output columns
129
199
 
130
200
  Default MBQL 5 aggregations materialize as `count`, `count_where`, `avg`, `avg_2`, `sum`, … — fine for an ad-hoc run, ugly when the output is a transform target table or a card column. Set `name` (becomes the warehouse column name) and `display-name` (the UI header) in the aggregation's options:
131
201
 
132
202
  ```json
133
- [
134
- "count",
135
- { "lib/uuid": "<mint>", "name": "shipments_shipped", "display-name": "Shipments shipped" }
136
- ]
203
+ ["count", { "name": "shipments_shipped", "display-name": "Shipments shipped" }]
137
204
  ```
138
205
 
139
206
  ## Operator reference
@@ -149,7 +216,7 @@ mb skills path mbql # → the skill dir; then Read references/operator
149
216
 
150
217
  ## Don't
151
218
 
152
- - Don't invent, hard-code, or copy `lib/uuid` values — `mb uuid` every slot at author time.
219
+ - Don't mint a `lib/uuid` for every clause — they're optional; omit them and the server fills them in. Mint (with `mb uuid`) only the clause you need to reference; never invent, hard-code, or copy a UUID (duplicates are rejected server-side).
153
220
  - Don't put the options object anywhere but slot 1, and don't use the legacy `["field", id, opts]` order.
154
221
  - Don't wrap an MBQL 5 body in `{type:"query", query:…}` — `dataset_query` / `source.query` / `definition` is the flat `mbql/query`.
155
222
  - Don't author MBQL 4 by hand — build it in the UI and pull it with `… get <id> --full --json`.
@@ -5,15 +5,15 @@ form. The clause _structure_ and the slot-1-options rule are in the SKILL.md bod
5
5
  this file is the catalog of which operators exist and their arguments.
6
6
 
7
7
  **Reading the tables.** Every clause is `[op, {options}, ...args]`. Below, `{…}`
8
- abbreviates the slot-1 options object, which always carries `lib/uuid` (mint with
9
- `mb uuid`) plus any operator-specific option noted in the row. Field refs are numeric:
10
- `["field", {…}, <field-id>]`. Everything here passes `mb query --dry-run`; when in
11
- doubt, that loop is the authority.
8
+ abbreviates the slot-1 options object — usually empty (`{}`), since `lib/uuid` is
9
+ optional and the server generates it (see the SKILL body). It carries a value only
10
+ when noted: an operator-specific option named in the row, or an explicit `lib/uuid`
11
+ you mint to reference the clause. Field refs are numeric: `["field", {…}, <field-id>]`.
12
+ Everything here passes `mb query --dry-run`; when in doubt, that loop is the authority.
12
13
 
13
- > Relative date filters use **`time-interval`** / **`relative-time-interval`** (below),
14
- > not bare date literals. If you pulled a query from the UI that contains
15
- > `relative-datetime` or `absolute-datetime`, the bundled schema does not yet model
16
- > those — send it with `--skip-validate` rather than rewriting it.
14
+ > For relative date filters, prefer **`time-interval`** / **`relative-time-interval`**
15
+ > (below). `relative-datetime` / `absolute-datetime` literals (e.g. from a UI-built
16
+ > query) also work.
17
17
 
18
18
  ---
19
19
 
@@ -67,7 +67,7 @@ options object.
67
67
  | `ends-with` | field, 1+ strings |
68
68
 
69
69
  ```json
70
- ["contains", { "lib/uuid": "<mint>", "case-sensitive": false }, ["field", {…}, 9], "widget"]
70
+ ["contains", { "case-sensitive": false }, ["field", {…}, 9], "widget"]
71
71
  ```
72
72
 
73
73
  ### Temporal
@@ -120,7 +120,7 @@ A stage's `aggregation` is a list of aggregation clauses.
120
120
  ```
121
121
 
122
122
  **Naming** — set `name` (warehouse column) and/or `display-name` (UI header) in the
123
- options object: `["sum", { "lib/uuid": "<mint>", "name": "revenue", "display-name": "Revenue" }, …]`.
123
+ options object: `["sum", { "name": "revenue", "display-name": "Revenue" }, …]`.
124
124
 
125
125
  **Window function** — `offset` is only valid inside `aggregation`:
126
126
 
@@ -205,7 +205,7 @@ Add/subtract/interval units: `year`, `quarter`, `month`, `week`, `day`, `hour`,
205
205
  | `coalesce` | 2+ expressions | first non-null |
206
206
 
207
207
  ```json
208
- ["case", { "lib/uuid": "<mint>", "lib/expression-name": "Tier" },
208
+ ["case", { "lib/expression-name": "Tier" },
209
209
  [[[">", {…}, ["field", {…}, 14], 100], "Premium"],
210
210
  [["<=", {…}, ["field", {…}, 14], 20], "Budget"]],
211
211
  "Standard"]
@@ -235,7 +235,7 @@ positional arg is the default.)
235
235
  `month-of-year`, `quarter-of-year`, `year-of-era`, `second-of-minute`.
236
236
 
237
237
  ```json
238
- ["field", { "lib/uuid": "<mint>", "temporal-unit": "month" }, 22]
238
+ ["field", { "temporal-unit": "month" }, 22]
239
239
  ```
240
240
 
241
241
  ## Field option: binning
@@ -249,5 +249,5 @@ positional arg is the default.)
249
249
  | `default` | — | Metabase chooses |
250
250
 
251
251
  ```json
252
- ["field", { "lib/uuid": "<mint>", "binning": { "strategy": "num-bins", "num-bins": 10 } }, 14]
252
+ ["field", { "binning": { "strategy": "num-bins", "num-bins": 10 } }, 14]
253
253
  ```