@mapomodule/mcp 0.0.0-stage → 1.0.0-beta.1
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 +479 -2
- package/bin/mapo-mcp.mjs +3 -0
- package/dist/build.d.mts +18 -0
- package/dist/build.d.ts +18 -0
- package/dist/build.mjs +351 -0
- package/dist/cli.d.mts +7 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.mjs +263 -0
- package/dist/index.d.mts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.mjs +1 -0
- package/dist/knowledge/api.json +1 -0
- package/dist/knowledge/docs.json +1 -0
- package/dist/module.d.mts +16 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +121 -0
- package/dist/runtime/core/doctor.d.ts +0 -0
- package/dist/runtime/core/doctor.js +128 -0
- package/dist/runtime/core/indexer.d.ts +0 -0
- package/dist/runtime/core/indexer.js +193 -0
- package/dist/runtime/core/knowledge.d.ts +0 -0
- package/dist/runtime/core/knowledge.js +76 -0
- package/dist/runtime/core/openapi.d.ts +0 -0
- package/dist/runtime/core/openapi.js +229 -0
- package/dist/runtime/core/prompts.d.ts +0 -0
- package/dist/runtime/core/prompts.js +108 -0
- package/dist/runtime/core/recipes.d.ts +0 -0
- package/dist/runtime/core/recipes.js +297 -0
- package/dist/runtime/core/resources.d.ts +0 -0
- package/dist/runtime/core/resources.js +88 -0
- package/dist/runtime/core/scaffold/fields.d.ts +0 -0
- package/dist/runtime/core/scaffold/fields.js +64 -0
- package/dist/runtime/core/scaffold/index.d.ts +0 -0
- package/dist/runtime/core/scaffold/index.js +74 -0
- package/dist/runtime/core/scaffold/templates.d.ts +0 -0
- package/dist/runtime/core/scaffold/templates.js +349 -0
- package/dist/runtime/core/schema-source.d.ts +0 -0
- package/dist/runtime/core/schema-source.js +70 -0
- package/dist/runtime/core/search.d.ts +0 -0
- package/dist/runtime/core/search.js +173 -0
- package/dist/runtime/core/tokenize.d.ts +0 -0
- package/dist/runtime/core/tokenize.js +96 -0
- package/dist/runtime/core/tool-spec.d.ts +0 -0
- package/dist/runtime/core/tool-spec.js +3 -0
- package/dist/runtime/core/tools/api.d.ts +0 -0
- package/dist/runtime/core/tools/api.js +192 -0
- package/dist/runtime/core/tools/app.d.ts +0 -0
- package/dist/runtime/core/tools/app.js +141 -0
- package/dist/runtime/core/tools/backend.d.ts +0 -0
- package/dist/runtime/core/tools/backend.js +143 -0
- package/dist/runtime/core/tools/docs.d.ts +0 -0
- package/dist/runtime/core/tools/docs.js +150 -0
- package/dist/runtime/core/tools/scaffold.d.ts +0 -0
- package/dist/runtime/core/tools/scaffold.js +127 -0
- package/dist/runtime/core/types.d.ts +0 -0
- package/dist/runtime/core/types.js +0 -0
- package/dist/runtime/core/write.d.ts +0 -0
- package/dist/runtime/core/write.js +53 -0
- package/dist/runtime/mcp/handlers/mapo/index.js +13 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/crud-page.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/custom-field.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/debug-form.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/migrate-v1.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/theme.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/resources/app-manifest.js +19 -0
- package/dist/runtime/mcp/handlers/mapo/resources/docs.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/fields.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/knowledge-index.js +22 -0
- package/dist/runtime/mcp/handlers/mapo/tools/backend-schema.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/component-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/composable-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/doctor.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/get-doc.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/inspect-app.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-field-types.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-recipes.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/scaffold.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/search-docs.js +3 -0
- package/dist/runtime/nitro/context.d.ts +0 -0
- package/dist/runtime/nitro/context.js +21 -0
- package/dist/runtime/nitro/to-mcp-prompt.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-prompt.js +23 -0
- package/dist/runtime/nitro/to-mcp-tool.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-tool.js +28 -0
- package/dist/runtime/types/virtual-modules.d.ts +6 -0
- package/dist/types.d.mts +9 -0
- package/package.json +73 -4
- package/src/__tests__/cli.test.ts +121 -0
- package/src/__tests__/doctor.test.ts +145 -0
- package/src/__tests__/fixtures/drf-schema.json +142 -0
- package/src/__tests__/fixtures.ts +198 -0
- package/src/__tests__/indexer.test.ts +114 -0
- package/src/__tests__/knowledge.test.ts +209 -0
- package/src/__tests__/openapi.test.ts +256 -0
- package/src/__tests__/recipes.test.ts +44 -0
- package/src/__tests__/resources.test.ts +69 -0
- package/src/__tests__/scaffold.test.ts +153 -0
- package/src/__tests__/search.test.ts +105 -0
- package/src/__tests__/tools.test.ts +226 -0
- package/src/__tests__/write.test.ts +134 -0
- package/src/build/extract-components.ts +135 -0
- package/src/build/extract-composables.ts +125 -0
- package/src/build/extract-fields.ts +250 -0
- package/src/build/index.ts +103 -0
- package/src/cli.ts +364 -0
- package/src/index.ts +65 -0
- package/src/module.ts +214 -0
- package/src/runtime/core/doctor.ts +204 -0
- package/src/runtime/core/indexer.ts +279 -0
- package/src/runtime/core/knowledge.ts +121 -0
- package/src/runtime/core/openapi.ts +417 -0
- package/src/runtime/core/prompts.ts +150 -0
- package/src/runtime/core/recipes.ts +361 -0
- package/src/runtime/core/resources.ts +144 -0
- package/src/runtime/core/scaffold/fields.ts +127 -0
- package/src/runtime/core/scaffold/index.ts +120 -0
- package/src/runtime/core/scaffold/templates.ts +394 -0
- package/src/runtime/core/schema-source.ts +123 -0
- package/src/runtime/core/search.ts +282 -0
- package/src/runtime/core/tokenize.ts +146 -0
- package/src/runtime/core/tool-spec.ts +74 -0
- package/src/runtime/core/tools/api.ts +300 -0
- package/src/runtime/core/tools/app.ts +200 -0
- package/src/runtime/core/tools/backend.ts +197 -0
- package/src/runtime/core/tools/docs.ts +215 -0
- package/src/runtime/core/tools/scaffold.ts +176 -0
- package/src/runtime/core/types.ts +133 -0
- package/src/runtime/core/write.ts +119 -0
- package/src/runtime/mcp/handlers/mapo/index.ts +22 -0
- package/src/runtime/mcp/handlers/mapo/prompts/crud-page.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/custom-field.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/debug-form.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/migrate-v1.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/theme.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/resources/app-manifest.ts +28 -0
- package/src/runtime/mcp/handlers/mapo/resources/docs.ts +41 -0
- package/src/runtime/mcp/handlers/mapo/resources/fields.ts +37 -0
- package/src/runtime/mcp/handlers/mapo/resources/knowledge-index.ts +24 -0
- package/src/runtime/mcp/handlers/mapo/tools/backend-schema.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/component-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/composable-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/doctor.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/get-doc.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/inspect-app.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-field-types.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-recipes.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/scaffold.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/search-docs.ts +4 -0
- package/src/runtime/nitro/context.ts +41 -0
- package/src/runtime/nitro/to-mcp-prompt.ts +30 -0
- package/src/runtime/nitro/to-mcp-tool.ts +35 -0
- package/src/runtime/types/virtual-modules.d.ts +6 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
apiTools,
|
|
4
|
+
componentApiTool,
|
|
5
|
+
composableApiTool,
|
|
6
|
+
fieldTypesTool,
|
|
7
|
+
} from "../runtime/core/tools/api.js";
|
|
8
|
+
import {
|
|
9
|
+
appTools,
|
|
10
|
+
doctorTool,
|
|
11
|
+
inspectAppTool,
|
|
12
|
+
} from "../runtime/core/tools/app.js";
|
|
13
|
+
import {
|
|
14
|
+
docsTools,
|
|
15
|
+
getDocTool,
|
|
16
|
+
searchDocsTool,
|
|
17
|
+
} from "../runtime/core/tools/docs.js";
|
|
18
|
+
import { makeContext, makeManifest } from "./fixtures.js";
|
|
19
|
+
|
|
20
|
+
const context = makeContext();
|
|
21
|
+
const allTools = [...docsTools, ...apiTools, ...appTools];
|
|
22
|
+
|
|
23
|
+
describe("tool specs", () => {
|
|
24
|
+
it("namespaces every tool and declares read-only annotations", () => {
|
|
25
|
+
for (const tool of allTools) {
|
|
26
|
+
expect(tool.name.startsWith("mapo_")).toBe(true);
|
|
27
|
+
expect(tool.annotations?.readOnlyHint).toBe(true);
|
|
28
|
+
expect(tool.annotations?.destructiveHint).toBe(false);
|
|
29
|
+
expect(tool.description.length).toBeGreaterThan(40);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("exposes input examples that satisfy the declared schema", () => {
|
|
34
|
+
for (const tool of allTools) {
|
|
35
|
+
for (const example of tool.inputExamples ?? []) {
|
|
36
|
+
for (const key of Object.keys(example)) {
|
|
37
|
+
expect(Object.keys(tool.inputSchema)).toContain(key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("mapo_search_docs", () => {
|
|
45
|
+
it("returns paths and anchors the agent can feed to mapo_get_doc", async () => {
|
|
46
|
+
const output = await searchDocsTool.run(
|
|
47
|
+
{ query: "bulk actions", limit: 2 },
|
|
48
|
+
context,
|
|
49
|
+
);
|
|
50
|
+
expect(output).toContain("howto/crud-list.md");
|
|
51
|
+
expect(output).toContain("#bulk-actions");
|
|
52
|
+
expect(output).toContain("mapo_get_doc");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("explains the miss instead of returning an empty result", async () => {
|
|
56
|
+
const output = await searchDocsTool.run({ query: "zzzqqq" }, context);
|
|
57
|
+
expect(output).toContain("No documentation section matched");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("mapo_get_doc", () => {
|
|
62
|
+
it("returns the section plus the page's heading list", async () => {
|
|
63
|
+
const output = await getDocTool.run(
|
|
64
|
+
{ path: "howto/crud-list.md", heading: "Minimal example" },
|
|
65
|
+
context,
|
|
66
|
+
);
|
|
67
|
+
expect(output).toContain("source: `howto/crud-list.md`");
|
|
68
|
+
expect(output).toContain("MapoList");
|
|
69
|
+
expect(output).toContain("Bulk actions");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("points back to search when the path is wrong", async () => {
|
|
73
|
+
const output = await getDocTool.run({ path: "nope.md" }, context);
|
|
74
|
+
expect(output).toContain("mapo_search_docs");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("mapo_component_api", () => {
|
|
79
|
+
it("renders props, events and slots with their real types", async () => {
|
|
80
|
+
const output = await componentApiTool.run({ name: "MapoList" }, context);
|
|
81
|
+
expect(output).toContain("# MapoList");
|
|
82
|
+
expect(output).toContain("`endpoint`: `string` **required**");
|
|
83
|
+
expect(output).toContain("(default `[]`)");
|
|
84
|
+
expect(output).toContain("**Events** (1)");
|
|
85
|
+
expect(output).toContain("uikit/list.md#mapolist");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("resolves partial names, with or without the Mapo prefix", async () => {
|
|
89
|
+
const output = await componentApiTool.run({ name: "detail" }, context);
|
|
90
|
+
expect(output).toContain("# MapoDetail");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("limits the response to the requested sections", async () => {
|
|
94
|
+
const output = await componentApiTool.run(
|
|
95
|
+
{ name: "MapoList", include: ["slots"] },
|
|
96
|
+
context,
|
|
97
|
+
);
|
|
98
|
+
expect(output).toContain("**Slots**");
|
|
99
|
+
expect(output).not.toContain("**Props**");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("lists what exists when the name is unknown", async () => {
|
|
103
|
+
const output = await componentApiTool.run({ name: "MapoNope" }, context);
|
|
104
|
+
expect(output).toContain("No Mapo component matches");
|
|
105
|
+
expect(output).toContain("MapoList");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("mapo_list_field_types", () => {
|
|
110
|
+
it("lists every registered type with its component", async () => {
|
|
111
|
+
const output = await fieldTypesTool.run({}, context);
|
|
112
|
+
expect(output).toContain("`select` → NuiSelectMenu");
|
|
113
|
+
expect(output).toContain("`text` → NuiInput");
|
|
114
|
+
expect(output).toContain("Shared descriptor properties");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("details one type with attrs, defaults and a skeleton descriptor", async () => {
|
|
118
|
+
const output = await fieldTypesTool.run({ type: "select" }, context);
|
|
119
|
+
expect(output).toContain("# Field type `select`");
|
|
120
|
+
expect(output).toContain("descriptor: `SelectDescriptor`");
|
|
121
|
+
expect(output).toContain('registry defaults: `{"labelKey":"text"}`');
|
|
122
|
+
expect(output).toContain('type: "select"');
|
|
123
|
+
expect(output).toContain("attrs: { items: … }");
|
|
124
|
+
expect(output).toContain("`items`: `readonly string[]` **required**");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("points at defineFormField for unknown types", async () => {
|
|
128
|
+
const output = await fieldTypesTool.run({ type: "nope" }, context);
|
|
129
|
+
expect(output).toContain("defineFormField");
|
|
130
|
+
expect(output).toContain("select, text");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("mapo_composable_api", () => {
|
|
135
|
+
it("groups the auto-imported composables by package", async () => {
|
|
136
|
+
const output = await composableApiTool.run({}, context);
|
|
137
|
+
expect(output).toContain("**@mapomodule/core**: useCrud");
|
|
138
|
+
expect(output).toContain("**@mapomodule/uikit**: useMediaStore");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("returns the real signature for one composable", async () => {
|
|
142
|
+
const output = await composableApiTool.run({ name: "useCrud" }, context);
|
|
143
|
+
expect(output).toContain(
|
|
144
|
+
"useCrud: <T>(endpoint: string) => CrudRepository<T>",
|
|
145
|
+
);
|
|
146
|
+
expect(output).toContain("auto-imported");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("reports unknown names without inventing an API", async () => {
|
|
150
|
+
const output = await composableApiTool.run({ name: "useNope" }, context);
|
|
151
|
+
expect(output).toContain("No auto-imported composable matches");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("mapo_inspect_app", () => {
|
|
156
|
+
it("reports the app's real setup", async () => {
|
|
157
|
+
const output = await inspectAppTool.run({}, context);
|
|
158
|
+
|
|
159
|
+
expect(output).toContain("Installed Mapo modules");
|
|
160
|
+
expect(output).toContain("@nuxt/ui` → `mapomodule");
|
|
161
|
+
expect(output).toContain("Registered field types (2)");
|
|
162
|
+
expect(output).toContain("MapoList");
|
|
163
|
+
expect(output).toContain("/articles");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("limits the report to the requested sections", async () => {
|
|
167
|
+
const output = await inspectAppTool.run({ include: ["fields"] }, context);
|
|
168
|
+
|
|
169
|
+
expect(output).toContain("Registered field types");
|
|
170
|
+
expect(output).not.toContain("## Routes");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("declares what a build-time snapshot cannot see", async () => {
|
|
174
|
+
const output = await inspectAppTool.run({ include: ["fields"] }, context);
|
|
175
|
+
expect(output).toContain("defineFormField()");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("explains how to get an app when there is none", async () => {
|
|
179
|
+
const output = await inspectAppTool.run({}, makeContext(undefined, null));
|
|
180
|
+
|
|
181
|
+
expect(output).toContain("/mcp/mapo");
|
|
182
|
+
expect(output).toContain("dev server");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("mapo_doctor", () => {
|
|
187
|
+
it("reports a clean bill of health", async () => {
|
|
188
|
+
const output = await doctorTool.run({}, context);
|
|
189
|
+
|
|
190
|
+
expect(output).toContain("No problem found");
|
|
191
|
+
expect(output).toContain("Not checked");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("renders findings with severity, fix and doc link", async () => {
|
|
195
|
+
const broken = makeContext(
|
|
196
|
+
undefined,
|
|
197
|
+
makeManifest({ moduleOrder: ["mapomodule"] }),
|
|
198
|
+
);
|
|
199
|
+
const output = await doctorTool.run({}, broken);
|
|
200
|
+
|
|
201
|
+
expect(output).toContain("nuxt-ui-missing (error)");
|
|
202
|
+
expect(output).toContain("**Fix**");
|
|
203
|
+
expect(output).toContain("guide/getting-started.md");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("filters by severity", async () => {
|
|
207
|
+
const noisy = makeContext(
|
|
208
|
+
undefined,
|
|
209
|
+
makeManifest({
|
|
210
|
+
config: { mapoCore: { loginUrl: "/login" } },
|
|
211
|
+
locales: ["fr"],
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const all = await doctorTool.run({}, noisy);
|
|
216
|
+
const errorsOnly = await doctorTool.run({ severity: "error" }, noisy);
|
|
217
|
+
|
|
218
|
+
expect(all).toContain("auth-endpoints-default");
|
|
219
|
+
expect(errorsOnly).not.toContain("auth-endpoints-default");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("explains how to get an app when there is none", async () => {
|
|
223
|
+
const output = await doctorTool.run({}, makeContext(undefined, null));
|
|
224
|
+
expect(output).toContain("/mcp/mapo");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The write guard is the only code here that can damage a project, so it gets
|
|
3
|
+
* the most adversarial tests: traversal, symlinks, absolute paths, and the
|
|
4
|
+
* refusal to replace existing work.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
symlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
17
|
+
import { resolveInsideRoot, writeScaffold } from "../runtime/core/write.js";
|
|
18
|
+
|
|
19
|
+
let root: string;
|
|
20
|
+
let outside: string;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
const base = mkdtempSync(join(tmpdir(), "mapo-write-"));
|
|
24
|
+
root = join(base, "project");
|
|
25
|
+
outside = join(base, "elsewhere");
|
|
26
|
+
mkdirSync(root, { recursive: true });
|
|
27
|
+
mkdirSync(outside, { recursive: true });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("resolveInsideRoot", () => {
|
|
31
|
+
it("resolves a normal relative path", () => {
|
|
32
|
+
expect(resolveInsideRoot(root, "app/pages/index.vue")).toContain(
|
|
33
|
+
"app/pages/index.vue",
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("refuses traversal out of the root", () => {
|
|
38
|
+
expect(resolveInsideRoot(root, "../elsewhere/evil.ts")).toBeNull();
|
|
39
|
+
expect(resolveInsideRoot(root, "app/../../elsewhere/evil.ts")).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("refuses absolute paths", () => {
|
|
43
|
+
expect(resolveInsideRoot(root, "/etc/passwd")).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("refuses a path escaping through a symlinked directory", () => {
|
|
47
|
+
// `project/link` points outside: writing "link/evil.ts" would land there.
|
|
48
|
+
symlinkSync(outside, join(root, "link"));
|
|
49
|
+
expect(resolveInsideRoot(root, "link/evil.ts")).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("accepts a symlink that stays inside the root", () => {
|
|
53
|
+
mkdirSync(join(root, "real"));
|
|
54
|
+
symlinkSync(join(root, "real"), join(root, "alias"));
|
|
55
|
+
expect(resolveInsideRoot(root, "alias/page.vue")).toContain("real");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("does not accept a sibling directory sharing the root's prefix", () => {
|
|
59
|
+
// `/tmp/x/project-evil` must not pass a naive `startsWith(root)` check.
|
|
60
|
+
expect(resolveInsideRoot(root, "../project-evil/file.ts")).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("writeScaffold", () => {
|
|
65
|
+
const file = {
|
|
66
|
+
path: "app/pages/articles/index.vue",
|
|
67
|
+
content: "<template>ok</template>\n",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
it("creates the file and its parent directories", () => {
|
|
71
|
+
const [outcome] = writeScaffold([file], { root });
|
|
72
|
+
|
|
73
|
+
expect(outcome!.status).toBe("written");
|
|
74
|
+
expect(readFileSync(outcome!.absolute!, "utf-8")).toContain("ok");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("refuses to replace an existing file by default", () => {
|
|
78
|
+
writeScaffold([file], { root });
|
|
79
|
+
const [outcome] = writeScaffold(
|
|
80
|
+
[{ ...file, content: "<template>overwritten</template>" }],
|
|
81
|
+
{ root },
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(outcome!.status).toBe("exists");
|
|
85
|
+
expect(outcome!.reason).toContain("overwrite");
|
|
86
|
+
expect(readFileSync(join(root, file.path), "utf-8")).toContain("ok");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("replaces it when overwrite is explicit", () => {
|
|
90
|
+
writeScaffold([file], { root });
|
|
91
|
+
const [outcome] = writeScaffold(
|
|
92
|
+
[{ ...file, content: "<template>overwritten</template>" }],
|
|
93
|
+
{ root, overwrite: true },
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(outcome!.status).toBe("written");
|
|
97
|
+
expect(readFileSync(join(root, file.path), "utf-8")).toContain(
|
|
98
|
+
"overwritten",
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("writes nothing when the adapter forbids it", () => {
|
|
103
|
+
const [outcome] = writeScaffold([file], { root, allowed: false });
|
|
104
|
+
|
|
105
|
+
expect(outcome!.status).toBe("not-allowed");
|
|
106
|
+
expect(existsSync(join(root, file.path))).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("reports each file separately instead of aborting the batch", () => {
|
|
110
|
+
const outcomes = writeScaffold(
|
|
111
|
+
[
|
|
112
|
+
file,
|
|
113
|
+
{ path: "../escape.ts", content: "x" },
|
|
114
|
+
{ path: "/tmp/abs.ts", content: "x" },
|
|
115
|
+
],
|
|
116
|
+
{ root },
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(outcomes.map((outcome) => outcome.status)).toEqual([
|
|
120
|
+
"written",
|
|
121
|
+
"outside-root",
|
|
122
|
+
"absolute-path",
|
|
123
|
+
]);
|
|
124
|
+
expect(existsSync(join(outside, "..", "escape.ts"))).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("leaves a pre-existing file untouched when the write is refused", () => {
|
|
128
|
+
const target = join(root, "keep.ts");
|
|
129
|
+
writeFileSync(target, "original");
|
|
130
|
+
writeScaffold([{ path: "keep.ts", content: "replaced" }], { root });
|
|
131
|
+
|
|
132
|
+
expect(readFileSync(target, "utf-8")).toBe("original");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the public API of every `Mapo*` component from its source.
|
|
3
|
+
*
|
|
4
|
+
* Build-time only: `vue-component-meta` is a devDependency and must never reach
|
|
5
|
+
* the runtime bundle. Source is the ground truth — the curated tables in
|
|
6
|
+
* `docs/uikit/api.md` drift (they listed 11 props for MapoDetail while the
|
|
7
|
+
* component declared 17).
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
10
|
+
import { join, relative } from "node:path";
|
|
11
|
+
import { createChecker } from "vue-component-meta";
|
|
12
|
+
import type { ApiMember, ComponentApi } from "../runtime/core/types.js";
|
|
13
|
+
|
|
14
|
+
/** Packages whose `runtime/components` tree is scanned. */
|
|
15
|
+
const COMPONENT_PACKAGES = [
|
|
16
|
+
{ pkg: "@mapomodule/uikit", dir: "packages/@mapomodule/uikit" },
|
|
17
|
+
{ pkg: "@mapomodule/form", dir: "packages/@mapomodule/form" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** Union types can be enormous; keep them readable in a tool response. */
|
|
21
|
+
const MAX_TYPE_LENGTH = 160;
|
|
22
|
+
|
|
23
|
+
function shortenType(type: string): string {
|
|
24
|
+
const collapsed = type.replace(/\s+/g, " ").trim();
|
|
25
|
+
return collapsed.length > MAX_TYPE_LENGTH
|
|
26
|
+
? `${collapsed.slice(0, MAX_TYPE_LENGTH)}…`
|
|
27
|
+
: collapsed;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function firstSentence(description: string | undefined): string | undefined {
|
|
31
|
+
if (!description) return undefined;
|
|
32
|
+
const trimmed = description.replace(/\s+/g, " ").trim();
|
|
33
|
+
return trimmed || undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function collectVueFiles(root: string): string[] {
|
|
37
|
+
if (!existsSync(root)) return [];
|
|
38
|
+
const files: string[] = [];
|
|
39
|
+
|
|
40
|
+
const walk = (dir: string) => {
|
|
41
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
42
|
+
const full = join(dir, entry.name);
|
|
43
|
+
if (entry.isDirectory()) walk(full);
|
|
44
|
+
else if (entry.name.endsWith(".vue")) files.push(full);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
walk(root);
|
|
49
|
+
return files.sort();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface MetaMember {
|
|
53
|
+
name: string;
|
|
54
|
+
type?: string;
|
|
55
|
+
required?: boolean;
|
|
56
|
+
default?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
global?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toMembers(
|
|
62
|
+
entries: MetaMember[] | undefined,
|
|
63
|
+
withType = true,
|
|
64
|
+
): ApiMember[] {
|
|
65
|
+
return (entries ?? []).map((entry) => ({
|
|
66
|
+
name: entry.name,
|
|
67
|
+
...(withType && entry.type ? { type: shortenType(entry.type) } : {}),
|
|
68
|
+
...(entry.required !== undefined ? { required: entry.required } : {}),
|
|
69
|
+
...(entry.default !== undefined && entry.default !== "undefined"
|
|
70
|
+
? { default: shortenType(String(entry.default)) }
|
|
71
|
+
: {}),
|
|
72
|
+
...(firstSentence(entry.description)
|
|
73
|
+
? { description: firstSentence(entry.description)! }
|
|
74
|
+
: {}),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param repoRoot absolute path of the monorepo root
|
|
80
|
+
* @param docsFor resolves the doc sections that mention a symbol
|
|
81
|
+
*/
|
|
82
|
+
export function extractComponents(
|
|
83
|
+
repoRoot: string,
|
|
84
|
+
docsFor: (symbol: string) => string[],
|
|
85
|
+
): ComponentApi[] {
|
|
86
|
+
const components: ComponentApi[] = [];
|
|
87
|
+
|
|
88
|
+
for (const { pkg, dir } of COMPONENT_PACKAGES) {
|
|
89
|
+
const packageRoot = join(repoRoot, dir);
|
|
90
|
+
const tsconfig = join(packageRoot, "tsconfig.json");
|
|
91
|
+
const componentsRoot = join(packageRoot, "src", "runtime", "components");
|
|
92
|
+
const files = collectVueFiles(componentsRoot).filter((file) =>
|
|
93
|
+
/\/Mapo[A-Z][^/]*\.vue$/.test(file),
|
|
94
|
+
);
|
|
95
|
+
if (!files.length || !existsSync(tsconfig)) continue;
|
|
96
|
+
|
|
97
|
+
const checker = createChecker(tsconfig, {
|
|
98
|
+
forceUseTs: true,
|
|
99
|
+
printer: { newLine: 1 },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
const name = file
|
|
104
|
+
.split("/")
|
|
105
|
+
.pop()!
|
|
106
|
+
.replace(/\.vue$/, "");
|
|
107
|
+
try {
|
|
108
|
+
const meta = checker.getComponentMeta(file);
|
|
109
|
+
const props = (meta.props as MetaMember[]).filter(
|
|
110
|
+
(prop) => !prop.global,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
components.push({
|
|
114
|
+
name,
|
|
115
|
+
pkg,
|
|
116
|
+
file: relative(repoRoot, file),
|
|
117
|
+
...(firstSentence(meta.description)
|
|
118
|
+
? { description: firstSentence(meta.description)! }
|
|
119
|
+
: {}),
|
|
120
|
+
props: toMembers(props),
|
|
121
|
+
events: toMembers(meta.events as MetaMember[]),
|
|
122
|
+
slots: toMembers(meta.slots as MetaMember[]),
|
|
123
|
+
exposed: toMembers(meta.exposed as MetaMember[]),
|
|
124
|
+
docs: docsFor(name),
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// A single unresolvable component must not break the whole build.
|
|
128
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
129
|
+
console.warn(`[mapo-mcp] skipped ${name}: ${message}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return components.sort((a, b) => a.name.localeCompare(b.name));
|
|
135
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the composables each Mapo module auto-imports.
|
|
3
|
+
*
|
|
4
|
+
* The module's `addImports([...])` calls are the authoritative list of what an
|
|
5
|
+
* app can call without importing anything — exactly what an assistant needs to
|
|
6
|
+
* know, and what it cannot infer from `node_modules`.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
9
|
+
import { join, relative } from "node:path";
|
|
10
|
+
import ts from "typescript";
|
|
11
|
+
import type { ComposableApi } from "../runtime/core/types.js";
|
|
12
|
+
|
|
13
|
+
const PACKAGES_ROOT = "packages/@mapomodule";
|
|
14
|
+
const MAX_SIGNATURE_LENGTH = 220;
|
|
15
|
+
|
|
16
|
+
/** `{ name: "useCrud", from: resolver.resolve("./runtime/api/crud") }` */
|
|
17
|
+
const ADD_IMPORT_ENTRY =
|
|
18
|
+
/name:\s*"([A-Za-z_$][\w$]*)"[\s\S]{0,160}?from:[\s\S]{0,120}?"(\.[^"]+)"/g;
|
|
19
|
+
|
|
20
|
+
function shorten(value: string): string {
|
|
21
|
+
const collapsed = value.replace(/\s+/g, " ").trim();
|
|
22
|
+
return collapsed.length > MAX_SIGNATURE_LENGTH
|
|
23
|
+
? `${collapsed.slice(0, MAX_SIGNATURE_LENGTH)}…`
|
|
24
|
+
: collapsed;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Candidate {
|
|
28
|
+
name: string;
|
|
29
|
+
pkg: string;
|
|
30
|
+
file: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Reads every `addImports` entry declared by the Mapo modules. */
|
|
34
|
+
function collectCandidates(repoRoot: string): Candidate[] {
|
|
35
|
+
const packagesDir = join(repoRoot, PACKAGES_ROOT);
|
|
36
|
+
if (!existsSync(packagesDir)) return [];
|
|
37
|
+
|
|
38
|
+
const candidates: Candidate[] = [];
|
|
39
|
+
|
|
40
|
+
for (const entry of readdirSync(packagesDir, { withFileTypes: true })) {
|
|
41
|
+
if (!entry.isDirectory()) continue;
|
|
42
|
+
|
|
43
|
+
const moduleFile = join(packagesDir, entry.name, "src", "module.ts");
|
|
44
|
+
if (!existsSync(moduleFile)) continue;
|
|
45
|
+
|
|
46
|
+
const source = readFileSync(moduleFile, "utf-8");
|
|
47
|
+
const packageRoot = join(packagesDir, entry.name);
|
|
48
|
+
|
|
49
|
+
for (const match of source.matchAll(ADD_IMPORT_ENTRY)) {
|
|
50
|
+
const [, name, from] = match;
|
|
51
|
+
if (!name || !from) continue;
|
|
52
|
+
|
|
53
|
+
const base = join(packageRoot, "src", from.replace(/^\.\//, ""));
|
|
54
|
+
const file = [".ts", ".mts", "/index.ts"]
|
|
55
|
+
.map((suffix) => `${base}${suffix}`)
|
|
56
|
+
.find((path) => existsSync(path));
|
|
57
|
+
|
|
58
|
+
if (file)
|
|
59
|
+
candidates.push({ name, pkg: `@mapomodule/${entry.name}`, file });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return candidates;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function extractComposables(
|
|
67
|
+
repoRoot: string,
|
|
68
|
+
docsFor: (symbol: string) => string[],
|
|
69
|
+
): ComposableApi[] {
|
|
70
|
+
const candidates = collectCandidates(repoRoot);
|
|
71
|
+
if (!candidates.length) return [];
|
|
72
|
+
|
|
73
|
+
const program = ts.createProgram(
|
|
74
|
+
candidates.map((candidate) => candidate.file),
|
|
75
|
+
{
|
|
76
|
+
target: ts.ScriptTarget.ESNext,
|
|
77
|
+
module: ts.ModuleKind.ESNext,
|
|
78
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
79
|
+
strict: true,
|
|
80
|
+
noEmit: true,
|
|
81
|
+
skipLibCheck: true,
|
|
82
|
+
allowJs: true,
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
const checker = program.getTypeChecker();
|
|
86
|
+
|
|
87
|
+
const composables: ComposableApi[] = [];
|
|
88
|
+
|
|
89
|
+
for (const candidate of candidates) {
|
|
90
|
+
const source = program.getSourceFile(candidate.file);
|
|
91
|
+
const moduleSymbol = source
|
|
92
|
+
? checker.getSymbolAtLocation(source)
|
|
93
|
+
: undefined;
|
|
94
|
+
const exported = moduleSymbol
|
|
95
|
+
? checker
|
|
96
|
+
.getExportsOfModule(moduleSymbol)
|
|
97
|
+
.find((symbol) => symbol.getName() === candidate.name)
|
|
98
|
+
: undefined;
|
|
99
|
+
|
|
100
|
+
const declaration =
|
|
101
|
+
exported?.valueDeclaration ?? exported?.declarations?.[0];
|
|
102
|
+
const signature =
|
|
103
|
+
exported && declaration
|
|
104
|
+
? checker.typeToString(
|
|
105
|
+
checker.getTypeOfSymbolAtLocation(exported, declaration),
|
|
106
|
+
)
|
|
107
|
+
: undefined;
|
|
108
|
+
const description = exported
|
|
109
|
+
? ts
|
|
110
|
+
.displayPartsToString(exported.getDocumentationComment(checker))
|
|
111
|
+
.trim()
|
|
112
|
+
: "";
|
|
113
|
+
|
|
114
|
+
composables.push({
|
|
115
|
+
name: candidate.name,
|
|
116
|
+
pkg: candidate.pkg,
|
|
117
|
+
file: relative(repoRoot, candidate.file),
|
|
118
|
+
...(signature ? { signature: shorten(signature) } : {}),
|
|
119
|
+
...(description ? { description: description.replace(/\s+/g, " ") } : {}),
|
|
120
|
+
docs: docsFor(candidate.name),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return composables.sort((a, b) => a.name.localeCompare(b.name));
|
|
125
|
+
}
|