init-xmcp 0.1.14-canary.1 → 0.2.0
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/.turbo/turbo-build.log +1 -1
- package/dist/helpers/create-prompt.d.ts +6 -0
- package/dist/helpers/create-prompt.js +54 -0
- package/dist/helpers/generate-config.d.ts +1 -1
- package/dist/helpers/generate-config.js +14 -1
- package/dist/helpers/init.d.ts +1 -0
- package/dist/helpers/init.js +6 -2
- package/dist/index.js +28 -0
- package/package.json +1 -1
- package/src/helpers/create-prompt.ts +60 -0
- package/src/helpers/generate-config.ts +16 -1
- package/src/helpers/init.ts +15 -3
- package/src/index.ts +31 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Create prompts directory and prompt file
|
|
6
|
+
* @param projectRoot - Project root directory
|
|
7
|
+
* @param promptsPath - Path for prompts directory (relative to project root)
|
|
8
|
+
*/
|
|
9
|
+
export function createPrompt(projectRoot, promptsPath) {
|
|
10
|
+
// normalize the path to handle any path separators correctly
|
|
11
|
+
const normalizedPromptsPath = path.normalize(promptsPath);
|
|
12
|
+
const promptsDirPath = path.join(projectRoot, normalizedPromptsPath);
|
|
13
|
+
try {
|
|
14
|
+
// create prompts directory and all parent directories
|
|
15
|
+
fs.ensureDirSync(promptsDirPath);
|
|
16
|
+
const promptFilePath = path.join(promptsDirPath, "review-code.ts");
|
|
17
|
+
fs.writeFileSync(promptFilePath, promptTemplate);
|
|
18
|
+
console.log(chalk.green(`Created prompt: ${normalizedPromptsPath}/review-code.ts`));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(chalk.red(`Failed to create prompt: ${error}`));
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const promptTemplate = `import { z } from "zod";
|
|
26
|
+
import { type InferSchema, type PromptMetadata } from "xmcp";
|
|
27
|
+
|
|
28
|
+
// Define the schema for prompt parameters
|
|
29
|
+
export const schema = {
|
|
30
|
+
code: z.string().describe("The code to review"),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Define prompt metadata
|
|
34
|
+
export const metadata: PromptMetadata = {
|
|
35
|
+
name: "review-code",
|
|
36
|
+
title: "Review Code",
|
|
37
|
+
description: "Review code for best practices and potential issues",
|
|
38
|
+
role: "user",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Prompt implementation
|
|
42
|
+
export default function reviewCode({ code }: InferSchema<typeof schema>) {
|
|
43
|
+
return \`Please review this code for:
|
|
44
|
+
- Code quality and best practices
|
|
45
|
+
- Potential bugs or security issues
|
|
46
|
+
- Performance optimizations
|
|
47
|
+
- Readability and maintainability
|
|
48
|
+
|
|
49
|
+
Code to review:
|
|
50
|
+
\\\`\\\`\\\`
|
|
51
|
+
\${code}
|
|
52
|
+
\\\`\\\`\\\`\`;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param frameworkAdapter - Selected framework adapter
|
|
5
5
|
* @param toolsPath - Optional path for tools directory
|
|
6
6
|
*/
|
|
7
|
-
export declare function generateConfig(projectPath: string, frameworkAdapter: string, toolsPath?: string): void;
|
|
7
|
+
export declare function generateConfig(projectPath: string, frameworkAdapter: string, toolsPath?: string, promptsPath?: string): void;
|
|
@@ -6,7 +6,7 @@ import fs from "fs-extra";
|
|
|
6
6
|
* @param frameworkAdapter - Selected framework adapter
|
|
7
7
|
* @param toolsPath - Optional path for tools directory
|
|
8
8
|
*/
|
|
9
|
-
export function generateConfig(projectPath, frameworkAdapter, toolsPath) {
|
|
9
|
+
export function generateConfig(projectPath, frameworkAdapter, toolsPath, promptsPath) {
|
|
10
10
|
let configContent = `import { type XmcpConfig } from "xmcp";
|
|
11
11
|
|
|
12
12
|
const config: XmcpConfig = {
|
|
@@ -18,6 +18,19 @@ const config: XmcpConfig = {
|
|
|
18
18
|
configContent += `
|
|
19
19
|
paths: {
|
|
20
20
|
tools: "${toolsPath}",
|
|
21
|
+
},`;
|
|
22
|
+
}
|
|
23
|
+
if (promptsPath) {
|
|
24
|
+
configContent += `
|
|
25
|
+
paths: {
|
|
26
|
+
prompts: "${promptsPath}",
|
|
27
|
+
},`;
|
|
28
|
+
}
|
|
29
|
+
if (toolsPath && promptsPath) {
|
|
30
|
+
configContent += `
|
|
31
|
+
paths: {
|
|
32
|
+
tools: "${toolsPath}",
|
|
33
|
+
prompts: "${promptsPath}",
|
|
21
34
|
},`;
|
|
22
35
|
}
|
|
23
36
|
configContent += `
|
package/dist/helpers/init.d.ts
CHANGED
package/dist/helpers/init.js
CHANGED
|
@@ -5,9 +5,10 @@ import { updateTsConfig } from "./update-tsconfig.js";
|
|
|
5
5
|
import { updateGitignore } from "./update-gitignore.js";
|
|
6
6
|
import { createTool } from "./create-tool.js";
|
|
7
7
|
import { createRoute } from "./create-handler.js";
|
|
8
|
+
import { createPrompt } from "./create-prompt.js";
|
|
8
9
|
export async function init(options) {
|
|
9
|
-
const { projectRoot, framework, toolsPath, routePath, packageManager } = options;
|
|
10
|
-
generateConfig(projectRoot, framework, toolsPath);
|
|
10
|
+
const { projectRoot, framework, toolsPath, promptsPath, routePath, packageManager, } = options;
|
|
11
|
+
generateConfig(projectRoot, framework, toolsPath, promptsPath);
|
|
11
12
|
await install(projectRoot, packageManager);
|
|
12
13
|
updatePackageJson(projectRoot);
|
|
13
14
|
updateTsConfig(projectRoot);
|
|
@@ -15,6 +16,9 @@ export async function init(options) {
|
|
|
15
16
|
if (toolsPath) {
|
|
16
17
|
createTool(projectRoot, toolsPath);
|
|
17
18
|
}
|
|
19
|
+
if (promptsPath) {
|
|
20
|
+
createPrompt(projectRoot, promptsPath);
|
|
21
|
+
}
|
|
18
22
|
if (framework === "nextjs" && routePath) {
|
|
19
23
|
createRoute(projectRoot, routePath);
|
|
20
24
|
}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const program = new Command()
|
|
|
21
21
|
.option("-y, --yes", "Skip confirmation prompts", false)
|
|
22
22
|
.option("--package-manager <manager>", "Specify package manager (npm, yarn, pnpm, bun)", "")
|
|
23
23
|
.option("--tools-path <path>", "Specify custom tools path", "")
|
|
24
|
+
.option("--prompts-path <path>", "Specify custom prompts path", "")
|
|
24
25
|
.option("--route-path <path>", "Specify custom route path", "")
|
|
25
26
|
.option("--skip-tools", "Skip tool creation", false)
|
|
26
27
|
.option("--skip-route", "Skip route creation", false)
|
|
@@ -57,6 +58,18 @@ const program = new Command()
|
|
|
57
58
|
toolsPath = hasSrcFolder ? "src/tools" : "tools";
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
// determine prompts path
|
|
62
|
+
let promptsPath;
|
|
63
|
+
if (!options.skipPrompts) {
|
|
64
|
+
if (options.promptsPath) {
|
|
65
|
+
promptsPath = options.promptsPath;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// check if src folder exists and default to src/prompts if it does, otherwise prompts
|
|
69
|
+
const hasSrcFolder = fs.existsSync(path.join(projectRoot, "src"));
|
|
70
|
+
promptsPath = hasSrcFolder ? "src/prompts" : "prompts";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
60
73
|
// determine route path
|
|
61
74
|
let routePath;
|
|
62
75
|
if (detectedFramework === "nextjs" && !options.skipRoute) {
|
|
@@ -94,6 +107,14 @@ const program = new Command()
|
|
|
94
107
|
default: toolsPath,
|
|
95
108
|
});
|
|
96
109
|
}
|
|
110
|
+
if (!options.skipPrompts) {
|
|
111
|
+
prompts.push({
|
|
112
|
+
type: "input",
|
|
113
|
+
name: "promptsPath",
|
|
114
|
+
message: "Prompts directory path:",
|
|
115
|
+
default: promptsPath,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
97
118
|
if (detectedFramework === "nextjs" && !options.skipRoute) {
|
|
98
119
|
prompts.push({
|
|
99
120
|
type: "input",
|
|
@@ -132,6 +153,9 @@ const program = new Command()
|
|
|
132
153
|
if (!options.skipTools) {
|
|
133
154
|
toolsPath = answers.toolsPath;
|
|
134
155
|
}
|
|
156
|
+
if (!options.skipPrompts) {
|
|
157
|
+
promptsPath = answers.promptsPath;
|
|
158
|
+
}
|
|
135
159
|
if (detectedFramework === "nextjs" &&
|
|
136
160
|
!options.skipRoute &&
|
|
137
161
|
answers.routePath) {
|
|
@@ -196,6 +220,7 @@ const program = new Command()
|
|
|
196
220
|
projectRoot,
|
|
197
221
|
framework: detectedFramework,
|
|
198
222
|
toolsPath,
|
|
223
|
+
promptsPath,
|
|
199
224
|
routePath,
|
|
200
225
|
packageManager,
|
|
201
226
|
});
|
|
@@ -205,6 +230,9 @@ const program = new Command()
|
|
|
205
230
|
if (toolsPath) {
|
|
206
231
|
console.log(` • ${toolsPath}/greet.ts`);
|
|
207
232
|
}
|
|
233
|
+
if (promptsPath) {
|
|
234
|
+
console.log(` • ${promptsPath}/greet.ts`);
|
|
235
|
+
}
|
|
208
236
|
if (routePath) {
|
|
209
237
|
console.log(` • ${routePath}/route.ts`);
|
|
210
238
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create prompts directory and prompt file
|
|
7
|
+
* @param projectRoot - Project root directory
|
|
8
|
+
* @param promptsPath - Path for prompts directory (relative to project root)
|
|
9
|
+
*/
|
|
10
|
+
export function createPrompt(projectRoot: string, promptsPath: string): void {
|
|
11
|
+
// normalize the path to handle any path separators correctly
|
|
12
|
+
const normalizedPromptsPath = path.normalize(promptsPath);
|
|
13
|
+
const promptsDirPath = path.join(projectRoot, normalizedPromptsPath);
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// create prompts directory and all parent directories
|
|
17
|
+
fs.ensureDirSync(promptsDirPath);
|
|
18
|
+
|
|
19
|
+
const promptFilePath = path.join(promptsDirPath, "review-code.ts");
|
|
20
|
+
fs.writeFileSync(promptFilePath, promptTemplate);
|
|
21
|
+
|
|
22
|
+
console.log(
|
|
23
|
+
chalk.green(`Created prompt: ${normalizedPromptsPath}/review-code.ts`)
|
|
24
|
+
);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(chalk.red(`Failed to create prompt: ${error}`));
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const promptTemplate = `import { z } from "zod";
|
|
32
|
+
import { type InferSchema, type PromptMetadata } from "xmcp";
|
|
33
|
+
|
|
34
|
+
// Define the schema for prompt parameters
|
|
35
|
+
export const schema = {
|
|
36
|
+
code: z.string().describe("The code to review"),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Define prompt metadata
|
|
40
|
+
export const metadata: PromptMetadata = {
|
|
41
|
+
name: "review-code",
|
|
42
|
+
title: "Review Code",
|
|
43
|
+
description: "Review code for best practices and potential issues",
|
|
44
|
+
role: "user",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Prompt implementation
|
|
48
|
+
export default function reviewCode({ code }: InferSchema<typeof schema>) {
|
|
49
|
+
return \`Please review this code for:
|
|
50
|
+
- Code quality and best practices
|
|
51
|
+
- Potential bugs or security issues
|
|
52
|
+
- Performance optimizations
|
|
53
|
+
- Readability and maintainability
|
|
54
|
+
|
|
55
|
+
Code to review:
|
|
56
|
+
\\\`\\\`\\\`
|
|
57
|
+
\${code}
|
|
58
|
+
\\\`\\\`\\\`\`;
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
@@ -10,7 +10,8 @@ import fs from "fs-extra";
|
|
|
10
10
|
export function generateConfig(
|
|
11
11
|
projectPath: string,
|
|
12
12
|
frameworkAdapter: string,
|
|
13
|
-
toolsPath?: string
|
|
13
|
+
toolsPath?: string,
|
|
14
|
+
promptsPath?: string
|
|
14
15
|
): void {
|
|
15
16
|
let configContent = `import { type XmcpConfig } from "xmcp";
|
|
16
17
|
|
|
@@ -26,6 +27,20 @@ const config: XmcpConfig = {
|
|
|
26
27
|
tools: "${toolsPath}",
|
|
27
28
|
},`;
|
|
28
29
|
}
|
|
30
|
+
if (promptsPath) {
|
|
31
|
+
configContent += `
|
|
32
|
+
paths: {
|
|
33
|
+
prompts: "${promptsPath}",
|
|
34
|
+
},`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (toolsPath && promptsPath) {
|
|
38
|
+
configContent += `
|
|
39
|
+
paths: {
|
|
40
|
+
tools: "${toolsPath}",
|
|
41
|
+
prompts: "${promptsPath}",
|
|
42
|
+
},`;
|
|
43
|
+
}
|
|
29
44
|
|
|
30
45
|
configContent += `
|
|
31
46
|
};
|
package/src/helpers/init.ts
CHANGED
|
@@ -7,20 +7,28 @@ import { createTool } from "./create-tool.js";
|
|
|
7
7
|
import { Framework } from "./detect-framework.js";
|
|
8
8
|
import { createRoute } from "./create-handler.js";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
+
import { createPrompt } from "./create-prompt.js";
|
|
10
11
|
|
|
11
12
|
interface InitOptions {
|
|
12
13
|
projectRoot: string;
|
|
13
14
|
framework: Framework;
|
|
14
15
|
toolsPath: string | undefined;
|
|
16
|
+
promptsPath: string | undefined;
|
|
15
17
|
routePath: string | undefined;
|
|
16
18
|
packageManager: "npm" | "yarn" | "pnpm" | "bun";
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export async function init(options: InitOptions) {
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
+
const {
|
|
23
|
+
projectRoot,
|
|
24
|
+
framework,
|
|
25
|
+
toolsPath,
|
|
26
|
+
promptsPath,
|
|
27
|
+
routePath,
|
|
28
|
+
packageManager,
|
|
29
|
+
} = options;
|
|
22
30
|
|
|
23
|
-
generateConfig(projectRoot, framework, toolsPath);
|
|
31
|
+
generateConfig(projectRoot, framework, toolsPath, promptsPath);
|
|
24
32
|
|
|
25
33
|
await install(projectRoot, packageManager);
|
|
26
34
|
|
|
@@ -34,6 +42,10 @@ export async function init(options: InitOptions) {
|
|
|
34
42
|
createTool(projectRoot, toolsPath);
|
|
35
43
|
}
|
|
36
44
|
|
|
45
|
+
if (promptsPath) {
|
|
46
|
+
createPrompt(projectRoot, promptsPath);
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
if (framework === "nextjs" && routePath) {
|
|
38
50
|
createRoute(projectRoot, routePath);
|
|
39
51
|
}
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ const program = new Command()
|
|
|
39
39
|
""
|
|
40
40
|
)
|
|
41
41
|
.option("--tools-path <path>", "Specify custom tools path", "")
|
|
42
|
+
.option("--prompts-path <path>", "Specify custom prompts path", "")
|
|
42
43
|
.option("--route-path <path>", "Specify custom route path", "")
|
|
43
44
|
.option("--skip-tools", "Skip tool creation", false)
|
|
44
45
|
.option("--skip-route", "Skip route creation", false)
|
|
@@ -89,6 +90,19 @@ const program = new Command()
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
// determine prompts path
|
|
94
|
+
|
|
95
|
+
let promptsPath: string | undefined;
|
|
96
|
+
if (!options.skipPrompts) {
|
|
97
|
+
if (options.promptsPath) {
|
|
98
|
+
promptsPath = options.promptsPath;
|
|
99
|
+
} else {
|
|
100
|
+
// check if src folder exists and default to src/prompts if it does, otherwise prompts
|
|
101
|
+
const hasSrcFolder = fs.existsSync(path.join(projectRoot, "src"));
|
|
102
|
+
promptsPath = hasSrcFolder ? "src/prompts" : "prompts";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
// determine route path
|
|
93
107
|
let routePath: string | undefined;
|
|
94
108
|
if (detectedFramework === "nextjs" && !options.skipRoute) {
|
|
@@ -132,6 +146,15 @@ const program = new Command()
|
|
|
132
146
|
});
|
|
133
147
|
}
|
|
134
148
|
|
|
149
|
+
if (!options.skipPrompts) {
|
|
150
|
+
prompts.push({
|
|
151
|
+
type: "input",
|
|
152
|
+
name: "promptsPath",
|
|
153
|
+
message: "Prompts directory path:",
|
|
154
|
+
default: promptsPath,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
if (detectedFramework === "nextjs" && !options.skipRoute) {
|
|
136
159
|
prompts.push({
|
|
137
160
|
type: "input",
|
|
@@ -176,6 +199,9 @@ const program = new Command()
|
|
|
176
199
|
if (!options.skipTools) {
|
|
177
200
|
toolsPath = answers.toolsPath;
|
|
178
201
|
}
|
|
202
|
+
if (!options.skipPrompts) {
|
|
203
|
+
promptsPath = answers.promptsPath;
|
|
204
|
+
}
|
|
179
205
|
if (
|
|
180
206
|
detectedFramework === "nextjs" &&
|
|
181
207
|
!options.skipRoute &&
|
|
@@ -260,6 +286,7 @@ const program = new Command()
|
|
|
260
286
|
projectRoot,
|
|
261
287
|
framework: detectedFramework,
|
|
262
288
|
toolsPath,
|
|
289
|
+
promptsPath,
|
|
263
290
|
routePath,
|
|
264
291
|
packageManager,
|
|
265
292
|
});
|
|
@@ -272,6 +299,10 @@ const program = new Command()
|
|
|
272
299
|
console.log(` • ${toolsPath}/greet.ts`);
|
|
273
300
|
}
|
|
274
301
|
|
|
302
|
+
if (promptsPath) {
|
|
303
|
+
console.log(` • ${promptsPath}/greet.ts`);
|
|
304
|
+
}
|
|
305
|
+
|
|
275
306
|
if (routePath) {
|
|
276
307
|
console.log(` • ${routePath}/route.ts`);
|
|
277
308
|
}
|