@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,292 @@
|
|
|
1
|
+
// A DDK plugin project's contributions, read from its .kos.json, and their checks
|
|
2
|
+
// against the extension points' schemas, the standard contributions they override
|
|
3
|
+
// and the rule that plugins compose DDK components without setting tokens.
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
MAX_RANK,
|
|
8
|
+
OVERRIDABLE_POINTS,
|
|
9
|
+
listOverridableContributions,
|
|
10
|
+
loadCatalog,
|
|
11
|
+
uniqueContributions,
|
|
12
|
+
} from "../codegen/overrides.mjs";
|
|
13
|
+
import {
|
|
14
|
+
descriptorListsSlot,
|
|
15
|
+
findDescriptorProjects,
|
|
16
|
+
} from "../codegen/descriptor.mjs";
|
|
17
|
+
import { findDdkPlugins } from "../generators/dev.mjs";
|
|
18
|
+
import { loadReference } from "./reference.mjs";
|
|
19
|
+
|
|
20
|
+
const readJson = (file) => JSON.parse(readFileSync(file, "utf-8"));
|
|
21
|
+
|
|
22
|
+
const SLOT_KEYS = Object.fromEntries(
|
|
23
|
+
Object.values(OVERRIDABLE_POINTS).flatMap(({ contributionKeys, keys }) =>
|
|
24
|
+
contributionKeys.map((key) => [key, keys])
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/** The plugin project, its directory and its kos.ui.plugin block. */
|
|
29
|
+
function loadPlugin(root, project) {
|
|
30
|
+
const plugins = findDdkPlugins(root);
|
|
31
|
+
const plugin = plugins.find(
|
|
32
|
+
(p) => p.project === project || p.alias === project
|
|
33
|
+
);
|
|
34
|
+
if (!plugin) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`No DDK plugin project "${project}". DDK plugin projects: ${
|
|
37
|
+
plugins.map((p) => p.project).join(", ") || "none"
|
|
38
|
+
}.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const dir = path.join(root, plugin.dir);
|
|
42
|
+
const kos = readJson(path.join(dir, ".kos.json"));
|
|
43
|
+
return { ...plugin, absDir: dir, block: kos.kos?.ui?.plugin ?? {} };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const slotOf = (key, entry) =>
|
|
47
|
+
Object.fromEntries(
|
|
48
|
+
(SLOT_KEYS[key] ?? [])
|
|
49
|
+
.filter((field) => entry[field] !== undefined)
|
|
50
|
+
.map((field) => [field, entry[field]])
|
|
51
|
+
);
|
|
52
|
+
const sameSlot = (a, b) => {
|
|
53
|
+
const keys = Object.keys(a);
|
|
54
|
+
return (
|
|
55
|
+
keys.length > 0 &&
|
|
56
|
+
keys.length === Object.keys(b).length &&
|
|
57
|
+
keys.every((k) => a[k] === b[k])
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
// Lower rank wins; an unranked contribution loses to any ranked one.
|
|
61
|
+
const beats = (rank, other) =>
|
|
62
|
+
typeof rank === "number" && (typeof other !== "number" || rank < other);
|
|
63
|
+
|
|
64
|
+
/** Each contribution with its point, slot, experience and the standard ones it shares a slot with. */
|
|
65
|
+
export function describePlugin(root, project) {
|
|
66
|
+
const plugin = loadPlugin(root, project);
|
|
67
|
+
const { extensionPoints } = loadReference();
|
|
68
|
+
const standard = uniqueContributions(listOverridableContributions());
|
|
69
|
+
const contributes = plugin.block.contributes ?? {};
|
|
70
|
+
const experiences = contributes.experiences ?? {};
|
|
71
|
+
const contributions = [];
|
|
72
|
+
for (const [key, entries] of Object.entries(contributes)) {
|
|
73
|
+
if (!Array.isArray(entries)) continue;
|
|
74
|
+
const point = extensionPoints.find((p) => p.contributionKey === key);
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
const slot = slotOf(key, entry);
|
|
77
|
+
const shared = standard.filter(
|
|
78
|
+
(s) =>
|
|
79
|
+
s.plugin !== plugin.project &&
|
|
80
|
+
s.contributionKey === key &&
|
|
81
|
+
sameSlot(slot, s.keys)
|
|
82
|
+
);
|
|
83
|
+
const experience = experiences[entry.experienceId];
|
|
84
|
+
contributions.push({
|
|
85
|
+
contributionKey: key,
|
|
86
|
+
...(point ? { extensionPoint: point.id } : {}),
|
|
87
|
+
id: entry.id,
|
|
88
|
+
...(Object.keys(slot).length ? { slot } : {}),
|
|
89
|
+
...(typeof entry.rank === "number" ? { rank: entry.rank } : {}),
|
|
90
|
+
...(experience
|
|
91
|
+
? { component: experience.component, location: experience.location }
|
|
92
|
+
: {}),
|
|
93
|
+
...(shared.length
|
|
94
|
+
? {
|
|
95
|
+
sharesSlotWith: shared.map((s) => ({
|
|
96
|
+
id: s.id,
|
|
97
|
+
...(typeof s.rank === "number" ? { rank: s.rank } : {}),
|
|
98
|
+
wins: beats(entry.rank, s.rank),
|
|
99
|
+
})),
|
|
100
|
+
}
|
|
101
|
+
: {}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
project: plugin.project,
|
|
107
|
+
dir: plugin.dir,
|
|
108
|
+
pluginId: plugin.block.id,
|
|
109
|
+
contributions,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sourceFiles(dir) {
|
|
114
|
+
if (!existsSync(dir)) return [];
|
|
115
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
116
|
+
const full = path.join(dir, entry.name);
|
|
117
|
+
if (entry.isDirectory())
|
|
118
|
+
return entry.name === "node_modules" ? [] : sourceFiles(full);
|
|
119
|
+
return /\.(tsx?|css)$/.test(entry.name) ? [full] : [];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The experience loads the module's default export, or the export named by component.
|
|
124
|
+
const exportsComponent = (text, name) =>
|
|
125
|
+
/export\s+default\b/.test(text) ||
|
|
126
|
+
new RegExp(`export\\s+(const|let|function|class)\\s+${name}\\b`).test(text) ||
|
|
127
|
+
new RegExp(`export\\s*\\{[^}]*\\b${name}\\b[^}]*\\}`).test(text);
|
|
128
|
+
|
|
129
|
+
function checkField(field, value) {
|
|
130
|
+
if (value === undefined || value === "") {
|
|
131
|
+
return field.required ? `missing required ${field.name}` : null;
|
|
132
|
+
}
|
|
133
|
+
if (field.type.startsWith('"')) {
|
|
134
|
+
const allowed = field.type.split(" | ").map((t) => JSON.parse(t));
|
|
135
|
+
return allowed.includes(value)
|
|
136
|
+
? null
|
|
137
|
+
: `${field.name} must be ${field.type}`;
|
|
138
|
+
}
|
|
139
|
+
if (
|
|
140
|
+
["string", "number", "boolean"].includes(field.type) &&
|
|
141
|
+
typeof value !== field.type
|
|
142
|
+
) {
|
|
143
|
+
return `${field.name} must be a ${field.type}`;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Errors and warnings for a plugin project; ok when there are no errors. */
|
|
149
|
+
export function validatePlugin(root, project) {
|
|
150
|
+
const plugin = loadPlugin(root, project);
|
|
151
|
+
const { extensionPoints } = loadReference();
|
|
152
|
+
const described = describePlugin(root, project);
|
|
153
|
+
const contributes = plugin.block.contributes ?? {};
|
|
154
|
+
const experiences = contributes.experiences ?? {};
|
|
155
|
+
const errors = [];
|
|
156
|
+
const warnings = [];
|
|
157
|
+
const ids = new Map();
|
|
158
|
+
|
|
159
|
+
for (const [key, entries] of Object.entries(contributes)) {
|
|
160
|
+
if (!Array.isArray(entries)) continue;
|
|
161
|
+
const point = extensionPoints.find((p) => p.contributionKey === key);
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
const where = `contributes.${key} ${entry.id ?? "(no id)"}`;
|
|
164
|
+
if (!entry.id) errors.push(`${where}: missing id`);
|
|
165
|
+
else if (ids.has(entry.id))
|
|
166
|
+
errors.push(
|
|
167
|
+
`${where}: id also used in contributes.${ids.get(entry.id)}`
|
|
168
|
+
);
|
|
169
|
+
else ids.set(entry.id, key);
|
|
170
|
+
|
|
171
|
+
for (const field of point?.fields ?? []) {
|
|
172
|
+
if (field.name === "rank") continue;
|
|
173
|
+
const problem = checkField(field, entry[field.name]);
|
|
174
|
+
if (problem) errors.push(`${where}: ${problem} (${point.id})`);
|
|
175
|
+
}
|
|
176
|
+
if (entry.rank !== undefined) {
|
|
177
|
+
if (
|
|
178
|
+
!Number.isInteger(entry.rank) ||
|
|
179
|
+
entry.rank < 0 ||
|
|
180
|
+
entry.rank > MAX_RANK
|
|
181
|
+
) {
|
|
182
|
+
errors.push(
|
|
183
|
+
`${where}: rank must be an integer from 0 to ${MAX_RANK}`
|
|
184
|
+
);
|
|
185
|
+
} else if (point && !point.isRankable) {
|
|
186
|
+
warnings.push(
|
|
187
|
+
`${where}: ${point.id} is not ranked, so rank has no effect`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (entry.experienceId !== undefined || point?.hasView) {
|
|
193
|
+
const experience = experiences[entry.experienceId];
|
|
194
|
+
if (!experience) {
|
|
195
|
+
errors.push(
|
|
196
|
+
`${where}: experience ${
|
|
197
|
+
entry.experienceId ?? "(none)"
|
|
198
|
+
} is not in contributes.experiences`
|
|
199
|
+
);
|
|
200
|
+
} else {
|
|
201
|
+
const file = path.join(plugin.absDir, experience.location ?? "");
|
|
202
|
+
if (!experience.location || !existsSync(file)) {
|
|
203
|
+
errors.push(
|
|
204
|
+
`${where}: component file ${experience.location} does not exist`
|
|
205
|
+
);
|
|
206
|
+
} else if (
|
|
207
|
+
experience.component &&
|
|
208
|
+
!exportsComponent(readFileSync(file, "utf-8"), experience.component)
|
|
209
|
+
) {
|
|
210
|
+
errors.push(
|
|
211
|
+
`${where}: ${experience.location} has no default export and does not export ${experience.component}`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// A utility, setup step or navigation view shows only if the NCUI descriptor lists it.
|
|
220
|
+
const readFs = {
|
|
221
|
+
root,
|
|
222
|
+
read: (file) => {
|
|
223
|
+
const abs = path.join(root, file);
|
|
224
|
+
return existsSync(abs) ? readFileSync(abs, "utf-8") : null;
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
const descriptorProjects = findDescriptorProjects(readFs).map((p) => p.name);
|
|
228
|
+
for (const [key, type, field] of [
|
|
229
|
+
["utilities", "utility", "utilDescriptor"],
|
|
230
|
+
["setupStep", "setup", "setupDescriptor"],
|
|
231
|
+
["navViews", "nav", "navDescriptor"],
|
|
232
|
+
]) {
|
|
233
|
+
for (const entry of contributes[key] ?? []) {
|
|
234
|
+
const slot = entry[field];
|
|
235
|
+
if (!slot || descriptorListsSlot(readFs, type, slot)) continue;
|
|
236
|
+
warnings.push(
|
|
237
|
+
`contributes.${key} ${entry.id}: ${field} "${slot}" is not in ${
|
|
238
|
+
descriptorProjects.length
|
|
239
|
+
? `descriptor project ${descriptorProjects.join(", ")}`
|
|
240
|
+
: "the standard NCUI descriptor (no descriptor project in the workspace)"
|
|
241
|
+
}, so the NCUI does not show it${
|
|
242
|
+
descriptorProjects.length
|
|
243
|
+
? `; list it with kosui ddk:descriptor-entries --project ${project} --descriptorProject ${descriptorProjects[0]}`
|
|
244
|
+
: ""
|
|
245
|
+
}`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const bySlot = new Map();
|
|
251
|
+
for (const c of described.contributions.filter((c) => c.slot)) {
|
|
252
|
+
const slotKey = `${c.contributionKey} ${JSON.stringify(c.slot)}`;
|
|
253
|
+
const other = bySlot.get(slotKey);
|
|
254
|
+
if (other && other.rank === c.rank) {
|
|
255
|
+
warnings.push(
|
|
256
|
+
`contributes.${c.contributionKey} ${c.id}: same slot and rank as ${other.id}; which renders is not defined`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
bySlot.set(slotKey, c);
|
|
260
|
+
// The standard plugins are alternatives, so sharing slots with each other is expected.
|
|
261
|
+
if (loadCatalog().sources.includes(plugin.project)) continue;
|
|
262
|
+
for (const s of c.sharesSlotWith ?? []) {
|
|
263
|
+
if (!s.wins) {
|
|
264
|
+
warnings.push(
|
|
265
|
+
`contributes.${c.contributionKey} ${c.id}: shares a slot with ${
|
|
266
|
+
s.id
|
|
267
|
+
} (${
|
|
268
|
+
typeof s.rank === "number" ? `rank ${s.rank}` : "unranked"
|
|
269
|
+
}) without a winning rank, so it does not replace it`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const srcDir = path.join(plugin.absDir, "src");
|
|
276
|
+
for (const file of sourceFiles(srcDir)) {
|
|
277
|
+
const text = readFileSync(file, "utf-8");
|
|
278
|
+
const rel = path.relative(plugin.absDir, file).split(path.sep).join("/");
|
|
279
|
+
const set = [
|
|
280
|
+
...new Set([...text.matchAll(/(--ddk-[\w-]+)\s*:/g)].map((m) => m[1])),
|
|
281
|
+
];
|
|
282
|
+
if (set.length) {
|
|
283
|
+
errors.push(
|
|
284
|
+
`${rel}: sets DDK tokens (${set.join(
|
|
285
|
+
", "
|
|
286
|
+
)}); plugins compose DDK components and do not set tokens`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return { project: plugin.project, ok: errors.length === 0, errors, warnings };
|
|
292
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// The build-time reference (extension points, components, DESIGN.md per theme) as
|
|
2
|
+
// the kos-ddk server's resources and as the data its component and capability
|
|
3
|
+
// tools answer from.
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { REFERENCE_PATH } from "../build-paths.mjs";
|
|
6
|
+
import {
|
|
7
|
+
listOverridableContributions,
|
|
8
|
+
uniqueContributions,
|
|
9
|
+
} from "../codegen/overrides.mjs";
|
|
10
|
+
|
|
11
|
+
export const COMPONENT_LIBRARIES = [
|
|
12
|
+
"@kosdev-code/kos-ddk-components",
|
|
13
|
+
"@kosdev-code/kos-ddk-model-components",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
let reference;
|
|
17
|
+
|
|
18
|
+
export function loadReference() {
|
|
19
|
+
if (!reference) {
|
|
20
|
+
if (!existsSync(REFERENCE_PATH)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`DDK reference missing at ${REFERENCE_PATH}; it is written by the kos-ddk-cli build.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
reference = JSON.parse(readFileSync(REFERENCE_PATH, "utf-8"));
|
|
26
|
+
}
|
|
27
|
+
return reference;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const ddkResources = () => loadReference().resources;
|
|
31
|
+
|
|
32
|
+
const STOP_WORDS = new Set(
|
|
33
|
+
"a an and add be can for from get i in is it like my new of on or should show that the this to want when which with".split(
|
|
34
|
+
" "
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
/** Lowercase words of a text, camelCase and kebab-case split, plural s dropped. */
|
|
39
|
+
export function terms(text) {
|
|
40
|
+
return String(text)
|
|
41
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
.split(/[^a-z0-9]+/)
|
|
44
|
+
.filter((t) => t && !STOP_WORDS.has(t))
|
|
45
|
+
.map((t) => (t.length > 3 && t.endsWith("s") ? t.slice(0, -1) : t));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Components whose name or folder matches `query`, optionally in one library. */
|
|
49
|
+
export function listComponents({ library, query } = {}) {
|
|
50
|
+
const wanted = query ? terms(query) : [];
|
|
51
|
+
return loadReference()
|
|
52
|
+
.components.filter((c) => !library || c.package === library)
|
|
53
|
+
.filter((c) => {
|
|
54
|
+
if (!wanted.length) return true;
|
|
55
|
+
const own = new Set(terms(`${c.name} ${c.file}`));
|
|
56
|
+
return wanted.every((t) => own.has(t));
|
|
57
|
+
})
|
|
58
|
+
.map(({ name, package: pkg, file, styled }) => ({
|
|
59
|
+
name,
|
|
60
|
+
package: pkg,
|
|
61
|
+
file,
|
|
62
|
+
...(styled ? { styled: true } : {}),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const cell = (v) => `\`${String(v).replace(/\|/g, "\\|")}\``;
|
|
67
|
+
|
|
68
|
+
/** One component's reference, as markdown, or null when no export has that name. */
|
|
69
|
+
export function describeComponent(name, library) {
|
|
70
|
+
const { components, themes } = loadReference();
|
|
71
|
+
const matches = components.filter(
|
|
72
|
+
(c) => c.name === name && (!library || c.package === library)
|
|
73
|
+
);
|
|
74
|
+
if (!matches.length) return null;
|
|
75
|
+
return matches
|
|
76
|
+
.map((c) => {
|
|
77
|
+
const lines = [
|
|
78
|
+
`# ${c.name}${c.styled ? " (styled part)" : ""}`,
|
|
79
|
+
"",
|
|
80
|
+
`\`import { ${c.name} } from "${c.package}";\` — source \`${c.file}\`.`,
|
|
81
|
+
...(c.description ? ["", c.description] : []),
|
|
82
|
+
"",
|
|
83
|
+
"## Props",
|
|
84
|
+
"",
|
|
85
|
+
];
|
|
86
|
+
const described = c.props.some((p) => p.description);
|
|
87
|
+
lines.push(
|
|
88
|
+
...(c.props.length
|
|
89
|
+
? [
|
|
90
|
+
`| Prop | Type | Required |${described ? " Description |" : ""}`,
|
|
91
|
+
`| --- | --- | --- |${described ? " --- |" : ""}`,
|
|
92
|
+
...c.props.map(
|
|
93
|
+
(p) =>
|
|
94
|
+
`| ${cell(p.name)} | ${cell(p.type)} | ${
|
|
95
|
+
p.optional ? "no" : "yes"
|
|
96
|
+
} |${
|
|
97
|
+
described
|
|
98
|
+
? ` ${(p.description ?? "").replace(/\s*\n\s*/g, " ")} |`
|
|
99
|
+
: ""
|
|
100
|
+
}`
|
|
101
|
+
),
|
|
102
|
+
]
|
|
103
|
+
: ["No props of its own; it takes the element's standard props."])
|
|
104
|
+
);
|
|
105
|
+
if (c.inherits?.length) {
|
|
106
|
+
lines.push(
|
|
107
|
+
"",
|
|
108
|
+
`Also takes every prop of ${c.inherits
|
|
109
|
+
.map((t) => cell(t))
|
|
110
|
+
.join(
|
|
111
|
+
", "
|
|
112
|
+
)} (for an element, all its HTML attributes and event handlers such as \`onClick\`).`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (c.renders.length) {
|
|
116
|
+
lines.push(
|
|
117
|
+
"",
|
|
118
|
+
`Renders: ${c.renders.map((r) => `\`${r}\``).join(", ")}.`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (c.hooks.length) {
|
|
122
|
+
lines.push("", `Uses: ${c.hooks.map((h) => `\`${h}\``).join(", ")}.`);
|
|
123
|
+
}
|
|
124
|
+
if (c.styles?.length) {
|
|
125
|
+
lines.push(
|
|
126
|
+
"",
|
|
127
|
+
"## Fixed styles",
|
|
128
|
+
"",
|
|
129
|
+
...c.styles.map((s) => `- \`${s.property}: ${s.value}\``)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (c.tokens.length) {
|
|
133
|
+
lines.push(
|
|
134
|
+
"",
|
|
135
|
+
"## Tokens it reads",
|
|
136
|
+
"",
|
|
137
|
+
"Theme values; plugins use the component as is. Change tokens only for a new component or theme.",
|
|
138
|
+
"",
|
|
139
|
+
`| Token | ${themes.join(" | ")} |`,
|
|
140
|
+
`| --- | ${themes.map(() => "---").join(" | ")} |`,
|
|
141
|
+
...c.tokens.map(
|
|
142
|
+
(t) =>
|
|
143
|
+
`| ${cell(t.name)} | ${themes
|
|
144
|
+
.map((id) =>
|
|
145
|
+
t.values[id] !== undefined ? cell(t.values[id]) : "undefined"
|
|
146
|
+
)
|
|
147
|
+
.join(" | ")} |`
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
const bySelector = c.tokens.filter((t) => t.bySelector);
|
|
151
|
+
if (bySelector.length) {
|
|
152
|
+
lines.push(
|
|
153
|
+
"",
|
|
154
|
+
"Overridden by selector:",
|
|
155
|
+
...bySelector.flatMap((t) =>
|
|
156
|
+
Object.entries(t.bySelector).flatMap(([id, sels]) =>
|
|
157
|
+
Object.entries(sels).map(
|
|
158
|
+
([sel, value]) =>
|
|
159
|
+
`- \`${t.name}\` (${id}, \`${sel}\`): \`${value}\``
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return lines.join("\n");
|
|
167
|
+
})
|
|
168
|
+
.join("\n\n");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function score(wanted, primary, secondary) {
|
|
172
|
+
const first = new Set(terms(primary));
|
|
173
|
+
const second = new Set(terms(secondary));
|
|
174
|
+
let total = 0;
|
|
175
|
+
const matched = [];
|
|
176
|
+
for (const t of wanted) {
|
|
177
|
+
if (first.has(t)) {
|
|
178
|
+
total += 3;
|
|
179
|
+
matched.push(t);
|
|
180
|
+
} else if (second.has(t)) {
|
|
181
|
+
total += 1;
|
|
182
|
+
matched.push(t);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { total, matched };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The extension points, standard contributions and components that best match a
|
|
190
|
+
* plain-language need.
|
|
191
|
+
*/
|
|
192
|
+
export function findCapability(need, { limit = 5 } = {}) {
|
|
193
|
+
const wanted = [...new Set(terms(need))];
|
|
194
|
+
const { extensionPoints, components, contributionTools } = loadReference();
|
|
195
|
+
const standard = uniqueContributions(listOverridableContributions());
|
|
196
|
+
const rank = (items) =>
|
|
197
|
+
items
|
|
198
|
+
.filter((item) => item.total > 0)
|
|
199
|
+
.sort((a, b) => b.total - a.total)
|
|
200
|
+
.slice(0, limit)
|
|
201
|
+
.map(({ total: _total, ...item }) => item);
|
|
202
|
+
const slot = (keys) => Object.values(keys).join(" ");
|
|
203
|
+
|
|
204
|
+
const defined = new Set(extensionPoints.map((p) => p.contributionKey));
|
|
205
|
+
const points = [
|
|
206
|
+
...extensionPoints.map((p) => ({
|
|
207
|
+
id: p.id,
|
|
208
|
+
contributionKey: p.contributionKey,
|
|
209
|
+
resource: `ddk://extension-point/${p.id}`,
|
|
210
|
+
...(p.writer ? { tool: p.writer.tool } : {}),
|
|
211
|
+
...score(
|
|
212
|
+
wanted,
|
|
213
|
+
`${p.id} ${p.displayName} ${p.contributionKey}`,
|
|
214
|
+
[
|
|
215
|
+
p.description,
|
|
216
|
+
p.category ?? "",
|
|
217
|
+
...p.fields.map((f) => `${f.name} ${f.description ?? ""}`),
|
|
218
|
+
...standard
|
|
219
|
+
.filter((c) => c.contributionKey === p.contributionKey)
|
|
220
|
+
.map((c) => `${c.id} ${slot(c.keys)}`),
|
|
221
|
+
].join(" ")
|
|
222
|
+
),
|
|
223
|
+
})),
|
|
224
|
+
...Object.entries(contributionTools)
|
|
225
|
+
.filter(([key]) => !defined.has(key))
|
|
226
|
+
.map(([key, writer]) => ({
|
|
227
|
+
contributionKey: key,
|
|
228
|
+
tool: writer.tool,
|
|
229
|
+
...score(
|
|
230
|
+
wanted,
|
|
231
|
+
`${key} ${writer.command}`,
|
|
232
|
+
standard
|
|
233
|
+
.filter((c) => c.contributionKey === key)
|
|
234
|
+
.map((c) => `${c.id} ${slot(c.keys)}`)
|
|
235
|
+
.join(" ")
|
|
236
|
+
),
|
|
237
|
+
})),
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
extensionPoints: rank(points),
|
|
242
|
+
standardContributions: rank(
|
|
243
|
+
standard.map((c) => ({
|
|
244
|
+
id: c.id,
|
|
245
|
+
contributionKey: c.contributionKey,
|
|
246
|
+
keys: c.keys,
|
|
247
|
+
...(typeof c.rank === "number" ? { rank: c.rank } : {}),
|
|
248
|
+
...score(wanted, `${c.id} ${slot(c.keys)}`, c.point),
|
|
249
|
+
}))
|
|
250
|
+
),
|
|
251
|
+
components: rank(
|
|
252
|
+
components.map((c) => ({
|
|
253
|
+
name: c.name,
|
|
254
|
+
package: c.package,
|
|
255
|
+
...score(
|
|
256
|
+
wanted,
|
|
257
|
+
c.name,
|
|
258
|
+
`${c.file} ${c.props.map((p) => p.name).join(" ")}`
|
|
259
|
+
),
|
|
260
|
+
}))
|
|
261
|
+
),
|
|
262
|
+
next: "Write with the point's tool (pass a standard contribution's id as override to replace it), then describe_ddk_component for each component you render.",
|
|
263
|
+
};
|
|
264
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// kos-ddk MCP server entry (stdio). The agent plugin bundles this with the chassis.
|
|
2
|
+
import { runMcpServer } from "@kosdev-code/kos-ui-cli/extension/mcp";
|
|
3
|
+
import { pkg } from "./pkg-info.mjs";
|
|
4
|
+
import { ddkResources } from "./reference.mjs";
|
|
5
|
+
import { ddkTools } from "./tools.mjs";
|
|
6
|
+
|
|
7
|
+
await runMcpServer(process.argv.slice(2), {
|
|
8
|
+
name: "kos-ddk",
|
|
9
|
+
version: pkg.version,
|
|
10
|
+
tools: ddkTools,
|
|
11
|
+
resources: ddkResources(),
|
|
12
|
+
});
|