kardalum 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/control/audit/index.js +1 -1
  2. package/dist/control/completion/tree.js +20 -6
  3. package/dist/control/plugins/read.js +9 -2
  4. package/dist/control/usage.d.ts +1 -1
  5. package/dist/control/usage.js +3 -1
  6. package/dist/dev/companions.d.ts +76 -0
  7. package/dist/dev/companions.js +197 -0
  8. package/dist/dev/config.d.ts +10 -0
  9. package/dist/dev/config.js +30 -1
  10. package/dist/dev/local-plugin.d.ts +18 -0
  11. package/dist/dev/local-plugin.js +36 -9
  12. package/dist/dev/needed-plugins.d.ts +11 -0
  13. package/dist/dev/needed-plugins.js +25 -0
  14. package/dist/dev/sandbox-env-policy.js +16 -0
  15. package/dist/dev/sandbox.d.ts +12 -1
  16. package/dist/dev/sandbox.js +146 -8
  17. package/dist/dev/usage.d.ts +1 -1
  18. package/dist/dev/usage.js +8 -0
  19. package/dist/plugin/build-federation-bundle.d.ts +2 -2
  20. package/dist/plugin/build-federation-bundle.js +18 -6
  21. package/dist/plugin/build.d.ts +4 -0
  22. package/dist/plugin/build.js +5 -4
  23. package/dist/plugin/checks/rich-text-update.d.ts +5 -0
  24. package/dist/plugin/checks/rich-text-update.js +42 -0
  25. package/dist/plugin/checks/service-contracts.d.ts +16 -0
  26. package/dist/plugin/checks/service-contracts.js +153 -0
  27. package/dist/plugin/checks/typescript-worker.js +4 -1
  28. package/dist/plugin/contracts/contract-command.d.ts +16 -0
  29. package/dist/plugin/contracts/contract-command.js +50 -0
  30. package/dist/plugin/contracts/folder.d.ts +22 -0
  31. package/dist/plugin/contracts/folder.js +78 -0
  32. package/dist/plugin/index.js +28 -1
  33. package/dist/plugin/layer-stylesheets.d.ts +2 -0
  34. package/dist/plugin/layer-stylesheets.js +18 -0
  35. package/dist/plugin/load-manifest.js +4 -1
  36. package/dist/plugin/pack.d.ts +4 -0
  37. package/dist/plugin/publish.d.ts +6 -0
  38. package/dist/plugin/publish.js +7 -2
  39. package/dist/plugin/usage.d.ts +1 -1
  40. package/dist/plugin/usage.js +8 -0
  41. package/dist/plugin/validate.d.ts +5 -0
  42. package/dist/plugin/validate.js +12 -2
  43. package/dist/plugin/write-manifest-json.d.ts +1 -1
  44. package/dist/plugin/write-manifest-json.js +135 -11
  45. package/node_modules/@kardalum/api-schemas/dist/ai-app-hosts.d.ts +21 -0
  46. package/node_modules/@kardalum/api-schemas/dist/ai-app-hosts.js +39 -0
  47. package/node_modules/@kardalum/api-schemas/dist/ai-app-redirects.d.ts +2 -0
  48. package/node_modules/@kardalum/api-schemas/dist/ai-app-redirects.js +31 -0
  49. package/node_modules/@kardalum/api-schemas/dist/ai-connections.schema.d.ts +127 -8
  50. package/node_modules/@kardalum/api-schemas/dist/ai-connections.schema.js +82 -7
  51. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +5 -1
  52. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +2 -2
  53. package/node_modules/@kardalum/api-schemas/dist/built-in-editor-ids.d.ts +7 -0
  54. package/node_modules/@kardalum/api-schemas/dist/built-in-editor-ids.js +11 -0
  55. package/node_modules/@kardalum/api-schemas/dist/capability-detail.d.ts +1 -1
  56. package/node_modules/@kardalum/api-schemas/dist/capability-detail.js +18 -0
  57. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +80 -0
  58. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +41 -2
  59. package/node_modules/@kardalum/api-schemas/dist/content-reads.schema.d.ts +213 -0
  60. package/node_modules/@kardalum/api-schemas/dist/content-reads.schema.js +234 -0
  61. package/node_modules/@kardalum/api-schemas/dist/contribution-issues.d.ts +11 -0
  62. package/node_modules/@kardalum/api-schemas/dist/contribution-issues.js +14 -0
  63. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +50 -13
  64. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +19 -10
  65. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +77 -0
  66. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +37 -0
  67. package/node_modules/@kardalum/api-schemas/dist/experimental-points.d.ts +19 -0
  68. package/node_modules/@kardalum/api-schemas/dist/experimental-points.js +250 -0
  69. package/node_modules/@kardalum/api-schemas/dist/form-protection-callers.d.ts +29 -0
  70. package/node_modules/@kardalum/api-schemas/dist/form-protection-callers.js +31 -0
  71. package/node_modules/@kardalum/api-schemas/dist/html-scan.d.ts +22 -0
  72. package/node_modules/@kardalum/api-schemas/dist/html-scan.js +122 -0
  73. package/node_modules/@kardalum/api-schemas/dist/html-start-tags.d.ts +48 -0
  74. package/node_modules/@kardalum/api-schemas/dist/html-start-tags.js +381 -0
  75. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +52 -14
  76. package/node_modules/@kardalum/api-schemas/dist/index.js +53 -9
  77. package/node_modules/@kardalum/api-schemas/dist/json-depth.d.ts +3 -0
  78. package/node_modules/@kardalum/api-schemas/dist/json-depth.js +20 -0
  79. package/node_modules/@kardalum/api-schemas/dist/mail-rules.d.ts +4 -2
  80. package/node_modules/@kardalum/api-schemas/dist/mail-rules.js +6 -1
  81. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +178 -2
  82. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +10 -0
  83. package/node_modules/@kardalum/api-schemas/dist/mcp-plugins.schema.d.ts +3 -3
  84. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +16 -0
  85. package/node_modules/@kardalum/api-schemas/dist/media.schema.d.ts +4 -0
  86. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +4 -0
  87. package/node_modules/@kardalum/api-schemas/dist/nested-validation.d.ts +7 -0
  88. package/node_modules/@kardalum/api-schemas/dist/nested-validation.js +51 -2
  89. package/node_modules/@kardalum/api-schemas/dist/page-audience.schema.d.ts +87 -0
  90. package/node_modules/@kardalum/api-schemas/dist/page-audience.schema.js +44 -0
  91. package/node_modules/@kardalum/api-schemas/dist/plugin-admin-slots.d.ts +11 -0
  92. package/node_modules/@kardalum/api-schemas/dist/plugin-admin-slots.js +61 -0
  93. package/node_modules/@kardalum/api-schemas/dist/plugin-content-access.d.ts +4 -2
  94. package/node_modules/@kardalum/api-schemas/dist/plugin-content-access.js +12 -2
  95. package/node_modules/@kardalum/api-schemas/dist/plugin-content-slots.d.ts +136 -0
  96. package/node_modules/@kardalum/api-schemas/dist/plugin-content-slots.js +254 -0
  97. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-checks.d.ts +22 -0
  98. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-checks.js +66 -0
  99. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-document.d.ts +130 -0
  100. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-document.js +173 -0
  101. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-fetch.d.ts +16 -0
  102. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-fetch.js +112 -0
  103. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-schema.d.ts +70 -0
  104. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-schema.js +380 -0
  105. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-types.d.ts +3 -0
  106. package/node_modules/@kardalum/api-schemas/dist/plugin-contract-types.js +68 -0
  107. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +18 -0
  108. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +18 -0
  109. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +5 -2
  110. package/node_modules/@kardalum/api-schemas/dist/plugin-durable-hooks.d.ts +10 -2
  111. package/node_modules/@kardalum/api-schemas/dist/plugin-durable-hooks.js +48 -1
  112. package/node_modules/@kardalum/api-schemas/dist/plugin-editor-extensions.d.ts +5 -2
  113. package/node_modules/@kardalum/api-schemas/dist/plugin-editor-extensions.js +6 -4
  114. package/node_modules/@kardalum/api-schemas/dist/plugin-events.d.ts +24 -0
  115. package/node_modules/@kardalum/api-schemas/dist/plugin-events.js +53 -0
  116. package/node_modules/@kardalum/api-schemas/dist/plugin-guards.d.ts +112 -0
  117. package/node_modules/@kardalum/api-schemas/dist/plugin-guards.js +118 -0
  118. package/node_modules/@kardalum/api-schemas/dist/plugin-held-embeds.d.ts +12 -0
  119. package/node_modules/@kardalum/api-schemas/dist/plugin-held-embeds.js +3 -0
  120. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +2 -0
  121. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +3 -0
  122. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +67 -0
  123. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +15 -0
  124. package/node_modules/@kardalum/api-schemas/dist/plugin-kept-parts.d.ts +138 -0
  125. package/node_modules/@kardalum/api-schemas/dist/plugin-kept-parts.js +110 -0
  126. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +80 -15
  127. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +67 -23
  128. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +10 -3
  129. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +33 -8
  130. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +2 -1
  131. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +7 -1
  132. package/node_modules/@kardalum/api-schemas/dist/plugin-outbound.d.ts +1 -1
  133. package/node_modules/@kardalum/api-schemas/dist/plugin-providers.d.ts +43 -7
  134. package/node_modules/@kardalum/api-schemas/dist/plugin-providers.js +36 -5
  135. package/node_modules/@kardalum/api-schemas/dist/plugin-rich-text.d.ts +638 -0
  136. package/node_modules/@kardalum/api-schemas/dist/plugin-rich-text.js +533 -0
  137. package/node_modules/@kardalum/api-schemas/dist/plugin-service-call.d.ts +36 -0
  138. package/node_modules/@kardalum/api-schemas/dist/plugin-service-call.js +32 -0
  139. package/node_modules/@kardalum/api-schemas/dist/plugin-service-connections.d.ts +193 -0
  140. package/node_modules/@kardalum/api-schemas/dist/plugin-service-connections.js +123 -0
  141. package/node_modules/@kardalum/api-schemas/dist/plugin-service-declarations.d.ts +209 -0
  142. package/node_modules/@kardalum/api-schemas/dist/plugin-service-declarations.js +372 -0
  143. package/node_modules/@kardalum/api-schemas/dist/plugin-services.d.ts +90 -0
  144. package/node_modules/@kardalum/api-schemas/dist/plugin-services.js +204 -0
  145. package/node_modules/@kardalum/api-schemas/dist/plugin-settings.d.ts +10 -0
  146. package/node_modules/@kardalum/api-schemas/dist/plugin-settings.js +10 -1
  147. package/node_modules/@kardalum/api-schemas/dist/plugin-site-extensions.d.ts +171 -4
  148. package/node_modules/@kardalum/api-schemas/dist/plugin-site-extensions.js +406 -42
  149. package/node_modules/@kardalum/api-schemas/dist/plugin-site-requests.d.ts +69 -0
  150. package/node_modules/@kardalum/api-schemas/dist/plugin-site-requests.js +149 -0
  151. package/node_modules/@kardalum/api-schemas/dist/plugin-styles.d.ts +5 -0
  152. package/node_modules/@kardalum/api-schemas/dist/plugin-styles.js +13 -0
  153. package/node_modules/@kardalum/api-schemas/dist/plugin-uploads.d.ts +96 -0
  154. package/node_modules/@kardalum/api-schemas/dist/plugin-uploads.js +185 -0
  155. package/node_modules/@kardalum/api-schemas/dist/plugin-user-accounts.d.ts +213 -0
  156. package/node_modules/@kardalum/api-schemas/dist/plugin-user-accounts.js +131 -0
  157. package/node_modules/@kardalum/api-schemas/dist/plugin-view-kit.d.ts +54 -0
  158. package/node_modules/@kardalum/api-schemas/dist/plugin-view-kit.js +154 -0
  159. package/node_modules/@kardalum/api-schemas/dist/plugin-visitor-points.d.ts +37 -0
  160. package/node_modules/@kardalum/api-schemas/dist/plugin-visitor-points.js +124 -0
  161. package/node_modules/@kardalum/api-schemas/dist/render-cache.d.ts +126 -0
  162. package/node_modules/@kardalum/api-schemas/dist/render-cache.js +263 -0
  163. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +303 -0
  164. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +61 -0
  165. package/node_modules/@kardalum/api-schemas/dist/rich-text-paste-hosts.d.ts +14 -0
  166. package/node_modules/@kardalum/api-schemas/dist/rich-text-paste-hosts.js +108 -0
  167. package/node_modules/@kardalum/api-schemas/dist/rich-text-shape.d.ts +66 -1
  168. package/node_modules/@kardalum/api-schemas/dist/rich-text-shape.js +465 -7
  169. package/node_modules/@kardalum/api-schemas/dist/rich-text-text.js +15 -118
  170. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +110 -0
  171. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +36 -0
  172. package/node_modules/@kardalum/api-schemas/dist/security-overview.schema.d.ts +64 -0
  173. package/node_modules/@kardalum/api-schemas/dist/security-overview.schema.js +38 -0
  174. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.d.ts +9 -2
  175. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.js +7 -2
  176. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +26 -0
  177. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +19 -0
  178. package/node_modules/@kardalum/api-schemas/dist/sign-in-steps.d.ts +724 -0
  179. package/node_modules/@kardalum/api-schemas/dist/sign-in-steps.js +408 -0
  180. package/node_modules/@kardalum/api-schemas/dist/sign-in.schema.d.ts +5 -3
  181. package/node_modules/@kardalum/api-schemas/dist/sign-in.schema.js +3 -1
  182. package/node_modules/@kardalum/api-schemas/dist/site-consent.d.ts +77 -0
  183. package/node_modules/@kardalum/api-schemas/dist/site-consent.js +122 -0
  184. package/node_modules/@kardalum/api-schemas/dist/structured-fields.schema.d.ts +4 -0
  185. package/node_modules/@kardalum/api-schemas/dist/structured-fields.schema.js +28 -0
  186. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +33 -0
  187. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +26 -1
  188. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +14 -0
  189. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +2 -0
  190. package/node_modules/@kardalum/api-schemas/dist/visitor-accounts.d.ts +482 -0
  191. package/node_modules/@kardalum/api-schemas/dist/visitor-accounts.js +380 -0
  192. package/node_modules/@kardalum/api-schemas/dist/visitor-groups.d.ts +109 -0
  193. package/node_modules/@kardalum/api-schemas/dist/visitor-groups.js +62 -0
  194. package/node_modules/@kardalum/api-schemas/package.json +1 -0
  195. package/node_modules/@kardalum/mcp-tools/package.json +3 -3
  196. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +17 -0
  197. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +9 -0
  198. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +1 -1
  199. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +276 -19
  200. package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +1 -1
  201. package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +23 -0
  202. package/node_modules/@kardalum/plugin-package/dist/contract-fingerprint.d.ts +17 -0
  203. package/node_modules/@kardalum/plugin-package/dist/contract-fingerprint.js +39 -0
  204. package/node_modules/@kardalum/plugin-package/dist/delivery/admin-styles.d.ts +23 -0
  205. package/node_modules/@kardalum/plugin-package/dist/delivery/admin-styles.js +351 -0
  206. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +2 -0
  207. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +1 -1
  208. package/node_modules/@kardalum/plugin-package/dist/delivery/content-access.js +21 -8
  209. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +1 -1
  210. package/node_modules/@kardalum/plugin-package/dist/delivery/editor-extensions.js +23 -10
  211. package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +3 -2
  212. package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +2 -0
  213. package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +2 -0
  214. package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +30 -2
  215. package/node_modules/@kardalum/plugin-package/dist/delivery/licence-check.js +6 -2
  216. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +6 -0
  217. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +6 -0
  218. package/node_modules/@kardalum/plugin-package/dist/delivery/providers.d.ts +2 -0
  219. package/node_modules/@kardalum/plugin-package/dist/delivery/providers.js +24 -6
  220. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +15 -0
  221. package/node_modules/@kardalum/plugin-package/dist/delivery/rich-text.d.ts +2 -0
  222. package/node_modules/@kardalum/plugin-package/dist/delivery/rich-text.js +173 -0
  223. package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +1 -1
  224. package/node_modules/@kardalum/plugin-package/dist/delivery/server-powers.js +14 -4
  225. package/node_modules/@kardalum/plugin-package/dist/delivery/services-events.d.ts +3 -0
  226. package/node_modules/@kardalum/plugin-package/dist/delivery/services-events.js +35 -0
  227. package/node_modules/@kardalum/plugin-package/dist/delivery/sign-in-steps.d.ts +3 -0
  228. package/node_modules/@kardalum/plugin-package/dist/delivery/sign-in-steps.js +71 -0
  229. package/node_modules/@kardalum/plugin-package/dist/delivery/site-extensions.js +44 -11
  230. package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +7 -0
  231. package/node_modules/@kardalum/plugin-package/dist/delivery/user-accounts.d.ts +3 -0
  232. package/node_modules/@kardalum/plugin-package/dist/delivery/user-accounts.js +36 -0
  233. package/node_modules/@kardalum/plugin-package/dist/delivery/visitor-points.d.ts +3 -0
  234. package/node_modules/@kardalum/plugin-package/dist/delivery/visitor-points.js +33 -0
  235. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +4 -0
  236. package/node_modules/@kardalum/plugin-package/dist/index.js +5 -0
  237. package/node_modules/@kardalum/plugin-package/dist/public-suffix.d.ts +7 -0
  238. package/node_modules/@kardalum/plugin-package/dist/public-suffix.js +23 -0
  239. package/node_modules/@kardalum/plugin-package/dist/rich-text-summary.d.ts +1 -0
  240. package/node_modules/@kardalum/plugin-package/dist/rich-text-summary.js +27 -0
  241. package/node_modules/@kardalum/plugin-package/dist/stylesheet-load-hook.d.ts +2 -0
  242. package/node_modules/@kardalum/plugin-package/dist/stylesheet-load-hook.js +28 -0
  243. package/node_modules/@kardalum/plugin-package/package.json +4 -0
  244. package/package.json +8 -6
