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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +181 -2
  2. package/agent-plugin/.claude-plugin/marketplace.json +13 -0
  3. package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
  4. package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
  5. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +45 -0
  6. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +43 -0
  7. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +965 -0
  8. package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
  9. package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
  10. package/agent-plugin/kos-ddk-tools/reference/reference.json +21161 -0
  11. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48656 -0
  12. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +110 -0
  13. package/agent-plugin/kos-ddk-tools/skills/ddk-config-page/SKILL.md +130 -0
  14. package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +59 -0
  15. package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +45 -0
  16. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  17. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  18. package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
  19. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  20. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  21. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  22. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  23. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  24. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/index.ts__template__ +1 -0
  25. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  26. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  27. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  28. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  29. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  30. package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
  31. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  32. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  33. package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
  34. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  35. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
  36. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  37. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  38. package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
  39. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  40. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  41. package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
  42. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  43. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  44. package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
  45. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
  46. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
  47. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
  48. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  49. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  50. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  51. package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
  52. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  53. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  54. package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
  55. package/catalog/contributions.json +965 -0
  56. package/guides/config-property-cards.md +77 -0
  57. package/guides/ddk-dev.md +59 -0
  58. package/guides/getting-started.md +126 -0
  59. package/guides/storybook.md +127 -0
  60. package/package.json +33 -3
  61. package/reference/reference.json +21161 -0
  62. package/src/build-paths.mjs +20 -0
  63. package/src/codegen/contribution.mjs +530 -0
  64. package/src/codegen/descriptor.mjs +422 -0
  65. package/src/codegen/json-preserve.mjs +137 -0
  66. package/src/codegen/ncui-descriptor.mjs +167 -0
  67. package/src/codegen/overrides.mjs +263 -0
  68. package/src/codegen/project.mjs +271 -0
  69. package/src/extension.mjs +32 -0
  70. package/src/generators/agent-install.mjs +80 -0
  71. package/src/generators/catalog.mjs +81 -0
  72. package/src/generators/contributions.mjs +164 -0
  73. package/src/generators/dashboard.mjs +282 -0
  74. package/src/generators/descriptor-entries.mjs +53 -0
  75. package/src/generators/descriptor-project.mjs +84 -0
  76. package/src/generators/dev.mjs +231 -0
  77. package/src/generators/override-prompts.mjs +27 -0
  78. package/src/generators/plugin-project.mjs +71 -0
  79. package/src/generators/theme-project.mjs +53 -0
  80. package/src/handlers.mjs +335 -0
  81. package/src/mcp/pkg-info.mjs +7 -0
  82. package/src/mcp/plugin-inspect.mjs +328 -0
  83. package/src/mcp/reference.mjs +315 -0
  84. package/src/mcp/server.mjs +12 -0
  85. package/src/mcp/tools.mjs +619 -0
  86. package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  87. package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  88. package/templates/cui/index.ts__template__ +1 -0
  89. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  90. package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  91. package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  92. package/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  93. package/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  94. package/templates/dashboard-region/index.ts__template__ +1 -0
  95. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  96. package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  97. package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  98. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  99. package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  100. package/templates/macro-summary/index.ts__template__ +1 -0
  101. package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  102. package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  103. package/templates/nav/index.ts__template__ +1 -0
  104. package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  105. package/templates/plugin-project/.storybook/registration.ts.template +6 -0
  106. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  107. package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  108. package/templates/pump-detail/index.ts__template__ +1 -0
  109. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  110. package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  111. package/templates/pump-summary/index.ts__template__ +1 -0
  112. package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  113. package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  114. package/templates/setup/index.ts__template__ +1 -0
  115. package/templates/theme-project/theme/assets/component.css.template +2 -0
  116. package/templates/theme-project/theme/assets/generic.css.template +2 -0
  117. package/templates/theme-project/theme/assets/semantic.css.template +2 -0
  118. package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  119. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  120. package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  121. package/templates/trouble-action/index.ts__template__ +1 -0
  122. package/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  123. package/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  124. package/templates/utility/index.ts__template__ +1 -0
