@celljs/cli 4.3.0 → 4.4.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 (106) hide show
  1. package/README.md +32 -25
  2. package/agent/guide.md +15 -6
  3. package/docs/coding-agents.md +79 -0
  4. package/docs/components.md +157 -0
  5. package/docs/deployment.md +111 -0
  6. package/docs/frontend.md +180 -0
  7. package/docs/getting-started.md +159 -0
  8. package/docs/packages.md +94 -0
  9. package/docs/project.md +181 -0
  10. package/docs/testing.md +78 -0
  11. package/docs/web.md +168 -0
  12. package/lib/agent/agent-guide.js +1 -1
  13. package/lib/agent/agent-guide.js.map +1 -1
  14. package/lib/build/single-compile.spec.js +2 -2
  15. package/lib/build/single-compile.spec.js.map +1 -1
  16. package/lib/check/project-checker.d.ts +20 -0
  17. package/lib/check/project-checker.d.ts.map +1 -1
  18. package/lib/check/project-checker.js +87 -23
  19. package/lib/check/project-checker.js.map +1 -1
  20. package/lib/check/project-checker.spec.js +19 -3
  21. package/lib/check/project-checker.spec.js.map +1 -1
  22. package/lib/cli/build-command.js +2 -2
  23. package/lib/cli/build-command.js.map +1 -1
  24. package/lib/cli/cell-cli.spec.js +12 -12
  25. package/lib/cli/cell-cli.spec.js.map +1 -1
  26. package/lib/cli/config-command.d.ts +3 -3
  27. package/lib/cli/config-command.d.ts.map +1 -1
  28. package/lib/cli/config-command.js +12 -8
  29. package/lib/cli/config-command.js.map +1 -1
  30. package/lib/cli/config-command.spec.js +38 -26
  31. package/lib/cli/config-command.spec.js.map +1 -1
  32. package/lib/cli/dev-command.js +2 -2
  33. package/lib/cli/dev-command.js.map +1 -1
  34. package/lib/cli/dev-command.spec.js +7 -7
  35. package/lib/cli/dev-command.spec.js.map +1 -1
  36. package/lib/cli/docs-command.d.ts +3 -2
  37. package/lib/cli/docs-command.d.ts.map +1 -1
  38. package/lib/cli/docs-command.js +3 -2
  39. package/lib/cli/docs-command.js.map +1 -1
  40. package/lib/cli/info-command.spec.js +28 -26
  41. package/lib/cli/info-command.spec.js.map +1 -1
  42. package/lib/cli/mcp-command.spec.js +5 -5
  43. package/lib/cli/mcp-command.spec.js.map +1 -1
  44. package/lib/cli/preview-command.js +3 -3
  45. package/lib/cli/preview-command.js.map +1 -1
  46. package/lib/config/config-build.spec.js +4 -4
  47. package/lib/config/config-build.spec.js.map +1 -1
  48. package/lib/config/config-explainer.d.ts +16 -11
  49. package/lib/config/config-explainer.d.ts.map +1 -1
  50. package/lib/config/config-explainer.js +31 -29
  51. package/lib/config/config-explainer.js.map +1 -1
  52. package/lib/docs/docs-index.d.ts +4 -1
  53. package/lib/docs/docs-index.d.ts.map +1 -1
  54. package/lib/docs/docs-index.js +6 -1
  55. package/lib/docs/docs-index.js.map +1 -1
  56. package/lib/docs/docs-index.spec.js +14 -4
  57. package/lib/docs/docs-index.spec.js.map +1 -1
  58. package/lib/info/project-inspector.d.ts +6 -5
  59. package/lib/info/project-inspector.d.ts.map +1 -1
  60. package/lib/info/project-inspector.js +10 -15
  61. package/lib/info/project-inspector.js.map +1 -1
  62. package/lib/mcp/dev-mcp-endpoint.js +3 -3
  63. package/lib/mcp/dev-mcp-endpoint.js.map +1 -1
  64. package/lib/mcp/dev-mcp-endpoint.spec.js +2 -2
  65. package/lib/mcp/dev-mcp-endpoint.spec.js.map +1 -1
  66. package/lib/mcp/project-mcp-tools.js +3 -3
  67. package/lib/mcp/project-mcp-tools.js.map +1 -1
  68. package/lib/modules/module-host.spec.js +1 -1
  69. package/lib/modules/module-host.spec.js.map +1 -1
  70. package/lib/preset/builtin-presets.d.ts +1 -1
  71. package/lib/preset/builtin-presets.d.ts.map +1 -1
  72. package/lib/preset/builtin-presets.js +1 -1
  73. package/lib/preset/builtin-presets.js.map +1 -1
  74. package/lib/preset/cloudflare/cloudflare.spec.js +2 -2
  75. package/lib/preset/cloudflare/cloudflare.spec.js.map +1 -1
  76. package/lib/preset/serverless-presets.spec.js +3 -3
  77. package/lib/preset/serverless-presets.spec.js.map +1 -1
  78. package/lib/preset/serverless-scripts.js +2 -2
  79. package/lib/preset/serverless-scripts.js.map +1 -1
  80. package/lib/preset/vercel/vercel-preset.js +2 -2
  81. package/lib/preset/vercel/vercel-preset.js.map +1 -1
  82. package/lib/testing/create-test-app.spec.js +5 -5
  83. package/lib/testing/create-test-app.spec.js.map +1 -1
  84. package/package.json +9 -8
  85. package/src/agent/agent-guide.ts +1 -1
  86. package/src/check/project-checker.ts +93 -22
  87. package/src/cli/build-command.ts +2 -2
  88. package/src/cli/config-command.ts +12 -8
  89. package/src/cli/dev-command.ts +2 -2
  90. package/src/cli/docs-command.ts +3 -2
  91. package/src/cli/preview-command.ts +3 -3
  92. package/src/config/config-explainer.ts +36 -32
  93. package/src/docs/docs-index.ts +7 -1
  94. package/src/info/project-inspector.ts +15 -22
  95. package/src/mcp/dev-mcp-endpoint.ts +3 -3
  96. package/src/mcp/project-mcp-tools.ts +3 -3
  97. package/src/preset/builtin-presets.ts +1 -1
  98. package/src/preset/serverless-scripts.ts +2 -2
  99. package/src/preset/vercel/vercel-preset.ts +2 -2
  100. package/templates/backend/cell.yml +5 -3
  101. package/templates/backend/src/node/home-controller.ts +1 -1
  102. package/templates/backend/template.json +1 -1
  103. package/templates/fullstack/cell.yml +7 -6
  104. package/templates/fullstack/src/browser/module.ts +1 -1
  105. package/templates/fullstack/src/browser/{home.view.tsx → pages/index.tsx} +3 -7
  106. package/templates/fullstack/src/node/greeting-server.ts +1 -1
