@codapult/cli 0.17.2 → 0.19.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.
Files changed (63) hide show
  1. package/README.md +94 -7
  2. package/dist/commands/config-show.js +6 -9
  3. package/dist/commands/db.js +10 -36
  4. package/dist/commands/deploy.js +8 -19
  5. package/dist/commands/doctor.js +2 -7
  6. package/dist/commands/env.js +3 -11
  7. package/dist/commands/generate.js +5 -21
  8. package/dist/commands/guard.d.ts +5 -0
  9. package/dist/commands/guard.js +5 -0
  10. package/dist/commands/mcp.js +5 -16
  11. package/dist/commands/plugins.js +5 -21
  12. package/dist/commands/setup.js +2 -6
  13. package/dist/commands/update.js +2 -6
  14. package/dist/index.js +111 -5
  15. package/dist/mcp/resources.js +15 -15
  16. package/dist/mcp/server.js +6 -0
  17. package/dist/mcp/tools/db.js +11 -16
  18. package/dist/mcp/tools/deploy.js +2 -8
  19. package/dist/mcp/tools/env.js +6 -12
  20. package/dist/mcp/tools/generate.js +10 -15
  21. package/dist/mcp/tools/plugins.js +5 -11
  22. package/dist/mcp/tools/project.js +9 -30
  23. package/dist/utils/command.d.ts +3 -0
  24. package/dist/utils/command.js +35 -4
  25. package/dist/utils/config.d.ts +5 -0
  26. package/dist/utils/config.js +5 -0
  27. package/dist/utils/project-checks.d.ts +2 -0
  28. package/dist/utils/project-checks.js +2 -0
  29. package/dist/utils/project.d.ts +1 -0
  30. package/dist/utils/project.js +16 -0
  31. package/package.json +16 -5
  32. package/dist/commands/generate.test.d.ts +0 -1
  33. package/dist/commands/generate.test.js +0 -125
  34. package/dist/mcp/tools/db.test.d.ts +0 -1
  35. package/dist/mcp/tools/db.test.js +0 -221
  36. package/dist/mcp/tools/env.test.d.ts +0 -1
  37. package/dist/mcp/tools/env.test.js +0 -156
  38. package/dist/mcp/tools/project.test.d.ts +0 -1
  39. package/dist/mcp/tools/project.test.js +0 -188
  40. package/dist/utils/config-report.test.d.ts +0 -1
  41. package/dist/utils/config-report.test.js +0 -18
  42. package/dist/utils/env-compatibility.test.d.ts +0 -1
  43. package/dist/utils/env-compatibility.test.js +0 -23
  44. package/dist/utils/env-schema-parser.test.d.ts +0 -1
  45. package/dist/utils/env-schema-parser.test.js +0 -11
  46. package/dist/utils/git.test.d.ts +0 -1
  47. package/dist/utils/git.test.js +0 -77
  48. package/dist/utils/health-render.test.d.ts +0 -1
  49. package/dist/utils/health-render.test.js +0 -18
  50. package/dist/utils/live-db-diff.test.d.ts +0 -1
  51. package/dist/utils/live-db-diff.test.js +0 -29
  52. package/dist/utils/manifest.test.d.ts +0 -1
  53. package/dist/utils/manifest.test.js +0 -107
  54. package/dist/utils/patchers.test.d.ts +0 -1
  55. package/dist/utils/patchers.test.js +0 -647
  56. package/dist/utils/project-env.test.d.ts +0 -1
  57. package/dist/utils/project-env.test.js +0 -47
  58. package/dist/utils/project.test.d.ts +0 -1
  59. package/dist/utils/project.test.js +0 -123
  60. package/dist/utils/schema-parity.test.d.ts +0 -1
  61. package/dist/utils/schema-parity.test.js +0 -27
  62. package/dist/utils/schema-parser.test.d.ts +0 -1
  63. package/dist/utils/schema-parser.test.js +0 -59
package/README.md CHANGED
@@ -1,6 +1,26 @@
1
1
  # @codapult/cli
2
2
 
