@codapult/cli 0.15.3 → 0.16.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 +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
package/dist/commands/doctor.js
CHANGED
|
@@ -1,241 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
6
|
-
import { resolveManifest } from '../utils/manifest.js';
|
|
7
|
-
import { findPageConflicts, findPageBackups } from '../utils/patchers.js';
|
|
8
|
-
import { findProviderIssues, getAdapters, readEnvVar } from '../utils/env-config.js';
|
|
9
|
-
import { heading, success, fail, warn, info, dim, label } from '../utils/ui.js';
|
|
10
|
-
function checkExists(root, path, description) {
|
|
11
|
-
const exists = existsSync(resolve(root, path));
|
|
12
|
-
if (exists) {
|
|
13
|
-
success(description);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
fail(`${description} — missing: ${path}`);
|
|
17
|
-
}
|
|
18
|
-
return exists;
|
|
19
|
-
}
|
|
20
|
-
function tryExec(cmd, cwd) {
|
|
21
|
-
try {
|
|
22
|
-
return execSync(cmd, { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim();
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import { findProjectRoot } from '../utils/project.js';
|
|
2
|
+
import { collectProjectHealth } from '../utils/health.js';
|
|
3
|
+
import { fail } from '../utils/ui.js';
|
|
4
|
+
import { healthExitCode, renderHealthReport } from '../utils/health-render.js';
|
|
28
5
|
export function doctorCommand(options = {}) {
|
|
29
6
|
const root = findProjectRoot();
|
|
30
7
|
if (!root) {
|
|
31
8
|
fail('Not inside a Codapult project.');
|
|
32
9
|
process.exit(1);
|
|
33
10
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// --- Project structure ---
|
|
40
|
-
info('Project structure');
|
|
41
|
-
if (!checkExists(root, 'package.json', 'package.json'))
|
|
42
|
-
issues += 1;
|
|
43
|
-
if (!checkExists(root, 'src/config/app.ts', 'App config (src/config/app.ts)'))
|
|
44
|
-
issues += 1;
|
|
45
|
-
if (!checkExists(root, 'src/lib/db/schema.ts', 'Database schema'))
|
|
46
|
-
issues += 1;
|
|
47
|
-
if (!checkExists(root, 'src/lib/auth/index.ts', 'Auth adapter'))
|
|
48
|
-
issues += 1;
|
|
49
|
-
if (!checkExists(root, 'src/lib/payments/index.ts', 'Payments adapter'))
|
|
50
|
-
issues += 1;
|
|
51
|
-
if (!checkExists(root, 'next.config.ts', 'Next.js config'))
|
|
52
|
-
issues += 1;
|
|
53
|
-
if (!checkExists(root, 'codapult.plugins.ts', 'Plugin registry'))
|
|
54
|
-
warnings += 1;
|
|
55
|
-
console.log();
|
|
56
|
-
// --- Environment ---
|
|
57
|
-
info('Environment');
|
|
58
|
-
const env = loadProjectEnv(root, options);
|
|
59
|
-
if (env.source === 'file' && !env.fileExists) {
|
|
60
|
-
fail(`${ENV_FILE_NAME} not found — run \`codapult setup\``);
|
|
61
|
-
issues += 1;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
if (env.source === 'process') {
|
|
65
|
-
success('Using process.env (project configured with --no-env-file)');
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
success(`${ENV_FILE_NAME} exists`);
|
|
69
|
-
}
|
|
70
|
-
const envContent = env.content;
|
|
71
|
-
const adapters = getAdapters(envContent);
|
|
72
|
-
label(' DB_PROVIDER', adapters.database);
|
|
73
|
-
label(' AUTH_PROVIDER', adapters.auth);
|
|
74
|
-
label(' PAYMENT_PROVIDER', adapters.payments);
|
|
75
|
-
label(' STORAGE_PROVIDER', adapters.storage);
|
|
76
|
-
label(' JOB_PROVIDER', adapters.jobs);
|
|
77
|
-
label(' NOTIFICATION_TRANSPORT', adapters.notifications);
|
|
78
|
-
const providerIssues = findProviderIssues(envContent);
|
|
79
|
-
if (providerIssues.length === 0) {
|
|
80
|
-
success('All provider-conditional env vars are set');
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
for (const i of providerIssues) {
|
|
84
|
-
if (i.severity === 'error') {
|
|
85
|
-
fail(`${i.key}: ${i.message}`);
|
|
86
|
-
issues += 1;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
warn(`${i.key}: ${i.message}`);
|
|
90
|
-
warnings += 1;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (!readEnvVar(envContent, 'NEXT_PUBLIC_APP_URL')) {
|
|
95
|
-
warn('NEXT_PUBLIC_APP_URL not set — defaults to http://localhost:3000');
|
|
96
|
-
warnings += 1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
console.log();
|
|
100
|
-
// --- Dependencies ---
|
|
101
|
-
info('Dependencies');
|
|
102
|
-
const nodeVersion = tryExec('node --version', root);
|
|
103
|
-
if (nodeVersion) {
|
|
104
|
-
const major = parseInt(nodeVersion.replace('v', ''), 10);
|
|
105
|
-
if (major >= 20) {
|
|
106
|
-
success(`Node.js ${nodeVersion}`);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
fail(`Node.js ${nodeVersion} — requires v20+`);
|
|
110
|
-
issues += 1;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
fail('Node.js not found');
|
|
115
|
-
issues += 1;
|
|
116
|
-
}
|
|
117
|
-
const pnpmVersion = tryExec('pnpm --version', root);
|
|
118
|
-
if (pnpmVersion) {
|
|
119
|
-
success(`pnpm ${pnpmVersion}`);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
fail('pnpm not found — install: npm i -g pnpm');
|
|
123
|
-
issues += 1;
|
|
124
|
-
}
|
|
125
|
-
const nodeModulesExist = existsSync(resolve(root, 'node_modules'));
|
|
126
|
-
if (nodeModulesExist) {
|
|
127
|
-
success('node_modules installed');
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
fail('node_modules missing — run: pnpm install');
|
|
131
|
-
issues += 1;
|
|
132
|
-
}
|
|
133
|
-
console.log();
|
|
134
|
-
// --- TypeScript ---
|
|
135
|
-
info('TypeScript');
|
|
136
|
-
const tscResult = tryExec('npx tsc --noEmit 2>&1 | tail -1', root);
|
|
137
|
-
if (tscResult == null || tscResult.includes('error')) {
|
|
138
|
-
warn('TypeScript has errors — run: pnpm type-check');
|
|
139
|
-
warnings += 1;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
success('TypeScript compiles cleanly');
|
|
143
|
-
}
|
|
144
|
-
console.log();
|
|
145
|
-
// --- Plugins ---
|
|
146
|
-
info('Plugins');
|
|
147
|
-
const pluginsDir = resolve(root, 'src/plugins');
|
|
148
|
-
const installedPlugins = existsSync(pluginsDir)
|
|
149
|
-
? readdirSync(pluginsDir)
|
|
150
|
-
.filter((f) => f.endsWith('.ts') && f !== 'index.ts')
|
|
151
|
-
.map((f) => f.replace('.ts', ''))
|
|
152
|
-
: [];
|
|
153
|
-
if (installedPlugins.length === 0) {
|
|
154
|
-
dim('No plugins installed.');
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
let pluginProblems = 0;
|
|
158
|
-
for (const pName of installedPlugins) {
|
|
159
|
-
const resolved = resolveManifest(root, pName);
|
|
160
|
-
if (!resolved?.manifest.install.pages)
|
|
161
|
-
continue;
|
|
162
|
-
const conflicts = findPageConflicts(root, resolved.manifest.install.pages).filter((c) => !c.isStub);
|
|
163
|
-
if (conflicts.length === 0)
|
|
164
|
-
continue;
|
|
165
|
-
pluginProblems += 1;
|
|
166
|
-
warn(`${pName}: ${conflicts.length} page conflict(s) shadow plugin stubs`);
|
|
167
|
-
for (const c of conflicts) {
|
|
168
|
-
dim(` ${c.conflictRel} (shadows ${c.pagePath})`);
|
|
169
|
-
}
|
|
170
|
-
dim(` Fix: codapult plugins add ${pName} (will back up and overwrite)`);
|
|
171
|
-
}
|
|
172
|
-
if (pluginProblems === 0) {
|
|
173
|
-
success(`${installedPlugins.length} plugin(s): no page conflicts`);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
issues += pluginProblems;
|
|
177
|
-
}
|
|
178
|
-
const orphanBackups = findPageBackups(root);
|
|
179
|
-
if (orphanBackups.length > 0) {
|
|
180
|
-
warn(`${orphanBackups.length} page backup file(s) found:`);
|
|
181
|
-
for (const b of orphanBackups)
|
|
182
|
-
dim(` ${b}`);
|
|
183
|
-
dim(' These are restored automatically when the owning plugin is removed.');
|
|
184
|
-
warnings += 1;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
console.log();
|
|
188
|
-
// --- Git ---
|
|
189
|
-
info('Git');
|
|
190
|
-
const gitRemotes = tryExec('git remote -v', root);
|
|
191
|
-
if (gitRemotes?.includes('codapult-upstream')) {
|
|
192
|
-
success('Upstream remote configured');
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
dim('No upstream remote — run `codapult update` to set up');
|
|
196
|
-
}
|
|
197
|
-
const gitStatus = tryExec('git status --porcelain', root);
|
|
198
|
-
if (gitStatus === '') {
|
|
199
|
-
success('Working tree clean');
|
|
200
|
-
}
|
|
201
|
-
else if (gitStatus != null) {
|
|
202
|
-
const lines = gitStatus.split('\n').filter(Boolean);
|
|
203
|
-
warn(`${lines.length} uncommitted change(s)`);
|
|
204
|
-
}
|
|
205
|
-
console.log();
|
|
206
|
-
// --- Package versions ---
|
|
207
|
-
info('Key packages');
|
|
208
|
-
const pkg = readJsonFile(resolve(root, 'package.json'));
|
|
209
|
-
if (pkg) {
|
|
210
|
-
const deps = {
|
|
211
|
-
...pkg.dependencies,
|
|
212
|
-
...pkg.devDependencies,
|
|
213
|
-
};
|
|
214
|
-
const keyPackages = [
|
|
215
|
-
'next',
|
|
216
|
-
'react',
|
|
217
|
-
'typescript',
|
|
218
|
-
'drizzle-orm',
|
|
219
|
-
'tailwindcss',
|
|
220
|
-
'better-auth',
|
|
221
|
-
];
|
|
222
|
-
for (const name of keyPackages) {
|
|
223
|
-
if (deps[name]) {
|
|
224
|
-
dim(` ${name}: ${deps[name]}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
console.log();
|
|
229
|
-
// --- Summary ---
|
|
230
|
-
heading('Summary');
|
|
231
|
-
if (issues === 0 && warnings === 0) {
|
|
232
|
-
success('Everything looks good!');
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
if (issues > 0)
|
|
236
|
-
fail(`${issues} issue(s) found`);
|
|
237
|
-
if (warnings > 0)
|
|
238
|
-
warn(`${warnings} warning(s)`);
|
|
239
|
-
}
|
|
240
|
-
console.log();
|
|
11
|
+
const report = collectProjectHealth(root, {
|
|
12
|
+
envSource: options.envFile === false ? 'process' : 'file',
|
|
13
|
+
});
|
|
14
|
+
renderHealthReport('Codapult Doctor', report);
|
|
15
|
+
process.exitCode = healthExitCode(report);
|
|
241
16
|
}
|
package/dist/commands/env.js
CHANGED
|
@@ -3,6 +3,7 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { findProjectRoot } from '../utils/project.js';
|
|
4
4
|
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
|
|
5
5
|
import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
|
|
6
|
+
import { renderStructuredReport, summarizeChecks } from '../utils/check-report.js';
|
|
6
7
|
function parseEnvFile(content) {
|
|
7
8
|
const entries = [];
|
|
8
9
|
let lastComment = '';
|
|
@@ -37,7 +38,6 @@ export function envCheckCommand(options = {}) {
|
|
|
37
38
|
fail('Not inside a Codapult project.');
|
|
38
39
|
process.exit(1);
|
|
39
40
|
}
|
|
40
|
-
heading('Environment Check');
|
|
41
41
|
const examplePath = resolve(root, ENV_EXAMPLE_FILE_NAME);
|
|
42
42
|
const localPath = resolve(root, ENV_FILE_NAME);
|
|
43
43
|
if (!existsSync(examplePath)) {
|
|
@@ -54,22 +54,33 @@ export function envCheckCommand(options = {}) {
|
|
|
54
54
|
const localEntries = parseEnvFile(localContent);
|
|
55
55
|
const localKeys = new Set(localEntries.map((e) => e.key));
|
|
56
56
|
const requiredKeys = exampleEntries.filter((e) => e.required);
|
|
57
|
-
|
|
58
|
-
let empty = 0;
|
|
57
|
+
const checks = [];
|
|
59
58
|
for (const entry of requiredKeys) {
|
|
60
59
|
if (!localKeys.has(entry.key)) {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
checks.push({
|
|
61
|
+
id: entry.key,
|
|
62
|
+
status: 'fail',
|
|
63
|
+
message: `Missing: ${entry.key}${entry.comment ? ` — ${entry.comment}` : ''}`,
|
|
64
|
+
});
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
67
|
const local = localEntries.find((e) => e.key === entry.key);
|
|
66
68
|
if (local && (!local.value || local.value === entry.value)) {
|
|
67
69
|
const isPlaceholder = /^(your-|generate-|https?:\/\/your|""?)/.test(local.value);
|
|
68
70
|
if (isPlaceholder || !local.value) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
checks.push({
|
|
72
|
+
id: entry.key,
|
|
73
|
+
status: 'warn',
|
|
74
|
+
message: `Not configured: ${entry.key}${entry.comment ? ` — ${entry.comment}` : ''}`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
checks.push({ id: entry.key, status: 'ok', message: `${entry.key} configured` });
|
|
71
79
|
}
|
|
72
80
|
}
|
|
81
|
+
else {
|
|
82
|
+
checks.push({ id: entry.key, status: 'ok', message: `${entry.key} configured` });
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
const extra = localEntries.filter((e) => !exampleEntries.some((ex) => ex.key === e.key));
|
|
@@ -81,16 +92,9 @@ export function envCheckCommand(options = {}) {
|
|
|
81
92
|
dim(` ${e.key}`);
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
if (missing > 0)
|
|
90
|
-
fail(`${missing} missing variable(s)`);
|
|
91
|
-
if (empty > 0)
|
|
92
|
-
warn(`${empty} variable(s) need configuration`);
|
|
93
|
-
}
|
|
95
|
+
const report = summarizeChecks(checks);
|
|
96
|
+
renderStructuredReport('Environment Check', report);
|
|
97
|
+
process.exitCode = report.summary.failures > 0 ? 1 : 0;
|
|
94
98
|
console.log();
|
|
95
99
|
}
|
|
96
100
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
+
import { collectMcpHealth } from '../utils/health.js';
|
|
6
|
+
import { checkEnvSchemaCompatibility } from '../utils/env-compatibility.js';
|
|
7
|
+
import { heading, success, fail, info, dim } from '../utils/ui.js';
|
|
8
|
+
import { healthExitCode, renderHealthReport } from '../utils/health-render.js';
|
|
9
|
+
const PACKAGE_NAME = '@codapult/cli';
|
|
10
|
+
const DEFAULT_VERSION = 'latest';
|
|
11
|
+
function getConfigPath(root) {
|
|
12
|
+
return resolve(root, '.cursor/mcp.json');
|
|
13
|
+
}
|
|
14
|
+
function resolveVersion(version) {
|
|
15
|
+
if (version)
|
|
16
|
+
return version;
|
|
17
|
+
try {
|
|
18
|
+
return execFileSync('npm', ['view', `${PACKAGE_NAME}@latest`, 'version'], {
|
|
19
|
+
stdio: 'pipe',
|
|
20
|
+
timeout: 30_000,
|
|
21
|
+
})
|
|
22
|
+
.toString()
|
|
23
|
+
.trim();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return DEFAULT_VERSION;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function mcpUpdateCommand(version, options = {}) {
|
|
30
|
+
const root = findProjectRoot();
|
|
31
|
+
if (!root) {
|
|
32
|
+
fail('Not inside a Codapult project.');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const configPath = getConfigPath(root);
|
|
36
|
+
const targetVersion = resolveVersion(version);
|
|
37
|
+
const packageSpec = `${PACKAGE_NAME}@${targetVersion}`;
|
|
38
|
+
const current = existsSync(configPath)
|
|
39
|
+
? JSON.parse(readFileSync(configPath, 'utf-8'))
|
|
40
|
+
: {};
|
|
41
|
+
const next = {
|
|
42
|
+
...current,
|
|
43
|
+
mcpServers: {
|
|
44
|
+
...(current.mcpServers ?? {}),
|
|
45
|
+
codapult: {
|
|
46
|
+
command: 'npx',
|
|
47
|
+
args: ['-y', packageSpec, 'mcp-server'],
|
|
48
|
+
cwd: '.',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
heading('MCP Update');
|
|
53
|
+
info(`Target: ${packageSpec}`);
|
|
54
|
+
if (options.dryRun) {
|
|
55
|
+
dim(`Would update ${configPath}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
mkdirSync(resolve(root, '.cursor'), { recursive: true });
|
|
59
|
+
writeFileSync(configPath, `${JSON.stringify(next, null, 2)}\n`, 'utf-8');
|
|
60
|
+
success(`Updated ${configPath}`);
|
|
61
|
+
dim('Restart or reload the MCP connection in your editor to use the new version.');
|
|
62
|
+
}
|
|
63
|
+
export function mcpDoctorCommand() {
|
|
64
|
+
const root = findProjectRoot();
|
|
65
|
+
if (!root) {
|
|
66
|
+
fail('Not inside a Codapult project.');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const report = collectMcpHealth(root);
|
|
70
|
+
renderHealthReport('MCP Doctor', report);
|
|
71
|
+
process.exitCode = healthExitCode(report);
|
|
72
|
+
}
|
|
73
|
+
export function mcpContractCheckCommand() {
|
|
74
|
+
const root = findProjectRoot();
|
|
75
|
+
if (!root) {
|
|
76
|
+
fail('Not inside a Codapult project.');
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const result = checkEnvSchemaCompatibility(root);
|
|
81
|
+
heading('MCP Contract Check');
|
|
82
|
+
if (result.status === 'ok') {
|
|
83
|
+
success(result.message);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
fail(result.message);
|
|
87
|
+
if (result.schemaOnly.length > 0) {
|
|
88
|
+
info('Variables present in env-schema.ts but missing from the CLI contract:');
|
|
89
|
+
for (const key of result.schemaOnly)
|
|
90
|
+
dim(` + ${key}`);
|
|
91
|
+
}
|
|
92
|
+
if (result.mirrorOnly.length > 0) {
|
|
93
|
+
info('Variables present in the CLI contract but missing from env-schema.ts:');
|
|
94
|
+
for (const key of result.mirrorOnly)
|
|
95
|
+
dim(` - ${key}`);
|
|
96
|
+
}
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
}
|
package/dist/commands/plugins.js
CHANGED
|
@@ -5,7 +5,7 @@ import { findProjectRoot } from '../utils/project.js';
|
|
|
5
5
|
import { ENV_FILE_NAME, getProjectEnvSource, } from '../utils/project-env.js';
|
|
6
6
|
import { resolveManifest } from '../utils/manifest.js';
|
|
7
7
|
import { clonePlugin } from '../utils/git.js';
|
|
8
|
-
import { patchSchemaImports, patchSchemaTables, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../utils/patchers.js';
|
|
8
|
+
import { patchSchemaImports, patchSchemaImportsPg, patchSchemaTables, patchSchemaTablesPg, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../utils/patchers.js';
|
|
9
9
|
import { heading, success, fail, warn, info, dim, confirm } from '../utils/ui.js';
|
|
10
10
|
function execQuiet(cmd, cwd) {
|
|
11
11
|
try {
|
|
@@ -66,6 +66,12 @@ export async function pluginsAddCommand(name, options = {}) {
|
|
|
66
66
|
patchSchemaImports(root, manifest.name, imports, 'add');
|
|
67
67
|
success(`Added imports: ${imports.join(', ')}`);
|
|
68
68
|
}
|
|
69
|
+
if (manifest.install.schemaImportsPg && manifest.install.schemaImportsPg.length > 0) {
|
|
70
|
+
const imports = manifest.install.schemaImportsPg;
|
|
71
|
+
info('Adding PostgreSQL schema imports...');
|
|
72
|
+
patchSchemaImportsPg(root, manifest.name, imports, 'add');
|
|
73
|
+
success(`Added PostgreSQL imports: ${imports.join(', ')}`);
|
|
74
|
+
}
|
|
69
75
|
// 3. Re-export tables from db/index.ts
|
|
70
76
|
if (manifest.install.dbReExports && manifest.install.dbReExports.length > 0) {
|
|
71
77
|
const reExports = manifest.install.dbReExports;
|
|
@@ -79,6 +85,11 @@ export async function pluginsAddCommand(name, options = {}) {
|
|
|
79
85
|
patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'add');
|
|
80
86
|
success('Schema tables added');
|
|
81
87
|
}
|
|
88
|
+
if (manifest.install.schemaTablesPg) {
|
|
89
|
+
info('Adding PostgreSQL schema tables...');
|
|
90
|
+
patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'add');
|
|
91
|
+
success('PostgreSQL schema tables added');
|
|
92
|
+
}
|
|
82
93
|
// 5. Patch next.config.ts
|
|
83
94
|
if ((manifest.install.transpilePackages?.length ?? 0) > 0 ||
|
|
84
95
|
(manifest.install.serverExternalPackages?.length ?? 0) > 0) {
|
|
@@ -242,12 +253,22 @@ export async function pluginsRemoveCommand(name, options = {}) {
|
|
|
242
253
|
patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'remove');
|
|
243
254
|
success('Schema tables removed');
|
|
244
255
|
}
|
|
256
|
+
if (manifest.install.schemaTablesPg) {
|
|
257
|
+
info('Removing PostgreSQL schema tables...');
|
|
258
|
+
patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'remove');
|
|
259
|
+
success('PostgreSQL schema tables removed');
|
|
260
|
+
}
|
|
245
261
|
// 4. Remove schema imports
|
|
246
262
|
if (manifest.install.schemaImports && manifest.install.schemaImports.length > 0) {
|
|
247
263
|
info('Removing schema imports...');
|
|
248
264
|
patchSchemaImports(root, manifest.name, manifest.install.schemaImports, 'remove');
|
|
249
265
|
success('Schema imports removed');
|
|
250
266
|
}
|
|
267
|
+
if (manifest.install.schemaImportsPg && manifest.install.schemaImportsPg.length > 0) {
|
|
268
|
+
info('Removing PostgreSQL schema imports...');
|
|
269
|
+
patchSchemaImportsPg(root, manifest.name, manifest.install.schemaImportsPg, 'remove');
|
|
270
|
+
success('PostgreSQL schema imports removed');
|
|
271
|
+
}
|
|
251
272
|
// 5. Remove DB re-exports
|
|
252
273
|
if (manifest.install.dbReExports && manifest.install.dbReExports.length > 0) {
|
|
253
274
|
info('Removing DB re-exports...');
|
|
@@ -323,22 +344,36 @@ export async function pluginsMigrateCommand(name, options) {
|
|
|
323
344
|
continue;
|
|
324
345
|
}
|
|
325
346
|
const { manifest, pluginDir } = result;
|
|
326
|
-
if (!manifest.install.schemaTables) {
|
|
347
|
+
if (!manifest.install.schemaTables && !manifest.install.schemaTablesPg) {
|
|
327
348
|
dim(`${manifest.name}: no schema tables — skipping.`);
|
|
328
349
|
continue;
|
|
329
350
|
}
|
|
330
|
-
|
|
351
|
+
let updated = false;
|
|
352
|
+
if (manifest.install.schemaTables) {
|
|
353
|
+
const sqliteUpdated = patchSchemaTables(root, manifest.name, pluginDir, manifest.install.schemaTables, 'update');
|
|
354
|
+
if (sqliteUpdated)
|
|
355
|
+
success(`${manifest.name}: schema updated in schema.ts`);
|
|
356
|
+
updated ||= sqliteUpdated;
|
|
357
|
+
}
|
|
358
|
+
if (manifest.install.schemaTablesPg) {
|
|
359
|
+
const postgresUpdated = patchSchemaTablesPg(root, manifest.name, pluginDir, manifest.install.schemaTablesPg, 'update');
|
|
360
|
+
if (postgresUpdated)
|
|
361
|
+
success(`${manifest.name}: schema updated in schema-pg.ts`);
|
|
362
|
+
updated ||= postgresUpdated;
|
|
363
|
+
}
|
|
331
364
|
if (updated) {
|
|
332
|
-
success(`${manifest.name}: schema updated in schema.ts`);
|
|
333
365
|
schemaUpdated = true;
|
|
334
366
|
}
|
|
335
367
|
else {
|
|
336
|
-
dim(`${manifest.name}:
|
|
368
|
+
dim(`${manifest.name}: schemas are already up to date.`);
|
|
337
369
|
}
|
|
338
370
|
// Also refresh imports in case the plugin added new drizzle column types
|
|
339
371
|
if (manifest.install.schemaImports && manifest.install.schemaImports.length > 0) {
|
|
340
372
|
patchSchemaImports(root, manifest.name, manifest.install.schemaImports, 'add');
|
|
341
373
|
}
|
|
374
|
+
if (manifest.install.schemaImportsPg && manifest.install.schemaImportsPg.length > 0) {
|
|
375
|
+
patchSchemaImportsPg(root, manifest.name, manifest.install.schemaImportsPg, 'add');
|
|
376
|
+
}
|
|
342
377
|
}
|
|
343
378
|
if (!schemaUpdated) {
|
|
344
379
|
console.log();
|
package/dist/commands/setup.js
CHANGED
|
@@ -547,8 +547,8 @@ function generateMcpConfig(root) {
|
|
|
547
547
|
const config = {
|
|
548
548
|
mcpServers: {
|
|
549
549
|
codapult: {
|
|
550
|
-
command: '
|
|
551
|
-
args: ['
|
|
550
|
+
command: 'npx',
|
|
551
|
+
args: ['-y', '@codapult/cli@latest', 'mcp-server'],
|
|
552
552
|
cwd: '.',
|
|
553
553
|
},
|
|
554
554
|
},
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,9 @@ import { doctorCommand } from './commands/doctor.js';
|
|
|
7
7
|
import { configShowCommand } from './commands/config-show.js';
|
|
8
8
|
import { pluginsAddCommand, pluginsRemoveCommand, pluginsListCommand, pluginsMigrateCommand, } from './commands/plugins.js';
|
|
9
9
|
import { generatePageCommand, generateApiCommand, generateActionCommand, generatePluginCommand, } from './commands/generate.js';
|
|
10
|
-
import { dbPushCommand, dbGenerateCommand, dbSeedCommand, dbStudioCommand, dbStatusCommand, } from './commands/db.js';
|
|
10
|
+
import { dbPushCommand, dbGenerateCommand, dbSeedCommand, dbStudioCommand, dbStatusCommand, dbLiveDiffCommand, dbSchemaDiffCommand, } from './commands/db.js';
|
|
11
11
|
import { envCheckCommand, envSyncCommand } from './commands/env.js';
|
|
12
|
+
import { mcpContractCheckCommand, mcpDoctorCommand, mcpUpdateCommand } from './commands/mcp.js';
|
|
12
13
|
import { deployVercelCommand, deployDockerCommand, deployStatusCommand, } from './commands/deploy.js';
|
|
13
14
|
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from './utils/project-env.js';
|
|
14
15
|
const program = new Command()
|
|
@@ -20,9 +21,7 @@ const program = new Command()
|
|
|
20
21
|
styleCommandText: (str) => pc.yellow(str),
|
|
21
22
|
styleOptionText: (str) => pc.green(str),
|
|
22
23
|
})
|
|
23
|
-
.hook('postAction', () =>
|
|
24
|
-
process.exit(0);
|
|
25
|
-
});
|
|
24
|
+
.hook('postAction', () => undefined);
|
|
26
25
|
function withNoEnvFileOption(command) {
|
|
27
26
|
return command.option('--no-env-file', `read env vars from process.env instead of ${ENV_FILE_NAME}`);
|
|
28
27
|
}
|
|
@@ -84,6 +83,10 @@ withNoEnvFileOption(db.command('generate').description('generate migration files
|
|
|
84
83
|
withNoEnvFileOption(db.command('seed').description('seed sample data')).action(dbSeedCommand);
|
|
85
84
|
withNoEnvFileOption(db.command('studio').description('open Drizzle Studio')).action(dbStudioCommand);
|
|
86
85
|
withNoEnvFileOption(db.command('status').description('show schema info and migration count')).action(dbStatusCommand);
|
|
86
|
+
withNoEnvFileOption(db.command('live-diff').description('read-only compare schema with the live database')).action(dbLiveDiffCommand);
|
|
87
|
+
db.command('schema-diff')
|
|
88
|
+
.description('compare SQLite and PostgreSQL schema files')
|
|
89
|
+
.action(dbSchemaDiffCommand);
|
|
87
90
|
const env = program.command('env').description('environment variable management');
|
|
88
91
|
withNoEnvFileOption(env.command('check').description(`validate env vars against ${ENV_EXAMPLE_FILE_NAME}`)).action(envCheckCommand);
|
|
89
92
|
withNoEnvFileOption(env.command('sync').description(`add missing variables from ${ENV_EXAMPLE_FILE_NAME}`)).action(envSyncCommand);
|
|
@@ -94,8 +97,24 @@ withNoEnvFileOption(deploy
|
|
|
94
97
|
.description('build Docker image')
|
|
95
98
|
.option('-t, --tag <tag>', 'image tag', 'latest')).action(deployDockerCommand);
|
|
96
99
|
withNoEnvFileOption(deploy.command('status').description('check deploy readiness')).action(deployStatusCommand);
|
|
97
|
-
program
|
|
100
|
+
const mcp = program
|
|
98
101
|
.commandsGroup('AI Integration')
|
|
102
|
+
.command('mcp')
|
|
103
|
+
.description('manage the project MCP configuration');
|
|
104
|
+
mcp
|
|
105
|
+
.command('update [version]')
|
|
106
|
+
.description('pin the Codapult MCP server to a version (defaults to the latest npm version)')
|
|
107
|
+
.option('--dry-run', 'show the update without writing .cursor/mcp.json')
|
|
108
|
+
.action(mcpUpdateCommand);
|
|
109
|
+
mcp
|
|
110
|
+
.command('doctor')
|
|
111
|
+
.description('check project health for MCP-assisted work')
|
|
112
|
+
.action(mcpDoctorCommand);
|
|
113
|
+
mcp
|
|
114
|
+
.command('contract-check')
|
|
115
|
+
.description('verify env-schema.ts matches the CLI MCP compatibility contract')
|
|
116
|
+
.action(mcpContractCheckCommand);
|
|
117
|
+
program
|
|
99
118
|
.command('mcp-server')
|
|
100
119
|
.description('start MCP server for AI assistant integration (Cursor, Claude, Codex)')
|
|
101
120
|
.action(async () => {
|
package/dist/mcp/resources.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
1
3
|
import { findProjectRoot, readProjectFile } from '../utils/project.js';
|
|
2
|
-
import { ENV_EXAMPLE_FILE_NAME } from '../utils/project-env.js';
|
|
4
|
+
import { ENV_EXAMPLE_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
|
|
5
|
+
import { getAdapters } from '../utils/env-config.js';
|
|
3
6
|
function getRoot() {
|
|
4
7
|
const root = findProjectRoot();
|
|
5
8
|
if (!root)
|
|
6
9
|
throw new Error('Not inside a Codapult project');
|
|
7
10
|
return root;
|
|
8
11
|
}
|
|
12
|
+
function getSchemaPath(root) {
|
|
13
|
+
const provider = getAdapters(loadProjectEnv(root).content).database;
|
|
14
|
+
return provider === 'postgres' ? 'src/lib/db/schema-pg.ts' : 'src/lib/db/schema.ts';
|
|
15
|
+
}
|
|
9
16
|
export function registerResources(server) {
|
|
10
17
|
server.registerResource('codapult_schema', 'codapult://schema', {
|
|
11
18
|
title: 'Database Schema',
|
|
12
|
-
description: 'Drizzle ORM schema
|
|
19
|
+
description: 'Active Drizzle ORM schema selected by DB_PROVIDER — all tables, columns, types, and relations',
|
|
13
20
|
mimeType: 'text/plain',
|
|
14
21
|
}, () => {
|
|
15
|
-
const
|
|
22
|
+
const root = getRoot();
|
|
23
|
+
const content = readProjectFile(root, getSchemaPath(root)) ?? 'Schema file not found';
|
|
16
24
|
return { contents: [{ uri: 'codapult://schema', text: content, mimeType: 'text/plain' }] };
|
|
17
25
|
});
|
|
18
26
|
server.registerResource('codapult_app_config', 'codapult://config/app', {
|
|
@@ -73,4 +81,27 @@ export function registerResources(server) {
|
|
|
73
81
|
contents: [{ uri: 'codapult://config/navigation', text: content, mimeType: 'text/plain' }],
|
|
74
82
|
};
|
|
75
83
|
});
|
|
84
|
+
server.registerResource('codapult_config_files', 'codapult://config/files', {
|
|
85
|
+
title: 'Configuration Files',
|
|
86
|
+
description: 'All non-test TypeScript configuration files from src/config, including marketing and navigation configuration',
|
|
87
|
+
mimeType: 'application/json',
|
|
88
|
+
}, () => {
|
|
89
|
+
const root = getRoot();
|
|
90
|
+
const configDir = resolve(root, 'src/config');
|
|
91
|
+
const files = existsSync(configDir)
|
|
92
|
+
? readdirSync(configDir)
|
|
93
|
+
.filter((file) => file.endsWith('.ts') && !file.endsWith('.test.ts'))
|
|
94
|
+
.sort()
|
|
95
|
+
: [];
|
|
96
|
+
const contents = Object.fromEntries(files.map((file) => [file, readProjectFile(root, `src/config/${file}`) ?? '']));
|
|
97
|
+
return {
|
|
98
|
+
contents: [
|
|
99
|
+
{
|
|
100
|
+
uri: 'codapult://config/files',
|
|
101
|
+
text: JSON.stringify({ files, contents }, null, 2),
|
|
102
|
+
mimeType: 'application/json',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
});
|
|
76
107
|
}
|