@ikas/code-components-mcp 1.4.0-beta.21 → 1.4.0-beta.212

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 (94) hide show
  1. package/data/framework.json +191 -78
  2. package/data/migration.json +10 -4
  3. package/data/section-templates/account-info-section/children/AccountFavorites/ikas-config-snippet.json +13 -0
  4. package/data/section-templates/account-info-section/children/AccountOrders/index.tsx +1 -1
  5. package/data/section-templates/account-info-section/ikas-config-snippet.json +19 -0
  6. package/data/section-templates/add-to-cart/ikas-config-snippet.json +17 -0
  7. package/data/section-templates/add-to-cart/index.tsx +16 -2
  8. package/data/section-templates/add-to-cart/sub-components/QuantitySelector/index.tsx +11 -3
  9. package/data/section-templates/add-to-cart/utils/cartLimits.ts +24 -0
  10. package/data/section-templates/blog-home-section/ikas-config-snippet.json +2 -0
  11. package/data/section-templates/blog-home-section/index.tsx +2 -1
  12. package/data/section-templates/blog-post-section/ikas-config-snippet.json +2 -0
  13. package/data/section-templates/blog-post-section/index.tsx +3 -2
  14. package/data/section-templates/bundle-products/hooks/useBundleProducts.ts +7 -6
  15. package/data/section-templates/bundle-products/ikas-config-snippet.json +20 -0
  16. package/data/section-templates/cart-section/components/EmptyState/index.tsx +1 -1
  17. package/data/section-templates/cart-section/sub-components/CartItem/index.tsx +66 -24
  18. package/data/section-templates/cart-section/sub-components/CartItem/styles.css +14 -0
  19. package/data/section-templates/cart-section/sub-components/QuantitySelector/index.tsx +11 -3
  20. package/data/section-templates/cart-section/utils/cartLimits.ts +24 -0
  21. package/data/section-templates/cart-section/utils/cartLineLimits.ts +100 -0
  22. package/data/section-templates/category-images-section/children/CategoryImageItem/ikas-config-snippet.json +4 -0
  23. package/data/section-templates/category-images-section/ikas-config-snippet.json +15 -0
  24. package/data/section-templates/category-list-section/children/CardProductName/ikas-config-snippet.json +2 -1
  25. package/data/section-templates/category-list-section/ikas-config-snippet.json +21 -0
  26. package/data/section-templates/category-list-section/index.tsx +2 -1
  27. package/data/section-templates/component-renderer/additional/ProductDetail/index.tsx +5 -1
  28. package/data/section-templates/component-renderer/ikas-config-snippet.json +13 -0
  29. package/data/section-templates/favorites/ikas-config-snippet.json +18 -1
  30. package/data/section-templates/features-section/ikas-config-snippet.json +13 -0
  31. package/data/section-templates/footer-section/ikas-config-snippet.json +15 -0
  32. package/data/section-templates/forgot-password-section/components/ForgotPasswordForm/index.tsx +1 -1
  33. package/data/section-templates/header-section/children/Announcements/ikas-config-snippet.json +7 -0
  34. package/data/section-templates/header-section/children/CookieBar/ikas-config-snippet.json +3 -0
  35. package/data/section-templates/header-section/children/Navbar/components/CartSidebar/index.tsx +2 -1
  36. package/data/section-templates/header-section/children/Navbar/components/SearchModal/index.tsx +2 -1
  37. package/data/section-templates/header-section/children/Navbar/ikas-config-snippet.json +27 -0
  38. package/data/section-templates/header-section/children/Navbar/index.tsx +6 -5
  39. package/data/section-templates/header-section/ikas-config-snippet.json +13 -0
  40. package/data/section-templates/header-section/sub-components/CartItem/index.tsx +66 -24
  41. package/data/section-templates/header-section/sub-components/CartItem/styles.css +14 -0
  42. package/data/section-templates/header-section/sub-components/QuantitySelector/index.tsx +11 -3
  43. package/data/section-templates/header-section/utils/cartLimits.ts +24 -0
  44. package/data/section-templates/header-section/utils/cartLineLimits.ts +100 -0
  45. package/data/section-templates/hero-slider-section/children/HeroSliderItem/ikas-config-snippet.json +18 -0
  46. package/data/section-templates/hero-slider-section/children/HeroSliderItem/index.tsx +12 -7
  47. package/data/section-templates/hero-slider-section/ikas-config-snippet.json +13 -0
  48. package/data/section-templates/image-handling/ikas-config-snippet.json +53 -0
  49. package/data/section-templates/image-handling/index.tsx +5 -1
  50. package/data/section-templates/login-section/ikas-config-snippet.json +2 -0
  51. package/data/section-templates/navigation/components/CartSidebar/index.tsx +2 -1
  52. package/data/section-templates/navigation/components/SearchModal/index.tsx +2 -1
  53. package/data/section-templates/navigation/ikas-config-snippet.json +27 -0
  54. package/data/section-templates/navigation/index.tsx +6 -5
  55. package/data/section-templates/navigation/sub-components/CartItem/index.tsx +66 -24
  56. package/data/section-templates/navigation/sub-components/CartItem/styles.css +14 -0
  57. package/data/section-templates/navigation/sub-components/QuantitySelector/index.tsx +11 -3
  58. package/data/section-templates/navigation/utils/cartLimits.ts +24 -0
  59. package/data/section-templates/navigation/utils/cartLineLimits.ts +100 -0
  60. package/data/section-templates/product-detail-section/children/ProductDetailAddToCart/ikas-config-snippet.json +17 -0
  61. package/data/section-templates/product-detail-section/children/ProductDetailAddToCart/index.tsx +16 -2
  62. package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/components/BackInStockForm/index.tsx +92 -0
  63. package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/ikas-config-snippet.json +175 -0
  64. package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/index.tsx +141 -0
  65. package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/styles.css +47 -0
  66. package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/types.ts +25 -0
  67. package/data/section-templates/product-detail-section/children/ProductDetailBundleFurniture/ikas-config-snippet.json +18 -0
  68. package/data/section-templates/product-detail-section/children/ProductDetailBundleProduct/ikas-config-snippet.json +20 -0
  69. package/data/section-templates/product-detail-section/children/ProductDetailDescription/ikas-config-snippet.json +27 -0
  70. package/data/section-templates/product-detail-section/children/ProductDetailFeatures/ikas-config-snippet.json +29 -0
  71. package/data/section-templates/product-detail-section/children/ProductDetailNameFavorite/ikas-config-snippet.json +18 -1
  72. package/data/section-templates/product-detail-section/children/ProductDetailOffer/ikas-config-snippet.json +20 -0
  73. package/data/section-templates/product-detail-section/children/ProductDetailOptionSet/ikas-config-snippet.json +16 -0
  74. package/data/section-templates/product-detail-section/children/ProductDetailPrices/ikas-config-snippet.json +16 -0
  75. package/data/section-templates/product-detail-section/children/ProductDetailProductGroup/ikas-config-snippet.json +16 -0
  76. package/data/section-templates/product-detail-section/children/ProductDetailSku/ikas-config-snippet.json +16 -0
  77. package/data/section-templates/product-detail-section/children/ProductDetailVariant/ikas-config-snippet.json +17 -0
  78. package/data/section-templates/product-detail-section/hooks/useBundleProducts.ts +7 -6
  79. package/data/section-templates/product-detail-section/ikas-config-snippet.json +53 -0
  80. package/data/section-templates/product-detail-section/index.tsx +5 -1
  81. package/data/section-templates/product-detail-section/sub-components/Modal/index.tsx +120 -0
  82. package/data/section-templates/product-detail-section/sub-components/Modal/styles.css +70 -0
  83. package/data/section-templates/product-detail-section/sub-components/QuantitySelector/index.tsx +11 -3
  84. package/data/section-templates/product-detail-section/utils/cartLimits.ts +24 -0
  85. package/data/section-templates/product-pricing/ikas-config-snippet.json +16 -0
  86. package/data/section-templates/product-slider-section/children/CardProductName/ikas-config-snippet.json +2 -1
  87. package/data/section-templates/product-slider-section/ikas-config-snippet.json +17 -0
  88. package/data/section-templates/register-section/ikas-config-snippet.json +2 -0
  89. package/data/section-templates/variant-selection/ikas-config-snippet.json +17 -0
  90. package/data/storefront-api.json +682 -39
  91. package/data/storefront-types.json +9694 -6047
  92. package/dist/index.js +1614 -42
  93. package/dist/index.js.map +1 -1
  94. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1589,20 +1589,53 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
1589
1589
  return parts.join("\n");
1590
1590
  }
1591
1591
  // --- Search helpers ---
