@kosdev-code/kos-ddk-cli 0.1.0-dev.50 → 0.1.0-dev.55

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 (66) hide show
  1. package/README.md +54 -18
  2. package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +1 -1
  3. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +0 -11
  4. package/agent-plugin/kos-ddk-tools/plugin.json +1 -1
  5. package/agent-plugin/kos-ddk-tools/reference/reference.json +108 -57
  6. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +428 -427
  7. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +9 -6
  8. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +3 -1
  9. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +1 -1
  10. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +3 -1
  11. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +3 -1
  12. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +3 -1
  13. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +3 -1
  14. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +37 -4
  15. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +3 -1
  16. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +3 -1
  17. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +3 -1
  18. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +1 -1
  19. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +3 -1
  20. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +3 -1
  21. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +2 -12
  22. package/catalog/contributions.json +0 -11
  23. package/guides/ddk-dev.md +2 -1
  24. package/guides/getting-started.md +117 -0
  25. package/guides/storybook.md +37 -2
  26. package/package.json +2 -2
  27. package/reference/reference.json +108 -57
  28. package/src/codegen/contribution.mjs +184 -14
  29. package/src/codegen/descriptor.mjs +210 -0
  30. package/src/codegen/ncui-descriptor.mjs +134 -0
  31. package/src/codegen/overrides.mjs +85 -1
  32. package/src/codegen/project.mjs +111 -13
  33. package/src/extension.mjs +10 -0
  34. package/src/generators/agent-install.mjs +3 -2
  35. package/src/generators/catalog.mjs +15 -4
  36. package/src/generators/contributions.mjs +41 -6
  37. package/src/generators/dashboard.mjs +12 -9
  38. package/src/generators/descriptor-entries.mjs +53 -0
  39. package/src/generators/descriptor-project.mjs +79 -0
  40. package/src/generators/dev.mjs +15 -5
  41. package/src/generators/plugin-project.mjs +36 -4
  42. package/src/generators/theme-project.mjs +14 -3
  43. package/src/handlers.mjs +9 -19
  44. package/src/mcp/plugin-inspect.mjs +35 -0
  45. package/src/mcp/reference.mjs +19 -3
  46. package/src/mcp/tools.mjs +118 -21
  47. package/templates/cui/__nameDashCase__.stories.tsx__template__ +3 -1
  48. package/templates/cui/__nameDashCase__.tsx__template__ +1 -1
  49. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +3 -1
  50. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +3 -1
  51. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +3 -1
  52. package/templates/nav/__nameDashCase__.stories.tsx__template__ +3 -1
  53. package/templates/plugin-project/.storybook/preview.tsx.template +37 -4
  54. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +3 -1
  55. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +3 -1
  56. package/templates/setup/__nameDashCase__.stories.tsx__template__ +3 -1
  57. package/templates/setup/__nameDashCase__.tsx__template__ +1 -1
  58. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +3 -1
  59. package/templates/utility/__nameDashCase__.stories.tsx__template__ +3 -1
  60. package/templates/utility/__nameDashCase__.tsx__template__ +2 -12
  61. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.stories.tsx__template__ +0 -30
  62. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.tsx__template__ +0 -27
  63. package/agent-plugin/kos-ddk-tools/templates/setting/index.ts__template__ +0 -1
  64. package/templates/setting/__nameDashCase__.stories.tsx__template__ +0 -30
  65. package/templates/setting/__nameDashCase__.tsx__template__ +0 -27
  66. package/templates/setting/index.ts__template__ +0 -1
@@ -1,30 +1,108 @@
1
1
  // DDK contributions (component, story, index, .kos.json entry, i18n title) in a
2
2
  // plugin project. Shared by the ddk:* commands and the DDK MCP tools.