3
- CLI tool for managing [Codapult](https://codapult.dev) SaaS projects.
3
+ [![CI](https://github.com/codapult/codapult-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/codapult/codapult-cli/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@codapult/cli?logo=npm)](https://www.npmjs.com/package/@codapult/cli)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+ [![Node.js >=20.19](https://img.shields.io/badge/node-%3E%3D20.19-339933.svg?logo=node.js&logoColor=white)](package.json)
7
+
8
+ CLI tool for managing [Codapult](https://codapult.dev) SaaS projects, with the universal
9
+ `@codapult/guard` architecture guard built in for AI-assisted development.
10
+
11
+ `@codapult/cli` is the open-source Codapult integration layer: a CLI and MCP server for
12
+ Codapult-based SaaS projects. It combines project setup, updates, plugins, database and
13
+ deployment tooling with the standalone Guard engine.
14
+
15
+ For a non-Codapult JavaScript or TypeScript project, install
16
+ [`@codapult/guard`](https://github.com/codapult/codapult-guard) directly. The CLI does not make
17
+ Guard universal by adding Codapult assumptions to it; it connects the Codapult-specific tools to
18
+ the same published Guard package through a thin adapter.
19
+
20
+ | Package | Use it when |
21
+ | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
22
+ | [`@codapult/guard`](https://github.com/codapult/codapult-guard) | You need architecture guardrails, project memory, MCP, and AI-agent verification in any JS/TS project. |
23
+ | `@codapult/cli` | You are building a Codapult SaaS and also need setup, plugins, database, environment, and deployment workflows. |
4
24
 
5
25
  ## Installation
6
26
 
@@ -16,7 +36,15 @@ Or run directly with npx:
16
36
  npx @codapult/cli <command>
17
37
  ```
18
38
 
19
- The command reference below uses the installed `codapult` binary. Project users who do not install the CLI globally should prefix commands with `npx @codapult/cli`, for example `npx @codapult/cli db schema-diff`.
39
+ The command reference below uses the installed `codapult` binary. For reproducible project and CI
40
+ usage, install and pin it as a dev dependency:
41
+
42
+ ```shell
43
+ pnpm add -D @codapult/cli
44
+ ```
45
+
46
+ Project users who do not install the CLI globally should prefix commands with `npx @codapult/cli`,
47
+ for example `npx @codapult/cli db schema-diff`.
20
48
 
21
49
  ## Commands
22
50
 
@@ -62,6 +90,41 @@ The command reference below uses the installed `codapult` binary. Project users
62
90
  - `codapult deploy docker` — build Docker image
63
91
  - `codapult deploy status` — check deploy readiness
64
92
 
93
+ ### Architecture Guard
94
+
95
+ Codapult CLI includes the standalone [`@codapult/guard`](https://github.com/codapult/codapult-guard)
96
+ engine and keeps the `codapult guard ...` command surface as a Codapult-friendly entrypoint.
97
+ Guard is responsible for project architecture memory, approved contracts, baselines, changed-file
98
+ regressions, impact context, and AI-agent review packets. It does not replace ESLint, TypeScript,
99
+ tests, SAST, or a general PR-review service.
100
+
101
+ - `codapult guard init` — discover the project and create `.codapult/guard/` state and baseline
102
+ - `codapult guard analyze` — refresh project facts without changing the baseline
103
+ - `codapult guard propose` — generate evidence-based rules and contract proposals
104
+ - `codapult guard check --changed` — check new architecture violations
105
+ - `codapult guard audit` — inspect the complete current state, including baseline findings
106
+ - `codapult guard review` — prepare a bounded diff and project-context packet for an AI reviewer
107
+ - `codapult guard impact <files...>` — explain dependencies, transitive dependents, capabilities, and relevant contracts
108
+ - `codapult guard verify` — run Guard verification and configured project checks
109
+ - `codapult guard doctor` — diagnose missing or invalid Guard artifacts
110
+ - `codapult guard rules ...` — approve proposed rules
111
+ - `codapult guard contracts ...` — approve or reject proposed contracts
112
+ - `codapult guard baseline ...` — inspect or intentionally update accepted findings
113
+
114
+ For any JavaScript or TypeScript project, install the standalone package directly:
115
+
116
+ ```shell
117
+ pnpm add -D @codapult/guard
118
+ pnpm exec codapult-guard init
119
+ ```
120
+
121
+ The Codapult CLI adapter and the standalone Guard package share the same implementation; Guard
122
+ logic is not duplicated in this repository. This section documents only the Codapult-specific
123
+ entrypoints. The standalone [Guard README](https://github.com/codapult/codapult-guard) and
124
+ [Guard documentation](https://github.com/codapult/codapult-guard/tree/main/docs) are the source of
125
+ truth for the complete lifecycle, contracts, impact analysis, AI-agent workflow, MCP tools, CI,
126
+ and current Guard capabilities.
127
+
65
128
  ### AI Integration
66
129
 
67
130
  - `codapult mcp update [version]` — pin or update the MCP version in `.cursor/mcp.json`
@@ -75,7 +138,7 @@ Mutation commands (`db push`, `db generate`, `plugins add/remove`, env sync, and
75
138
 
76
139
  ## MCP Server
77
140
 
78
- The CLI includes an MCP (Model Context Protocol) server with 29 tools, 8 resources, and 2 prompt templates for AI-assisted development. The following is the complete MCP surface exposed by the current CLI.
141
+ The CLI includes an MCP (Model Context Protocol) server with 39 tools, 12 resources, and 4 prompt templates for AI-assisted development. The following is the complete MCP surface exposed by the current CLI.
79
142
 
80
143
  ### MCP Tools
81
144
 
@@ -138,6 +201,21 @@ The CLI includes an MCP (Model Context Protocol) server with 29 tools, 8 resourc
138
201
  | ------------------------ | --------------------------------------------------------------- |
139
202
  | `codapult_deploy_status` | Check Docker, Helm, Terraform, and Pulumi deployment readiness. |
140
203
 
204
+ #### Architecture Guard
205
+
206
+ | Tool | Description |
207
+ | -------------------------------- | ---------------------------------------------------------------------------------------------------- |
208
+ | `codapult_guard_init` | Discover the project and create Guard state and an initial baseline. |
209
+ | `codapult_guard_context` | Return project architecture context for an AI agent. |
210
+ | `codapult_guard_propose` | Generate evidence-based rule and contract proposals. |
211
+ | `codapult_guard_proposal_decide` | Approve or reject proposed Guard policy. |
212
+ | `codapult_guard_check` | Check active Guard policy against the project or changed files. |
213
+ | `codapult_guard_audit` | Run a complete Guard scan, including baseline-suppressed findings. |
214
+ | `codapult_guard_review` | Prepare a bounded semantic-review packet from the current diff. |
215
+ | `codapult_guard_verify` | Run Guard, project checks, adapters, and contract verification. |
216
+ | `codapult_guard_impact` | Analyze dependencies, transitive dependents, capabilities, contracts, and architecture impact paths. |
217
+ | `codapult_guard_explain` | Explain Guard findings and project-specific architectural constraints. |
218
+
141
219
  Mutating MCP tools support `dry_run` where applicable. The tool returns the planned operations without writing project files, changing environment files, running migrations, or applying database changes. `codapult_env_read` masks sensitive values by default; `show_secrets: true` is optional and returns a security warning.
142
220
 
143
221
  ### MCP Resources
@@ -178,6 +256,9 @@ pnpm lint # lint
178
256
  pnpm typecheck # type-check without emitting
179
257
  ```
180
258
 
259
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the public repository workflow and
260
+ [SECURITY.md](SECURITY.md) for vulnerability reporting and safe CLI usage.
261
+
181
262
  ## Releasing
182
263
 
183
264
  Releases are managed with [release-it](https://github.com/release-it/release-it). The workflow:
@@ -186,9 +267,9 @@ Releases are managed with [release-it](https://github.com/release-it/release-it)
186
267
 
187
268
  ```shell
188
269
  pnpm run release # interactive — prompts for version bump type
189
- pnpm run release -- patch # non-interactive patch bump (0.1.0 → 0.1.1)
190
- pnpm run release -- minor # minor bump (0.1.0 → 0.2.0)
191
- pnpm run release -- major # major bump (0.1.0 → 1.0.0)
270
+ pnpm run release -- patch # non-interactive patch bump (0.18.1 → 0.18.2)
271
+ pnpm run release -- minor # minor bump (0.18.1 → 0.19.0)
272
+ pnpm run release -- major # major bump (0.18.1 → 1.0.0)
192
273
  ```
193
274
 
194
275
  2. `release-it` will automatically:
@@ -198,8 +279,11 @@ pnpm run release -- major # major bump (0.1.0 → 1.0.0)
198
279
  - Commit the changes (`chore: release v<version>`)
199
280
  - Create a Git tag (`v<version>`)
200
281
  - Push the commit and tag to `origin`
282
+ - Create a published GitHub Release for the tag
201
283
 
202
- 3. The `v*` tag push triggers the **Publish** GitHub Actions workflow, which builds and publishes the package to npm.
284
+ 3. The published GitHub Release triggers `.github/workflows/release.yml`, which checks out the
285
+ exact tag, validates the package, and publishes it to npm. GitHub Release is the reviewed
286
+ release record; npm remains the distribution channel.
203
287
 
204
288
  ### Dry run
205
289
 
@@ -212,6 +296,9 @@ pnpm run release -- --dry-run
212
296
  ### Prerequisites
213
297
 
214
298
  - npm [trusted publishing](https://docs.npmjs.com/trusted-publishers) must be configured for the `@codapult/cli` package on npmjs.com.
299
+ - The npm trusted publisher must point to this repository's `.github/workflows/release.yml` workflow
300
+ and allow direct `npm publish`.
301
+ - Before publishing a CLI release, the standalone `codapult-guard` package must be available on npm and the CLI dependency must use its published version rather than the pre-release workspace `file:` dependency.
215
302
  - Commit messages should follow [Conventional Commits](https://www.conventionalcommits.org/) for meaningful changelogs (e.g. `feat:`, `fix:`, `chore:`).
216
303
 
217
304
  ## License
@@ -1,16 +1,13 @@
1
1
  import { resolve } from 'node:path';
2
- import { findProjectRoot, readJsonFile } from '../utils/project.js';
2
+ import { checkProjectRoot, readJsonFile } from '../utils/project.js';
3
3
  import { ENV_FILE_NAME, loadProjectEnv } from '../utils/project-env.js';
4
4
  import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, FEATURE_ENV, } from '../utils/env-config.js';
5
- import { heading, success, fail, info, dim, label } from '../utils/ui.js';
5
+ import { heading, success, info, dim, label } from '../utils/ui.js';
6
6
  import { collectAppConfigSummary } from '../utils/config-report.js';
7
+ import { config } from '../utils/config.js';
7
8
  export function configShowCommand(options = {}) {
8
- const root = findProjectRoot();
9
- if (!root) {
10
- fail('Not inside a Codapult project.');
11
- process.exit(1);
12
- }
13
- heading('Codapult Configuration');
9
+ const root = checkProjectRoot('exit');
10
+ heading(`${config.projectName} Configuration`);
14
11
  label('Project root', root);
15
12
  // --- Package info ---
16
13
  const pkg = readJsonFile(resolve(root, 'package.json'));
@@ -44,7 +41,7 @@ export function configShowCommand(options = {}) {
44
41
  console.log();
45
42
  }
46
43
  else {
47
- dim('src/config/app.ts not found — run `codapult setup`');
44
+ dim(`src/config/app.ts not found — run \`${config.commandName} setup\``);
48
45
  }
49
46
  console.log();
50
47
  if (env.source === 'file' && !env.fileExists) {
@@ -1,7 +1,7 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
- import { findProjectRoot } from '../utils/project.js';
4
+ import { checkProjectRoot } from '../utils/project.js';
5
5
  import { loadProjectEnv } from '../utils/project-env.js';
6
6
  import { heading, success, fail, info, dim, warn } from '../utils/ui.js';
7
7
  import { parseDatabaseSchema } from '../utils/schema-parser.js';
@@ -27,22 +27,14 @@ function getDbProvider(root, options) {
27
27
  return 'turso';
28
28
  }
29
29
  export function dbPushCommand(options = {}) {
30
- const root = findProjectRoot();
31
- if (!root) {
32
- fail('Not inside a Codapult project.');
33
- process.exit(1);
34
- }
30
+ const root = checkProjectRoot('exit');
35
31
  heading('Database Push');
36
32
  const provider = getDbProvider(root, options);
37
33
  info(`Provider: ${provider}`);
38
34
  run('pnpm db:push', root);
39
35
  }
40
36
  export function dbGenerateCommand(options = {}) {
41
- const root = findProjectRoot();
42
- if (!root) {
43
- fail('Not inside a Codapult project.');
44
- process.exit(1);
45
- }
37
+ const root = checkProjectRoot('exit');
46
38
  heading('Generate Migration');
47
39
  const provider = getDbProvider(root, options);
48
40
  info(`Provider: ${provider}`);
@@ -54,20 +46,12 @@ export function dbGenerateCommand(options = {}) {
54
46
  }
55
47
  }
56
48
  export function dbSeedCommand(_options = {}) {
57
- const root = findProjectRoot();
58
- if (!root) {
59
- fail('Not inside a Codapult project.');
60
- process.exit(1);
61
- }
49
+ const root = checkProjectRoot('exit');
62
50
  heading('Seed Database');
63
51
  run('pnpm db:seed', root);
64
52
  }
65
53
  export function dbStudioCommand(options = {}) {
66
- const root = findProjectRoot();
67
- if (!root) {
68
- fail('Not inside a Codapult project.');
69
- process.exit(1);
70
- }
54
+ const root = checkProjectRoot('exit');
71
55
  heading('Drizzle Studio');
72
56
  const provider = getDbProvider(root, options);
73
57
  info(`Provider: ${provider}`);
@@ -80,11 +64,7 @@ export function dbStudioCommand(options = {}) {
80
64
  }
81
65
  }
82
66
  export async function dbStatusCommand(options = {}) {
83
- const root = findProjectRoot();
84
- if (!root) {
85
- fail('Not inside a Codapult project.');
86
- process.exit(1);
87
- }
67
+ const root = checkProjectRoot('exit');
88
68
  heading('Database Status');
89
69
  const provider = getDbProvider(root, options);
90
70
  info(`Provider: ${provider}`);
@@ -115,12 +95,9 @@ export async function dbStatusCommand(options = {}) {
115
95
  console.log();
116
96
  }
117
97
  export function dbLiveDiffCommand(options = {}) {
118
- const root = findProjectRoot();
119
- if (!root) {
120
- fail('Not inside a Codapult project.');
121
- process.exitCode = 1;
98
+ const root = checkProjectRoot('code');
99
+ if (!root)
122
100
  return;
123
- }
124
101
  const env = loadProjectEnv(root, options);
125
102
  const provider = getDbProvider(root, options);
126
103
  const schemaPath = provider === 'postgres' ? 'src/lib/db/schema-pg.ts' : 'src/lib/db/schema.ts';
@@ -150,12 +127,9 @@ export function dbLiveDiffCommand(options = {}) {
150
127
  }
151
128
  }
152
129
  export function dbSchemaDiffCommand() {
153
- const root = findProjectRoot();
154
- if (!root) {
155
- fail('Not inside a Codapult project.');
156
- process.exitCode = 1;
130
+ const root = checkProjectRoot('code');
131
+ if (!root)
157
132
  return;
158
- }
159
133
  const sqlitePath = 'src/lib/db/schema.ts';
160
134
  const postgresPath = 'src/lib/db/schema-pg.ts';
161
135
  const sqliteAbsolutePath = resolve(root, sqlitePath);
@@ -1,10 +1,11 @@
1
1
  import { execSync, spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
- import { findProjectRoot } from '../utils/project.js';
4
+ import { checkProjectRoot } from '../utils/project.js';
5
5
  import { ENV_FILE_NAME, getProjectEnvSource, loadProjectEnv, } from '../utils/project-env.js';
6
6
  import { heading, success, fail, info, dim, warn, confirm } from '../utils/ui.js';
7
7
  import { renderStructuredReport, summarizeChecks, } from '../utils/check-report.js';
8
+ import { config } from '../utils/config.js';
8
9
  function hasCommand(cmd) {
9
10
  return spawnSync(cmd, ['--version'], { stdio: 'ignore' }).status === 0;
10
11
  }
@@ -12,11 +13,7 @@ function hasCommand(cmd) {
12
13
  // codapult deploy vercel
13
14
  // ---------------------------------------------------------------------------
14
15
  export async function deployVercelCommand(options = {}) {
15
- const root = findProjectRoot();
16
- if (!root) {
17
- fail('Not inside a Codapult project.');
18
- process.exit(1);
19
- }
16
+ const root = checkProjectRoot('exit');
20
17
  heading('Deploy to Vercel');
21
18
  // 1. Check Vercel CLI
22
19
  if (!hasCommand('vercel')) {
@@ -81,11 +78,7 @@ export async function deployVercelCommand(options = {}) {
81
78
  // codapult deploy docker
82
79
  // ---------------------------------------------------------------------------
83
80
  export async function deployDockerCommand(opts = {}) {
84
- const root = findProjectRoot();
85
- if (!root) {
86
- fail('Not inside a Codapult project.');
87
- process.exit(1);
88
- }
81
+ const root = checkProjectRoot('exit');
89
82
  heading('Deploy with Docker');
90
83
  // 1. Check Docker
91
84
  if (!hasCommand('docker')) {
@@ -108,7 +101,7 @@ export async function deployDockerCommand(opts = {}) {
108
101
  }
109
102
  // 4. Read package.json for name
110
103
  const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
111
- const appName = pkg.name || 'codapult';
104
+ const appName = pkg.name || config.appName;
112
105
  const tag = opts.tag || 'latest';
113
106
  const imageName = `${appName}:${tag}`;
114
107
  info(`Image: ${imageName}`);
@@ -156,11 +149,7 @@ export async function deployDockerCommand(opts = {}) {
156
149
  // codapult deploy status
157
150
  // ---------------------------------------------------------------------------
158
151
  export function deployStatusCommand(options = {}) {
159
- const root = findProjectRoot();
160
- if (!root) {
161
- fail('Not inside a Codapult project.');
162
- process.exit(1);
163
- }
152
+ const root = checkProjectRoot('exit');
164
153
  const checks = [
165
154
  { name: 'Dockerfile', path: 'Dockerfile' },
166
155
  { name: 'docker-compose.yml', path: 'docker-compose.yml' },
@@ -235,7 +224,7 @@ export function deployStatusCommand(options = {}) {
235
224
  process.exitCode = report.summary.failures > 0 ? 1 : 0;
236
225
  console.log();
237
226
  dim('Deploy targets:');
238
- dim(' codapult deploy vercel — Vercel (recommended)');
239
- dim(' codapult deploy docker — Docker build + run');
227
+ dim(` ${config.commandName} deploy vercel — Vercel (recommended)`);
228
+ dim(` ${config.commandName} deploy docker — Docker build + run`);
240
229
  console.log();
241
230
  }
@@ -1,13 +1,8 @@
1
- import { findProjectRoot } from '../utils/project.js';
1
+ import { checkProjectRoot } from '../utils/project.js';
2
2
  import { collectProjectHealth } from '../utils/health.js';
3
- import { fail } from '../utils/ui.js';
4
3
  import { healthExitCode, renderHealthReport } from '../utils/health-render.js';
5
4
  export function doctorCommand(options = {}) {
6
- const root = findProjectRoot();
7
- if (!root) {
8
- fail('Not inside a Codapult project.');
9
- process.exit(1);
10
- }
5
+ const root = checkProjectRoot('exit');
11
6
  const report = collectProjectHealth(root, {
12
7
  envSource: options.envFile === false ? 'process' : 'file',
13
8
  });
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
- import { findProjectRoot } from '../utils/project.js';
3
+ import { checkProjectRoot } 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
6
  import { renderStructuredReport, summarizeChecks } from '../utils/check-report.js';
@@ -33,11 +33,7 @@ function parseEnvFile(content) {
33
33
  // codapult env check
34
34
  // ---------------------------------------------------------------------------
35
35
  export function envCheckCommand(options = {}) {
36
- const root = findProjectRoot();
37
- if (!root) {
38
- fail('Not inside a Codapult project.');
39
- process.exit(1);
40
- }
36
+ const root = checkProjectRoot('exit');
41
37
  const examplePath = resolve(root, ENV_EXAMPLE_FILE_NAME);
42
38
  const localPath = resolve(root, ENV_FILE_NAME);
43
39
  if (!existsSync(examplePath)) {
@@ -101,11 +97,7 @@ export function envCheckCommand(options = {}) {
101
97
  // codapult env sync
102
98
  // ---------------------------------------------------------------------------
103
99
  export async function envSyncCommand(options = {}) {
104
- const root = findProjectRoot();
105
- if (!root) {
106
- fail('Not inside a Codapult project.');
107
- process.exit(1);
108
- }
100
+ const root = checkProjectRoot('exit');
109
101
  heading(`Sync ${ENV_FILE_NAME} with ${ENV_EXAMPLE_FILE_NAME}`);
110
102
  if (getProjectEnvSource(options) === 'process') {
111
103
  warn(`\`codapult env sync --no-env-file\` cannot update process.env`);
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { resolve, dirname } from 'node:path';
3
- import { findProjectRoot } from '../utils/project.js';
3
+ import { checkProjectRoot } from '../utils/project.js';
4
4
  import { heading, success, fail, info, dim } from '../utils/ui.js';
5
5
  import { validateGeneratedName } from '../utils/validation.js';
6
6
  function toKebab(name) {
@@ -31,11 +31,7 @@ function writeIfNotExists(filePath, content) {
31
31
  // ---------------------------------------------------------------------------
32
32
  export function generatePageCommand(name) {
33
33
  validateGeneratedName(name);
34
- const root = findProjectRoot();
35
- if (!root) {
36
- fail('Not inside a Codapult project.');
37
- process.exit(1);
38
- }
34
+ const root = checkProjectRoot('exit');
39
35
  const kebab = toKebab(name);
40
36
  const pascal = toPascal(name);
41
37
  const title = pascal.replace(/([A-Z])/g, ' $1').trim();
@@ -87,11 +83,7 @@ export default async function ${pascal}Page() {
87
83
  // ---------------------------------------------------------------------------
88
84
  export function generateApiCommand(name) {
89
85
  validateGeneratedName(name);
90
- const root = findProjectRoot();
91
- if (!root) {
92
- fail('Not inside a Codapult project.');
93
- process.exit(1);
94
- }
86
+ const root = checkProjectRoot('exit');
95
87
  const kebab = toKebab(name);
96
88
  const camel = toCamel(name);
97
89
  const schemaName = `${camel}Schema`;
@@ -167,11 +159,7 @@ export async function POST(req: Request) {
167
159
  // ---------------------------------------------------------------------------
168
160
  export function generateActionCommand(name) {
169
161
  validateGeneratedName(name);
170
- const root = findProjectRoot();
171
- if (!root) {
172
- fail('Not inside a Codapult project.');
173
- process.exit(1);
174
- }
162
+ const root = checkProjectRoot('exit');
175
163
  const kebab = toKebab(name);
176
164
  const camel = toCamel(name);
177
165
  const schemaName = `${camel}Schema`;
@@ -220,11 +208,7 @@ export async function ${camel}Action(input: unknown): Promise<{ success: boolean
220
208
  // ---------------------------------------------------------------------------
221
209
  export function generatePluginCommand(name) {
222
210
  validateGeneratedName(name);
223
- const root = findProjectRoot();
224
- if (!root) {
225
- fail('Not inside a Codapult project.');
226
- process.exit(1);
227
- }
211
+ const root = checkProjectRoot('exit');
228
212
  const kebab = toKebab(name);
229
213
  const camel = toCamel(name);
230
214
  const pascal = toPascal(name);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Compatibility adapter: Guard owns its implementation in the standalone package.
3
+ * Codapult keeps the historical `codapult guard ...` command surface.
4
+ */
5
+ export * from '@codapult/guard/commands/guard';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Compatibility adapter: Guard owns its implementation in the standalone package.
3
+ * Codapult keeps the historical `codapult guard ...` command surface.
4
+ */
5
+ export * from '@codapult/guard/commands/guard';
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { execFileSync } from 'node:child_process';
3
3
  import { resolve } from 'node:path';
4
- import { findProjectRoot } from '../utils/project.js';
4
+ import { checkProjectRoot } from '../utils/project.js';
5
5
  import { collectMcpHealth } from '../utils/health.js';
6
6
  import { checkEnvSchemaCompatibility } from '../utils/env-compatibility.js';
7
7
  import { heading, success, fail, info, dim } from '../utils/ui.js';
@@ -27,11 +27,7 @@ function resolveVersion(version) {
27
27
  }
28
28
  }
29
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
- }
30
+ const root = checkProjectRoot('exit');
35
31
  const configPath = getConfigPath(root);
36
32
  const targetVersion = resolveVersion(version);
37
33
  const packageSpec = `${PACKAGE_NAME}@${targetVersion}`;
@@ -61,22 +57,15 @@ export function mcpUpdateCommand(version, options = {}) {
61
57
  dim('Restart or reload the MCP connection in your editor to use the new version.');
62
58
  }
63
59
  export function mcpDoctorCommand() {
64
- const root = findProjectRoot();
65
- if (!root) {
66
- fail('Not inside a Codapult project.');
67
- process.exit(1);
68
- }
60
+ const root = checkProjectRoot('exit');
69
61
  const report = collectMcpHealth(root);
70
62
  renderHealthReport('MCP Doctor', report);
71
63
  process.exitCode = healthExitCode(report);
72
64
  }
73
65
  export function mcpContractCheckCommand() {
74
- const root = findProjectRoot();
75
- if (!root) {
76
- fail('Not inside a Codapult project.');
77
- process.exitCode = 1;
66
+ const root = checkProjectRoot('code');
67
+ if (!root)
78
68
  return;
79
- }
80
69
  const result = checkEnvSchemaCompatibility(root);
81
70
  heading('MCP Contract Check');
82
71
  if (result.status === 'ok') {
@@ -1,7 +1,7 @@
1
1
  import { execSync, spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
- import { findProjectRoot } from '../utils/project.js';
4
+ import { checkProjectRoot } 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';
@@ -17,11 +17,7 @@ function execQuiet(cmd, cwd) {
17
17
  }
18
18
  }
19
19
  export async function pluginsAddCommand(name, options = {}) {
20
- const root = findProjectRoot();
21
- if (!root) {
22
- fail('Not inside a Codapult project.');
23
- process.exit(1);
24
- }
20
+ const root = checkProjectRoot('exit');
25
21
  heading(`Installing plugin: ${name}`);
26
22
  // Clone from a git URL when --from is provided
27
23
  if (options.from) {
@@ -212,11 +208,7 @@ export async function pluginsAddCommand(name, options = {}) {
212
208
  console.log();
213
209
  }
214
210
  export async function pluginsRemoveCommand(name, options = {}) {
215
- const root = findProjectRoot();
216
- if (!root) {
217
- fail('Not inside a Codapult project.');
218
- process.exit(1);
219
- }
211
+ const root = checkProjectRoot('exit');
220
212
  heading(`Removing plugin: ${name}`);
221
213
  const result = resolveManifest(root, name);
222
214
  let manifest = result?.manifest;
@@ -324,11 +316,7 @@ function getInstalledPluginNames(root) {
324
316
  .map((f) => f.replace('.ts', ''));
325
317
  }
326
318
  export async function pluginsMigrateCommand(name, options) {
327
- const root = findProjectRoot();
328
- if (!root) {
329
- fail('Not inside a Codapult project.');
330
- process.exit(1);
331
- }
319
+ const root = checkProjectRoot('exit');
332
320
  const pluginNames = name ? [name] : getInstalledPluginNames(root);
333
321
  if (pluginNames.length === 0) {
334
322
  info('No installed plugins found.');
@@ -422,11 +410,7 @@ export async function pluginsMigrateCommand(name, options) {
422
410
  // codapult plugins list
423
411
  // ---------------------------------------------------------------------------
424
412
  export function pluginsListCommand() {
425
- const root = findProjectRoot();
426
- if (!root) {
427
- fail('Not inside a Codapult project.');
428
- process.exit(1);
429
- }
413
+ const root = checkProjectRoot('exit');
430
414
  heading('Installed Plugins');
431
415
  const pluginsDir = resolve(root, 'src/plugins');
432
416
  if (!existsSync(pluginsDir)) {
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
2
2
  import { resolve, relative, join } from 'node:path';
3
3
  import { createInterface } from 'node:readline';
4
- import { findProjectRoot } from '../utils/project.js';
4
+ import { checkProjectRoot } from '../utils/project.js';
5
5
  import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, } from '../utils/project-env.js';
6
6
  import { heading, success, fail, info, dim, ask, confirm } from '../utils/ui.js';
7
7
  async function selectPrompt(iface, question, options) {
@@ -783,11 +783,7 @@ async function interactiveSetup() {
783
783
  return config;
784
784
  }
785
785
  export async function setupCommand(options) {
786
- const root = findProjectRoot();
787
- if (!root) {
788
- fail('Not inside a Codapult project. Run this from your project directory.');
789
- process.exit(1);
790
- }
786
+ const root = checkProjectRoot('exit');
791
787
  const presetRaw = options.preset;
792
788
  let config;
793
789
  if (presetRaw) {
@@ -1,5 +1,5 @@
1
1
  import { execSync } from 'node:child_process';
2
- import { findProjectRoot } from '../utils/project.js';
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';
@@ -73,11 +73,7 @@ function classifyConflicts(cwd) {
73
73
  return { safe, caution, core };
74
74
  }
75
75
  export async function updateCommand(version, options) {
76
- const root = findProjectRoot();
77
- if (!root) {
78
- fail('Not inside a Codapult project.');
79
- process.exit(1);
80
- }
76
+ const root = checkProjectRoot('exit');
81
77
  ensureUpstreamRemote(root);
82
78
  fetchUpstream(root);
83
79
  const tags = getAvailableTags(root);