@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.
Files changed (67) hide show
  1. package/README.md +107 -3
  2. package/dist/commands/config-show.js +6 -32
  3. package/dist/commands/db.d.ts +2 -0
  4. package/dist/commands/db.js +81 -2
  5. package/dist/commands/deploy.js +44 -17
  6. package/dist/commands/doctor.d.ts +1 -1
  7. package/dist/commands/doctor.js +9 -234
  8. package/dist/commands/env.js +21 -17
  9. package/dist/commands/mcp.d.ts +5 -0
  10. package/dist/commands/mcp.js +98 -0
  11. package/dist/commands/plugins.js +40 -5
  12. package/dist/commands/setup.js +2 -2
  13. package/dist/index.js +24 -5
  14. package/dist/mcp/resources.js +34 -3
  15. package/dist/mcp/server.js +4 -1
  16. package/dist/mcp/tools/db.js +185 -49
  17. package/dist/mcp/tools/db.test.js +59 -7
  18. package/dist/mcp/tools/env.d.ts +7 -0
  19. package/dist/mcp/tools/env.js +96 -2
  20. package/dist/mcp/tools/env.test.js +4 -2
  21. package/dist/mcp/tools/generate.js +64 -10
  22. package/dist/mcp/tools/plugins.js +125 -13
  23. package/dist/mcp/tools/project.js +59 -46
  24. package/dist/mcp/tools/project.test.js +20 -8
  25. package/dist/utils/check-report.d.ts +18 -0
  26. package/dist/utils/check-report.js +30 -0
  27. package/dist/utils/command.d.ts +18 -0
  28. package/dist/utils/command.js +29 -0
  29. package/dist/utils/config-report.d.ts +12 -0
  30. package/dist/utils/config-report.js +41 -0
  31. package/dist/utils/config-report.test.d.ts +1 -0
  32. package/dist/utils/config-report.test.js +20 -0
  33. package/dist/utils/db-diff.d.ts +11 -0
  34. package/dist/utils/db-diff.js +37 -0
  35. package/dist/utils/env-compatibility.d.ts +10 -0
  36. package/dist/utils/env-compatibility.js +52 -0
  37. package/dist/utils/env-compatibility.test.d.ts +1 -0
  38. package/dist/utils/env-compatibility.test.js +23 -0
  39. package/dist/utils/env-config.d.ts +9 -0
  40. package/dist/utils/env-config.js +116 -4
  41. package/dist/utils/env-schema-parser.d.ts +2 -0
  42. package/dist/utils/env-schema-parser.js +32 -0
  43. package/dist/utils/env-schema-parser.test.d.ts +1 -0
  44. package/dist/utils/env-schema-parser.test.js +11 -0
  45. package/dist/utils/health-render.d.ts +3 -0
  46. package/dist/utils/health-render.js +28 -0
  47. package/dist/utils/health-render.test.d.ts +1 -0
  48. package/dist/utils/health-render.test.js +18 -0
  49. package/dist/utils/health.d.ts +26 -0
  50. package/dist/utils/health.js +249 -0
  51. package/dist/utils/live-db-diff.d.ts +17 -0
  52. package/dist/utils/live-db-diff.js +131 -0
  53. package/dist/utils/live-db-diff.test.d.ts +1 -0
  54. package/dist/utils/live-db-diff.test.js +29 -0
  55. package/dist/utils/manifest.d.ts +1 -0
  56. package/dist/utils/patchers.d.ts +2 -0
  57. package/dist/utils/patchers.js +25 -13
  58. package/dist/utils/patchers.test.js +41 -7
  59. package/dist/utils/schema-parity.d.ts +15 -0
  60. package/dist/utils/schema-parity.js +91 -0
  61. package/dist/utils/schema-parity.test.d.ts +1 -0
  62. package/dist/utils/schema-parity.test.js +27 -0
  63. package/dist/utils/schema-parser.d.ts +12 -0
  64. package/dist/utils/schema-parser.js +130 -0
  65. package/dist/utils/schema-parser.test.d.ts +1 -0
  66. package/dist/utils/schema-parser.test.js +59 -0
  67. package/package.json +2 -2
