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

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 (116) hide show
  1. package/README.md +129 -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 +40 -0
  6. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +33 -0
  7. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +888 -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 +19288 -0
  11. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48632 -0
  12. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +71 -0
  13. package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +49 -0
  14. package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +39 -0
  15. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +30 -0
  16. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  17. package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
  18. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +32 -0
  19. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  20. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  21. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +32 -0
  22. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  23. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  24. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  25. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  26. package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
  27. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +30 -0
  28. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  29. package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
  30. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +80 -0
  31. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
  32. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +32 -0
  33. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  34. package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
  35. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  36. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  37. package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
  38. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.stories.tsx__template__ +30 -0
  39. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.tsx__template__ +27 -0
  40. package/agent-plugin/kos-ddk-tools/templates/setting/index.ts__template__ +1 -0
  41. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -0
  42. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  43. package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
  44. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
  45. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
  46. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
  47. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  48. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +29 -0
  49. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  50. package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
  51. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -0
  52. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +47 -0
  53. package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
  54. package/catalog/contributions.json +888 -0
  55. package/guides/ddk-dev.md +46 -0
  56. package/guides/storybook.md +69 -0
  57. package/package.json +33 -3
  58. package/reference/reference.json +19288 -0
  59. package/src/build-paths.mjs +20 -0
  60. package/src/codegen/contribution.mjs +255 -0
  61. package/src/codegen/overrides.mjs +179 -0
  62. package/src/codegen/project.mjs +144 -0
  63. package/src/extension.mjs +22 -0
  64. package/src/generators/agent-install.mjs +79 -0
  65. package/src/generators/catalog.mjs +70 -0
  66. package/src/generators/contributions.mjs +116 -0
  67. package/src/generators/dashboard.mjs +238 -0
  68. package/src/generators/dev.mjs +221 -0
  69. package/src/generators/override-prompts.mjs +27 -0
  70. package/src/generators/plugin-project.mjs +34 -0
  71. package/src/generators/theme-project.mjs +34 -0
  72. package/src/handlers.mjs +325 -0
  73. package/src/mcp/pkg-info.mjs +7 -0
  74. package/src/mcp/plugin-inspect.mjs +257 -0
  75. package/src/mcp/reference.mjs +248 -0
  76. package/src/mcp/server.mjs +12 -0
  77. package/src/mcp/tools.mjs +478 -0
  78. package/templates/cui/__nameDashCase__.stories.tsx__template__ +30 -0
  79. package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  80. package/templates/cui/index.ts__template__ +1 -0
  81. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +32 -0
  82. package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  83. package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  84. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +32 -0
  85. package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  86. package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  87. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  88. package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  89. package/templates/macro-summary/index.ts__template__ +1 -0
  90. package/templates/nav/__nameDashCase__.stories.tsx__template__ +30 -0
  91. package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  92. package/templates/nav/index.ts__template__ +1 -0
  93. package/templates/plugin-project/.storybook/preview.tsx.template +80 -0
  94. package/templates/plugin-project/.storybook/registration.ts.template +6 -0
  95. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +32 -0
  96. package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  97. package/templates/pump-detail/index.ts__template__ +1 -0
  98. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  99. package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  100. package/templates/pump-summary/index.ts__template__ +1 -0
  101. package/templates/setting/__nameDashCase__.stories.tsx__template__ +30 -0
  102. package/templates/setting/__nameDashCase__.tsx__template__ +27 -0
  103. package/templates/setting/index.ts__template__ +1 -0
  104. package/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -0
  105. package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  106. package/templates/setup/index.ts__template__ +1 -0
  107. package/templates/theme-project/theme/assets/component.css.template +2 -0
  108. package/templates/theme-project/theme/assets/generic.css.template +2 -0
  109. package/templates/theme-project/theme/assets/semantic.css.template +2 -0
  110. package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  111. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +29 -0
  112. package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  113. package/templates/trouble-action/index.ts__template__ +1 -0
  114. package/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -0
  115. package/templates/utility/__nameDashCase__.tsx__template__ +47 -0
  116. package/templates/utility/index.ts__template__ +1 -0
