@codapult/cli 0.4.2 → 0.6.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/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { generatePageCommand, generateApiCommand, generateActionCommand, generat
10
10
  import { dbPushCommand, dbGenerateCommand, dbSeedCommand, dbStudioCommand, dbStatusCommand, } from './commands/db.js';
11
11
  import { envCheckCommand, envSyncCommand } from './commands/env.js';
12
12
  import { deployVercelCommand, deployDockerCommand, deployStatusCommand, } from './commands/deploy.js';
13
+ import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from './utils/project-env.js';
13
14
  const program = new Command()
14
15
  .name('codapult')
15
16
  .description('Codapult CLI — manage your SaaS project')
@@ -19,11 +20,15 @@ const program = new Command()
19
20
  styleCommandText: (str) => pc.yellow(str),
20
21
  styleOptionText: (str) => pc.green(str),
21
22
  });
23
+ function withNoEnvFileOption(command) {
24
+ return command.option('--no-env-file', `read env vars from process.env instead of ${ENV_FILE_NAME}`);
25
+ }
22
26
  program
23
27
  .commandsGroup('Project')
24
28
  .command('setup')
25
29
  .description('interactive project setup wizard (or non-interactive with --preset)')
26
30
  .option('--preset <value>', 'apply a preset non-interactively (name, key=value pairs, or both)')
31
+ .option('--no-env-file', `do not create ${ENV_FILE_NAME}; read env vars from process.env instead`)
27
32
  .action(setupCommand);
28
33
  program
29
34
  .command('update [version]')
@@ -31,25 +36,18 @@ program
31
36
  .option('--dry-run', 'show what would change without applying')
32
37
  .option('--list', 'list available versions')
33
38
  .action(updateCommand);
34
- program
35
- .command('doctor')
36
- .description('check project health and configuration')
37
- .action(doctorCommand);
38
- program
39
- .command('config')
40
- .description('show current project configuration')
41
- .action(configShowCommand);
39
+ withNoEnvFileOption(program.command('doctor').description('check project health and configuration')).action(doctorCommand);
40
+ withNoEnvFileOption(program.command('config').description('show current project configuration')).action(configShowCommand);
42
41
  const plugins = program
43
42
  .commandsGroup('Plugins')
44
43
  .command('plugins')
45
44
  .description('manage Codapult plugins');
46
- plugins
45
+ withNoEnvFileOption(plugins
47
46
  .command('add <name>')
48
47
  .description('install a plugin (local or remote)')
49
48
  .option('--from <url>', 'git URL to clone the plugin from')
50
- .option('--ci', 'CI/Vercel mode: skip pnpm install, db:push, env patching, and interactive prompts')
51
- .action(pluginsAddCommand);
52
- plugins.command('remove <name>').description('uninstall a plugin').action(pluginsRemoveCommand);
49
+ .option('--ci', 'CI/Vercel mode: skip pnpm install, db:push, env patching, and interactive prompts')).action(pluginsAddCommand);
50
+ withNoEnvFileOption(plugins.command('remove <name>').description('uninstall a plugin')).action(pluginsRemoveCommand);
53
51
  plugins
54
52
  .command('migrate [name]')
55
53
  .description('update plugin schema and generate DB migration')
@@ -78,25 +76,21 @@ const db = program
78
76
  .commandsGroup('Infrastructure')
79
77
  .command('db')
80
78
  .description('database management (Drizzle ORM)');
81
- db.command('push').description('apply schema to database').action(dbPushCommand);
82
- db.command('generate').description('generate migration files').action(dbGenerateCommand);
83
- db.command('seed').description('seed sample data').action(dbSeedCommand);
84
- db.command('studio').description('open Drizzle Studio').action(dbStudioCommand);
85
- db.command('status').description('show schema info and migration count').action(dbStatusCommand);
79
+ withNoEnvFileOption(db.command('push').description('apply schema to database')).action(dbPushCommand);
80
+ withNoEnvFileOption(db.command('generate').description('generate migration files')).action(dbGenerateCommand);
81
+ withNoEnvFileOption(db.command('seed').description('seed sample data')).action(dbSeedCommand);
82
+ withNoEnvFileOption(db.command('studio').description('open Drizzle Studio')).action(dbStudioCommand);
83
+ withNoEnvFileOption(db.command('status').description('show schema info and migration count')).action(dbStatusCommand);
86
84
  const env = program.command('env').description('environment variable management');
