@kosdev-code/kos-ddk-cli 0.0.0-stage → 0.1.0-dev.105

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 (124) hide show
  1. package/README.md +181 -2
  2. package/agent-plugin/.claude-plugin/marketplace.json +13 -0
  3. package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
  4. package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
  5. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +45 -0
  6. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +43 -0
  7. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +921 -0
  8. package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
  9. package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
  10. package/agent-plugin/kos-ddk-tools/reference/reference.json +21141 -0
  11. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48656 -0
  12. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +110 -0
  13. package/agent-plugin/kos-ddk-tools/skills/ddk-config-page/SKILL.md +130 -0
  14. package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +59 -0
  15. package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +45 -0
  16. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  17. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  18. package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
  19. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  20. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  21. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  22. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  23. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  24. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/index.ts__template__ +1 -0
  25. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  26. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  27. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  28. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  29. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  30. package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
  31. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  32. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  33. package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
  34. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  35. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
  36. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  37. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  38. package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
  39. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  40. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  41. package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
  42. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  43. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  44. package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
  45. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
  46. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
  47. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
  48. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  49. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  50. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  51. package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
  52. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  53. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  54. package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
  55. package/catalog/contributions.json +921 -0
  56. package/guides/config-property-cards.md +77 -0
  57. package/guides/ddk-dev.md +59 -0
  58. package/guides/getting-started.md +126 -0
  59. package/guides/storybook.md +127 -0
  60. package/package.json +33 -3
  61. package/reference/reference.json +21141 -0
  62. package/src/build-paths.mjs +20 -0
  63. package/src/codegen/contribution.mjs +530 -0
  64. package/src/codegen/descriptor.mjs +422 -0
  65. package/src/codegen/json-preserve.mjs +137 -0
  66. package/src/codegen/ncui-descriptor.mjs +167 -0
  67. package/src/codegen/overrides.mjs +263 -0
  68. package/src/codegen/project.mjs +271 -0
  69. package/src/extension.mjs +32 -0
  70. package/src/generators/agent-install.mjs +80 -0
  71. package/src/generators/catalog.mjs +81 -0
  72. package/src/generators/contributions.mjs +164 -0
  73. package/src/generators/dashboard.mjs +282 -0
  74. package/src/generators/descriptor-entries.mjs +53 -0
  75. package/src/generators/descriptor-project.mjs +84 -0
  76. package/src/generators/dev.mjs +231 -0
  77. package/src/generators/override-prompts.mjs +27 -0
  78. package/src/generators/plugin-project.mjs +71 -0
  79. package/src/generators/theme-project.mjs +53 -0
  80. package/src/handlers.mjs +335 -0
  81. package/src/mcp/pkg-info.mjs +7 -0
  82. package/src/mcp/plugin-inspect.mjs +328 -0
  83. package/src/mcp/reference.mjs +315 -0
  84. package/src/mcp/server.mjs +12 -0
  85. package/src/mcp/tools.mjs +619 -0
  86. package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  87. package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  88. package/templates/cui/index.ts__template__ +1 -0
  89. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  90. package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  91. package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  92. package/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  93. package/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  94. package/templates/dashboard-region/index.ts__template__ +1 -0
  95. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  96. package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  97. package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  98. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  99. package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  100. package/templates/macro-summary/index.ts__template__ +1 -0
  101. package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  102. package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  103. package/templates/nav/index.ts__template__ +1 -0
  104. package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  105. package/templates/plugin-project/.storybook/registration.ts.template +6 -0
  106. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  107. package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  108. package/templates/pump-detail/index.ts__template__ +1 -0
  109. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  110. package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  111. package/templates/pump-summary/index.ts__template__ +1 -0
  112. package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  113. package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  114. package/templates/setup/index.ts__template__ +1 -0
  115. package/templates/theme-project/theme/assets/component.css.template +2 -0
  116. package/templates/theme-project/theme/assets/generic.css.template +2 -0
  117. package/templates/theme-project/theme/assets/semantic.css.template +2 -0
  118. package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  119. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  120. package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  121. package/templates/trouble-action/index.ts__template__ +1 -0
  122. package/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  123. package/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  124. package/templates/utility/index.ts__template__ +1 -0
