@kosdev-code/kos-ddk-cli 0.1.0-dev.72 → 0.1.0-dev.75
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 +6 -4
- package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +1 -1
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +6 -1
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +11 -1
- package/agent-plugin/kos-ddk-tools/plugin.json +1 -1
- package/agent-plugin/kos-ddk-tools/reference/reference.json +1692 -81
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +427 -417
- package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +17 -6
- package/agent-plugin/kos-ddk-tools/skills/ddk-config-page/SKILL.md +58 -17
- package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +8 -3
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +11 -8
- package/guides/config-property-cards.md +40 -8
- package/guides/getting-started.md +9 -9
- package/guides/storybook.md +18 -0
- package/package.json +2 -2
- package/reference/reference.json +1692 -81
- package/src/codegen/contribution.mjs +47 -1
- package/src/codegen/descriptor.mjs +4 -2
- package/src/codegen/json-preserve.mjs +137 -0
- package/src/codegen/project.mjs +29 -6
- package/src/generators/descriptor-project.mjs +8 -3
- package/src/generators/plugin-project.mjs +8 -3
- package/src/generators/theme-project.mjs +12 -4
- package/src/mcp/reference.mjs +54 -3
- package/src/mcp/tools.mjs +3 -3
- package/templates/utility/__nameDashCase__.stories.tsx__template__ +11 -8
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// plugin project. Shared by the ddk:* commands and the DDK MCP tools.
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import {
|
|
5
|
+
discoverProjects,
|
|
5
6
|
findProjectByName,
|
|
6
7
|
generateComponent,
|
|
7
8
|
normalizeAllValues,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
descriptorListsSlot,
|
|
14
15
|
findDescriptorProjects,
|
|
15
16
|
} from "./descriptor.mjs";
|
|
17
|
+
import { stringifyPreserving } from "./json-preserve.mjs";
|
|
16
18
|
import { alsoReplacedNotes, resolveOverride } from "./overrides.mjs";
|
|
17
19
|
|
|
18
20
|
/** Extension point → plugin type and what a contribution of it needs. */
|
|
@@ -104,8 +106,37 @@ function assertNameFree(codegenFs, project, name) {
|
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
/** Warnings for a component name equal to a model's registration bean. */
|
|
110
|
+
export function beanCollisionNotes(codegenFs, name) {
|
|
111
|
+
const pascal = normalizeAllValues({ name }).namePascalCase;
|
|
112
|
+
const notes = [];
|
|
113
|
+
for (const project of discoverProjects(codegenFs.root).values()) {
|
|
114
|
+
const raw = codegenFs.read(path.join(project.root, ".kos.json"));
|
|
115
|
+
if (!raw) continue;
|
|
116
|
+
let models;
|
|
117
|
+
try {
|
|
118
|
+
models = JSON.parse(raw).models;
|
|
119
|
+
} catch {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const [model, entry] of Object.entries(models ?? {})) {
|
|
123
|
+
const bean =
|
|
124
|
+
entry?.factory ?? normalizeAllValues({ name: model }).namePascalCase;
|
|
125
|
+
if (bean === pascal) {
|
|
126
|
+
notes.push(
|
|
127
|
+
`WARNING: component ${pascal} has the same name as model ${model}'s registration bean ${bean} (${project.name}). Choose another name, e.g. ${name}-config (${pascal}Config), before writing.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return notes;
|
|
133
|
+
}
|
|
134
|
+
|
|
107
135
|
function generate(codegenFs, pluginType, { name, project, ...extra }) {
|
|
108
136
|
registerDdkHandlers();
|
|
137
|
+
const root = findProjectByName(codegenFs.root, project)?.root;
|
|
138
|
+
const kosJsonPath = root && path.join(root, ".kos.json");
|
|
139
|
+
const before = kosJsonPath && codegenFs.read(kosJsonPath);
|
|
109
140
|
generateComponent(codegenFs, TEMPLATES_DIR, {
|
|
110
141
|
name,
|
|
111
142
|
appProject: project,
|
|
@@ -116,6 +147,11 @@ function generate(codegenFs, pluginType, { name, project, ...extra }) {
|
|
|
116
147
|
modelDirectory: "",
|
|
117
148
|
...extra,
|
|
118
149
|
});
|
|
150
|
+
// Keep the original layout of .kos.json entries the contribution did not touch.
|
|
151
|
+
const after = before && codegenFs.read(kosJsonPath);
|
|
152
|
+
if (after && after !== before) {
|
|
153
|
+
codegenFs.write(kosJsonPath, stringifyPreserving(before, JSON.parse(after)));
|
|
154
|
+
}
|
|
119
155
|
addTemplateKeys(codegenFs, pluginType, project);
|
|
120
156
|
}
|
|
121
157
|
|
|
@@ -216,7 +252,12 @@ export function generateDdkContribution(
|
|
|
216
252
|
: [];
|
|
217
253
|
return {
|
|
218
254
|
label: spec.label,
|
|
219
|
-
notes: [
|
|
255
|
+
notes: [
|
|
256
|
+
...beanCollisionNotes(codegenFs, name),
|
|
257
|
+
...resolved.notes,
|
|
258
|
+
...derived,
|
|
259
|
+
...listed,
|
|
260
|
+
],
|
|
220
261
|
};
|
|
221
262
|
}
|
|
222
263
|
|
|
@@ -280,6 +321,7 @@ export function generateDashboardCard(
|
|
|
280
321
|
return {
|
|
281
322
|
label: detail ? "DDK Dashboard Card" : "DDK Dashboard Summary",
|
|
282
323
|
notes: [
|
|
324
|
+
...beanCollisionNotes(codegenFs, name),
|
|
283
325
|
`The dashboard draws one card per active model at assembly.${key} (or the FreestyleAssembly companion's ${key}); no such model, no card.`,
|
|
284
326
|
...(detail
|
|
285
327
|
? ["The detail opens when a technician selects the card."]
|
|
@@ -319,6 +361,7 @@ export function generatePumpDetail(
|
|
|
319
361
|
return {
|
|
320
362
|
label: "DDK Pump Detail",
|
|
321
363
|
notes: [
|
|
364
|
+
...beanCollisionNotes(codegenFs, name),
|
|
322
365
|
`Shown in the holder modal when the dashboard key factory returns "${key}" for the holder (default: its first pump's type), unless the holder has its own content.`,
|
|
323
366
|
...resolved.notes,
|
|
324
367
|
],
|
|
@@ -356,6 +399,7 @@ export function generatePumpCard(
|
|
|
356
399
|
return {
|
|
357
400
|
label: detail ? "DDK Pump Card" : "DDK Pump Summary",
|
|
358
401
|
notes: [
|
|
402
|
+
...beanCollisionNotes(codegenFs, name),
|
|
359
403
|
`Used for holders whose dashboard key factory returns "${key}" (default: the holder's first pump type, which the backend assembly assigns); other holders keep the default card body.`,
|
|
360
404
|
...(detail
|
|
361
405
|
? [
|
|
@@ -397,6 +441,7 @@ export function generateMacroSummary(
|
|
|
397
441
|
return {
|
|
398
442
|
label: "DDK Macro Summary",
|
|
399
443
|
notes: [
|
|
444
|
+
...beanCollisionNotes(codegenFs, name),
|
|
400
445
|
`Matched to a macro holder by holder.name "${key}" first, then by the dashboard key factory.`,
|
|
401
446
|
...resolved.notes,
|
|
402
447
|
],
|
|
@@ -430,6 +475,7 @@ export function generateTroubleAction(
|
|
|
430
475
|
return {
|
|
431
476
|
label: "DDK Trouble Action",
|
|
432
477
|
notes: [
|
|
478
|
+
...beanCollisionNotes(codegenFs, name),
|
|
433
479
|
`troubleType "${type}" must be the exact type the device raises; the experience shows while one is active and goes away once it is resolved.`,
|
|
434
480
|
...resolved.notes,
|
|
435
481
|
],
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
NCUI_OPTIONS,
|
|
13
13
|
buildNcuiDescriptor,
|
|
14
14
|
} from "./ncui-descriptor.mjs";
|
|
15
|
+
import { stringifyPreserving } from "./json-preserve.mjs";
|
|
15
16
|
|
|
16
17
|
export const DESCRIPTOR_KAB_TYPE = "ddk.ncui.descriptor";
|
|
17
18
|
|
|
@@ -89,7 +90,8 @@ export function addDescriptorEntry(
|
|
|
89
90
|
{ project, slot, roles, column }
|
|
90
91
|
) {
|
|
91
92
|
const { name, kosJsonPath } = descriptorProject(codegenFs, project);
|
|
92
|
-
const
|
|
93
|
+
const original = codegenFs.read(kosJsonPath);
|
|
94
|
+
const kosJson = JSON.parse(original);
|
|
93
95
|
const ncui = ((kosJson.kondra ??= {}).ncui ??= {});
|
|
94
96
|
const roleList = parseRoles(roles);
|
|
95
97
|
const withRoles = roleList.length ? { roles: roleList } : {};
|
|
@@ -142,7 +144,7 @@ export function addDescriptorEntry(
|
|
|
142
144
|
note = `Listed navigation "${slot}" in ${name}.`;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
|
-
codegenFs.write(kosJsonPath,
|
|
147
|
+
codegenFs.write(kosJsonPath, stringifyPreserving(original, kosJson));
|
|
146
148
|
const setup = descriptorMockSetup(kosJson);
|
|
147
149
|
codegenFs.write(setup.path, setup.content);
|
|
148
150
|
return note;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// JSON serialization that keeps the original text of unchanged nodes. New nodes
|
|
2
|
+
// follow Prettier's JSON layout: objects expanded, short primitive arrays inline.
|
|
3
|
+
|
|
4
|
+
const PRINT_WIDTH = 80;
|
|
5
|
+
const INDENT = " ";
|
|
6
|
+
|
|
7
|
+
/** Parses strict JSON into `{ value, start, end, kind, children }` nodes. */
|
|
8
|
+
function parse(text) {
|
|
9
|
+
let i = 0;
|
|
10
|
+
const ws = () => {
|
|
11
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
12
|
+
};
|
|
13
|
+
const fail = () => {
|
|
14
|
+
throw new Error(`Invalid JSON at offset ${i}`);
|
|
15
|
+
};
|
|
16
|
+
const node = () => {
|
|
17
|
+
ws();
|
|
18
|
+
const start = i;
|
|
19
|
+
const ch = text[i];
|
|
20
|
+
if (ch === "{") {
|
|
21
|
+
i++;
|
|
22
|
+
const children = new Map();
|
|
23
|
+
const value = {};
|
|
24
|
+
ws();
|
|
25
|
+
if (text[i] === "}") {
|
|
26
|
+
i++;
|
|
27
|
+
return { kind: "object", value, children, start, end: i };
|
|
28
|
+
}
|
|
29
|
+
for (;;) {
|
|
30
|
+
ws();
|
|
31
|
+
const key = node();
|
|
32
|
+
if (typeof key.value !== "string") fail();
|
|
33
|
+
ws();
|
|
34
|
+
if (text[i++] !== ":") fail();
|
|
35
|
+
const child = node();
|
|
36
|
+
children.set(key.value, child);
|
|
37
|
+
value[key.value] = child.value;
|
|
38
|
+
ws();
|
|
39
|
+
if (text[i] === ",") {
|
|
40
|
+
i++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (text[i++] !== "}") fail();
|
|
44
|
+
return { kind: "object", value, children, start, end: i };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (ch === "[") {
|
|
48
|
+
i++;
|
|
49
|
+
const children = [];
|
|
50
|
+
ws();
|
|
51
|
+
if (text[i] === "]") {
|
|
52
|
+
i++;
|
|
53
|
+
return { kind: "array", value: [], children, start, end: i };
|
|
54
|
+
}
|
|
55
|
+
for (;;) {
|
|
56
|
+
children.push(node());
|
|
57
|
+
ws();
|
|
58
|
+
if (text[i] === ",") {
|
|
59
|
+
i++;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (text[i++] !== "]") fail();
|
|
63
|
+
return {
|
|
64
|
+
kind: "array",
|
|
65
|
+
value: children.map((c) => c.value),
|
|
66
|
+
children,
|
|
67
|
+
start,
|
|
68
|
+
end: i,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (ch === '"') {
|
|
73
|
+
i++;
|
|
74
|
+
while (text[i] !== '"') {
|
|
75
|
+
if (i >= text.length) fail();
|
|
76
|
+
i += text[i] === "\\" ? 2 : 1;
|
|
77
|
+
}
|
|
78
|
+
i++;
|
|
79
|
+
return { kind: "primitive", value: JSON.parse(text.slice(start, i)), start, end: i };
|
|
80
|
+
}
|
|
81
|
+
const m = /^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(
|
|
82
|
+
text.slice(i)
|
|
83
|
+
);
|
|
84
|
+
if (!m) fail();
|
|
85
|
+
i += m[0].length;
|
|
86
|
+
return { kind: "primitive", value: JSON.parse(m[0]), start, end: i };
|
|
87
|
+
};
|
|
88
|
+
const root = node();
|
|
89
|
+
ws();
|
|
90
|
+
if (i !== text.length) fail();
|
|
91
|
+
return root;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const equal = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
95
|
+
const isPlainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
96
|
+
|
|
97
|
+
function emit(text, original, value, depth, column) {
|
|
98
|
+
if (original && equal(original.value, value)) {
|
|
99
|
+
return text.slice(original.start, original.end);
|
|
100
|
+
}
|
|
101
|
+
const pad = INDENT.repeat(depth + 1);
|
|
102
|
+
const close = INDENT.repeat(depth);
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
if (!value.length) return "[]";
|
|
105
|
+
const children = original?.kind === "array" ? original.children : [];
|
|
106
|
+
if (value.every((v) => v === null || typeof v !== "object")) {
|
|
107
|
+
const inline = `[${value.map((v) => JSON.stringify(v)).join(", ")}]`;
|
|
108
|
+
if (column + inline.length <= PRINT_WIDTH) return inline;
|
|
109
|
+
}
|
|
110
|
+
const items = value.map(
|
|
111
|
+
(v, n) => pad + emit(text, children[n], v, depth + 1, pad.length)
|
|
112
|
+
);
|
|
113
|
+
return `[\n${items.join(",\n")}\n${close}]`;
|
|
114
|
+
}
|
|
115
|
+
if (isPlainObject(value)) {
|
|
116
|
+
const keys = Object.keys(value);
|
|
117
|
+
if (!keys.length) return "{}";
|
|
118
|
+
const children = original?.kind === "object" ? original.children : new Map();
|
|
119
|
+
const entries = keys.map((key) => {
|
|
120
|
+
const head = `${pad}${JSON.stringify(key)}: `;
|
|
121
|
+
return head + emit(text, children.get(key), value[key], depth + 1, head.length);
|
|
122
|
+
});
|
|
123
|
+
return `{\n${entries.join(",\n")}\n${close}}`;
|
|
124
|
+
}
|
|
125
|
+
return JSON.stringify(value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** `value` as JSON, reusing `originalText` verbatim for every unchanged node. */
|
|
129
|
+
export function stringifyPreserving(originalText, value) {
|
|
130
|
+
let root;
|
|
131
|
+
try {
|
|
132
|
+
root = originalText ? parse(originalText) : undefined;
|
|
133
|
+
} catch {
|
|
134
|
+
root = undefined;
|
|
135
|
+
}
|
|
136
|
+
return `${emit(originalText ?? "", root, value, 0, 0)}\n`;
|
|
137
|
+
}
|
package/src/codegen/project.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import { stringifyPreserving } from "./json-preserve.mjs";
|
|
6
7
|
import { findProjectByName } from "@kosdev-code/kos-codegen-core";
|
|
7
8
|
import { TEMPLATES_DIR } from "../handlers.mjs";
|
|
8
9
|
import { DESCRIPTOR_KAB_TYPE, descriptorMockSetup } from "./descriptor.mjs";
|
|
@@ -151,7 +152,8 @@ export function pluginHost(workspaceRoot, host) {
|
|
|
151
152
|
export function unregisterPlugin(workspaceRoot, name) {
|
|
152
153
|
const file = rootKosJsonPath(workspaceRoot);
|
|
153
154
|
if (!fs.existsSync(file)) return;
|
|
154
|
-
const
|
|
155
|
+
const original = fs.readFileSync(file, "utf-8");
|
|
156
|
+
const rootConfig = JSON.parse(original);
|
|
155
157
|
let changed = false;
|
|
156
158
|
for (const h of rootConfig.development?.hosts ?? []) {
|
|
157
159
|
const plugins = (h.plugins ?? []).filter((p) => p.project !== name);
|
|
@@ -160,7 +162,20 @@ export function unregisterPlugin(workspaceRoot, name) {
|
|
|
160
162
|
changed = true;
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
|
-
if (changed)
|
|
165
|
+
if (changed)
|
|
166
|
+
fs.writeFileSync(file, stringifyPreserving(original, rootConfig));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** What a CLI dry run of createDdkProject prints. */
|
|
170
|
+
export function dryRunReport({ output, ddkFiles }) {
|
|
171
|
+
return [
|
|
172
|
+
"DRY RUN — nothing was written.",
|
|
173
|
+
output,
|
|
174
|
+
"DDK layer written over it:",
|
|
175
|
+
...ddkFiles.map((file) => ` ${file}`),
|
|
176
|
+
]
|
|
177
|
+
.filter(Boolean)
|
|
178
|
+
.join("\n");
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
/**
|
|
@@ -212,15 +227,23 @@ export function createDdkProject(
|
|
|
212
227
|
shell: process.platform === "win32",
|
|
213
228
|
}
|
|
214
229
|
);
|
|
215
|
-
|
|
230
|
+
const output = result.stdout?.trim() ?? "";
|
|
231
|
+
// Nx refuses --dry-run when a generator would first install an Nx plugin
|
|
232
|
+
// (e.g. @nx/storybook); the write installs it, so report the plan instead.
|
|
233
|
+
const installsOnWrite =
|
|
234
|
+
dryRun && /does not support --dry-run/.test(output + (result.stderr ?? ""));
|
|
235
|
+
if (result.status !== 0 && !installsOnWrite) {
|
|
216
236
|
throw new Error(
|
|
217
|
-
`nx generate exited with ${result.status}\n${result.stderr
|
|
237
|
+
`nx generate exited with ${result.status}\n${[result.stderr, output]
|
|
238
|
+
.filter(Boolean)
|
|
239
|
+
.join("\n")}`
|
|
218
240
|
);
|
|
219
241
|
}
|
|
220
|
-
const output = result.stdout?.trim() ?? "";
|
|
221
242
|
if (dryRun) {
|
|
222
243
|
return {
|
|
223
|
-
output
|
|
244
|
+
output: installsOnWrite
|
|
245
|
+
? `${spec.generator} creates project ${name}; it installs a missing Nx plugin on write, so Nx cannot list its files in a dry run.`
|
|
246
|
+
: output,
|
|
224
247
|
ddkFiles:
|
|
225
248
|
kind === "descriptor"
|
|
226
249
|
? [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ddk:descriptor-project: an NCUI descriptor project. kos-nx-plugin's generic content
|
|
2
2
|
// project as a ddk.ncui.descriptor KAB, with the NCUI descriptor for a layout and the
|
|
3
3
|
// dispenser's options.
|
|
4
|
-
import { createDdkProject } from "../codegen/project.mjs";
|
|
4
|
+
import { createDdkProject, dryRunReport } from "../codegen/project.mjs";
|
|
5
5
|
import { NCUI_LAYOUTS, NCUI_OPTIONS } from "../codegen/ncui-descriptor.mjs";
|
|
6
6
|
|
|
7
7
|
const installNote = (toInstall) =>
|
|
@@ -21,6 +21,7 @@ export const metadata = {
|
|
|
21
21
|
name: "name",
|
|
22
22
|
layout: "layout",
|
|
23
23
|
...Object.fromEntries(Object.keys(NCUI_OPTIONS).map((o) => [o, o])),
|
|
24
|
+
dryRun: "dryRun",
|
|
24
25
|
interactive: "interactive",
|
|
25
26
|
},
|
|
26
27
|
};
|
|
@@ -33,12 +34,16 @@ export async function register(plop, { host }) {
|
|
|
33
34
|
Object.keys(NCUI_OPTIONS).map((o) => [o, flag(answers[o])])
|
|
34
35
|
),
|
|
35
36
|
};
|
|
36
|
-
const
|
|
37
|
+
const dryRun = !!answers.dryRun;
|
|
38
|
+
const result = createDdkProject("descriptor", {
|
|
37
39
|
workspaceRoot: process.cwd(),
|
|
38
40
|
name: answers.name,
|
|
39
41
|
ncui,
|
|
40
|
-
|
|
42
|
+
dryRun,
|
|
43
|
+
stdio: dryRun ? "pipe" : "inherit",
|
|
41
44
|
});
|
|
45
|
+
if (dryRun) return dryRunReport(result);
|
|
46
|
+
const { root, toInstall } = result;
|
|
42
47
|
const on = Object.keys(NCUI_OPTIONS).filter((o) => ncui[o]);
|
|
43
48
|
return [
|
|
44
49
|
`DDK NCUI descriptor project ${answers.name} created at ${root}: ${
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// ddk:plugin-project: a DDK plugin project. kos-nx-plugin's generic plugin project with
|
|
2
2
|
// the DDK KAB type, Storybook preview, registration, contribution keys and packages.
|
|
3
|
-
import { createDdkProject } from "../codegen/project.mjs";
|
|
3
|
+
import { createDdkProject, dryRunReport } from "../codegen/project.mjs";
|
|
4
4
|
|
|
5
5
|
const installNote = (toInstall) =>
|
|
6
6
|
toInstall?.length
|
|
@@ -17,19 +17,24 @@ export const metadata = {
|
|
|
17
17
|
name: "name",
|
|
18
18
|
directory: "directory",
|
|
19
19
|
host: "host",
|
|
20
|
+
dryRun: "dryRun",
|
|
20
21
|
interactive: "interactive",
|
|
21
22
|
},
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export async function register(plop, { host }) {
|
|
25
26
|
plop.setActionType("ddk:createPluginProject", (answers) => {
|
|
26
|
-
const
|
|
27
|
+
const dryRun = !!answers.dryRun;
|
|
28
|
+
const result = createDdkProject("plugin", {
|
|
27
29
|
workspaceRoot: process.cwd(),
|
|
28
30
|
name: answers.name,
|
|
29
31
|
directory: answers.directory || undefined,
|
|
30
32
|
host: answers.host || undefined,
|
|
31
|
-
|
|
33
|
+
dryRun,
|
|
34
|
+
stdio: dryRun ? "pipe" : "inherit",
|
|
32
35
|
});
|
|
36
|
+
if (dryRun) return dryRunReport(result);
|
|
37
|
+
const { toInstall } = result;
|
|
33
38
|
return [
|
|
34
39
|
`DDK plugin project ${answers.name} created.`,
|
|
35
40
|
installNote(toInstall),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// ddk:theme-project: a DDK theme project. kos-nx-plugin's generic theme project with the
|
|
2
2
|
// DDK KAB type and the theme-overlay.css the DDK apps load over their base tokens.
|
|
3
|
-
import { createDdkProject } from "../codegen/project.mjs";
|
|
3
|
+
import { createDdkProject, dryRunReport } from "../codegen/project.mjs";
|
|
4
4
|
|
|
5
5
|
const installNote = (toInstall) =>
|
|
6
6
|
toInstall?.length
|
|
@@ -12,16 +12,24 @@ export const metadata = {
|
|
|
12
12
|
name: "DDK Theme Project",
|
|
13
13
|
description: "Create a new DDK theme project",
|
|
14
14
|
invalidateCache: true,
|
|
15
|
-
namedArguments: {
|
|
15
|
+
namedArguments: {
|
|
16
|
+
name: "name",
|
|
17
|
+
dryRun: "dryRun",
|
|
18
|
+
interactive: "interactive",
|
|
19
|
+
},
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
export async function register(plop, { host }) {
|
|
19
23
|
plop.setActionType("ddk:createThemeProject", (answers) => {
|
|
20
|
-
const
|
|
24
|
+
const dryRun = !!answers.dryRun;
|
|
25
|
+
const result = createDdkProject("theme", {
|
|
21
26
|
workspaceRoot: process.cwd(),
|
|
22
27
|
name: answers.name,
|
|
23
|
-
|
|
28
|
+
dryRun,
|
|
29
|
+
stdio: dryRun ? "pipe" : "inherit",
|
|
24
30
|
});
|
|
31
|
+
if (dryRun) return dryRunReport(result);
|
|
32
|
+
const { toInstall } = result;
|
|
25
33
|
return [
|
|
26
34
|
`DDK theme project ${answers.name} created.`,
|
|
27
35
|
installNote(toInstall),
|
package/src/mcp/reference.mjs
CHANGED
|
@@ -65,13 +65,64 @@ export function listComponents({ library, query } = {}) {
|
|
|
65
65
|
|
|
66
66
|
const cell = (v) => `\`${String(v).replace(/\|/g, "\\|")}\``;
|
|
67
67
|
|
|
68
|
-
/**
|
|
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. */
|
|
69
113
|
export function describeComponent(name, library) {
|
|
70
|
-
const { components, themes } = loadReference();
|
|
114
|
+
const { components, themes, hooks = [] } = loadReference();
|
|
71
115
|
const matches = components.filter(
|
|
72
116
|
(c) => c.name === name && (!library || c.package === library)
|
|
73
117
|
);
|
|
74
|
-
if (!matches.length)
|
|
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
|
+
}
|
|
75
126
|
return matches
|
|
76
127
|
.map((c) => {
|
|
77
128
|
const lines = [
|
package/src/mcp/tools.mjs
CHANGED
|
@@ -525,13 +525,13 @@ export const ddkTools = [
|
|
|
525
525
|
{
|
|
526
526
|
name: "describe_ddk_component",
|
|
527
527
|
description:
|
|
528
|
-
"One DDK component from its source: props, the components and hooks it uses,
|
|
528
|
+
"One DDK component or hook from its source. Component: props (inherited ones included), the components and hooks it uses, each token it reads per theme. Hook: signature, option fields, returned fields.",
|
|
529
529
|
inputSchema: {
|
|
530
530
|
type: "object",
|
|
531
531
|
properties: {
|
|
532
532
|
name: {
|
|
533
533
|
type: "string",
|
|
534
|
-
description: "Export name, e.g. HolderDashboardCard.",
|
|
534
|
+
description: "Export name, e.g. HolderDashboardCard or useUtilityModal.",
|
|
535
535
|
},
|
|
536
536
|
library: {
|
|
537
537
|
type: "string",
|
|
@@ -547,7 +547,7 @@ export const ddkTools = [
|
|
|
547
547
|
return text
|
|
548
548
|
? { content: [{ type: "text", text }] }
|
|
549
549
|
: errorResult(
|
|
550
|
-
`No DDK component named ${args.name}; list_ddk_components lists
|
|
550
|
+
`No DDK component or hook named ${args.name}; list_ddk_components lists the components.`
|
|
551
551
|
);
|
|
552
552
|
} catch (e) {
|
|
553
553
|
return errorResult(e.message);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { Button } from "@kosdev-code/kos-ddk-components";
|
|
7
7
|
import { UtilityStoryContainer } from "@kosdev-code/kos-ddk-story-containers";
|
|
8
8
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
9
|
-
import type
|
|
9
|
+
import { Suspense, type ComponentProps } from "react";
|
|
10
10
|
import { useArgs } from "storybook/preview-api";
|
|
11
11
|
import { fn } from "storybook/test";
|
|
12
12
|
import { <%= namePascalCase %> } from "./<%= nameDashCase %>";
|
|
@@ -42,14 +42,17 @@ export const Default: Story = {
|
|
|
42
42
|
<Button onPointerDown={() => updateArgs({ open: true })}>
|
|
43
43
|
Open <%= namePascalCase %>
|
|
44
44
|
</Button>
|
|
45
|
+
{/* A utility that loads a model suspends; keep that out of this render. */}
|
|
45
46
|
{open && (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onComplete()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
<Suspense>
|
|
48
|
+
<<%= namePascalCase %>
|
|
49
|
+
{...props}
|
|
50
|
+
onComplete={() => {
|
|
51
|
+
onComplete();
|
|
52
|
+
updateArgs({ open: false });
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
</Suspense>
|
|
53
56
|
)}
|
|
54
57
|
</>
|
|
55
58
|
);
|