@@ -31,7 +31,7 @@ async function filtersOf(args) {
31
31
  const { AuditActorKindSchema } = await import("@kardalum/api-schemas");
32
32
  const parsed = AuditActorKindSchema.safeParse(kind);
33
33
  if (!parsed.success)
34
- throw new UsageError("--kind must be session, key, site or anonymous.");
34
+ throw new UsageError("--kind must be session, key, site, plugin, visitor or anonymous.");
35
35
  filters.actorKind = parsed.data;
36
36
  }
37
37
  const status = stringOption(args, "status");
@@ -35,17 +35,31 @@ function hand(name, subs) {
35
35
  children: subs.map((sub) => ({ name: sub.name, flags: ["--help", ...sub.flags], valueFlags: sub.valueFlags, children: [] })),
36
36
  };
37
37
  }
38
+ /** `plugin` and its `contract add` / `contract export` pair (M35 B1c): every word takes the plugin parser's flags. */
39
+ function pluginNode() {
40
+ const flags = ["--json", "--out", "--scramble", "--registry", "--token", "--online"];
41
+ const valueFlags = ["--out", "--registry", "--token"];
42
+ const leaf = (name) => ({ name, flags: ["--help", ...flags], valueFlags, children: [] });
43
+ return {
44
+ name: "plugin",
45
+ flags: ["--help"],
46
+ valueFlags: [],
47
+ children: [...["validate", "build", "bundle-server", "pack", "publish"].map(leaf), { ...leaf("contract"), children: [leaf("add"), leaf("export")] }],
48
+ };
49
+ }
38
50
  /**
39
51
  * `dev`, `plugin` and `mcp` have their own parsers (src/dev/config.ts, src/plugin/index.ts, src/mcp/index.ts) and are not in the
40
52
  * dispatcher's table, so their words are written here. The completion test checks every word against USAGE.
41
53
  */