1592
+ /**
1593
+ * Strip every non-alphanumeric character and lowercase, so the SAME identifier written in
1594
+ * different conventions collapses to one form: `PRODUCT_ATTRIBUTE`, `IkasProductAttributeDetail`
1595
+ * and the prose "product attribute detail" all become `productattribute…`. Without this a query
1596
+ * for a prop type (which is always SCREAMING_SNAKE) can never reach the function/type docs that
1597
+ * spell the same concept in camelCase or prose — `search_docs("PRODUCT_ATTRIBUTE")` used to miss
1598
+ * `getAttributeDetailValues` entirely.
1599
+ */
1600
+ function squashIdentifier(text) {
1601
+ return text.replace(/[^a-z0-9]/gi, "").toLowerCase();
1602
+ }
1603
+ /** A query word worth matching separator-insensitively: an identifier, not prose. */
1604
+ function isIdentifierLike(word) {
1605
+ return (word.length > 3 &&
1606
+ (/[_\-.]/.test(word) ||
1607
+ /[a-z][A-Z]/.test(word) ||
1608
+ /^[A-Z0-9_]+$/.test(word)));
1609
+ }
1592
1610
  function matchScore(text, query) {
1593
1611
  const lower = text.toLowerCase();
1594
1612
  const queryLower = query.toLowerCase();
1595
- const words = queryLower.split(/\s+/).filter(Boolean);
1613
+ const words = query.split(/\s+/).filter(Boolean);
1596
1614
  let score = 0;
1597
1615
  // Exact substring match
1598
1616
  if (lower.includes(queryLower)) {
1599
1617
  score += 10;
1600
1618
  }
1601
- // Word matches
1619
+ // Word matches. Squashing the (potentially guide-sized) text is the expensive half of the
1620
+ // identifier check — compute it lazily, once per call, not once per query word.
1621
+ let squashedText = null;
1602
1622
  for (const word of words) {
1603
- if (lower.includes(word)) {
1623
+ const wordLower = word.toLowerCase();
1624
+ if (lower.includes(wordLower)) {
1604
1625
  score += 3;
1605
1626
  }
1627
+ else if (isIdentifierLike(word)) {
1628
+ // Same identifier, different convention (PRODUCT_ATTRIBUTE ↔ IkasProductAttributeDetail
1629
+ // ↔ "product attribute"). Scored below an exact word hit so literal matches still win.
1630
+ const squashed = squashIdentifier(word);
1631
+ if (squashed) {
1632
+ if (squashedText === null)
1633
+ squashedText = squashIdentifier(text);
1634
+ if (squashedText.includes(squashed)) {
1635
+ score += 2;
1636
+ }
1637
+ }
1638
+ }
1606
1639
  }
1607
1640
  // Name exact match bonus
1608
1641
  if (lower === queryLower) {
@@ -1657,6 +1690,73 @@ function suggestClosestNames(input, candidates, opts) {
1657
1690
  .sort((a, b) => a.d - b.d);
1658
1691
  return edits.slice(0, max).map((s) => s.name);
1659
1692
  }
1693
+ /**
1694
+ * Formatted ` — matching sections: ...` suffix naming the guide sections that match the query,
1695
+ * so a hit buried mid-guide (e.g. "Quantity Limits" inside cart-patterns) is visible without
1696
+ * opening the full guide. Section bodies are scored on purpose: a query for an identifier that
1697
+ * appears only inside a section (an error code, a prop name) must still surface that section's
1698
+ * heading. Returns "" when the query matches most of the guide's sections — matchScore is
1699
+ * presence-based, so a broad query ("cart" against cart-patterns) ties every section and a
1700
+ * top-3 would just echo document order, hinting nothing.
1701
+ */
1702
+ // Topic content is loaded once at startup and never mutates, so the section parse is
1703
+ // memoized on the content string — a query only pays for scoring.
1704
+ const parsedSectionsCache = new Map();
1705
+ function parseSections(content) {
1706
+ const cached = parsedSectionsCache.get(content);
1707
+ if (cached)
1708
+ return cached;
1709
+ // Line walk instead of a heading-regex split: a `## ` line inside a fenced code block must
1710
+ // not become a pseudo-section (it would surface a heading that doesn't exist in the guide
1711
+ // and swallow the rest of the real section's body).
1712
+ const sections = [];
1713
+ let fenceOpen = false;
1714
+ for (const line of content.split("\n")) {
1715
+ if (/^\s*```/.test(line))
1716
+ fenceOpen = !fenceOpen;
1717
+ const headingMatch = fenceOpen ? null : line.match(/^#{2,4} (.+)/);
1718
+ if (headingMatch)
1719
+ sections.push({ heading: headingMatch[1].trim(), body: "" });
1720
+ else if (sections.length > 0)
1721
+ sections[sections.length - 1].body += line + "\n";
1722
+ }
1723
+ parsedSectionsCache.set(content, sections);
1724
+ return sections;
1725
+ }
1726
+ function sectionHint(content, query, topicTitle) {
1727
+ const sections = parseSections(content);
1728
+ const scored = [];
1729
+ for (const { heading, body } of sections) {
1730
+ // Heading hits weigh double. The floor of 3 drops sections whose only signal is a single
1731
+ // squashed-identifier body match (worth 2) — a literal word hit (3) or any heading match
1732
+ // clears it.
1733
+ const score = matchScore(heading, query) * 2 + matchScore(body, query);
1734
+ if (score >= 3)
1735
+ scored.push({ heading, score });
1736
+ }
1737
+ if (scored.length === 0)
1738
+ return "";
1739
+ scored.sort((a, b) => b.score - a.score);
1740
+ // The tie-guard below must only fire when the field is genuinely flat. A single common
1741
+ // query word ("cart") pushes every section past the floor, so counting raw matches would
1742
+ // also suppress steep fields where one section clearly won. Sections below 60% of the top
1743
+ // score are noise from such a word, not real matches — drop them before counting.
1744
+ const strong = scored.filter((s) => s.score >= scored[0].score * 0.6);
1745
+ if (strong.length > sections.length / 2)
1746
+ return "";
1747
+ // The guide's own title is usually its first `##` line, so it registers as a section.
1748
+ // Its heading is the exact text the result line already prints — listing it would burn
1749
+ // one of the three slots on a pure echo. Keep it in scoring (its body can be a genuine
1750
+ // hit and it counts toward the tie-guard), drop it from the output only. Headings are
1751
+ // already trimmed at parse time; trim the title too so stray whitespace in the JSON
1752
+ // cannot silently re-admit the echo.
1753
+ const title = topicTitle.trim();
1754
+ const named = strong.filter((s) => s.heading !== title);
1755
+ if (named.length === 0)
1756
+ return "";
1757
+ const top = named.slice(0, 3);
1758
+ return ` — matching sections: ${top.map((s) => `"${s.heading}"`).join(", ")}`;
1759
+ }
1660
1760
  function searchFunctions(query) {
1661
1761
  const scored = storefrontData.functions
1662
1762
  .map((fn) => {
@@ -1719,13 +1819,31 @@ function searchTypes(query) {
1719
1819
  const enumScore = td.enumValues?.some((v) => matchScore(v, query) > 0)
1720
1820
  ? 4
1721
1821
  : 0;
1722
- return { td, score: nameScore + domainScore + propScore + enumScore };
1822
+ const unionScore = td.unionValues?.some((v) => matchScore(v, query) > 0)
1823
+ ? 4
1824
+ : 0;
1825
+ return {
1826
+ td,
1827
+ score: nameScore + domainScore + propScore + enumScore + unionScore,
1828
+ };
1723
1829
  })
1724
1830
  .filter((item) => item.score > 0)
1725
1831
  .sort((a, b) => b.score - a.score);
1726
1832
  return scored.map((item) => item.td);
1727
1833
  }
1728
1834
  // --- Format helpers ---
1835
+ /**
1836
+ * Wrap a code snippet in a fenced block — unless it already carries its own fence. JSDoc `@example`
1837
+ * bodies are indexed verbatim, so every one of them arrives fenced; wrapping them again produced a
1838
+ * double ```` ``` ```` opener, which makes the block unparseable for anything extracting code from
1839
+ * the doc. Bare snippets still get fenced as typescript.
1840
+ */
1841
+ function asCodeBlock(snippet) {
1842
+ const trimmed = snippet.trim();
1843
+ return trimmed.startsWith("```")
1844
+ ? trimmed
1845
+ : ["```typescript", trimmed, "```"].join("\n");
1846
+ }
1729
1847
  function formatFunctionDoc(fn) {
1730
1848
  const lines = [];
1731
1849
  lines.push(`## ${fn.name}`);
@@ -1752,7 +1870,7 @@ function formatFunctionDoc(fn) {
1752
1870
  lines.push("", `**Returns:** \`${fn.returnType}\`${fn.returns ? ` - ${fn.returns}` : ""}`);
1753
1871
  }
1754
1872
  if (fn.example) {
1755
- lines.push("", "**Example:**", "```typescript", fn.example, "```");
1873
+ lines.push("", "**Example:**", asCodeBlock(fn.example));
1756
1874
  }
1757
1875
  if (fn.related.length > 0) {
1758
1876
  lines.push("", `**Related:** ${fn.related.map((r) => `\`${r}\``).join(", ")}`);
@@ -1773,13 +1891,24 @@ function formatTypeDefinition(td, opts = {}) {
1773
1891
  const lines = [];
1774
1892
  lines.push(`## ${td.name}`);
1775
1893
  lines.push("", `**Kind:** ${td.kind} | **Domain:** ${td.domain}`);
1776
- if (td.kind === "type") {
1894
+ if (td.description) {
1895
+ lines.push("", td.description);
1896
+ }
1897
+ if (td.kind === "type" && td.unionValues) {
1898
+ lines.push("", "```typescript");
1899
+ lines.push(`type ${td.name} = ${td.unionValues.map((v) => `"${v}"`).join(" | ")};`);
1900
+ lines.push("```");
1901
+ }
1902
+ else if (td.kind === "type") {
1777
1903
  lines.push("", "```typescript");
1778
1904
  const extendsStr = td.extends ? ` & ${td.extends.join(" & ")}` : "";
1779
1905
  lines.push(`type ${td.name} = {`);
1780
1906
  if (td.properties) {
1781
1907
  for (const p of td.properties) {
1782
1908
  const opt = p.optional ? "?" : "";
1909
+ if (p.description) {
1910
+ lines.push(" /**", ...p.description.split("\n").map((l) => ` * ${l.trim()}`), " */");
1911
+ }
1783
1912
  lines.push(` ${p.name}${opt}: ${p.type};`);
1784
1913
  }
1785
1914
  }
@@ -1828,6 +1957,10 @@ function formatTypeSummary(td) {
1828
1957
  const count = td.enumValues?.length ?? 0;
1829
1958
  return `- \`${td.name}\` (enum, ${count} values) — domain: ${td.domain}`;
1830
1959
  }
1960
+ if (td.unionValues) {
1961
+ const values = td.unionValues.map((v) => `"${v}"`).join(" | ");
1962
+ return `- \`${td.name}\` (union: ${values}) — domain: ${td.domain}`;
1963
+ }
1831
1964
  const count = td.properties?.length ?? 0;
1832
1965
  const ext = td.extends ? ` extends ${td.extends.join(", ")}` : "";
1833
1966
  return `- \`${td.name}\` (${count} properties${ext}) — domain: ${td.domain}`;
@@ -1838,12 +1971,15 @@ const server = new McpServer({
1838
1971
  version: "0.1.0",
1839
1972
  }, {
1840
1973
  instructions: "Examples and section templates from this server are API reference only — reuse imports, function calls, and data-access patterns; create your own JSX structure, CSS class names, and visual design.\n\n" +
1841
- "Live-editor actions (require `ikas-component dev` running with the editor connected): `list_editor_pages` → page ids; `list_imported_sections` → imported component ids; `import_section` → import a built component; `add_section_to_page` → place a section on a page; `list_page_sections` → the sections already placed on a page, each with its per-placement `elementId`, current `propValues`, and blueprint `props`; `update_section_prop` → change a single prop value of a placed section; `upload_image` → upload an image (file or URL) and get an image id to use in an IMAGE prop value.\n\n" +
1974
+ "CONFIG FILE — HARD RULE: NEVER edit `ikas.config.json` directly (no file write, patch or search/replace). Change it ONLY through `ikas-component` commands (`ikas-component config add-component` / `add-prop` / `update-prop` / `add-enum`, …; `ikas-component config list` to inspect). `projectId` and every component `id` are generated once and are IMMUTABLE — never change them, and never copy an id returned by the editor (`list_imported_sections`, `list_page_sections`, …) into `ikas.config.json`. On a theme that INSTALLED this project as a design asset the editor reports PUBLISHED ids, whose prefix differs from this project's `projectId`; that difference is expected and is NOT drift to fix — pass the editor's id to the editor tools and leave the config untouched. A config id that does not start with the project's own `projectId` makes `ikas-component dev` / `publish` fail and can corrupt the published theme.\n\n" +
1975
+ "Live-editor actions (require `ikas theme dev` running with the editor connected): `list_editor_pages` → page ids; `list_imported_sections` → imported component ids; `import_section` → import a built component; `add_section_to_page` → place one section (`add_sections_to_page` places MANY at once and can set their props in the same call — fastest way to build a page); `list_page_sections` → the sections placed on a page (LEAN roster: per-placement `elementId`, `componentId`, `propCount`, which props are filled — NO schema/values, so it never truncates); `move_page_section` → reorder a section already placed on a page (by `direction` up/down or an absolute `to_index`) — the only way to change section order, since the editor UI offers it solely as a drag; `get_component_props` → a component's prop blueprint (types, ENUM valid `options`, COMPONENT_LIST `allowedComponentIds`) for any section OR child id; `get_section_values` → one section's current prop values (for read-modify-write); `get_page_by_type` → a theme page id by pageType (e.g. CATEGORY), to build PAGE links to entities (`create_page` adds that page if it does not exist yet, so you never guess a slug); `update_section_prop` → change a single prop value of a placed section (`update_page_sections` fills MANY sections/props of a page in ONE call — strongly prefer it to cut round-trips when filling content); `upload_image` → upload one image (file or URL) and get an image id (`upload_images` uploads many in one call — prefer it for several); `search_products` / `list_categories` / `list_brands` / `list_blogs` / `list_blog_categories` → find real entity ids for PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY prop values; `publish_theme` → publish the theme LIVE and get back the preview URL to review (guarded — needs `confirm:true`, and `confirm_production:true` for the main theme; only call it when the user explicitly asks to publish); `list_ready_made_pages` / `update_ready_made_page_prop` / `enable_ready_made_pages` → the ikas-rendered ready-made account/membership pages (login, register, my account, orders, …) — these are NOT sections and the section tools cannot edit them; use these three to enable the groups, read their prop schemas, and customize/localize them (logo, colors, texts). When the user asks to BUILD a login/register/password/my-account/orders/addresses page, FIRST offer these ready-made pages instead of assembling one from sections — they are fully functional out of the box and customizable (logo, colors, texts); build a custom section page only if the user prefers a custom design. Offer, don't flip: `enable_ready_made_pages` creates/removes pages, so get the user's explicit OK before calling it. For the full end-to-end process (placing a section and filling its content, with per-prop value shapes and COMPONENT_LIST rules), call `get_editor_workflow` first.\n\n" +
1976
+ "READY-MADE PAGES FIRST — HARD RULE for account/membership pages: USER-FACING NAME: name these in the USER'S OWN LANGUAGE — English: \"ikas's ready-made pages\", Turkish: \"ikas'ın hazır sayfaları\"; never mix the English term into a sentence in another language — the editor UI lists them as Membership Pages / My Account Pages; \"built-in\" is an internal term — keep it out of everything the user sees, including question/option labels. When the user asks for a login, register, forgot/recover-password, my-account, orders, order-detail, addresses, favorites or email-verification page, do NOT start coding a custom section page. STOP and ask the user FIRST whether to use ikas's ready-made version of that page (`list_ready_made_pages` shows it — fully functional out of the box, customized/localized via `update_ready_made_page_prop`, the whole group turned on with `enable_ready_made_pages`). Only build a custom section page AFTER the user explicitly chooses custom. When asking, list the ready-made option FIRST as the recommended default; the custom section option comes second. Never call `enable_ready_made_pages` without the user's OK — it creates/removes pages. Ready-made pages are born with ONLY their own ikas-rendered element: the theme's header/footer are NOT on them (the page draws its own top bar — logo, back-to-store link — and account nav). If the user wants the theme header/footer on a ready-made page, PLACE it there with add_section_to_page — sections can sit above/below that element — and suggest turning the page's own `showBrandBar` prop off to avoid double chrome.\n\n" +
1842
1977
  "To CHANGE/EDIT a prop value (text, color, boolean, number, etc.) of a section that is already on a page, this IS supported: call `list_page_sections(page_id)` to get the placement `elementId` and the prop names/ids, then `update_section_prop(page_id, element_id, prop_name|prop_id, value)`. Do not assume prop editing is unavailable.\n\n" +
1843
1978
  "TWO DISTINCT JOBS — do not confuse them, and do not jump to writing code for the second one:\n" +
1844
1979
  "(A) DEFINING props / authoring a component = changing which props a component HAS. This edits the component source/config (types.ts via `ikas-component config add-prop`/`add-component`, JSX in index.tsx, etc.) and requires a rebuild. Use this ONLY when the needed prop does not exist yet, or the user explicitly asks to build/modify the component's code or prop schema.\n" +
1845
1980
  "(B) SETTING prop VALUES / filling content = giving values to props that ALREADY exist on a section placed on a page. This is pure data entry via `list_page_sections` + `update_section_prop` (and `upload_image` for images). It writes NO code and needs NO rebuild.\n" +
1846
- "When the user says things like 'fill this section', 'set the heading/title/text/image/link', 'populate', 'change the content/value', or 'enter this data', that is JOB (B): use `update_section_prop`. First call `list_page_sections` and check the existing `props` — if the prop is already there (it usually is), just set its value. Only fall back to JOB (A) if the required prop genuinely does not exist in that section's `props`. Writing a new component or adding a prop to fill in a value the section already supports is the wrong move.",
1981
+ "When the user says things like 'fill this section', 'set the heading/title/text/image/link', 'populate', 'change the content/value', or 'enter this data', that is JOB (B): use `update_section_prop`. First call `list_page_sections` and check the existing `props` — if the prop is already there (it usually is), just set its value. Only fall back to JOB (A) if the required prop genuinely does not exist in that section's `props`. Writing a new component or adding a prop to fill in a value the section already supports is the wrong move.\n\n" +
1982
+ "COMMON (GLOBAL) SECTIONS — HEADER & FOOTER: these render on every page that CARRIES A PLACEMENT of them — pages created in the editor are seeded with one, EXCEPT ikas ready-made (built-in) account/membership pages, which are born WITHOUT the theme header/footer (see the ready-made rule above) — and their prop values are shared theme-wide, stored in ONE record on the INDEX (Home) page's placement. Reads and writes from any page are resolved to that record, and every response about such a section carries a `common` block (`isCommon`, `commonSectionType`, `canonicalPageId`, `canonicalElementId`, `valuesArePageSpecific: false`). Consequences: changing a header/footer prop from, say, a product-detail page changes it on ALL pages; and since the header/footer normally already holds the merchant's content, you must `get_section_values` first and change only what the user asked — never treat a prop as empty and never blind-fill 'missing' props, or you overwrite live content everywhere. If the INDEX page has no placement of the section there is no record at all: reads report nothing and writes fail until you add it to the INDEX page.",
1847
1983
  });
1848
1984
  // Tool: search_docs
1849
1985
  server.tool("search_docs", "Search across all ikas storefront API docs, framework guides, and migration guides. Returns matching functions, framework topics, and migration topics ranked by relevance.", { query: z.string().describe("Search keyword or phrase") }, async ({ query }) => {
@@ -1863,7 +1999,7 @@ server.tool("search_docs", "Search across all ikas storefront API docs, framewor
1863
1999
  if (topics.length > 0) {
1864
2000
  parts.push("\n## Matching Framework Topics\n");
1865
2001
  for (const item of topics) {
1866
- parts.push(`- **${item.topic.title}** (key: \`${item.key}\`) - ${item.topic.description}`);
2002
+ parts.push(`- **${item.topic.title}** (key: \`${item.key}\`) - ${item.topic.description}${sectionHint(item.topic.content, query, item.topic.title)}`);
1867
2003
  }
1868
2004
  parts.push("");
1869
2005
  parts.push("Use `get_framework_guide(topic)` to get full content for any topic.");
@@ -1879,7 +2015,7 @@ server.tool("search_docs", "Search across all ikas storefront API docs, framewor
1879
2015
  if (migrationTopics.length > 0) {
1880
2016
  parts.push("\n## Matching Migration Topics\n");
1881
2017
  for (const item of migrationTopics) {
1882
- parts.push(`- [migration] **${item.topic.title}** (key: \`${item.key}\`) - ${item.topic.description}`);
2018
+ parts.push(`- [migration] **${item.topic.title}** (key: \`${item.key}\`) - ${item.topic.description}${sectionHint(item.topic.content, query, item.topic.title)}`);
1883
2019
  }
1884
2020
  parts.push("");
1885
2021
  parts.push("Use `get_migration_guide(topic)` to get full content for any migration topic.");
@@ -2109,7 +2245,7 @@ server.tool("get_code_example", "Get an API usage reference for a specific task.
2109
2245
  }
2110
2246
  }
2111
2247
  else {
2112
- parts.push("```typescript", example.code, "```", "");
2248
+ parts.push(asCodeBlock(example.code), "");
2113
2249
  }
2114
2250
  parts.push(`**Reminder:** Use the API patterns above (function calls, imports, type handling) but create your own original HTML structure and CSS.`);
2115
2251
  parts.push("");
@@ -2157,6 +2293,13 @@ server.tool("get_framework_guide", "Get a framework guide on a specific topic (e
2157
2293
  global: "global-css",
2158
2294
  "css-variables": "global-css",
2159
2295
  "custom-properties": "global-css",
2296
+ conditional: "conditional-visibility",
2297
+ "conditional-props": "conditional-visibility",
2298
+ visibility: "conditional-visibility",
2299
+ requiredprop: "conditional-visibility",
2300
+ "required-prop": "conditional-visibility",
2301
+ "dependent-props": "conditional-visibility",
2302
+ "show-hide": "conditional-visibility",
2160
2303
  };
2161
2304
  const resolvedTopic = topicAliases[topicLower] || topicLower;
2162
2305
  // Topics that involve MobX store reads get a reminder about root reactivity
@@ -2227,7 +2370,7 @@ server.tool("get_framework_guide", "Get a framework guide on a specific topic (e
2227
2370
  };
2228
2371
  });
2229
2372
  // Tool: get_type_definition
2230
- server.tool("get_type_definition", "Get the full definition of a storefront type or enum by name (e.g. 'IkasProduct', 'IkasOrderStatus'). Shows all properties with types, extends, or enum values.", {
2373
+ server.tool("get_type_definition", "Get the full definition of a storefront type or enum by name. Shows all properties with types, extends, enum values, or string-union values. Covers runtime models (e.g. 'IkasProduct', 'IkasOrderStatus'), theme-globals tokens returned by the getters (e.g. 'ThemeSetting', 'DesignToken', 'TypographyToken', 'ColorSchemeToken', 'BreakpointToken', 'KeyframeToken'), and style-prop TYPE shapes used by ikas.config.json props (e.g. 'BorderRadiusStyleType', 'PaddingStyleType', 'GapStyleType', 'SizeStyleType' and their '*StyleUnitType' unions). If a type reports as not found, it may not be indexed yet — fall back to reading the package's `.d.ts` (e.g. `@ikas/bp-storefront-config`) rather than typing the value as `any`.", {
2231
2374
  name: z
2232
2375
  .string()
2233
2376
  .describe("Type or enum name (e.g. 'IkasProduct', 'IkasOrderStatus')"),
@@ -2623,7 +2766,7 @@ server.tool("list_types", "List storefront types and enums. Use `domain` and/or
2623
2766
  return { content: [{ type: "text", text: parts.join("\n") }] };
2624
2767
  });
2625
2768
  // Tool: get_prop_types
2626
- server.tool("get_prop_types", "Get all available ikas.config.json prop types with descriptions, TypeScript types, and examples. NOTE: these are the TypeScript prop-definition types for authoring a component — they are NOT the runtime JSON value shapes you write via `update_section_prop` (e.g. a TEXT prop is typed `string` here but written as `{ \"value\": \"...\" }`, and an IMAGE is `IkasImage | null` here but written as `{ \"id\": \"...\" }`). For the value shapes to pass to `update_section_prop`, see that tool's description. Tip: Use `npx ikas-component config add-component --props '[...]'` to create a component with all props in one command, or `add-prop` to add props incrementally. NEVER manually edit types.ts — it is auto-generated by the CLI.", {}, async () => {
2769
+ server.tool("get_prop_types", 'Get all available ikas.config.json prop types with descriptions, TypeScript types, and examples. NOTE: these are the TypeScript prop-definition types for authoring a component — they are NOT the runtime JSON value shapes you write via `update_section_prop` (e.g. a TEXT prop is typed `string` here but written as `{ "value": "..." }`, and an IMAGE is `IkasImage | null` here but written as `{ "id": "..." }`). For the value shapes to pass to `update_section_prop`, see that tool\'s description. Tip: Use `npx ikas-component config add-component --props \'[...]\'` to create a component with all props in one command, or `add-prop` to add props incrementally. NEVER manually edit types.ts — it is auto-generated by the CLI.', {}, async () => {
2627
2770
  const propTypesTopic = frameworkData.topics["prop-types"];
2628
2771
  if (propTypesTopic) {
2629
2772
  return {
@@ -2645,6 +2788,23 @@ server.tool("get_prop_types", "Get all available ikas.config.json prop types wit
2645
2788
  };
2646
2789
  });
2647
2790
  // Tool: get_section_template
2791
+ // Starter templates that rebuild a page ikas already ships as a ready-made BUILT-IN page. Asked to
2792
+ // "build a login page", the agent reaches for the template before any other tool — so the
2793
+ // ask-the-user gate rides this response, where it cannot be skimmed past.
2794
+ const BUILTIN_COVERED_TEMPLATES = new Set([
2795
+ "login-section",
2796
+ "register-section",
2797
+ "forgot-password-section",
2798
+ "recover-password-section",
2799
+ "email-verification-section",
2800
+ "account-info-section",
2801
+ "favorites",
2802
+ ]);
2803
+ const BUILTIN_COVERED_BANNER = [
2804
+ "STOP — ASK THE USER BEFORE CODING THIS.",
2805
+ "This template rebuilds a page ikas already ships as a ready-made page: fully functional auth/account flows out of the box, customized and localized via `update_ready_made_page_prop`, the whole group enabled with `enable_ready_made_pages` (see `list_ready_made_pages`).",
2806
+ "If the user has not EXPLICITLY chosen a custom-coded page, do not write code yet. Ask them now: (a) ikas's ready-made page — instant, maintained by ikas — or (b) a custom section with full design freedom. List the ready-made option FIRST as the recommended default; custom comes second. Continue with this template ONLY after they explicitly choose custom.",
2807
+ ].join("\n");
2648
2808
  // Build the enum dynamically from the on-disk section templates directory
2649
2809
  const sectionTemplateKeys = sectionTemplateNames.length > 0
2650
2810
  ? sectionTemplateNames
@@ -2729,6 +2889,9 @@ server.tool("get_section_template", "Get the root files of a starter section tem
2729
2889
  (bundle.componentNames.length > 0 && !componentsFullyIncluded) ||
2730
2890
  (bundle.subComponentNames.length > 0 && !subComponentsFullyIncluded);
2731
2891
  const parts = [
2892
+ ...(BUILTIN_COVERED_TEMPLATES.has(normalizedType)
2893
+ ? [BUILTIN_COVERED_BANNER, ""]
2894
+ : []),
2732
2895
  `## ${bundle.title} — API Integration Pattern Reference`,
2733
2896
  "",
2734
2897
  ];
@@ -3095,7 +3258,10 @@ server.tool("list_section_types", "List all available `get_section_template` sec
3095
3258
  ];
3096
3259
  for (const name of sectionTemplateNames) {
3097
3260
  const meta = loadSectionMeta(name);
3098
- lines.push(`- \`${name}\`${meta ? ` — ${meta.title}` : ""}`);
3261
+ const builtinMark = BUILTIN_COVERED_TEMPLATES.has(name)
3262
+ ? " [ikas ships a ready-made page for this — ask the user before coding a custom one; see list_ready_made_pages]"
3263
+ : "";
3264
+ lines.push(`- \`${name}\`${meta ? ` — ${meta.title}` : ""}${builtinMark}`);
3099
3265
  }
3100
3266
  lines.push("", "Call `get_section_template(sectionType)` to fetch one.");
3101
3267
  return { content: [{ type: "text", text: lines.join("\n") }] };
@@ -3476,7 +3642,12 @@ function resolveIkasComponentBinary(projectRoot) {
3476
3642
  async function runIkasComponentCli(projectRoot, args) {
3477
3643
  const bin = resolveIkasComponentBinary(projectRoot);
3478
3644
  return new Promise((resolve) => {
3479
- execFile(bin, args, { cwd: projectRoot, windowsHide: true }, (err, stdout, stderr) => {
3645
+ execFile(bin, args,
3646
+ // Large editor responses (e.g. list_categories on a big store, or
3647
+ // add_sections_to_page echoing many sections) easily exceed Node's default
3648
+ // 1MB stdout buffer, which truncates output mid-JSON and yields a
3649
+ // "no parseable JSON" error. Give it generous headroom.
3650
+ { cwd: projectRoot, windowsHide: true, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
3480
3651
  const exitCode = err && typeof err.code === "number"
3481
3652
  ? err.code
3482
3653
  : err
@@ -3494,22 +3665,58 @@ function parseCliJson(stdout) {
3494
3665
  const trimmed = stdout.trim();
3495
3666
  if (!trimmed)
3496
3667
  return null;
3497
- // CLI prints exactly one JSON object on stdout; if multiple lines appeared
3498
- // (e.g., warnings on stderr leaked), take the last non-empty line.
3499
- const last = trimmed
3500
- .split("\n")
3501
- .map((l) => l.trim())
3502
- .filter(Boolean)
3503
- .pop();
3504
- if (!last)
3505
- return null;
3668
+ // Fast path: the CLI prints exactly one JSON object on stdout.
3506
3669
  try {
3507
- return JSON.parse(last);
3670
+ return JSON.parse(trimmed);
3508
3671
  }
3509
3672
  catch {
3673
+ // Fallback: if anything leaked onto stdout before/after the JSON, scan the
3674
+ // lines and return the last one that parses as JSON.
3675
+ const lines = trimmed
3676
+ .split("\n")
3677
+ .map((l) => l.trim())
3678
+ .filter(Boolean);
3679
+ for (let i = lines.length - 1; i >= 0; i--) {
3680
+ try {
3681
+ return JSON.parse(lines[i]);
3682
+ }
3683
+ catch {
3684
+ // keep scanning
3685
+ }
3686
+ }
3510
3687
  return null;
3511
3688
  }
3512
3689
  }
3690
+ // Coerce a JSON-ARRAY argument (points / settings / colors) into the single JSON-array string the
3691
+ // CLI expects. Agents sometimes send these PRE-STRINGIFIED (a JSON string instead of a real array);
3692
+ // a blind JSON.stringify would then double-encode it ("[...]" -> "\"[...]\"") and the CLI rejects it
3693
+ // with "must be a JSON array". So pass a string through as-is (the CLI parses + validates it) and
3694
+ // only stringify real arrays/values. NOTE: only for array args — a scalar `value` arg must NOT use
3695
+ // this (a plain string there is a literal value, not stringified JSON).
3696
+ function toJsonArrayArg(value) {
3697
+ return typeof value === "string" ? value : JSON.stringify(value ?? []);
3698
+ }
3699
+ /**
3700
+ * The `confirm` parameter shared by the destructive editor tools.
3701
+ *
3702
+ * Spelled out at length on purpose: a one-word "confirmation" flag reads to a model as a
3703
+ * formality to fill in, and the whole point is that it stands for a human's answer.
3704
+ */
3705
+ const CONFIRM_PARAM_DESCRIPTION = "Must be `true`, and only after the USER has explicitly agreed to this specific deletion. It stands for their consent, not for your own confidence \u2014 never set it to clear up something you merely believe is unused, and never re-run with it after a refusal without asking first. The merchant's content goes with the deletion and only the editor's undo stack can bring it back.";
3706
+ /** Reply for a destructive tool called without consent. The dev-server action refuses too. */
3707
+ function destructiveConfirmRefusal() {
3708
+ return {
3709
+ content: [
3710
+ {
3711
+ type: "text",
3712
+ text: JSON.stringify({
3713
+ success: false,
3714
+ error: "Refused: `confirm` was not true. This deletes the merchant's content and can only be undone from the editor's undo stack. Ask the user whether to proceed, and pass confirm: true only after they agree.",
3715
+ }, null, 2),
3716
+ },
3717
+ ],
3718
+ };
3719
+ }
3513
3720
  async function callEditorAction(projectRoot, args) {
3514
3721
  try {
3515
3722
  const { stdout, stderr, exitCode } = await runIkasComponentCli(projectRoot, args);
@@ -3544,7 +3751,7 @@ async function callEditorAction(projectRoot, args) {
3544
3751
  }
3545
3752
  //
3546
3753
  // Tool: list_editor_pages
3547
- server.tool("list_editor_pages", "List pages in the connected editor's project. Returns id, name, pageType, slug for each page. Requires `ikas-component dev` to be running with the editor connected. Use the returned `id`s as the `pageId` argument to `add_section_to_page`.", {
3754
+ server.tool("list_editor_pages", "List pages in the connected editor's project. Returns id, name, pageType, slug for each page. Requires `ikas theme dev` to be running with the editor connected. Use the returned `id`s as the `pageId` argument to `add_section_to_page`.", {
3548
3755
  project_root: z
3549
3756
  .string()
3550
3757
  .describe("Absolute path to the code-component project (where `node_modules/.bin/ikas-component` lives)."),
@@ -3557,7 +3764,7 @@ server.tool("list_editor_pages", "List pages in the connected editor's project.
3557
3764
  return callEditorAction(project_root, args);
3558
3765
  });
3559
3766
  // Tool: list_imported_sections
3560
- server.tool("list_imported_sections", "List section-type code components already imported into the editor's project (theme.codeComponents, filtered to type=section). Use to confirm a component is ready to be placed on a page. The component must be built (`ikas-component build`/`dev`) and imported (`import_section`) before it can be added to a page. The returned `id` is the editor's id for the imported component — normally identical to the id in `ikas.config.json`, but it can differ if the dev component was deleted and re-scaffolded after a previous import. Always use the `id` from this tool, not from `ikas.config.json`, when calling `add_section_to_page`.", {
3767
+ server.tool("list_imported_sections", "List section-type code components already imported into the editor's project (theme.codeComponents, filtered to type=section). Use to confirm a component is ready to be placed on a page. The component must be built (`ikas-component build`/`dev`) and imported (`import_section`) before it can be added to a page. The returned `id` is the editor's id for the imported component — normally identical to the id in `ikas.config.json`, but it can differ if the dev component was deleted and re-scaffolded after a previous import, or when the theme installed this project as a design asset (the editor then reports the published id). Always use the `id` from this tool, not from `ikas.config.json`, when calling `add_section_to_page`. A differing id is NEVER a reason to edit `ikas.config.json` — config ids are immutable.", {
3561
3768
  project_root: z
3562
3769
  .string()
3563
3770
  .describe("Absolute path to the code-component project."),
@@ -3595,13 +3802,13 @@ server.tool("import_section", "Import a built section-type code component into t
3595
3802
  return callEditorAction(project_root, args);
3596
3803
  });
3597
3804
  // Tool: add_section_to_page
3598
- server.tool("add_section_to_page", 'Place an already-imported section-type code component on a page in the editor. Equivalent to right-clicking the section in the dev-components panel and choosing "Add to Page". Errors if the component is not imported, is not section-type, or the page id is unknown. Use `list_editor_pages` to discover page ids and `list_imported_sections` to discover component ids. After placing, change the section\'s prop values with `update_section_prop` (use `list_page_sections` to get the placement\'s `elementId` and prop names).', {
3805
+ server.tool("add_section_to_page", "Place a SINGLE already-imported section-type code component on a page. Use this ONLY when adding exactly one section. If you are adding more than one section — or building/populating a page — call `add_sections_to_page` instead: it places them all AND fills their props in ONE call. Calling this tool repeatedly (one section per call) is the slow path and should be avoided. Equivalent to right-clicking the section in the dev-components panel and choosing \"Add to Page\". Errors if the component is not imported, is not section-type, or the page id is unknown. Use `list_editor_pages` to discover page ids and `list_imported_sections` to discover component ids. After placing, change the section's prop values with `update_section_prop` / `update_page_sections` (use `list_page_sections` to get the placement's `elementId` and prop names).", {
3599
3806
  project_root: z
3600
3807
  .string()
3601
3808
  .describe("Absolute path to the code-component project."),
3602
3809
  component_id: z
3603
3810
  .string()
3604
- .describe("Imported code component id from `list_imported_sections` — NOT the id in `ikas.config.json` (the two are usually the same but can diverge after a rescaffold)."),
3811
+ .describe("Imported code component id from `list_imported_sections` — NOT the id in `ikas.config.json` (the two are usually the same but can diverge after a rescaffold or on a theme that installed the project as a design asset; never edit the config to make them match)."),
3605
3812
  page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
3606
3813
  index: z
3607
3814
  .number()
@@ -3625,28 +3832,194 @@ server.tool("add_section_to_page", 'Place an already-imported section-type code
3625
3832
  ];
3626
3833
  return callEditorAction(project_root, args);
3627
3834
  });
3835
+ // Tool: add_sections_to_page
3836
+ server.tool("add_sections_to_page", "Place MANY sections on a page in a SINGLE call — and optionally set each section's prop values AT placement time, so you skip the separate fill step. The fastest way to build a page: one round-trip instead of one add (and one fill) per section. Pass `sections`, each `{ component_id, index?, updates?: [{ prop_name|prop_id, value }] }`; values use the same per-type shapes as update_section_prop / get_editor_workflow. Returns the new `elementId` for each placement (plus written prop results). Built-but-unimported section AND child code components are auto-imported. All update values are validated before anything is placed. Use `list_editor_pages` for page ids and `list_imported_sections` for component ids. Placing a COMMON (global) section — the theme's header/footer — is special: it has ONE shared set of prop values stored on the INDEX (Home) page's placement, so `updates` land there and change that section on every page (the result carries a `common` block), and placing it with `updates` on a non-INDEX page while the INDEX page does not have it is rejected — place and fill it on the INDEX page instead.", {
3837
+ project_root: z
3838
+ .string()
3839
+ .describe("Absolute path to the code-component project."),
3840
+ page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
3841
+ sections: z
3842
+ .array(z.object({
3843
+ component_id: z
3844
+ .string()
3845
+ .describe("Imported (or built) section-type code component id."),
3846
+ index: z
3847
+ .number()
3848
+ .int()
3849
+ .nonnegative()
3850
+ .optional()
3851
+ .describe("Zero-based insertion index; appends when omitted."),
3852
+ updates: z
3853
+ .array(z.object({
3854
+ prop_id: z
3855
+ .string()
3856
+ .optional()
3857
+ .describe("Blueprint prop id (provide this or prop_name)."),
3858
+ prop_name: z
3859
+ .string()
3860
+ .optional()
3861
+ .describe("Blueprint prop name (alternative to prop_id)."),
3862
+ value: z
3863
+ .any()
3864
+ .describe("Prop value, same shape update_section_prop expects for that type."),
3865
+ }))
3866
+ .optional()
3867
+ .describe("Optional prop values to set on this section right after placing it."),
3868
+ }))
3869
+ .describe("Non-empty array of sections to place (in order), each with its componentId and optional prop updates."),
3870
+ port: z
3871
+ .number()
3872
+ .optional()
3873
+ .describe("Dev server WebSocket port (default 5201)."),
3874
+ }, async ({ project_root, page_id, sections, port }) => {
3875
+ const normalized = (sections || []).map((s) => ({
3876
+ componentId: s.component_id,
3877
+ ...(typeof s.index === "number" ? { index: s.index } : {}),
3878
+ ...(s.updates
3879
+ ? {
3880
+ updates: s.updates.map((u) => ({
3881
+ ...(u.prop_id ? { propId: u.prop_id } : {}),
3882
+ ...(u.prop_name ? { propName: u.prop_name } : {}),
3883
+ value: u.value,
3884
+ })),
3885
+ }
3886
+ : {}),
3887
+ }));
3888
+ const args = [
3889
+ "add-sections-to-page",
3890
+ "--page-id",
3891
+ page_id,
3892
+ "--sections",
3893
+ JSON.stringify(normalized),
3894
+ ...(port ? ["--port", String(port)] : []),
3895
+ ];
3896
+ return callEditorAction(project_root, args);
3897
+ });
3628
3898
  // Tool: list_page_sections
3629
- server.tool("list_page_sections", "List the sections placed on a page. Each entry includes the per-placement `elementId` (the identity of THIS placement — there can be multiple placements of the same section), `sectionId`, `componentId`, `name`, the current `propValues`, and the blueprint `props` (each with `id`, `name`, `type`). Use the returned `elementId` plus a prop `id`/`name` with `update_section_prop` to change a prop value of that specific placement. Use `list_editor_pages` to discover page ids.", {
3899
+ server.tool("list_page_sections", "List the sections placed on a page — a LEAN ROSTER that never truncates: per-placement `elementId` (the identity of THIS placement — there can be multiple of the same section), `sectionId`, `componentId`, `name`, `propCount`, and `setPropNames` (which props already have a value). It deliberately omits the prop SCHEMA and the prop VALUES (both can be large — Header alone can have ~80 props). To get a section's prop schema (types, ENUM options, allowed children) call `get_component_props(componentId)`; to read its current values call `get_section_values(element_id)`. Use the returned `elementId` with `update_section_prop` / `update_page_sections`. Use `list_editor_pages` for page ids. COMMON (global) sections — the theme's header and footer — carry an extra `common` field (`isCommon`, `commonSectionType`, `canonicalPageId`/`canonicalElementId`, `valuesArePageSpecific: false`): their prop values are NOT page-specific, they are shared by every page and stored on the INDEX (Home) page's placement, so `setPropNames` for them reflects that one shared record and any write from any page changes the header/footer everywhere. A page customized per storefront-routing/specification holds a SEPARATE set of placements with its own section order in each state: this lists the BASE layer by default and reports the available states in `pageStates` (plus a `scope` field) — pass `sf_routing_id`/`specification_id` to list a state's own placements instead, which is what `move_page_section` needs when reordering that state.", {
3630
3900
  project_root: z
3631
3901
  .string()
3632
3902
  .describe("Absolute path to the code-component project."),
3633
3903
  page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
3904
+ sf_routing_id: z
3905
+ .string()
3906
+ .optional()
3907
+ .describe("List a routing-customized state of the page instead of the base layer. Ids come from the `pageStates` block this tool returns for a customized page."),
3908
+ specification_id: z
3909
+ .string()
3910
+ .optional()
3911
+ .describe("Specification of the customized state to list (used together with `sf_routing_id`)."),
3634
3912
  port: z
3635
3913
  .number()
3636
3914
  .optional()
3637
3915
  .describe("Dev server WebSocket port (default 5201)."),
3638
- }, async ({ project_root, page_id, port }) => {
3916
+ }, async ({ project_root, page_id, sf_routing_id, specification_id, port }) => {
3639
3917
  const args = [
3640
3918
  "list-page-sections",
3641
3919
  "--page-id",
3642
3920
  page_id,
3921
+ ...(sf_routing_id ? ["--sf-routing-id", sf_routing_id] : []),
3922
+ ...(specification_id ? ["--specification-id", specification_id] : []),
3923
+ ...(port ? ["--port", String(port)] : []),
3924
+ ];
3925
+ return callEditorAction(project_root, args);
3926
+ });
3927
+ // Tool: move_page_section
3928
+ server.tool("move_page_section", "Reorder a section that is ALREADY placed on a page — the only way to change section order, since the editor UI offers it solely as a drag in the layers tree. Target the placement by its `element_id` from `list_page_sections` (NOT the sectionId/componentId — a page can hold several placements of the same section and each moves independently). Give EITHER `direction` (\"up\"/\"down\", one position — use this for a simple nudge) OR `to_index` (absolute 0-based position), never both. Indices are 0-based and count ONLY placed sections, in exactly the order `list_page_sections` returns them, so you can read that list, pick a target position from it, and pass it straight back. The result returns `fromIndex`, `resultIndex` (where the section ACTUALLY ended up) and `sections` (the full resulting order) — assert on `resultIndex`/`sections` rather than assuming the move landed where you asked; if it lands somewhere other than requested a `note` says so. A reorder that does not take effect comes back as an ERROR, never as a success that changed nothing, so a successful result means the section really moved. Out-of-range indices are rejected with the valid range (and the section's current index) instead of being clamped. Passing a `sectionId`/`componentId` where an `element_id` belongs is detected and the error names the elementId you actually wanted. COMMON (global) sections — the theme's header and footer — are REJECTED: their position is fixed by the theme, so there is nothing to reorder. SCOPE: by default this reorders the page's BASE layer. A page customized per storefront-routing/specification keeps a SEPARATE set of placements and its own section order in each of those states — pass `sf_routing_id` (and `specification_id`) to reorder one of them instead, and read that state's current order with `list_page_sections` using the SAME ids. Whenever the page has any state the result carries `scope`, `pageStates` and `pageStatesNote`: do not report a reorder as verified on such a page without checking them, since reordering the base layer leaves every state exactly as it was. The state must ALREADY exist — creating one duplicates the whole page and is a deliberate editor action, so an unknown routing/specification is rejected with the list of existing states rather than created. To place a NEW section at a specific position use `add_sections_to_page` with its `index` instead; this tool only moves existing placements.", {
3929
+ project_root: z
3930
+ .string()
3931
+ .describe("Absolute path to the code-component project."),
3932
+ page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
3933
+ element_id: z
3934
+ .string()
3935
+ .describe("Placed-section elementId to move (from `list_page_sections`)."),
3936
+ direction: z
3937
+ .enum(["up", "down"])
3938
+ .optional()
3939
+ .describe("Move one position up or down. Provide this or `to_index`, not both."),
3940
+ to_index: z
3941
+ .number()
3942
+ .int()
3943
+ .min(0)
3944
+ .optional()
3945
+ .describe("Absolute 0-based target position among the page's placed sections. Provide this or `direction`, not both."),
3946
+ sf_routing_id: z
3947
+ .string()
3948
+ .optional()
3949
+ .describe("Reorder a routing-customized state of the page instead of the base layer. Ids come from the `pageStates` block returned by `list_page_sections`. The state must already exist."),
3950
+ specification_id: z
3951
+ .string()
3952
+ .optional()
3953
+ .describe("Specification of the customized state to reorder (used together with `sf_routing_id`)."),
3954
+ port: z
3955
+ .number()
3956
+ .optional()
3957
+ .describe("Dev server WebSocket port (default 5201)."),
3958
+ }, async ({ project_root, page_id, element_id, direction, to_index, sf_routing_id, specification_id, port, }) => {
3959
+ const args = [
3960
+ "move-page-section",
3961
+ "--page-id",
3962
+ page_id,
3963
+ "--element-id",
3964
+ element_id,
3965
+ ...(direction ? ["--direction", direction] : []),
3966
+ ...(to_index !== undefined ? ["--to-index", String(to_index)] : []),
3967
+ ...(sf_routing_id ? ["--sf-routing-id", sf_routing_id] : []),
3968
+ ...(specification_id ? ["--specification-id", specification_id] : []),
3969
+ ...(port ? ["--port", String(port)] : []),
3970
+ ];
3971
+ return callEditorAction(project_root, args);
3972
+ });
3973
+ // Tool: get_component_props
3974
+ server.tool("get_component_props", "Get prop blueprints straight from the editor (the source of truth) for one or MANY components in a single call — for any section OR child code component ids. Returns `{ components: [...] }`, each prop carrying its `id`, `name`, `type`, `required`, `default`, and crucially: a ready-to-use `writeExample` (the EXACT value shape to pass to update_section_prop / update_page_sections — e.g. PRODUCT_LIST, BLOG_LIST, COMPONENT_LIST, LINK) plus a `writeNote` for variants, so you do NOT have to guess or trial-write the JSON; for ENUM props the `options` (valid `value`s); and for COMPONENT/COMPONENT_LIST props the `allowedComponentIds` (which children the slot permits — when empty, an `allowedComponentsNote` says any imported code component is allowed). Use this (its `writeExample`/`options`/`allowedComponentIds`) instead of guessing or reading ikas.config.json. Pass ALL the section/child ids you need at once (batch). Child component ids come from a parent prop's `allowedComponentIds` (or get_section_template).", {
3975
+ project_root: z
3976
+ .string()
3977
+ .describe("Absolute path to the code-component project."),
3978
+ component_ids: z
3979
+ .array(z.string())
3980
+ .describe("Section/child code-component ids to resolve (batch). From list_imported_sections or a COMPONENT_LIST prop's allowedComponentIds."),
3981
+ port: z
3982
+ .number()
3983
+ .optional()
3984
+ .describe("Dev server WebSocket port (default 5201)."),
3985
+ }, async ({ project_root, component_ids, port }) => {
3986
+ const args = [
3987
+ "get-component-props",
3988
+ "--component-ids",
3989
+ (component_ids || []).join(","),
3990
+ ...(port ? ["--port", String(port)] : []),
3991
+ ];
3992
+ return callEditorAction(project_root, args);
3993
+ });
3994
+ // Tool: get_section_values
3995
+ server.tool("get_section_values", "Get the CURRENT prop values of one or MANY placed sections (each with its full `propValues` plus blueprint `props` — every prop carrying a `writeExample`/`writeNote` for the exact value shape, plus ENUM `options` and COMPONENT_LIST `allowedComponentIds`). `list_page_sections` is lean and omits values to avoid truncation; use this to read sections' values — needed for read-modify-write of a COMPONENT_LIST, or to inspect the exact stored shape of an existing value. Returns `{ sections: [...] }`. Pass all the elementIds you need at once (batch). COMMON (global) sections — the theme's header and footer — keep ONE shared set of prop values for the whole theme, stored on the INDEX (Home) page's placement; for those this tool reads the values FROM that canonical placement (a non-INDEX placement stores nothing of its own) and returns a `common` block naming `canonicalPageId`/`canonicalElementId`. So the values you get for a header/footer are the live ones the page actually renders no matter which page_id you ask from — do NOT read defaults as \"empty\" and blind-fill them, and remember any write goes to that same shared record and changes all pages. A prop bound to a theme GLOBAL variable stores no value in `propValues` — it is listed in the section's `bindings` map instead (`{ \"<propName>\": { boundGlobal: \"_<id>\", displayName, type } }`); treat such a prop as SET, not empty, and do not overwrite it with a static value unless asked (a static write removes the binding).", {
3996
+ project_root: z
3997
+ .string()
3998
+ .describe("Absolute path to the code-component project."),
3999
+ page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
4000
+ element_ids: z
4001
+ .array(z.string())
4002
+ .describe("Placed-section elementIds to read (batch). From `list_page_sections`."),
4003
+ port: z
4004
+ .number()
4005
+ .optional()
4006
+ .describe("Dev server WebSocket port (default 5201)."),
4007
+ }, async ({ project_root, page_id, element_ids, port }) => {
4008
+ const args = [
4009
+ "get-section-values",
4010
+ "--page-id",
4011
+ page_id,
4012
+ "--element-ids",
4013
+ (element_ids || []).join(","),
3643
4014
  ...(port ? ["--port", String(port)] : []),
3644
4015
  ];
3645
4016
  return callEditorAction(project_root, args);
3646
4017
  });
3647
4018
  // Tool: update_section_prop
3648
- server.tool("update_section_prop", 'Change a single prop value of a section placed on a page. This is the tool for FILLING/SETTING content (heading, text, image, link, etc.) on an existing section — it is pure data entry: it writes NO component code and needs NO rebuild. Do not author a new prop or component to set a value the section already supports; first check the section\'s existing `props` via `list_page_sections`. Target the specific placement by its `element_id` (from `list_page_sections`) and the prop by `prop_id` or `prop_name` (also from `list_page_sections`). `value` is the prop value object as stored by the editor — for scalar props it is wrapped as `{ "value": <scalar> }` (e.g. `{ "value": "Hello" }` for TEXT, `{ "value": true }` for BOOLEAN, `{ "value": 12 }` for NUMBER, `{ "value": "#FF0000" }` for COLOR, `{ "value": "<enum-key>" }` for ENUM). Richer object prop types use their own object shape and are NOT `{ "value": ... }`-wrapped: IMAGE/VIDEO/SVG = `{ "id": "<asset-id>", "altText"?: "<alt>", "isVideo"?: false }` (the `id` MUST reference an already-uploaded asset — call `upload_image` with a `file_path`/`image_url` to get one, or reuse an existing `id` from another section\'s `propValues`); LINK = a single link object `{ "id": "<unique-short-id>", "linkType": "PAGE"|"EXTERNAL"|"FILE", "label": "...", "openInNewTab"?: false, "subLinks": [] }` plus the target for its type — for PAGE add `"pageId"` AND `"pageType"` (both from `list_editor_pages`, e.g. pageType "INDEX"; for dynamic page types like PRODUCT/CATEGORY/BLOG also add the target `"itemId"`), for EXTERNAL add `"externalLink": "https://..."`. Examples: PAGE → `{ "id": "k3p9x", "linkType": "PAGE", "label": "Home", "pageId": "<page-id>", "pageType": "INDEX", "openInNewTab": false, "subLinks": [] }`; EXTERNAL → `{ "id": "m7q2z", "linkType": "EXTERNAL", "label": "Docs", "externalLink": "https://example.com", "openInNewTab": true, "subLinks": [] }`. LIST_OF_LINK = `{ "links": [ <link>, ... ] }` (each item is a link object as above). PRODUCT = `{ "productId": "...", "variantId"?: "..." }`. This SAME unwrapped shape applies whether the prop sits at section level OR nested inside a COMPONENT_LIST entry\'s `propValues` — there is no section-vs-nested difference. IMPORTANT: pass `value` as the parsed JSON object/array itself, NEVER as a JSON string (a stringified value is double-encoded and stored as a useless string). Values are validated server-side: a wrong shape (e.g. `{ "value": [...] }` for a COMPONENT_LIST, a `{ "value": ... }`-wrapped IMAGE, `componentId`+`props` instead of `codeComponentId`+`propValues`, or a missing entry `id`) is now REJECTED with an explanatory error instead of being silently stored. For any prop type you are unsure about, inspect the existing entry in `list_page_sections` `propValues` and match its exact shape. The change is applied with undo support.\n\n' +
3649
- 'COMPONENT_LIST / COMPONENT props: the value is NOT wrapped in `{ "value": ... }`. A COMPONENT_LIST value is `{ "components": [ <entry>, ... ] }`; a single COMPONENT value is one `<entry>`. Each entry = `{ "id": "<unique-id>", "codeComponentId": "<child-id>" | "componentId": "<child-id>", "propValues": { "<childPropName>": <wrapped-value>, ... } }`. Rules: (1) `id` is a unique short alphanumeric string identifying THIS entry — generate a fresh one per new entry and NEVER reuse an existing entry\'s id. (2) Use `codeComponentId` for code components, `componentId` for built-in theme components. (3) `propValues` is keyed by the CHILD component\'s prop NAMES, each using the same scalar wrappers as above (nesting is recursive — a child may itself hold a COMPONENT_LIST). (4) `update_section_prop` REPLACES the whole prop value — there is NO partial/deep merge. ALWAYS send the COMPLETE, fully-nested value for the prop: every existing entry (with its id), every nested `propValues`, and every nested COMPONENT_LIST at every depth. To change anything (even one deeply-nested scalar, or to add/remove/reorder a child), READ-MODIFY-WRITE: take the current `{ "components": [...] }` from `list_page_sections`, edit it in place (preserving all other entries, ids, and nested structures), then send the ENTIRE updated object back. Sending only the changed part — a single entry, or a child without its siblings — wipes everything you omitted. (5) You can only add child component types the prop permits; the allowed set is the blueprint prop\'s `filteredComponentIds`, which for container sections (Header, Footer, ProductDetail, …) is wired at build/config time per the `get_section_template` setup recipe (`config update-prop`), not here.\n\n' +
4019
+ server.tool("update_section_prop", 'Change a single prop value of a section placed on a page. This is the tool for FILLING/SETTING content (heading, text, image, link, etc.) on an existing section — it is pure data entry: it writes NO component code and needs NO rebuild. Do not author a new prop or component to set a value the section already supports; first check the section\'s existing `props` via `list_page_sections`. Target the specific placement by its `element_id` (from `list_page_sections`) and the prop by `prop_id` or `prop_name` (also from `list_page_sections`). `value` is the prop value object as stored by the editor — for scalar props it is wrapped as `{ "value": <scalar> }` (e.g. `{ "value": "Hello" }` for TEXT, `{ "value": true }` for BOOLEAN, `{ "value": 12 }` for NUMBER, `{ "value": "#FF0000" }` for COLOR, `{ "value": "<enum-key>" }` for ENUM). A COLOR prop can ALSO bind to a global theme color instead of a literal hex — pass `{ "patternValueId": "<id>" }` (the color id from `list_theme_globals` → `colors[].id`) and the prop tracks that global color live (resolved to `var(--<id>)` at render); the id is validated and an unknown one is REJECTED. Richer object prop types use their own object shape and are NOT `{ "value": ... }`-wrapped (full catalog in `get_editor_workflow`): IMAGE = `{ "id": "<asset-id>", "altText"?: "<alt>", "isVideo"?: false }` (the `id` MUST reference an already-uploaded asset — call `upload_image` with a `file_path`/`image_url` to get one, or reuse an existing `id` from another section\'s `propValues`); IMAGE_LIST = `{ "images": [ <image>, ... ] }`; VIDEO = `{ "video": { "id": "<asset-id>" }, "thumbnailImage"?: { "id": "..." }, "autoplay"?: false, "controls"?: true, "loop"?: false, "muted"?: false }` (NOT a bare `{ "id": ... }`); SVG = `{ "value": "<svg markup>" }` (value-wrapped, like a scalar); SVG_LIST = `{ "svgs": [ "<svg>", ... ] }`; TYPE (style props such as BorderRadiusStyleType/PaddingStyleType/GapStyleType) = the type-shaped object ITSELF, e.g. `{ "value": 8, "unit": "px" }` — get the exact field structure from the prop\'s `writeExample`/`typeName` in `get_component_props` or `get_type_definition("<typeName>")`; unknown fields, wrong field types, and invalid union values (e.g. `"unit": "banana"`) are REJECTED; entity props PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY/RAFFLE = `{ "<entity>Id": "...", "usePageData"?: false }` (e.g. `{ "categoryId": "..." }`) — get real ids from `search_products` (PRODUCT), `list_categories`, `list_brands`, `list_blogs`, `list_blog_categories`; PRODUCT_ATTRIBUTE = `{ "productId": "...", "variantId": "...", "attributeId": "..." }` — `variantId` is REQUIRED alongside `productId` (without it the value resolves with `product: null` and the component renders nothing), or bind to the page product with `{ "attributeId": "...", "usePageData": true }` on a product detail page; PRODUCT_ATTRIBUTE_LIST = the same with `"attributeIds": [ "..." ]`, and note the component receives a SINGLE wrapper object, never an array (read both with `getAttributeDetailValues()` / `getAttributeListValues()` — see `get_framework_guide("prop-types")`); list/collection props are typed objects keyed by a `<entity>ListType` discriminator: PRODUCT_LIST = `{ "id": "<unique>", "productListType": "STATIC", "productIds": [ { "productId": "...", "variantId": "..." } ], "initialLimit"?: 12 }` — note productIds is an array of {productId, variantId} PAIRS (from search_products), not bare ids; productListType ∈ ALL|STATIC|DISCOUNTED|RECOMMENDED|CATEGORY|SEARCH|LAST_VIEWED|RELATED_PRODUCTS|VIEWED_TOGETHER|PURCHASED_TOGETHER, and for a dynamic type use e.g. `{ "id": "<unique>", "productListType": "CATEGORY", "category": "<id from list_categories>" }` (the field is `category`, NOT `categoryId` — `categoryId` is only the standalone CATEGORY entity prop; no productIds here) or `"ALL"` (no ids). Unknown sub-fields inside a PRODUCT_LIST (e.g. `categoryId`) are REJECTED, not silently stored. CATEGORY_LIST = `{ "categoryListType": "STATIC", "categoryIds": ["..."] }` or `{ "categoryListType": "ALL" }`. BRAND_LIST = `{ "brandListType": "STATIC", "brandIds": ["..."] }` or ALL. BLOG_LIST = `{ "blogListType": "STATIC", "blogIds": ["..."] }`, `{ "blogListType": "CATEGORY", "categoryId": "..." }`, or ALL. BLOG_CATEGORY_LIST = `{ "blogCategoryListType": "STATIC", "blogCategoryIds": ["..."] }` or ALL. (Get the entity ids from search_products / list_*; you can also read an existing value with `get_section_values` to copy its exact shape.) LINK = a single link object `{ "id": "<unique-short-id>", "linkType": "PAGE"|"EXTERNAL"|"FILE", "label": "...", "openInNewTab"?: false, "subLinks": [] }` plus the target for its type — for PAGE add `"pageId"` AND `"pageType"` (both from `list_editor_pages`, e.g. pageType "INDEX"; for dynamic page types like PRODUCT/CATEGORY/BLOG also add the target `"itemId"`), for EXTERNAL add `"externalLink": "https://..."`. Examples: PAGE → `{ "id": "k3p9x", "linkType": "PAGE", "label": "Home", "pageId": "<page-id>", "pageType": "INDEX", "openInNewTab": false, "subLinks": [] }`; EXTERNAL → `{ "id": "m7q2z", "linkType": "EXTERNAL", "label": "Docs", "externalLink": "https://example.com", "openInNewTab": true, "subLinks": [] }`. To link to an ENTITY (category/brand/blog/blog-category) do NOT guess a slug — get the entity id from `list_categories`/`list_brands`/`list_blogs`/`list_blog_categories` and the page id from `get_page_by_type("<TYPE>")`, then build `{ "id": "<unique>", "linkType": "PAGE", "label": "...", "pageId": <pageId>, "pageType": "<TYPE>", "itemId": <entityId>, "subLinks": [] }`. LIST_OF_LINK = `{ "links": [ <link>, ... ] }` (each item is a link object as above). PRODUCT = `{ "productId": "...", "variantId"?: "..." }`. This SAME unwrapped shape applies whether the prop sits at section level OR nested inside a COMPONENT_LIST entry\'s `propValues` — there is no section-vs-nested difference. IMPORTANT: pass `value` as the parsed JSON object/array itself, NEVER as a JSON string (a stringified value is double-encoded and stored as a useless string). Values are validated server-side (deeply, including nested COMPONENT_LIST children): wrong shapes AND wrong semantics are REJECTED with an explanatory error instead of being silently stored. This includes: a `{ "value": [...] }` wrapper for a COMPONENT_LIST; a `{ "value": ... }`-wrapped IMAGE; `props` instead of `propValues`; a missing/duplicate entry `id`; a child referenced by the wrong key (a code component MUST use `codeComponentId`, a theme component `componentId`) or by an id that does not exist (child ids are opaque — take them from `get_section_template` / `list_imported_sections`, never invent them); and any `propValues` key that is not a real prop of that child component (the error lists the valid prop names). Auto-import: a referenced child code component that has been BUILT but not yet imported into the theme is imported automatically before the value is set (the response lists any such ids under `autoImported`); only children that are not built at all fail with a "no imported code component" error — build them first (`ikas-component build`/`dev`). For any prop type you are unsure about, inspect the existing value with `get_section_values` and match its exact shape. The change is applied with undo support.\n\n' +
4020
+ "COMMON (global) sections — the theme's HEADER and FOOTER: these render on every page that carries a placement of them (ikas ready-made account/membership pages are born without one) and have ONE shared set of prop values, stored on the INDEX (Home) page's placement. Whichever page_id you write from, the value lands on that single record and changes the header/footer on ALL pages; the response carries a `common` block (`commonSectionType`, `canonicalPageId`, `canonicalElementId`) saying so, and the echoed `value` is read back from that canonical placement. Therefore: ALWAYS `get_section_values` first and change only the prop the user asked about — the props are already filled with the merchant's content even when you are on a page you have not inspected, so blind-filling \"empty-looking\" props overwrites the live header/footer everywhere. If the INDEX page has no placement of the section, there is no record to write to and the call fails telling you to add it to the INDEX page first.\n\n" +
4021
+ "BIND TO A GLOBAL VARIABLE (Theme Setting): instead of a static `value`, pass `bind_global` = the global's `name` (its `variableName`, the `_<id>` form) from `list_theme_globals`. The prop becomes a LIVE dynamic value that always reflects that global's current value — editing the global in Theme Settings updates every bound prop. Use this to wire content to a project-wide setting (e.g. a shared announcement text, brand color, or logo image) rather than duplicating a literal. Pick a global whose type matches the prop (TEXT↔TEXT/RICH_TEXT, NUMBER↔NUMBER, BOOLEAN↔BOOLEAN, IMAGE↔IMAGE, COLOR↔COLOR, ENUM↔ENUM of the SAME enum type — the prop's `enumTypeId` must equal the setting's `enumTypeId`; a mismatch is REJECTED, …). Provide `value` OR `bind_global`, not both. Writing a static `value` to a prop that is bound to a global (see `bindings` in `get_section_values`) REPLACES the binding — the prop stops following the global, and the result carries `unboundGlobal` + a `warning`. To change what a bound prop shows, update the global (`update_theme_global`) instead. To bind a prop of a COMPONENT_LIST CHILD, also pass `list_path` (the `{ propId, index }` steps down to the child) and set `prop_id` to the child's prop id. Works for every section type, including built-in / code-component sections that have no blueprint.\n\n" +
4022
+ 'COMPONENT_LIST / COMPONENT props: the value is NOT wrapped in `{ "value": ... }`. A COMPONENT_LIST value is `{ "components": [ <entry>, ... ] }`; a single COMPONENT value is one `<entry>`. Each entry = `{ "id": "<unique-id>", "codeComponentId": "<child-id>" | "componentId": "<child-id>", "propValues": { "<childPropName>": <wrapped-value>, ... } }`. Rules: (1) `id` is a unique short alphanumeric string identifying THIS entry — generate a fresh one per new entry and NEVER reuse an existing entry\'s id. (2) Use `codeComponentId` for code components, `componentId` for built-in theme components. (3) `propValues` is keyed by the CHILD component\'s prop NAMES, each using the same scalar wrappers as above (nesting is recursive — a child may itself hold a COMPONENT_LIST). (4) `update_section_prop` REPLACES the whole prop value — there is NO partial/deep merge. ALWAYS send the COMPLETE, fully-nested value for the prop: every existing entry (with its id), every nested `propValues`, and every nested COMPONENT_LIST at every depth. To change anything (even one deeply-nested scalar, or to add/remove/reorder a child), READ-MODIFY-WRITE: take the current `{ "components": [...] }` from `get_section_values`, edit it in place (preserving all other entries, ids, and nested structures), then send the ENTIRE updated object back. Sending only the changed part — a single entry, or a child without its siblings — wipes everything you omitted. (5) You can only add child component types the prop permits — call `get_component_props(parentComponentId)` to read the COMPONENT_LIST prop\'s `allowedComponentIds`, then `get_component_props(childId)` to learn that child\'s props (names, types, ENUM `options`/valid values) instead of guessing or reading ikas.config.json. The allowed set is wired at build/config time per the `get_section_template` setup recipe (`config update-prop`), not here.\n\n' +
3650
4023
  'Example — a full COMPONENT_LIST `value` with two children, where the second child itself nests another COMPONENT_LIST (note: scalar leaves are `{ "value": ... }`-wrapped, COMPONENT_LIST values are `{ "components": [...] }` and are NOT wrapped, every entry has a unique `id`, and this is the COMPLETE value you would send even to change just one field): ' +
3651
4024
  `{ "components": [ { "id": "a1b2c", "codeComponentId": "7ojrigep-Eml9n5sN3i", "propValues": { "heading": { "value": "Featured" }, "visible": { "value": true } } }, { "id": "d3e4f", "codeComponentId": "x2plk9zq-Qw8rt", "propValues": { "title": { "value": "Sub group" }, "cards": { "components": [ { "id": "g5h6i", "codeComponentId": "card01ab-Zz12", "propValues": { "label": { "value": "Card 1" } } }, { "id": "j7k8l", "codeComponentId": "card01ab-Zz12", "propValues": { "label": { "value": "Card 2" } } } ] } } } ] }`, {
3652
4025
  project_root: z
@@ -3666,12 +4039,21 @@ server.tool("update_section_prop", 'Change a single prop value of a section plac
3666
4039
  .describe("Blueprint prop name to update (alternative to `prop_id`)."),
3667
4040
  value: z
3668
4041
  .any()
3669
- .describe('The prop value object to store, e.g. `{ "value": "Hello" }`. Match the shape of the existing entry in `list_page_sections` propValues for non-scalar prop types.'),
4042
+ .optional()
4043
+ .describe('The prop value object to store, e.g. `{ "value": "Hello" }`. Match the shape of the existing value from `get_section_values` for non-scalar prop types. Omit when using `bind_global`.'),
4044
+ bind_global: z
4045
+ .string()
4046
+ .optional()
4047
+ .describe("Bind this prop to a project GLOBAL variable (Theme Setting) as a LIVE dynamic value instead of writing a static `value` — the prop then always reflects that global's current value (edited in Theme Settings). Pass the global's `name` (its `variableName`, the `_<id>` form) from `list_theme_globals`. Provide `value` OR `bind_global`, not both. Writing a static `value` to a prop that is bound to a global (see `bindings` in `get_section_values`) REPLACES the binding — the prop stops following the global, and the result carries `unboundGlobal` + a `warning`. To change what a bound prop shows, update the global (`update_theme_global`) instead. Bindable globals include TEXT / RICH_TEXT / NUMBER / BOOLEAN / IMAGE / COLOR / BORDER / SHADOW / ENUM settings; pick a global whose type matches the prop (an ENUM prop only binds an ENUM setting of the same enum type). (This is the general theme-global binding; a COLOR prop can alternatively take an inline `{ \"patternValueId\" }` for theme colors.)"),
4048
+ list_path: z
4049
+ .array(z.object({ propId: z.string(), index: z.number() }))
4050
+ .optional()
4051
+ .describe("Only with `bind_global`: bind a prop of a COMPONENT_LIST child instead of a section-level prop. An array of `{ propId, index }` steps from the section down to the target child; `prop_id` is then the CHILD's prop id (from `get_component_props`)."),
3670
4052
  port: z
3671
4053
  .number()
3672
4054
  .optional()
3673
4055
  .describe("Dev server WebSocket port (default 5201)."),
3674
- }, async ({ project_root, page_id, element_id, prop_id, prop_name, value, port }) => {
4056
+ }, async ({ project_root, page_id, element_id, prop_id, prop_name, value, bind_global, list_path, port, }) => {
3675
4057
  const args = [
3676
4058
  "update-section-prop",
3677
4059
  "--page-id",
@@ -3680,17 +4062,25 @@ server.tool("update_section_prop", 'Change a single prop value of a section plac
3680
4062
  element_id,
3681
4063
  ...(prop_id ? ["--prop-id", prop_id] : []),
3682
4064
  ...(prop_name ? ["--prop-name", prop_name] : []),
3683
- "--value",
3684
- // The CLI JSON.parses --value. If `value` is already a JSON string, pass
3685
- // it through verbatim — re-stringifying it would double-encode it and the
3686
- // editor would store a string instead of the object/array.
3687
- typeof value === "string" ? value : JSON.stringify(value),
4065
+ ...(bind_global
4066
+ ? [
4067
+ "--bind-global",
4068
+ bind_global,
4069
+ ...(list_path ? ["--list-path", JSON.stringify(list_path)] : []),
4070
+ ]
4071
+ : [
4072
+ "--value",
4073
+ // The CLI JSON.parses --value. If `value` is already a JSON string, pass
4074
+ // it through verbatim — re-stringifying it would double-encode it and the
4075
+ // editor would store a string instead of the object/array.
4076
+ typeof value === "string" ? value : JSON.stringify(value),
4077
+ ]),
3688
4078
  ...(port ? ["--port", String(port)] : []),
3689
4079
  ];
3690
4080
  return callEditorAction(project_root, args);
3691
4081
  });
3692
4082
  // Tool: upload_image
3693
- server.tool("upload_image", "Upload an image to the connected editor's project and get back its image `id`. Provide the image via `file_path` (a local path) OR `image_url`. Use the returned `id` as the `id` of an IMAGE prop value passed to `update_section_prop` (e.g. `{ \"id\": \"<returned-id>\", \"altText\": \"...\", \"isVideo\": false }`). This is the way to set an image prop — `update_section_prop` does not upload, it only references an existing image id. Supported types: png, jpg, jpeg, webp, gif; max 10MB. Requires the editor to be embedded in the ikas admin panel (the admin panel performs the actual upload; a standalone editor cannot upload and will error/time out).", {
4083
+ server.tool("upload_image", 'Upload an image to the connected editor\'s project and get back its image `id`. Provide the image via `file_path` (a local path) OR `image_url`. This is the ONLY way to obtain a real image id — an id cannot be invented. Use the returned `id`: (1) as an IMAGE prop value for `update_section_prop` (e.g. `{ "id": "<returned-id>", "altText": "...", "isVideo": false }`), or (2) as an IMAGE theme global\'s value for `create_theme_global`/`update_theme_global` (e.g. `{ "id": "<returned-id>" }`). An id cannot be invented — an unreal one is stored as given and renders as a broken image, so always use a `upload_image` id or one already listed by `list_theme_globals`. Neither tool uploads; both only reference an existing image id. Supported types: png, jpg, jpeg, webp, gif; max 10MB. Requires the editor to be embedded in the ikas admin panel (the admin panel performs the actual upload; a standalone editor cannot upload and will error/time out).', {
3694
4084
  project_root: z
3695
4085
  .string()
3696
4086
  .describe("Absolute path to the code-component project."),
@@ -3702,7 +4092,10 @@ server.tool("upload_image", "Upload an image to the connected editor's project a
3702
4092
  .string()
3703
4093
  .optional()
3704
4094
  .describe("Image URL to fetch and upload (alternative to `file_path`)."),
3705
- alt_text: z.string().optional().describe("Alt text to store with the image."),
4095
+ alt_text: z
4096
+ .string()
4097
+ .optional()
4098
+ .describe("Alt text to store with the image."),
3706
4099
  port: z
3707
4100
  .number()
3708
4101
  .optional()
@@ -3717,6 +4110,1185 @@ server.tool("upload_image", "Upload an image to the connected editor's project a
3717
4110
  ];
3718
4111
  return callEditorAction(project_root, args);
3719
4112
  });
4113
+ // Tool: update_page_sections
4114
+ server.tool("update_page_sections", "Fill MANY placed sections of a page in a SINGLE call — the fastest way to populate a whole page (one round-trip for the entire page instead of one call per section/prop). Takes `sections`, each `{ element_id, updates: [{ prop_name|prop_id, value }] }`; values use the same per-type shapes as update_section_prop / get_editor_workflow. All-or-nothing across the whole page: every value is resolved and deeply validated (and built-but-unimported child code components auto-imported) before anything is written — one invalid value rejects the entire page update. An update item may instead bind a prop to a project GLOBAL variable (Theme Setting) as a live dynamic value: use `{ prop_id|prop_name, bind_global }` where `bind_global` is the global's `name` (its `variableName`) from `list_theme_globals` — omit `value`. Add `list_path` (an array of `{ propId, index }` steps) to bind a prop of a COMPONENT_LIST child (then `prop_id` is the child's prop id). Static value writes are applied first, then bindings. Prefer this over many update_section_prop(s) calls. If any targeted section is a COMMON (global) one — the theme's header/footer — its values are shared by every page and stored on the INDEX (Home) page's placement: the write goes there and changes that section on ALL pages, the result's `common` block says so, and the echoed values are read back from that canonical placement. Read those sections with `get_section_values` first and only change what was asked; a header/footer missing from the INDEX page has no record to write to and rejects the whole call.", {
4115
+ project_root: z
4116
+ .string()
4117
+ .describe("Absolute path to the code-component project."),
4118
+ page_id: z.string().describe("Target page id (from list_editor_pages)."),
4119
+ sections: z
4120
+ .array(z.object({
4121
+ element_id: z
4122
+ .string()
4123
+ .describe("Placed-section elementId (from list_page_sections)."),
4124
+ updates: z
4125
+ .array(z.object({
4126
+ prop_id: z
4127
+ .string()
4128
+ .optional()
4129
+ .describe("Blueprint prop id (provide this or prop_name)."),
4130
+ prop_name: z
4131
+ .string()
4132
+ .optional()
4133
+ .describe("Blueprint prop name (alternative to prop_id)."),
4134
+ value: z
4135
+ .any()
4136
+ .optional()
4137
+ .describe("Prop value, same shape update_section_prop expects for that type. Omit when using bind_global."),
4138
+ bind_global: z
4139
+ .string()
4140
+ .optional()
4141
+ .describe("Bind this prop to a project GLOBAL variable (Theme Setting) as a live dynamic value instead of a static value. The global's `name` (variableName) from list_theme_globals. Provide value OR bind_global."),
4142
+ list_path: z
4143
+ .array(z.object({ propId: z.string(), index: z.number() }))
4144
+ .optional()
4145
+ .describe("Only with bind_global: `{ propId, index }` steps down to a COMPONENT_LIST child; prop_id is then the child's prop id."),
4146
+ }))
4147
+ .describe("Non-empty array of prop updates for this section."),
4148
+ }))
4149
+ .describe("Non-empty array of sections to fill, each with its elementId and prop updates."),
4150
+ port: z
4151
+ .number()
4152
+ .optional()
4153
+ .describe("Dev server WebSocket port (default 5201)."),
4154
+ }, async ({ project_root, page_id, sections, port }) => {
4155
+ const normalized = (sections || []).map((s) => ({
4156
+ elementId: s.element_id,
4157
+ updates: (s.updates || []).map((u) => ({
4158
+ ...(u.prop_id ? { propId: u.prop_id } : {}),
4159
+ ...(u.prop_name ? { propName: u.prop_name } : {}),
4160
+ ...(u.bind_global
4161
+ ? {
4162
+ bindGlobal: u.bind_global,
4163
+ ...(u.list_path ? { listPath: u.list_path } : {}),
4164
+ }
4165
+ : { value: u.value }),
4166
+ })),
4167
+ }));
4168
+ const args = [
4169
+ "update-page-sections",
4170
+ "--page-id",
4171
+ page_id,
4172
+ "--sections",
4173
+ JSON.stringify(normalized),
4174
+ ...(port ? ["--port", String(port)] : []),
4175
+ ];
4176
+ return callEditorAction(project_root, args);
4177
+ });
4178
+ // Tool: upload_images
4179
+ server.tool("upload_images", "Upload MANY images in one call (batch upload_image) and get their ids back in order — the host uploads them all in a single round-trip. Pass `images`, each `{ file_path?, image_url?, alt_text? }`. Returns an array of { id, fileName, altText, isVideo } in the same order; use each id in an IMAGE prop value. Prefer this over multiple upload_image calls when a section/page needs several images. Supported: png/jpg/jpeg/webp/gif, max 10MB each. Requires the editor embedded in the ikas admin panel.", {
4180
+ project_root: z
4181
+ .string()
4182
+ .describe("Absolute path to the code-component project."),
4183
+ images: z
4184
+ .array(z.object({
4185
+ file_path: z
4186
+ .string()
4187
+ .optional()
4188
+ .describe("Local image file path (provide this or image_url)."),
4189
+ image_url: z
4190
+ .string()
4191
+ .optional()
4192
+ .describe("Image URL to fetch (alternative to file_path)."),
4193
+ alt_text: z.string().optional().describe("Alt text for this image."),
4194
+ }))
4195
+ .describe("Non-empty array of images to upload."),
4196
+ port: z
4197
+ .number()
4198
+ .optional()
4199
+ .describe("Dev server WebSocket port (default 5201)."),
4200
+ }, async ({ project_root, images, port }) => {
4201
+ const manifest = (images || []).map((im) => ({
4202
+ ...(im.file_path ? { file: im.file_path } : {}),
4203
+ ...(im.image_url ? { url: im.image_url } : {}),
4204
+ ...(im.alt_text ? { alt: im.alt_text } : {}),
4205
+ }));
4206
+ const args = [
4207
+ "upload-images",
4208
+ "--manifest",
4209
+ JSON.stringify(manifest),
4210
+ ...(port ? ["--port", String(port)] : []),
4211
+ ];
4212
+ return callEditorAction(project_root, args);
4213
+ });
4214
+ // Tool: search_products
4215
+ server.tool("search_products", 'Search the connected store\'s products to obtain a real productId (and first variantId) for a PRODUCT prop value. Returns products with productId, variantId, name, slug, variantCount, and `imageSrc` (the full-resolution CDN URL of the product\'s main image). To use that product image in an IMAGE prop, you CANNOT reuse a product image id directly (it is not a theme asset) — pass the `imageSrc` URL to `upload_image(image_url: <imageSrc>)` (or `upload_images`), then use the returned id in the IMAGE value. This gives real product imagery instead of external/placeholder URLs. Use the result in update_section_prop as `{ "productId": "<productId>", "variantId": "<variantId>" }`. Pass `query` for free-text search, or `product_ids` to resolve specific ids. Requires the editor embedded in the ikas admin panel (the admin panel runs the search; a standalone editor cannot).', {
4216
+ project_root: z
4217
+ .string()
4218
+ .describe("Absolute path to the code-component project."),
4219
+ query: z
4220
+ .string()
4221
+ .optional()
4222
+ .describe("Free-text product search (name, sku, barcode)."),
4223
+ product_ids: z
4224
+ .array(z.string())
4225
+ .optional()
4226
+ .describe("Specific product ids to resolve directly (alternative to `query`)."),
4227
+ per_page: z.number().optional().describe("Results per page."),
4228
+ port: z
4229
+ .number()
4230
+ .optional()
4231
+ .describe("Dev server WebSocket port (default 5201)."),
4232
+ }, async ({ project_root, query, product_ids, per_page, port }) => {
4233
+ const args = [
4234
+ "search-products",
4235
+ ...(query ? ["--query", query] : []),
4236
+ ...(product_ids && product_ids.length
4237
+ ? ["--ids", product_ids.join(",")]
4238
+ : []),
4239
+ ...(typeof per_page === "number" ? ["--per-page", String(per_page)] : []),
4240
+ ...(port ? ["--port", String(port)] : []),
4241
+ ];
4242
+ return callEditorAction(project_root, args);
4243
+ });
4244
+ // Tool: list_categories
4245
+ server.tool("list_categories", 'List the store\'s product categories and their ids, to fill a CATEGORY prop value `{ "categoryId": "<id>" }`. Returns categoryId, name, slug, parentId for each. Returns all categories (no query). To link to a category from a LINK prop, also call `get_page_by_type("CATEGORY")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "CATEGORY", "itemId": <categoryId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
4246
+ project_root: z
4247
+ .string()
4248
+ .describe("Absolute path to the code-component project."),
4249
+ port: z
4250
+ .number()
4251
+ .optional()
4252
+ .describe("Dev server WebSocket port (default 5201)."),
4253
+ }, async ({ project_root, port }) => {
4254
+ const args = [
4255
+ "list-entities",
4256
+ "--kind",
4257
+ "category",
4258
+ ...(port ? ["--port", String(port)] : []),
4259
+ ];
4260
+ return callEditorAction(project_root, args);
4261
+ });
4262
+ // Tool: list_brands
4263
+ server.tool("list_brands", 'List the store\'s product brands and their ids, to fill a BRAND prop value `{ "brandId": "<id>" }`. Returns brandId, name, slug for each. Returns all brands (no query). To link to a brand from a LINK prop, also call `get_page_by_type("BRAND")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BRAND", "itemId": <brandId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
4264
+ project_root: z
4265
+ .string()
4266
+ .describe("Absolute path to the code-component project."),
4267
+ port: z
4268
+ .number()
4269
+ .optional()
4270
+ .describe("Dev server WebSocket port (default 5201)."),
4271
+ }, async ({ project_root, port }) => {
4272
+ const args = [
4273
+ "list-entities",
4274
+ "--kind",
4275
+ "brand",
4276
+ ...(port ? ["--port", String(port)] : []),
4277
+ ];
4278
+ return callEditorAction(project_root, args);
4279
+ });
4280
+ // Tool: list_blogs
4281
+ server.tool("list_blogs", 'List the store\'s blogs and their ids, to fill a BLOG prop value `{ "blogId": "<id>" }`. Returns blogId, name, slug for each. Accepts an optional `query` for free-text search. To link to a blog from a LINK prop, also call `get_page_by_type("BLOG")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BLOG", "itemId": <blogId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
4282
+ project_root: z
4283
+ .string()
4284
+ .describe("Absolute path to the code-component project."),
4285
+ query: z.string().optional().describe("Free-text blog search."),
4286
+ port: z
4287
+ .number()
4288
+ .optional()
4289
+ .describe("Dev server WebSocket port (default 5201)."),
4290
+ }, async ({ project_root, query, port }) => {
4291
+ const args = [
4292
+ "list-entities",
4293
+ "--kind",
4294
+ "blog",
4295
+ ...(query ? ["--query", query] : []),
4296
+ ...(port ? ["--port", String(port)] : []),
4297
+ ];
4298
+ return callEditorAction(project_root, args);
4299
+ });
4300
+ // Tool: list_blog_categories
4301
+ server.tool("list_blog_categories", 'List the store\'s blog categories and their ids, to fill a BLOG_CATEGORY prop value `{ "blogCategoryId": "<id>" }`. Returns blogCategoryId, name, slug for each. Accepts an optional `query` for free-text search. To link to a blog category from a LINK prop, also call `get_page_by_type("BLOG_CATEGORY")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BLOG_CATEGORY", "itemId": <blogCategoryId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
4302
+ project_root: z
4303
+ .string()
4304
+ .describe("Absolute path to the code-component project."),
4305
+ query: z.string().optional().describe("Free-text blog-category search."),
4306
+ port: z
4307
+ .number()
4308
+ .optional()
4309
+ .describe("Dev server WebSocket port (default 5201)."),
4310
+ }, async ({ project_root, query, port }) => {
4311
+ const args = [
4312
+ "list-entities",
4313
+ "--kind",
4314
+ "blog-category",
4315
+ ...(query ? ["--query", query] : []),
4316
+ ...(port ? ["--port", String(port)] : []),
4317
+ ];
4318
+ return callEditorAction(project_root, args);
4319
+ });
4320
+ // Tool: get_page_by_type
4321
+ server.tool("get_page_by_type", 'Resolve a theme page\'s id from its pageType (CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX, …). Use this to get the `pageId` needed to build a PAGE link to an entity: pair it with the entity id from list_categories/list_brands/list_blogs/list_blog_categories — `{ linkType:"PAGE", pageId:<this pageId>, pageType:<type>, itemId:<entityId>, id:<unique>, label:... }`. Returns `pageId: null` (with a note) if no page of that type exists yet — in that case call `create_page(page_type)` to add it, then use the returned pageId (do not guess a slug/EXTERNAL URL).', {
4322
+ project_root: z
4323
+ .string()
4324
+ .describe("Absolute path to the code-component project."),
4325
+ page_type: z
4326
+ .string()
4327
+ .describe("Page type to resolve, e.g. CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX."),
4328
+ port: z
4329
+ .number()
4330
+ .optional()
4331
+ .describe("Dev server WebSocket port (default 5201)."),
4332
+ }, async ({ project_root, page_type, port }) => {
4333
+ const args = [
4334
+ "get-page-by-type",
4335
+ "--page-type",
4336
+ page_type,
4337
+ ...(port ? ["--port", String(port)] : []),
4338
+ ];
4339
+ return callEditorAction(project_root, args);
4340
+ });
4341
+ // Tool: create_page
4342
+ server.tool("create_page", 'Create a theme page of a given pageType in the connected editor. Use this when get_page_by_type returns `pageId: null` for a dynamic page (CATEGORY/PRODUCT/BRAND/BLOG/BLOG_CATEGORY) you need to link to: create the page, then build a PAGE link `{ linkType:"PAGE", pageId:<this pageId>, pageType:<type>, itemId:<entityId>, id:<unique>, label:... }` — do NOT guess a slug/EXTERNAL URL. Non-CUSTOM page types are unique per theme: if one already exists it is returned unchanged (`alreadyExisted: true`). CUSTOM pages require `name` and a unique `slug`. Account sub-pages (ADDRESSES/ORDERS/ORDER_DETAIL/FAVORITE_PRODUCTS/RAFFLE_ACCOUNT) need an ACCOUNT page first. Returns `{ pageType, pageId, name, slug }`. Requires `ikas theme dev` running with the editor connected.', {
4343
+ project_root: z
4344
+ .string()
4345
+ .describe("Absolute path to the code-component project."),
4346
+ page_type: z
4347
+ .string()
4348
+ .describe("Page type to create, e.g. CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX, CUSTOM."),
4349
+ name: z
4350
+ .string()
4351
+ .optional()
4352
+ .describe("Page name. Required for CUSTOM pages; ignored otherwise."),
4353
+ slug: z
4354
+ .string()
4355
+ .optional()
4356
+ .describe("Page slug. Required (and unique) for CUSTOM pages; ignored otherwise."),
4357
+ port: z
4358
+ .number()
4359
+ .optional()
4360
+ .describe("Dev server WebSocket port (default 5201)."),
4361
+ }, async ({ project_root, page_type, name, slug, port }) => {
4362
+ const args = [
4363
+ "create-page",
4364
+ "--page-type",
4365
+ page_type,
4366
+ ...(name ? ["--name", name] : []),
4367
+ ...(slug ? ["--slug", slug] : []),
4368
+ ...(port ? ["--port", String(port)] : []),
4369
+ ];
4370
+ return callEditorAction(project_root, args);
4371
+ });
4372
+ // Tool: delete_page
4373
+ server.tool("delete_page", "Delete a theme page and every section placed on it. DESTRUCTIVE and effectively one-way from here (only the editor's own undo stack can bring it back) — ALWAYS get the user's explicit OK before calling it, and never call it to \"clean up\" a page you merely think is unused. Takes the page id from `list_editor_pages` / `get_page_by_type`; there is no name resolution. Refused for the pages a theme cannot run without — INDEX (home), CHECKOUT and NOT_FOUND (404) — and for an ikas-rendered ready-made account page, which must be turned off by its group with `enable_ready_made_pages` so the cleanup that flow does actually runs. Deleting the page currently open in the editor moves it to the home page first. Returns the deleted page's `{ pageId, pageType, name, slug }` plus `remainingPages`. Requires `ikas theme dev` running with the editor connected.", {
4374
+ project_root: z
4375
+ .string()
4376
+ .describe("Absolute path to the code-component project."),
4377
+ page_id: z
4378
+ .string()
4379
+ .describe("Id of the page to delete (from `list_editor_pages` or `get_page_by_type`). Strict — no name resolution."),
4380
+ confirm: z.boolean().describe(CONFIRM_PARAM_DESCRIPTION),
4381
+ port: z
4382
+ .number()
4383
+ .optional()
4384
+ .describe("Dev server WebSocket port (default 5201)."),
4385
+ }, async ({ project_root, page_id, confirm, port }) => {
4386
+ if (confirm !== true)
4387
+ return destructiveConfirmRefusal();
4388
+ const args = [
4389
+ "delete-page",
4390
+ "--id",
4391
+ page_id,
4392
+ "--yes",
4393
+ ...(port ? ["--port", String(port)] : []),
4394
+ ];
4395
+ return callEditorAction(project_root, args);
4396
+ });
4397
+ // Tool: remove_page_section
4398
+ server.tool("remove_page_section", "Remove ONE section placement from a page — the delete counterpart of `add_section_to_page` / `move_page_section`. DESTRUCTIVE: it takes the merchant's content in that section with it, so get the user's explicit OK first. The checkout section on the CHECKOUT page is refused — the checkout page requires it, so never offer to remove it. Target the PLACEMENT by `element_id` from `list_page_sections`, never the `sectionId` or `componentId` — the same section placed twice has two independent placements and each is removed on its own (passing the wrong id is rejected with the elementId you meant). A common (header/footer) section on the home page is HIDDEN rather than deleted, because the INDEX placement is where a common section's prop values live for EVERY page; the reply says so with `hidden: true`, and `add_section_to_page` brings it back with its values intact. A page customized per routing/specification holds its own placements per state: pass `sf_routing_id`/`specification_id` to remove from that state, otherwise only the BASE layer is touched (the reply lists the states it left alone). Returns the removed placement plus the page's remaining `sections`. Requires `ikas theme dev` running with the editor connected.", {
4399
+ project_root: z
4400
+ .string()
4401
+ .describe("Absolute path to the code-component project."),
4402
+ page_id: z
4403
+ .string()
4404
+ .describe("Id of the page holding the placement (from `list_editor_pages`)."),
4405
+ element_id: z
4406
+ .string()
4407
+ .describe("The PLACEMENT's elementId from `list_page_sections` — not the sectionId and not the componentId."),
4408
+ sf_routing_id: z
4409
+ .string()
4410
+ .optional()
4411
+ .describe("Remove from this customized routing state instead of the page's base layer. The state must already exist."),
4412
+ specification_id: z
4413
+ .string()
4414
+ .optional()
4415
+ .describe("Remove from this customized specification state instead of the page's base layer. The state must already exist."),
4416
+ confirm: z.boolean().describe(CONFIRM_PARAM_DESCRIPTION),
4417
+ port: z
4418
+ .number()
4419
+ .optional()
4420
+ .describe("Dev server WebSocket port (default 5201)."),
4421
+ }, async ({ project_root, page_id, element_id, sf_routing_id, specification_id, confirm, port, }) => {
4422
+ if (confirm !== true)
4423
+ return destructiveConfirmRefusal();
4424
+ const args = [
4425
+ "remove-page-section",
4426
+ "--page-id",
4427
+ page_id,
4428
+ "--element-id",
4429
+ element_id,
4430
+ "--yes",
4431
+ ...(sf_routing_id ? ["--sf-routing-id", sf_routing_id] : []),
4432
+ ...(specification_id ? ["--specification-id", specification_id] : []),
4433
+ ...(port ? ["--port", String(port)] : []),
4434
+ ];
4435
+ return callEditorAction(project_root, args);
4436
+ });
4437
+ // Tool: publish_theme
4438
+ // Tool: list_ready_made_pages
4439
+ server.tool("list_ready_made_pages", "List the ikas-rendered ready-made (\"built-in\") account/membership pages (login, register, forgot/recover password, my account, orders, addresses, favorites, email verification) and how to customize them. These pages are rendered by ikas's own components, NOT by sections: a ready-made page carries no sections, so `list_page_sections` shows nothing and `update_section_prop` cannot touch it — `update_ready_made_page_prop` is the write tool. Without arguments returns the roster: per-group (`membership` = login/register/password flows, `account` = my-account pages) enabled state, every ready-made page type with its theme pageId and which props the merchant already edited, plus the SHARED SCOPES (logo, palette, account-menu labels — values edited once that reach every page in the scope's group). Pass `page_type` (e.g. LOGIN) or `scope_id` for that page's/scope's FULL prop schema (types, defaults, ENUM options, translations) and current values (`values` = what the page renders with; `ownValues` = what this page's own layer stores). Pass `sf_routing_id` to read what one storefront routing/locale sees — the no-argument call lists the store's routings (id, path, locale; `isDefault: true` = the base, needing no sf_routing_id). Typical branding flow: read the theme's palette via `list_theme_globals`, then set the shared scope's colors as `{ \"patternValueId\": \"<global color id>\" }` bindings so the pages follow the theme's colors live.", {
4440
+ project_root: z
4441
+ .string()
4442
+ .describe("Absolute path to the code-component project."),
4443
+ page_type: z
4444
+ .string()
4445
+ .optional()
4446
+ .describe("One ready-made page's full prop schema and values (e.g. LOGIN, ACCOUNT, ORDERS)."),
4447
+ scope_id: z
4448
+ .string()
4449
+ .optional()
4450
+ .describe("One shared scope's full prop schema and values (scope ids come from the no-argument call)."),
4451
+ sf_routing_id: z
4452
+ .string()
4453
+ .optional()
4454
+ .describe("Read the values one storefront routing/locale sees (default: the base routing)."),
4455
+ port: z
4456
+ .number()
4457
+ .optional()
4458
+ .describe("Dev server WebSocket port (default 5201)."),
4459
+ }, async ({ project_root, page_type, scope_id, sf_routing_id, port }) => {
4460
+ const args = [
4461
+ "list-builtin-pages",
4462
+ ...(page_type ? ["--page-type", page_type] : []),
4463
+ ...(scope_id ? ["--scope-id", scope_id] : []),
4464
+ ...(sf_routing_id ? ["--sf-routing-id", sf_routing_id] : []),
4465
+ ...(port ? ["--port", String(port)] : []),
4466
+ ];
4467
+ return callEditorAction(project_root, args);
4468
+ });
4469
+ // Tool: update_ready_made_page_prop
4470
+ server.tool("update_ready_made_page_prop", 'Set, bind, or clear ONE prop of an ikas-rendered ready-made account/membership page — the write half of `list_ready_made_pages`, and the ONLY way to customize those pages (they have no sections, so `update_section_prop` cannot reach them). Target a page\'s own prop with `page_type` (e.g. LOGIN) or a SHARED prop — logo, palette, menu labels, edited once for every page in the scope\'s group — with `scope_id`. Identify the prop by `prop_id` or `prop_name` from `list_ready_made_pages`. VALUES ARE RAW (no `{ "value": ... }` envelope — an envelope is tolerated and unwrapped): TEXT = the plain string; BOOLEAN = true/false; NUMBER = a number; ENUM = one of the prop\'s `enumOptions` VALUES; COLOR = "#rrggbb" OR `{ "patternValueId": "<global color id>" }` to follow a theme color live (ids from `list_theme_globals` → colors[].id — prefer the binding when branding, so a palette change updates the pages); IMAGE = `{ "id": "<image id>" }` (id from `upload_image`); LINK/LIST_OF_LINK = copy the shape from `list_ready_made_pages` values. `bind_global` (a global\'s `name` from `list_theme_globals`) makes the prop follow a Theme Setting instead of holding a value; `clear: true` deletes the stored value so the prop falls back to the shared value or the manifest default. `sf_routing_id` writes one routing\'s override — use it to localize texts per language; without it you write the base value every routing inherits. Writes are undoable in the editor.', {
4471
+ project_root: z
4472
+ .string()
4473
+ .describe("Absolute path to the code-component project."),
4474
+ page_type: z
4475
+ .string()
4476
+ .optional()
4477
+ .describe("Page type whose OWN prop to write (e.g. LOGIN). Pass this or scope_id."),
4478
+ scope_id: z
4479
+ .string()
4480
+ .optional()
4481
+ .describe("Shared scope whose prop to write — reaches every ready-made page in its group."),
4482
+ prop_id: z
4483
+ .string()
4484
+ .optional()
4485
+ .describe("Prop id from list_ready_made_pages. Provide this or prop_name."),
4486
+ prop_name: z
4487
+ .string()
4488
+ .optional()
4489
+ .describe("Prop name (alternative to prop_id)."),
4490
+ value: z
4491
+ .any()
4492
+ .optional()
4493
+ .describe("The RAW value (see the tool description for per-type shapes). Omit when using bind_global or clear."),
4494
+ bind_global: z
4495
+ .string()
4496
+ .optional()
4497
+ .describe("Bind the prop to a global variable (Theme Setting) — pass the global's `name` from list_theme_globals."),
4498
+ clear: z
4499
+ .boolean()
4500
+ .optional()
4501
+ .describe("true deletes the stored value; the prop falls back to the shared value or the manifest default."),
4502
+ sf_routing_id: z
4503
+ .string()
4504
+ .optional()
4505
+ .describe("Write one storefront routing's override (localization). Omit to write the base value."),
4506
+ port: z
4507
+ .number()
4508
+ .optional()
4509
+ .describe("Dev server WebSocket port (default 5201)."),
4510
+ }, async ({ project_root, page_type, scope_id, prop_id, prop_name, value, bind_global, clear, sf_routing_id, port, }) => {
4511
+ const args = [
4512
+ "update-builtin-page-prop",
4513
+ ...(page_type ? ["--page-type", page_type] : []),
4514
+ ...(scope_id ? ["--scope-id", scope_id] : []),
4515
+ ...(prop_id ? ["--prop-id", prop_id] : []),
4516
+ ...(prop_name ? ["--prop-name", prop_name] : []),
4517
+ ...(bind_global
4518
+ ? ["--bind-global", bind_global]
4519
+ : clear
4520
+ ? ["--clear"]
4521
+ : value !== undefined
4522
+ ? [
4523
+ "--value",
4524
+ // ALWAYS JSON-encode: the CLI JSON.parses --value (raw-string fallback), so a
4525
+ // verbatim TEXT string that happens to parse — "2024", "true", "null" — would
4526
+ // arrive as a number/boolean/clear. Encoded, it round-trips as the string it is.
4527
+ JSON.stringify(value),
4528
+ ]
4529
+ : []),
4530
+ ...(sf_routing_id ? ["--sf-routing-id", sf_routing_id] : []),
4531
+ ...(port ? ["--port", String(port)] : []),
4532
+ ];
4533
+ return callEditorAction(project_root, args);
4534
+ });
4535
+ // Tool: enable_ready_made_pages
4536
+ server.tool("enable_ready_made_pages", 'Turn one GROUP of ikas-rendered ready-made pages on or off: "membership" (login, register, forgot/recover password, email verification) or "account" (my account, orders, order detail, addresses, favorites). Enabling records the choice and creates any page of the group the theme does not have yet — each born rendered by ikas\'s own component; customize them right after with `update_ready_made_page_prop`. Disabling removes ONLY the untouched pages the toggle itself created — a page the merchant built on is never deleted. The flip is one undo step in the editor. Check the current state first with `list_ready_made_pages`.', {
4537
+ project_root: z
4538
+ .string()
4539
+ .describe("Absolute path to the code-component project."),
4540
+ group: z
4541
+ .enum(["membership", "account"])
4542
+ .describe('"membership" = login/register/password flows; "account" = my-account pages.'),
4543
+ enabled: z
4544
+ .boolean()
4545
+ .describe("true to enable the group, false to disable it."),
4546
+ port: z
4547
+ .number()
4548
+ .optional()
4549
+ .describe("Dev server WebSocket port (default 5201)."),
4550
+ }, async ({ project_root, group, enabled, port }) => {
4551
+ const args = [
4552
+ "enable-builtin-pages",
4553
+ "--group",
4554
+ group,
4555
+ "--enabled",
4556
+ String(enabled),
4557
+ ...(port ? ["--port", String(port)] : []),
4558
+ ];
4559
+ return callEditorAction(project_root, args);
4560
+ });
4561
+ server.tool("publish_theme", "Publish the current theme LIVE — the same action as the editor's Publish button (uploads the whole project to the storefront). This is REAL and customer-facing: the published site changes. SAFETY: it publishes nothing unless `confirm: true` is passed; if you omit it you get a dry-run with the `previewUrl` and a warning describing the impact. The MAIN/production theme additionally requires `confirm_production: true` (its URL is the live customer-facing domain). Use this when the user explicitly asks to publish/go live — do NOT publish on your own initiative. On success returns `{ published: true, previewUrl, isMainTheme }`; open `previewUrl` to review the result. Requires `ikas theme dev` running with the editor connected.", {
4562
+ project_root: z
4563
+ .string()
4564
+ .describe("Absolute path to the code-component project."),
4565
+ confirm: z
4566
+ .boolean()
4567
+ .optional()
4568
+ .describe("Set true to actually publish. Omitted/false = dry-run (returns previewUrl + warning, publishes nothing)."),
4569
+ confirm_production: z
4570
+ .boolean()
4571
+ .optional()
4572
+ .describe("Required IN ADDITION to confirm when the target is the MAIN/production theme (live customer-facing site)."),
4573
+ port: z
4574
+ .number()
4575
+ .optional()
4576
+ .describe("Dev server WebSocket port (default 5201)."),
4577
+ }, async ({ project_root, confirm, confirm_production, port }) => {
4578
+ const args = [
4579
+ "publish-theme",
4580
+ ...(confirm ? ["--confirm"] : []),
4581
+ ...(confirm_production ? ["--confirm-production"] : []),
4582
+ ...(port ? ["--port", String(port)] : []),
4583
+ ];
4584
+ return callEditorAction(project_root, args);
4585
+ });
4586
+ // Tool: get_editor_workflow
4587
+ const EDITOR_WORKFLOW_GUIDE = [
4588
+ "# Editor workflow: placing sections and filling their content on a page",
4589
+ "",
4590
+ "Use this when the user wants to add a section to a page and/or fill in its content (heading, text, image, link, slides, etc.) in the live editor. These are LIVE-EDITOR actions and require `ikas theme dev` running with the editor connected; image upload additionally requires the editor to be embedded in the ikas admin panel (the admin panel performs the upload — a standalone editor cannot upload).",
4591
+ "",
4592
+ "## Account & membership pages: ASK before you build",
4593
+ "If the page the user wants is a login, register, forgot/recover-password, my-account, orders, order-detail, addresses, favorites or email-verification page: do NOT code a custom section page yet. ikas ships ready-made versions of exactly these pages — fully functional (real auth/order/address flows), customizable (logo, colors, texts) and localizable via update_ready_made_page_prop, the whole group enabled at once with enable_ready_made_pages. FIRST ask the user which they want: the ready-made page (fast, maintained by ikas) or a custom section page (full design freedom) — list the ready-made option FIRST as the recommended default, custom second. Only start coding after the user explicitly chooses custom — and never call enable_ready_made_pages without the user's OK, it creates/removes pages. Start discovery with list_ready_made_pages. USER-FACING NAME: name these in the USER'S OWN LANGUAGE — English: \"ikas's ready-made pages\", Turkish: \"ikas'ın hazır sayfaları\"; never mix the English term into a sentence in another language — the editor UI lists them as Membership Pages / My Account Pages; \"built-in\" is an internal term — keep it out of everything the user sees, including question/option labels. Note: a ready-made page is born with ONLY its own ikas-rendered element — the theme's header/footer are NOT on it (the page draws its own top bar — logo, back-to-store link — and account nav). If the user wants the theme header/footer there, place it with add_section_to_page (sections can sit above/below that element) and suggest turning the page's `showBrandBar` prop off to avoid double chrome.",
4594
+ "",
4595
+ "## Two distinct jobs — do not confuse them",
4596
+ "- (A) DEFINE props / author component code — changing WHICH props a component has. Edits component source/config (config add-prop/add-component, index.tsx) and needs a rebuild. Do this ONLY when a needed prop does not exist yet, or the user explicitly asks to build/modify the component.",
4597
+ "- (B) SET prop VALUES / fill content — giving values to props that ALREADY exist on a placed section. Pure data entry via list_page_sections + update_section_prop (+ upload_image). No code, no rebuild.",
4598
+ "When the user says 'fill this section', 'set the title/text/image/link', 'populate', 'change the content' → that is JOB (B). Do NOT write a component or add a prop to fill a value the section already supports.",
4599
+ "",
4600
+ "## Step-by-step (JOB B — fill content)",
4601
+ "1. list_editor_pages → choose the target page_id.",
4602
+ "2. list_page_sections(page_id) → for each placed section: its per-placement elementId, blueprint props (id, name, type), and setPropNames (which props already have a value). It is LEAN — no prop VALUES, so it never truncates. To read a section's current values (e.g. to read-modify-write a COMPONENT_LIST), call get_section_values(page_id, element_id). A section returned with a `common` field is the theme's header/footer — its values are theme-wide, not this page's; read the 'COMMON (global) sections' section below BEFORE touching it. (If the section is not on the page yet, see 'Placing a section' below.)",
4603
+ "3. To set props (fewest round-trips = fastest): update_page_sections(page_id, sections:[{element_id, updates:[{prop_name,value}]}]) fills the WHOLE page (or one section, or just one prop — it scales to all cases) in ONE call (best). update_section_prop sets a single prop, for quick one-offs. Pass each value as a parsed JSON object/array, NEVER a JSON string.",
4604
+ "4. For image props: upload_images(images:[{file_path|image_url, alt_text}]) uploads many in ONE call (preferred); upload_image for a single one. Use the returned id(s) in IMAGE values. Do uploads BEFORE the update call so you have the ids.",
4605
+ "Speed tip: each tool call is a round-trip — gather first (one list_page_sections), batch your uploads (upload_images) and your writes (update_page_sections), rather than calling per-prop/per-image.",
4606
+ "",
4607
+ "## COMMON (global) sections: the header and the footer",
4608
+ "The theme's header and footer are COMMON sections: they render on every page that carries a placement of them (pages created in the editor are seeded with one — EXCEPT ikas ready-made (built-in) account/membership pages, which are born without the theme header/footer) and their prop values are SHARED by the whole theme — there is exactly ONE record, kept on the INDEX (Home) page's placement. A placement of the same section on any other page stores NOTHING of its own.",
4609
+ '- How to recognize one: list_page_sections / get_section_values / the write results return a `common` block for it — `isCommon: true`, `commonSectionType: "header"|"footer"`, `valuesArePageSpecific: false`, plus `canonicalPageId`/`canonicalElementId` (the INDEX placement that holds the values). A page containing one also gets a top-level `commonSectionsNote`.',
4610
+ "- READS are redirected for you: get_section_values / list_page_sections report a common section's values FROM the INDEX placement, whatever page_id you pass. So what you see is what the page actually renders — no need to re-read from the INDEX page.",
4611
+ "- WRITES are redirected too: update_section_prop / update_page_sections / add_sections_to_page store the value on that INDEX record, so the change applies to the header/footer on ALL pages. The echoed value is read back from the canonical placement, so it reflects what was really stored.",
4612
+ '- THE TRAP to avoid: a header/footer is normally already filled with the merchant\'s content. Never conclude a prop is empty and never blind-fill "missing" props — you would overwrite live content on every page, including pages you never opened. Always get_section_values first and change ONLY the prop the user asked about.',
4613
+ "- If the INDEX page has no placement of the section, there is no record: reads return nothing and writes are REJECTED (\"Index page does not have the common section!\"). Fix it by placing the section on the INDEX page (add_section_to_page with the INDEX page id — get it from list_editor_pages / get_page_by_type('INDEX')) and setting its props there; it then renders on the other pages too.",
4614
+ "",
4615
+ "## Building a whole page fast (placing + filling)",
4616
+ "- add_sections_to_page(page_id, sections:[{component_id, index?, updates:[{prop_name,value}]}]) places MANY sections AND sets their props in ONE call, returning each new elementId. This is the fastest path — prefer it over add_section_to_page per section followed by separate fills. Built-but-unimported section/child components are auto-imported.",
4617
+ "- For a single section: list_imported_sections (confirm imported; else import_section, after building) → add_section_to_page(component_id, page_id, index?) → then list_page_sections to get its elementId.",
4618
+ "- REORDERING an already-placed section is a different tool: move_page_section(page_id, element_id, direction:'up'|'down' | to_index:<n>). The `index` on add_* only positions a NEW placement; it cannot move an existing one, and the editor UI exposes reordering solely as a drag, so this tool is the only way. Indices are 0-based over the placed sections in list_page_sections order; the result returns `resultIndex` + the full resulting `sections` order — assert on those. Header/footer (COMMON) sections cannot be reordered and are rejected.",
4619
+ "",
4620
+ "## Value shapes by prop type (what to pass as `value`)",
4621
+ '- Scalars are WRAPPED: TEXT/RICH_TEXT { "value": "..." }, BOOLEAN { "value": true }, NUMBER { "value": 12 }, COLOR { "value": "#FF0000" }, ENUM { "value": "<key>" }, DATE { "value": ... }.',
4622
+ '- SVG is value-wrapped: { "value": "<svg markup>" }. NUMBER_RANGE: { "value": <number>, "unit": "px"|null }.',
4623
+ '- SVG naming: the editor shows each svg\'s `class` attribute as its display name in the list; add class="my-icon" to name it. SVG_LIST items with no class render as svg-1, svg-2, ….',
4624
+ '- Object props are NOT wrapped (no { "value": ... }):',
4625
+ ' - IMAGE: { "id": "<asset-id>", "altText"?: "...", "isVideo"?: false } — get the id from upload_image. Same shape at section level AND nested in a component list. IMAGE_LIST: { "images": [ <image>, ... ] }.',
4626
+ ' - VIDEO: { "video": { "id": "<asset-id>" }, "thumbnailImage"?: { "id": "..." }, "autoplay"?: false, "controls"?: true, "loop"?: false, "muted"?: false } — NOT a bare { "id": ... }. SVG_LIST: { "svgs": [ "<svg>", ... ] }.',
4627
+ ' - LINK: { "id": "<unique>", "linkType": "PAGE"|"EXTERNAL"|"FILE", "label": "...", "subLinks": [] } plus target — for a static page: pageId + pageType (from list_editor_pages); for EXTERNAL: externalLink. To link to a CATEGORY/BRAND/BLOG/BLOG_CATEGORY entity, do NOT guess a slug — get the entity id from list_categories/list_brands/list_blogs/list_blog_categories and the page id from get_page_by_type(\'<TYPE>\'), then build { id, linkType:\'PAGE\', label, pageId:<pageId>, pageType:\'<TYPE>\', itemId:<entityId>, subLinks:[] }. LIST_OF_LINK = { "links": [ <link>, ... ] }.',
4628
+ ' - Entity props PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY/RAFFLE: { "<entity>Id": "...", "usePageData"?: false } — e.g. { "productId": "...", "variantId"?: "..." }, { "categoryId": "..." }. Get real ids (never invent them) from: search_products (PRODUCT), list_categories (CATEGORY), list_brands (BRAND), list_blogs (BLOG), list_blog_categories (BLOG_CATEGORY). (RAFFLE has no lookup tool yet — read an existing value or ask the user.)',
4629
+ " - List/collection props (PRODUCT_LIST/CATEGORY_LIST/BRAND_LIST/BLOG_LIST/…): typed objects keyed by a <entity>ListType discriminator plus initialSort/initialLimit. The id field DEPENDS on the type — for PRODUCT_LIST: STATIC → productIds:[{productId,variantId}] (from search_products); CATEGORY → category:'<categoryId>' (from list_categories) — the field is `category`, NOT `categoryId` (categoryId is ONLY the standalone CATEGORY entity prop above); ALL/DISCOUNTED/RECOMMENDED/etc → no id field. Get the exact field set + writeNote from get_component_props, or read+edit an existing value via get_section_values. Unknown sub-fields (e.g. categoryId inside a PRODUCT_LIST) are REJECTED.",
4630
+ ' - COMPONENT_LIST: { "components": [ { "id": "<unique>", "codeComponentId": "<child-id>", "propValues": { "<childProp>": <value>, ... } }, ... ] }. A single COMPONENT prop is one such entry. childProp values use these same per-type shapes, recursively.',
4631
+ "",
4632
+ "## COMPONENT_LIST rules (the part most often gotten wrong)",
4633
+ "- READ-MODIFY-WRITE: update_section_prop REPLACES the whole prop value. To add/edit/remove one child, take the CURRENT { components: [...] } from get_section_values, edit it, and resend the ENTIRE array (with all existing entries and their ids). Sending only your new entry wipes the rest.",
4634
+ "- Each entry needs a UNIQUE id (a short string you generate; it does not need to match anything). Do not reuse another entry's id.",
4635
+ '- Reference a code component with "codeComponentId" and a built-in theme component with "componentId" — not the other way around. Use "propValues" (not "props").',
4636
+ "- Child ids are opaque — take them from get_section_template / list_imported_sections; never invent them.",
4637
+ "- Auto-import: a referenced child that is BUILT but not yet imported is imported automatically (returned under autoImported). A child that is not built at all errors — build it first.",
4638
+ "",
4639
+ "## Reading prop schemas (avoid guessing)",
4640
+ "- get_component_props(componentId) → a component's props with types, required, default, ENUM `options` (the valid values to set), and COMPONENT_LIST `allowedComponentIds` (valid children). Works for any section OR child id. Use it BEFORE filling — to know prop names, enum values, and which children a slot allows — instead of guessing or reading ikas.config.json.",
4641
+ "- For a COMPONENT_LIST: get_component_props(parent) → its allowedComponentIds → get_component_props(child) → the child's props/enums. Then build the components array.",
4642
+ "- get_section_values(element_id) → one placed section's current values (read-modify-write of a COMPONENT_LIST, or to copy an existing value's exact shape).",
4643
+ "- Real entity ids/images: search_products returns productId + variantId + imageSrc (the product image URL). To use that image in an IMAGE prop, you can't reuse a product image id — upload it: upload_image(image_url: imageSrc) → use the returned id. list_categories/list_brands/list_blogs/list_blog_categories return the entity ids; to LINK to one, also call get_page_by_type('<TYPE>') for the page id and build a PAGE link { linkType:'PAGE', pageId, pageType, itemId:<entityId>, id, label }. IMPORTANT: if get_page_by_type returns pageId:null, that dynamic page does NOT exist in the theme yet — do NOT guess a slug/EXTERNAL URL. Call create_page('<TYPE>') to add it (non-CUSTOM types are unique and returned as-is if already present), then use the returned pageId to build the PAGE link. Always have a real pageId before building a PAGE link.",
4644
+ "",
4645
+ "## Validation",
4646
+ "Values are validated server-side (deeply, including nested children). Wrong shape or wrong semantics (double-encoded string, { value } wrapper on an object prop, props vs propValues, missing/duplicate id, wrong reference key, nonexistent component id, unknown prop name) are REJECTED with an explanatory error instead of being stored silently. Read the error and fix the value; if unsure of a shape, read it with get_section_values and match it.",
4647
+ ].join("\n");
4648
+ server.tool("get_editor_workflow", "Read this FIRST when the user wants to place a section on a page or fill/edit a section's content (text, image, link, slides, component lists) in the live editor. Returns the complete step-by-step workflow for the live-editor tools (list_editor_pages, list_imported_sections, import_section, add_section_to_page, list_page_sections, update_section_prop, upload_image), the per-prop-type value shapes, the COMPONENT_LIST read-modify-write rules, how COMMON (global) header/footer sections keep one theme-wide set of values on the INDEX page (and how not to overwrite them), and how validation/auto-import behave. Use it to avoid the common mistake of writing component code to set a value a section already supports.", {}, async () => {
4649
+ return {
4650
+ content: [{ type: "text", text: EDITOR_WORKFLOW_GUIDE }],
4651
+ };
4652
+ });
4653
+ // Tool: list_theme_globals
4654
+ server.tool("list_theme_globals", "List the theme's global settings from the connected editor: global variables (Theme Settings) and design tokens (colors, typography, breakpoints, keyframes, color schemes). Call this BEFORE generating sections/components so you reuse the theme's existing variables and tokens (read them in component code via `getThemeSetting`/`getThemeColors`/... from `@ikas/bp-storefront`). Includes items created manually in the editor UI. Requires `ikas theme dev` running with the editor connected. Two shape gotchas when consuming the result at runtime: (1) color schemes — `colorSchemes.schemes` holds only `{id,name}` slot LABELS; the actual colors live in `colorSchemes.values[].colorsByScheme` keyed by slot id, so iterate `values[].colorsByScheme` (iterating `schemes` renders empty). (2) An IMAGE setting's `value` is an image REFERENCE like `{id:'theme-images/<uuid>'}` with no `.url` — resolve it via `getDefaultSrc`/`getSrc`. (3) Each keyframe now includes its animation `settings` (type-dependent { property, value } entries — duration/iteration/timing/etc. for keyframe, transition for transition) and each point's resolved `styles`, so you can read back the full animation config, not just the `ref`. (4) Each typography entry may include `supportedFontWeights` — the exact numeric weights that text style's font actually ships (e.g. `[400]` for Modak); when present, only set `font_weight` to a value in this list (via `update_text_style`/`create_theme_global`), otherwise the write is rejected. If the field is absent the font's weight set couldn't be determined — fall back to 400 or rely on the validation error. Each typography entry also carries `isDefault` (true for the theme's default/global text style — the editor's \"Make Default Style\"); toggle it via `update_text_style`'s `is_default`. (5) Token NAMES are NOT unique — a theme can contain two tokens with the SAME name (e.g. colors pulled from two different design assets), so NEVER match a token by its human name. ALWAYS identify a token by its `id` (globally unique). IN COMPONENT CODE: prefer embedding the token's id-derived STABLE ref directly — color → cssVar `var(--<id>)`, typography → `className` `_<id>`, keyframe (animation-name) → `ref` `_<id>` — so you don't look anything up at runtime. If you DO need to pick a token out of a `getThemeColors()` / `getThemeTypography()` / `getThemeKeyframes()` / `getThemeColorSchemes()` array, match on `.id` (e.g. `getThemeColors().find(c => c.id === \"<id>\")`), NEVER on `.name`. EXCEPTION — global variables/settings: `getThemeSetting(name)` takes the token's `name`, but here `name` is the unique runtime key (`variableName`, the `_<id>` form returned in this list), which IS safe; do NOT pass a setting's human `displayName`. The update/delete tools also identify a token ONLY by `id` (they do NOT look up by name — on those tools `name` means the NEW name when renaming). Always take the `id` (or, for settings, the `name`/variableName) from THIS list. (6) GROUPING convention: a \"/\" in a token's NAME organizes it into a group in the editor UI — the text before the first \"/\" is the group, the rest is the item label. This applies to COLORS (e.g. \"Brand/Primary\"), TEXT STYLES (e.g. \"Heading/H1\"), and COLOR-SCHEME SLOTS (e.g. \"PrimaryButton/Background\"). When you create globals (via `create_theme_global`/`update_theme_color_scheme`), use \"/\"-prefixed names to keep related tokens grouped and tidy; reuse an existing group's exact prefix so they nest together. (7) ENUM settings: a setting with `type: \"ENUM\"` selects one option of a PROJECT enum and carries `enumTypeId` (the enum's id — the same one an ENUM prop declares as `enumTypeId`) and `options` (`{ label: value }`); its `value` is always one of those option VALUES (never a label), or null when unset. The response's top-level `enumTypes` array lists the project enums a new ENUM setting may select from (`{ id, name, options }`) — use an `id` from it as `enum_type_id` in `create_theme_global`. An ENUM prop can be bound (`bind_global`) only to an ENUM setting of the SAME enum.", {
4655
+ project_root: z
4656
+ .string()
4657
+ .describe("Absolute path to the code-component project (where `node_modules/.bin/ikas-component` lives)."),
4658
+ port: z
4659
+ .number()
4660
+ .optional()
4661
+ .describe("Dev server WebSocket port (default 5201)."),
4662
+ }, async ({ project_root, port }) => {
4663
+ const args = [
4664
+ "list-theme-globals",
4665
+ ...(port ? ["--port", String(port)] : []),
4666
+ ];
4667
+ return callEditorAction(project_root, args);
4668
+ });
4669
+ // Shared text-style (typography) font-property schema — kept in lock-step with the editor's
4670
+ // "Update Text Style" modal fields (no color/text-align, since that modal doesn't expose them).
4671
+ // Each enum prop documents its accepted values so a bad value is caught with a clear error. Spread
4672
+ // into both create_theme_global (typography) and update_text_style so the two never drift apart.
4673
+ const textStyleFontParams = {
4674
+ font_family: z
4675
+ .string()
4676
+ .optional()
4677
+ .describe('A real font family the editor offers — a Google Fonts name with EXACT casing (e.g. "Inter", "Roboto", ' +
4678
+ '"Poppins"), or a font already used by an existing text style in list_theme_globals. An unknown font ' +
4679
+ "(or wrong casing) is rejected; do NOT invent a family name."),
4680
+ font_size: z.string().optional(),
4681
+ font_weight: z
4682
+ .string()
4683
+ .optional()
4684
+ .describe("font-weight as a number (e.g. \"600\"); append 'i' for italic (e.g. \"600i\"). A PLAIN number with no 'i' " +
4685
+ "is upright and REMOVES italic if the text style was italic (italic is carried by the weight — re-send the " +
4686
+ "weight without 'i' to turn it off). Must be a weight the chosen " +
4687
+ 'font ships — if it isn\'t, the error lists the supported weights; when unsure use "400".'),
4688
+ line_height: z.string().optional(),
4689
+ letter_spacing: z.string().optional(),
4690
+ text_decoration: z
4691
+ .string()
4692
+ .optional()
4693
+ .describe("text-decoration: none | underline | line-through"),
4694
+ text_transform: z
4695
+ .string()
4696
+ .optional()
4697
+ .describe("text-transform: none | uppercase | lowercase | capitalize"),
4698
+ text_overflow: z
4699
+ .string()
4700
+ .optional()
4701
+ .describe("text-overflow: clip | ellipsis — ellipsis only truncates with white_space: nowrap and overflow: hidden in the component CSS"),
4702
+ white_space: z
4703
+ .string()
4704
+ .optional()
4705
+ .describe("white-space: normal | pre | pre-wrap | pre-line | wrap | nowrap | collapse"),
4706
+ line_break: z
4707
+ .string()
4708
+ .optional()
4709
+ .describe("line-break: auto | loose | normal | strict | anywhere"),
4710
+ word_break: z
4711
+ .string()
4712
+ .optional()
4713
+ .describe("word-break: normal | break-all | keep-all"),
4714
+ text_wrap_style: z
4715
+ .string()
4716
+ .optional()
4717
+ .describe("text-wrap-style: auto | balance | pretty | stable"),
4718
+ };
4719
+ // Turn the supplied text-style font params into `ikas-component` CLI flags (omitted ones dropped).
4720
+ // The editor validates each value and rejects an unsupported one with the offending value + allowed set.
4721
+ function textStyleFontArgs(input) {
4722
+ const map = {
4723
+ "--font-family": input.font_family,
4724
+ "--font-size": input.font_size,
4725
+ "--font-weight": input.font_weight,
4726
+ "--line-height": input.line_height,
4727
+ "--letter-spacing": input.letter_spacing,
4728
+ "--text-decoration": input.text_decoration,
4729
+ "--text-transform": input.text_transform,
4730
+ "--text-overflow": input.text_overflow,
4731
+ "--white-space": input.white_space,
4732
+ "--line-break": input.line_break,
4733
+ "--word-break": input.word_break,
4734
+ "--text-wrap-style": input.text_wrap_style,
4735
+ };
4736
+ // An empty string is passed through: with breakpoint_id it removes that override.
4737
+ return Object.entries(map).flatMap(([flag, value]) => value != null ? [flag, value] : []);
4738
+ }
4739
+ // Per-breakpoint text-style overrides in one call. `.strict()` so a non-responsive property
4740
+ // (e.g. text_transform) is rejected instead of silently dropped.
4741
+ const textStyleBreakpointsParam = z
4742
+ .array(z
4743
+ .object({
4744
+ breakpoint_id: z
4745
+ .string()
4746
+ .describe("Existing theme breakpoint id from `list_theme_globals`."),
4747
+ font_size: z.string().optional(),
4748
+ font_weight: z
4749
+ .string()
4750
+ .optional()
4751
+ .describe('Plain number, e.g. "500" (the style\'s italic is kept).'),
4752
+ line_height: z.string().optional(),
4753
+ letter_spacing: z.string().optional(),
4754
+ })
4755
+ .strict())
4756
+ .optional()
4757
+ .describe("RESPONSIVE overrides for several breakpoints in ONE call: [{ breakpoint_id, font_size?, font_weight?, " +
4758
+ "line_height?, letter_spacing? }]. Only these 4 properties, each needs a desktop value (set in this same " +
4759
+ 'call or earlier), "" removes an override. Validated as a whole: one invalid entry rejects the call and ' +
4760
+ "nothing is written. Breakpoints are not created here.");
4761
+ function textStyleBreakpointsArgs(breakpoints) {
4762
+ if (!breakpoints)
4763
+ return [];
4764
+ const json = breakpoints.map((bp) => ({
4765
+ breakpointId: bp.breakpoint_id,
4766
+ fontSize: bp.font_size,
4767
+ fontWeight: bp.font_weight,
4768
+ lineHeight: bp.line_height,
4769
+ letterSpacing: bp.letter_spacing,
4770
+ }));
4771
+ return ["--breakpoints", JSON.stringify(json)];
4772
+ }
4773
+ // Tool: create_theme_global
4774
+ server.tool("create_theme_global", "Create a theme global setting in the connected editor. `kind` selects what to create:\n" +
4775
+ '- globalVariable: requires display_name + type (TEXT|RICH_TEXT|IMAGE|COLOR|NUMBER|BOOLEAN|BORDER|SHADOW|ENUM); value optional. Pass `value` as a REAL JSON value, never a stringified JSON. Value shapes — TEXT/COLOR: string; RICH_TEXT: HTML string; NUMBER: number; BOOLEAN: real JSON boolean true/false (NOT the string "true"); IMAGE: an image REFERENCE object { id: "theme-images/<uuid>" } (NOT { url }) — the id MUST come from a REAL upload: call `upload_image` (file_path or image_url) and use the id it returns, or reuse an id already listed by `list_theme_globals`. NEVER invent an id — it is stored as given and renders as a broken image, so if you have no image, omit `value` and let the merchant set it from the "Theme Settings" panel; BORDER: { width: { value, unit }, style, color } (width.value must be a number); SHADOW: { x, y, blur, spread, color, position: "outside"|"inside" }; ENUM: a setting that selects ONE option of a PROJECT enum — pass `enum_type_id` (an enum id from `list_theme_globals` → `enumTypes[]`; the same enum an ENUM prop declares as `enumTypeId`; built-in @ikas/* enums are REJECTED) and `value` = one of that enum\'s option VALUES (the strings in its `options`, e.g. "bottom"), NOT a label; omit `value` to leave it unset. Once created, an ENUM prop of the SAME enum can be bound to it with `update_section_prop` `bind_global`, and in component code `themeValue("_<id>")` from `./global-types` narrows to the enum\'s union type. For object types (IMAGE/BORDER/SHADOW) pass an actual JSON object, not a JSON-encoded string. Every value is validated server-side and a wrong shape is REJECTED, not silently stored.\n' +
4776
+ '- color: requires name + value — a CONCRETE color (hex e.g. "#ff0000", rgb()/hsl() or a CSS color name). A color token cannot alias another color, so a "var(...)" reference is REJECTED here (to reuse another theme color, reference its cssVar in component code, or in a colorScheme slot). TIP: a "/" in the `name` GROUPS the color in the editor UI (e.g. "Brand/Primary", "Brand/Accent" appear under a "Brand" group); use this to organize related colors. To CHANGE an existing color later, use `update_theme_color` (edits in place, keeps the cssVar stable) — do NOT delete+recreate.\n' +
4777
+ '- typography: requires name + at least one text-style property. These are exactly the fields the editor\'s "Update Text Style" modal exposes — nothing else (in particular there is NO color or text-align on a text style). VALUE FORMATS (all validated; a bad value is rejected with the offending value and the allowed set): font_weight is one of 100,200,300,400,500,600,700,800,900 (append \'i\' for italic, e.g. "600i") AND must be a weight the chosen font actually ships (many fonts provide only a subset, e.g. "Modak" only ships 400) — if unavailable the call fails and lists the supported weights, so when unsure use 400; stored as a numeric weight + a font-style entry; font_size is a number WITH a unit (e.g. "16px", "1.2rem", "80%"); line_height is "normal", a unitless number (e.g. "1.5") or a length; letter_spacing is "normal" or a length (e.g. "0.02em", "0.5px"); font_family is a real font the editor offers (a Google Fonts name with EXACT casing, e.g. "Inter") — an unknown/invented family is rejected; text_decoration is none|underline|line-through; text_transform is none|uppercase|lowercase|capitalize; text_overflow is clip|ellipsis; white_space is normal|pre|pre-wrap|pre-line|wrap|nowrap|collapse; line_break is auto|loose|normal|strict|anywhere; word_break is normal|break-all|keep-all; text_wrap_style is auto|balance|pretty|stable. TIP: a "/" in the `name` GROUPS the text style in the editor UI (e.g. "Heading/H1", "Heading/H2" appear under a "Heading" group); use this to organize related styles. Optional `breakpoints` sets responsive overrides in the same call (see the param). To CHANGE an existing text style later, use `update_text_style` (edits in place, keeps the `className` stable) — do NOT delete+recreate, which changes the id/className.\n' +
4778
+ "- breakpoint: requires name + width (a positive INTEGER, in px — no decimals). To CHANGE an existing breakpoint later, use `update_theme_breakpoint` (edits in place, keeps the id).\n" +
4779
+ "- keyframe: requires name + points (array of { point, styles? }) where each style is { property, value } using a CSS property name (opacity, transform, filter, background, color, …); keyframe_type defaults to \"keyframe\". Optional `settings` = animation-level config as { property, value } entries, TYPE-DEPENDENT: for keyframe — animation-duration, animation-iteration-count, animation-play-state, animation-delay, animation-timing-function, animation-direction, animation-fill-mode, animation-timeline, animation-range, transform-origin, backface-visibility; for transition — transition, backface-visibility. Setting these means the editor drives the animation timing (you don't have to hand-write `animation:` CSS). Use the keyframe's `ref` as the CSS animation-name. For a TRANSITION keyframe, put the target/hover-state styles on the 100% point (points[1].styles) — the 0% point is ignored (the start state is the element's own normal state). To CHANGE an existing keyframe later, use `update_theme_keyframe` (edits in place, keeps the `ref` stable) — do NOT delete+recreate, which changes the ref and breaks references.\n" +
4780
+ '- colorScheme: requires name + colors (array of { slotId? | newSlotName?, value }) — each color targets ONE color SLOT, EITHER by `slotId` (an EXISTING slot\'s id, from `list_theme_globals` → colorSchemes.schemes[].id or a `colorsByScheme` key — the id-keyed path) OR by `newSlotName` (a name to CREATE-or-reuse a slot; write-only, for the standard vocabulary and brand-new slots). Pass EXACTLY ONE of the two per entry. `value` is EITHER a literal color (hex/rgb/hsl or a CSS color name, e.g. "#0b1120") OR a REFERENCE to an existing theme color, passed as that color\'s cssVar from `list_theme_globals` (e.g. "var(--<colorId>)"). A `var(--id)` value is stored as a linked reference (editing the global color updates the scheme too and the dependency is tracked) — do NOT inline a hex you copied from a global color; pass its cssVar. SLOT IDENTITY: `colorSchemes.schemes` lists each slot as `{id, name}`. To set a color on an EXISTING slot, find it there by name and pass its `slotId` (names are NOT unique — two design assets can each have a "Background" — so when ambiguous disambiguate via the scheme\'s existing `colorsByScheme` keys); use `newSlotName` only to add a slot the scheme does not have yet. When creating slots use the theme\'s STANDARD slot names so components resolve them: "Background", "Heading", "Text", "Link", "HoverLink", "Border", and per button "PrimaryButton/Background", "PrimaryButton/Text", "PrimaryButton/Border", "PrimaryButton/HoverBackground", "PrimaryButton/HoverText", "PrimaryButton/HoverBorder" (and the same six under "SecondaryButton/"); a "/" groups the slot in the editor UI. A scheme should normally define EVERY slot it uses; omitted slots fall back to the default scheme\'s color. A mistaken slot can be removed with `delete_theme_global` kind `colorSchemeSlot` (by slot id), or renamed in place (id stays stable) with `rename_theme_color_scheme_slot`. To CHANGE an existing scheme later, use `update_theme_color_scheme` (edits in place, keeps the className stable; merges colors by slot, and can set/clear its default flag via `is_default`).\n' +
4781
+ "Read created items back with `list_theme_globals`. Requires `ikas theme dev` running with the editor connected.", {
4782
+ project_root: z
4783
+ .string()
4784
+ .describe("Absolute path to the code-component project."),
4785
+ kind: z
4786
+ .enum([
4787
+ "globalVariable",
4788
+ "color",
4789
+ "typography",
4790
+ "breakpoint",
4791
+ "keyframe",
4792
+ "colorScheme",
4793
+ ])
4794
+ .describe("What to create."),
4795
+ name: z.string().optional().describe("Name (design tokens)."),
4796
+ display_name: z
4797
+ .string()
4798
+ .optional()
4799
+ .describe("Human label (globalVariable)."),
4800
+ type: z.string().optional().describe("globalVariable value type."),
4801
+ value: z
4802
+ .any()
4803
+ .optional()
4804
+ .describe("globalVariable default value (shape depends on type — see tool description), or color hex string."),
4805
+ enum_type_id: z
4806
+ .string()
4807
+ .optional()
4808
+ .describe("globalVariable of type ENUM only: id of the project enum the setting selects from (from `list_theme_globals` → `enumTypes[]`). Required for ENUM, invalid for other types."),
4809
+ ...textStyleFontParams,
4810
+ breakpoints: textStyleBreakpointsParam.describe("typography only: " + textStyleBreakpointsParam.description),
4811
+ width: z
4812
+ .number()
4813
+ .int()
4814
+ .optional()
4815
+ .describe("breakpoint width in px (positive integer, no decimals)."),
4816
+ keyframe_type: z.enum(["keyframe", "transition"]).optional(),
4817
+ points: z.any().optional().describe("keyframe points array."),
4818
+ settings: z
4819
+ .any()
4820
+ .optional()
4821
+ .describe("keyframe animation settings: array of { property, value } (type-dependent — see tool description)."),
4822
+ colors: z
4823
+ .any()
4824
+ .optional()
4825
+ .describe('colorScheme colors: array of { slotId? | newSlotName?, value } — target an EXISTING slot by `slotId` (its id from list_theme_globals → colorSchemes.schemes / colorsByScheme keys) OR create/reuse one by `newSlotName` (use the standard slot names, "/" to group, e.g. "PrimaryButton/Background"). Exactly one per entry. value = a literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" to store a linked reference.'),
4826
+ port: z
4827
+ .number()
4828
+ .optional()
4829
+ .describe("Dev server WebSocket port (default 5201)."),
4830
+ }, async (input) => {
4831
+ const p = input.port ? ["--port", String(input.port)] : [];
4832
+ let args;
4833
+ switch (input.kind) {
4834
+ case "globalVariable":
4835
+ args = [
4836
+ "create-global-variable",
4837
+ "--display-name",
4838
+ String(input.display_name ?? ""),
4839
+ "--type",
4840
+ String(input.type ?? ""),
4841
+ ...(input.value !== undefined
4842
+ ? ["--value", JSON.stringify(input.value)]
4843
+ : []),
4844
+ ...(input.enum_type_id
4845
+ ? ["--enum-type-id", String(input.enum_type_id)]
4846
+ : []),
4847
+ ...p,
4848
+ ];
4849
+ break;
4850
+ case "color":
4851
+ args = [
4852
+ "create-color",
4853
+ "--name",
4854
+ String(input.name ?? ""),
4855
+ "--value",
4856
+ String(input.value ?? ""),
4857
+ ...p,
4858
+ ];
4859
+ break;
4860
+ case "typography":
4861
+ args = [
4862
+ "create-text-style",
4863
+ "--name",
4864
+ String(input.name ?? ""),
4865
+ ...textStyleFontArgs(input),
4866
+ ...textStyleBreakpointsArgs(input.breakpoints),
4867
+ ...p,
4868
+ ];
4869
+ break;
4870
+ case "breakpoint":
4871
+ args = [
4872
+ "create-breakpoint",
4873
+ "--name",
4874
+ String(input.name ?? ""),
4875
+ "--width",
4876
+ String(input.width ?? ""),
4877
+ ...p,
4878
+ ];
4879
+ break;
4880
+ case "keyframe":
4881
+ args = [
4882
+ "create-keyframe",
4883
+ "--name",
4884
+ String(input.name ?? ""),
4885
+ ...(input.keyframe_type ? ["--type", input.keyframe_type] : []),
4886
+ "--points",
4887
+ toJsonArrayArg(input.points),
4888
+ ...(input.settings !== undefined
4889
+ ? ["--settings", toJsonArrayArg(input.settings)]
4890
+ : []),
4891
+ ...p,
4892
+ ];
4893
+ break;
4894
+ case "colorScheme":
4895
+ args = [
4896
+ "create-color-scheme",
4897
+ "--name",
4898
+ String(input.name ?? ""),
4899
+ "--colors",
4900
+ toJsonArrayArg(input.colors),
4901
+ ...p,
4902
+ ];
4903
+ break;
4904
+ default:
4905
+ return {
4906
+ content: [
4907
+ {
4908
+ type: "text",
4909
+ text: `Error: unknown kind "${input.kind}"`,
4910
+ },
4911
+ ],
4912
+ };
4913
+ }
4914
+ return callEditorAction(input.project_root, args);
4915
+ });
4916
+ // Tool: update_theme_global
4917
+ server.tool("update_theme_global", "Update an existing global variable in the connected editor (e.g. fix its value or change its type). Identify it by `name` (the runtime key from `list_theme_globals`). Only the fields you pass are changed. Value shapes follow `create_theme_global` — pass `value` as REAL JSON (objects/booleans, never stringified); BOOLEAN is a real boolean, BORDER/SHADOW are real objects; IMAGE is an image REFERENCE object { id: \"theme-images/<uuid>\" } whose id MUST come from `upload_image` or an existing `list_theme_globals` entry — an invented id renders as a broken image; ENUM `value` is one of the enum's option VALUES (see the setting's `options` in `list_theme_globals`), and `enum_type_id` re-points the setting at another project enum. Changing `type` or `enum_type_id` of a global that props are bound to is REJECTED (the error names the places) — unbind those props first. Values are validated server-side; a wrong shape is REJECTED, not silently stored.", {
4918
+ project_root: z
4919
+ .string()
4920
+ .describe("Absolute path to the code-component project."),
4921
+ name: z
4922
+ .string()
4923
+ .describe("The variable's runtime key (from `list_theme_globals`)."),
4924
+ display_name: z.string().optional().describe("New label."),
4925
+ type: z
4926
+ .string()
4927
+ .optional()
4928
+ .describe("New value type (TEXT|RICH_TEXT|IMAGE|COLOR|NUMBER|BOOLEAN|BORDER|SHADOW|ENUM)."),
4929
+ value: z
4930
+ .any()
4931
+ .optional()
4932
+ .describe('New value as REAL JSON (shape depends on type; e.g. BOOLEAN: true/false, NUMBER: 12, IMAGE: { id: "theme-images/<uuid>" } from upload_image, ENUM: an option VALUE string — see create_theme_global). An invented IMAGE id renders as a broken image.'),
4933
+ enum_type_id: z
4934
+ .string()
4935
+ .optional()
4936
+ .describe('ENUM only: the project enum to select from (from `list_theme_globals` → `enumTypes[]`); may be passed alone to re-point an unbound ENUM global, or together with `type: "ENUM"`.'),
4937
+ port: z
4938
+ .number()
4939
+ .optional()
4940
+ .describe("Dev server WebSocket port (default 5201)."),
4941
+ }, async ({ project_root, name, display_name, type, value, enum_type_id, port, }) => {
4942
+ const args = [
4943
+ "update-global-variable",
4944
+ "--name",
4945
+ name,
4946
+ ...(display_name !== undefined ? ["--display-name", display_name] : []),
4947
+ ...(type !== undefined ? ["--type", type] : []),
4948
+ ...(value !== undefined ? ["--value", JSON.stringify(value)] : []),
4949
+ ...(enum_type_id !== undefined ? ["--enum-type-id", enum_type_id] : []),
4950
+ ...(port ? ["--port", String(port)] : []),
4951
+ ];
4952
+ return callEditorAction(project_root, args);
4953
+ });
4954
+ // Tool: update_theme_keyframe
4955
+ server.tool("update_theme_keyframe", "Update an existing theme keyframe IN PLACE in the connected editor. Prefer this over delete+recreate: " +
4956
+ "it keeps the keyframe's id, so its runtime `ref` (the CSS animation-name `_<id>`) stays STABLE and every " +
4957
+ "existing reference to it keeps working. Identify the keyframe by `id` (REQUIRED — globally unique, from " +
4958
+ "`list_theme_globals`); name-based lookup is intentionally NOT supported here because names can collide across " +
4959
+ "design assets. To rename, pass `name` (the new name) together with `id`. " +
4960
+ "`points` REPLACES the keyframe's points: an array of { point, styles? } where `point` is a CSS " +
4961
+ 'keyframe offset (e.g. "0%", "50%", "100%") and each style is { property, value } using a CSS property ' +
4962
+ "name (opacity, transform, filter, background, color, …). Pass `points` as REAL JSON (not a stringified array). " +
4963
+ "For a TRANSITION keyframe, put the target/hover-state styles on the 100% point (points[1].styles) — the 0% " +
4964
+ "point is ignored (the start state is the element's own normal state). " +
4965
+ "Optional `settings` REPLACES the keyframe's animation settings (type-dependent { property, value } entries — " +
4966
+ "see `create_theme_global`); OMIT it to keep the existing settings, or pass [] to clear them. " +
4967
+ "Requires `ikas theme dev` running with the editor connected.", {
4968
+ project_root: z
4969
+ .string()
4970
+ .describe("Absolute path to the code-component project."),
4971
+ id: z
4972
+ .string()
4973
+ .describe("Keyframe id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
4974
+ name: z
4975
+ .string()
4976
+ .optional()
4977
+ .describe("Optional NEW name to rename the keyframe to. NOT used to find the token — lookup is always by id."),
4978
+ keyframe_type: z
4979
+ .enum(["keyframe", "transition"])
4980
+ .optional()
4981
+ .describe("Optional new keyframe type."),
4982
+ points: z
4983
+ .any()
4984
+ .describe("New keyframe points array of { point, styles? } — REPLACES the existing points."),
4985
+ settings: z
4986
+ .any()
4987
+ .optional()
4988
+ .describe("New animation settings { property, value } array (type-dependent — see create_theme_global). Omit to keep existing; [] to clear."),
4989
+ port: z
4990
+ .number()
4991
+ .optional()
4992
+ .describe("Dev server WebSocket port (default 5201)."),
4993
+ }, async ({ project_root, id, name, keyframe_type, points, settings, port }) => {
4994
+ const args = [
4995
+ "update-keyframe",
4996
+ "--id",
4997
+ id,
4998
+ ...(name !== undefined ? ["--name", name] : []),
4999
+ ...(keyframe_type ? ["--type", keyframe_type] : []),
5000
+ "--points",
5001
+ toJsonArrayArg(points),
5002
+ ...(settings !== undefined
5003
+ ? ["--settings", toJsonArrayArg(settings)]
5004
+ : []),
5005
+ ...(port ? ["--port", String(port)] : []),
5006
+ ];
5007
+ return callEditorAction(project_root, args);
5008
+ });
5009
+ // Tool: update_text_style
5010
+ server.tool("update_text_style", "Update an existing theme typography token (text style) IN PLACE in the connected editor. Prefer this over " +
5011
+ "delete+recreate: it keeps the text style's id, so its `className` (`_<id>`) — and every section bound to it — " +
5012
+ "stays STABLE. Identify the text style by `id` (REQUIRED — globally unique, from `list_theme_globals`); " +
5013
+ "name-based lookup is intentionally NOT supported here because names can collide across design assets. " +
5014
+ "To rename, pass `name` (the new name) together with `id`. Pass only the properties you want to change; omitted " +
5015
+ 'ones keep their existing values. The settable properties are exactly the editor\'s "Update Text Style" modal ' +
5016
+ "fields — there is NO color or text-align on a text style. VALUE FORMATS (all validated; a bad value is rejected " +
5017
+ "with the offending value and the allowed set): font_weight is one of 100…900 (append 'i' for italic, e.g. " +
5018
+ '"600i") AND must be a weight the chosen font actually ships — many fonts only provide a subset (e.g. "Modak" ' +
5019
+ "only ships 400); if a weight isn't available the call fails and the error lists the supported weights, so when " +
5020
+ 'unsure use 400; font_size is a number with a unit (e.g. "16px"); line_height is "normal", a unitless number ' +
5021
+ 'or a length; letter_spacing is "normal" or a length (e.g. "0.02em"); font_family is a real font the editor ' +
5022
+ 'offers (a Google Fonts name with EXACT casing, e.g. "Inter") — an unknown/invented family is rejected; ' +
5023
+ "text_decoration is none|underline|" +
5024
+ "line-through; text_transform is none|uppercase|lowercase|capitalize; text_overflow is clip|ellipsis (ellipsis also needs white_space: nowrap here and overflow: hidden in the component CSS); white_space " +
5025
+ "is normal|pre|pre-wrap|pre-line|wrap|nowrap|collapse; line_break is auto|loose|normal|strict|anywhere; word_break " +
5026
+ "is normal|break-all|keep-all; text_wrap_style is auto|balance|pretty|stable. Set `is_default: true` to make " +
5027
+ 'this text style the theme\'s default/global style (the editor\'s right-click "Make Default Style" / "Global ' +
5028
+ "Stil Yap\") — any other default in the group is cleared; `is_default: false` removes the flag. A text style's " +
5029
+ "current default state is readable from `list_theme_globals` (each typography entry's `isDefault`). " +
5030
+ "RESPONSIVE: pass `breakpoint_id` (an existing breakpoint id from `list_theme_globals`) to set that breakpoint's " +
5031
+ "overrides instead of the desktop values. Then ONLY font_size, font_weight, line_height and letter_spacing are " +
5032
+ "allowed, each needs a desktop value on the style first, font_weight is a plain number (the style's italic is kept — italic is " +
5033
+ 'shared by all breakpoints) and an empty string ("") removes that override so the value is inherited again. Overrides cascade ' +
5034
+ "desktop-first and chained: a property a breakpoint does not override comes from the nearest WIDER breakpoint that overrides it, else desktop; `list_theme_globals` returns them per typography " +
5035
+ "entry under `breakpoints` (`overrides` = own values, `resolved` = effective values). Breakpoints are NOT created " +
5036
+ "by this tool. To write SEVERAL breakpoints (optionally together with desktop values) in one call, use " +
5037
+ "`breakpoints` instead of `breakpoint_id`. Requires " +
5038
+ "`ikas theme dev` running with the editor connected.", {
5039
+ project_root: z
5040
+ .string()
5041
+ .describe("Absolute path to the code-component project."),
5042
+ id: z
5043
+ .string()
5044
+ .describe("Text style id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
5045
+ name: z
5046
+ .string()
5047
+ .optional()
5048
+ .describe("Optional NEW name to rename the text style to. NOT used to find the token — lookup is always by id."),
5049
+ ...textStyleFontParams,
5050
+ is_default: z
5051
+ .boolean()
5052
+ .optional()
5053
+ .describe("true → make this the theme's default/global text style (clears any other default); false → remove the " +
5054
+ "default flag. Omit to leave the default state unchanged."),
5055
+ breakpoint_id: z
5056
+ .string()
5057
+ .optional()
5058
+ .describe("Existing theme breakpoint id from `list_theme_globals`. When set, the font params are written as that " +
5059
+ 'breakpoint\'s overrides (font_size/font_weight/line_height/letter_spacing only; "" removes one).'),
5060
+ breakpoints: textStyleBreakpointsParam,
5061
+ port: z
5062
+ .number()
5063
+ .optional()
5064
+ .describe("Dev server WebSocket port (default 5201)."),
5065
+ }, async (input) => {
5066
+ const { project_root, id, name, is_default, breakpoint_id, breakpoints, port, } = input;
5067
+ const args = [
5068
+ "update-text-style",
5069
+ "--id",
5070
+ id,
5071
+ ...(breakpoint_id !== undefined ? ["--breakpoint", breakpoint_id] : []),
5072
+ ...(name !== undefined ? ["--name", name] : []),
5073
+ ...textStyleFontArgs(input),
5074
+ ...textStyleBreakpointsArgs(breakpoints),
5075
+ ...(is_default === true
5076
+ ? ["--default"]
5077
+ : is_default === false
5078
+ ? ["--no-default"]
5079
+ : []),
5080
+ ...(port ? ["--port", String(port)] : []),
5081
+ ];
5082
+ return callEditorAction(project_root, args);
5083
+ });
5084
+ // Tool: update_theme_color
5085
+ server.tool("update_theme_color", "Update an existing theme color token IN PLACE in the connected editor. Prefer this over delete+recreate: " +
5086
+ "it keeps the color's id, so its cssVar (`var(--<id>)`) — and every element style bound to it — stays STABLE. " +
5087
+ "Identify it by `id` (REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally " +
5088
+ "NOT supported here because a theme can have two colors with the same name (e.g. from two different design assets). " +
5089
+ "To rename, pass `name` (the new name) together with `id`. Pass `value` to change the color — a CONCRETE " +
5090
+ 'color (hex/rgb/hsl or a CSS color name), NOT a "var(...)" reference (a color token can\'t alias another ' +
5091
+ "color); omit it to only rename. Requires `ikas-component " +
5092
+ "dev` running with the editor connected.", {
5093
+ project_root: z
5094
+ .string()
5095
+ .describe("Absolute path to the code-component project."),
5096
+ id: z
5097
+ .string()
5098
+ .describe("Color id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
5099
+ name: z
5100
+ .string()
5101
+ .optional()
5102
+ .describe("Optional NEW name to rename the color to. NOT used to find the token — lookup is always by id."),
5103
+ value: z
5104
+ .string()
5105
+ .optional()
5106
+ .describe('New color value — a concrete color (e.g. "#ff0000", rgb/hsl/name), not a "var(...)" reference. Omit to only rename.'),
5107
+ port: z
5108
+ .number()
5109
+ .optional()
5110
+ .describe("Dev server WebSocket port (default 5201)."),
5111
+ }, async ({ project_root, id, name, value, port }) => {
5112
+ const args = [
5113
+ "update-color",
5114
+ "--id",
5115
+ id,
5116
+ ...(name !== undefined ? ["--name", name] : []),
5117
+ ...(value !== undefined ? ["--value", value] : []),
5118
+ ...(port ? ["--port", String(port)] : []),
5119
+ ];
5120
+ return callEditorAction(project_root, args);
5121
+ });
5122
+ // Tool: update_theme_breakpoint
5123
+ server.tool("update_theme_breakpoint", "Update an existing theme breakpoint IN PLACE in the connected editor (keeps its id). Identify it by `id` " +
5124
+ "(REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally NOT supported here " +
5125
+ "because names can collide across design assets. To rename, pass `name` (the new name) together with `id`. " +
5126
+ "Pass `width` (px) to change it; omit it to only rename. " +
5127
+ "Requires `ikas theme dev` running with the editor connected.", {
5128
+ project_root: z
5129
+ .string()
5130
+ .describe("Absolute path to the code-component project."),
5131
+ id: z
5132
+ .string()
5133
+ .describe("Breakpoint id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
5134
+ name: z
5135
+ .string()
5136
+ .optional()
5137
+ .describe("Optional NEW name to rename the breakpoint to. NOT used to find the token — lookup is always by id."),
5138
+ width: z
5139
+ .number()
5140
+ .int()
5141
+ .optional()
5142
+ .describe("New breakpoint width in px (positive integer, no decimals). Omit to only rename."),
5143
+ port: z
5144
+ .number()
5145
+ .optional()
5146
+ .describe("Dev server WebSocket port (default 5201)."),
5147
+ }, async ({ project_root, id, name, width, port }) => {
5148
+ const args = [
5149
+ "update-breakpoint",
5150
+ "--id",
5151
+ id,
5152
+ ...(name !== undefined ? ["--name", name] : []),
5153
+ ...(width !== undefined ? ["--width", String(width)] : []),
5154
+ ...(port ? ["--port", String(port)] : []),
5155
+ ];
5156
+ return callEditorAction(project_root, args);
5157
+ });
5158
+ // Tool: update_theme_color_scheme
5159
+ server.tool("update_theme_color_scheme", "Update an existing theme color scheme (palette) IN PLACE in the connected editor. Prefer this over " +
5160
+ "delete+recreate: it keeps the scheme's id, so its className (`_<id>`) stays STABLE. Identify it by `id` " +
5161
+ "(REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally NOT supported here " +
5162
+ "because names can collide across design assets. To rename, pass `name` (the new name) together with `id`. " +
5163
+ "`colors` is an array of { slotId? | newSlotName?, value } — each entry targets ONE slot, EITHER by " +
5164
+ "`slotId` (an EXISTING slot's id, from list_theme_globals colorsByScheme keys / colorSchemes.schemes — the " +
5165
+ "id-keyed path; slot names ARE listed in colorSchemes.schemes but are not unique, so prefer the scheme's colorsByScheme keys to get the right id) OR by `newSlotName` (create/reuse " +
5166
+ 'a slot by name; use the standard slot names, "/" to group, e.g. "PrimaryButton/Background"); value = a ' +
5167
+ 'literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" from ' +
5168
+ "list_theme_globals to store it as a LINKED reference — pass the cssVar, not a hex copied from a global color) " +
5169
+ "and MERGES by slot — only the slots you pass change. Pass `colors` as REAL " +
5170
+ "JSON (not a stringified array). Set `is_default: true` to make this the theme's DEFAULT scheme (the " +
5171
+ "fallback whose colors fill any slot a non-default scheme leaves unset); this is exclusive — the editor " +
5172
+ "automatically clears the default flag from any other scheme in the same group, so there is always exactly " +
5173
+ "one default. Set `is_default: false` to remove the default flag from this scheme. Omit all of name/colors/" +
5174
+ "is_default to no-op. Requires `ikas theme dev` running with the editor connected.", {
5175
+ project_root: z
5176
+ .string()
5177
+ .describe("Absolute path to the code-component project."),
5178
+ id: z
5179
+ .string()
5180
+ .describe("Color scheme id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
5181
+ name: z
5182
+ .string()
5183
+ .optional()
5184
+ .describe("Optional NEW name to rename the color scheme to. NOT used to find the token — lookup is always by id."),
5185
+ colors: z
5186
+ .any()
5187
+ .optional()
5188
+ .describe('Array of { slotId? | newSlotName?, value } to set — target an existing slot by `slotId` (from list_theme_globals colorsByScheme keys / colorSchemes.schemes) or create/reuse by `newSlotName`; value = a literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" (linked reference). Merges by slot. Omit to only rename.'),
5189
+ is_default: z
5190
+ .boolean()
5191
+ .optional()
5192
+ .describe("true = make this the default scheme (exclusive — the editor clears the default flag from every other scheme in its group); false = remove the default flag. Omit to leave the default unchanged. The result echoes the persisted `isDefault`."),
5193
+ port: z
5194
+ .number()
5195
+ .optional()
5196
+ .describe("Dev server WebSocket port (default 5201)."),
5197
+ }, async ({ project_root, id, name, colors, is_default, port }) => {
5198
+ const args = [
5199
+ "update-color-scheme",
5200
+ "--id",
5201
+ id,
5202
+ ...(name !== undefined ? ["--name", name] : []),
5203
+ ...(colors !== undefined ? ["--colors", toJsonArrayArg(colors)] : []),
5204
+ ...(is_default === true
5205
+ ? ["--default"]
5206
+ : is_default === false
5207
+ ? ["--no-default"]
5208
+ : []),
5209
+ ...(port ? ["--port", String(port)] : []),
5210
+ ];
5211
+ return callEditorAction(project_root, args);
5212
+ });
5213
+ // Tool: rename_theme_color_scheme_slot
5214
+ server.tool("rename_theme_color_scheme_slot", 'Rename a color scheme SLOT (a scheme key like "Background" or "PrimaryButton/Text") IN PLACE in the ' +
5215
+ "connected editor. A slot's id is STABLE, so renaming keeps every runtime reference intact " +
5216
+ "(`var(--<slotId>)` in CSS, `colorsByScheme[slotId]` in component code) — only the human display name " +
5217
+ "changes; nothing rebinds. Identify the slot by `id` (REQUIRED — the slot id from `list_theme_globals` → " +
5218
+ "colorSchemes.schemes[].id or a `colorsByScheme` key); name-based lookup is intentionally NOT supported " +
5219
+ 'because slot names can collide across design assets. `name` is the NEW slot name (a "/" groups it in the ' +
5220
+ 'editor UI, e.g. "PrimaryButton/Background"). Only non-design-asset (user/theme) slots can be renamed here. ' +
5221
+ "This renames the slot itself across ALL schemes that use it (a slot is shared) — it does NOT rename a single " +
5222
+ "scheme/palette (for that use `update_theme_color_scheme`). Requires `ikas theme dev` running with the " +
5223
+ "editor connected.", {
5224
+ project_root: z
5225
+ .string()
5226
+ .describe("Absolute path to the code-component project."),
5227
+ id: z
5228
+ .string()
5229
+ .min(1, "id is REQUIRED — the slot id from list_theme_globals (colorSchemes.schemes[].id / colorsByScheme keys).")
5230
+ .describe("Slot id (REQUIRED) from `list_theme_globals` → colorSchemes.schemes[].id / colorsByScheme keys. The slot is always identified by id."),
5231
+ name: z
5232
+ .string()
5233
+ .min(1, "name is REQUIRED — the new slot name (non-empty).")
5234
+ .describe('The NEW slot name (non-empty). A "/" groups it in the editor UI (e.g. "PrimaryButton/Background").'),
5235
+ port: z
5236
+ .number()
5237
+ .optional()
5238
+ .describe("Dev server WebSocket port (default 5201)."),
5239
+ }, async ({ project_root, id, name, port }) => {
5240
+ const args = [
5241
+ "rename-color-scheme-slot",
5242
+ "--id",
5243
+ id,
5244
+ "--name",
5245
+ name,
5246
+ ...(port ? ["--port", String(port)] : []),
5247
+ ];
5248
+ return callEditorAction(project_root, args);
5249
+ });
5250
+ // Tool: delete_theme_global
5251
+ server.tool("delete_theme_global", 'Delete a theme global setting from the connected editor. For `kind: globalVariable` pass `name` (the runtime key); for design-token kinds (color | typography | breakpoint | keyframe | colorScheme) pass the token `id`. For `kind: colorSchemeSlot` pass the color SLOT id (from `list_theme_globals` → colorSchemes.schemes[].id or a `colorsByScheme` key) — this deletes the slot itself across ALL schemes (use it to clean up a junk slot created by a typo); it CASCADES: the slot\'s color is removed from every scheme and any element/component style bound to that slot is cleared, so only delete a slot you are sure is unused. Only non-design-asset (user/theme) slots can be deleted here. Get names/ids from `list_theme_globals`. Deleting a non-existent id fails with a "not found" error (it does NOT report a false success), so a success result means the token really existed and was removed.', {
5252
+ project_root: z
5253
+ .string()
5254
+ .describe("Absolute path to the code-component project."),
5255
+ kind: z
5256
+ .enum([
5257
+ "globalVariable",
5258
+ "color",
5259
+ "typography",
5260
+ "breakpoint",
5261
+ "keyframe",
5262
+ "colorScheme",
5263
+ "colorSchemeSlot",
5264
+ ])
5265
+ .describe("What to delete."),
5266
+ name: z
5267
+ .string()
5268
+ .optional()
5269
+ .describe("globalVariable runtime key (from `list_theme_globals`)."),
5270
+ id: z
5271
+ .string()
5272
+ .optional()
5273
+ .describe("design-token id, or for colorSchemeSlot the slot id from `list_theme_globals` → colorSchemes.schemes."),
5274
+ port: z
5275
+ .number()
5276
+ .optional()
5277
+ .describe("Dev server WebSocket port (default 5201)."),
5278
+ }, async ({ project_root, kind, name, id, port }) => {
5279
+ const p = port ? ["--port", String(port)] : [];
5280
+ const args = kind === "globalVariable"
5281
+ ? ["delete-global-variable", "--name", String(name ?? ""), ...p]
5282
+ : [
5283
+ "delete-design-token",
5284
+ "--token-type",
5285
+ kind,
5286
+ "--id",
5287
+ String(id ?? ""),
5288
+ ...p,
5289
+ ];
5290
+ return callEditorAction(project_root, args);
5291
+ });
3720
5292
  // --- Start server ---
3721
5293
  async function main() {
3722
5294
  const transport = new StdioServerTransport();