@@ -0,0 +1,30 @@
1
+ import { dim, fail, heading, success, warn } from './ui.js';
2
+ export function summarizeChecks(checks) {
3
+ const summary = {
4
+ ok: checks.filter((check) => check.status === 'ok').length,
5
+ warnings: checks.filter((check) => check.status === 'warn').length,
6
+ failures: checks.filter((check) => check.status === 'fail').length,
7
+ };
8
+ return {
9
+ status: summary.failures > 0 ? 'fail' : summary.warnings > 0 ? 'warn' : 'ok',
10
+ checks,
11
+ summary,
12
+ };
13
+ }
14
+ export function renderStructuredReport(title, report) {
15
+ heading(title);
16
+ for (const check of report.checks) {
17
+ if (check.status === 'ok')
18
+ success(check.message);
19
+ else if (check.status === 'fail')
20
+ fail(check.message);
21
+ else
22
+ warn(check.message);
23
+ if (check.status !== 'ok' && check.path)
24
+ dim(` Path: ${check.path}`);
25
+ }
26
+ if (report.summary.failures > 0)
27
+ fail(`${report.summary.failures} issue(s) found`);
28
+ if (report.summary.warnings > 0)
29
+ warn(`${report.summary.warnings} warning(s)`);
30
+ }
@@ -0,0 +1,18 @@
1
+ export interface CommandResult {
2
+ command: string;
3
+ passed: boolean;
4
+ exitCode: number;
5
+ stdout: string;
6
+ stderr: string;
7
+ }
8
+ export declare function runProjectCommand(command: string, cwd: string, options?: {
9
+ timeout?: number;
10
+ env?: NodeJS.ProcessEnv;
11
+ }): CommandResult;
12
+ export declare function commandResponse(result: CommandResult): {
13
+ content: {
14
+ type: 'text';
15
+ text: string;
16
+ }[];
17
+ isError: boolean;
18
+ };
@@ -0,0 +1,29 @@
1
+ import { execSync } from 'node:child_process';
2
+ export function runProjectCommand(command, cwd, options = {}) {
3
+ try {
4
+ const stdout = execSync(command, {
5
+ cwd,
6
+ env: { ...process.env, ...options.env },
7
+ stdio: 'pipe',
8
+ timeout: options.timeout ?? 120_000,
9
+ }).toString();
10
+ return { command, passed: true, exitCode: 0, stdout, stderr: '' };
11
+ }
12
+ catch (error) {
13
+ const execError = error;
14
+ const exitCode = execError.status ?? 1;
15
+ return {
16
+ command,
17
+ passed: exitCode === 0,
18
+ exitCode,
19
+ stdout: execError.stdout?.toString() ?? '',
20
+ stderr: execError.stderr?.toString() ?? '',
21
+ };
22
+ }
23
+ }
24
+ export function commandResponse(result) {
25
+ return {
26
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
27
+ isError: !result.passed,
28
+ };
29
+ }
@@ -0,0 +1,12 @@
1
+ export interface AppConfigSummary {
2
+ brand: Record<string, string>;
3
+ company: Record<string, string>;
4
+ ai: {
5
+ defaultModel?: string;
6
+ ragEnabled?: boolean;
7
+ ragMaxChunks?: string;
8
+ ragMinScore?: string;
9
+ };
10
+ }
11
+ /** Read the stable, displayable subset of app.ts for both CLI and MCP clients. */
12
+ export declare function collectAppConfigSummary(root: string): AppConfigSummary | undefined;
@@ -0,0 +1,41 @@
1
+ import { readProjectFile } from './project.js';
2
+ function stringField(content, field) {
3
+ const quotes = '[\'"` ]'.replace(' ', '');
4
+ return new RegExp('\\b' + field + '\\s*:\\s*' + quotes + '([^\'"`]+)' + quotes).exec(content)?.[1];
5
+ }
6
+ function numberField(content, field) {
7
+ return new RegExp(`\\b${field}\\s*:\\s*([\\d.]+)`).exec(content)?.[1];
8
+ }
9
+ function booleanField(content, field) {
10
+ const value = new RegExp(`\\b${field}\\s*:\\s*(true|false)`).exec(content)?.[1];
11
+ return value === undefined ? undefined : value === 'true';
12
+ }
13
+ function strings(content, fields) {
14
+ return Object.fromEntries(fields.flatMap((field) => {
15
+ const value = stringField(content, field);
16
+ return value === undefined ? [] : [[field, value]];
17
+ }));
18
+ }
19
+ /** Read the stable, displayable subset of app.ts for both CLI and MCP clients. */
20
+ export function collectAppConfigSummary(root) {
21
+ const content = readProjectFile(root, 'src/config/app.ts');
22
+ if (!content)
23
+ return undefined;
24
+ const ai = { defaultModel: stringField(content, 'defaultModel') };
25
+ const ragEnabled = booleanField(content, 'ragEnabled');
26
+ const ragMaxChunks = numberField(content, 'ragMaxChunks');
27
+ const ragMinScore = numberField(content, 'ragMinScore');
28
+ if (ai.defaultModel === undefined)
29
+ delete ai.defaultModel;
30
+ if (ragEnabled !== undefined)
31
+ ai.ragEnabled = ragEnabled;
32
+ if (ragMaxChunks !== undefined)
33
+ ai.ragMaxChunks = ragMaxChunks;
34
+ if (ragMinScore !== undefined)
35
+ ai.ragMinScore = ragMinScore;
36
+ return {
37
+ brand: strings(content, ['name', 'description', 'logo', 'favicon']),
38
+ company: strings(content, ['contactEmail', 'githubUrl']),
39
+ ai,
40
+ };
41
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ vi.mock('./project.js', () => ({ readProjectFile: vi.fn() }));
3
+ const { readProjectFile } = await import('./project.js');
4
+ const { collectAppConfigSummary } = await import('./config-report.js');
5
+ describe('collectAppConfigSummary', () => {
6
+ it('returns the shared displayable app config subset', () => {
7
+ vi.mocked(readProjectFile).mockReturnValue(`
8
+ export const appConfig = {
9
+ brand: { name: 'Codapult', description: 'Starter', logo: '/logo.svg' },
10
+ company: { contactEmail: 'hello@example.com', githubUrl: 'https://github.com/codapult' },
11
+ ai: { defaultModel: 'gpt-5', ragEnabled: true, ragMaxChunks: 12, ragMinScore: 0.4 },
12
+ };
13
+ `);
14
+ expect(collectAppConfigSummary('/project')).toEqual({
15
+ brand: { name: 'Codapult', description: 'Starter', logo: '/logo.svg' },
16
+ company: { contactEmail: 'hello@example.com', githubUrl: 'https://github.com/codapult' },
17
+ ai: { defaultModel: 'gpt-5', ragEnabled: true, ragMaxChunks: '12', ragMinScore: '0.4' },
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,11 @@
1
+ import { type CommandResult } from './command.js';
2
+ export interface MigrationPreview {
3
+ command: CommandResult;
4
+ provider: 'turso' | 'postgres';
5
+ schemaPath: string;
6
+ migrationFiles: {
7
+ name: string;
8
+ sql: string;
9
+ }[];
10
+ }
11
+ export declare function previewMigration(root: string, provider: 'turso' | 'postgres', schemaPath: string): MigrationPreview;
@@ -0,0 +1,37 @@
1
+ import { cpSync, existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
2
+ import { relative, resolve } from 'node:path';
3
+ import { runProjectCommand } from './command.js';
4
+ function shellQuote(value) {
5
+ return `'${value.replaceAll("'", "'\\''")}'`;
6
+ }
7
+ export function previewMigration(root, provider, schemaPath) {
8
+ const tempRoot = mkdtempSync(resolve(root, '.codapult-mcp-diff-'));
9
+ const sourceMigrations = resolve(root, provider === 'postgres' ? 'src/lib/db/migrations-pg' : 'src/lib/db/migrations');
10
+ const tempMigrations = resolve(tempRoot, 'migrations');
11
+ try {
12
+ if (existsSync(sourceMigrations)) {
13
+ cpSync(sourceMigrations, tempMigrations, { recursive: true });
14
+ }
15
+ const command = [
16
+ 'pnpm exec drizzle-kit generate',
17
+ '--schema',
18
+ shellQuote(resolve(root, schemaPath)),
19
+ '--out',
20
+ shellQuote(relative(root, tempMigrations)),
21
+ '--dialect',
22
+ provider === 'postgres' ? 'postgresql' : 'turso',
23
+ '--name',
24
+ 'codapult-mcp-preview',
25
+ ].join(' ');
26
+ const result = runProjectCommand(command, root, { timeout: 120_000 });
27
+ const migrationFiles = result.passed && existsSync(tempMigrations)
28
+ ? readdirSync(tempMigrations)
29
+ .filter((file) => file.endsWith('.sql') && file.includes('codapult-mcp-preview'))
30
+ .map((name) => ({ name, sql: readFileSync(resolve(tempMigrations, name), 'utf-8') }))
31
+ : [];
32
+ return { command: result, provider, schemaPath, migrationFiles };
33
+ }
34
+ finally {
35
+ rmSync(tempRoot, { recursive: true, force: true });
36
+ }
37
+ }
@@ -0,0 +1,10 @@
1
+ export interface EnvSchemaCompatibility {
2
+ status: 'ok' | 'warn' | 'fail';
3
+ schemaPath: string;
4
+ schemaKeys: string[];
5
+ expectedKeys: string[];
6
+ schemaOnly: string[];
7
+ mirrorOnly: string[];
8
+ message: string;
9
+ }
10
+ export declare function checkEnvSchemaCompatibility(root: string): EnvSchemaCompatibility;
@@ -0,0 +1,52 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { readProjectFile } from './project.js';
4
+ import { extractEnvSchemaKeys } from './env-schema-parser.js';
5
+ import { ENV_SCHEMA_KEYS } from './env-config.js';
6
+ export function checkEnvSchemaCompatibility(root) {
7
+ const schemaPath = 'src/config/env-schema.ts';
8
+ const absolutePath = resolve(root, schemaPath);
9
+ if (!existsSync(absolutePath)) {
10
+ return {
11
+ status: 'fail',
12
+ schemaPath,
13
+ schemaKeys: [],
14
+ expectedKeys: [...ENV_SCHEMA_KEYS],
15
+ schemaOnly: [],
16
+ mirrorOnly: [...ENV_SCHEMA_KEYS],
17
+ message: 'Environment schema is missing',
18
+ };
19
+ }
20
+ const content = readProjectFile(root, schemaPath) ?? '';
21
+ let schemaKeys;
22
+ try {
23
+ schemaKeys = extractEnvSchemaKeys(content);
24
+ }
25
+ catch (error) {
26
+ return {
27
+ status: 'fail',
28
+ schemaPath,
29
+ schemaKeys: [],
30
+ expectedKeys: [...ENV_SCHEMA_KEYS],
31
+ schemaOnly: [],
32
+ mirrorOnly: [...ENV_SCHEMA_KEYS],
33
+ message: `Could not parse environment schema: ${String(error)}`,
34
+ };
35
+ }
36
+ const actual = new Set(schemaKeys);
37
+ const expected = new Set(ENV_SCHEMA_KEYS);
38
+ const schemaOnly = schemaKeys.filter((key) => !expected.has(key));
39
+ const mirrorOnly = ENV_SCHEMA_KEYS.filter((key) => !actual.has(key));
40
+ const drift = schemaOnly.length > 0 || mirrorOnly.length > 0;
41
+ return {
42
+ status: drift ? 'warn' : 'ok',
43
+ schemaPath,
44
+ schemaKeys,
45
+ expectedKeys: [...ENV_SCHEMA_KEYS],
46
+ schemaOnly,
47
+ mirrorOnly,
48
+ message: drift
49
+ ? `Environment schema drift detected (${schemaOnly.length} added, ${mirrorOnly.length} missing)`
50
+ : `Environment schema is compatible (${schemaKeys.length} variables)`,
51
+ };
52
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { checkEnvSchemaCompatibility } from './env-compatibility.js';
3
+ vi.mock('node:fs', () => ({ existsSync: vi.fn(() => true) }));
4
+ vi.mock('./project.js', () => ({ readProjectFile: vi.fn() }));
5
+ const { readProjectFile } = await import('./project.js');
6
+ const mockedRead = vi.mocked(readProjectFile);
7
+ describe('checkEnvSchemaCompatibility', () => {
8
+ it('reports a compatible host schema', async () => {
9
+ const { ENV_SCHEMA_KEYS } = await import('./env-config.js');
10
+ mockedRead.mockReturnValue(`export const envSchema = z.object({ ${ENV_SCHEMA_KEYS.map((key) => `${key}: z.string()`).join(', ')} });`);
11
+ const result = checkEnvSchemaCompatibility('/project');
12
+ expect(result.status).toBe('ok');
13
+ expect(result.schemaOnly).toEqual([]);
14
+ expect(result.mirrorOnly).toEqual([]);
15
+ });
16
+ it('reports variables added to or removed from the host schema', () => {
17
+ mockedRead.mockReturnValue('export const envSchema = z.object({ APP_MODE: z.string(), NEW_KEY: z.string() });');
18
+ const result = checkEnvSchemaCompatibility('/project');
19
+ expect(result.status).toBe('warn');
20
+ expect(result.schemaOnly).toEqual(['NEW_KEY']);
21
+ expect(result.mirrorOnly.length).toBeGreaterThan(0);
22
+ });
23
+ });
@@ -17,8 +17,16 @@ export type JobProvider = 'memory' | 'bullmq' | 'none';
17
17
  export type NotificationTransport = 'poll' | 'sse' | 'ws';
18
18
  export type EmbeddingProvider = 'openai' | 'ollama';
19
19
  export type VectorStoreProvider = 'sqlite' | 'memory';
20
+ export type SupportProvider = 'crisp' | 'intercom' | 'none';
20
21
  /** Feature toggle key → ENABLE_* env var. Order = display order. */
21
22
  export declare const FEATURE_ENV: Readonly<Record<string, string>>;
23
+ /**
24
+ * Snapshot of the host env-schema contract. The compatibility check compares
25
+ * this explicit contract with `src/config/env-schema.ts`; adding a variable to
26
+ * the template therefore produces an actionable doctor warning until the CLI
27
+ * mirror is reviewed.
28
+ */
29
+ export declare const ENV_SCHEMA_KEYS: readonly ["NEXT_PUBLIC_APP_URL", "NEXT_PUBLIC_APP_NAME", "APP_MODE", "DEMO_URL", "LOG_LEVEL", "DB_PROVIDER", "AUTH_PROVIDER", "PAYMENT_PROVIDER", "STORAGE_PROVIDER", "JOB_PROVIDER", "SSO_PROVIDER", "NOTIFICATION_TRANSPORT", "EMBEDDING_PROVIDER", "VECTOR_STORE_PROVIDER", "SUPPORT_PROVIDER", "TURSO_DATABASE_URL", "TURSO_AUTH_TOKEN", "DATABASE_URL", "ENABLE_TWO_FACTOR", "AUTH_MAGIC_LINK", "AUTH_PASSKEYS", "BETTER_AUTH_SECRET", "BETTER_AUTH_URL", "KINDE_CLIENT_ID", "KINDE_CLIENT_SECRET", "KINDE_ISSUER_URL", "GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", "GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET", "APPLE_CLIENT_ID", "APPLE_CLIENT_SECRET", "DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET", "TWITTER_CLIENT_ID", "TWITTER_CLIENT_SECRET", "MICROSOFT_CLIENT_ID", "MICROSOFT_CLIENT_SECRET", "STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET", "STRIPE_CONNECT_FEE_PERCENT", "STRIPE_CONNECT_ONBOARDING_RETURN_URL", "STRIPE_CONNECT_ONBOARDING_REFRESH_URL", "LEMONSQUEEZY_API_KEY", "LEMONSQUEEZY_STORE_ID", "LEMONSQUEEZY_WEBHOOK_SECRET", "POLAR_ACCESS_TOKEN", "POLAR_WEBHOOK_SECRET", "S3_BUCKET", "S3_REGION", "S3_ENDPOINT", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY", "S3_PUBLIC_URL", "JOB_QUEUE_NAME", "REDIS_URL", "CODAPULT_WORKER_MODE", "CODAPULT_DISABLE_IN_PROCESS_JOBS", "CUSTOM_DOMAIN_CNAME_TARGET", "REFERRAL_REWARD_AMOUNT", "REFERRAL_REWARD_TYPE", "SSO_PRODUCT", "SSO_DB_ENGINE", "SSO_DB_TYPE", "SSO_DB_URL", "NOTIFICATION_WS_URL", "NOTIFICATION_WS_PORT", "OPENAI_API_KEY", "ANTHROPIC_API_KEY", "OLLAMA_BASE_URL", "OLLAMA_EMBEDDING_MODEL", "RESEND_API_KEY", "EMAIL_FROM", "CRISP_WEBSITE_ID", "INTERCOM_APP_ID", "DEFAULT_MONTHLY_CREDITS", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_SERVICE_NAME", "OTEL_TRACES_SAMPLE_RATE", "OTEL_EXPORTER_OTLP_HEADERS", "POSTHOG_TOKEN", "POSTHOG_HOST", "POSTHOG_UI_HOST", ...string[]];
22
30
  /** Auth-gated features: when AUTH_PROVIDER=none, these are forced off. */
23
31
  export declare const AUTH_GATED_FEATURES: ReadonlySet<string>;
24
32
  /** OAuth provider → [client id env, client secret env]. Mirrors oauth-providers.ts. */
@@ -37,6 +45,7 @@ export interface Adapters {
37
45
  notifications: NotificationTransport;
38
46
  embedding: EmbeddingProvider;
39
47
  vectorStore: VectorStoreProvider;
48
+ support: SupportProvider;
40
49
  }
41
50
  /** Resolve all adapters from .env content, applying the same defaults as `env.*`. */
42
51
  export declare function getAdapters(envContent: string): Adapters;
@@ -29,7 +29,100 @@ export const FEATURE_ENV = {
29
29
  experiments: 'ENABLE_EXPERIMENTS',
30
30
  dripCampaigns: 'ENABLE_DRIP_CAMPAIGNS',
31
31
  plugins: 'ENABLE_PLUGINS',
32
+ compare: 'ENABLE_COMPARE',
32
33
  };
34
+ /**
35
+ * Snapshot of the host env-schema contract. The compatibility check compares
36
+ * this explicit contract with `src/config/env-schema.ts`; adding a variable to
37
+ * the template therefore produces an actionable doctor warning until the CLI
38
+ * mirror is reviewed.
39
+ */
40
+ export const ENV_SCHEMA_KEYS = [
41
+ 'NEXT_PUBLIC_APP_URL',
42
+ 'NEXT_PUBLIC_APP_NAME',
43
+ 'APP_MODE',
44
+ 'DEMO_URL',
45
+ 'LOG_LEVEL',
46
+ 'DB_PROVIDER',
47
+ 'AUTH_PROVIDER',
48
+ 'PAYMENT_PROVIDER',
49
+ 'STORAGE_PROVIDER',
50
+ 'JOB_PROVIDER',
51
+ 'SSO_PROVIDER',
52
+ 'NOTIFICATION_TRANSPORT',
53
+ 'EMBEDDING_PROVIDER',
54
+ 'VECTOR_STORE_PROVIDER',
55
+ 'SUPPORT_PROVIDER',
56
+ 'TURSO_DATABASE_URL',
57
+ 'TURSO_AUTH_TOKEN',
58
+ 'DATABASE_URL',
59
+ 'ENABLE_TWO_FACTOR',
60
+ 'AUTH_MAGIC_LINK',
61
+ 'AUTH_PASSKEYS',
62
+ 'BETTER_AUTH_SECRET',
63
+ 'BETTER_AUTH_URL',
64
+ 'KINDE_CLIENT_ID',
65
+ 'KINDE_CLIENT_SECRET',
66
+ 'KINDE_ISSUER_URL',
67
+ 'GOOGLE_CLIENT_ID',
68
+ 'GOOGLE_CLIENT_SECRET',
69
+ 'GITHUB_CLIENT_ID',
70
+ 'GITHUB_CLIENT_SECRET',
71
+ 'APPLE_CLIENT_ID',
72
+ 'APPLE_CLIENT_SECRET',
73
+ 'DISCORD_CLIENT_ID',
74
+ 'DISCORD_CLIENT_SECRET',
75
+ 'TWITTER_CLIENT_ID',
76
+ 'TWITTER_CLIENT_SECRET',
77
+ 'MICROSOFT_CLIENT_ID',
78
+ 'MICROSOFT_CLIENT_SECRET',
79
+ 'STRIPE_SECRET_KEY',
80
+ 'STRIPE_WEBHOOK_SECRET',
81
+ 'STRIPE_CONNECT_FEE_PERCENT',
82
+ 'STRIPE_CONNECT_ONBOARDING_RETURN_URL',
83
+ 'STRIPE_CONNECT_ONBOARDING_REFRESH_URL',
84
+ 'LEMONSQUEEZY_API_KEY',
85
+ 'LEMONSQUEEZY_STORE_ID',
86
+ 'LEMONSQUEEZY_WEBHOOK_SECRET',
87
+ 'POLAR_ACCESS_TOKEN',
88
+ 'POLAR_WEBHOOK_SECRET',
89
+ 'S3_BUCKET',
90
+ 'S3_REGION',
91
+ 'S3_ENDPOINT',
92
+ 'S3_ACCESS_KEY_ID',
93
+ 'S3_SECRET_ACCESS_KEY',
94
+ 'S3_PUBLIC_URL',
95
+ 'JOB_QUEUE_NAME',
96
+ 'REDIS_URL',
97
+ 'CODAPULT_WORKER_MODE',
98
+ 'CODAPULT_DISABLE_IN_PROCESS_JOBS',
99
+ 'CUSTOM_DOMAIN_CNAME_TARGET',
100
+ 'REFERRAL_REWARD_AMOUNT',
101
+ 'REFERRAL_REWARD_TYPE',
102
+ 'SSO_PRODUCT',
103
+ 'SSO_DB_ENGINE',
104
+ 'SSO_DB_TYPE',
105
+ 'SSO_DB_URL',
106
+ 'NOTIFICATION_WS_URL',
107
+ 'NOTIFICATION_WS_PORT',
108
+ 'OPENAI_API_KEY',
109
+ 'ANTHROPIC_API_KEY',
110
+ 'OLLAMA_BASE_URL',
111
+ 'OLLAMA_EMBEDDING_MODEL',
112
+ 'RESEND_API_KEY',
113
+ 'EMAIL_FROM',
114
+ 'CRISP_WEBSITE_ID',
115
+ 'INTERCOM_APP_ID',
116
+ 'DEFAULT_MONTHLY_CREDITS',
117
+ 'OTEL_EXPORTER_OTLP_ENDPOINT',
118
+ 'OTEL_SERVICE_NAME',
119
+ 'OTEL_TRACES_SAMPLE_RATE',
120
+ 'OTEL_EXPORTER_OTLP_HEADERS',
121
+ 'POSTHOG_TOKEN',
122
+ 'POSTHOG_HOST',
123
+ 'POSTHOG_UI_HOST',
124
+ ...Object.values(FEATURE_ENV),
125
+ ];
33
126
  /** Auth-gated features: when AUTH_PROVIDER=none, these are forced off. */
34
127
  export const AUTH_GATED_FEATURES = new Set([
35
128
  'apiDocs',
@@ -60,9 +153,11 @@ export function readEnv(envContent, key, fallback) {
60
153
  }
61
154
  /** Resolve all adapters from .env content, applying the same defaults as `env.*`. */
62
155
  export function getAdapters(envContent) {
156
+ const landingMode = readEnv(envContent, 'APP_MODE', 'app') === 'landing';
157
+ const authProvider = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth');
63
158
  return {
64
159
  database: readEnv(envContent, 'DB_PROVIDER', 'turso'),
65
- auth: readEnv(envContent, 'AUTH_PROVIDER', 'better-auth'),
160
+ auth: landingMode ? 'none' : authProvider,
66
161
  sso: readEnv(envContent, 'SSO_PROVIDER', 'none'),
67
162
  payments: readEnv(envContent, 'PAYMENT_PROVIDER', 'stripe'),
68
163
  storage: readEnv(envContent, 'STORAGE_PROVIDER', 'local'),
@@ -70,6 +165,7 @@ export function getAdapters(envContent) {
70
165
  notifications: readEnv(envContent, 'NOTIFICATION_TRANSPORT', 'poll'),
71
166
  embedding: readEnv(envContent, 'EMBEDDING_PROVIDER', 'openai'),
72
167
  vectorStore: readEnv(envContent, 'VECTOR_STORE_PROVIDER', 'sqlite'),
168
+ support: readEnv(envContent, 'SUPPORT_PROVIDER', 'none'),
73
169
  };
74
170
  }
75
171
  /**
@@ -81,18 +177,20 @@ export function getAdapters(envContent) {
81
177
  * - auth-gated features forced off when AUTH_PROVIDER=none.
82
178
  */
83
179
  export function getFeatures(envContent) {
84
- const authProvider = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth');
180
+ const appMode = readEnv(envContent, 'APP_MODE', 'app');
181
+ const authProvider = getAdapters(envContent).auth;
85
182
  const authEnabled = authProvider !== 'none';
86
183
  const features = { auth: authEnabled };
87
184
  for (const [key, envVar] of Object.entries(FEATURE_ENV)) {
88
185
  const raw = readEnvVar(envContent, envVar);
89
- const enabled = raw !== 'false';
186
+ const defaultEnabled = key === 'compare' ? appMode === 'landing' : true;
187
+ const enabled = raw == null ? defaultEnabled : raw !== 'false';
90
188
  features[key] = enabled && (!AUTH_GATED_FEATURES.has(key) || authEnabled);
91
189
  }
92
190
  return features;
93
191
  }
94
192
  export function getAuthMethods(envContent) {
95
- const authEnabled = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth') !== 'none';
193
+ const authEnabled = getAdapters(envContent).auth !== 'none';
96
194
  return {
97
195
  twoFactor: authEnabled && readEnvVar(envContent, 'ENABLE_TWO_FACTOR') !== 'false',
98
196
  magicLink: (readEnvVar(envContent, 'AUTH_MAGIC_LINK') ?? 'true') === 'true',
@@ -207,5 +305,19 @@ export function findProviderIssues(envContent) {
207
305
  severity: 'error',
208
306
  });
209
307
  }
308
+ if (adapters.support === 'crisp' && !has('CRISP_WEBSITE_ID')) {
309
+ issues.push({
310
+ key: 'CRISP_WEBSITE_ID',
311
+ message: 'Required when SUPPORT_PROVIDER="crisp"',
312
+ severity: 'error',
313
+ });
314
+ }
315
+ if (adapters.support === 'intercom' && !has('INTERCOM_APP_ID')) {
316
+ issues.push({
317
+ key: 'INTERCOM_APP_ID',
318
+ message: 'Required when SUPPORT_PROVIDER="intercom"',
319
+ severity: 'error',
320
+ });
321
+ }
210
322
  return issues;
211
323
  }
@@ -0,0 +1,2 @@
1
+ /** Extract keys from the z.object({...}) assigned to envSchema, independent of formatting/chaining. */
2
+ export declare function extractEnvSchemaKeys(content: string): string[];
@@ -0,0 +1,32 @@
1
+ import ts from 'typescript';
2
+ function propertyName(node) {
3
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node))
4
+ return node.text;
5
+ return undefined;
6
+ }
7
+ /** Extract keys from the z.object({...}) assigned to envSchema, independent of formatting/chaining. */
8
+ export function extractEnvSchemaKeys(content) {
9
+ const sourceFile = ts.createSourceFile('env-schema.ts', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
10
+ const keys = [];
11
+ const visit = (node) => {
12
+ if (ts.isCallExpression(node) &&
13
+ ts.isPropertyAccessExpression(node.expression) &&
14
+ node.expression.name.text === 'object') {
15
+ const object = node.arguments[0];
16
+ if (node.arguments.length > 0 && ts.isObjectLiteralExpression(object)) {
17
+ for (const property of object.properties) {
18
+ if (ts.isPropertyAssignment(property) ||
19
+ ts.isMethodDeclaration(property) ||
20
+ ts.isGetAccessorDeclaration(property)) {
21
+ const name = propertyName(property.name);
22
+ if (name)
23
+ keys.push(name);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ ts.forEachChild(node, visit);
29
+ };
30
+ visit(sourceFile);
31
+ return [...new Set(keys)];
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { extractEnvSchemaKeys } from './env-schema-parser.js';
3
+ describe('extractEnvSchemaKeys', () => {
4
+ it('finds z.object keys through chained calls and comments', () => {
5
+ expect(extractEnvSchemaKeys(`
6
+ export const envSchema = z
7
+ .object({ APP_MODE: z.string(), 'CUSTOM_KEY': z.string(), })
8
+ .superRefine(() => {});
9
+ `)).toEqual(['APP_MODE', 'CUSTOM_KEY']);
10
+ });
11
+ });
@@ -0,0 +1,3 @@
1
+ import type { ProjectHealthReport } from './health.js';
2
+ export declare function healthExitCode(report: ProjectHealthReport): number;
3
+ export declare function renderHealthReport(title: string, report: ProjectHealthReport): void;
@@ -0,0 +1,28 @@
1
+ import { dim, fail, heading, label, success, warn } from './ui.js';
2
+ export function healthExitCode(report) {
3
+ return report.summary.failures > 0 ? 1 : 0;
4
+ }
5
+ export function renderHealthReport(title, report) {
6
+ heading(title);
7
+ label('Project root', report.root);
8
+ console.log();
9
+ for (const check of report.checks) {
10
+ if (check.status === 'ok')
11
+ success(check.message);
12
+ else if (check.status === 'fail')
13
+ fail(check.message);
14
+ else
15
+ warn(check.message);
16
+ if (check.status !== 'ok' && check.path)
17
+ dim(` Path: ${check.path}`);
18
+ }
19
+ console.log();
20
+ if (report.status === 'ok')
21
+ success('Everything looks good!');
22
+ else {
23
+ if (report.summary.failures > 0)
24
+ fail(`${report.summary.failures} issue(s) found`);
25
+ if (report.summary.warnings > 0)
26
+ warn(`${report.summary.warnings} warning(s)`);
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { healthExitCode } from './health-render.js';
3
+ describe('healthExitCode', () => {
4
+ it('fails CI only when the health report contains failures', () => {
5
+ expect(healthExitCode({
6
+ root: '/',
7
+ status: 'warn',
8
+ checks: [],
9
+ summary: { ok: 0, warnings: 1, failures: 0 },
10
+ })).toBe(0);
11
+ expect(healthExitCode({
12
+ root: '/',
13
+ status: 'fail',
14
+ checks: [],
15
+ summary: { ok: 0, warnings: 0, failures: 1 },
16
+ })).toBe(1);
17
+ });
18
+ });
@@ -0,0 +1,26 @@
1
+ import { type ProjectEnvSource } from './project-env.js';
2
+ export type HealthStatus = 'ok' | 'warn' | 'fail';
3
+ export interface HealthCheck {
4
+ id: string;
5
+ status: HealthStatus;
6
+ message: string;
7
+ path?: string;
8
+ details?: unknown;
9
+ }
10
+ export interface ProjectHealthReport {
11
+ root: string;
12
+ status: HealthStatus;
13
+ checks: HealthCheck[];
14
+ summary: {
15
+ ok: number;
16
+ warnings: number;
17
+ failures: number;
18
+ };
19
+ }
20
+ export interface ProjectHealthOptions {
21
+ envSource?: ProjectEnvSource;
22
+ includeCommands?: boolean;
23
+ }
24
+ export declare function collectProjectHealth(root?: string, options?: ProjectHealthOptions): ProjectHealthReport;
25
+ /** Project health plus checks specific to the editor-facing MCP installation. */
26
+ export declare function collectMcpHealth(root?: string, options?: ProjectHealthOptions): ProjectHealthReport;