42
54
  export const HAND_COMMANDS = [
43
- hand("dev", [{ name: "start", flags: ["--db", "--server-port", "--plugin-port", "--server-version", "--marketplace"], valueFlags: ["--db", "--server-port", "--plugin-port", "--server-version"] }]),
44
- hand("plugin", ["validate", "build", "bundle-server", "pack", "publish"].map((name) => ({
45
- name,
46
- flags: ["--json", "--out", "--scramble", "--registry", "--token"],
47
- valueFlags: ["--out", "--registry", "--token"],
48
- }))),
55
+ hand("dev", [
56
+ {
57
+ name: "start",
58
+ flags: ["--db", "--server-port", "--plugin-port", "--server-version", "--marketplace", "--with", "--with-optional"],
59
+ valueFlags: ["--db", "--server-port", "--plugin-port", "--server-version", "--with"],
60
+ },
61
+ ]),
62
+ pluginNode(),
49
63
  // `kardalum mcp` takes no subcommand: its flags are its own (src/mcp/index.ts).
50
64
  { name: "mcp", flags: ["--help", "--allow-production", "--allow-private-urls", "--profile"], valueFlags: ["--profile"], children: [] },
51
65
  ];
@@ -52,6 +52,11 @@ export const installRecord = {
52
52
  return EXIT.ok;
53
53
  },
54
54
  };