87
- env
88
- .command('check')
89
- .description('validate .env.local against .env.example')
90
- .action(envCheckCommand);
91
- env.command('sync').description('add missing variables from .env.example').action(envSyncCommand);
85
+ withNoEnvFileOption(env.command('check').description(`validate env vars against ${ENV_EXAMPLE_FILE_NAME}`)).action(envCheckCommand);
86
+ withNoEnvFileOption(env.command('sync').description(`add missing variables from ${ENV_EXAMPLE_FILE_NAME}`)).action(envSyncCommand);
92
87
  const deploy = program.command('deploy').description('deployment helpers');
93
- deploy.command('vercel').description('build and deploy to Vercel').action(deployVercelCommand);
94
- deploy
88
+ withNoEnvFileOption(deploy.command('vercel').description('build and deploy to Vercel')).action(deployVercelCommand);
89
+ withNoEnvFileOption(deploy
95
90
  .command('docker')
96
91
  .description('build Docker image')
97
- .option('-t, --tag <tag>', 'image tag', 'latest')
98
- .action(deployDockerCommand);
99
- deploy.command('status').description('check deploy readiness').action(deployStatusCommand);
92
+ .option('-t, --tag <tag>', 'image tag', 'latest')).action(deployDockerCommand);
93
+ withNoEnvFileOption(deploy.command('status').description('check deploy readiness')).action(deployStatusCommand);
100
94
  program
101
95
  .commandsGroup('AI Integration')
102
96
  .command('mcp-server')
@@ -1,4 +1,5 @@
1
1
  import { findProjectRoot, readProjectFile } from '../utils/project.js';
2
+ import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from '../utils/project-env.js';
2
3
  function getRoot() {
3
4
  const root = findProjectRoot();
4
5
  if (!root)
@@ -16,7 +17,7 @@ export function registerResources(server) {
16
17
  });
