@kosdev-code/kos-ddk-cli 0.0.0-stage → 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.
- package/README.md +165 -2
- package/agent-plugin/.claude-plugin/marketplace.json +13 -0
- package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
- package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +40 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +33 -0
- package/agent-plugin/kos-ddk-tools/catalog/contributions.json +877 -0
- package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
- package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
- package/agent-plugin/kos-ddk-tools/reference/reference.json +19339 -0
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48633 -0
- package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +74 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +49 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +39 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
- package/catalog/contributions.json +877 -0
- package/guides/ddk-dev.md +47 -0
- package/guides/getting-started.md +117 -0
- package/guides/storybook.md +104 -0
- package/package.json +33 -3
- package/reference/reference.json +19339 -0
- package/src/build-paths.mjs +20 -0
- package/src/codegen/contribution.mjs +425 -0
- package/src/codegen/descriptor.mjs +210 -0
- package/src/codegen/ncui-descriptor.mjs +134 -0
- package/src/codegen/overrides.mjs +263 -0
- package/src/codegen/project.mjs +242 -0
- package/src/extension.mjs +32 -0
- package/src/generators/agent-install.mjs +80 -0
- package/src/generators/catalog.mjs +81 -0
- package/src/generators/contributions.mjs +151 -0
- package/src/generators/dashboard.mjs +241 -0
- package/src/generators/descriptor-entries.mjs +53 -0
- package/src/generators/descriptor-project.mjs +79 -0
- package/src/generators/dev.mjs +231 -0
- package/src/generators/override-prompts.mjs +27 -0
- package/src/generators/plugin-project.mjs +66 -0
- package/src/generators/theme-project.mjs +45 -0
- package/src/handlers.mjs +315 -0
- package/src/mcp/pkg-info.mjs +7 -0
- package/src/mcp/plugin-inspect.mjs +292 -0
- package/src/mcp/reference.mjs +264 -0
- package/src/mcp/server.mjs +12 -0
- package/src/mcp/tools.mjs +575 -0
- package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/templates/cui/index.ts__template__ +1 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/templates/macro-summary/index.ts__template__ +1 -0
- package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/templates/nav/index.ts__template__ +1 -0
- package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/templates/pump-detail/index.ts__template__ +1 -0
- package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/templates/pump-summary/index.ts__template__ +1 -0
- package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/templates/setup/index.ts__template__ +1 -0
- package/templates/theme-project/theme/assets/component.css.template +2 -0
- package/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/templates/trouble-action/index.ts__template__ +1 -0
- package/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/templates/utility/index.ts__template__ +1 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Overriding a contribution of a rankable extension point: a new contribution to
|
|
2
|
+
// the same point, with the same key, whose rank the host prefers. Lower rank wins
|
|
3
|
+
// and an unranked contribution loses to any ranked one.
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { CATALOG_PATH } from "../build-paths.mjs";
|
|
6
|
+
|
|
7
|
+
export { CATALOG_PATH };
|
|
8
|
+
|
|
9
|
+
/** Rank given to an override of an unranked contribution. */
|
|
10
|
+
export const DEFAULT_OVERRIDE_RANK = 100;
|
|
11
|
+
export const MAX_RANK = 1000;
|
|
12
|
+
|
|
13
|
+
/** Command → the .kos.json keys it contributes to and the fields that name the slot. */
|
|
14
|
+
export const OVERRIDABLE_POINTS = {
|
|
15
|
+
utility: { contributionKeys: ["utilities"], keys: ["utilDescriptor"] },
|
|
16
|
+
setup: { contributionKeys: ["setupStep"], keys: ["setupDescriptor"] },
|
|
17
|
+
nav: { contributionKeys: ["navViews"], keys: ["navDescriptor"] },
|
|
18
|
+
"dashboard-card": {
|
|
19
|
+
contributionKeys: ["dashboardSummary", "dashboardDetail"],
|
|
20
|
+
keys: ["dashboardKey"],
|
|
21
|
+
},
|
|
22
|
+
"pump-detail": {
|
|
23
|
+
contributionKeys: ["dashboardPumpDetail"],
|
|
24
|
+
keys: ["dashboardKey"],
|
|
25
|
+
},
|
|
26
|
+
"pump-card": {
|
|
27
|
+
contributionKeys: ["dashboardPumpSummary", "dashboardPumpDetail"],
|
|
28
|
+
keys: ["dashboardKey"],
|
|
29
|
+
},
|
|
30
|
+
"macro-summary": {
|
|
31
|
+
contributionKeys: ["dashboardMacroSummary"],
|
|
32
|
+
keys: ["dashboardKey"],
|
|
33
|
+
},
|
|
34
|
+
"trouble-action": {
|
|
35
|
+
contributionKeys: ["troubleActions"],
|
|
36
|
+
keys: ["troubleType", "stateKey", "stateValue"],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let catalog;
|
|
41
|
+
|
|
42
|
+
/** The standard plugins' contributions to rankable points, extracted at build time. */
|
|
43
|
+
export function loadCatalog() {
|
|
44
|
+
if (!catalog) {
|
|
45
|
+
if (!existsSync(CATALOG_PATH)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Contribution catalog missing at ${CATALOG_PATH}; it is written by the kos-ddk-cli build.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
catalog = JSON.parse(readFileSync(CATALOG_PATH, "utf-8"));
|
|
51
|
+
}
|
|
52
|
+
return catalog;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Each standard contribution once, though a pump detail is listed under both
|
|
57
|
+
* ddk:pump-detail and ddk:pump-card.
|
|
58
|
+
*/
|
|
59
|
+
export function uniqueContributions(entries) {
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
return entries.filter((entry) => {
|
|
62
|
+
const key = `${entry.plugin} ${entry.contributionKey} ${entry.id}`;
|
|
63
|
+
if (seen.has(key)) return false;
|
|
64
|
+
seen.add(key);
|
|
65
|
+
return true;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Contributions a ddk:<point> command can override, optionally for one point. */
|
|
70
|
+
export function listOverridableContributions(point) {
|
|
71
|
+
if (point && !OVERRIDABLE_POINTS[point]) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Unknown point "${point}". Choose from ${Object.keys(
|
|
74
|
+
OVERRIDABLE_POINTS
|
|
75
|
+
).join(", ")}.`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return loadCatalog().contributions.filter(
|
|
79
|
+
(entry) => !point || entry.point === point
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Each ddk:<point> command's contribution keys and slot fields, naming the keys
|
|
85
|
+
* no standard plugin contributes to.
|
|
86
|
+
*/
|
|
87
|
+
export function describeOverridablePoints(point) {
|
|
88
|
+
const { contributions } = loadCatalog();
|
|
89
|
+
return Object.entries(OVERRIDABLE_POINTS)
|
|
90
|
+
.filter(([name]) => !point || name === point)
|
|
91
|
+
.map(([name, spec]) => {
|
|
92
|
+
const unfilled = spec.contributionKeys.filter(
|
|
93
|
+
(key) => !contributions.some((entry) => entry.contributionKey === key)
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
point: name,
|
|
97
|
+
contributionKeys: spec.contributionKeys,
|
|
98
|
+
slot: spec.keys,
|
|
99
|
+
...(unfilled.length ? { noStandardContributions: unfilled } : {}),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Parses a rank from the CLI or a tool call; undefined when none was given. */
|
|
105
|
+
export function parseRank(rank) {
|
|
106
|
+
if (rank === undefined || rank === null || rank === "") return undefined;
|
|
107
|
+
const value = typeof rank === "number" ? rank : Number(rank);
|
|
108
|
+
if (!Number.isInteger(value) || value < 0 || value > MAX_RANK) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`rank must be a whole number from 0 to ${MAX_RANK}; got "${rank}"`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const describeRank = (rank) =>
|
|
117
|
+
typeof rank === "number" ? `rank ${rank}` : "unranked";
|
|
118
|
+
|
|
119
|
+
/** Notes for standard contributions a new one shares a slot with and does not beat. */
|
|
120
|
+
function slotTakenNotes(point, explicit, rank) {
|
|
121
|
+
const given = Object.entries(explicit).filter(([, value]) => value);
|
|
122
|
+
if (given.length === 0) return [];
|
|
123
|
+
const sharing = uniqueContributions(
|
|
124
|
+
loadCatalog().contributions.filter(
|
|
125
|
+
(entry) =>
|
|
126
|
+
entry.point === point &&
|
|
127
|
+
given.every(([key, value]) => entry.keys[key] === value)
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
return sharing
|
|
131
|
+
.filter(
|
|
132
|
+
(entry) =>
|
|
133
|
+
rank === undefined ||
|
|
134
|
+
(typeof entry.rank === "number" && rank >= entry.rank)
|
|
135
|
+
)
|
|
136
|
+
.map((entry) => {
|
|
137
|
+
const slot = given.map(([key, value]) => `${key} "${value}"`).join(", ");
|
|
138
|
+
const rankHint =
|
|
139
|
+
typeof entry.rank === "number"
|
|
140
|
+
? `give this one a --rank below ${entry.rank} (lower wins)`
|
|
141
|
+
: "give this one any --rank (any rank beats an unranked one)";
|
|
142
|
+
return `${entry.id} (${
|
|
143
|
+
entry.plugin
|
|
144
|
+
}) also fills ${slot} and is ${describeRank(
|
|
145
|
+
entry.rank
|
|
146
|
+
)}, so it still renders. To replace it, ${rankHint}, or use --override ${
|
|
147
|
+
entry.id
|
|
148
|
+
}.`;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Notes for the other standard contributions an override's shared rank also beats:
|
|
154
|
+
* a dashboard or pump card writes a summary and a detail in one slot, so overriding
|
|
155
|
+
* one replaces both.
|
|
156
|
+
*/
|
|
157
|
+
export function alsoReplacedNotes(point, { override, rank, slot, written }) {
|
|
158
|
+
if (!override || rank === undefined) return [];
|
|
159
|
+
return uniqueContributions(
|
|
160
|
+
loadCatalog().contributions.filter(
|
|
161
|
+
(entry) =>
|
|
162
|
+
entry.point === point &&
|
|
163
|
+
entry.id !== override &&
|
|
164
|
+
written.includes(entry.contributionKey) &&
|
|
165
|
+
Object.entries(slot).every(
|
|
166
|
+
([key, value]) => entry.keys[key] === value
|
|
167
|
+
) &&
|
|
168
|
+
(typeof entry.rank !== "number" || rank < entry.rank)
|
|
169
|
+
)
|
|
170
|
+
).map(
|
|
171
|
+
(entry) =>
|
|
172
|
+
`Also replaces ${entry.id} (${entry.plugin}, ${describeRank(
|
|
173
|
+
entry.rank
|
|
174
|
+
)}): the ${entry.contributionKey} in the same slot gets rank ${rank} too.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Resolves `--override <id>` and `--rank` for a ddk:<point> command.
|
|
180
|
+
*
|
|
181
|
+
* Returns the slot fields copied from the overridden contribution, the rank to
|
|
182
|
+
* write, and notes for the report. `explicit` holds slot fields the caller also
|
|
183
|
+
* gave, which must agree with the overridden contribution.
|
|
184
|
+
*/
|
|
185
|
+
export function resolveOverride(point, { override, rank, explicit = {} }) {
|
|
186
|
+
const spec = OVERRIDABLE_POINTS[point];
|
|
187
|
+
const requested = parseRank(rank);
|
|
188
|
+
if (!override) {
|
|
189
|
+
return {
|
|
190
|
+
fields: {},
|
|
191
|
+
rank: requested,
|
|
192
|
+
notes: slotTakenNotes(point, explicit, requested),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// The standard and compact plugins can share an id; both fill the same slot.
|
|
197
|
+
const matches = loadCatalog().contributions.filter(
|
|
198
|
+
(entry) => entry.id === override && entry.point === point
|
|
199
|
+
);
|
|
200
|
+
const target = matches[0];
|
|
201
|
+
if (!target) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`No ${point} contribution "${override}" to override. List them with: kosui ddk:contributions --point ${point}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const fields = Object.fromEntries(
|
|
208
|
+
spec.keys
|
|
209
|
+
.filter((key) => target.keys[key] !== undefined)
|
|
210
|
+
.map((key) => [key, target.keys[key]])
|
|
211
|
+
);
|
|
212
|
+
const sameSlot = (entry) =>
|
|
213
|
+
spec.keys.every((key) => entry.keys[key] === target.keys[key]);
|
|
214
|
+
if (!matches.every(sameSlot)) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`${override} fills different slots in ${matches
|
|
217
|
+
.map((entry) => entry.plugin)
|
|
218
|
+
.join(" and ")}; give the slot and --rank instead of --override`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
for (const [key, value] of Object.entries(explicit)) {
|
|
222
|
+
if (value && fields[key] !== undefined && value !== fields[key]) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`--${key} "${value}" conflicts with ${override}, whose ${key} is "${fields[key]}"`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const ranks = matches
|
|
230
|
+
.map((entry) => entry.rank)
|
|
231
|
+
.filter((rank) => typeof rank === "number");
|
|
232
|
+
const targetRank = ranks.length ? Math.min(...ranks) : undefined;
|
|
233
|
+
let resolved = requested;
|
|
234
|
+
if (resolved === undefined) {
|
|
235
|
+
if (typeof targetRank !== "number") resolved = DEFAULT_OVERRIDE_RANK;
|
|
236
|
+
else if (targetRank > 0) resolved = targetRank - 1;
|
|
237
|
+
else
|
|
238
|
+
throw new Error(
|
|
239
|
+
`${override} has rank 0, which no rank can beat; ties are broken by id`
|
|
240
|
+
);
|
|
241
|
+
} else if (typeof targetRank === "number" && resolved >= targetRank) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`rank ${resolved} does not outrank ${override} (rank ${targetRank}); lower rank wins`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const slot = Object.entries(fields)
|
|
248
|
+
.map(([key, value]) => `${key} "${value}"`)
|
|
249
|
+
.join(", ");
|
|
250
|
+
return {
|
|
251
|
+
fields,
|
|
252
|
+
rank: resolved,
|
|
253
|
+
notes: [
|
|
254
|
+
`Overrides ${override} from ${matches
|
|
255
|
+
.map((entry) => entry.plugin)
|
|
256
|
+
.join(
|
|
257
|
+
" and "
|
|
258
|
+
)} (${slot}) with rank ${resolved}; lower rank wins, and ${override} is ${describeRank(
|
|
259
|
+
targetRank
|
|
260
|
+
)}.`,
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// DDK plugin and theme projects: kos-nx-plugin's generic project generators run with
|
|
2
|
+
// the DDK KAB type, then the DDK layer from templates/<kind>-project is written on top.
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { findProjectByName } from "@kosdev-code/kos-codegen-core";
|
|
7
|
+
import { TEMPLATES_DIR } from "../handlers.mjs";
|
|
8
|
+
import { DESCRIPTOR_KAB_TYPE } from "./descriptor.mjs";
|
|
9
|
+
import { buildNcuiDescriptor } from "./ncui-descriptor.mjs";
|
|
10
|
+
|
|
11
|
+
export const DDK_VERSION = "~3.1.0";
|
|
12
|
+
|
|
13
|
+
/** The plugin context the DDK hosts load plugins from. */
|
|
14
|
+
export const DDK_PLUGIN_CONTEXT = "kosdev.ddk";
|
|
15
|
+
|
|
16
|
+
const DDK_PACKAGES = [
|
|
17
|
+
"@kosdev-code/kos-ddk",
|
|
18
|
+
"@kosdev-code/kos-ddk-components",
|
|
19
|
+
"@kosdev-code/kos-ddk-model-components",
|
|
20
|
+
"@kosdev-code/kos-ddk-models",
|
|
21
|
+
"@kosdev-code/kos-ddk-styles",
|
|
22
|
+
"@kosdev-code/kos-ddk-story-containers",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const PLUGIN_CONTRIBUTES = {
|
|
26
|
+
cui: [],
|
|
27
|
+
utilities: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
31
|
+
const writeJson = (file, json) =>
|
|
32
|
+
fs.writeFileSync(file, JSON.stringify(json, null, 2) + "\n");
|
|
33
|
+
|
|
34
|
+
function templateFiles(kind) {
|
|
35
|
+
const dir = path.join(TEMPLATES_DIR, `${kind}-project`);
|
|
36
|
+
return fs
|
|
37
|
+
.readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
38
|
+
.filter((entry) => entry.isFile())
|
|
39
|
+
.map((entry) =>
|
|
40
|
+
path
|
|
41
|
+
.relative(dir, path.join(entry.parentPath, entry.name))
|
|
42
|
+
.replace(/\.template$/, "")
|
|
43
|
+
)
|
|
44
|
+
.sort();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeTemplates(kind, projectRoot) {
|
|
48
|
+
const dir = path.join(TEMPLATES_DIR, `${kind}-project`);
|
|
49
|
+
for (const file of templateFiles(kind)) {
|
|
50
|
+
const target = path.join(projectRoot, file);
|
|
51
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
52
|
+
fs.copyFileSync(path.join(dir, `${file}.template`), target);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function overlayPlugin(workspaceRoot, projectRoot) {
|
|
57
|
+
writeTemplates("plugin", projectRoot);
|
|
58
|
+
|
|
59
|
+
const kosJsonPath = path.join(projectRoot, ".kos.json");
|
|
60
|
+
const kosJson = readJson(kosJsonPath);
|
|
61
|
+
const plugin = kosJson.kos.ui.plugin;
|
|
62
|
+
plugin.contributes = { ...PLUGIN_CONTRIBUTES, ...plugin.contributes };
|
|
63
|
+
kosJson.test = {
|
|
64
|
+
...kosJson.test,
|
|
65
|
+
plugin: { ...kosJson.test?.plugin, context: DDK_PLUGIN_CONTEXT },
|
|
66
|
+
};
|
|
67
|
+
writeJson(kosJsonPath, kosJson);
|
|
68
|
+
|
|
69
|
+
const packageJsonPath = path.join(workspaceRoot, "package.json");
|
|
70
|
+
const packageJson = readJson(packageJsonPath);
|
|
71
|
+
const installed = {
|
|
72
|
+
...packageJson.dependencies,
|
|
73
|
+
...packageJson.devDependencies,
|
|
74
|
+
};
|
|
75
|
+
const missing = DDK_PACKAGES.filter((name) => !installed[name]);
|
|
76
|
+
if (missing.length) {
|
|
77
|
+
packageJson.dependencies = { ...packageJson.dependencies };
|
|
78
|
+
for (const name of missing) packageJson.dependencies[name] = DDK_VERSION;
|
|
79
|
+
writeJson(packageJsonPath, packageJson);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function overlayTheme(_workspaceRoot, projectRoot) {
|
|
84
|
+
writeTemplates("theme", projectRoot);
|
|
85
|
+
fs.rmSync(path.join(projectRoot, "theme", "assets", ".gitkeep"), {
|
|
86
|
+
force: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function overlayDescriptor(_workspaceRoot, projectRoot, { ncui } = {}) {
|
|
91
|
+
const kosJsonPath = path.join(projectRoot, ".kos.json");
|
|
92
|
+
const kosJson = readJson(kosJsonPath);
|
|
93
|
+
kosJson.type = DESCRIPTOR_KAB_TYPE;
|
|
94
|
+
kosJson.kondra = buildNcuiDescriptor(ncui);
|
|
95
|
+
writeJson(kosJsonPath, kosJson);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const PROJECT_KINDS = {
|
|
99
|
+
plugin: {
|
|
100
|
+
generator: "@kosdev-code/kos-nx-plugin:kos-plugin-project",
|
|
101
|
+
uiType: "ddk.ncui.plugin",
|
|
102
|
+
overlay: overlayPlugin,
|
|
103
|
+
},
|
|
104
|
+
theme: {
|
|
105
|
+
generator: "@kosdev-code/kos-nx-plugin:kos-theme-project",
|
|
106
|
+
uiType: "ddk.ncui.theme",
|
|
107
|
+
overlay: overlayTheme,
|
|
108
|
+
},
|
|
109
|
+
// A content project's .kos.json is its KAB's descriptor.json.
|
|
110
|
+
descriptor: {
|
|
111
|
+
generator: "@kosdev-code/kos-nx-plugin:kos-content-project",
|
|
112
|
+
overlay: overlayDescriptor,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Writes the DDK layer over a generic plugin, theme or content project at `projectRoot`. */
|
|
117
|
+
export function applyDdkLayer(kind, workspaceRoot, projectRoot, options = {}) {
|
|
118
|
+
PROJECT_KINDS[kind].overlay(workspaceRoot, projectRoot, options);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The workspace's declared dependencies and devDependencies. */
|
|
122
|
+
function declaredPackages(workspaceRoot) {
|
|
123
|
+
const pkg = readJson(path.join(workspaceRoot, "package.json"));
|
|
124
|
+
return { ...pkg.dependencies, ...pkg.devDependencies };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const rootKosJsonPath = (workspaceRoot) =>
|
|
128
|
+
path.join(workspaceRoot, ".kos.json");
|
|
129
|
+
|
|
130
|
+
function workspaceHosts(workspaceRoot) {
|
|
131
|
+
const file = rootKosJsonPath(workspaceRoot);
|
|
132
|
+
return fs.existsSync(file) ? readJson(file).development?.hosts ?? [] : [];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The host a DDK plugin registers with: the one asked for, else the first host
|
|
137
|
+
* serving the DDK plugin context. A workspace without one registers none.
|
|
138
|
+
*/
|
|
139
|
+
export function pluginHost(workspaceRoot, host) {
|
|
140
|
+
if (host) return host;
|
|
141
|
+
return workspaceHosts(workspaceRoot).find(
|
|
142
|
+
(h) => h.pluginContext === DDK_PLUGIN_CONTEXT
|
|
143
|
+
)?.name;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Undoes the generic generator's default registration with a non-DDK host. */
|
|
147
|
+
export function unregisterPlugin(workspaceRoot, name) {
|
|
148
|
+
const file = rootKosJsonPath(workspaceRoot);
|
|
149
|
+
if (!fs.existsSync(file)) return;
|
|
150
|
+
const rootConfig = readJson(file);
|
|
151
|
+
let changed = false;
|
|
152
|
+
for (const h of rootConfig.development?.hosts ?? []) {
|
|
153
|
+
const plugins = (h.plugins ?? []).filter((p) => p.project !== name);
|
|
154
|
+
if (plugins.length !== (h.plugins ?? []).length) {
|
|
155
|
+
h.plugins = plugins;
|
|
156
|
+
changed = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (changed) writeJson(file, rootConfig);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Creates a DDK plugin or theme project. A dry run lists the generic generator's
|
|
164
|
+
* changes and the DDK files that would be written over them.
|
|
165
|
+
* A plugin registers with `host`, else with the workspace's DDK host, else with none.
|
|
166
|
+
*
|
|
167
|
+
* A descriptor project starts from the NCUI descriptor `ncui` describes: its layout
|
|
168
|
+
* (default standard) and options (carb, ice, beveragePourTest; all off by default).
|
|
169
|
+
*
|
|
170
|
+
* @param {"plugin" | "theme" | "descriptor"} kind
|
|
171
|
+
* @param {{workspaceRoot: string, name: string, directory?: string, host?: string,
|
|
172
|
+
* ncui?: object, dryRun?: boolean, stdio?: "pipe" | "inherit"}} options
|
|
173
|
+
*/
|
|
174
|
+
export function createDdkProject(
|
|
175
|
+
kind,
|
|
176
|
+
{
|
|
177
|
+
workspaceRoot,
|
|
178
|
+
name,
|
|
179
|
+
directory,
|
|
180
|
+
host,
|
|
181
|
+
ncui = {},
|
|
182
|
+
dryRun = false,
|
|
183
|
+
stdio = "pipe",
|
|
184
|
+
}
|
|
185
|
+
) {
|
|
186
|
+
const spec = PROJECT_KINDS[kind];
|
|
187
|
+
if (kind === "descriptor") buildNcuiDescriptor(ncui);
|
|
188
|
+
const before = declaredPackages(workspaceRoot);
|
|
189
|
+
const registerWith =
|
|
190
|
+
kind === "plugin" ? pluginHost(workspaceRoot, host) : undefined;
|
|
191
|
+
const result = spawnSync(
|
|
192
|
+
"npx",
|
|
193
|
+
[
|
|
194
|
+
"nx",
|
|
195
|
+
"generate",
|
|
196
|
+
spec.generator,
|
|
197
|
+
`--name=${name}`,
|
|
198
|
+
...(spec.uiType ? [`--uiType=${spec.uiType}`] : []),
|
|
199
|
+
...(directory ? [`--directory=${directory}`] : []),
|
|
200
|
+
...(registerWith ? [`--host=${registerWith}`] : []),
|
|
201
|
+
"--no-interactive",
|
|
202
|
+
...(dryRun ? ["--dry-run"] : []),
|
|
203
|
+
],
|
|
204
|
+
{
|
|
205
|
+
cwd: workspaceRoot,
|
|
206
|
+
encoding: "utf-8",
|
|
207
|
+
stdio,
|
|
208
|
+
shell: process.platform === "win32",
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
if (result.status !== 0) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`nx generate exited with ${result.status}\n${result.stderr ?? ""}`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const output = result.stdout?.trim() ?? "";
|
|
217
|
+
if (dryRun) {
|
|
218
|
+
return {
|
|
219
|
+
output,
|
|
220
|
+
ddkFiles:
|
|
221
|
+
kind === "descriptor"
|
|
222
|
+
? [
|
|
223
|
+
`.kos.json: type ${DESCRIPTOR_KAB_TYPE}, kondra.ncui for the ${
|
|
224
|
+
ncui.layout ?? "standard"
|
|
225
|
+
} layout`,
|
|
226
|
+
]
|
|
227
|
+
: templateFiles(kind),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const project = findProjectByName(workspaceRoot, name);
|
|
232
|
+
if (!project) throw new Error(`nx generate did not create project ${name}`);
|
|
233
|
+
if (kind === "plugin" && !registerWith) unregisterPlugin(workspaceRoot, name);
|
|
234
|
+
applyDdkLayer(kind, workspaceRoot, path.join(workspaceRoot, project.root), {
|
|
235
|
+
ncui,
|
|
236
|
+
});
|
|
237
|
+
const installed = path.join(workspaceRoot, "node_modules");
|
|
238
|
+
const toInstall = Object.keys(declaredPackages(workspaceRoot)).filter(
|
|
239
|
+
(name) => !before[name] && !fs.existsSync(path.join(installed, name))
|
|
240
|
+
);
|
|
241
|
+
return { output, root: project.root, toInstall };
|
|
242
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// kosui extension entry: adds the ddk:* commands when this package is installed in a
|
|
2
|
+
// KOS workspace (or globally beside kosui). kosui passes its CLI helpers as `host`.
|
|
3
|
+
import * as agentInstall from "./generators/agent-install.mjs";
|
|
4
|
+
import * as catalog from "./generators/catalog.mjs";
|
|
5
|
+
import * as contributions from "./generators/contributions.mjs";
|
|
6
|
+
import * as dashboard from "./generators/dashboard.mjs";
|
|
7
|
+
import * as descriptorEntries from "./generators/descriptor-entries.mjs";
|
|
8
|
+
import * as descriptorProject from "./generators/descriptor-project.mjs";
|
|
9
|
+
import * as dev from "./generators/dev.mjs";
|
|
10
|
+
import * as pluginProject from "./generators/plugin-project.mjs";
|
|
11
|
+
import * as themeProject from "./generators/theme-project.mjs";
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
id: "ddk",
|
|
15
|
+
generators: [
|
|
16
|
+
{ metadata: contributions.metadata, register: contributions.register },
|
|
17
|
+
{ metadata: dashboard.metadata, register: dashboard.register },
|
|
18
|
+
{ metadata: catalog.metadata, register: catalog.register },
|
|
19
|
+
{ metadata: pluginProject.metadata, register: pluginProject.register },
|
|
20
|
+
{ metadata: themeProject.metadata, register: themeProject.register },
|
|
21
|
+
{
|
|
22
|
+
metadata: descriptorProject.metadata,
|
|
23
|
+
register: descriptorProject.register,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
metadata: descriptorEntries.metadata,
|
|
27
|
+
register: descriptorEntries.register,
|
|
28
|
+
},
|
|
29
|
+
{ metadata: dev.metadata, register: dev.register },
|
|
30
|
+
{ metadata: agentInstall.metadata, register: agentInstall.register },
|
|
31
|
+
],
|
|
32
|
+
};
|