55
+ /** The records a snapshot group holds beside its tables, or "-" when none. */
56
+ function recordsCell(records) {
57
+ const held = [...(records?.settings ? ["settings"] : []), ...(records?.userFields ? ["account fields"] : [])];
58
+ return held.length === 0 ? "-" : held.join(", ");
59
+ }
55
60
  export const snapshots = {
56
61
  remote: true,
57
62
  async run({ ctx, args, client }) {
@@ -60,8 +65,10 @@ export const snapshots = {
60
65
  return runList(ctx, args, {
61
66
  max: PAGE_MAX.pluginSnapshotGroups,
62
67
  fetch: (query) => api.manage.plugins.listSnapshotGroups(id, query),
63
- headers: ["group", "taken", "trigger", "tables", "status"],
64
- row: (g) => [g.snapshotGroupId, g.takenAt, g.trigger, `${g.tableNames.length} of ${g.totalTableCount}`, g.status],
68
+ // M35 U1 (D1): a group may hold an uninstall's records beside or instead of tables, so the owner
69
+ // can tell a group of no tables still holds values (and delete it for an erasure).
70
+ headers: ["group", "taken", "trigger", "tables", "records", "status"],
71
+ row: (g) => [g.snapshotGroupId, g.takenAt, g.trigger, `${g.tableNames.length} of ${g.totalTableCount}`, recordsCell(g.records), g.status],
65
72
  });
66
73
  },
67
74
  };
@@ -8,7 +8,7 @@ export declare const TYPES_USAGE = "kardalum types: document types\n\nUsage:\n
8
8
  export declare const DATATYPES_USAGE = "kardalum datatypes: data types (named, configured editors for fields)\n\nUsage:\n kardalum datatypes list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum datatypes get <id> [--json]\n kardalum datatypes create --name <text> --editor <editor id> [--settings <file|->]\n kardalum datatypes update <id> [--name <text>] [--settings <file|->]\n kardalum datatypes delete <id> [--yes] [--dry-run]\n\nOptions:\n --name <text> create: the data type's name; update: rename it\n --editor <editor id> create: the editor it configures, such as com.kardalum.text (cannot change)\n --settings <file|-> The editor's settings as a JSON object; on update it replaces the settings\n -h, --help Show this help and exit\n\nThe editor of a data type cannot be changed. delete asks first; the server refuses a built-in data\ntype, and refuses while a document type has a field of the data type, naming those types. delete\nreads the data type first to name it, so a key profile needs dataTypes.read beside dataTypes.delete.\n\nExamples:\n kardalum datatypes list\n kardalum datatypes create --name \"Short text\" --editor com.kardalum.text";
9
9
  export declare const TEMPLATES_USAGE = "kardalum templates: render templates\n\nUsage:\n kardalum templates list [--kind page|layout|partial] [--document-type <name|id>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates get <id> [--json]\n kardalum templates create --name <text> [--alias <alias>] [--kind page|layout|partial]\n [--document-type <name|id>] [--content <file|->]\n kardalum templates update <id> [--name <text>] [--content <file|->] [--base-version <n>]\n kardalum templates delete <id> [--yes] [--dry-run]\n kardalum templates sync\n kardalum templates versions <id> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates version <id> <n> [--json]\n kardalum templates make-current <id> <n> [--yes] [--dry-run]\n kardalum templates trash [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates restore <id> [--yes] [--dry-run]\n\nOptions:\n --name <text> create: the template's name; update: rename it\n --alias <alias> create: its file name inside its kind's folder (default: made from the name)\n --kind page|layout|partial\n list: only this kind; create: the kind, which picks the folder\n (default page)\n --document-type <name|id>\n list: only the templates of this document type; create: the document\n type it renders\n --content <file|-> The template source, from a file or standard input (the site's template limit applies: 1 MiB unless KARDALUM_MAX_TEMPLATE_BYTES raises it)\n --base-version <n> Refuse the save when the template has moved past version n (exit 5)\n -h, --help Show this help and exit\n\nTemplates are addressed by id. delete asks first, naming the document types that use the template as\ntheir default and whether it is the catch-all; a confirmed delete clears those pointers.\n\nA template's file is templates/<pages|layouts|partials>/<alias>.liquid: the folder is the kind, and\naliases are unique per kind. list prints three sections, Pages, Layouts and Partials; --kind lists one\n(a --cursor belongs to one kind's list, so it needs --kind). create writes the file into its kind's\nfolder and refuses an alias whose first folder is pages, layouts or partials (a one-segment alias such\nas \"pages\" is an ordinary name). sync reads the template files in the three folders on the server's\ndisk, updates the stored versions from them and adopts a file no template owns; it names every other\nentry at the top of the templates folder as ignored, and moves nothing.\n\nversions lists a template's history, newest first; version prints one with its text. make-current\nasks first, then makes a stored version the one the site renders and writes it to the template file;\nno version is changed, and the next save becomes the version after the newest. trash lists trashed\ntemplates; restore asks first, then brings one back with its history and its file, as the site's own\n(a plugin that shipped it no longer tracks it; exit 5 when a live template uses its alias now).\n\nExamples:\n kardalum templates get 4f2a... --json\n kardalum templates update 4f2a... --content ./article.liquid --base-version 3\n kardalum templates versions 4f2a...\n kardalum templates make-current 4f2a... 2 --dry-run";
10
10
  export declare const SNAPSHOTS_USAGE = "kardalum snapshots: snapshots of which version of each page is published\n\nUsage:\n kardalum snapshots list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum snapshots create <label> [--description <text>]\n kardalum snapshots restore <id> [--yes] [--dry-run]\n kardalum snapshots delete <id> [--yes] [--dry-run]\n\nOptions:\n --description <text> create: a longer note kept beside the label\n -h, --help Show this help and exit\n\nrestore repoints the published version of every page the snapshot recorded, all at once. It asks\nfirst, naming how many page versions and pages move. Pages created since keep their state and no\nversion is deleted. The restore runs in one transaction: if it fails, no page moves.\ndelete asks first and removes the snapshot's record only; no page changes.\nThese are site snapshots; a plugin's data snapshots are `kardalum plugins snapshots <id>`.\n\nExamples:\n kardalum snapshots create \"Before the redesign\"\n kardalum snapshots restore 4f2a... --profile staging --dry-run";
11
- export declare const AUDIT_USAGE = "kardalum audit: the site's audit log, who did what and from where\n\nUsage:\n kardalum audit list [--limit <n>] [--all] [--cursor <c>] [--json]\n [--from <time>] [--to <time>] [--kind <kind>] [--user <id>]\n [--key <id>] [--ip <address>] [--route <pattern>] [--status <code>]\n kardalum audit export --period <YYYY-MM> [--out <file>]\n\nOptions:\n --from, --to <time> Entries at or after, at or before this time (ISO 8601: 2026-10-01T00:00:00Z)\n --kind <kind> session, key, site or anonymous\n --user <id> Only the entries of this user id\n --key <id> Only the entries of this API key id\n --ip <address> Only the entries from this address\n --route <pattern> Only this registered route, such as /api/manage/v1/content/:id/publish\n --status <code> Only this HTTP status\n --period <YYYY-MM> The month to export, in UTC\n --out <file> Write the export to this file instead of standard output\n -h, --help Show this help and exit\n\nlist prints the newest entries first, and says on standard error how many entries the server\ncould not record since it started, when there are any. export prints one JSON object per line\n(NDJSON), oldest first, and is itself recorded in the log. Piped into a command that stops\nreading early, such as head, either ends quietly: with 0, or with the run's own code when it\nhad already failed. The key needs managementApi.use with\naudit.read for list and audit.export for export: administrator actions, because every entry\ncarries the name and email of who acted.\n\nExamples:\n kardalum audit list --kind key --status 403 --json\n kardalum audit export --period 2026-10 --out audit-2026-10.ndjson --profile production";
11
+ export declare const AUDIT_USAGE = "kardalum audit: the site's audit log, who did what and from where\n\nUsage:\n kardalum audit list [--limit <n>] [--all] [--cursor <c>] [--json]\n [--from <time>] [--to <time>] [--kind <kind>] [--user <id>]\n [--key <id>] [--ip <address>] [--route <pattern>] [--status <code>]\n kardalum audit export --period <YYYY-MM> [--out <file>]\n\nOptions:\n --from, --to <time> Entries at or after, at or before this time (ISO 8601: 2026-10-01T00:00:00Z)\n --kind <kind> session, key, site, plugin, visitor or anonymous\n --user <id> Only the entries of this user id\n --key <id> Only the entries of this API key id\n --ip <address> Only the entries from this address\n --route <pattern> Only this registered route, such as /api/manage/v1/content/:id/publish\n --status <code> Only this HTTP status\n --period <YYYY-MM> The month to export, in UTC\n --out <file> Write the export to this file instead of standard output\n -h, --help Show this help and exit\n\nlist prints the newest entries first, and says on standard error how many entries the server\ncould not record since it started, when there are any. export prints one JSON object per line\n(NDJSON), oldest first, and is itself recorded in the log. Piped into a command that stops\nreading early, such as head, either ends quietly: with 0, or with the run's own code when it\nhad already failed. The key needs managementApi.use with\naudit.read for list and audit.export for export: administrator actions, because every entry\ncarries the name and email of who acted.\n\nExamples:\n kardalum audit list --kind key --status 403 --json\n kardalum audit export --period 2026-10 --out audit-2026-10.ndjson --profile production";
12
12
  export declare const PLUGINS_USAGE = "kardalum plugins: the plugins installed on a site and the marketplace\n(kardalum plugin, without the s, builds a plugin: validate, build, pack, publish)\n\nUsage:\n kardalum plugins list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins install-record <id>\n kardalum plugins install <file|id> [--answers <file>] [--answers-stdin] [--print-questions]\n [--plugin-version <v>] [--license-key-stdin] [--confirm-trust-downgrade]\n kardalum plugins activate <id>\n kardalum plugins deactivate <id>\n kardalum plugins recheck-licence <id>\n kardalum plugins snapshots <id> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins uninstall <id> [--keep-sample-content] [--keep-roles] [--yes] [--dry-run]\n kardalum plugins restore-snapshot <id> [--yes] [--dry-run]\n kardalum plugins restore-data-types <id> [--group <id>] [--yes] [--dry-run] [--json]\n kardalum plugins marketplace list [--search <text>] [--type <type>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins marketplace get <id>\n\nOptions:\n --search <text> marketplace list: only the listings that match this text\n --type <type> marketplace list: only the listings of this type, such as utility or theme\n --keep-sample-content Uninstall: keep the sample pages the install added\n --keep-roles Uninstall: keep the roles the install created\n --group <id> restore-data-types: the snapshot group whose record comes back (default: the latest)\n --answers <file> Answers to the install questions as JSON (anything left out takes its default)\n --answers-stdin The same answers, read from standard input\n --print-questions Print what the listing asks, with an answers.json to start from; installs nothing\n --plugin-version <v> A listing's version other than the latest\n --license-key-stdin A paid listing's licence key, from standard input (or set KARDALUM_LICENSE_KEY)\n --confirm-trust-downgrade\n Allow a package upload to lower an installed plugin's trust\n -h, --help Show this help and exit\n\ninstall takes a package file (made by `kardalum plugin pack`) or a marketplace plugin id. A listing\npublishes its questions: `--print-questions` prints them and an answers.json, a script passes it with\n--answers, and a person at a terminal is asked. An update asks only what the recorded answers leave\nopen; it reads the install record, so the key also needs plugins.read. A package file has no listing, so it is never asked: without --answers the server applies each\ndefault and says what it refused. A licence key is never a flag: pipe it in or set KARDALUM_LICENSE_KEY.\nThe server refuses a package above its size limit (50 MiB by default) with a 413.\n\nA plugin id is reverse-domain, such as com.example.shop. uninstall asks first, naming the sample\npages and roles that go, the media that stays, and, for a plugin with its own data tables, that they\nare removed after a snapshot; a bundle names its member plugins, which go with it. The dry run only\nreads and changes nothing. restore-snapshot brings a plugin's\ndata tables back from their newest snapshots: it asks with the plan's table count, and the confirmation\ncarries the plan it showed, so a plan that changed meanwhile is shown again and nothing is restored.\nrestore-data-types brings back the data types an uninstall recorded, with their ids, once the plugin\nis installed again: it asks with how many come back and names each one skipped with why (its id or\nname exists again, its editor's plugin is missing or switched off, or its settings no longer fit).\nThe marketplace commands exist only when the site has a marketplace (otherwise: not found, exit 4).\n\nExamples:\n kardalum plugins list\n kardalum plugins uninstall com.example.shop --keep-roles --dry-run\n kardalum plugins marketplace list --search commerce";
13
13
  export declare const USERS_USAGE = "kardalum users: the people who can sign in to a site\n\nUsage:\n kardalum users list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum users set-role <userId> <role> [--yes] [--dry-run]\n kardalum users delete <userId> [--yes] [--dry-run]\n\nOptions:\n -h, --help Show this help and exit\n\nset-role asks first, showing the old role and the new one; it reads the roles first, so the key needs\nroles.read beside users.update, and it may assign only a role whose actions it holds. Only an\nadministrator's session may grant or revoke the admin role; a key is refused. delete asks first: the person's sessions end at once, the API\nkeys they made keep working as site credentials (revoke them in the admin if they should stop), content\nthey wrote keeps their id, and files they uploaded stay and move to the system account. A key can never\ndelete an administrator; the last administrator, the system account and your own account cannot be\ndeleted. A delete or a role change takes effect on the person's next request.\nPeople are created in the admin (Users); a key cannot create one.\n\nExamples:\n kardalum users list --json\n kardalum users set-role 4f2a... editor --profile staging --dry-run";
14
14
  export declare const ROLES_USAGE = "kardalum roles: roles and the actions they hold\n\nUsage:\n kardalum roles list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum roles actions [--json]\n kardalum roles create <id> --label <text> [--actions a,b,c | --actions-file <file|->]\n kardalum roles update <id> [--label <text>] [--actions a,b,c | --actions-file <file|->]\n kardalum roles delete <id> [--yes] [--dry-run]\n\nOptions:\n --label <text> The name shown in the admin\n --actions <a,b,c> The actions, separated by commas\n --actions-file <f|-> A JSON array of action ids, or a role object (`roles list --json` prints one)\n -h, --help Show this help and exit\n\nactions lists every action a role can hold, plugins' included. update replaces the whole set of actions\nwith the one given; start from `kardalum roles list --json`. A role id is a lowercase slug chosen at\ncreate. You can only give a role an action you hold yourself (a 403 names the action). delete asks first\nand is refused while users hold the role; the admin and editor roles cannot be deleted.\n\nExamples:\n kardalum roles create reviewer --label \"Reviewers\" --actions content.read,content.update\n kardalum roles delete reviewer --profile staging --dry-run";
@@ -43,6 +43,8 @@ Usage:
43
43
  kardalum dev start [options] Run a local CMS sandbox for plugin development
44
44
  kardalum plugin <validate|build|bundle-server|pack|publish> [dir] [options]
45
45
  Validate, build, pack, or publish a plugin
46
+ kardalum plugin contract <add|export> [args] [options]
47
+ Copy another plugin's contract in, or write this plugin's own out
46
48
  kardalum mcp [--profile <name>] [--allow-production] [--allow-private-urls]
47
49
  Serve a site's tools to an MCP host over standard input and output
48
50
  kardalum <noun> <verb> [options] Manage a running site through its management API
@@ -374,7 +376,7 @@ Usage:
374
376
 
375
377
  Options:
376
378
  --from, --to <time> Entries at or after, at or before this time (ISO 8601: 2026-10-01T00:00:00Z)
377
- --kind <kind> session, key, site or anonymous
379
+ --kind <kind> session, key, site, plugin, visitor or anonymous
378
380
  --user <id> Only the entries of this user id
379
381
  --key <id> Only the entries of this API key id
380
382
  --ip <address> Only the entries from this address
@@ -0,0 +1,76 @@
1
+ import { type SandboxCompanionResponse } from "@kardalum/api-schemas";
2
+ import { type AttachClientOptions } from "./local-plugin.js";
3
+ import { type NeededPlugin } from "./needed-plugins.js";
4
+ export declare const COMPANIONS_FILE = "companions.json";
5
+ export type CompanionRecord = Record<string, {
6
+ version: string;
7
+ contracts: Record<string, string>;
8
+ }>;
9
+ export declare function readCompanionRecord(stateDir: string): CompanionRecord;
10
+ export declare function recordCompanion(stateDir: string, entry: {
11
+ pluginId: string;
12
+ version: string;
13
+ contract: string;
14
+ contractVersion: string;
15
+ }): void;
16
+ /** A record the server did not bear out goes, so the next start does not trust it again. */
17
+ export declare function forgetCompanion(stateDir: string, pluginId: string): void;
18
+ /** Each needed owner's name from the project's holding copies (a copy's document passed ContractDocumentSchema,
19
+ * whose owner name is a checked display name): the offline source of the name the design's message shows. */
20
+ export declare function ownerNamesFromCopies(pluginDir: string, needed: readonly NeededPlugin[]): Record<string, string>;
21
+ export interface CompanionPlan {
22
+ fromMarketplace: NeededPlugin[];
23
+ fromFolders: Array<{
24
+ dir: string;
25
+ pluginId: string;
26
+ port: number;
27
+ }>;
28
+ skipped: NeededPlugin[];
29
+ /** What companions.json says is installed: confirmed with the server once it is up (plan decision 10). */
30
+ confirm: NeededPlugin[];
31
+ }
32
+ export declare function planCompanions(input: {
33
+ needed: NeededPlugin[];
34
+ record: CompanionRecord;
35
+ folders: Array<{
36
+ dir: string;
37
+ pluginId: string;
38
+ }>;
39
+ marketplace: boolean;
40
+ withOptional: boolean;
41
+ ask?: (needed: NeededPlugin) => Promise<boolean>;
42
+ pluginPort: number;
43
+ ownerNames?: Record<string, string>;
44
+ }): Promise<CompanionPlan>;
45
+ /** Design 4.9a point 2's question for an optional use, worded with the owner's name when a copy gives one. */
46
+ export declare function optionalUseQuestion(needed: NeededPlugin, ownerName: string | undefined): string;
47
+ export interface CompanionClient {
48
+ install(body: {
49
+ contract: string;
50
+ range: string;
51
+ answers?: unknown;
52
+ }, token?: string): Promise<{
53
+ ok: true;
54
+ body: SandboxCompanionResponse;
55
+ } | {
56
+ ok: false;
57
+ status: number;
58
+ code?: string;
59
+ message: string;
60
+ }>;
61
+ }
62
+ /** The answers install-answers.json's `with` gives one needed plugin, or none. */
63
+ export declare function companionAnswersFor(answersPath: string | undefined, pluginId: string): unknown;
64
+ export declare function installCompanionsFromMarketplace(plan: CompanionPlan, client: CompanionClient, options: {
65
+ stateDir: string;
66
+ answersPath?: string;
67
+ developerToken?: string;
68
+ ownerNames?: Record<string, string>;
69
+ log(line: string): void;
70
+ }): Promise<void>;
71
+ /** Plan decision 12 and Global Constraints: the publish token goes only to the marketplace it belongs to. */
72
+ export declare function developerTokenFor(env: NodeJS.ProcessEnv, sandboxMarketplace: string): string | undefined;
73
+ /** The companion route's client, signing in as the attach client does (its options, its token cache, its 401
74
+ * retry, through createSandboxSession). The token header is added only when a token is given. A sign-in that
75
+ * fails, a timeout or an unreachable server answers a refusal in words, never a throw. */
76
+ export declare function createCompanionClient(options: AttachClientOptions): CompanionClient;
@@ -0,0 +1,197 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { DEVELOPER_TOKEN_HEADER, SANDBOX_COMPANION_PATH, SANDBOX_COMPANIONS_MAX, SandboxAnswersFileSchema, SandboxCompanionResponseSchema, contractRangeAllows, isPluginManifestId, } from "@kardalum/api-schemas";
4
+ import { resolveRegistryUrl } from "../plugin/publish.js";
5
+ import { contractCopiesOf, readContractCopy } from "../plugin/contracts/folder.js";
6
+ import { SandboxError } from "./config.js";
7
+ import { createSandboxSession, errorText } from "./local-plugin.js";
8
+ import { missingPluginMessage, notOnMarketplaceMessage } from "./needed-plugins.js";
9
+ // M35 B1c (design 4.9a point 2): the plugins a sandbox installs for the plugin under development, and the
10
+ // record of what it installed, read before the server starts so a start without --marketplace knows
11
+ // whether it can go on.
12
+ export const COMPANIONS_FILE = "companions.json";
13
+ export function readCompanionRecord(stateDir) {
14
+ const path = join(stateDir, COMPANIONS_FILE);
15
+ if (!existsSync(path))
16
+ return {};
17
+ try {
18
+ const raw = JSON.parse(readFileSync(path, "utf8"));
19
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
20
+ return {};
21
+ const out = {};
22
+ for (const [id, entry] of Object.entries(raw).slice(0, SANDBOX_COMPANIONS_MAX)) {
23
+ const e = entry;
24
+ if (!isPluginManifestId(id) || typeof e.version !== "string" || e.contracts === null || typeof e.contracts !== "object")
25
+ continue;
26
+ out[id] = { version: e.version, contracts: Object.fromEntries(Object.entries(e.contracts).filter((pair) => typeof pair[1] === "string")) };
27
+ }
28
+ return out;
29
+ }
30
+ catch {
31
+ return {};
32
+ }
33
+ }
34
+ export function recordCompanion(stateDir, entry) {
35
+ const record = readCompanionRecord(stateDir);
36
+ const before = record[entry.pluginId];
37
+ record[entry.pluginId] = { version: entry.version, contracts: { ...(before?.version === entry.version ? before.contracts : {}), [entry.contract]: entry.contractVersion } };
38
+ writeFileSync(join(stateDir, COMPANIONS_FILE), `${JSON.stringify(record, null, 2)}\n`);
39
+ }
40
+ /** A record the server did not bear out goes, so the next start does not trust it again. */
41
+ export function forgetCompanion(stateDir, pluginId) {
42
+ const record = readCompanionRecord(stateDir);
43
+ if (!(pluginId in record))
44
+ return;
45
+ delete record[pluginId];
46
+ writeFileSync(join(stateDir, COMPANIONS_FILE), `${JSON.stringify(record, null, 2)}\n`);
47
+ }
48
+ /** Each needed owner's name from the project's holding copies (a copy's document passed ContractDocumentSchema,
49
+ * whose owner name is a checked display name): the offline source of the name the design's message shows. */
50
+ export function ownerNamesFromCopies(pluginDir, needed) {
51
+ const names = {};
52
+ for (const entry of needed) {
53
+ if (names[entry.ownerId] !== undefined)
54
+ continue;
55
+ for (const version of contractCopiesOf(pluginDir, entry.contract).reverse()) {
56
+ const copy = readContractCopy(pluginDir, entry.contract, version);
57
+ if (copy.ok) {
58
+ names[entry.ownerId] = copy.document.owner.name;
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ return names;
64
+ }
65
+ export async function planCompanions(input) {
66
+ const plan = { fromMarketplace: [], fromFolders: [], skipped: [], confirm: [] };
67
+ input.folders.forEach((folder, index) => plan.fromFolders.push({ ...folder, port: input.pluginPort + 1 + index }));
68
+ for (const needed of input.needed) {
69
+ if (input.folders.some((folder) => folder.pluginId === needed.ownerId))
70
+ continue;
71
+ const installed = input.record[needed.ownerId]?.contracts[needed.contract];
72
+ if (installed !== undefined && contractRangeAllows(needed.range, installed)) {
73
+ plan.confirm.push(needed);
74
+ continue;
75
+ }
76
+ if (needed.optional) {
77
+ // Only the marketplace installs an optional use, so with it off the question is never asked.
78
+ const wanted = input.marketplace && (input.withOptional || (input.ask !== undefined && (await input.ask(needed))));
79
+ if (!wanted) {
80
+ plan.skipped.push(needed);
81
+ continue;
82
+ }
83
+ }
84
+ else if (!input.marketplace) {
85
+ throw new SandboxError(missingPluginMessage(needed, input.ownerNames?.[needed.ownerId]));
86
+ }
87
+ if (!plan.fromMarketplace.some((n) => n.contract === needed.contract))
88
+ plan.fromMarketplace.push(needed);
89
+ }
90
+ // The plugins installed beside the one you build, recorded ones included: one owner of two contracts is one plugin.
91
+ const owners = new Set([...plan.fromMarketplace, ...plan.confirm].map((n) => n.ownerId).concat(plan.fromFolders.map((f) => f.pluginId)));
92
+ if (owners.size > SANDBOX_COMPANIONS_MAX)
93
+ throw new SandboxError(`A sandbox installs at most ${SANDBOX_COMPANIONS_MAX} plugins beside the one you build.`);
94
+ return plan;
95
+ }
96
+ /** Design 4.9a point 2's question for an optional use, worded with the owner's name when a copy gives one. */
97
+ export function optionalUseQuestion(needed, ownerName) {
98
+ const owner = ownerName ?? needed.ownerId;
99
+ return `Your plugin can use ${owner}'s ${needed.contract.slice(needed.ownerId.length + 1)} service (optional). Install ${owner} in the sandbox too?`;
100
+ }
101
+ /** The answers install-answers.json's `with` gives one needed plugin, or none. */
102
+ export function companionAnswersFor(answersPath, pluginId) {
103
+ if (answersPath === undefined)
104
+ return undefined;
105
+ try {
106
+ const parsed = SandboxAnswersFileSchema.safeParse(JSON.parse(readFileSync(answersPath, "utf8")));
107
+ return parsed.success ? parsed.data.with?.[pluginId] : undefined;
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ }
113
+ export async function installCompanionsFromMarketplace(plan, client, options) {
114
+ // Plan decision 10: companions.json is a hint. The route answers already-installed from the server's own
115
+ // registry without a request; a record it does not bear out (a reset database) is dropped and named.
116
+ for (const needed of plan.confirm) {
117
+ // With the marketplace on, a reset database installs the companion again: with its `with` answers, as at first.
118
+ const answers = companionAnswersFor(options.answersPath, needed.ownerId);
119
+ const result = await client.install({ contract: needed.contract, range: needed.range, ...(answers !== undefined ? { answers } : {}) }, options.developerToken);
120
+ if (result.ok) {
121
+ recordCompanion(options.stateDir, { pluginId: result.body.pluginId, version: result.body.version, contract: needed.contract, contractVersion: result.body.contractVersion });
122
+ if (result.body.outcome === "installed")
123
+ options.log(installedLine(needed, result.body));
124
+ continue;
125
+ }
126
+ // Only an answer of the server that the companion is not there drops the record; a timeout or an unreachable
127
+ // server (status 0) says nothing about it, so the next start still trusts it.
128
+ const notThere = result.code === "marketplace_off" || result.code === "not_on_marketplace" || result.code === "no_version_in_range";
129
+ if (notThere)
130
+ forgetCompanion(options.stateDir, needed.ownerId);
131
+ if (result.code === "marketplace_off")
132
+ throw new SandboxError(missingPluginMessage(needed, options.ownerNames?.[needed.ownerId]));
133
+ if (notThere)
134
+ throw new SandboxError(notOnMarketplaceMessage(needed));
135
+ // M35 wave 4 merge (B1c minor 12): a reinstall after a database reset can be refused a developer copy too.
136
+ if (result.code === "developer_copy_refused")
137
+ throw developerCopyRefused(needed, result.message, options.developerToken);
138
+ throw new SandboxError(`${needed.ownerId} could not be installed in the sandbox: ${result.message}`);
139
+ }
140
+ for (const needed of plan.fromMarketplace) {
141
+ const answers = companionAnswersFor(options.answersPath, needed.ownerId);
142
+ const result = await client.install({ contract: needed.contract, range: needed.range, ...(answers !== undefined ? { answers } : {}) }, options.developerToken);
143
+ if (!result.ok) {
144
+ if (result.code === "not_on_marketplace" || result.code === "no_version_in_range")
145
+ throw new SandboxError(notOnMarketplaceMessage(needed));
146
+ if (result.code === "developer_copy_refused")
147
+ throw developerCopyRefused(needed, result.message, options.developerToken);
148
+ throw new SandboxError(`${needed.ownerId} could not be installed in the sandbox: ${result.message}`);
149
+ }
150
+ recordCompanion(options.stateDir, { pluginId: result.body.pluginId, version: result.body.version, contract: needed.contract, contractVersion: result.body.contractVersion });
151
+ options.log(installedLine(needed, result.body));
152
+ }
153
+ for (const skipped of plan.skipped)
154
+ options.log(`[kardalum dev] ${skipped.ownerId} is not installed: calls to ${skipped.contract} answer missing (an optional use)`);
155
+ }
156
+ /** A refused developer copy, in both loops: with the hint where the token is set when none was sent. */
157
+ function developerCopyRefused(needed, message, developerToken) {
158
+ return new SandboxError(`${needed.ownerId} is paid, and the marketplace refused a developer copy: ${message}${developerToken === undefined ? " (set KARDALUM_PUBLISH_TOKEN, the token kardalum plugin publish uses, for the marketplace the sandbox uses)" : ""}`);
159
+ }
160
+ function installedLine(needed, body) {
161
+ return `[kardalum dev] ${body.pluginId} ${body.version} ${body.outcome === "installed" ? "installed from the marketplace" : "is already installed"} (${needed.contract} ${body.contractVersion})`;
162
+ }
163
+ /** Plan decision 12 and Global Constraints: the publish token goes only to the marketplace it belongs to. */
164
+ export function developerTokenFor(env, sandboxMarketplace) {
165
+ const token = env.KARDALUM_PUBLISH_TOKEN;
166
+ if (!token)
167
+ return undefined;
168
+ try {
169
+ return new URL(resolveRegistryUrl(undefined, env)).origin === new URL(sandboxMarketplace).origin ? token : undefined;
170
+ }
171
+ catch {
172
+ return undefined;
173
+ }
174
+ }
175
+ /** The companion route's client, signing in as the attach client does (its options, its token cache, its 401
176
+ * retry, through createSandboxSession). The token header is added only when a token is given. A sign-in that
177
+ * fails, a timeout or an unreachable server answers a refusal in words, never a throw. */
178
+ export function createCompanionClient(options) {
179
+ const session = createSandboxSession(options);
180
+ return {
181
+ async install(body, token) {
182
+ let response;
183
+ let json;
184
+ try {
185
+ response = await session.post(SANDBOX_COMPANION_PATH, body, token ? { [DEVELOPER_TOKEN_HEADER]: token } : {});
186
+ json = (await response.json().catch(() => ({})));
187
+ }
188
+ catch (error) {
189
+ return { ok: false, status: 0, message: errorText(error).slice(0, 300) };
190
+ }
191
+ if (!response.ok)
192
+ return { ok: false, status: response.status, ...(typeof json.code === "string" ? { code: json.code } : {}), message: typeof json.message === "string" ? json.message.slice(0, 300) : `the sandbox answered ${response.status}` };
193
+ const parsed = SandboxCompanionResponseSchema.safeParse(json);
194
+ return parsed.success ? { ok: true, body: parsed.data } : { ok: false, status: 502, message: "the sandbox's answer did not read" };
195
+ },
196
+ };
197
+ }
@@ -14,6 +14,10 @@ export interface SandboxConfig {
14
14
  adminPort: number;
15
15
  pluginPort: number;
16
16
  marketplace: boolean;
17
+ /** M35 B1c: local plugin projects the plugin needs, installed before it. */
18
+ with: string[];
19
+ /** M35 B1c: --with-optional, install the plugins the plugin may use (optional uses) without asking. */
20
+ withOptional: boolean;
17
21
  serverVersion?: string;
18
22
  contentDatabaseUrl: string;
19
23
  prismaDatabaseUrl: string;
@@ -29,5 +33,11 @@ export declare function kardalumDevHome(env?: NodeJS.ProcessEnv): string;
29
33
  export declare function sandboxKey(projectPath: string): string;
30
34
  export declare function standaloneStateDir(projectPath: string, home?: string): string;
31
35
  export declare function marketplaceBannerLine(env: NodeJS.ProcessEnv): string;
36
+ /** M35 B1c: the hosted marketplace a server talks to when KARDALUM_MARKETPLACE_URL is unset (the server's own
37
+ * DEFAULT_MARKETPLACE_URL; config.test.ts ties it to the publish registry's default, the same host). */
38
+ export declare const DEFAULT_MARKETPLACE_URL = "https://dev.kardalum.com";
39
+ /** M35 B1c: the marketplace the sandbox's server talks to, read from the env the server is given: its
40
+ * KARDALUM_MARKETPLACE_URL when set and not off, else the hosted default. */
41
+ export declare function sandboxMarketplaceUrl(env: NodeJS.ProcessEnv): string;
32
42
  export declare function resolveSandboxConfig(argv: string[], cwd: string, env?: NodeJS.ProcessEnv, isPluginProject?: (cwd: string) => boolean): SandboxConfig;
33
43
  export {};
@@ -33,7 +33,7 @@ const COMPOSE_SERVICES = {
33
33
  mysql: "mysql-sandbox",
34
34
  };
35
35
  const USAGE = "Usage: kardalum dev start [--db sqlite|postgres|mysql] [--server-port <n>] " +
36
- "[--plugin-port <n>] [--server-version <version>] [--marketplace]";
36
+ "[--plugin-port <n>] [--server-version <version>] [--marketplace] [--with <folder>] [--with-optional]";
37
37
  // Cold first boot compiles the whole server off tsx while vite cold-starts
38
38
  // the admin: on a slow disk (OneDrive-synced checkouts especially) 60s
39
39
  // was genuinely not enough (2026-08-25 fresh-clone finding #3).
@@ -107,6 +107,15 @@ export function marketplaceBannerLine(env) {
107
107
  }
108
108
  return "Marketplace: KARDALUM_MARKETPLACE_URL from your shell (not a usable address, the server will say)";
109
109
  }
110
+ /** M35 B1c: the hosted marketplace a server talks to when KARDALUM_MARKETPLACE_URL is unset (the server's own
111
+ * DEFAULT_MARKETPLACE_URL; config.test.ts ties it to the publish registry's default, the same host). */
112
+ export const DEFAULT_MARKETPLACE_URL = "https://dev.kardalum.com";
113
+ /** M35 B1c: the marketplace the sandbox's server talks to, read from the env the server is given: its
114
+ * KARDALUM_MARKETPLACE_URL when set and not off, else the hosted default. */
115
+ export function sandboxMarketplaceUrl(env) {
116
+ const raw = env.KARDALUM_MARKETPLACE_URL?.trim();
117
+ return raw === undefined || raw === "" || raw.toLowerCase() === "off" ? DEFAULT_MARKETPLACE_URL : raw;
118
+ }
110
119
  // Shared by --server-port/--plugin-port(/--admin-port). Not reused for
111
120
  // --db (a closed enum, not a number) or KARDALUM_DEV_READY_TIMEOUT_MS
112
121
  // (resolveReadyTimeoutMs has its own message shape and allows the env-var
@@ -138,6 +147,9 @@ export function resolveSandboxConfig(argv, cwd, env = process.env, isPluginProje
138
147
  // pluginPort below.
139
148
  "admin-port": { type: "string" },
140
149
  marketplace: { type: "boolean" },
150
+ // M35 B1c (design 4.9a point 2): the plugin projects the plugin needs, and yes to its optional uses.
151
+ with: { type: "string", multiple: true },
152
+ "with-optional": { type: "boolean" },
141
153
  },
142
154
  }));
143
155
  }
@@ -162,6 +174,13 @@ export function resolveSandboxConfig(argv, cwd, env = process.env, isPluginProje
162
174
  "(no package.json that depends on @kardalum/plugin-sdk beside a vite.config.ts). " +
163
175
  "Drop --plugin-port, or run kardalum dev start from the plugin's folder.");
164
176
  }