3
- import { generateComponent } from "@kosdev-code/kos-codegen-core";
3
+ import path from "node:path";
4
+ import {
5
+ findProjectByName,
6
+ generateComponent,
7
+ normalizeAllValues,
8
+ updateJson,
9
+ } from "@kosdev-code/kos-codegen-core";
4
10
  import { TEMPLATES_DIR, registerDdkHandlers } from "../handlers.mjs";
5
- import { resolveOverride } from "./overrides.mjs";
11
+ import {
12
+ addDescriptorEntry,
13
+ descriptorListsSlot,
14
+ findDescriptorProjects,
15
+ } from "./descriptor.mjs";
16
+ import { alsoReplacedNotes, resolveOverride } from "./overrides.mjs";
6
17
 
7
18
  /** Extension point → plugin type and what a contribution of it needs. */
8
19
  export const CONTRIBUTION_TYPES = {
9
- cui: { pluginType: "ddk.cui", label: "DDK CUI Configuration" },
20
+ cui: {
21
+ pluginType: "ddk.cui",
22
+ label: "DDK CUI Configuration",
23
+ required: "cuiDescriptor",
24
+ description:
25
+ "Create a CUI configuration; --descriptor is the CUI's appId from /api/app/kosdev.ddk/cui",
26
+ },
10
27
  setup: {
11
28
  pluginType: "ddk.setup",
12
29
  label: "DDK Setup Step",
13
30
  overridable: "setupDescriptor",
31
+ listedIn: "kondra.ncui.setup.steps",
32
+ descriptorType: "setup",
33
+ description:
34
+ "Create a setup step; --descriptor is its kondra.ncui.setup.steps entry (default: from the name)",
14
35
  },
15
36
  utility: {
16
37
  pluginType: "ddk.utility",
17
38
  label: "DDK Utility",
18
39
  overridable: "utilDescriptor",
40
+ listedIn: "kondra.ncui.utilities",
41
+ descriptorType: "utility",
42
+ description:
43
+ "Create a utility; --descriptor is its kondra.ncui.utilities entry (default: from the name)",
19
44
  },
20
- setting: { pluginType: "ddk.setting", label: "DDK Setting", group: true },
21
45
  nav: {
22
46
  pluginType: "ddk.nav",
23
47
  label: "DDK Navigation View",
24
48
  overridable: "navDescriptor",
49
+ listedIn: "kondra.ncui.navigations",
50
+ descriptorType: "nav",
51
+ // A navigation view fills a kondra.ncui.navigations path; no name is one.
52
+ slotRequired: true,
53
+ description:
54
+ "Create a navigation view; --descriptor is its kondra.ncui.navigations entry, e.g. settings.water for a Settings tab",
25
55
  },
26
56
  };
27
57
 