@@ -0,0 +1,315 @@
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
+ /** A props-style table: name, type, required, and description when any has one. */
69
+ function fieldTable(fields) {
70
+ const described = fields.some((p) => p.description);
71
+ return [
72
+ `| Name | Type | Required |${described ? " Description |" : ""}`,
73
+ `| --- | --- | --- |${described ? " --- |" : ""}`,
74
+ ...fields.map(
75
+ (p) =>
76
+ `| ${cell(p.name)} | ${cell(p.type)} | ${p.optional ? "no" : "yes"} |${
77
+ described
78
+ ? ` ${(p.description ?? "").replace(/\s*\n\s*/g, " ")} |`
79
+ : ""
80
+ }`
81
+ ),
82
+ ];
83
+ }
84
+
85
+ /** One hook's reference, as markdown: signature, options and what it returns. */
86
+ function describeHook(h) {
87
+ const lines = [
88
+ `# ${h.name} (hook)`,
89
+ "",
90
+ `\`import { ${h.name} } from "${h.package}";\` — source \`${h.file}\`.`,
91
+ ...(h.description ? ["", h.description] : []),
92
+ ];
93
+ if (h.signature) {
94
+ lines.push("", "```ts", `${h.name}${h.signature}`, "```");
95
+ }
96
+ for (const p of h.params ?? []) {
97
+ lines.push(
98
+ "",
99
+ `## Parameter \`${p.name}\`${p.optional ? " (optional)" : ""}: ${cell(
100
+ p.type
101
+ )}`
102
+ );
103
+ if (p.fields?.length) lines.push("", ...fieldTable(p.fields));
104
+ }
105
+ if (h.returnType) {
106
+ lines.push("", `## Returns ${cell(h.returnType)}`);
107
+ if (h.returns?.length) lines.push("", ...fieldTable(h.returns));
108
+ }
109
+ return lines.join("\n");
110
+ }
111
+
112
+ /** One component's or hook's reference, as markdown, or null when none has that name. */
113
+ export function describeComponent(name, library) {
114
+ const { components, themes, hooks = [] } = loadReference();
115
+ const matches = components.filter(
116
+ (c) => c.name === name && (!library || c.package === library)
117
+ );
118
+ if (!matches.length) {
119
+ const hookMatches = hooks.filter(
120
+ (h) => h.name === name && (!library || h.package === library)
121
+ );
122
+ return hookMatches.length
123
+ ? hookMatches.map(describeHook).join("\n\n")
124
+ : null;
125
+ }
126
+ return matches
127
+ .map((c) => {
128
+ const lines = [
129
+ `# ${c.name}${c.styled ? " (styled part)" : ""}`,
130
+ "",
131
+ `\`import { ${c.name} } from "${c.package}";\` — source \`${c.file}\`.`,
132
+ ...(c.description ? ["", c.description] : []),
133
+ "",
134
+ "## Props",
135
+ "",
136
+ ];
137
+ const described = c.props.some((p) => p.description);
138
+ lines.push(
139
+ ...(c.props.length
140
+ ? [
141
+ `| Prop | Type | Required |${described ? " Description |" : ""}`,
142
+ `| --- | --- | --- |${described ? " --- |" : ""}`,
143
+ ...c.props.map(
144
+ (p) =>
145
+ `| ${cell(p.name)} | ${cell(p.type)} | ${
146
+ p.optional ? "no" : "yes"
147
+ } |${
148
+ described
149
+ ? ` ${(p.description ?? "").replace(/\s*\n\s*/g, " ")} |`
150
+ : ""
151
+ }`
152
+ ),
153
+ ]
154
+ : ["No props of its own; it takes the element's standard props."])
155
+ );
156
+ if (c.inherits?.length) {
157
+ lines.push(
158
+ "",
159
+ `Also takes every prop of ${c.inherits
160
+ .map((t) => cell(t))
161
+ .join(
162
+ ", "
163
+ )} (for an element, all its HTML attributes and event handlers such as \`onClick\`).`
164
+ );
165
+ }
166
+ if (c.renders.length) {
167
+ lines.push(
168
+ "",
169
+ `Renders: ${c.renders.map((r) => `\`${r}\``).join(", ")}.`
170
+ );
171
+ }
172
+ if (c.hooks.length) {
173
+ lines.push("", `Uses: ${c.hooks.map((h) => `\`${h}\``).join(", ")}.`);
174
+ }
175
+ if (c.styles?.length) {
176
+ lines.push(
177
+ "",
178
+ "## Fixed styles",
179
+ "",
180
+ ...c.styles.map((s) => `- \`${s.property}: ${s.value}\``)
181
+ );
182
+ }
183
+ if (c.tokens.length) {
184
+ lines.push(
185
+ "",
186
+ "## Tokens it reads",
187
+ "",
188
+ "Theme values; plugins use the component as is. Change tokens only for a new component or theme.",
189
+ "",
190
+ `| Token | ${themes.join(" | ")} |`,
191
+ `| --- | ${themes.map(() => "---").join(" | ")} |`,
192
+ ...c.tokens.map(
193
+ (t) =>
194
+ `| ${cell(t.name)} | ${themes
195
+ .map((id) =>
196
+ t.values[id] !== undefined ? cell(t.values[id]) : "undefined"
197
+ )
198
+ .join(" | ")} |`
199
+ )
200
+ );
201
+ const bySelector = c.tokens.filter((t) => t.bySelector);
202
+ if (bySelector.length) {
203
+ lines.push(
204
+ "",
205
+ "Overridden by selector:",
206
+ ...bySelector.flatMap((t) =>
207
+ Object.entries(t.bySelector).flatMap(([id, sels]) =>
208
+ Object.entries(sels).map(
209
+ ([sel, value]) =>
210
+ `- \`${t.name}\` (${id}, \`${sel}\`): \`${value}\``
211
+ )
212
+ )
213
+ )
214
+ );
215
+ }
216
+ }
217
+ return lines.join("\n");
218
+ })
219
+ .join("\n\n");
220
+ }
221
+
222
+ function score(wanted, primary, secondary) {
223
+ const first = new Set(terms(primary));
224
+ const second = new Set(terms(secondary));
225
+ let total = 0;
226
+ const matched = [];
227
+ for (const t of wanted) {
228
+ if (first.has(t)) {
229
+ total += 3;
230
+ matched.push(t);
231
+ } else if (second.has(t)) {
232
+ total += 1;
233
+ matched.push(t);
234
+ }
235
+ }
236
+ return { total, matched };
237
+ }
238
+
239
+ /**
240
+ * The extension points, standard contributions and components that best match a
241
+ * plain-language need.
242
+ */
243
+ export function findCapability(need, { limit = 5 } = {}) {
244
+ const wanted = [...new Set(terms(need))];
245
+ const { extensionPoints, components, contributionTools } = loadReference();
246
+ const standard = uniqueContributions(listOverridableContributions());
247
+ const rank = (items) =>
248
+ items
249
+ .filter((item) => item.total > 0)
250
+ .sort((a, b) => b.total - a.total)
251
+ .slice(0, limit)
252
+ .map(({ total: _total, ...item }) => item);
253
+ const slot = (keys) => Object.values(keys).join(" ");
254
+
255
+ const defined = new Set(extensionPoints.map((p) => p.contributionKey));
256
+ const points = [
257
+ ...extensionPoints.map((p) => ({
258
+ id: p.id,
259
+ contributionKey: p.contributionKey,
260
+ resource: `ddk://extension-point/${p.id}`,
261
+ ...(p.writer ? { tool: p.writer.tool } : {}),
262
+ ...score(
263
+ wanted,
264
+ `${p.id} ${p.displayName} ${p.contributionKey}`,
265
+ [
266
+ p.description,
267
+ p.category ?? "",
268
+ ...p.fields.map((f) => `${f.name} ${f.description ?? ""}`),
269
+ ...standard
270
+ .filter((c) => c.contributionKey === p.contributionKey)
271
+ .map((c) => `${c.id} ${slot(c.keys)}`),
272
+ ].join(" ")
273
+ ),
274
+ })),
275
+ ...Object.entries(contributionTools)
276
+ .filter(([key]) => !defined.has(key))
277
+ .map(([key, writer]) => ({
278
+ contributionKey: key,
279
+ tool: writer.tool,
280
+ ...score(
281
+ wanted,
282
+ `${key} ${writer.command}`,
283
+ standard
284
+ .filter((c) => c.contributionKey === key)
285
+ .map((c) => `${c.id} ${slot(c.keys)}`)
286
+ .join(" ")
287
+ ),
288
+ })),
289
+ ];
290
+
291
+ return {
292
+ extensionPoints: rank(points),
293
+ standardContributions: rank(
294
+ standard.map((c) => ({
295
+ id: c.id,
296
+ contributionKey: c.contributionKey,
297
+ keys: c.keys,
298
+ ...(typeof c.rank === "number" ? { rank: c.rank } : {}),
299
+ ...score(wanted, `${c.id} ${slot(c.keys)}`, c.point),
300
+ }))
301
+ ),
302
+ components: rank(
303
+ components.map((c) => ({
304
+ name: c.name,
305
+ package: c.package,
306
+ ...score(
307
+ wanted,
308
+ c.name,
309
+ `${c.file} ${c.props.map((p) => p.name).join(" ")}`
310
+ ),
311
+ }))
312
+ ),
313
+ 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.",
314
+ };
315
+ }
@@ -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
+ });