@codapult/cli 0.15.3 → 0.16.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/README.md +107 -3
- package/dist/commands/config-show.js +6 -32
- package/dist/commands/db.d.ts +2 -0
- package/dist/commands/db.js +81 -2
- package/dist/commands/deploy.js +44 -17
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +9 -234
- package/dist/commands/env.js +21 -17
- package/dist/commands/mcp.d.ts +5 -0
- package/dist/commands/mcp.js +98 -0
- package/dist/commands/plugins.js +40 -5
- package/dist/commands/setup.js +2 -2
- package/dist/index.js +24 -5
- package/dist/mcp/resources.js +34 -3
- package/dist/mcp/server.js +4 -1
- package/dist/mcp/tools/db.js +185 -49
- package/dist/mcp/tools/db.test.js +59 -7
- package/dist/mcp/tools/env.d.ts +7 -0
- package/dist/mcp/tools/env.js +96 -2
- package/dist/mcp/tools/env.test.js +4 -2
- package/dist/mcp/tools/generate.js +64 -10
- package/dist/mcp/tools/plugins.js +125 -13
- package/dist/mcp/tools/project.js +59 -46
- package/dist/mcp/tools/project.test.js +20 -8
- package/dist/utils/check-report.d.ts +18 -0
- package/dist/utils/check-report.js +30 -0
- package/dist/utils/command.d.ts +18 -0
- package/dist/utils/command.js +29 -0
- package/dist/utils/config-report.d.ts +12 -0
- package/dist/utils/config-report.js +41 -0
- package/dist/utils/config-report.test.d.ts +1 -0
- package/dist/utils/config-report.test.js +20 -0
- package/dist/utils/db-diff.d.ts +11 -0
- package/dist/utils/db-diff.js +37 -0
- package/dist/utils/env-compatibility.d.ts +10 -0
- package/dist/utils/env-compatibility.js +52 -0
- package/dist/utils/env-compatibility.test.d.ts +1 -0
- package/dist/utils/env-compatibility.test.js +23 -0
- package/dist/utils/env-config.d.ts +9 -0
- package/dist/utils/env-config.js +116 -4
- package/dist/utils/env-schema-parser.d.ts +2 -0
- package/dist/utils/env-schema-parser.js +32 -0
- package/dist/utils/env-schema-parser.test.d.ts +1 -0
- package/dist/utils/env-schema-parser.test.js +11 -0
- package/dist/utils/health-render.d.ts +3 -0
- package/dist/utils/health-render.js +28 -0
- package/dist/utils/health-render.test.d.ts +1 -0
- package/dist/utils/health-render.test.js +18 -0
- package/dist/utils/health.d.ts +26 -0
- package/dist/utils/health.js +249 -0
- package/dist/utils/live-db-diff.d.ts +17 -0
- package/dist/utils/live-db-diff.js +131 -0
- package/dist/utils/live-db-diff.test.d.ts +1 -0
- package/dist/utils/live-db-diff.test.js +29 -0
- package/dist/utils/manifest.d.ts +1 -0
- package/dist/utils/patchers.d.ts +2 -0
- package/dist/utils/patchers.js +25 -13
- package/dist/utils/patchers.test.js +41 -7
- package/dist/utils/schema-parity.d.ts +15 -0
- package/dist/utils/schema-parity.js +91 -0
- package/dist/utils/schema-parity.test.d.ts +1 -0
- package/dist/utils/schema-parity.test.js +27 -0
- package/dist/utils/schema-parser.d.ts +12 -0
- package/dist/utils/schema-parser.js +130 -0
- package/dist/utils/schema-parser.test.d.ts +1 -0
- package/dist/utils/schema-parser.test.js +59 -0
- package/package.json +2 -2
|
@@ -36,29 +36,55 @@ export function registerGenerateTools(server) {
|
|
|
36
36
|
server.registerTool('codapult_generate_page', {
|
|
37
37
|
title: 'Generate Page',
|
|
38
38
|
description: 'Create a new dashboard page following Codapult conventions (server component, auth, Card UI)',
|
|
39
|
-
inputSchema: {
|
|
40
|
-
|
|
39
|
+
inputSchema: {
|
|
40
|
+
name: z.string().describe('Page name (e.g. "analytics", "team-settings")'),
|
|
41
|
+
dry_run: z.boolean().default(false).describe('Preview without writing files'),
|
|
42
|
+
},
|
|
43
|
+
}, ({ name, dry_run }) => {
|
|
41
44
|
validateGeneratedName(name);
|
|
42
45
|
const root = getRoot();
|
|
43
46
|
const kebab = toKebab(name);
|
|
44
47
|
const pascal = toPascal(name);
|
|
45
48
|
const title = pascal.replace(/([A-Z])/g, ' $1').trim();
|
|
49
|
+
const path = `src/app/(dashboard)/dashboard/${kebab}/page.tsx`;
|
|
50
|
+
if (dry_run)
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: JSON.stringify({ dryRun: true, path, wouldCreate: !existsSync(resolve(getRoot(), path)) }, null, 2),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
46
59
|
const page = `import { getAppSession } from '@/lib/auth';\nimport { redirect } from 'next/navigation';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';\n\nexport const metadata = {\n title: '${title} — Codapult',\n};\n\nexport default async function ${pascal}Page() {\n const session = await getAppSession();\n if (!session) redirect('/sign-in');\n\n return (\n <div className="space-y-6">\n <div>\n <h1 className="text-3xl font-bold tracking-tight">${title}</h1>\n <p className="text-muted-foreground">Manage your ${kebab} settings</p>\n </div>\n\n <Card>\n <CardHeader>\n <CardTitle>${title}</CardTitle>\n <CardDescription>Your ${kebab} content goes here</CardDescription>\n </CardHeader>\n <CardContent>\n <p className="text-muted-foreground">Start building your ${kebab} page.</p>\n </CardContent>\n </Card>\n </div>\n );\n}\n`;
|
|
47
|
-
const result = writeIfNew(resolve(root,
|
|
60
|
+
const result = writeIfNew(resolve(root, path), page);
|
|
48
61
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
49
62
|
});
|
|
50
63
|
server.registerTool('codapult_generate_api', {
|
|
51
64
|
title: 'Generate API Route',
|
|
52
65
|
description: 'Create a new API route with auth, rate limiting, and Zod validation',
|
|
53
|
-
inputSchema: {
|
|
54
|
-
|
|
66
|
+
inputSchema: {
|
|
67
|
+
name: z.string().describe('Route name (e.g. "webhooks", "billing")'),
|
|
68
|
+
dry_run: z.boolean().default(false).describe('Preview without writing files'),
|
|
69
|
+
},
|
|
70
|
+
}, ({ name, dry_run }) => {
|
|
55
71
|
validateGeneratedName(name);
|
|
56
72
|
const root = getRoot();
|
|
57
73
|
const kebab = toKebab(name);
|
|
58
74
|
const camel = toCamel(name);
|
|
59
75
|
const schemaName = `${camel}Schema`;
|
|
76
|
+
const path = `src/app/api/${kebab}/route.ts`;
|
|
77
|
+
if (dry_run)
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: 'text',
|
|
82
|
+
text: JSON.stringify({ dryRun: true, path, wouldCreate: !existsSync(resolve(getRoot(), path)) }, null, 2),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
60
86
|
const route = `import { NextResponse } from 'next/server';\nimport { getAppSession } from '@/lib/auth';\nimport { checkRateLimit } from '@/lib/rate-limit';\nimport { z } from 'zod';\n\nconst ${schemaName} = z.object({\n // Define your request body schema here\n});\n\nexport async function GET() {\n const session = await getAppSession();\n if (!session) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });\n }\n\n const { allowed, resetAt } = checkRateLimit(\`${kebab}:\${session.user.id}\`, {\n limit: 30,\n windowSeconds: 60,\n });\n if (!allowed) {\n return NextResponse.json(\n { error: 'Too many requests. Please wait a moment.' },\n { status: 429, headers: { 'Retry-After': String(Math.ceil((resetAt - Date.now()) / 1000)) } },\n );\n }\n\n return NextResponse.json({ message: 'ok' });\n}\n\nexport async function POST(req: Request) {\n const session = await getAppSession();\n if (!session) {\n return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });\n }\n\n const { allowed, resetAt } = checkRateLimit(\`${kebab}:\${session.user.id}\`, {\n limit: 30,\n windowSeconds: 60,\n });\n if (!allowed) {\n return NextResponse.json(\n { error: 'Too many requests. Please wait a moment.' },\n { status: 429, headers: { 'Retry-After': String(Math.ceil((resetAt - Date.now()) / 1000)) } },\n );\n }\n\n try {\n const body = ${schemaName}.parse(await req.json());\n return NextResponse.json({ success: true });\n } catch {\n return NextResponse.json({ error: 'Invalid request body' }, { status: 400 });\n }\n}\n`;
|
|
61
|
-
const result = writeIfNew(resolve(root,
|
|
87
|
+
const result = writeIfNew(resolve(root, path), route);
|
|
62
88
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
63
89
|
});
|
|
64
90
|
server.registerTool('codapult_generate_action', {
|
|
@@ -66,28 +92,56 @@ export function registerGenerateTools(server) {
|
|
|
66
92
|
description: 'Create a new server action with auth, rate limiting, and Zod validation',
|
|
67
93
|
inputSchema: {
|
|
68
94
|
name: z.string().describe('Action name (e.g. "update-profile", "create-team")'),
|
|
95
|
+
dry_run: z.boolean().default(false).describe('Preview without writing files'),
|
|
69
96
|
},
|
|
70
|
-
}, ({ name }) => {
|
|
97
|
+
}, ({ name, dry_run }) => {
|
|
71
98
|
validateGeneratedName(name);
|
|
72
99
|
const root = getRoot();
|
|
73
100
|
const kebab = toKebab(name);
|
|
74
101
|
const camel = toCamel(name);
|
|
75
102
|
const schemaName = `${camel}Schema`;
|
|
103
|
+
const path = `src/lib/actions/${kebab}.ts`;
|
|
104
|
+
if (dry_run)
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: 'text',
|
|
109
|
+
text: JSON.stringify({ dryRun: true, path, wouldCreate: !existsSync(resolve(getRoot(), path)) }, null, 2),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
76
113
|
const action = `'use server';\n\nimport { redirect } from 'next/navigation';\nimport { revalidatePath } from 'next/cache';\nimport { getAppSession } from '@/lib/auth';\nimport { checkRateLimit } from '@/lib/rate-limit';\nimport { z } from 'zod';\n\nconst ${schemaName} = z.object({\n // Define your input schema here\n});\n\nconst RATE_LIMIT = { limit: 10, windowSeconds: 60 } as const;\n\nexport async function ${camel}Action(input: unknown): Promise<{ success: boolean }> {\n const session = await getAppSession();\n if (!session) redirect('/sign-in');\n\n const { allowed } = checkRateLimit(\`${kebab}:\${session.user.id}\`, RATE_LIMIT);\n if (!allowed) throw new Error('Too many requests. Please wait a moment.');\n\n const data = ${schemaName}.parse(input);\n\n // TODO: implement your action logic\n\n revalidatePath('/dashboard/${kebab}');\n return { success: true };\n}\n`;
|
|
77
|
-
const result = writeIfNew(resolve(root,
|
|
114
|
+
const result = writeIfNew(resolve(root, path), action);
|
|
78
115
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
79
116
|
});
|
|
80
117
|
server.registerTool('codapult_generate_plugin', {
|
|
81
118
|
title: 'Generate Plugin',
|
|
82
119
|
description: 'Scaffold a new plugin repository with package.json, tsconfig, index.ts, and manifest',
|
|
83
|
-
inputSchema: {
|
|
84
|
-
|
|
120
|
+
inputSchema: {
|
|
121
|
+
name: z.string().describe('Plugin name (e.g. "my-widget")'),
|
|
122
|
+
dry_run: z.boolean().default(false).describe('Preview without creating files'),
|
|
123
|
+
},
|
|
124
|
+
}, ({ name, dry_run }) => {
|
|
85
125
|
validateGeneratedName(name);
|
|
86
126
|
const root = getRoot();
|
|
87
127
|
const kebab = toKebab(name);
|
|
88
128
|
const camel = toCamel(name);
|
|
89
129
|
const pascal = toPascal(name);
|
|
90
130
|
const pluginDir = resolve(root, '..', `codapult-plugin-${kebab}`);
|
|
131
|
+
if (dry_run) {
|
|
132
|
+
return {
|
|
133
|
+
content: [
|
|
134
|
+
{
|
|
135
|
+
type: 'text',
|
|
136
|
+
text: JSON.stringify({
|
|
137
|
+
dryRun: true,
|
|
138
|
+
path: pluginDir,
|
|
139
|
+
files: ['package.json', 'src/index.ts', 'codapult-plugin.json', '.gitignore'],
|
|
140
|
+
}, null, 2),
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
91
145
|
if (existsSync(pluginDir)) {
|
|
92
146
|
return {
|
|
93
147
|
content: [{ type: 'text', text: `Directory already exists: ${pluginDir}` }],
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { findProjectRoot } from '../../utils/project.js';
|
|
5
5
|
import { ENV_FILE_NAME } from '../../utils/project-env.js';
|
|
6
6
|
import { resolveManifest } from '../../utils/manifest.js';
|
|
7
|
-
import { patchSchemaImports, patchSchemaTables, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../../utils/patchers.js';
|
|
7
|
+
import { patchSchemaImports, patchSchemaImportsPg, patchSchemaTables, patchSchemaTablesPg, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../../utils/patchers.js';
|
|
8
8
|
import { envSourceSchema } from './schemas.js';
|
|
9
9
|
function getRoot() {
|
|
10
10
|
const root = findProjectRoot();
|
|
@@ -21,7 +21,9 @@ export function registerPluginTools(server) {
|
|
|
21
21
|
const root = getRoot();
|
|
22
22
|
const pluginsDir = resolve(root, 'src/plugins');
|
|
23
23
|
if (!existsSync(pluginsDir)) {
|
|
24
|
-
return {
|
|
24
|
+
return {
|
|
25
|
+
content: [{ type: 'text', text: JSON.stringify({ plugins: [] }) }],
|
|
26
|
+
};
|
|
25
27
|
}
|
|
26
28
|
const files = readdirSync(pluginsDir).filter((f) => f.endsWith('.ts') && f !== 'index.ts');
|
|
27
29
|
const pkgPath = resolve(root, 'package.json');
|
|
@@ -37,7 +39,9 @@ export function registerPluginTools(server) {
|
|
|
37
39
|
const packageName = pkgMatch?.[1] ?? 'unknown';
|
|
38
40
|
return { name, package: packageName, version: deps[packageName] ?? '' };
|
|
39
41
|
});
|
|
40
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: 'text', text: JSON.stringify({ plugins }, null, 2) }],
|
|
44
|
+
};
|
|
41
45
|
});
|
|
42
46
|
server.registerTool('codapult_plugins_add', {
|
|
43
47
|
title: 'Add Plugin',
|
|
@@ -45,8 +49,12 @@ export function registerPluginTools(server) {
|
|
|
45
49
|
inputSchema: {
|
|
46
50
|
name: z.string().describe('Plugin name (e.g. "ai-kit", "video-player")'),
|
|
47
51
|
env_source: envSourceSchema.optional(),
|
|
52
|
+
dry_run: z
|
|
53
|
+
.boolean()
|
|
54
|
+
.default(false)
|
|
55
|
+
.describe('Preview changes without modifying the project'),
|
|
48
56
|
},
|
|
49
|
-
}, ({ name, env_source }) => {
|
|
57
|
+
}, ({ name, env_source, dry_run }) => {
|
|
50
58
|
const root = getRoot();
|
|
51
59
|
const result = resolveManifest(root, name);
|
|
52
60
|
if (!result) {
|
|
@@ -57,6 +65,44 @@ export function registerPluginTools(server) {
|
|
|
57
65
|
}
|
|
58
66
|
const { manifest, pluginDir } = result;
|
|
59
67
|
const steps = [];
|
|
68
|
+
if (dry_run) {
|
|
69
|
+
return {
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: 'text',
|
|
73
|
+
text: JSON.stringify({
|
|
74
|
+
dryRun: true,
|
|
75
|
+
plugin: manifest.name,
|
|
76
|
+
package: manifest.package,
|
|
77
|
+
changes: [
|
|
78
|
+
'Update package.json',
|
|
79
|
+
...(manifest.install.schemaImports && manifest.install.schemaImports.length > 0
|
|
80
|
+
? ['Update schema imports']
|
|
81
|
+
: []),
|
|
82
|
+
...(manifest.install.schemaImportsPg &&
|
|
83
|
+
manifest.install.schemaImportsPg.length > 0
|
|
84
|
+
? ['Update PostgreSQL schema imports']
|
|
85
|
+
: []),
|
|
86
|
+
...(manifest.install.dbReExports && manifest.install.dbReExports.length > 0
|
|
87
|
+
? ['Update DB re-exports']
|
|
88
|
+
: []),
|
|
89
|
+
...(manifest.install.schemaTables ? ['Update schema tables'] : []),
|
|
90
|
+
...(manifest.install.schemaTablesPg ? ['Update PostgreSQL schema tables'] : []),
|
|
91
|
+
...(manifest.install.pages && Object.keys(manifest.install.pages).length > 0
|
|
92
|
+
? ['Create plugin pages']
|
|
93
|
+
: []),
|
|
94
|
+
'Register plugin',
|
|
95
|
+
...(manifest.install.env &&
|
|
96
|
+
Object.keys(manifest.install.env).length > 0 &&
|
|
97
|
+
env_source !== 'process'
|
|
98
|
+
? [`Update ${ENV_FILE_NAME}`]
|
|
99
|
+
: []),
|
|
100
|
+
],
|
|
101
|
+
}, null, 2),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
60
106
|
patchPackageJson(root, manifest.name, manifest.package, pluginDir, 'add');
|
|
61
107
|
steps.push('package.json updated');
|
|
62
108
|
if (manifest.install.schemaImports && manifest.install.schemaImports.length > 0) {
|
|
@@ -64,6 +110,11 @@ export function registerPluginTools(server) {
|
|
|
64
110
|
patchSchemaImports(root, manifest.name, imports, 'add');
|
|
65
111
|
steps.push(`Schema imports: ${imports.join(', ')}`);
|
|
66
112
|
}
|
|
113
|
+
if (manifest.install.schemaImportsPg && manifest.install.schemaImportsPg.length > 0) {
|
|
114
|
+
const imports = manifest.install.schemaImportsPg;
|
|
115
|
+
patchSchemaImportsPg(root, manifest.name, imports, 'add');
|
|
116
|
+
steps.push(`PostgreSQL schema imports: ${imports.join(', ')}`);
|
|
117
|
+
}
|
|
67
118
|
if (manifest.install.dbReExports && manifest.install.dbReExports.length > 0) {
|
|
68
119
|
const reExports = manifest.install.dbReExports;
|
|
69
120
|
patchDbReExports(root, manifest.name, reExports, 'add');
|
|
@@ -73,6 +124,10 @@ export function registerPluginTools(server) {
|
|
|
73
124
|
patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'add');
|
|
74
125
|
steps.push('Schema tables added');
|
|
75
126
|
}
|
|
127
|
+
if (manifest.install.schemaTablesPg) {
|
|
128
|
+
patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'add');
|
|
129
|
+
steps.push('PostgreSQL schema tables added');
|
|
130
|
+
}
|
|
76
131
|
if ((manifest.install.transpilePackages?.length ?? 0) > 0 ||
|
|
77
132
|
(manifest.install.serverExternalPackages?.length ?? 0) > 0) {
|
|
78
133
|
patchNextConfig(root, manifest.name, manifest, 'add');
|
|
@@ -82,7 +137,9 @@ export function registerPluginTools(server) {
|
|
|
82
137
|
if (manifest.install.pages && Object.keys(manifest.install.pages).length > 0) {
|
|
83
138
|
const conflicts = findPageConflicts(root, manifest.install.pages);
|
|
84
139
|
backedUp = conflicts.filter((c) => !c.isStub).map((c) => c.conflictRel);
|
|
85
|
-
patchPages(root, manifest.name, manifest.install.pages, 'add', {
|
|
140
|
+
patchPages(root, manifest.name, manifest.install.pages, 'add', {
|
|
141
|
+
onConflict: 'backup',
|
|
142
|
+
});
|
|
86
143
|
steps.push(`${Object.keys(manifest.install.pages).length} page(s) created`);
|
|
87
144
|
if (backedUp.length > 0) {
|
|
88
145
|
steps.push(`Backed up ${backedUp.length} existing page file(s) as *.codapult-bak-${manifest.name}`);
|
|
@@ -110,7 +167,9 @@ export function registerPluginTools(server) {
|
|
|
110
167
|
'Run: pnpm db:push (if schema changed)',
|
|
111
168
|
],
|
|
112
169
|
};
|
|
113
|
-
return {
|
|
170
|
+
return {
|
|
171
|
+
content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
|
|
172
|
+
};
|
|
114
173
|
});
|
|
115
174
|
server.registerTool('codapult_plugins_remove', {
|
|
116
175
|
title: 'Remove Plugin',
|
|
@@ -118,8 +177,12 @@ export function registerPluginTools(server) {
|
|
|
118
177
|
inputSchema: {
|
|
119
178
|
name: z.string().describe('Plugin name to remove'),
|
|
120
179
|
env_source: envSourceSchema.optional(),
|
|
180
|
+
dry_run: z
|
|
181
|
+
.boolean()
|
|
182
|
+
.default(false)
|
|
183
|
+
.describe('Preview changes without modifying the project'),
|
|
121
184
|
},
|
|
122
|
-
}, ({ name, env_source }) => {
|
|
185
|
+
}, ({ name, env_source, dry_run }) => {
|
|
123
186
|
const root = getRoot();
|
|
124
187
|
const result = resolveManifest(root, name);
|
|
125
188
|
const manifest = result?.manifest ?? {
|
|
@@ -131,6 +194,26 @@ export function registerPluginTools(server) {
|
|
|
131
194
|
};
|
|
132
195
|
const pluginDir = result?.pluginDir ?? '';
|
|
133
196
|
const steps = [];
|
|
197
|
+
if (dry_run) {
|
|
198
|
+
return {
|
|
199
|
+
content: [
|
|
200
|
+
{
|
|
201
|
+
type: 'text',
|
|
202
|
+
text: JSON.stringify({
|
|
203
|
+
dryRun: true,
|
|
204
|
+
plugin: manifest.name,
|
|
205
|
+
changes: [
|
|
206
|
+
'Remove plugin pages',
|
|
207
|
+
'Unregister plugin',
|
|
208
|
+
'Remove schema changes',
|
|
209
|
+
'Update package.json',
|
|
210
|
+
...(env_source !== 'process' ? [`Update ${ENV_FILE_NAME}`] : []),
|
|
211
|
+
],
|
|
212
|
+
}, null, 2),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
134
217
|
if (manifest.install.pages && Object.keys(manifest.install.pages).length > 0) {
|
|
135
218
|
patchPages(root, manifest.name, manifest.install.pages, 'remove');
|
|
136
219
|
steps.push('Pages removed');
|
|
@@ -141,10 +224,18 @@ export function registerPluginTools(server) {
|
|
|
141
224
|
patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'remove');
|
|
142
225
|
steps.push('Schema tables removed');
|
|
143
226
|
}
|
|
227
|
+
if (manifest.install.schemaTablesPg) {
|
|
228
|
+
patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'remove');
|
|
229
|
+
steps.push('PostgreSQL schema tables removed');
|
|
230
|
+
}
|
|
144
231
|
if (manifest.install.schemaImports && manifest.install.schemaImports.length > 0) {
|
|
145
232
|
patchSchemaImports(root, manifest.name, manifest.install.schemaImports, 'remove');
|
|
146
233
|
steps.push('Schema imports removed');
|
|
147
234
|
}
|
|
235
|
+
if (manifest.install.schemaImportsPg && manifest.install.schemaImportsPg.length > 0) {
|
|
236
|
+
patchSchemaImportsPg(root, manifest.name, manifest.install.schemaImportsPg, 'remove');
|
|
237
|
+
steps.push('PostgreSQL schema imports removed');
|
|
238
|
+
}
|
|
148
239
|
if (manifest.install.dbReExports && manifest.install.dbReExports.length > 0) {
|
|
149
240
|
patchDbReExports(root, manifest.name, manifest.install.dbReExports, 'remove');
|
|
150
241
|
steps.push('DB re-exports removed');
|
|
@@ -167,7 +258,10 @@ export function registerPluginTools(server) {
|
|
|
167
258
|
steps.push('Dependency removed');
|
|
168
259
|
return {
|
|
169
260
|
content: [
|
|
170
|
-
{
|
|
261
|
+
{
|
|
262
|
+
type: 'text',
|
|
263
|
+
text: JSON.stringify({ plugin: name, steps }, null, 2),
|
|
264
|
+
},
|
|
171
265
|
],
|
|
172
266
|
};
|
|
173
267
|
});
|
|
@@ -193,25 +287,41 @@ export function registerPluginTools(server) {
|
|
|
193
287
|
.map((f) => f.replace('.ts', ''))
|
|
194
288
|
: [];
|
|
195
289
|
if (pluginNames.length === 0) {
|
|
196
|
-
return {
|
|
290
|
+
return {
|
|
291
|
+
content: [{ type: 'text', text: 'No installed plugins found.' }],
|
|
292
|
+
};
|
|
197
293
|
}
|
|
198
294
|
const results = [];
|
|
199
295
|
for (const pName of pluginNames) {
|
|
200
296
|
const res = resolveManifest(root, pName);
|
|
201
297
|
if (!res) {
|
|
202
|
-
results.push({
|
|
298
|
+
results.push({
|
|
299
|
+
plugin: pName,
|
|
300
|
+
updated: false,
|
|
301
|
+
error: 'manifest not found',
|
|
302
|
+
});
|
|
203
303
|
continue;
|
|
204
304
|
}
|
|
205
305
|
const { manifest, pluginDir } = res;
|
|
206
|
-
if (!manifest.install.schemaTables) {
|
|
306
|
+
if (!manifest.install.schemaTables && !manifest.install.schemaTablesPg) {
|
|
207
307
|
results.push({ plugin: pName, updated: false });
|
|
208
308
|
continue;
|
|
209
309
|
}
|
|
210
|
-
const
|
|
310
|
+
const updatedSqlite = manifest.install.schemaTables
|
|
311
|
+
? patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'update')
|
|
312
|
+
: false;
|
|
313
|
+
const updatedPostgres = manifest.install.schemaTablesPg
|
|
314
|
+
? patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'update')
|
|
315
|
+
: false;
|
|
316
|
+
const updated = updatedSqlite || updatedPostgres;
|
|
211
317
|
const imports = manifest.install.schemaImports;
|
|
212
318
|
if (updated && imports && imports.length > 0) {
|
|
213
319
|
patchSchemaImports(root, manifest.name, imports, 'add');
|
|
214
320
|
}
|
|
321
|
+
const importsPg = manifest.install.schemaImportsPg;
|
|
322
|
+
if (updated && importsPg && importsPg.length > 0) {
|
|
323
|
+
patchSchemaImportsPg(root, manifest.name, importsPg, 'add');
|
|
324
|
+
}
|
|
215
325
|
results.push({ plugin: pName, updated });
|
|
216
326
|
}
|
|
217
327
|
const anyUpdated = results.some((r) => r.updated);
|
|
@@ -226,6 +336,8 @@ export function registerPluginTools(server) {
|
|
|
226
336
|
]
|
|
227
337
|
: [],
|
|
228
338
|
};
|
|
229
|
-
return {
|
|
339
|
+
return {
|
|
340
|
+
content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
|
|
341
|
+
};
|
|
230
342
|
});
|
|
231
343
|
}
|
|
@@ -3,9 +3,12 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { findProjectRoot, readProjectFile } from '../../utils/project.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getProjectEnvOptions, loadProjectEnv } from '../../utils/project-env.js';
|
|
7
7
|
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, } from '../../utils/env-config.js';
|
|
8
8
|
import { envSourceSchema } from './schemas.js';
|
|
9
|
+
import { commandResponse, runProjectCommand } from '../../utils/command.js';
|
|
10
|
+
import { collectMcpHealth } from '../../utils/health.js';
|
|
11
|
+
import { collectAppConfigSummary } from '../../utils/config-report.js';
|
|
9
12
|
function getRoot() {
|
|
10
13
|
const root = findProjectRoot();
|
|
11
14
|
if (!root)
|
|
@@ -90,14 +93,10 @@ export function registerProjectTools(server) {
|
|
|
90
93
|
if (!cmd)
|
|
91
94
|
continue;
|
|
92
95
|
try {
|
|
93
|
-
|
|
94
|
-
results[check] = { passed: true, output: output.slice(-2000) };
|
|
96
|
+
results[check] = runProjectCommand(cmd, root);
|
|
95
97
|
}
|
|
96
|
-
catch
|
|
97
|
-
|
|
98
|
-
err.stdout?.toString() ??
|
|
99
|
-
'Check failed';
|
|
100
|
-
results[check] = { passed: false, output: output.slice(-2000) };
|
|
98
|
+
catch {
|
|
99
|
+
results[check] = runProjectCommand(cmd, root);
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
return { content: [{ type: 'text', text: JSON.stringify(results, null, 2) }] };
|
|
@@ -110,43 +109,57 @@ export function registerProjectTools(server) {
|
|
|
110
109
|
},
|
|
111
110
|
}, ({ env_source }) => {
|
|
112
111
|
const root = getRoot();
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
const report = collectMcpHealth(root, {
|
|
113
|
+
envSource: env_source,
|
|
114
|
+
});
|
|
115
|
+
return { content: [{ type: 'text', text: JSON.stringify(report, null, 2) }] };
|
|
116
|
+
});
|
|
117
|
+
server.registerTool('codapult_project_context', {
|
|
118
|
+
title: 'Project Context',
|
|
119
|
+
description: 'Get a compact, structured overview of the current Codapult project for AI-assisted work',
|
|
120
|
+
inputSchema: {},
|
|
121
|
+
}, () => {
|
|
122
|
+
const root = getRoot();
|
|
123
|
+
const packageJson = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
|
|
124
|
+
const files = ['AGENTS.md', '.env.example', 'src/config/app.ts', 'src/config/env.ts'];
|
|
125
|
+
const existingFiles = files.filter((file) => existsSync(resolve(root, file)));
|
|
126
|
+
const envContent = loadProjectEnv(root).content;
|
|
127
|
+
const adapters = getAdapters(envContent);
|
|
128
|
+
const features = getFeatures(envContent);
|
|
129
|
+
const configDir = resolve(root, 'src/config');
|
|
130
|
+
const configFiles = existsSync(configDir)
|
|
131
|
+
? readdirSync(configDir)
|
|
132
|
+
.filter((file) => file.endsWith('.ts') && !file.endsWith('.test.ts'))
|
|
133
|
+
.sort()
|
|
134
|
+
: [];
|
|
135
|
+
const scripts = (packageJson.scripts ?? {});
|
|
136
|
+
const dependencies = {
|
|
137
|
+
...(packageJson.dependencies ?? {}),
|
|
138
|
+
...(packageJson.devDependencies ?? {}),
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: 'text',
|
|
144
|
+
text: JSON.stringify({
|
|
145
|
+
root,
|
|
146
|
+
name: packageJson.name,
|
|
147
|
+
version: packageJson.version,
|
|
148
|
+
scripts,
|
|
149
|
+
dependencies,
|
|
150
|
+
existingFiles,
|
|
151
|
+
configFiles,
|
|
152
|
+
adapters,
|
|
153
|
+
enabledFeatures: Object.keys(features).filter((key) => features[key]),
|
|
154
|
+
appConfig: collectAppConfigSummary(root),
|
|
155
|
+
}, null, 2),
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
151
159
|
});
|
|
160
|
+
server.registerTool('codapult_build', {
|
|
161
|
+
title: 'Build Project',
|
|
162
|
+
description: 'Run the production build and return structured stdout, stderr, and exit code',
|
|
163
|
+
inputSchema: {},
|
|
164
|
+
}, () => commandResponse(runProjectCommand('pnpm build', getRoot(), { timeout: 300_000 })));
|
|
152
165
|
}
|
|
@@ -5,6 +5,7 @@ vi.mock('node:child_process');
|
|
|
5
5
|
vi.mock('../../utils/project.js', () => ({
|
|
6
6
|
findProjectRoot: vi.fn(),
|
|
7
7
|
readProjectFile: vi.fn(),
|
|
8
|
+
readJsonFile: vi.fn(),
|
|
8
9
|
}));
|
|
9
10
|
vi.mock('../../utils/project-env.js', () => ({
|
|
10
11
|
ENV_FILE_NAME: '.env.local',
|
|
@@ -14,7 +15,7 @@ vi.mock('../../utils/project-env.js', () => ({
|
|
|
14
15
|
}));
|
|
15
16
|
const { existsSync, readFileSync, readdirSync } = await import('node:fs');
|
|
16
17
|
const { execSync } = await import('node:child_process');
|
|
17
|
-
const { findProjectRoot, readProjectFile } = await import('../../utils/project.js');
|
|
18
|
+
const { findProjectRoot, readProjectFile, readJsonFile } = await import('../../utils/project.js');
|
|
18
19
|
const { loadProjectEnv } = await import('../../utils/project-env.js');
|
|
19
20
|
const { registerProjectTools } = await import('./project.js');
|
|
20
21
|
const mockedFindRoot = vi.mocked(findProjectRoot);
|
|
@@ -23,6 +24,7 @@ const mockedLoadProjectEnv = vi.mocked(loadProjectEnv);
|
|
|
23
24
|
const mockedExists = vi.mocked(existsSync);
|
|
24
25
|
const mockedRead = vi.mocked(readFileSync);
|
|
25
26
|
const mockedReaddir = vi.mocked(readdirSync);
|
|
27
|
+
const mockedReadJson = vi.mocked(readJsonFile);
|
|
26
28
|
const mockedExec = vi.mocked(execSync);
|
|
27
29
|
beforeEach(() => {
|
|
28
30
|
vi.resetAllMocks();
|
|
@@ -33,6 +35,8 @@ beforeEach(() => {
|
|
|
33
35
|
fileExists: false,
|
|
34
36
|
content: '',
|
|
35
37
|
});
|
|
38
|
+
mockedReaddir.mockReturnValue([]);
|
|
39
|
+
mockedReadJson.mockReturnValue({ name: 'codapult', version: '1.0.0' });
|
|
36
40
|
});
|
|
37
41
|
function createMockServer() {
|
|
38
42
|
const tools = [];
|
|
@@ -42,15 +46,17 @@ function createMockServer() {
|
|
|
42
46
|
return { registerTool, tools };
|
|
43
47
|
}
|
|
44
48
|
describe('registerProjectTools', () => {
|
|
45
|
-
it('registers
|
|
49
|
+
it('registers project inspection and execution tools', () => {
|
|
46
50
|
const server = createMockServer();
|
|
47
51
|
registerProjectTools(server);
|
|
48
|
-
expect(server.tools).toHaveLength(
|
|
52
|
+
expect(server.tools).toHaveLength(6);
|
|
49
53
|
const names = server.tools.map((t) => t.name);
|
|
50
54
|
expect(names).toContain('codapult_project_status');
|
|
51
55
|
expect(names).toContain('codapult_project_config');
|
|
52
56
|
expect(names).toContain('codapult_run_checks');
|
|
53
57
|
expect(names).toContain('codapult_doctor');
|
|
58
|
+
expect(names).toContain('codapult_project_context');
|
|
59
|
+
expect(names).toContain('codapult_build');
|
|
54
60
|
});
|
|
55
61
|
describe('codapult_project_status', () => {
|
|
56
62
|
it('returns project info with adapters and plugins', () => {
|
|
@@ -143,9 +149,9 @@ describe('registerProjectTools', () => {
|
|
|
143
149
|
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
144
150
|
const result = handler({});
|
|
145
151
|
const parsed = JSON.parse(result.content[0].text);
|
|
146
|
-
const pkgCheck = parsed.find((c) => c.
|
|
152
|
+
const pkgCheck = parsed.checks.find((c) => c.id === 'package');
|
|
147
153
|
expect(pkgCheck?.status).toBe('ok');
|
|
148
|
-
const tsCheck = parsed.find((c) => c.
|
|
154
|
+
const tsCheck = parsed.checks.find((c) => c.id === 'typecheck');
|
|
149
155
|
expect(tsCheck?.status).toBe('ok');
|
|
150
156
|
});
|
|
151
157
|
it('reports missing files', () => {
|
|
@@ -158,7 +164,7 @@ describe('registerProjectTools', () => {
|
|
|
158
164
|
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
159
165
|
const result = handler({});
|
|
160
166
|
const parsed = JSON.parse(result.content[0].text);
|
|
161
|
-
const failedChecks = parsed.filter((c) => c.status === 'fail');
|
|
167
|
+
const failedChecks = parsed.checks.filter((c) => c.status === 'fail');
|
|
162
168
|
expect(failedChecks.length).toBeGreaterThan(0);
|
|
163
169
|
});
|
|
164
170
|
it('reports process env source when requested', () => {
|
|
@@ -166,11 +172,17 @@ describe('registerProjectTools', () => {
|
|
|
166
172
|
registerProjectTools(server);
|
|
167
173
|
mockedExists.mockReturnValue(true);
|
|
168
174
|
mockedExec.mockReturnValue(Buffer.from(''));
|
|
175
|
+
mockedLoadProjectEnv.mockReturnValue({
|
|
176
|
+
source: 'process',
|
|
177
|
+
filePath: `/project/${ENV_FILE_NAME}`,
|
|
178
|
+
fileExists: false,
|
|
179
|
+
content: '',
|
|
180
|
+
});
|
|
169
181
|
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
170
182
|
const result = handler({ env_source: 'process' });
|
|
171
183
|
const parsed = JSON.parse(result.content[0].text);
|
|
172
|
-
const envCheck = parsed.find((c) => c.
|
|
173
|
-
expect(envCheck?.
|
|
184
|
+
const envCheck = parsed.checks.find((c) => c.id === 'env-file');
|
|
185
|
+
expect(envCheck?.message).toBe('Using process.env');
|
|
174
186
|
});
|
|
175
187
|
});
|
|
176
188
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type CheckStatus = 'ok' | 'warn' | 'fail';
|
|
2
|
+
export interface ReportCheck {
|
|
3
|
+
id: string;
|
|
4
|
+
status: CheckStatus;
|
|
5
|
+
message: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface StructuredReport {
|
|
9
|
+
status: CheckStatus;
|
|
10
|
+
checks: ReportCheck[];
|
|
11
|
+
summary: {
|
|
12
|
+
ok: number;
|
|
13
|
+
warnings: number;
|
|
14
|
+
failures: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare function summarizeChecks(checks: ReportCheck[]): StructuredReport;
|
|
18
|
+
export declare function renderStructuredReport(title: string, report: StructuredReport): void;
|