@@ -0,0 +1,20 @@
1
+ // Where the build writes the contribution catalog and the reference; the agent-plugin
2
+ // bundle swaps this module for its own copies' locations.
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const packageRoot = path.resolve(
7
+ path.dirname(fileURLToPath(import.meta.url)),
8
+ ".."
9
+ );
10
+
11
+ export const CATALOG_PATH = path.join(
12
+ packageRoot,
13
+ "catalog",
14
+ "contributions.json"
15
+ );
16
+ export const REFERENCE_PATH = path.join(
17
+ packageRoot,
18
+ "reference",
19
+ "reference.json"
20
+ );
@@ -0,0 +1,530 @@
1
+ // DDK contributions (component, story, index, .kos.json entry, i18n title) in a
2
+ // plugin project. Shared by the ddk:* commands and the DDK MCP tools.
3
+ import path from "node:path";
4
+ import {
5
+ discoverProjects,
6
+ findProjectByName,
7
+ generateComponent,
8
+ normalizeAllValues,
9
+ updateJson,
10
+ } from "@kosdev-code/kos-codegen-core";
11
+ import { TEMPLATES_DIR, registerDdkHandlers } from "../handlers.mjs";
12
+ import {
13
+ addDashboardRegion,
14
+ addDescriptorEntry,
15
+ dashboardHasRegion,
16
+ descriptorListsSlot,
17
+ findDescriptorProjects,
18
+ } from "./descriptor.mjs";
19
+ import { stringifyPreserving } from "./json-preserve.mjs";
20
+ import {
21
+ alsoReplacedNotes,
22
+ parseRank,
23
+ resolveOverride,
24
+ } from "./overrides.mjs";
25
+
26
+ /** Extension point → plugin type and what a contribution of it needs. */
27
+ export const CONTRIBUTION_TYPES = {
28
+ cui: {
29
+ pluginType: "ddk.cui",
30
+ label: "DDK CUI Configuration",
31
+ required: "cuiDescriptor",
32
+ description:
33
+ "Create a CUI configuration; --descriptor is the CUI's appId from /api/app/kosdev.ddk/cui",
34
+ },
35
+ setup: {
36
+ pluginType: "ddk.setup",
37
+ label: "DDK Setup Step",
38
+ overridable: "setupDescriptor",
39
+ listedIn: "kondra.ncui.setup.steps",
40
+ descriptorType: "setup",
41
+ description:
42
+ "Create a setup step; --descriptor is its kondra.ncui.setup.steps entry (default: from the name)",
43
+ },
44
+ utility: {
45
+ pluginType: "ddk.utility",
46
+ label: "DDK Utility",
47
+ overridable: "utilDescriptor",
48
+ listedIn: "kondra.ncui.utilities",
49
+ descriptorType: "utility",
50
+ layouts: ["maximized", "fullscreen"],
51
+ description:
52
+ "Create a utility in a modal; --layout maximized (default) or fullscreen; --descriptor is its kondra.ncui.utilities entry (default: from the name)",
53
+ },
54
+ nav: {
55
+ pluginType: "ddk.nav",
56
+ label: "DDK Navigation View",
57
+ overridable: "navDescriptor",
58
+ listedIn: "kondra.ncui.navigations",
59
+ descriptorType: "nav",
60
+ // A navigation view fills a kondra.ncui.navigations path; no name is one.
61
+ slotRequired: true,
62
+ description:
63
+ "Create a navigation view; --descriptor is its kondra.ncui.navigations entry, e.g. settings.water for a Settings tab",
64
+ },
65
+ };
66
+
67
+ /** The keys each component template translates beyond its title, with their English text. */
68
+ export const TEMPLATE_KEYS = {
69
+ "ddk.cui": { proceed: "Proceed" },
70
+ "ddk.setup": { proceed: "Proceed" },
71
+ "ddk.utility": { back: "Back", close: "Close", done: "Done" },
72
+ "ddk.dashboardDetail": { close: "Close" },
73
+ "ddk.troubleAction": { resolve: "Resolve" },
74
+ };
75
+
76
+ /** Adds the template's keys to the plugin's en locale file, keeping existing values. */
77
+ function addTemplateKeys(codegenFs, pluginType, project) {
78
+ const keys = TEMPLATE_KEYS[pluginType];
79
+ const sourceRoot = findProjectByName(codegenFs.root, project)?.sourceRoot;
80
+ if (!keys || !sourceRoot) return;
81
+ const localePath = path.join(
82
+ sourceRoot,
83
+ "assets",
84
+ "locales",
85
+ "en",
86
+ `${project}.json`
87
+ );
88
+ if (!codegenFs.exists(localePath)) return;
89
+ updateJson(codegenFs, localePath, (json) => ({ ...keys, ...json }));
90
+ }
91
+
92
+ /**
93
+ * Refuses a name whose component the plugin already exposes: module federation
94
+ * exposes each component by name, so a second one would replace the first.
95
+ */
96
+ function assertNameFree(codegenFs, project, name) {
97
+ const root = findProjectByName(codegenFs.root, project)?.root;
98
+ const kosJson = root && codegenFs.read(path.join(root, ".kos.json"));
99
+ if (!kosJson) return;
100
+ const experiences =
101
+ JSON.parse(kosJson).kos?.ui?.plugin?.contributes?.experiences ?? {};
102
+ const pascal = normalizeAllValues({ name }).namePascalCase;
103
+ const taken = Object.values(experiences).find((experience) =>
104
+ [pascal, `${pascal}Summary`, `${pascal}Detail`].includes(
105
+ experience.component
106
+ )
107
+ );
108
+ if (taken) {
109
+ throw new Error(
110
+ `${project} already has a component ${taken.component} (${taken.location}); components are exposed by name, so choose another --name (kosui ddk:descriptor-entries lists an existing contribution's slot in a descriptor project)`
111
+ );
112
+ }
113
+ }
114
+
115
+ /** Warnings for a component name equal to a model's registration bean. */
116
+ export function beanCollisionNotes(codegenFs, name) {
117
+ const pascal = normalizeAllValues({ name }).namePascalCase;
118
+ const notes = [];
119
+ for (const project of discoverProjects(codegenFs.root).values()) {
120
+ const raw = codegenFs.read(path.join(project.root, ".kos.json"));
121
+ if (!raw) continue;
122
+ let models;
123
+ try {
124
+ models = JSON.parse(raw).models;
125
+ } catch {
126
+ continue;
127
+ }
128
+ for (const [model, entry] of Object.entries(models ?? {})) {
129
+ const bean =
130
+ entry?.factory ?? normalizeAllValues({ name: model }).namePascalCase;
131
+ if (bean === pascal) {
132
+ notes.push(
133
+ `WARNING: component ${pascal} has the same name as model ${model}'s registration bean ${bean} (${project.name}). Choose another name, e.g. ${name}-config (${pascal}Config), before writing.`
134
+ );
135
+ }
136
+ }
137
+ }
138
+ return notes;
139
+ }
140
+
141
+ function generate(codegenFs, pluginType, { name, project, ...extra }) {
142
+ registerDdkHandlers();
143
+ const root = findProjectByName(codegenFs.root, project)?.root;
144
+ const kosJsonPath = root && path.join(root, ".kos.json");
145
+ const before = kosJsonPath && codegenFs.read(kosJsonPath);
146
+ generateComponent(codegenFs, TEMPLATES_DIR, {
147
+ name,
148
+ appProject: project,
149
+ type: "components",
150
+ pluginType,
151
+ useEmotionCss: false,
152
+ appDirectory: "",
153
+ modelDirectory: "",
154
+ ...extra,
155
+ });
156
+ // Keep the original layout of .kos.json entries the contribution did not touch.
157
+ const after = before && codegenFs.read(kosJsonPath);
158
+ if (after && after !== before) {
159
+ codegenFs.write(kosJsonPath, stringifyPreserving(before, JSON.parse(after)));
160
+ }
161
+ addTemplateKeys(codegenFs, pluginType, project);
162
+ }
163
+
164
+ function requireOption(value, flag) {
165
+ if (!value) throw new Error(`${flag} is required`);
166
+ }
167
+
168
+ const rankField = (rank) => (rank === undefined ? {} : { rank });
169
+
170
+ /**
171
+ * @param {{type: keyof CONTRIBUTION_TYPES, name: string, project: string,
172
+ * descriptor?: string, override?: string, rank?: number|string,
173
+ * layout?: string}} options
174
+ * `override` and `rank` apply to the rankable types (setup, utility, nav); `descriptor`
175
+ * to those and to cui, which requires it; `layout` to a utility's modal.
176
+ */
177
+ export function generateDdkContribution(
178
+ codegenFs,
179
+ {
180
+ type,
181
+ name,
182
+ project,
183
+ descriptor,
184
+ override,
185
+ rank,
186
+ descriptorProject,
187
+ roles,
188
+ column,
189
+ layout,
190
+ }
191
+ ) {
192
+ const spec = CONTRIBUTION_TYPES[type];
193
+ if (!spec) {
194
+ throw new Error(
195
+ `Unknown contribution type "${type}". Choose from ${Object.keys(
196
+ CONTRIBUTION_TYPES
197
+ ).join(", ")}.`
198
+ );
199
+ }
200
+ const ranked = override || (rank !== undefined && rank !== "");
201
+ if (!spec.overridable && ranked) {
202
+ throw new Error(
203
+ `${type} contributions are not ranked; --override and --rank do not apply`
204
+ );
205
+ }
206
+ if (spec.required) requireOption(descriptor, `descriptor (${spec.required})`);
207
+ if (layout && !spec.layouts) {
208
+ throw new Error(`${type} contributions have no layout; --layout does not apply`);
209
+ }
210
+ if (layout && !spec.layouts.includes(layout)) {
211
+ throw new Error(
212
+ `Unknown layout "${layout}". Choose from ${spec.layouts.join(", ")}.`
213
+ );
214
+ }
215
+ const resolved = spec.overridable
216
+ ? resolveOverride(type, {
217
+ override,
218
+ rank,
219
+ explicit: { [spec.overridable]: descriptor },
220
+ })
221
+ : { fields: {}, notes: [] };
222
+ const slot = resolved.fields[spec.overridable] ?? descriptor;
223
+ if (spec.slotRequired && !slot) {
224
+ requireOption(
225
+ slot,
226
+ `descriptor (${spec.overridable}, a kondra.ncui.navigations path such as settings.water)`
227
+ );
228
+ }
229
+ assertNameFree(codegenFs, project, name);
230
+ if (descriptorProject && override) {
231
+ throw new Error(
232
+ "--override fills a slot the descriptor already lists; --descriptorProject does not apply"
233
+ );
234
+ }
235
+ const derived =
236
+ spec.listedIn && !slot
237
+ ? [
238
+ `${spec.overridable} "${
239
+ normalizeAllValues({ name }).nameCamelCase
240
+ }" comes from the name (--descriptor sets it).`,
241
+ ]
242
+ : [];
243
+ generate(codegenFs, spec.pluginType, {
244
+ name,
245
+ project,
246
+ ...(slot ? { descriptor: slot } : {}),
247
+ ...rankField(resolved.rank),
248
+ ...(spec.layouts ? { layout: layout || spec.layouts[0] } : {}),
249
+ });
250
+ const listed = spec.descriptorType
251
+ ? descriptorNotes(codegenFs, spec, {
252
+ slot: slot || normalizeAllValues({ name }).nameCamelCase,
253
+ override,
254
+ descriptorProject,
255
+ roles,
256
+ column,
257
+ })
258
+ : [];
259
+ return {
260
+ label: spec.label,
261
+ notes: [
262
+ ...beanCollisionNotes(codegenFs, name),
263
+ ...resolved.notes,
264
+ ...derived,
265
+ ...listed,
266
+ ],
267
+ };
268
+ }
269
+
270
+ /**
271
+ * Lists a new utility, setup step or navigation slot in the named descriptor project,
272
+ * or says where it needs listing: the NCUI shows only the slots its descriptor lists.
273
+ */
274
+ function descriptorNotes(
275
+ codegenFs,
276
+ spec,
277
+ { slot, override, descriptorProject, roles, column }
278
+ ) {
279
+ if (override) return [];
280
+ if (descriptorProject) {
281
+ return [
282
+ addDescriptorEntry(codegenFs, spec.descriptorType, {
283
+ project: descriptorProject,
284
+ slot,
285
+ roles,
286
+ column,
287
+ }),
288
+ ];
289
+ }
290
+ const listed = descriptorListsSlot(codegenFs, spec.descriptorType, slot);
291
+ if (listed) return [];
292
+ const projects = findDescriptorProjects(codegenFs).map((p) => p.name);
293
+ return [
294
+ projects.length
295
+ ? `No descriptor project lists ${spec.overridable} "${slot}"; add it with --descriptorProject ${projects[0]}.`
296
+ : `The NCUI shows "${slot}" only if its descriptor (${spec.listedIn}) lists it: create a descriptor project with kosui ddk:descriptor-project and pass --descriptorProject, or the system app's descriptor must list it.`,
297
+ ];
298
+ }
299
+
300
+ /**
301
+ * A dashboard summary card and, unless `detail` is false, the detail its card
302
+ * opens; both share `dashboardKey` and `rank`. `override` names a standard
303
+ * summary or detail whose dashboardKey to take over.
304
+ */
305
+ export function generateDashboardCard(
306
+ codegenFs,
307
+ { name, project, dashboardKey, detail = true, override, rank }
308
+ ) {
309
+ assertNameFree(codegenFs, project, name);
310
+ const resolved = resolveOverride("dashboard-card", {
311
+ override,
312
+ rank,
313
+ explicit: { dashboardKey },
314
+ });
315
+ const key = resolved.fields.dashboardKey ?? dashboardKey;
316
+ requireOption(key, "dashboardKey");
317
+ const options = {
318
+ name,
319
+ project,
320
+ dashboardKey: key,
321
+ ...rankField(resolved.rank),
322
+ };
323
+ generate(codegenFs, "ddk.dashboardSummary", options);
324
+ if (detail) {
325
+ generate(codegenFs, "ddk.dashboardDetail", options);
326
+ }
327
+ return {
328
+ label: detail ? "DDK Dashboard Card" : "DDK Dashboard Summary",
329
+ notes: [
330
+ ...beanCollisionNotes(codegenFs, name),
331
+ `The dashboard draws one card per active model at assembly.${key} (or the FreestyleAssembly companion's ${key}); no such model, no card.`,
332
+ ...(detail
333
+ ? ["The detail opens when a technician selects the card."]
334
+ : []),
335
+ ...resolved.notes,
336
+ ...alsoReplacedNotes("dashboard-card", {
337
+ override,
338
+ rank: resolved.rank,
339
+ slot: { dashboardKey: key },
340
+ written: detail
341
+ ? ["dashboardSummary", "dashboardDetail"]
342
+ : ["dashboardSummary"],
343
+ }),
344
+ ],
345
+ };
346
+ }
347
+
348
+ /** Pump detail for holders whose dashboard key is `dashboardKey`. */
349
+ export function generatePumpDetail(
350
+ codegenFs,
351
+ { name, project, dashboardKey, override, rank }
352
+ ) {
353
+ assertNameFree(codegenFs, project, name);
354
+ const resolved = resolveOverride("pump-detail", {
355
+ override,
356
+ rank,
357
+ explicit: { dashboardKey },
358
+ });
359
+ const key = resolved.fields.dashboardKey ?? dashboardKey;
360
+ requireOption(key, "dashboardKey");
361
+ generate(codegenFs, "ddk.pumpDetail", {
362
+ name,
363
+ project,
364
+ dashboardKey: key,
365
+ ...rankField(resolved.rank),
366
+ });
367
+ return {
368
+ label: "DDK Pump Detail",
369
+ notes: [
370
+ ...beanCollisionNotes(codegenFs, name),
371
+ `Shown in the holder modal for holders with dashboard key "${key}" (default: its first pump's type; a holder with several keys uses the first one that has a pump detail), unless the holder has its own content.`,
372
+ ...resolved.notes,
373
+ ],
374
+ };
375
+ }
376
+
377
+ /**
378
+ * A pump card for holders whose dashboard key is `dashboardKey`: the summary body on
379
+ * the holder's dashboard card and, unless `detail` is false, the pump detail in its
380
+ * modal; both share `dashboardKey` and `rank`. `override` names a standard pump
381
+ * summary or detail whose dashboardKey to take over.
382
+ */
383
+ export function generatePumpCard(
384
+ codegenFs,
385
+ { name, project, dashboardKey, detail = true, override, rank }
386
+ ) {
387
+ assertNameFree(codegenFs, project, name);
388
+ const resolved = resolveOverride("pump-card", {
389
+ override,
390
+ rank,
391
+ explicit: { dashboardKey },
392
+ });
393
+ const key = resolved.fields.dashboardKey ?? dashboardKey;
394
+ requireOption(key, "dashboardKey");
395
+ const options = {
396
+ name,
397
+ project,
398
+ dashboardKey: key,
399
+ ...rankField(resolved.rank),
400
+ };
401
+ generate(codegenFs, "ddk.pumpSummary", options);
402
+ if (detail) {
403
+ generate(codegenFs, "ddk.pumpDetail", options);
404
+ }
405
+ return {
406
+ label: detail ? "DDK Pump Card" : "DDK Pump Summary",
407
+ notes: [
408
+ ...beanCollisionNotes(codegenFs, name),
409
+ `Used for holders with dashboard key "${key}" (default: the holder's first pump type, which the backend assembly assigns; a holder with several keys uses the first one that has a contribution); other holders keep the default card body.`,
410
+ ...(detail
411
+ ? [
412
+ "The detail shows in the holder modal a technician opens from the card.",
413
+ ]
414
+ : []),
415
+ ...resolved.notes,
416
+ ...alsoReplacedNotes("pump-card", {
417
+ override,
418
+ rank: resolved.rank,
419
+ slot: { dashboardKey: key },
420
+ written: detail
421
+ ? ["dashboardPumpSummary", "dashboardPumpDetail"]
422
+ : ["dashboardPumpSummary"],
423
+ }),
424
+ ],
425
+ };
426
+ }
427
+
428
+ /** The macro holder card body for `dashboardKey`. */
429
+ export function generateMacroSummary(
430
+ codegenFs,
431
+ { name, project, dashboardKey, override, rank }
432
+ ) {
433
+ assertNameFree(codegenFs, project, name);
434
+ const resolved = resolveOverride("macro-summary", {
435
+ override,
436
+ rank,
437
+ explicit: { dashboardKey },
438
+ });
439
+ const key = resolved.fields.dashboardKey ?? dashboardKey;
440
+ requireOption(key, "dashboardKey");
441
+ generate(codegenFs, "ddk.macroSummary", {
442
+ name,
443
+ project,
444
+ dashboardKey: key,
445
+ ...rankField(resolved.rank),
446
+ });
447
+ return {
448
+ label: "DDK Macro Summary",
449
+ notes: [
450
+ ...beanCollisionNotes(codegenFs, name),
451
+ `Matched to a macro holder by holder.name "${key}" first, then by the dashboard key factory.`,
452
+ ...resolved.notes,
453
+ ],
454
+ };
455
+ }
456
+
457
+ /**
458
+ * A component that renders a whole dashboard region: the descriptor region whose
459
+ * `component` (else `name`) is `regionKey`. `descriptorProject` adds that region.
460
+ */
461
+ export function generateDashboardRegion(
462
+ codegenFs,
463
+ { name, project, regionKey, rank, descriptorProject }
464
+ ) {
465
+ assertNameFree(codegenFs, project, name);
466
+ const key = regionKey || normalizeAllValues({ name }).nameCamelCase;
467
+ generate(codegenFs, "ddk.dashboardRegion", {
468
+ name,
469
+ project,
470
+ regionKey: key,
471
+ // The region --descriptorProject adds claims no holders, so its story passes none.
472
+ claimsNothing: !!descriptorProject,
473
+ ...rankField(parseRank(rank)),
474
+ });
475
+ const derived = regionKey
476
+ ? []
477
+ : [`regionKey "${key}" comes from the name (--regionKey sets it).`];
478
+ let placement;
479
+ if (descriptorProject) {
480
+ placement = addDashboardRegion(codegenFs, {
481
+ project: descriptorProject,
482
+ key,
483
+ });
484
+ } else if (dashboardHasRegion(codegenFs, key)) {
485
+ placement = `Renders the dashboard region "${key}" in place of its built-in cards.`;
486
+ } else {
487
+ const projects = findDescriptorProjects(codegenFs).map((p) => p.name);
488
+ placement = projects.length
489
+ ? `No dashboard region in a descriptor project is rendered by "${key}"; add one with --descriptorProject ${projects[0]}, or set a region's component to "${key}".`
490
+ : `The dashboard shows "${key}" only if its descriptor (kondra.ncui.dashboard) has a region named "${key}" or with component "${key}": create a descriptor project with kosui ddk:descriptor-project and pass --descriptorProject.`;
491
+ }
492
+ return {
493
+ label: "DDK Dashboard Region",
494
+ notes: [...beanCollisionNotes(codegenFs, name), ...derived, placement],
495
+ };
496
+ }
497
+
498
+ /**
499
+ * The experience shown while the device has an active `troubleType` trouble.
500
+ * Contributions sharing a stateKey share one experience.
501
+ */
502
+ export function generateTroubleAction(
503
+ codegenFs,
504
+ { name, project, troubleType, stateKey, stateValue, override, rank }
505
+ ) {
506
+ assertNameFree(codegenFs, project, name);
507
+ const resolved = resolveOverride("trouble-action", {
508
+ override,
509
+ rank,
510
+ explicit: { troubleType, stateKey, stateValue },
511
+ });
512
+ const type = resolved.fields.troubleType ?? troubleType;
513
+ requireOption(type, "troubleType");
514
+ generate(codegenFs, "ddk.troubleAction", {
515
+ name,
516
+ project,
517
+ troubleType: type,
518
+ stateKey: resolved.fields.stateKey ?? (stateKey || type),
519
+ stateValue: resolved.fields.stateValue ?? (stateValue || type),
520
+ ...rankField(resolved.rank),
521
+ });
522
+ return {
523
+ label: "DDK Trouble Action",
524
+ notes: [
525
+ ...beanCollisionNotes(codegenFs, name),
526
+ `troubleType "${type}" must be the exact type the device raises; the experience shows while one is active and goes away once it is resolved.`,
527
+ ...resolved.notes,
528
+ ],
529
+ };
530
+ }