58
+ /** The keys each component template translates beyond its title, with their English text. */
59
+ export const TEMPLATE_KEYS = {
60
+ "ddk.cui": { proceed: "Proceed" },
61
+ "ddk.setup": { proceed: "Proceed" },
62
+ "ddk.utility": { proceed: "Proceed" },
63
+ "ddk.dashboardDetail": { close: "Close" },
64
+ "ddk.troubleAction": { resolve: "Resolve" },
65
+ };
66
+
67
+ /** Adds the template's keys to the plugin's en locale file, keeping existing values. */
68
+ function addTemplateKeys(codegenFs, pluginType, project) {
69
+ const keys = TEMPLATE_KEYS[pluginType];
70
+ const sourceRoot = findProjectByName(codegenFs.root, project)?.sourceRoot;
71
+ if (!keys || !sourceRoot) return;
72
+ const localePath = path.join(
73
+ sourceRoot,
74
+ "assets",
75
+ "locales",
76
+ "en",
77
+ `${project}.json`
78
+ );
79
+ if (!codegenFs.exists(localePath)) return;
80
+ updateJson(codegenFs, localePath, (json) => ({ ...keys, ...json }));
81
+ }
82
+
83
+ /**
84
+ * Refuses a name whose component the plugin already exposes: module federation
85
+ * exposes each component by name, so a second one would replace the first.
86
+ */
87
+ function assertNameFree(codegenFs, project, name) {
88
+ const root = findProjectByName(codegenFs.root, project)?.root;
89
+ const kosJson = root && codegenFs.read(path.join(root, ".kos.json"));
90
+ if (!kosJson) return;
91
+ const experiences =
92
+ JSON.parse(kosJson).kos?.ui?.plugin?.contributes?.experiences ?? {};
93
+ const pascal = normalizeAllValues({ name }).namePascalCase;
94
+ const taken = Object.values(experiences).find((experience) =>
95
+ [pascal, `${pascal}Summary`, `${pascal}Detail`].includes(
96
+ experience.component
97
+ )
98
+ );
99
+ if (taken) {
100
+ throw new Error(
101
+ `${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)`
102
+ );
103
+ }
104
+ }
105
+
28
106
  function generate(codegenFs, pluginType, { name, project, ...extra }) {
29
107
  registerDdkHandlers();
30
108
  generateComponent(codegenFs, TEMPLATES_DIR, {
@@ -37,6 +115,7 @@ function generate(codegenFs, pluginType, { name, project, ...extra }) {
37
115
  modelDirectory: "",
38
116
  ...extra,
39
117
  });
118
+ addTemplateKeys(codegenFs, pluginType, project);
40
119
  }
41
120
 
42
121
  function requireOption(value, flag) {
@@ -46,13 +125,24 @@ function requireOption(value, flag) {
46
125
  const rankField = (rank) => (rank === undefined ? {} : { rank });
47
126
 
48
127
  /**
49
- * @param {{type: keyof CONTRIBUTION_TYPES, name: string, project: string, group?: string,
128
+ * @param {{type: keyof CONTRIBUTION_TYPES, name: string, project: string,
50
129
  * descriptor?: string, override?: string, rank?: number|string}} options
51
- * `descriptor`, `override` and `rank` apply to the rankable types (setup, utility, nav).
130
+ * `override` and `rank` apply to the rankable types (setup, utility, nav); `descriptor`
131
+ * to those and to cui, which requires it.
52
132
  */
53
133
  export function generateDdkContribution(
54
134
  codegenFs,
55
- { type, name, project, group, descriptor, override, rank }
135
+ {
136
+ type,
137
+ name,
138
+ project,
139
+ descriptor,
140
+ override,
141
+ rank,
142
+ descriptorProject,
143
+ roles,
144
+ column,
145
+ }
56
146
  ) {
57
147
  const spec = CONTRIBUTION_TYPES[type];
58
148
  if (!spec) {
@@ -62,15 +152,13 @@ export function generateDdkContribution(
62
152
  ).join(", ")}.`
63
153
  );
64
154
  }
65
- if (spec.group && !group) {
66
- throw new Error("Settings group is required for setting plugin type");
67
- }
68
- const ranked = override || descriptor || (rank !== undefined && rank !== "");
155
+ const ranked = override || (rank !== undefined && rank !== "");
69
156
  if (!spec.overridable && ranked) {
70
157
  throw new Error(
71
- `${type} contributions are not ranked; --override, --descriptor and --rank do not apply`
158
+ `${type} contributions are not ranked; --override and --rank do not apply`
72
159
  );
73
160
  }
161
+ if (spec.required) requireOption(descriptor, `descriptor (${spec.required})`);
74
162
  const resolved = spec.overridable
75
163
  ? resolveOverride(type, {
76
164
  override,
@@ -79,14 +167,75 @@ export function generateDdkContribution(
79
167
  })
80
168
  : { fields: {}, notes: [] };
81
169
  const slot = resolved.fields[spec.overridable] ?? descriptor;
170
+ if (spec.slotRequired && !slot) {
171
+ requireOption(
172
+ slot,
173
+ `descriptor (${spec.overridable}, a kondra.ncui.navigations path such as settings.water)`
174
+ );
175
+ }
176
+ assertNameFree(codegenFs, project, name);
177
+ if (descriptorProject && override) {
178
+ throw new Error(
179
+ "--override fills a slot the descriptor already lists; --descriptorProject does not apply"
180
+ );
181
+ }
182
+ const derived =
183
+ spec.listedIn && !slot
184
+ ? [
185
+ `${spec.overridable} "${
186
+ normalizeAllValues({ name }).nameCamelCase
187
+ }" comes from the name (--descriptor sets it).`,
188
+ ]
189
+ : [];
82
190
  generate(codegenFs, spec.pluginType, {
83
191
  name,
84
192
  project,
85
- ...(group ? { group } : {}),
86
193
  ...(slot ? { descriptor: slot } : {}),
87
194
  ...rankField(resolved.rank),
88
195
  });
89
- return { label: spec.label, notes: resolved.notes };
196
+ const listed = spec.descriptorType
197
+ ? descriptorNotes(codegenFs, spec, {
198
+ slot: slot || normalizeAllValues({ name }).nameCamelCase,
199
+ override,
200
+ descriptorProject,
201
+ roles,
202
+ column,
203
+ })
204
+ : [];
205
+ return {
206
+ label: spec.label,
207
+ notes: [...resolved.notes, ...derived, ...listed],
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Lists a new utility, setup step or navigation slot in the named descriptor project,
213
+ * or says where it needs listing: the NCUI shows only the slots its descriptor lists.
214
+ */
215
+ function descriptorNotes(
216
+ codegenFs,
217
+ spec,
218
+ { slot, override, descriptorProject, roles, column }
219
+ ) {
220
+ if (override) return [];
221
+ if (descriptorProject) {
222
+ return [
223
+ addDescriptorEntry(codegenFs, spec.descriptorType, {
224
+ project: descriptorProject,
225
+ slot,
226
+ roles,
227
+ column,
228
+ }),
229
+ ];
230
+ }
231
+ const listed = descriptorListsSlot(codegenFs, spec.descriptorType, slot);
232
+ if (listed) return [];
233
+ const projects = findDescriptorProjects(codegenFs).map((p) => p.name);
234
+ return [
235
+ projects.length
236
+ ? `No descriptor project lists ${spec.overridable} "${slot}"; add it with --descriptorProject ${projects[0]}.`
237
+ : `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.`,
238
+ ];
90
239
  }
91
240
 
92
241
  /**
@@ -98,6 +247,7 @@ export function generateDashboardCard(
98
247
  codegenFs,
99
248
  { name, project, dashboardKey, detail = true, override, rank }
100
249
  ) {
250
+ assertNameFree(codegenFs, project, name);
101
251
  const resolved = resolveOverride("dashboard-card", {
102
252
  override,
103
253
  rank,
@@ -123,6 +273,14 @@ export function generateDashboardCard(
123
273
  ? ["The detail opens when a technician selects the card."]
124
274
  : []),
125
275
  ...resolved.notes,
276
+ ...alsoReplacedNotes("dashboard-card", {
277
+ override,
278
+ rank: resolved.rank,
279
+ slot: { dashboardKey: key },
280
+ written: detail
281
+ ? ["dashboardSummary", "dashboardDetail"]
282
+ : ["dashboardSummary"],
283
+ }),
126
284
  ],
127
285
  };
128
286
  }
@@ -132,6 +290,7 @@ export function generatePumpDetail(
132
290
  codegenFs,
133
291
  { name, project, dashboardKey, override, rank }
134
292
  ) {
293
+ assertNameFree(codegenFs, project, name);
135
294
  const resolved = resolveOverride("pump-detail", {
136
295
  override,
137
296
  rank,
@@ -164,6 +323,7 @@ export function generatePumpCard(
164
323
  codegenFs,
165
324
  { name, project, dashboardKey, detail = true, override, rank }
166
325
  ) {
326
+ assertNameFree(codegenFs, project, name);
167
327
  const resolved = resolveOverride("pump-card", {
168
328
  override,
169
329
  rank,
@@ -191,6 +351,14 @@ export function generatePumpCard(
191
351
  ]
192
352
  : []),
193
353
  ...resolved.notes,
354
+ ...alsoReplacedNotes("pump-card", {
355
+ override,
356
+ rank: resolved.rank,
357
+ slot: { dashboardKey: key },
358
+ written: detail
359
+ ? ["dashboardPumpSummary", "dashboardPumpDetail"]
360
+ : ["dashboardPumpSummary"],
361
+ }),
194
362
  ],
195
363
  };
196
364
  }
@@ -200,6 +368,7 @@ export function generateMacroSummary(
200
368
  codegenFs,
201
369
  { name, project, dashboardKey, override, rank }
202
370
  ) {
371
+ assertNameFree(codegenFs, project, name);
203
372
  const resolved = resolveOverride("macro-summary", {
204
373
  override,
205
374
  rank,
@@ -230,6 +399,7 @@ export function generateTroubleAction(
230
399
  codegenFs,
231
400
  { name, project, troubleType, stateKey, stateValue, override, rank }
232
401
  ) {
402
+ assertNameFree(codegenFs, project, name);
233
403
  const resolved = resolveOverride("trouble-action", {
234
404
  override,
235
405
  rank,
@@ -0,0 +1,210 @@
1
+ // NCUI descriptor projects: a ddk.ncui.descriptor KAB whose descriptor.json (its
2
+ // .kos.json) carries `kondra.ncui`. The DDK app uses an installed one in place of the
3
+ // system app's descriptor, so a plugin's new utility, setup step or navigation slot
4
+ // is listed there.
5
+ import path from "node:path";
6
+ import {
7
+ discoverProjects,
8
+ findProjectByName,
9
+ } from "@kosdev-code/kos-codegen-core";
10
+ import {
11
+ NCUI_LAYOUTS,
12
+ NCUI_OPTIONS,
13
+ buildNcuiDescriptor,
14
+ } from "./ncui-descriptor.mjs";
15
+
16
+ export const DESCRIPTOR_KAB_TYPE = "ddk.ncui.descriptor";
17
+
18
+ /** The workspace's descriptor projects: {name, kosJsonPath} relative to the root. */
19
+ export function findDescriptorProjects(codegenFs) {
20
+ return [...discoverProjects(codegenFs.root).values()]
21
+ .map((project) => ({
22
+ name: project.name,
23
+ kosJsonPath: path.join(project.root, ".kos.json"),
24
+ }))
25
+ .filter(({ kosJsonPath }) => {
26
+ const raw = codegenFs.read(kosJsonPath);
27
+ return raw && JSON.parse(raw).type === DESCRIPTOR_KAB_TYPE;
28
+ });
29
+ }
30
+
31
+ function descriptorProject(codegenFs, name) {
32
+ const projects = findDescriptorProjects(codegenFs);
33
+ const project = projects.find((p) => p.name === name);
34
+ if (!project) {
35
+ throw new Error(
36
+ `No descriptor project "${name}". ${
37
+ projects.length
38
+ ? `Descriptor projects: ${projects.map((p) => p.name).join(", ")}.`
39
+ : "Create one with kosui ddk:descriptor-project."
40
+ }`
41
+ );
42
+ }
43
+ return project;
44
+ }
45
+
46
+ const parseRoles = (roles) =>
47
+ (Array.isArray(roles) ? roles : String(roles ?? "").split(","))
48
+ .map((role) => role.trim())
49
+ .filter(Boolean);
50
+
51
+ /**
52
+ * Lists a slot in a descriptor project's `kondra.ncui`, unless it already is.
53
+ * Returns the note for the command's report.
54
+ *
55
+ * @param {"utility" | "setup" | "nav"} type
56
+ * @param {{project: string, slot: string, roles?: string | string[], column?: number | string}} options
57
+ * `column` (1-based, default the last) is for utilities; `roles` default to everyone
58
+ * for a utility and to the parent's roles for a navigation view.
59
+ */
60
+ export function addDescriptorEntry(
61
+ codegenFs,
62
+ type,
63
+ { project, slot, roles, column }
64
+ ) {
65
+ const { name, kosJsonPath } = descriptorProject(codegenFs, project);
66
+ const kosJson = JSON.parse(codegenFs.read(kosJsonPath));
67
+ const ncui = ((kosJson.kondra ??= {}).ncui ??= {});
68
+ const roleList = parseRoles(roles);
69
+ const withRoles = roleList.length ? { roles: roleList } : {};
70
+ let note;
71
+
72
+ if (type === "utility") {
73
+ const columns = (ncui.utilities ??= [[]]);
74
+ if (columns.flat().some((entry) => entry.name === slot)) {
75
+ return `${name} already lists utility "${slot}".`;
76
+ }
77
+ const index =
78
+ column === undefined || column === ""
79
+ ? columns.length - 1
80
+ : Number(column) - 1;
81
+ if (!Number.isInteger(index) || index < 0 || index > columns.length) {
82
+ throw new Error(
83
+ `column must be 1 to ${columns.length + 1}; got "${column}"`
84
+ );
85
+ }
86
+ (columns[index] ??= []).push({ name: slot, options: {}, ...withRoles });
87
+ note = `Listed utility "${slot}" in ${name} (column ${index + 1}).`;
88
+ } else if (type === "setup") {
89
+ const steps = ((ncui.setup ??= {}).steps ??= []);
90
+ if (steps.some((step) => step.name === slot)) {
91
+ return `${name} already lists setup step "${slot}".`;
92
+ }
93
+ steps.push({ name: slot });
94
+ note = `Listed setup step "${slot}" last in ${name}; the setup flow runs steps in that order.`;
95
+ } else {
96
+ const parts = slot.split(".");
97
+ let level = (ncui.navigations ??= []);
98
+ let parent;
99
+ for (const part of parts.slice(0, -1)) {
100
+ parent = level.find((item) => item.name === part);
101
+ if (!parent) {
102
+ throw new Error(
103
+ `${name} has no navigation "${parts
104
+ .slice(0, parts.indexOf(part) + 1)
105
+ .join(".")}" to add "${slot}" under`
106
+ );
107
+ }
108
+ level = parent.children ??= [];
109
+ }
110
+ const leaf = parts[parts.length - 1];
111
+ if (level.some((item) => item.name === leaf)) {
112
+ return `${name} already lists navigation "${slot}".`;
113
+ }
114
+ const navRoles = roleList.length ? roleList : parent?.roles;
115
+ level.push({ name: leaf, ...(navRoles ? { roles: navRoles } : {}) });
116
+ note = `Listed navigation "${slot}" in ${name}.`;
117
+ }
118
+
119
+ codegenFs.write(kosJsonPath, JSON.stringify(kosJson, null, 2) + "\n");
120
+ return note;
121
+ }
122
+
123
+ function ncuiLists(ncui, type, slot) {
124
+ if (type === "utility") {
125
+ return (ncui.utilities ?? []).flat().some((entry) => entry.name === slot);
126
+ }
127
+ if (type === "setup") {
128
+ return (ncui.setup?.steps ?? []).some((step) => step.name === slot);
129
+ }
130
+ let level = ncui.navigations ?? [];
131
+ for (const part of slot.split(".")) {
132
+ const found = level.find((item) => item.name === part);
133
+ if (!found) return false;
134
+ level = found.children ?? [];
135
+ }
136
+ return true;
137
+ }
138
+
139
+ /**
140
+ * Whether the workspace's descriptor projects list the slot, or with none, whether
141
+ * a generated NCUI descriptor could (the system app's descriptor is one of them).
142
+ */
143
+ export function descriptorListsSlot(codegenFs, type, slot) {
144
+ const projects = findDescriptorProjects(codegenFs);
145
+ if (!projects.length) {
146
+ return NCUI_LAYOUTS.some((layout) =>
147
+ [false, true].some((on) =>
148
+ ncuiLists(
149
+ buildNcuiDescriptor({
150
+ layout,
151
+ ...Object.fromEntries(
152
+ Object.keys(NCUI_OPTIONS).map((option) => [option, on])
153
+ ),
154
+ }).ncui,
155
+ type,
156
+ slot
157
+ )
158
+ )
159
+ );
160
+ }
161
+ return projects.some(({ kosJsonPath }) =>
162
+ ncuiLists(
163
+ JSON.parse(codegenFs.read(kosJsonPath)).kondra?.ncui ?? {},
164
+ type,
165
+ slot
166
+ )
167
+ );
168
+ }
169
+
170
+ const SLOT_FIELDS = [
171
+ ["utilities", "utility", "utilDescriptor"],
172
+ ["setupStep", "setup", "setupDescriptor"],
173
+ ["navViews", "nav", "navDescriptor"],
174
+ ];
175
+
176
+ /**
177
+ * Lists every utility, setup step and navigation slot a plugin already contributes in
178
+ * a descriptor project, keeping the entries it has; for a plugin that predates it.
179
+ */
180
+ export function addPluginDescriptorEntries(
181
+ codegenFs,
182
+ { project, descriptorProject }
183
+ ) {
184
+ const root = findProjectByName(codegenFs.root, project)?.root;
185
+ const raw = root && codegenFs.read(path.join(root, ".kos.json"));
186
+ if (!raw) throw new Error(`No plugin project "${project}" with a .kos.json`);
187
+ const contributes = JSON.parse(raw).kos?.ui?.plugin?.contributes ?? {};
188
+ const notes = [];
189
+ for (const [key, type, field] of SLOT_FIELDS) {
190
+ for (const entry of contributes[key] ?? []) {
191
+ if (!entry[field]) continue;
192
+ try {
193
+ notes.push(
194
+ addDescriptorEntry(codegenFs, type, {
195
+ project: descriptorProject,
196
+ slot: entry[field],
197
+ })
198
+ );
199
+ } catch (error) {
200
+ notes.push(`${entry.id}: ${error.message}`);
201
+ }
202
+ }
203
+ }
204
+ return {
205
+ label: "DDK descriptor entries",
206
+ notes: notes.length
207
+ ? notes
208
+ : [`${project} contributes no utility, setup step or navigation slot.`],
209
+ };
210
+ }
@@ -0,0 +1,134 @@
1
+ // The NCUI descriptor a new descriptor project starts from (`kondra.ncui`), for the
2
+ // standard or compact layout and the dispenser's options. Standard navigation marks
3
+ // about and settings `embed` (shown as tabs) and spreads utilities over two columns;
4
+ // compact keeps utilities in one column.
5
+
6
+ export const NCUI_LAYOUTS = ["standard", "compact"];
7
+
8
+ /** The options a descriptor project can switch on; all off by default. */
9
+ export const NCUI_OPTIONS = {
10
+ carb: "carbonation: the carbWater and carbTank setup steps",
11
+ ice: "ice: the iceSettings setup step and the ice settings tab",
12
+ beveragePourTest: "the beveragePourTest utility",
13
+ };
14
+
15
+ const MANAGERS = ["manager", "technician"];
16
+
17
+ function setupSteps({ carb, ice }) {
18
+ return [
19
+ { name: "selectCountry", preStep: true },
20
+ { name: "selectLanguage", preStep: true },
21
+ { name: "plainWater" },
22
+ ...(carb ? [{ name: "carbWater" }, { name: "carbTank" }] : []),
23
+ { name: "ns" },
24
+ { name: "macroAssignment" },
25
+ { name: "ingredients" },
26
+ { name: "regions" },
27
+ { name: "timeSettings" },
28
+ { name: "dispenserProfile" },
29
+ { name: "waterSettings" },
30
+ ...(ice ? [{ name: "iceSettings" }] : []),
31
+ ];
32
+ }
33
+
34
+ function utilities(layout, { beveragePourTest }) {
35
+ const tests = [
36
+ { name: "touchScreenTest", options: {} },
37
+ { name: "pixelQualityTest", options: {} },
38
+ { name: "setup", options: {} },
39
+ { name: "usbUpdate", options: {}, roles: MANAGERS },
40
+ ];
41
+ const service = [
42
+ { name: "reboot", options: {}, roles: ["manager"] },
43
+ { name: "downloadLogs", options: {}, roles: MANAGERS },
44
+ ...(beveragePourTest
45
+ ? [{ name: "beveragePourTest", options: {}, roles: MANAGERS }]
46
+ : []),
47
+ ];
48
+ return layout === "compact" ? [[...tests, ...service]] : [tests, service];
49
+ }
50
+
51
+ const technician = (name) => ({ name, roles: ["technician"] });
52
+ const everyone = (name, roles = ["crew", "technician"]) => ({ name, roles });
53
+
54
+ function navigations(layout, { ice }) {
55
+ if (layout === "compact") {
56
+ return [
57
+ everyone("dashboard"),
58
+ everyone("notifications"),
59
+ {
60
+ ...everyone("about"),
61
+ children: [everyone("software"), everyone("hardware")],
62
+ },
63
+ everyone("network", ["technician", "crew"]),
64
+ everyone("utilities", ["technician", "manager"]),
65
+ {
66
+ ...technician("settings"),
67
+ children: [
68
+ technician("localization"),
69
+ technician("time-settings"),
70
+ technician("water-settings"),
71
+ technician("dispenser-profile"),
72
+ technician("cui-selection"),
73
+ ...(ice ? [technician("ice-settings")] : []),
74
+ ],
75
+ },
76
+ ];
77
+ }
78
+ const crew = (name) => everyone(name, ["technician", "crew"]);
79
+ return [
80
+ everyone("summary"),
81
+ everyone("dashboard"),
82
+ everyone("notifications"),
83
+ {
84
+ ...everyone("about"),
85
+ options: { embed: true },
86
+ children: [
87
+ crew("dispenser-info"),
88
+ crew("hardware"),
89
+ crew("connectivity"),
90
+ crew("software"),
91
+ ],
92
+ },
93
+ everyone("utilities", ["technician", "manager"]),
94
+ {
95
+ ...technician("settings"),
96
+ options: { embed: true },
97
+ children: [
98
+ technician("regions"),
99
+ technician("dispenser-profile"),
100
+ technician("cui-selection"),
101
+ technician("water"),
102
+ ...(ice ? [technician("ice")] : []),
103
+ // Hidden at runtime when the dispenser has no remote trays.
104
+ technician("remote-nns"),
105
+ ],
106
+ },
107
+ ];
108
+ }
109
+
110
+ /**
111
+ * The `kondra` block of a new descriptor project.
112
+ * @param {{layout?: "standard" | "compact", carb?: boolean, ice?: boolean,
113
+ * beveragePourTest?: boolean}} options
114
+ */
115
+ export function buildNcuiDescriptor({
116
+ layout = "standard",
117
+ carb = false,
118
+ ice = false,
119
+ beveragePourTest = false,
120
+ } = {}) {
121
+ if (!NCUI_LAYOUTS.includes(layout)) {
122
+ throw new Error(
123
+ `No "${layout}" layout. Choose from ${NCUI_LAYOUTS.join(", ")}.`
124
+ );
125
+ }
126
+ const options = { carb, ice, beveragePourTest };
127
+ return {
128
+ ncui: {
129
+ setup: { steps: setupSteps(options) },
130
+ utilities: utilities(layout, options),
131
+ navigations: navigations(layout, options),
132
+ },
133
+ };
134
+ }