@codapult/cli 0.19.1 → 0.19.2

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.
@@ -1,4 +1,4 @@
1
- import { execSync, spawnSync } from 'node:child_process';
1
+ import { execFileSync, spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
4
  import { checkProjectRoot } from '../utils/project.js';
@@ -50,7 +50,7 @@ export async function deployVercelCommand(options = {}) {
50
50
  // 4. Build check
51
51
  info('Running build check...');
52
52
  try {
53
- execSync('pnpm build', { cwd: root, stdio: 'pipe' });
53
+ execFileSync('pnpm', ['build'], { cwd: root, stdio: 'pipe' });
54
54
  success('Build passed');
55
55
  }
56
56
  catch {
@@ -66,7 +66,7 @@ export async function deployVercelCommand(options = {}) {
66
66
  }
67
67
  info('Deploying...');
68
68
  try {
69
- execSync('vercel --prod', { cwd: root, stdio: 'inherit' });
69
+ execFileSync('vercel', ['--prod'], { cwd: root, stdio: 'inherit' });
70
70
  success('Deployed to Vercel');
71
71
  }
72
72
  catch {
@@ -113,7 +113,10 @@ export async function deployDockerCommand(opts = {}) {
113
113
  // 5. Build
114
114
  info('Building Docker image...');
115
115
  try {
116
- execSync(`docker build -t ${imageName} .`, { cwd: root, stdio: 'inherit' });
116
+ execFileSync('docker', ['build', '-t', imageName, '.'], {
117
+ cwd: root,
118
+ stdio: 'inherit',
119
+ });
117
120
  success(`Image built: ${imageName}`);
118
121
  }
119
122
  catch {
@@ -134,7 +137,7 @@ export async function deployDockerCommand(opts = {}) {
134
137
  info('Starting container...');
135
138
  dim(`docker run -p 3000:3000 --env-file ${ENV_FILE_NAME} ${imageName}`);
136
139
  try {
137
- execSync(`docker run -p 3000:3000 --env-file ${ENV_FILE_NAME} ${imageName}`, {
140
+ execFileSync('docker', ['run', '-p', '3000:3000', '--env-file', ENV_FILE_NAME, imageName], {
138
141
  cwd: root,
139
142
  stdio: 'inherit',
140
143
  });
@@ -1,4 +1,4 @@
1
- import { execSync, spawnSync } from 'node:child_process';
1
+ import { execFileSync, spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
4
  import { checkProjectRoot } from '../utils/project.js';
@@ -7,10 +7,9 @@ import { resolveManifest } from '../utils/manifest.js';
7
7
  import { clonePlugin } from '../utils/git.js';
8
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
- function execQuiet(cmd, cwd) {
10
+ function execQuiet(args, cwd) {
11
11
  try {
12
- execSync(cmd, { cwd, stdio: 'pipe' });
13
- return true;
12
+ return spawnSync('pnpm', args, { cwd, stdio: 'pipe' }).status === 0;
14
13
  }
15
14
  catch {
16
15
  return false;
@@ -165,7 +164,7 @@ export async function pluginsAddCommand(name, options = {}) {
165
164
  }
166
165
  // 10. pnpm install
167
166
  info('Installing dependencies...');
168
- if (!execQuiet('pnpm install --no-frozen-lockfile', root)) {
167
+ if (!execQuiet(['install', '--no-frozen-lockfile'], root)) {
169
168
  warn('pnpm install failed — run manually: pnpm install --no-frozen-lockfile');
170
169
  }
171
170
  else {
@@ -181,7 +180,7 @@ export async function pluginsAddCommand(name, options = {}) {
181
180
  // 11. pnpm db:push
182
181
  if (manifest.install.schemaTables) {
183
182
  info('Applying database schema...');
184
- if (!execQuiet('pnpm db:push', root)) {
183
+ if (!execQuiet(['db:push'], root)) {
185
184
  warn('db:push failed — run manually: pnpm db:push');
186
185
  }
187
186
  else {
@@ -197,9 +196,13 @@ export async function pluginsAddCommand(name, options = {}) {
197
196
  }
198
197
  const installOptional = await confirm('Install optional dependencies?', false);
199
198
  if (installOptional) {
200
- const pkgs = Object.keys(manifest.install.optionalDeps).join(' ');
201
- execQuiet(`pnpm add ${pkgs}`, root);
202
- success('Optional dependencies installed');
199
+ const pkgs = Object.keys(manifest.install.optionalDeps);
200
+ if (execQuiet(['add', ...pkgs], root)) {
201
+ success('Optional dependencies installed');
202
+ }
203
+ else {
204
+ warn('Optional dependency installation failed');
205
+ }
203
206
  }
204
207
  }
205
208
  heading('Done!');
@@ -297,7 +300,7 @@ export async function pluginsRemoveCommand(name, options = {}) {
297
300
  success('Dependency removed');
298
301
  // 10. pnpm install
299
302
  info('Updating dependencies...');
300
- execQuiet('pnpm install --no-frozen-lockfile', root);
303
+ execQuiet(['install', '--no-frozen-lockfile'], root);
301
304
  success('Dependencies updated');
302
305
  heading('Done!');
303
306
  success(`Plugin "${name}" removed.`);
@@ -371,7 +374,7 @@ export async function pluginsMigrateCommand(name, options) {
371
374
  console.log();
372
375
  if (options.push) {
373
376
  info('Applying schema changes (db:push)...');
374
- if (!execQuiet('pnpm db:push', root)) {
377
+ if (!execQuiet(['db:push'], root)) {
375
378
  fail('db:push failed — run manually: pnpm db:push');
376
379
  process.exit(1);
377
380
  }
@@ -380,7 +383,7 @@ export async function pluginsMigrateCommand(name, options) {
380
383
  else {
381
384
  info('Generating migration...');
382
385
  try {
383
- execSync('pnpm db:generate', { cwd: root, stdio: 'inherit' });
386
+ execFileSync('pnpm', ['db:generate'], { cwd: root, stdio: 'inherit' });
384
387
  success('Migration generated');
385
388
  }
386
389
  catch {
@@ -391,7 +394,7 @@ export async function pluginsMigrateCommand(name, options) {
391
394
  const apply = await confirm('Apply the migration now (pnpm db:migrate)?');
392
395
  if (apply) {
393
396
  try {
394
- execSync('pnpm db:migrate', { cwd: root, stdio: 'inherit' });
397
+ execFileSync('pnpm', ['db:migrate'], { cwd: root, stdio: 'inherit' });
395
398
  success('Migration applied');
396
399
  }
397
400
  catch {
@@ -1,45 +1,52 @@
1
- import { execSync } from 'node:child_process';
1
+ import { execFileSync } from 'node:child_process';
2
2
  import { checkProjectRoot } from '../utils/project.js';
3
3
  import { heading, success, fail, warn, info, dim, confirm, label } from '../utils/ui.js';
4
4
  const UPSTREAM_REMOTE = 'codapult-upstream';
5
5
  const UPSTREAM_URL = 'https://github.com/codapult/codapult.git';
6
- function exec(cmd, cwd, silent = false) {
6
+ function runGit(args, cwd, silent = false) {
7
7
  const stdio = silent ? 'pipe' : 'inherit';
8
- const result = execSync(cmd, { cwd, encoding: 'utf-8', stdio });
8
+ const result = execFileSync('git', args, { cwd, encoding: 'utf-8', stdio });
9
9
  return typeof result === 'string' ? result : '';
10
10
  }
11
- function execQuiet(cmd, cwd) {
11
+ function execQuiet(args, cwd) {
12
12
  try {
13
- return execSync(cmd, { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim();
13
+ return runGit(args, cwd, true).trim();
14
14
  }
15
15
  catch {
16
16
  return '';
17
17
  }
18
18
  }
19
+ function isSafeGitRef(value) {
20
+ return (/^[A-Za-z0-9._/@-]+$/.test(value) &&
21
+ !value.startsWith('-') &&
22
+ !value.endsWith('.') &&
23
+ !value.includes('..') &&
24
+ !value.includes('@{'));
25
+ }
19
26
  function hasUncommittedChanges(cwd) {
20
- const status = execQuiet('git status --porcelain', cwd);
27
+ const status = execQuiet(['status', '--porcelain'], cwd);
21
28
  return status.length > 0;
22
29
  }
23
30
  function ensureUpstreamRemote(cwd) {
24
- const remotes = execQuiet('git remote', cwd);
31
+ const remotes = execQuiet(['remote'], cwd);
25
32
  if (!remotes.split('\n').includes(UPSTREAM_REMOTE)) {
26
33
  info(`Adding upstream remote "${UPSTREAM_REMOTE}"...`);
27
- execQuiet(`git remote add ${UPSTREAM_REMOTE} ${UPSTREAM_URL}`, cwd);
34
+ runGit(['remote', 'add', UPSTREAM_REMOTE, UPSTREAM_URL], cwd, true);
28
35
  success(`Remote "${UPSTREAM_REMOTE}" added`);
29
36
  }
30
37
  }
31
38
  function fetchUpstream(cwd) {
32
39
  info('Fetching upstream releases...');
33
- execQuiet(`git fetch ${UPSTREAM_REMOTE} --tags`, cwd);
40
+ execQuiet(['fetch', UPSTREAM_REMOTE, '--tags'], cwd);
34
41
  }
35
42
  function getAvailableTags(cwd) {
36
- const raw = execQuiet(`git tag -l "v*" --sort=-v:refname`, cwd);
43
+ const raw = execQuiet(['tag', '-l', 'v*', '--sort=-v:refname'], cwd);
37
44
  if (!raw)
38
45
  return [];
39
46
  return raw.split('\n').filter(Boolean);
40
47
  }
41
48
  function getCurrentVersion(cwd) {
42
- const tag = execQuiet('git describe --tags --abbrev=0 2>/dev/null', cwd);
49
+ const tag = execQuiet(['describe', '--tags', '--abbrev=0'], cwd);
43
50
  return tag || '(no version tag)';
44
51
  }
45
52
  const SAFE_ZONE_PATTERNS = [
@@ -52,7 +59,7 @@ const SAFE_ZONE_PATTERNS = [
52
59
  '.env',
53
60
  ];
54
61
  function classifyConflicts(cwd) {
55
- const raw = execQuiet('git diff --name-only --diff-filter=U', cwd);
62
+ const raw = execQuiet(['diff', '--name-only', '--diff-filter=U'], cwd);
56
63
  if (!raw)
57
64
  return { safe: [], caution: [], core: [] };
58
65
  const files = raw.split('\n').filter(Boolean);
@@ -106,12 +113,22 @@ export async function updateCommand(version, options) {
106
113
  fail('No target version found. Run with --list to see available versions.');
107
114
  process.exit(1);
108
115
  }
116
+ if (!isSafeGitRef(target)) {
117
+ fail(`Invalid version or Git ref: ${target}`);
118
+ process.exit(1);
119
+ }
109
120
  label('Target version', target);
110
121
  console.log();
111
122
  if (options.dryRun) {
112
123
  info('Dry run — showing changes without applying:');
113
124
  console.log();
114
- exec(`git log --oneline ${current}..${UPSTREAM_REMOTE}/${target} 2>/dev/null || git log --oneline ..${target} 2>/dev/null`, root);
125
+ const currentRef = isSafeGitRef(current) ? current : 'HEAD';
126
+ try {
127
+ runGit(['log', '--oneline', `${currentRef}..${UPSTREAM_REMOTE}/${target}`], root);
128
+ }
129
+ catch {
130
+ runGit(['log', '--oneline', `..${target}`], root);
131
+ }
115
132
  console.log();
116
133
  dim('Run without --dry-run to apply the update.');
117
134
  return;
@@ -124,7 +141,7 @@ export async function updateCommand(version, options) {
124
141
  info(`Merging ${target}...`);
125
142
  console.log();
126
143
  try {
127
- exec(`git merge ${target} --no-edit`, root);
144
+ runGit(['merge', target, '--no-edit'], root);
128
145
  success('Update merged successfully!');
129
146
  }
130
147
  catch {
@@ -1,7 +1,48 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
2
  import { resolve, join, isAbsolute, relative } from 'node:path';
3
+ import { z } from 'zod';
3
4
  import { getCacheDir } from './git.js';
4
5
  const MANIFEST_FILENAME = 'codapult-plugin.json';
6
+ const nonEmptyString = z.string().trim().min(1);
7
+ const packageName = z.string().regex(/^@?[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)?$/);
8
+ const relativePluginPath = nonEmptyString.refine((value) => !isAbsolute(value) && !value.split(/[\\/]+/).includes('..'), 'Plugin paths must stay inside the plugin directory');
9
+ const pluginManifestSchema = z.object({
10
+ name: z.string().regex(/^[a-z][a-z0-9-]*$/),
11
+ package: packageName,
12
+ version: nonEmptyString,
13
+ description: z.string(),
14
+ install: z
15
+ .object({
16
+ schemaImports: z.array(nonEmptyString).optional(),
17
+ schemaImportsPg: z.array(nonEmptyString).optional(),
18
+ dbReExports: z.array(nonEmptyString).optional(),
19
+ schemaTables: relativePluginPath.optional(),
20
+ schemaTablesPg: relativePluginPath.optional(),
21
+ transpilePackages: z.array(packageName).optional(),
22
+ serverExternalPackages: z.array(packageName).optional(),
23
+ shadcnComponents: z.array(z.string().regex(/^[a-z][a-z0-9-]*$/)).optional(),
24
+ // Keys are project-relative page paths; values are package import specifiers.
25
+ pages: z.record(nonEmptyString, nonEmptyString).optional(),
26
+ env: z
27
+ .record(z.string().regex(/^[A-Z][A-Z0-9_]*$/), z.object({
28
+ default: z.string().optional(),
29
+ required: z.boolean(),
30
+ description: z.string().optional(),
31
+ }))
32
+ .optional(),
33
+ optionalDeps: z.record(packageName, z.string()).optional(),
34
+ })
35
+ .default({}),
36
+ });
37
+ function realPathOrOriginal(path) {
38
+ try {
39
+ const resolved = realpathSync(path);
40
+ return typeof resolved === 'string' ? resolved : path;
41
+ }
42
+ catch {
43
+ return path;
44
+ }
45
+ }
5
46
  /**
6
47
  * Verifies the resolved directory stays within expected boundaries
7
48
  * (sibling of projectRoot or inside .codapult/plugins/).
@@ -9,8 +50,11 @@ const MANIFEST_FILENAME = 'codapult-plugin.json';
9
50
  function isWithinAllowedScope(dir, projectRoot) {
10
51
  const parentDir = resolve(projectRoot, '..');
11
52
  const cacheDir = getCacheDir(projectRoot);
12
- const relToParent = relative(parentDir, dir);
13
- const relToCache = relative(cacheDir, dir);
53
+ const resolvedDir = existsSync(dir) ? realPathOrOriginal(dir) : dir;
54
+ const resolvedParent = existsSync(parentDir) ? realPathOrOriginal(parentDir) : parentDir;
55
+ const resolvedCache = existsSync(cacheDir) ? realPathOrOriginal(cacheDir) : cacheDir;
56
+ const relToParent = relative(resolvedParent, resolvedDir);
57
+ const relToCache = relative(resolvedCache, resolvedDir);
14
58
  const isUnderParent = !relToParent.startsWith('..') && !isAbsolute(relToParent);
15
59
  const isUnderCache = !relToCache.startsWith('..') && !isAbsolute(relToCache);
16
60
  return isUnderParent || isUnderCache;
@@ -38,8 +82,10 @@ export function resolveManifest(projectRoot, nameOrPath) {
38
82
  if (existsSync(manifestPath)) {
39
83
  try {
40
84
  const content = readFileSync(manifestPath, 'utf-8');
41
- const manifest = JSON.parse(content);
42
- return { manifest, pluginDir: dir };
85
+ const parsed = pluginManifestSchema.safeParse(JSON.parse(content));
86
+ if (parsed.success) {
87
+ return { manifest: parsed.data, pluginDir: dir };
88
+ }
43
89
  }
44
90
  catch {
45
91
  // Invalid JSON
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codapult/cli",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "Open-source CLI and MCP server for Codapult SaaS projects, with architecture guardrails for AI-assisted development",
5
5
  "license": "MIT",
6
6
  "packageManager": "pnpm@11.22.0+sha512.1ff870c4c6133dfd88fb2afc46dd13d47f09c9794b438c6fdb47ca98caf3bc16381ee0be93a091b8e3824cf01f889f46d7d9e20910fb0be1ab0fb5baa80dd621",
@@ -52,28 +52,28 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
+ "@codapult/guard": "^0.3.0",
55
56
  "@modelcontextprotocol/sdk": "^1.30.0",
56
- "@codapult/guard": "^0.1.0",
57
57
  "commander": "^15.0.0",
58
58
  "picocolors": "^1.1.1",
59
59
  "typescript": "npm:@typescript/typescript6@^6.0.2",
60
- "zod": "^4.4.3"
60
+ "zod": "^4.6.5"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@js-toolkit/config-utils": "^1.0.1",
64
- "@js-toolkit/eslint-config": "^1.1.4",
64
+ "@js-toolkit/eslint-config": "^1.3.2",
65
65
  "@js-toolkit/prettier-config": "^1.0.1",
66
66
  "@js-toolkit/tsconfig": "^1.0.1",
67
- "@release-it/conventional-changelog": "^12.0.0",
68
- "@types/node": "^26.2.0",
67
+ "@release-it/conventional-changelog": "^12.0.2",
68
+ "@types/node": "^26.6.2",
69
69
  "@typescript/native": "npm:typescript@^7.0.2",
70
- "@vitest/coverage-v8": "^4.1.11",
71
- "eslint": "^9.39.4",
70
+ "@vitest/coverage-v8": "^5.0.1",
71
+ "eslint": "^10.11.0",
72
72
  "eslint-config-prettier": "^10.1.8",
73
73
  "eslint-plugin-prettier": "^5.5.6",
74
- "prettier": "^3.9.6",
75
- "release-it": "^21.0.2",
76
- "typescript-eslint": "^8.67.0",
77
- "vitest": "^4.1.11"
74
+ "prettier": "^3.9.8",
75
+ "release-it": "^21.1.0",
76
+ "typescript-eslint": "^8.70.1",
77
+ "vitest": "^5.0.1"
78
78
  }
79
79
  }