177
+ // M35 B1c: what a plugin needs is read from its project, which a folder that is not one does not have.
178
+ const withGiven = values.with !== undefined || values["with-optional"] !== undefined;
179
+ if (withGiven && !pluginProject) {
180
+ throw new SandboxError(`--with needs a plugin project: it installs the plugins a plugin project needs, and ${fwd(cwd)} is not a plugin project ` +
181
+ "(no package.json that depends on @kardalum/plugin-sdk beside a vite.config.ts). " +
182
+ "Drop --with and --with-optional, or run kardalum dev start from the plugin's folder.");
183
+ }
165
184
  const serverPort = parsePort("server-port", values["server-port"], DEFAULT_SERVER_PORT);
166
185
  // packages/cli/src/dev/config.ts (or dist/dev/config.js) → four levels up
167
186
  // is the repo root. One short lands on packages/, which has no
@@ -192,6 +211,14 @@ export function resolveSandboxConfig(argv, cwd, env = process.env, isPluginProje
192
211
  if (pluginProject && serverPort === pluginPort) {
193
212
  throw new SandboxError(`--server-port and --plugin-port must be different (both were ${serverPort}).`);
194
213
  }
214
+ // M35 B1c: each --with folder is served on the next port after the plugin's (planCompanions), so a folder
215
+ // landing on the server's port, or a checkout's admin dev server's, is refused here, before anything starts.
216
+ (values.with ?? []).forEach((dir, index) => {
217
+ const port = pluginPort + 1 + index;
218
+ const taken = port === serverPort ? "the server's" : mode === "checkout" && port === CHECKOUT_ADMIN_PORT ? "the admin dev server's" : undefined;
219
+ if (taken !== undefined)
220
+ throw new SandboxError(`--with ${dir} would be served on port ${port}, which is ${taken}: choose another --plugin-port.`);
221
+ });
195
222
  const normalizedCwd = fwd(cwd);
196
223
  // Checkout mode's state dir stays exactly `<cwd>/.kardalum-dev`, as it
197
224
  // always has. Standalone has no monorepo checkout to root itself
@@ -209,6 +236,8 @@ export function resolveSandboxConfig(argv, cwd, env = process.env, isPluginProje
209
236
  adminPort: CHECKOUT_ADMIN_PORT,
210
237
  pluginPort,
211
238
  marketplace: values.marketplace === true,
239
+ with: (values.with ?? []).map((dir) => resolve(cwd, dir)),
240
+ withOptional: values["with-optional"] === true,
212
241
  serverVersion: values["server-version"],
213
242
  contentDatabaseUrl: CONTENT_URLS[dialect](stateDir),
214
243
  prismaDatabaseUrl: `file:${stateDir}/prisma.db`,
@@ -65,6 +65,24 @@ export interface AttachClientOptions {
65
65
  timeoutMs?: number;
66
66
  }
67
67
  export declare function errorText(error: unknown): string;
68
+ /** M35 B1c: the sandbox admin's session on the running server, shared by the attach client and the
69
+ * companion client: one sign-in, its access token kept, and a fresh sign-in when a request answers 401. */
70
+ export interface SandboxSession {
71
+ /** One POST with the token held (none before the first sign-in) and any extra headers. */
72
+ send(path: string, body: unknown, headers?: Record<string, string>): Promise<Response>;
73
+ /** Signs in again and keeps the new token, or says in words why it could not. */
74
+ signIn(): Promise<{
75
+ ok: true;
76
+ } | {
77
+ problem: string;
78
+ }>;
79
+ /** send, and on a 401 one sign-in and the same POST again. A sign-in that fails throws SandboxSignInError. */
80
+ post(path: string, body: unknown, headers?: Record<string, string>): Promise<Response>;
81
+ }
82
+ export declare class SandboxSignInError extends Error {
83
+ constructor(message: string);
84
+ }
85
+ export declare function createSandboxSession(options: AttachClientOptions): SandboxSession;
68
86
  export declare function createAttachClient(options: AttachClientOptions): AttachClient;
69
87
  /** The bundle step's budget, first run and rebuild alike: a plugin module that
70
88
  * starts a timer at import would otherwise keep bundle-server alive. */
@@ -130,20 +130,29 @@ function attachedFrom(text) {
130
130
  }
131
131
  return { kind: "attached", plugin: parsed.data };
132
132
  }
133
- export function createAttachClient(options) {
133
+ export class SandboxSignInError extends Error {
134
+ constructor(message) {
135
+ super(message);
136
+ this.name = "SandboxSignInError";
137
+ }
138
+ }
139
+ export function createSandboxSession(options) {
134
140
  const fetchImpl = options.fetchImpl ?? fetch;
135
141
  const timeoutMs = options.timeoutMs ?? ATTACH_TIMEOUT_MS;
136
142
  let token;
137
- const post = (path, body, bearer) => fetchImpl(`${options.baseUrl}${path}`, {
143
+ const request = (path, body, bearer, headers = {}) => fetchImpl(`${options.baseUrl}${path}`, {
138
144
  method: "POST",
139
- headers: { "content-type": "application/json", ...(bearer === undefined ? {} : { authorization: `Bearer ${bearer}` }) },
145
+ headers: { ...headers, "content-type": "application/json", ...(bearer === undefined ? {} : { authorization: `Bearer ${bearer}` }) },
140
146
  body: JSON.stringify(body),
141
147
  signal: AbortSignal.timeout(timeoutMs),
142
148
  });
143
149
  async function signIn() {
144
150
  if (options.password === undefined)
145
151
  return { problem: `no password is known for ${options.email}` };
146
- const response = await post("/api/auth/login", { email: options.email, password: options.password }, undefined);
152
+ const response = await request("/api/auth/login", { email: options.email, password: options.password }, undefined);
153
+ // M35 U3a (design 6.3): a 202 is a sign-in step; the sandbox never answers one.
154
+ if (response.status === 202)
155
+ return { problem: "This site asks a sign-in step; the sandbox signs in only where no step is switched on." };
147
156
  if (!response.ok)
148
157
  return { problem: `signing in as ${options.email} answered ${await messageOf(response)}` };
149
158
  let body;
@@ -158,20 +167,38 @@ export function createAttachClient(options) {
158
167
  }
159
168
  if (typeof body?.accessToken !== "string")
160
169
  return { problem: "the sign-in answer carried no access token" };
161
- return { token: body.accessToken };
170
+ token = body.accessToken;
171
+ return { ok: true };
162
172
  }
173
+ const send = (path, body, headers) => request(path, body, token, headers);
174
+ return {
175
+ send,
176
+ signIn,
177
+ async post(path, body, headers) {
178
+ const response = await send(path, body, headers);
179
+ if (response.status !== 401)
180
+ return response;
181
+ const signedIn = await signIn();
182
+ if ("problem" in signedIn)
183
+ throw new SandboxSignInError(signedIn.problem);
184
+ return send(path, body, headers);
185
+ },
186
+ };
187
+ }
188
+ export function createAttachClient(options) {
189
+ const timeoutMs = options.timeoutMs ?? ATTACH_TIMEOUT_MS;
190
+ const session = createSandboxSession(options);
163
191
  return {
164
192
  async attach(body) {
165
193
  try {
166
- let response = await post(SANDBOX_ATTACH_PATH, body, token);
194
+ let response = await session.send(SANDBOX_ATTACH_PATH, body);
167
195
  if (response.status === 404)
168
196
  return { kind: "no-route" };
169
197
  if (response.status === 401) {
170
- const signedIn = await signIn();
198
+ const signedIn = await session.signIn();
171
199
  if ("problem" in signedIn)
172
200
  return { kind: "no-login", message: signedIn.problem };
173
- token = signedIn.token;
174
- response = await post(SANDBOX_ATTACH_PATH, body, token);
201
+ response = await session.send(SANDBOX_ATTACH_PATH, body);
175
202
  }
176
203
  if (!response.ok)
177
204
  return { kind: "refused", status: response.status, message: await messageOf(response) };
@@ -0,0 +1,11 @@
1
+ import { type ServiceDeclarations } from "@kardalum/api-schemas";
2
+ export interface NeededPlugin {
3
+ ownerId: string;
4
+ contract: string;
5
+ range: string;
6
+ why: "use" | "offer";
7
+ optional: boolean;
8
+ }
9
+ export declare function neededPlugins(declarations: ServiceDeclarations): NeededPlugin[];
10
+ export declare function missingPluginMessage(needed: NeededPlugin, ownerName?: string): string;
11
+ export declare function notOnMarketplaceMessage(needed: NeededPlugin): string;