@@ -3,7 +3,7 @@ import { existsSync, readFileSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import { dirname, isAbsolute, join, resolve } from 'node:path';
5
5
  import { CellError, type CheckIssue } from '@celljs/kit';
6
- import { CellDevServer, ProjectLoader } from '@celljs/vite';
6
+ import { CellDevServer, OutputWriter, ProjectLoader } from '@celljs/vite';
7
7
  import { ProjectInspector } from '../info/project-inspector.js';
8
8
  import type { Toolchain } from '../toolchain/toolchain.js';
9
9
 
@@ -32,7 +32,11 @@ interface Check {
32
32
  * and the checks of toolchain modules. Every finding is a CheckIssue with a stable code.
33
33
  */
34
34
  export class ProjectChecker {
35
- static readonly BUILTIN = ['config', 'types', 'decorators', 'di'];
35
+ static readonly BUILTIN = ['config', 'types', 'decorators', 'di', 'security'];
36
+
37
+ /** The backend loaded once for the di and security checks, closed when the checks are done. */
38
+ protected backendServer?: CellDevServer;
39
+ protected backend?: Promise<{ server: CellDevServer; container?: DiContainer }>;
36
40
 
37
41
  constructor(
38
42
  protected readonly toolchain: Toolchain,
@@ -59,6 +63,17 @@ export class ProjectChecker {
59
63
  });
60
64
  }
61
65
  const reports: CheckReport[] = [];
66
+ try {
67
+ await this.runChecks(skip, reports);
68
+ } finally {
69
+ await this.backendServer?.close();
70
+ this.backendServer = undefined;
71
+ this.backend = undefined;
72
+ }
73
+ return reports;
74
+ }
75
+
76
+ protected async runChecks(skip: Set<string>, reports: CheckReport[]): Promise<void> {
62
77
  for (const check of this.checks()) {
63
78
  const started = performance.now();
64
79
  const base = { name: check.name, description: check.description, ...(check.source ? { source: check.source } : {}) };
@@ -85,7 +100,6 @@ export class ProjectChecker {
85
100
  const durationMs = Math.round(performance.now() - started);
86
101
  reports.push(Array.isArray(outcome) ? { ...base, durationMs, issues: outcome } : { ...base, durationMs, issues: [], skipped: outcome.skipped });
87
102
  }
88
- return reports;
89
103
  }
90
104
 
91
105
  protected checks(): Check[] {
@@ -94,6 +108,7 @@ export class ProjectChecker {
94
108
  { name: 'types', description: 'TypeScript types (tsc --noEmit)', run: () => this.types() },
95
109
  { name: 'decorators', description: 'tsconfig settings the DI decorators need', run: async () => this.decorators() },
96
110
  { name: 'di', description: 'every DI binding of the backend resolves', run: () => this.di() },
111
+ { name: 'security', description: 'settings that are unsafe in production (SecurityCheck components)', run: () => this.security() },
97
112
  ];
98
113
  const modules = this.toolchain.modules.checks.map(({ source, value }) => ({
99
114
  name: value.name,
@@ -110,6 +125,19 @@ export class ProjectChecker {
110
125
 
111
126
  protected config(): CheckIssue[] {
112
127
  const { config, preset, presets, modules } = this.toolchain;
128
+ const { schema, problems } = new ProjectLoader({ ...this.toolchain.projectOptions(), env: this.options.env }).validate();
129
+ // The merged schema, for the editor and the agent (cell.yml: # yaml-language-server: $schema=./.cell/schema/cell.yml.json).
130
+ OutputWriter.writeSchema(this.root, schema);
131
+ if (problems.length > 0) {
132
+ return problems.map(p => ({
133
+ level: 'error',
134
+ code: 'CELL_CONFIG_INVALID',
135
+ message: `${p.path}: ${p.message}`,
136
+ file: p.file,
137
+ ...(p.line ? { line: p.line } : {}),
138
+ hint: p.hint,
139
+ }));
140
+ }
113
141
  const inspector = new ProjectInspector(config, preset, presets.names, { projectOptions: this.toolchain.projectOptions(), modules: modules.loaded });
114
142
  inspector.inspect({ env: this.options.env });
115
143
  return inspector.issues;
@@ -213,37 +241,75 @@ export class ProjectChecker {
213
241
 
214
242
  /** Loads the backend's container (not the application) and resolves every binding. */
215
243
  protected async di(): Promise<CheckIssue[] | { skipped: string }> {
216
- const options = this.toolchain.projectOptions();
217
- const server = new CellDevServer({
218
- ...options,
219
- mode: this.toolchain.config.mode,
220
- env: this.options.env,
221
- vite: this.toolchain.config.vite,
222
- plugins: this.toolchain.modules.vitePlugins(),
223
- listen: false,
224
- backend: false,
225
- logLevel: 'silent',
226
- });
227
- await server.start();
244
+ const { container } = await this.loadBackend();
245
+ if (!container) {
246
+ return { skipped: 'no backend target' };
247
+ }
248
+ return ProjectChecker.resolveAll(container);
249
+ }
250
+
251
+ /**
252
+ * The warnings of the backend's `SecurityCheck` components (default keys, short secrets), with the
253
+ * configuration of the mode checked: what a production start logs or refuses (`securityChecks`).
254
+ */
255
+ protected async security(): Promise<CheckIssue[] | { skipped: string }> {
256
+ let backend: { server: CellDevServer; container?: DiContainer };
228
257
  try {
258
+ backend = await this.loadBackend();
259
+ } catch {
260
+ return { skipped: 'the backend DI modules did not load (see the di check)' };
261
+ }
262
+ const { server, container } = backend;
263
+ if (!container) {
264
+ return { skipped: 'no backend target' };
265
+ }
266
+ let id: unknown;
267
+ try {
268
+ // The identifier from the project's own @celljs/core, the module instance its container uses.
269
+ ({ SecurityChecker: id } = await server.import<{ SecurityChecker: symbol }>('@celljs/core/lib/common/security-check/security-check-protocol'));
270
+ } catch {
271
+ return { skipped: 'the @celljs/core of the project has no security checks' };
272
+ }
273
+ const [checker] = container.bindings().has(id) ? (container.getAll(id) as SecurityCheckerLike[]) : [];
274
+ if (!checker) {
275
+ return { skipped: 'the @celljs/core of the project has no security checks' };
276
+ }
277
+ return (await checker.check()).map(warning => ({ level: 'warning', code: warning.code, message: warning.message, hint: warning.hint }));
278
+ }
279
+
280
+ /** The backend's container, loaded once for the di and security checks; `container` is absent without a backend. */
281
+ protected loadBackend(): Promise<{ server: CellDevServer; container?: DiContainer }> {
282
+ this.backend ??= (async () => {
283
+ const options = this.toolchain.projectOptions();
284
+ const server = new CellDevServer({
285
+ ...options,
286
+ mode: this.toolchain.config.mode,
287
+ env: this.options.env,
288
+ vite: this.toolchain.config.vite,
289
+ plugins: this.toolchain.modules.vitePlugins(),
290
+ listen: false,
291
+ backend: false,
292
+ logLevel: 'silent',
293
+ });
294
+ this.backendServer = server;
295
+ await server.start();
229
296
  if (!server.project.backend) {
230
- return { skipped: 'no backend target' };
297
+ return { server };
231
298
  }
232
- let container: DiContainer;
233
299
  try {
234
- container = await (await server.import<{ container: Promise<DiContainer> }>('@celljs/core/lib/common/container/dynamic-container')).container;
300
+ const container = await (await server.import<{ container: Promise<DiContainer> }>('@celljs/core/lib/common/container/dynamic-container'))
301
+ .container;
235
302
  // Components look the container up through ContainerProvider, as the entry sets it.
236
303
  const { ContainerProvider } = await server.import<{ ContainerProvider: { set(c: unknown): void } }>(
237
304
  '@celljs/core/lib/common/container/container-provider',
238
305
  );
239
306
  ContainerProvider.set(container);
307
+ return { server, container };
240
308
  } catch (error) {
241
309
  throw CellDevServer.toCellError(error, 'CELL_DI_MODULE_FAILED');
242
310
  }
243
- return ProjectChecker.resolveAll(container);
244
- } finally {
245
- await server.close();
246
- }
311
+ })();
312
+ return this.backend;
247
313
  }
248
314
 
249
315
  /**
@@ -353,6 +419,11 @@ interface DiContainer {
353
419
  getAll(id: unknown): unknown[];
354
420
  }
355
421
 
422
+ /** The SecurityChecker of @celljs/core. */
423
+ interface SecurityCheckerLike {
424
+ check(): Promise<{ code: string; message: string; hint: string }[]>;
425
+ }
426
+
356
427
  /** A ContainerError of @celljs/core. */
357
428
  interface DiError extends Error {
358
429
  code: string;
@@ -148,9 +148,9 @@ export class BuildCommand extends Command {
148
148
  if (model.backend && preset.entry && !model.backend.entryComponent && !options.entry?.backend) {
149
149
  reporter.warn(ProjectInspector.missingEntryWarning(preset));
150
150
  }
151
- // Backend variables matter where the server runs, not here; `cell info` checks them.
151
+ // The variables of this environment reach the frontend keys; the server applies its own at startup.
152
152
  for (const problem of model.frontend?.envOverrides.problems ?? []) {
153
- reporter.warn(ProjectInspector.envProblemWarning('frontend', problem));
153
+ reporter.warn(ProjectInspector.envProblemWarning(problem));
154
154
  }
155
155
  const outDir = resolve(config.root, options.outDir ?? ConfigResolver.DEFAULT_OUT_DIR);
156
156
  let manifest = await PresetOutput.write(preset, {
@@ -6,9 +6,9 @@ import { BuildCommand } from './build-command.js';
6
6
  import { Command, type CommandContext } from './command.js';
7
7
 
8
8
  /**
9
- * `cell config get <key>`: one value of the merged application configuration (cell*.yml of every
10
- * component and the active modes, then `CELL_<TARGET>__*` variables), with the files and variables
11
- * that set it. Read-only, like `cell info`.
9
+ * `cell config get <key>`: one value of the application configuration (cell*.yml of every component
10
+ * and the active modes, then `CELL_*` variables), with the files and variables that set it, the
11
+ * component that owns it and whether the browser receives it. Read-only, like `cell info`.
12
12
  */
13
13
  export class ConfigCommand extends Command {
14
14
  readonly name = 'config';
@@ -21,7 +21,7 @@ export class ConfigCommand extends Command {
21
21
  } as const;
22
22
  override readonly usage = [
23
23
  '-m, --mode <mode> extra mode, reads cell.<mode>.yml (repeatable)',
24
- '--target <target> backend or frontend (default: backend, else frontend)',
24
+ '--target <target> backend or frontend: the frontend only has the public keys (default: backend)',
25
25
  '--why list the files and variables that set the value',
26
26
  ];
27
27
 
@@ -31,7 +31,7 @@ export class ConfigCommand extends Command {
31
31
  throw new CellError({
32
32
  code: 'CELL_ARGUMENT_INVALID',
33
33
  message: action === 'get' ? 'cell config get takes one key.' : `Unknown config action '${action ?? ''}'.`,
34
- hint: 'Use cell config get <key>, e.g. cell config get cell.server.port.',
34
+ hint: 'Use cell config get <key>, e.g. cell config get server.port.',
35
35
  });
36
36
  }
37
37
  const target = values.target as string | undefined;
@@ -52,8 +52,9 @@ export class ConfigCommand extends Command {
52
52
  logger: reporter,
53
53
  });
54
54
  await toolchain.close();
55
- const model = new ProjectLoader({ ...toolchain.projectOptions(), env }).load();
56
- const result = new ConfigExplainer(model, env).explain(key, target as Target | undefined);
55
+ const loader = new ProjectLoader({ ...toolchain.projectOptions(), env });
56
+ const model = loader.load();
57
+ const result = new ConfigExplainer(model, env, loader.schema).explain(key, target as Target | undefined);
57
58
  reporter.result('config', { ...result }, ConfigCommand.format(result, values.why === true));
58
59
  return 0;
59
60
  }
@@ -63,9 +64,12 @@ export class ConfigCommand extends Command {
63
64
  if (!why) {
64
65
  return value;
65
66
  }
67
+ const owner = result.owners.length > 0 ? `, owned by ${result.owners.join(', ')}` : '';
66
68
  return [
67
69
  `${result.key} (${result.target}) = ${value}`,
68
- ...result.layers.map(layer => ` ${layer.file}${layer.section === 'shared' ? '' : ` [${layer.section}]`}: ${JSON.stringify(layer.value)}`),
70
+ ` ${result.public ? 'public: the frontend receives it' : 'server-only'}${owner}`,
71
+ ...(result.description ? [` ${result.description}`] : []),
72
+ ...result.layers.map(layer => ` ${layer.file}: ${JSON.stringify(layer.value)}`),
69
73
  ...result.env.map(({ variable, path }) => ` ${variable} → ${path}`),
70
74
  ...(result.expressions ? [' ${...} is evaluated by the server at startup'] : []),
71
75
  ].join('\n');
@@ -30,8 +30,8 @@ export class DevCommand extends Command {
30
30
  override readonly usage = [
31
31
  '--preset <name> preset whose entry runs the backend (default: node)',
32
32
  '-m, --mode <mode> extra mode, reads cell.<mode>.yml (repeatable); development is always on',
33
- '-p, --port <port> port (default: cell.server.port, else 3000)',
34
- '--host <host> interface to listen on (default: cell.server.host, else 127.0.0.1)',
33
+ '-p, --port <port> port (default: server.port, else 3000)',
34
+ '--host <host> interface to listen on (default: server.host, else 127.0.0.1)',
35
35
  ];
36
36
 
37
37
  async run({ values, reporter, env }: CommandContext): Promise<number> {
@@ -4,8 +4,9 @@ import { Toolchain } from '../toolchain/toolchain.js';
4
4
  import { Command, type CommandContext } from './command.js';
5
5
 
6
6
  /**
7
- * `cell docs <query>`: searches the README.md and docs/ of the installed components and the docs
8
- * of toolchain modules, the versions this project uses. Read-only; prints the best sections.
7
+ * `cell docs <query>`: searches the README.md and docs/ of the installed components, the docs of
8
+ * toolchain modules and the guides of @celljs/cli, the versions this project uses. Read-only; prints
9
+ * the best sections.
9
10
  */
10
11
  export class DocsCommand extends Command {
11
12
  readonly name = 'docs';
@@ -17,7 +17,7 @@ export class PreviewCommand extends Command {
17
17
  'out-dir': { type: 'string' },
18
18
  } as const;
19
19
  override readonly usage = [
20
- '-p, --port <port> port to listen on (default: cell.server.port; 8787 for cloudflare)',
20
+ '-p, --port <port> port to listen on (default: server.port; 8787 for cloudflare)',
21
21
  '--out-dir <dir> output directory (default: .cell/output)',
22
22
  ];
23
23
 
@@ -46,7 +46,7 @@ export class PreviewCommand extends Command {
46
46
  const app = join(outDir, manifest.executable.file);
47
47
  const child = spawn(app, [], {
48
48
  cwd: root,
49
- env: { ...env, NODE_ENV: env.NODE_ENV ?? 'production', ...(port ? { CELL_BACKEND__SERVER__PORT: port } : {}) },
49
+ env: { ...env, NODE_ENV: env.NODE_ENV ?? 'production', ...(port ? { CELL_SERVER__PORT: port } : {}) },
50
50
  stdio: [...stdio],
51
51
  });
52
52
  reporter.result('preview', { executable: app, pid: child.pid, port: port ? Number(port) : undefined, preset: manifest.preset }, `Running ${app}`);
@@ -63,7 +63,7 @@ export class PreviewCommand extends Command {
63
63
  const server = join(outDir, manifest.server);
64
64
  const child = spawn(process.execPath.includes('bun') ? 'node' : process.execPath, [server], {
65
65
  cwd: root,
66
- env: { ...env, NODE_ENV: env.NODE_ENV ?? 'production', ...(port ? { CELL_BACKEND__SERVER__PORT: port } : {}) },
66
+ env: { ...env, NODE_ENV: env.NODE_ENV ?? 'production', ...(port ? { CELL_SERVER__PORT: port } : {}) },
67
67
  stdio: [...stdio],
68
68
  });
69
69
  reporter.result('preview', { server, pid: child.pid, port: port ? Number(port) : undefined, preset: manifest.preset }, `Running ${server}`);
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { CellError, type ProjectModel, type Target } from '@celljs/kit';
3
- import { EnvOverrides, TOOLING_KEYS } from '@celljs/vite';
3
+ import { type ConfigSchema, EnvOverrides } from '@celljs/vite';
4
4
  import yaml from 'js-yaml';
5
5
  import { PathUtil } from '../utils/path-util.js';
6
6
  import { TextUtil } from '../utils/text-util.js';
@@ -10,8 +10,6 @@ export interface ConfigLayer {
10
10
  /** Relative to the project root. */
11
11
  file: string;
12
12
  component: string;
13
- /** `shared`: top level of the file; `frontend` / `backend`: the target's section. */
14
- section: 'shared' | Target;
15
13
  value: unknown;
16
14
  }
17
15
 
@@ -20,25 +18,32 @@ export interface ConfigValue {
20
18
  key: string;
21
19
  target: Target;
22
20
  value: unknown;
23
- /** Files that set the key or a part of it, in merge order (the last wins): shared parts of all files, then the target sections. */
21
+ /** Components whose schema declares the key (`cell.schema.json`). */
22
+ owners: string[];
23
+ /** The frontend receives the key (`x-cell-public` in the schema). */
24
+ public: boolean;
25
+ description?: string;
26
+ /** Files that set the key or a part of it, in merge order (the last wins). */
24
27
  layers: ConfigLayer[];
25
- /** `CELL_<TARGET>__*` variables that set the key or a part of it. */
28
+ /** `CELL_*` variables that set the key or a part of it. */
26
29
  env: { variable: string; path: string }[];
27
30
  /** Backend values keep `${...}` expressions; the server evaluates them at startup. */
28
31
  expressions: boolean;
29
32
  }
30
33
 
31
34
  /**
32
- * Looks up one key of the merged application configuration of a target and says where it came
33
- * from: which cell*.yml files set it (shared or target section) and which environment variables.
35
+ * Looks up one key of the application configuration of a target and says where it came from:
36
+ * which cell*.yml files and environment variables set it, which component owns it and whether
37
+ * the browser receives it.
34
38
  */
35
39
  export class ConfigExplainer {
36
40
  constructor(
37
41
  protected readonly model: ProjectModel,
38
42
  protected readonly env: Record<string, string | undefined>,
43
+ protected readonly schema: ConfigSchema,
39
44
  ) {}
40
45
 
41
- /** `cell.server.port`, `items[0].name` and `items.0.name` all work. */
46
+ /** `server.port`, `items[0].name` and `items.0.name` all work. */
42
47
  static parseKey(key: string): string[] {
43
48
  const parts = key
44
49
  .replace(/\[(\d+)\]/g, '.$1')
@@ -48,7 +53,7 @@ export class ConfigExplainer {
48
53
  throw new CellError({
49
54
  code: 'CELL_ARGUMENT_INVALID',
50
55
  message: `Invalid configuration key '${key}'.`,
51
- hint: 'Pass a dotted key, e.g. cell.server.port.',
56
+ hint: 'Pass a dotted key, e.g. server.port.',
52
57
  });
53
58
  }
54
59
  return parts;
@@ -69,11 +74,12 @@ export class ConfigExplainer {
69
74
  }
70
75
  const path = ConfigExplainer.parseKey(key);
71
76
  const config = structuredClone(model.config);
72
- // The frontend model has its variables applied already; the server applies the backend ones at startup.
73
- const report = target === 'backend' ? new EnvOverrides(this.model.root, this.env).apply('backend', config) : model.envOverrides;
77
+ // The frontend model has the variables applied already; the server applies them at startup.
78
+ const report = target === 'backend' ? new EnvOverrides(this.model.root, this.env).apply(config, model.configTypes) : model.envOverrides;
74
79
  const found = ConfigExplainer.lookup(config, path);
80
+ const described = this.schema.describe(path);
75
81
  if (!found.found) {
76
- throw this.notFound(key, path, config, target);
82
+ throw this.notFound(key, path, config, target, described.public);
77
83
  }
78
84
  const env = report.applied
79
85
  .filter(({ path: set }) => ConfigExplainer.overlaps(ConfigExplainer.parseKey(set), path))
@@ -82,39 +88,37 @@ export class ConfigExplainer {
82
88
  key: path.join('.'),
83
89
  target,
84
90
  value: found.value,
85
- layers: this.layers(path, target),
91
+ owners: described.owners,
92
+ public: described.public,
93
+ ...(described.node?.description ? { description: described.node.description } : {}),
94
+ layers: this.layers(path),
86
95
  env,
87
96
  expressions: target === 'backend' && JSON.stringify(found.value ?? null).includes('${'),
88
97
  };
89
98
  }
90
99
 
91
- /** Shared layers of every file first, then the target sections: how ConfigLoader.forTarget merges. */
92
- protected layers(path: string[], target: Target): ConfigLayer[] {
93
- const shared: ConfigLayer[] = [];
94
- const sections: ConfigLayer[] = [];
100
+ protected layers(path: string[]): ConfigLayer[] {
101
+ const layers: ConfigLayer[] = [];
95
102
  for (const component of this.model.components) {
96
103
  for (const file of component.configFiles) {
97
104
  const doc = (yaml.load(readFileSync(file, 'utf8')) ?? {}) as Record<string, unknown>;
98
- const layer = (section: 'shared' | Target, value: unknown): ConfigLayer => ({
99
- file: PathUtil.relative(this.model.root, file) || file,
100
- component: component.name,
101
- section,
102
- value,
103
- });
104
- const inShared = TOOLING_KEYS.includes(path[0]) ? { found: false } : ConfigExplainer.lookup(doc, path);
105
- if (inShared.found) {
106
- shared.push(layer('shared', inShared.value));
107
- }
108
- const inSection = ConfigExplainer.lookup(doc[target], path);
109
- if (inSection.found) {
110
- sections.push(layer(target, inSection.value));
105
+ const found = ConfigExplainer.lookup(doc, path);
106
+ if (found.found) {
107
+ layers.push({ file: PathUtil.relative(this.model.root, file) || file, component: component.name, value: found.value });
111
108
  }
112
109
  }
113
110
  }
114
- return [...shared, ...sections];
111
+ return layers;
115
112
  }
116
113
 
117
- protected notFound(key: string, path: string[], config: Record<string, unknown>, target: Target): CellError {
114
+ protected notFound(key: string, path: string[], config: Record<string, unknown>, target: Target, isPublic: boolean): CellError {
115
+ if (target === 'frontend' && !isPublic && ConfigExplainer.lookup(this.model.backend?.config ?? {}, path).found) {
116
+ return new CellError({
117
+ code: 'CELL_CONFIG_KEY_NOT_FOUND',
118
+ message: `'${key}' is server-only: the frontend does not receive it.`,
119
+ hint: 'Read it on the server, or put your own frontend configuration under app.public; a component marks its frontend keys with x-cell-public in cell.schema.json.',
120
+ });
121
+ }
118
122
  let parent: unknown = config;
119
123
  let depth = 0;
120
124
  for (; depth < path.length - 1; depth++) {
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import { PathUtil } from '../utils/path-util.js';
4
5
 
5
6
  /** Where documentation is read from: a directory of Markdown or one file, and who provides it. */
@@ -28,7 +29,8 @@ export interface DocsHit extends Omit<DocsSection, 'text'> {
28
29
 
29
30
  /**
30
31
  * Searches the Markdown that ships with the installed components and toolchain modules (README.md
31
- * and `docs/` of each component, `cell.addDocs()` directories), so agents read the docs of the
32
+ * and `docs/` of each component, `cell.addDocs()` directories) and with @celljs/cli itself (its
33
+ * README and the guides in docs/), so agents read the docs of the
32
34
  * versions the project uses (docs/design/agent-first.md R7). Sections are ranked by how many query
33
35
  * words they contain, headings counting more.
34
36
  */
@@ -44,6 +46,9 @@ export class DocsIndex {
44
46
  protected readonly sources: DocsSource[],
45
47
  ) {}
46
48
 
49
+ /** The CLI reference and the guides (docs/) that ship with @celljs/cli. */
50
+ static readonly CLI_DOCS: readonly string[] = ['../../README.md', '../../docs'].map(path => fileURLToPath(new URL(path, import.meta.url)));
51
+
47
52
  /** README.md and docs/ of each component directory, then the modules' docs directories. */
48
53
  static sourcesOf(components: readonly { name: string; dir: string }[], moduleDocs: readonly { source: string; value: string }[]): DocsSource[] {
49
54
  return [
@@ -52,6 +57,7 @@ export class DocsIndex {
52
57
  { path: join(c.dir, 'docs'), source: c.name },
53
58
  ]),
54
59
  ...moduleDocs.map(d => ({ path: d.value, source: d.source })),
60
+ ...DocsIndex.CLI_DOCS.map(path => ({ path, source: '@celljs/cli' })),
55
61
  ].filter(s => existsSync(s.path));
56
62
  }
57
63
 
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { basename, isAbsolute, join } from 'node:path';
3
- import type { CheckIssue, ComponentInfo, EnvOverrideReport, Preset, ProjectModel, ServerRuntime, Target, TargetModel } from '@celljs/kit';
3
+ import type { CheckIssue, ComponentInfo, EnvOverrideReport, PageRoute, Preset, ProjectModel, ServerRuntime, Target, TargetModel } from '@celljs/kit';
4
4
  import { type OutputManifest, ProjectLoader, type ProjectLoaderOptions } from '@celljs/vite';
5
5
  import { ConfigResolver, type ModuleSpec, type ResolvedConfig, type ValueSource } from '../config/config-resolver.js';
6
6
  import type { CompileTarget } from '../config/types.js';
@@ -32,11 +32,12 @@ export interface TargetSummary {
32
32
  /** Merged application configuration, only with `--app-config`. Backend values keep `${...}`. */
33
33
  config?: Record<string, unknown>;
34
34
  /**
35
- * `CELL_FRONTEND__*` / `CELL_BACKEND__*` variables of the current environment and the keys they set;
36
- * present when there are any. Frontend ones are applied by `cell build`, backend ones by the server
37
- * at startup. Values are left out.
35
+ * `CELL_*` variables of the current environment and the keys they set; present when there are
36
+ * any. `cell build` applies them to the frontend keys, the server at startup. Values are left out.
38
37
  */
39
38
  envOverrides?: EnvOverrideReport;
39
+ /** Frontend: the pages of `src/browser/pages` (path, file, layouts), when there are any. */
40
+ routes?: PageRoute[];
40
41
  }
41
42
 
42
43
  export interface OutputSummary {
@@ -182,9 +183,11 @@ export class ProjectInspector {
182
183
  const summary = info[target] as TargetSummary;
183
184
  const count = summary.staticModules.length + summary.modules.length;
184
185
  const entry = target === 'backend' && !summary.entryComponent ? `${summary.entry} (default entry)` : summary.entry;
185
- rows.push([target, `${entry}, ${count} DI module${count === 1 ? '' : 's'}`]);
186
+ const pages = summary.routes?.length ? `, ${summary.routes.length} page${summary.routes.length === 1 ? '' : 's'}` : '';
187
+ rows.push([target, `${entry}, ${count} DI module${count === 1 ? '' : 's'}${pages}`]);
186
188
  }
187
- const overrides = info.targets.flatMap(target => (info[target] as TargetSummary).envOverrides?.applied ?? []);
189
+ // Both targets see the same variables.
190
+ const overrides = (info[info.targets[info.targets.length - 1]] as TargetSummary | undefined)?.envOverrides?.applied ?? [];
188
191
  if (overrides.length > 0) {
189
192
  rows.push(['env', overrides.map(({ variable, path }) => `${variable} → ${path}`).join(', ')]);
190
193
  }
@@ -218,8 +221,8 @@ export class ProjectInspector {
218
221
  return `No component provides the '${preset.entry}' entry of the ${preset.name} preset, so the backend starts the application without an HTTP server (servers of components, such as the gRPC server of @celljs/grpc, still start). Add @celljs/express-adapter to dependencies for an HTTP server, or use the cli preset for a command-line application.`;
219
222
  }
220
223
 
221
- static envProblemWarning(target: Target, problem: { variable: string; message: string }): string {
222
- return `${problem.variable} is ignored${target === 'backend' ? ' by the server' : ''}: ${problem.message}`;
224
+ static envProblemWarning(problem: { variable: string; message: string }): string {
225
+ return `${problem.variable} is ignored: ${problem.message}`;
223
226
  }
224
227
 
225
228
  /** `@x/ui (2 vite plugins, 1 check)`: what a module registered, counted. */
@@ -291,6 +294,7 @@ export class ProjectInspector {
291
294
  modules: model.modules.map(m => specifier(m.specifier)),
292
295
  ...(appConfig ? { config: model.config } : {}),
293
296
  ...(model.envOverrides.applied.length + model.envOverrides.problems.length > 0 ? { envOverrides: model.envOverrides } : {}),
297
+ ...(model.routes?.length ? { routes: model.routes } : {}),
294
298
  };
295
299
  }
296
300
 
@@ -324,20 +328,9 @@ export class ProjectInspector {
324
328
  );
325
329
  }
326
330
  }
327
- for (const target of model.targets) {
328
- const { applied, problems } = (model[target] as TargetModel).envOverrides;
329
- for (const problem of problems) {
330
- this.warn('CELL_ENV_OVERRIDE_IGNORED', ProjectInspector.envProblemWarning(target, problem));
331
- }
332
- for (const { variable, path, shadows } of applied) {
333
- if (shadows) {
334
- const explicit = variable.replace(/^(CELL_[A-Z]+__)/, '$1CELL__');
335
- this.warn(
336
- 'CELL_ENV_OVERRIDE_SHADOWS',
337
- `${variable} sets ${path}, not ${shadows}: the top-level key comes first. Use ${explicit} for ${shadows}.`,
338
- );
339
- }
340
- }
331
+ // Both targets see the same variables: report them once.
332
+ for (const problem of (model.backend ?? model.frontend)?.envOverrides.problems ?? []) {
333
+ this.warn('CELL_ENV_OVERRIDE_IGNORED', ProjectInspector.envProblemWarning(problem));
341
334
  }
342
335
  }
343
336
 
@@ -158,8 +158,8 @@ export class DevMcpEndpoint {
158
158
  {
159
159
  name: 'get_config',
160
160
  description:
161
- 'A configuration value as the running backend sees it, with ${...} expressions evaluated (e.g. cell.server.port). For where a value comes from, use config_get of cell mcp.',
162
- inputSchema: object({ key: { type: 'string', description: 'Dotted key, e.g. cell.server.port.' } }, ['key']),
161
+ 'A configuration value as the running backend sees it, with ${...} expressions evaluated (e.g. server.port). For where a value comes from, use config_get of cell mcp.',
162
+ inputSchema: object({ key: { type: 'string', description: 'Dotted key, e.g. server.port.' } }, ['key']),
163
163
  readOnly: true,
164
164
  run: input => this.config(input.key as string),
165
165
  },
@@ -289,7 +289,7 @@ export class DevMcpEndpoint {
289
289
  throw new CellError({
290
290
  code: 'CELL_ARGUMENT_INVALID',
291
291
  message: `Invalid configuration key '${key}'.`,
292
- hint: 'Pass a dotted key, e.g. cell.server.port or items[0].name.',
292
+ hint: 'Pass a dotted key, e.g. server.port or items[0].name.',
293
293
  });
294
294
  }
295
295
  // ConfigProvider.get() turns 0, false and '' into the default; the expression handler does not.
@@ -68,10 +68,10 @@ export class ProjectMcpTools {
68
68
  {
69
69
  name: 'config_get',
70
70
  description:
71
- 'One value of the merged application configuration (cell*.yml of all components and modes, then CELL_<TARGET>__* variables) and the files and variables that set it. Backend values keep ${...}; the server evaluates them.',
71
+ 'One value of the application configuration (cell*.yml of all components and modes, then CELL_* variables): the files and variables that set it, the component that owns it and whether the frontend receives it. Backend values keep ${...}; the server evaluates them.',
72
72
  inputSchema: object(
73
73
  {
74
- key: { type: 'string', description: 'Dotted key, e.g. cell.server.port.' },
74
+ key: { type: 'string', description: 'Dotted key, e.g. server.port.' },
75
75
  target: { type: 'string', enum: ['backend', 'frontend'], description: 'Default: backend, else frontend.' },
76
76
  mode,
77
77
  },
@@ -83,7 +83,7 @@ export class ProjectMcpTools {
83
83
  {
84
84
  name: 'docs_search',
85
85
  description:
86
- 'Searches the docs (README.md, docs/) of the installed Cell components and toolchain modules, the versions this project uses. Returns the best matching sections with file and line.',
86
+ 'Searches the docs (README.md, docs/) of the installed Cell components and toolchain modules, and the Cell guides and CLI reference, in the versions this project uses. Returns the best matching sections with file and line.',
87
87
  inputSchema: object(
88
88
  {
89
89
  query: { type: 'string', description: 'Words to look for, e.g. "transactional typeorm".' },
@@ -5,7 +5,7 @@ import { lambdaPreset } from './lambda/lambda-preset.js';
5
5
  import { scfPreset } from './scf/scf-preset.js';
6
6
  import { vercelPreset } from './vercel/vercel-preset.js';
7
7
 
8
- /** A Node.js HTTP server: `node server/index.mjs` listens on `cell.server.port` (override with `CELL_BACKEND__SERVER__PORT`). */
8
+ /** A Node.js HTTP server: `node server/index.mjs` listens on `server.port` (override with `CELL_SERVER__PORT`). */
9
9
  export const nodePreset = definePreset({
10
10
  name: 'node',
11
11
  description: 'Node.js HTTP server',
@@ -30,8 +30,8 @@ export namespace ServerlessScripts {
30
30
  '[ -x "$NODE" ] || NODE=node',
31
31
  'export NODE_ENV="${NODE_ENV:-production}"',
32
32
  // The platform forwards requests to this port on all interfaces.
33
- 'export CELL_BACKEND__SERVER__HOST=0.0.0.0',
34
- `export CELL_BACKEND__SERVER__PORT="${portValue}"`,
33
+ 'export CELL_SERVER__HOST=0.0.0.0',
34
+ `export CELL_SERVER__PORT="${portValue}"`,
35
35
  `exec "$NODE" ${server}`,
36
36
  '',
37
37
  ].join('\n');
@@ -88,8 +88,8 @@ export namespace VercelPreset {
88
88
  args: [join(outDir, manifest.server ?? `${FUNCTION}/server/index.mjs`)],
89
89
  env: {
90
90
  NODE_ENV: 'production',
91
- CELL_BACKEND__PATHS__PUBLIC: join(outDir, 'static'),
92
- ...(port === undefined ? {} : { CELL_BACKEND__SERVER__PORT: String(port) }),
91
+ CELL_PATHS__PUBLIC: join(outDir, 'static'),
92
+ ...(port === undefined ? {} : { CELL_SERVER__PORT: String(port) }),
93
93
  },
94
94
  };
95
95
  }