@@ -0,0 +1,248 @@
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
+ "",
82
+ "## Props",
83
+ "",
84
+ ];
85
+ lines.push(
86
+ ...(c.props.length
87
+ ? [
88
+ "| Prop | Type | Required |",
89
+ "| --- | --- | --- |",
90
+ ...c.props.map(
91
+ (p) =>
92
+ `| ${cell(p.name)} | ${cell(p.type)} | ${
93
+ p.optional ? "no" : "yes"
94
+ } |`
95
+ ),
96
+ ]
97
+ : ["No props of its own; it takes the element's standard props."])
98
+ );
99
+ if (c.renders.length) {
100
+ lines.push(
101
+ "",
102
+ `Renders: ${c.renders.map((r) => `\`${r}\``).join(", ")}.`
103
+ );
104
+ }
105
+ if (c.hooks.length) {
106
+ lines.push("", `Uses: ${c.hooks.map((h) => `\`${h}\``).join(", ")}.`);
107
+ }
108
+ if (c.styles?.length) {
109
+ lines.push(
110
+ "",
111
+ "## Fixed styles",
112
+ "",
113
+ ...c.styles.map((s) => `- \`${s.property}: ${s.value}\``)
114
+ );
115
+ }
116
+ if (c.tokens.length) {
117
+ lines.push(
118
+ "",
119
+ "## Tokens it reads",
120
+ "",
121
+ "Theme values; plugins use the component as is. Change tokens only for a new component or theme.",
122
+ "",
123
+ `| Token | ${themes.join(" | ")} |`,
124
+ `| --- | ${themes.map(() => "---").join(" | ")} |`,
125
+ ...c.tokens.map(
126
+ (t) =>
127
+ `| ${cell(t.name)} | ${themes
128
+ .map((id) =>
129
+ t.values[id] !== undefined ? cell(t.values[id]) : "undefined"
130
+ )
131
+ .join(" | ")} |`
132
+ )
133
+ );
134
+ const bySelector = c.tokens.filter((t) => t.bySelector);
135
+ if (bySelector.length) {
136
+ lines.push(
137
+ "",
138
+ "Overridden by selector:",
139
+ ...bySelector.flatMap((t) =>
140
+ Object.entries(t.bySelector).flatMap(([id, sels]) =>
141
+ Object.entries(sels).map(
142
+ ([sel, value]) =>
143
+ `- \`${t.name}\` (${id}, \`${sel}\`): \`${value}\``
144
+ )
145
+ )
146
+ )
147
+ );
148
+ }
149
+ }
150
+ return lines.join("\n");
151
+ })
152
+ .join("\n\n");
153
+ }
154
+
155
+ function score(wanted, primary, secondary) {
156
+ const first = new Set(terms(primary));
157
+ const second = new Set(terms(secondary));
158
+ let total = 0;
159
+ const matched = [];
160
+ for (const t of wanted) {
161
+ if (first.has(t)) {
162
+ total += 3;
163
+ matched.push(t);
164
+ } else if (second.has(t)) {
165
+ total += 1;
166
+ matched.push(t);
167
+ }
168
+ }
169
+ return { total, matched };
170
+ }
171
+
172
+ /**
173
+ * The extension points, standard contributions and components that best match a
174
+ * plain-language need.
175
+ */
176
+ export function findCapability(need, { limit = 5 } = {}) {
177
+ const wanted = [...new Set(terms(need))];
178
+ const { extensionPoints, components, contributionTools } = loadReference();
179
+ const standard = uniqueContributions(listOverridableContributions());
180
+ const rank = (items) =>
181
+ items
182
+ .filter((item) => item.total > 0)
183
+ .sort((a, b) => b.total - a.total)
184
+ .slice(0, limit)
185
+ .map(({ total: _total, ...item }) => item);
186
+ const slot = (keys) => Object.values(keys).join(" ");
187
+
188
+ const defined = new Set(extensionPoints.map((p) => p.contributionKey));
189
+ const points = [
190
+ ...extensionPoints.map((p) => ({
191
+ id: p.id,
192
+ contributionKey: p.contributionKey,
193
+ resource: `ddk://extension-point/${p.id}`,
194
+ ...(p.writer ? { tool: p.writer.tool } : {}),
195
+ ...score(
196
+ wanted,
197
+ `${p.id} ${p.displayName} ${p.contributionKey}`,
198
+ [
199
+ p.description,
200
+ p.category ?? "",
201
+ ...p.fields.map((f) => `${f.name} ${f.description ?? ""}`),
202
+ ...standard
203
+ .filter((c) => c.contributionKey === p.contributionKey)
204
+ .map((c) => `${c.id} ${slot(c.keys)}`),
205
+ ].join(" ")
206
+ ),
207
+ })),
208
+ ...Object.entries(contributionTools)
209
+ .filter(([key]) => !defined.has(key))
210
+ .map(([key, writer]) => ({
211
+ contributionKey: key,
212
+ tool: writer.tool,
213
+ ...score(
214
+ wanted,
215
+ `${key} ${writer.command}`,
216
+ standard
217
+ .filter((c) => c.contributionKey === key)
218
+ .map((c) => `${c.id} ${slot(c.keys)}`)
219
+ .join(" ")
220
+ ),
221
+ })),
222
+ ];
223
+
224
+ return {
225
+ extensionPoints: rank(points),
226
+ standardContributions: rank(
227
+ standard.map((c) => ({
228
+ id: c.id,
229
+ contributionKey: c.contributionKey,
230
+ keys: c.keys,
231
+ ...(typeof c.rank === "number" ? { rank: c.rank } : {}),
232
+ ...score(wanted, `${c.id} ${slot(c.keys)}`, c.point),
233
+ }))
234
+ ),
235
+ components: rank(
236
+ components.map((c) => ({
237
+ name: c.name,
238
+ package: c.package,
239
+ ...score(
240
+ wanted,
241
+ c.name,
242
+ `${c.file} ${c.props.map((p) => p.name).join(" ")}`
243
+ ),
244
+ }))
245
+ ),
246
+ 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.",
247
+ };
248
+ }
@@ -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
+ });