17
18
  server.registerResource('codapult_app_config', 'codapult://config/app', {
18
19
  title: 'App Configuration',
19
- description: 'Application config (src/config/app.ts) — brand, AI, payments, company. Feature toggles and auth methods live in .env.local (read via codapult://env-example or codapult_project_status).',
20
+ description: `Application config (src/config/app.ts) — brand, AI, payments, company. Feature toggles and auth methods live in the project env source (${ENV_FILE_NAME} or process.env) and can be inspected via codapult://env-example or codapult_project_status.`,
20
21
  mimeType: 'text/plain',
21
22
  }, () => {
22
23
  const content = readProjectFile(getRoot(), 'src/config/app.ts') ?? 'Config file not found';
@@ -33,11 +34,11 @@ export function registerResources(server) {
33
34
  return { contents: [{ uri: 'codapult://agents', text: content, mimeType: 'text/markdown' }] };
34
35
  });
35
36
  server.registerResource('codapult_env_example', 'codapult://env-example', {
36
- title: '.env.example',
37
+ title: ENV_EXAMPLE_FILE_NAME,
37
38
  description: 'Environment variable template with descriptions and defaults',
38
39
  mimeType: 'text/plain',
39
40
  }, () => {
40
- const content = readProjectFile(getRoot(), '.env.example') ?? '.env.example not found';
41
+ const content = readProjectFile(getRoot(), ENV_EXAMPLE_FILE_NAME) ?? `${ENV_EXAMPLE_FILE_NAME} not found`;
41
42
  return {
42
43
  contents: [{ uri: 'codapult://env-example', text: content, mimeType: 'text/plain' }],
43
44
  };
@@ -2,6 +2,8 @@ import { existsSync, readdirSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { findProjectRoot, readProjectFile } from '../../utils/project.js';
5
+ import { getProjectEnvOptions, loadProjectEnv } from '../../utils/project-env.js';
6
+ import { envSourceSchema } from './schemas.js';
5
7
  function getRoot() {
6
8
  const root = findProjectRoot();
7
9
  if (!root)
@@ -101,10 +103,12 @@ export function registerDbTools(server) {
101
103
  server.registerTool('codapult_db_status', {
102
104
  title: 'Database Status',
103
105
  description: 'Get database provider, table count, and migration count',
104
- inputSchema: {},
105
- }, () => {
106
+ inputSchema: {
107
+ env_source: envSourceSchema.optional(),
108
+ },
109
+ }, ({ env_source }) => {
106
110
  const root = getRoot();
107
- const envContent = readProjectFile(root, '.env.local') ?? '';
111
+ const envContent = loadProjectEnv(root, getProjectEnvOptions(env_source)).content;
108
112
  const providerMatch = /^DB_PROVIDER\s*=\s*"?(\w+)"?/m.exec(envContent);
109
113
  const provider = providerMatch?.[1] ?? 'turso';
110
114
  const schemaContent = readProjectFile(root, 'src/lib/db/schema.ts') ?? '';
@@ -1,4 +1,5 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { ENV_FILE_NAME } from '../../utils/project-env.js';
2
3
  vi.mock('node:fs');
3
4
  vi.mock('node:child_process');
4
5
  vi.mock('../../utils/project.js', () => ({
@@ -118,7 +119,7 @@ export const user = sqliteTable('user', {
118
119
  const envContent = 'DB_PROVIDER=turso\nOTHER=val';
119
120
  const schema = `export const user = sqliteTable('user', { id: text('id') });`;
120
121
  mockedReadProject.mockImplementation((_root, path) => {
121
- if (path === '.env.local')
122
+ if (path === ENV_FILE_NAME)
122
123
  return envContent;
123
124
  if (path === 'src/lib/db/schema.ts')
124
125
  return schema;
@@ -137,7 +138,7 @@ export const user = sqliteTable('user', {
137
138
  const server = createMockServer();
138
139
  registerDbTools(server);
139
140
  mockedReadProject.mockImplementation((_root, path) => {
140
- if (path === '.env.local')
141
+ if (path === ENV_FILE_NAME)
141
142
  return '';
142
143
  if (path === 'src/lib/db/schema.ts')
143
144
  return '';
@@ -149,5 +150,20 @@ export const user = sqliteTable('user', {
149
150
  const parsed = JSON.parse(result.content[0].text);
150
151
  expect(parsed.provider).toBe('turso');
151
152
  });
153
+ it('can read provider from process env', () => {
154
+ const server = createMockServer();
155
+ registerDbTools(server);
156
+ vi.stubEnv('DB_PROVIDER', 'postgres');
157
+ mockedReadProject.mockImplementation((_root, path) => {
158
+ if (path === 'src/lib/db/schema.ts')
159
+ return '';
160
+ return null;
161
+ });
162
+ mockedExists.mockReturnValue(false);
163
+ const handler = server.tools.find((t) => t.name === 'codapult_db_status').handler;
164
+ const result = handler({ env_source: 'process' });
165
+ const parsed = JSON.parse(result.content[0].text);
166
+ expect(parsed.provider).toBe('postgres');
167
+ });
152
168
  });
153
169
  });
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { findProjectRoot } from '../../utils/project.js';
4
+ import { ENV_FILE_NAME } from '../../utils/project-env.js';
4
5
  function getRoot() {
5
6
  const root = findProjectRoot();
6
7
  if (!root)
@@ -21,7 +22,7 @@ export function registerDeployTools(server) {
21
22
  { name: 'Terraform (AWS)', path: 'infra/terraform/main.tf' },
22
23
  { name: 'Pulumi (AWS)', path: 'infra/pulumi/index.ts' },
23
24
  { name: 'Helm chart', path: 'infra/helm/codapult/Chart.yaml' },
24
- { name: '.env.local', path: '.env.local' },
25
+ { name: ENV_FILE_NAME, path: ENV_FILE_NAME },
25
26
  ].map(({ name, path }) => ({
26
27
  name,
27
28
  found: existsSync(resolve(root, path)),
@@ -2,6 +2,8 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { findProjectRoot, readProjectFile } from '../../utils/project.js';
5
+ import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, getProjectEnvOptions, loadProjectEnv, } from '../../utils/project-env.js';
6
+ import { envSourceSchema } from './schemas.js';
5
7
  function getRoot() {
6
8
  const root = findProjectRoot();
7
9
  if (!root)
@@ -46,14 +48,14 @@ const ENV_KEY_REGEX = /^[A-Z][A-Z0-9_]*$/;
46
48
  export function registerEnvTools(server) {
47
49
  server.registerTool('codapult_env_schema', {
48
50
  title: 'Env Schema',
49
- description: 'Get all environment variables from .env.example with descriptions and default values',
51
+ description: `Get all environment variables from ${ENV_EXAMPLE_FILE_NAME} with descriptions and default values`,
50
52
  inputSchema: {},
51
53
  }, () => {
52
54
  const root = getRoot();
53
- const content = readProjectFile(root, '.env.example');
55
+ const content = readProjectFile(root, ENV_EXAMPLE_FILE_NAME);
54
56
  if (!content)
55
57
  return {
56
- content: [{ type: 'text', text: '.env.example not found' }],
58
+ content: [{ type: 'text', text: `${ENV_EXAMPLE_FILE_NAME} not found` }],
57
59
  isError: true,
58
60
  };
59
61
  const entries = parseEnvFile(content);
@@ -61,22 +63,24 @@ export function registerEnvTools(server) {
61
63
  });
62
64
  server.registerTool('codapult_env_read', {
63
65
  title: 'Read Env',
64
- description: 'Read current .env.local values with validation status against .env.example. Sensitive values (keys containing SECRET, KEY, TOKEN, PASSWORD, CREDENTIAL) are masked by default.',
66
+ description: `Read current ${ENV_FILE_NAME} values with validation status against ${ENV_EXAMPLE_FILE_NAME}. Sensitive values (keys containing SECRET, KEY, TOKEN, PASSWORD, CREDENTIAL) are masked by default.`,
65
67
  inputSchema: {
66
68
  show_secrets: z
67
69
  .boolean()
68
70
  .default(false)
69
71
  .describe('When true, show full values for sensitive keys (use with caution)'),
72
+ env_source: envSourceSchema.optional(),
70
73
  },
71
- }, ({ show_secrets }) => {
74
+ }, ({ show_secrets, env_source }) => {
72
75
  const root = getRoot();
73
- const localContent = readProjectFile(root, '.env.local');
74
- if (!localContent)
76
+ const env = loadProjectEnv(root, getProjectEnvOptions(env_source));
77
+ const localContent = env.content;
78
+ if (!localContent && env.source === 'file')
75
79
  return {
76
- content: [{ type: 'text', text: '.env.local not found' }],
80
+ content: [{ type: 'text', text: `${ENV_FILE_NAME} not found` }],
77
81
  isError: true,
78
82
  };
79
- const exampleContent = readProjectFile(root, '.env.example') ?? '';
83
+ const exampleContent = readProjectFile(root, ENV_EXAMPLE_FILE_NAME) ?? '';
80
84
  const localEntries = parseEnvFile(localContent);
81
85
  const exampleEntries = parseEnvFile(exampleContent);
82
86
  const localKeys = new Set(localEntries.map((e) => e.key));
@@ -102,12 +106,13 @@ export function registerEnvTools(server) {
102
106
  });
103
107
  server.registerTool('codapult_env_update', {
104
108
  title: 'Update Env Variable',
105
- description: 'Update or add a single environment variable in .env.local',
109
+ description: `Update or add a single environment variable in ${ENV_FILE_NAME}`,
106
110
  inputSchema: {
107
111
  key: z.string().describe('Variable name (e.g. "STRIPE_SECRET_KEY")'),
108
112
  value: z.string().describe('Variable value'),
113
+ env_source: envSourceSchema.optional(),
109
114
  },
110
- }, ({ key, value }) => {
115
+ }, ({ key, value, env_source }) => {
111
116
  if (!ENV_KEY_REGEX.test(key)) {
112
117
  return {
113
118
  content: [
@@ -120,10 +125,21 @@ export function registerEnvTools(server) {
120
125
  };
121
126
  }
122
127
  const root = getRoot();
123
- const envPath = resolve(root, '.env.local');
128
+ if (env_source === 'process') {
129
+ return {
130
+ content: [
131
+ {
132
+ type: 'text',
133
+ text: 'Updating process.env via MCP is not supported; use env_source="file"',
134
+ },
135
+ ],
136
+ isError: true,
137
+ };
138
+ }
139
+ const envPath = resolve(root, ENV_FILE_NAME);
124
140
  if (!existsSync(envPath)) {
125
141
  return {
126
- content: [{ type: 'text', text: '.env.local not found' }],
142
+ content: [{ type: 'text', text: `${ENV_FILE_NAME} not found` }],
127
143
  isError: true,
128
144
  };
129
145
  }
@@ -138,6 +154,6 @@ export function registerEnvTools(server) {
138
154
  content = content.trimEnd() + `\n${line}\n`;
139
155
  }
140
156
  writeFileSync(envPath, content, 'utf-8');
141
- return { content: [{ type: 'text', text: `Updated ${key} in .env.local` }] };
157
+ return { content: [{ type: 'text', text: `Updated ${key} in ${ENV_FILE_NAME}` }] };
142
158
  });
143
159
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from '../../utils/project-env.js';
2
3
  vi.mock('node:fs');
3
4
  vi.mock('../../utils/project.js', () => ({
4
5
  findProjectRoot: vi.fn(),
@@ -35,7 +36,7 @@ describe('registerEnvTools', () => {
35
36
  ]);
36
37
  });
37
38
  describe('codapult_env_schema', () => {
38
- it('parses .env.example entries with comments', () => {
39
+ it(`parses ${ENV_EXAMPLE_FILE_NAME} entries with comments`, () => {
39
40
  const server = createMockServer();
40
41
  registerEnvTools(server);
41
42
  const envExample = `# Auth provider
@@ -59,7 +60,7 @@ DATABASE_URL=sqlite://local.db
59
60
  expect(dbEntry.value).toBe('sqlite://local.db');
60
61
  expect(dbEntry.comment).toBe('Optional database URL');
61
62
  });
62
- it('returns error when .env.example not found', () => {
63
+ it(`returns error when ${ENV_EXAMPLE_FILE_NAME} not found`, () => {
63
64
  const server = createMockServer();
64
65
  registerEnvTools(server);
65
66
  mockedReadProject.mockReturnValue(null);
@@ -74,10 +75,10 @@ DATABASE_URL=sqlite://local.db
74
75
  registerEnvTools(server);
75
76
  const envLocal = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=your-key-here\n`;
76
77
  const envExample = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
78
+ mockedExists.mockReturnValue(true);
79
+ mockedRead.mockReturnValue(envLocal);
77
80
  mockedReadProject.mockImplementation((_root, path) => {
78
- if (path === '.env.local')
79
- return envLocal;
80
- if (path === '.env.example')
81
+ if (path === ENV_EXAMPLE_FILE_NAME)
81
82
  return envExample;
82
83
  return null;
83
84
  });
@@ -87,7 +88,22 @@ DATABASE_URL=sqlite://local.db
87
88
  expect(parsed.missing).toContain('DATABASE_URL');
88
89
  expect(parsed.unconfigured).toContain('STRIPE_SECRET_KEY');
89
90
  });
90
- it('returns error when .env.local not found', () => {
91
+ it('can read from process env', () => {
92
+ const server = createMockServer();
93
+ registerEnvTools(server);
94
+ vi.stubEnv('AUTH_PROVIDER', 'better-auth');
95
+ vi.stubEnv('STRIPE_SECRET_KEY', 'sk_live_123');
96
+ mockedReadProject.mockImplementation((_root, path) => {
97
+ if (path === ENV_EXAMPLE_FILE_NAME)
98
+ return `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
99
+ return null;
100
+ });
101
+ const handler = server.tools.find((t) => t.name === 'codapult_env_read').handler;
102
+ const result = handler({ env_source: 'process' });
103
+ const parsed = JSON.parse(result.content[0].text);
104
+ expect(parsed.variables.some((v) => v.key === 'AUTH_PROVIDER')).toBe(true);
105
+ });
106
+ it(`returns error when ${ENV_FILE_NAME} not found`, () => {
91
107
  const server = createMockServer();
92
108
  registerEnvTools(server);
93
109
  mockedReadProject.mockReturnValue(null);
@@ -97,7 +113,7 @@ DATABASE_URL=sqlite://local.db
97
113
  });
98
114
  });
99
115
  describe('codapult_env_update', () => {
100
- it('updates existing variable in .env.local', () => {
116
+ it(`updates existing variable in ${ENV_FILE_NAME}`, () => {
101
117
  const server = createMockServer();
102
118
  registerEnvTools(server);
103
119
  mockedExists.mockReturnValue(true);
@@ -119,7 +135,7 @@ DATABASE_URL=sqlite://local.db
119
135
  const written = mockedWrite.mock.calls[0][1];
120
136
  expect(written).toContain('NEW_VAR="new_value"');
121
137
  });
122
- it('returns error when .env.local not found', () => {
138
+ it(`returns error when ${ENV_FILE_NAME} not found`, () => {
123
139
  const server = createMockServer();
124
140
  registerEnvTools(server);
125
141
  mockedExists.mockReturnValue(false);
@@ -127,5 +143,12 @@ DATABASE_URL=sqlite://local.db
127
143
  const result = handler({ key: 'X', value: 'Y' });
128
144
  expect(result.isError).toBe(true);
129
145
  });
146
+ it('returns error for process env updates', () => {
147
+ const server = createMockServer();
148
+ registerEnvTools(server);
149
+ const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
150
+ const result = handler({ key: 'X', value: 'Y', env_source: 'process' });
151
+ expect(result.isError).toBe(true);
152
+ });
130
153
  });
131
154
  });
@@ -2,8 +2,10 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { findProjectRoot } from '../../utils/project.js';
5
+ import { ENV_FILE_NAME } from '../../utils/project-env.js';
5
6
  import { resolveManifest } from '../../utils/manifest.js';
6
7
  import { patchSchemaImports, patchSchemaTables, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../../utils/patchers.js';
8
+ import { envSourceSchema } from './schemas.js';
7
9
  function getRoot() {
8
10
  const root = findProjectRoot();
9
11
  if (!root)
@@ -42,8 +44,9 @@ export function registerPluginTools(server) {
42
44
  description: 'Install a Codapult plugin by name. Patches schema, config, pages, and env automatically.',
43
45
  inputSchema: {
44
46
  name: z.string().describe('Plugin name (e.g. "ai-kit", "video-player")'),
47
+ env_source: envSourceSchema.optional(),
45
48
  },
46
- }, ({ name }) => {
49
+ }, ({ name, env_source }) => {
47
50
  const root = getRoot();
48
51
  const result = resolveManifest(root, name);
49
52
  if (!result) {
@@ -88,8 +91,13 @@ export function registerPluginTools(server) {
88
91
  createPluginRegistration(root, manifest.name, manifest.package, 'add');
89
92
  steps.push('Plugin registered');
90
93
  if (manifest.install.env && Object.keys(manifest.install.env).length > 0) {
91
- patchEnvFile(root, manifest.name, manifest.install.env, 'add');
92
- steps.push('Env vars added to .env.local');
94
+ if (env_source === 'process') {
95
+ steps.push('Project uses process.env; add plugin env vars outside the CLI');
96
+ }
97
+ else {
98
+ patchEnvFile(root, manifest.name, manifest.install.env, 'add');
99
+ steps.push(`Env vars added to ${ENV_FILE_NAME}`);
100
+ }
93
101
  }
94
102
  const output = {
95
103
  plugin: manifest.name,
@@ -109,8 +117,9 @@ export function registerPluginTools(server) {
109
117
  description: 'Uninstall a Codapult plugin by name. Reverts all patches.',
110
118
  inputSchema: {
111
119
  name: z.string().describe('Plugin name to remove'),
120
+ env_source: envSourceSchema.optional(),
112
121
  },
113
- }, ({ name }) => {
122
+ }, ({ name, env_source }) => {
114
123
  const root = getRoot();
115
124
  const result = resolveManifest(root, name);
116
125
  const manifest = result?.manifest ?? {
@@ -146,8 +155,13 @@ export function registerPluginTools(server) {
146
155
  steps.push('next.config.ts reverted');
147
156
  }
148
157
  if (manifest.install.env && Object.keys(manifest.install.env).length > 0) {
149
- patchEnvFile(root, manifest.name, manifest.install.env, 'remove');
150
- steps.push('Env vars removed');
158
+ if (env_source === 'process') {
159
+ steps.push(`Project uses process.env; no ${ENV_FILE_NAME} env vars were removed`);
160
+ }
161
+ else {
162
+ patchEnvFile(root, manifest.name, manifest.install.env, 'remove');
163
+ steps.push('Env vars removed');
164
+ }
151
165
  }
152
166
  patchPackageJson(root, manifest.name, manifest.package, pluginDir, 'remove');
153
167
  steps.push('Dependency removed');
@@ -3,7 +3,9 @@ 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 { ENV_FILE_NAME, getProjectEnvOptions, loadProjectEnv } from '../../utils/project-env.js';
6
7
  import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, } from '../../utils/env-config.js';
8
+ import { envSourceSchema } from './schemas.js';
7
9
  function getRoot() {
8
10
  const root = findProjectRoot();
9
11
  if (!root)
@@ -14,11 +16,13 @@ export function registerProjectTools(server) {
14
16
  server.registerTool('codapult_project_status', {
15
17
  title: 'Project Status',
16
18
  description: 'Get Codapult project status: variant, adapters, installed plugins, enabled features, git status',
17
- inputSchema: {},
18
- }, () => {
19
+ inputSchema: {
20
+ env_source: envSourceSchema.optional(),
21
+ },
22
+ }, ({ env_source }) => {
19
23
  const root = getRoot();
20
24
  const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
21
- const envContent = readProjectFile(root, '.env.local') ?? '';
25
+ const envContent = loadProjectEnv(root, getProjectEnvOptions(env_source)).content;
22
26
  const pluginsDir = resolve(root, 'src/plugins');
23
27
  const plugins = existsSync(pluginsDir)
24
28
  ? readdirSync(pluginsDir)
@@ -58,7 +62,6 @@ export function registerProjectTools(server) {
58
62
  server.registerTool('codapult_project_config', {
59
63
  title: 'Project Config',
60
64
  description: 'Read the app configuration from src/config/app.ts (brand, auth, features)',
61
- inputSchema: {},
62
65
  }, () => {
63
66
  const root = getRoot();
64
67
  const content = readProjectFile(root, 'src/config/app.ts') ?? 'Config file not found';
@@ -102,8 +105,10 @@ export function registerProjectTools(server) {
102
105
  server.registerTool('codapult_doctor', {
103
106
  title: 'Doctor',
104
107
  description: 'Run project health checks: file structure, env vars, dependencies, TypeScript, git',
105
- inputSchema: {},
106
- }, () => {
108
+ inputSchema: {
109
+ env_source: envSourceSchema.optional(),
110
+ },
111
+ }, ({ env_source }) => {
107
112
  const root = getRoot();
108
113
  const checks = [];
109
114
  const requiredFiles = [
@@ -113,7 +118,6 @@ export function registerProjectTools(server) {
113
118
  'src/lib/auth/index.ts',
114
119
  'src/lib/payments/index.ts',
115
120
  'src/config/app.ts',
116
- '.env.local',
117
121
  ];
118
122
  for (const f of requiredFiles) {
119
123
  checks.push({
@@ -122,6 +126,20 @@ export function registerProjectTools(server) {
122
126
  detail: existsSync(resolve(root, f)) ? 'exists' : 'missing',
123
127
  });
124
128
  }
129
+ if (env_source === 'process') {
130
+ checks.push({
131
+ name: 'Environment source',
132
+ status: 'ok',
133
+ detail: 'process.env',
134
+ });
135
+ }
136
+ else {
137
+ checks.push({
138
+ name: ENV_FILE_NAME,
139
+ status: existsSync(resolve(root, ENV_FILE_NAME)) ? 'ok' : 'fail',
140
+ detail: existsSync(resolve(root, ENV_FILE_NAME)) ? 'exists' : 'missing',
141
+ });
142
+ }
125
143
  try {
126
144
  execSync('pnpm tsc --noEmit', { cwd: root, stdio: 'pipe', timeout: 60_000 });
127
145
  checks.push({ name: 'TypeScript', status: 'ok', detail: 'compiles cleanly' });