@dokebi/cli 0.4.52 → 0.4.54

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.
@@ -20,16 +20,17 @@ import { csrfFormsProblems, formProblems } from './form-rules.js';
20
20
  import { formatterProblems } from './formatter-rules.js';
21
21
  import { missingKeysProblems } from './i18n-rules.js';
22
22
  import { DokebiImports } from './packages.js';
23
- import { byPlace, MARKABLE, RULES } from './problems.js';
23
+ import { byPlace, MARKABLE, RULES, uniqueProblems, } from './problems.js';
24
24
  import { projectProblems } from './project-rules.js';
25
25
  import { sealHeadsProblems } from './seal-rules.js';
26
+ import { sharedFolderProblems } from './shared-folder-rules.js';
26
27
  import { sharedStateProblems } from './shared-state-rules.js';
27
28
  import { readMarkers, sourceProblems } from './source-rules.js';
28
29
  import { openTypeScript } from './typescript.js';
29
30
  import { viteConfigProblems } from './vite-rules.js';
30
31
  export { RULES } from './problems.js';
31
32
  /** CLI-generated TypeScript: judged by doctor (generated-file), not by the source rules. */
32
- const GENERATED_SOURCES = new Set(['src/dokebi.generated.ts']);
33
+ const GENERATED_SOURCES = new Set(['src/dokebi.generated.ts', 'src/dokebi.modules.generated.ts']);
33
34
  export async function check(directory, options = {}) {
34
35
  const began = performance.now();
35
36
  const root = await realpath(directory);
@@ -54,29 +55,31 @@ export async function check(directory, options = {}) {
54
55
  problems.push(...(await formatterProblems(root)));
55
56
  problems.push(...(await sharedStateProblems(root, installed)));
56
57
  problems.push(...(await assetProblems(root)));
58
+ problems.push(...(await sharedFolderProblems(root)));
57
59
  if (installed.has('dokebi-app'))
58
60
  problems.push(...(await sealHeadsProblems(root, skip)));
59
61
  if (installed.has('dokebi-i18n'))
60
62
  problems.push(...(await missingKeysProblems(root, skip)));
61
63
  problems.sort(byPlace);
64
+ const reported = uniqueProblems(problems);
62
65
  const allowed = await allowedMarkers(root, skip);
63
66
  const ms = {
64
67
  total: Math.round(performance.now() - began),
65
68
  typescript: typescript.loadMs,
66
69
  };
67
- const errors = problems.filter((problem) => problem.severity !== 'warning').length;
70
+ const errors = reported.filter((problem) => problem.severity !== 'warning').length;
68
71
  debug('check: finished', {
69
72
  root,
70
- problems: problems.length,
73
+ problems: reported.length,
71
74
  allowed: allowed.length,
72
- warnings: problems.length - errors,
75
+ warnings: reported.length - errors,
73
76
  files,
74
77
  ...ms,
75
78
  });
76
79
  return {
77
80
  // Warnings (inertia-form-only, the CSRF ones) are reported but never fail check or verify.
78
81
  ok: errors === 0,
79
- problems,
82
+ problems: reported,
80
83
  allowed,
81
84
  files,
82
85
  rules: RULES,
@@ -1,4 +1,4 @@
1
- export declare const RULES: readonly ['empty-catch', 'missing-cause', 'floating-promise', 'non-erasable-syntax', 'private-import', 'generated-file', 'secret-in-config', 'missing-package', 'inertia-form-only', 'form-without-csrf', 'csrf-exempt-unverified', 'plain-password-compare', 'unknown-error-code', 'mail-send-in-request', 'mail-secret-in-data', 'background-timer', 'polling-loop', 'responsibility-size', 'memory-filtered-page', 'untyped-browser-import', 'vite-dev-files', 'module-point-not-installed', 'formatter-migrations', 'formatter-generated', 'shared-state-memory', 'asset-in-views', 'asset-route', 'seal-head-copied', 'i18n-missing-key', 'i18n-layer-override', 'i18n-layer-missing', 'console-output', 'undeclared-section', 'template-fix-missing', 'wait-count-refusal', 'in-process-queue', 'private-pool', 'overload-off', 'readiness-off', 'fixed-owner-cap'];
1
+ export declare const RULES: readonly ['empty-catch', 'missing-cause', 'floating-promise', 'non-erasable-syntax', 'private-import', 'generated-file', 'secret-in-config', 'missing-package', 'inertia-form-only', 'form-without-csrf', 'csrf-exempt-unverified', 'plain-password-compare', 'unknown-error-code', 'mail-send-in-request', 'mail-secret-in-data', 'background-timer', 'polling-loop', 'responsibility-size', 'memory-filtered-page', 'untyped-browser-import', 'vite-dev-files', 'module-point-not-installed', 'formatter-migrations', 'formatter-generated', 'shared-state-memory', 'asset-in-views', 'asset-route', 'seal-head-copied', 'i18n-missing-key', 'i18n-layer-override', 'i18n-layer-missing', 'console-output', 'undeclared-section', 'template-fix-missing', 'wait-count-refusal', 'in-process-queue', 'private-pool', 'overload-off', 'readiness-off', 'fixed-owner-cap', 'shared-folder'];
2
2
  export type RuleName = (typeof RULES)[number];
3
3
  /** Rules a `// dokebi-check: allow <rule> <reason>` comment may silence (D-0072 §4, markers). */
4
4
  export declare const MARKABLE: ReadonlySet<RuleName>;
@@ -22,3 +22,9 @@ export interface Problem {
22
22
  readonly fix: string;
23
23
  }
24
24
  export declare function byPlace(a: Problem, b: Problem): number;
25
+ /**
26
+ * Problems sorted by place, one per rule and line: a module of src/shared/browser/ that
27
+ * tsconfig.json still includes (a project from before D-0226) is read by both programs, whose
28
+ * messages may differ (floating-promise says "in the browser" there), D-0226 §3.
29
+ */
30
+ export declare function uniqueProblems(sorted: readonly Problem[]): Problem[];
@@ -6,7 +6,8 @@
6
6
  // undeclared-section D-0155; wait-count-refusal AI-M34, @dokebi/db AI.md 1.2 and 6.4; polling-loop
7
7
  // AI-M35, not markable; in-process-queue AI-M35; private-pool, overload-off and fixed-owner-cap AI-M37; readiness-off M51;
8
8
  // shared-state-memory D-0161; asset-in-views R1; asset-route R6; seal-head-copied R7;
9
- // i18n-missing-key community request A2; i18n-layer-override and i18n-layer-missing D-0181).
9
+ // i18n-missing-key community request A2; i18n-layer-override and i18n-layer-missing D-0181;
10
+ // shared-folder D-0226).
10
11
  export const RULES = [
11
12
  'empty-catch',
12
13
  'missing-cause',
@@ -48,6 +49,7 @@ export const RULES = [
48
49
  'overload-off',
49
50
  'readiness-off',
50
51
  'fixed-owner-cap',
52
+ 'shared-folder',
51
53
  ];
52
54
  /** Rules a `// dokebi-check: allow <rule> <reason>` comment may silence (D-0072 §4, markers). */
53
55
  export const MARKABLE = new Set([
@@ -104,6 +106,7 @@ export const WARNING_RULES = new Set([
104
106
  'wait-count-refusal',
105
107
  'in-process-queue',
106
108
  'fixed-owner-cap',
109
+ 'shared-folder',
107
110
  ]);
108
111
  /**
109
112
  * The rules that read browser code outside the program — .vue scripts and the .js under views/
@@ -118,3 +121,21 @@ export const BROWSER_RULES = new Set([
118
121
  export function byPlace(a, b) {
119
122
  return a.file.localeCompare(b.file) || a.line - b.line || a.rule.localeCompare(b.rule);
120
123
  }
124
+ /**
125
+ * Problems sorted by place, one per rule and line: a module of src/shared/browser/ that
126
+ * tsconfig.json still includes (a project from before D-0226) is read by both programs, whose
127
+ * messages may differ (floating-promise says "in the browser" there), D-0226 §3.
128
+ */
129
+ export function uniqueProblems(sorted) {
130
+ const kept = [];
131
+ for (const problem of sorted) {
132
+ const last = kept.at(-1);
133
+ if (last !== undefined &&
134
+ last.rule === problem.rule &&
135
+ last.file === problem.file &&
136
+ last.line === problem.line)
137
+ continue;
138
+ kept.push(problem);
139
+ }
140
+ return kept;
141
+ }
@@ -285,6 +285,14 @@ export async function projectProblems(root, inspection) {
285
285
  message: `${item.path} is generated by the CLI and was edited (doctor MODIFIED_REGISTRATION); add, upgrade and remove refuse to run until it is restored`,
286
286
  fix: 'undo the edit (for example git checkout -- src/dokebi.generated.ts) and keep code formatters out of the file (formatter-generated); change plugins with npx dokebi add/remove/app/module and options in dokebi.yaml',
287
287
  });
288
+ for (const item of codes('MODULE_LIST_MODIFIED'))
289
+ problems.push({
290
+ rule: 'generated-file',
291
+ file: item.path,
292
+ line: 1,
293
+ message: `${item.path} is the module list the CLI writes (D-0227) and was edited (doctor MODULE_LIST_MODIFIED); the next module add, remove or sync writes it again without the edit`,
294
+ fix: 'run npx dokebi module sync and keep code formatters out of the file (formatter-generated); register and unregister modules with npx dokebi module add/remove',
295
+ });
288
296
  for (const item of codes('MODIFIED_TEMPLATE'))
289
297
  problems.push({
290
298
  rule: 'generated-file',
@@ -0,0 +1,3 @@
1
+ import type { Problem } from './problems.js';
2
+ /** One warning per entry of src/shared/ the layout does not name. */
3
+ export declare function sharedFolderProblems(root: string): Promise<Problem[]>;
@@ -0,0 +1,50 @@
1
+ // The shared-folder rule of `dokebi check` (a warning, D-0226):
2
+ // shared-folder an entry right under src/shared/ that the layout does not name. src/shared
3
+ // holds shared code by kind: the folders of SHARED_FOLDERS (models, services,
4
+ // views, locales, mail, settings, feature modules, browser for the browser
5
+ // code several apps and modules share, and validation for the input rules
6
+ // several apps and modules share, D-0227) and the app error catalog errors.ts.
7
+ // Server code of one feature belongs in its module, browser code in
8
+ // src/shared/browser/. The shop measured a project drifting into folders of
9
+ // its own (src/shared/shop/, src/shared/browser/ before it was named). Entries
10
+ // whose name starts with a dot (.DS_Store, .gitkeep) are not read.
11
+ import { readdir } from 'node:fs/promises';
12
+ import { join } from 'node:path';
13
+ import { debug, isMissing } from '../diagnostics.js';
14
+ import { CliError } from '../errors.js';
15
+ import { SHARED_FILES, SHARED_FOLDERS } from '../layout.js';
16
+ const RULE = 'shared-folder';
17
+ const FOLDERS = new Set(SHARED_FOLDERS);
18
+ const FILES = new Set(SHARED_FILES);
19
+ /** One warning per entry of src/shared/ the layout does not name. */
20
+ export async function sharedFolderProblems(root) {
21
+ let entries;
22
+ try {
23
+ entries = await readdir(join(root, 'src/shared'), { withFileTypes: true });
24
+ }
25
+ catch (error) {
26
+ if (isMissing(error))
27
+ return [];
28
+ throw new CliError('READ_FAILED', 'Cannot read src/shared', { cause: error });
29
+ }
30
+ const problems = [];
31
+ const named = `${[...SHARED_FOLDERS].join(', ')} and ${[...SHARED_FILES].join(', ')}`;
32
+ for (const entry of entries) {
33
+ if (entry.name.startsWith('.'))
34
+ continue;
35
+ const folder = entry.isDirectory();
36
+ if (folder ? FOLDERS.has(entry.name) : FILES.has(entry.name))
37
+ continue;
38
+ const file = `src/shared/${entry.name}`;
39
+ problems.push({
40
+ rule: RULE,
41
+ severity: 'warning',
42
+ file,
43
+ line: 0,
44
+ message: `${file} is ${folder ? 'a folder' : 'a file'} the project layout does not name: src/shared/ holds only ${named}`,
45
+ fix: 'move server code of one feature into its module (src/shared/modules/<name>/: npx dokebi module add <name>), code several features share into src/shared/models/ or src/shared/services/, input rules several apps or modules share (reading a list query, a reason) into src/shared/validation/, a wrapper of a plugin or code that reads a request through one (request.auth) into src/infra/<plugin>/, and browser code several apps or modules share into src/shared/browser/ (components, layouts, composables, styles, lib)',
46
+ });
47
+ }
48
+ debug('check: shared-folder rule done', { entries: entries.length, problems: problems.length });
49
+ return problems;
50
+ }
@@ -129,7 +129,7 @@ export async function viteConfigProblems(root, installed) {
129
129
  const open = (match.index ?? 0) + match[0].length - 1;
130
130
  for (const [offset, item] of items(text, code, open))
131
131
  if (WIDE_ALLOW.test(item))
132
- report(offset, `allow: [${item.trim()}] lets the dev server serve the project root or server code (src/ outside views/, tests/, scripts/); through a devHosts tunnel that is public`, 'allow only the folders the browser loads (the views folders are allowed already), for example dokebiInertia({ allow: ["src/shared/browser"] })');
132
+ report(offset, `allow: [${item.trim()}] lets the dev server serve the project root or server code (src/ outside views/, tests/, scripts/); through a devHosts tunnel that is public`, 'allow only folders whose files the browser loads by URL without an import; the views folders and every file a served page imports (src/shared/browser/, D-0226) are allowed already');
133
133
  }
134
134
  debug('check: vite config read for the dev file rule', { file, problems: problems.length });
135
135
  return problems;
package/dist/commands.js CHANGED
@@ -180,6 +180,11 @@ export const COMMANDS = [
180
180
  summary: 'Unregister a feature module; its folder is kept',
181
181
  },
182
182
  { name: 'module list', usage: 'dokebi module list [--json]', summary: 'List feature modules' },
183
+ {
184
+ name: 'module sync',
185
+ usage: 'dokebi module sync [--dry-run] [--json]',
186
+ summary: 'Write src/dokebi.modules.generated.ts from the registered modules',
187
+ },
183
188
  {
184
189
  name: 'settings add',
185
190
  usage: 'dokebi settings add <section> [--dry-run] [--json]',
@@ -667,6 +672,10 @@ export const COMMAND_DETAILS = {
667
672
  example: 'npx dokebi module remove items --json',
668
673
  },
669
674
  'module list': { flags: [], example: 'npx dokebi module list --json' },
675
+ 'module sync': {
676
+ flags: [['--dry-run', 'plan only']],
677
+ example: 'npx dokebi module sync --json',
678
+ },
670
679
  'settings add': {
671
680
  flags: [['--dry-run', 'plan only']],
672
681
  example: 'npx dokebi settings add survey --json',
@@ -15,7 +15,9 @@ export function templateTarget(path) {
15
15
  key === 'src/main.ts' ||
16
16
  key.startsWith('src/main.ts/') ||
17
17
  key === 'src/dokebi.generated.ts' ||
18
- key.startsWith('src/dokebi.generated.ts/')) {
18
+ key.startsWith('src/dokebi.generated.ts/') ||
19
+ key === 'src/dokebi.modules.generated.ts' ||
20
+ key.startsWith('src/dokebi.modules.generated.ts/')) {
19
21
  throw new CliError('UNSAFE_PATH', `Template target is reserved: ${path}`);
20
22
  }
21
23
  }
@@ -3,6 +3,10 @@ export declare const PRETTIER_IGNORE = ".prettierignore";
3
3
  export declare const PRETTIER_MARKER = "# dokebi: applied migrations are never reformatted (D-0145; @dokebi/migrate checks them)";
4
4
  /** The CLI-written registration; the CLI refuses a project whose copy differs (MODIFIED_REGISTRATION). */
5
5
  export declare const GENERATED_FILE = "src/dokebi.generated.ts";
6
+ /** The CLI-written module list (D-0227); doctor refuses a copy that differs, like the registration. */
7
+ export declare const MODULE_LIST_FILE = "src/dokebi.modules.generated.ts";
8
+ /** The files the CLI writes and refuses when they differ: formatters stay out of each. */
9
+ export declare const GENERATED_FILES: readonly string[];
6
10
  /** The comment line above the CLI-owned .prettierignore entry of the generated registration. */
7
11
  export declare const PRETTIER_GENERATED_MARKER = "# dokebi: the CLI writes src/dokebi.generated.ts and refuses a reformatted copy (MODIFIED_REGISTRATION)";
8
12
  export type FormatterTool = 'prettier' | 'biome' | 'eslint';
@@ -16,8 +16,18 @@ export const PRETTIER_IGNORE = '.prettierignore';
16
16
  export const PRETTIER_MARKER = '# dokebi: applied migrations are never reformatted (D-0145; @dokebi/migrate checks them)';
17
17
  /** The CLI-written registration; the CLI refuses a project whose copy differs (MODIFIED_REGISTRATION). */
18
18
  export const GENERATED_FILE = 'src/dokebi.generated.ts';
19
+ /** The CLI-written module list (D-0227); doctor refuses a copy that differs, like the registration. */
20
+ export const MODULE_LIST_FILE = 'src/dokebi.modules.generated.ts';
21
+ /** The files the CLI writes and refuses when they differ: formatters stay out of each. */
22
+ export const GENERATED_FILES = [GENERATED_FILE, MODULE_LIST_FILE];
19
23
  /** The comment line above the CLI-owned .prettierignore entry of the generated registration. */
20
24
  export const PRETTIER_GENERATED_MARKER = '# dokebi: the CLI writes src/dokebi.generated.ts and refuses a reformatted copy (MODIFIED_REGISTRATION)';
25
+ /** The comment line above the CLI-owned .prettierignore entry of a generated file. */
26
+ function generatedMarker(file) {
27
+ return file === GENERATED_FILE
28
+ ? PRETTIER_GENERATED_MARKER
29
+ : `# dokebi: the CLI writes ${file} and refuses a reformatted copy (MODIFIED_REGISTRATION)`;
30
+ }
21
31
  /** Whether a path is a migrations folder (bare `migrations` patterns keep any of those out). */
22
32
  const isMigrations = (path) => path === 'migrations' || path.endsWith('/migrations');
23
33
  const PRETTIER_CONFIGS = [
@@ -119,8 +129,8 @@ export function prettierIgnoreText(ignore, folder) {
119
129
  if (prettierCovers(ignore, folder))
120
130
  return ignore;
121
131
  const end = ignore === '' || ignore.endsWith('\n') ? '' : '\n';
122
- const file = folder === GENERATED_FILE;
123
- return `${ignore}${end}${ignore === '' ? '' : '\n'}${file ? PRETTIER_GENERATED_MARKER : PRETTIER_MARKER}\n${folder}${file ? '' : '/'}\n`;
132
+ const file = GENERATED_FILES.includes(folder);
133
+ return `${ignore}${end}${ignore === '' ? '' : '\n'}${file ? generatedMarker(folder) : PRETTIER_MARKER}\n${folder}${file ? '' : '/'}\n`;
124
134
  }
125
135
  /** A negated biome pattern that keeps `folder` out (`!src/infra/db/migrations`, or any migrations folder). */
126
136
  function biomeExcludes(pattern, folder) {
@@ -330,7 +340,7 @@ export async function formatterUses(root, folder) {
330
340
  }
331
341
  /** The one-line fix for a formatter that would format the migrations folder. */
332
342
  export function formatterFix(use, folder) {
333
- const file = folder === GENERATED_FILE;
343
+ const file = GENERATED_FILES.includes(folder);
334
344
  switch (use.tool) {
335
345
  case 'prettier':
336
346
  return `add ${folder}${file ? '' : '/'} to ${PRETTIER_IGNORE} (npx dokebi add writes it when it installs a plugin)`;
@@ -338,7 +348,7 @@ export function formatterFix(use, folder) {
338
348
  return `add "!${folder}" to files.includes of ${use.config} (biome 1: "${folder}" to files.ignore)`;
339
349
  case 'eslint':
340
350
  return file
341
- ? `add "${folder}" to the ignores of ${use.config}: its formatting rules would rewrite the registration the CLI writes`
351
+ ? `add "${folder}" to the ignores of ${use.config}: its formatting rules would rewrite a file the CLI writes`
342
352
  : `add "${folder}/**" to the ignores of ${use.config}: its formatting rules would rewrite applied migrations`;
343
353
  }
344
354
  }
@@ -1,3 +1,4 @@
1
+ import { MODULE_LIST_FILE } from './formatter-ignore.js';
1
2
  import { type PluginManifest } from './manifest.js';
2
3
  import type { Installation } from './project-state.js';
3
4
  /**
@@ -18,6 +19,15 @@ import type { Installation } from './project-state.js';
18
19
  * `options.logging`; without one, `createLogger` returns undefined (core's console logger).
19
20
  */
20
21
  export declare function generateRegistration(plugins: PluginManifest[], installations?: Readonly<Record<string, Installation>>, apps?: readonly string[], modules?: readonly string[], settings?: readonly string[]): string;
22
+ /**
23
+ * The registered modules as code (D-0227): `src/dokebi.modules.generated.ts`, written beside the
24
+ * registration whenever a plugin hosts modules (`@dokebi/module`). Apps and project files import
25
+ * it where they need every module (an app that mounts each one, permission keys or menu entries
26
+ * collected from each module), so a project never keeps a module list of its own (D-0032 §5).
27
+ * It imports the modules only, never the registration or the apps, so an app can import it.
28
+ */
29
+ export { MODULE_LIST_FILE };
30
+ export declare function generateModuleList(modules: readonly string[]): string;
21
31
  export declare const LEGACY_MAIN_SOURCE = "import { Application } from '@dokebi/core';\nimport { registerPlugins } from './dokebi.generated.ts';\n\nconst app = new Application();\nregisterPlugins(app);\nawait app.start();\ntry {\n app.logger.log('info', 'Dokebi application started');\n // Run local work here. Long-running apps own their signal and shutdown policy.\n} finally {\n await app.stop();\n}\n";
22
32
  /** The 0.2.0 YAML entry point before it became long-running; migrate still recognizes it. */
23
33
  export declare const MAIN_SOURCE_V1 = "import { Application, loadConfig } from '@dokebi/core';\nimport { registerPlugins } from './dokebi.generated.ts';\n\nconst document = await loadConfig(new URL('../dokebi.yaml', import.meta.url));\nconst app = new Application({ config: document.options });\nawait registerPlugins(app);\nawait app.start();\ntry {\n app.logger.log('info', 'Dokebi application started');\n // Run local work here. Long-running apps own their signal and shutdown policy.\n} finally {\n await app.stop();\n}\n";
@@ -56,7 +66,8 @@ export declare const MAIN_SOURCE: string;
56
66
  /**
57
67
  * tsconfig.json written by init. `node src/main.ts` strips types without compiling, so the
58
68
  * editor and `tsc` should reject syntax Node cannot run (erasableSyntaxOnly) and need explicit
59
- * `.ts` imports and `import type` (allowImportingTsExtensions, verbatimModuleSyntax).
69
+ * `.ts` imports and `import type` (allowImportingTsExtensions, verbatimModuleSyntax). Browser code
70
+ * (BROWSER_CODE) is left to tsconfig.vue.json (D-0226).
60
71
  */
61
72
  /**
62
73
  * Development tools `dokebi init` pins in a new project (stage 3 §0). `@dokebi/cli` is the CLI
@@ -75,4 +86,10 @@ export declare const TYPECHECK_SCRIPT = "tsc -p tsconfig.json --noEmit";
75
86
  * named *.test.ts (D-0092 §3, the "Files and folders" rule of capability-guide.ts).
76
87
  */
77
88
  export declare const TEST_SCRIPT = "node --test \"tests/**/*.test.ts\"";
89
+ /**
90
+ * The browser code of a project (D-0226): the views folders of apps and modules (Vue pages and
91
+ * their .ts helpers) and the code they share. tsconfig.json leaves it out; tsconfig.vue.json of
92
+ * `app add --inertia` checks its .ts with vue-tsc.
93
+ */
94
+ export declare const BROWSER_CODE: readonly string[];
78
95
  export declare const TSCONFIG_SOURCE: string;
package/dist/generator.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { MODULE_LIST_FILE } from './formatter-ignore.js';
1
2
  import { findHost, hostOf } from './manifest.js';
2
3
  import { CLI_VERSION } from './output.js';
3
4
  /** Import specifier of a user entry file, relative to src/dokebi.generated.ts. */
@@ -148,6 +149,28 @@ ${factories.join('\n')}
148
149
  }
149
150
  `;
150
151
  }
152
+ /**
153
+ * The registered modules as code (D-0227): `src/dokebi.modules.generated.ts`, written beside the
154
+ * registration whenever a plugin hosts modules (`@dokebi/module`). Apps and project files import
155
+ * it where they need every module (an app that mounts each one, permission keys or menu entries
156
+ * collected from each module), so a project never keeps a module list of its own (D-0032 §5).
157
+ * It imports the modules only, never the registration or the apps, so an app can import it.
158
+ */
159
+ export { MODULE_LIST_FILE };
160
+ export function generateModuleList(modules) {
161
+ const imports = modules.map((name, index) => `import module${index} from ${JSON.stringify(`./shared/modules/${name}/module.ts`)};`);
162
+ const entries = modules.map((name, index) => ` ${JSON.stringify(name)}: module${index},`);
163
+ return `// Generated by dokebi from the modules \`dokebi module add\` registered (D-0227). Never edit it:
164
+ // \`dokebi module add\` and \`dokebi module remove\` rewrite it. Import it where code needs every
165
+ // module instead of keeping a list of your own.
166
+ ${imports.join('\n')}${imports.length ? '\n\n' : ''}/** The registered modules by name, in registration order. */
167
+ export const registeredModules = {
168
+ ${entries.join('\n')}${entries.length ? '\n' : ''}} as const;
169
+
170
+ /** The name of a registered module. */
171
+ export type RegisteredModuleName = keyof typeof registeredModules;
172
+ `;
173
+ }
151
174
  export const LEGACY_MAIN_SOURCE = "import { Application } from '@dokebi/core';\nimport { registerPlugins } from './dokebi.generated.ts';\n\nconst app = new Application();\nregisterPlugins(app);\nawait app.start();\ntry {\n app.logger.log('info', 'Dokebi application started');\n // Run local work here. Long-running apps own their signal and shutdown policy.\n} finally {\n await app.stop();\n}\n";
152
175
  /** The 0.2.0 YAML entry point before it became long-running; migrate still recognizes it. */
153
176
  export const MAIN_SOURCE_V1 = `import { Application, loadConfig } from '@dokebi/core';
@@ -325,7 +348,8 @@ export const MAIN_SOURCE = MAIN_SOURCE_V5.replace('resolve(process.env.DOKEBI_CO
325
348
  /**
326
349
  * tsconfig.json written by init. `node src/main.ts` strips types without compiling, so the
327
350
  * editor and `tsc` should reject syntax Node cannot run (erasableSyntaxOnly) and need explicit
328
- * `.ts` imports and `import type` (allowImportingTsExtensions, verbatimModuleSyntax).
351
+ * `.ts` imports and `import type` (allowImportingTsExtensions, verbatimModuleSyntax). Browser code
352
+ * (BROWSER_CODE) is left to tsconfig.vue.json (D-0226).
329
353
  */
330
354
  /**
331
355
  * Development tools `dokebi init` pins in a new project (stage 3 §0). `@dokebi/cli` is the CLI
@@ -348,6 +372,16 @@ export const TYPECHECK_SCRIPT = 'tsc -p tsconfig.json --noEmit';
348
372
  * named *.test.ts (D-0092 §3, the "Files and folders" rule of capability-guide.ts).
349
373
  */
350
374
  export const TEST_SCRIPT = 'node --test "tests/**/*.test.ts"';
375
+ /**
376
+ * The browser code of a project (D-0226): the views folders of apps and modules (Vue pages and
377
+ * their .ts helpers) and the code they share. tsconfig.json leaves it out; tsconfig.vue.json of
378
+ * `app add --inertia` checks its .ts with vue-tsc.
379
+ */
380
+ export const BROWSER_CODE = Object.freeze([
381
+ 'src/apps/*/views/**',
382
+ 'src/shared/modules/*/views/**',
383
+ 'src/shared/browser/**',
384
+ ]);
351
385
  export const TSCONFIG_SOURCE = `${JSON.stringify({
352
386
  compilerOptions: {
353
387
  target: 'ES2023',
@@ -365,4 +399,7 @@ export const TSCONFIG_SOURCE = `${JSON.stringify({
365
399
  types: ['node'],
366
400
  },
367
401
  include: ['src/**/*.ts', 'tests/**/*.ts'],
402
+ // D-0226: browser code — the views of apps and modules and what they share — is checked by
403
+ // vue-tsc (tsconfig.vue.json, with Vite's types), not as server code.
404
+ exclude: BROWSER_CODE,
368
405
  }, null, 2)}\n`;
package/dist/layout.d.ts CHANGED
@@ -10,6 +10,15 @@ import type { InstallPlan } from './install-plan.js';
10
10
  * (each app's folder is made by `dokebi app add`).
11
11
  */
12
12
  export declare function layoutAllowed(path: string, hosts?: readonly string[], kind?: 'file' | 'directory'): boolean;
13
+ /**
14
+ * What the layout names right under src/shared/ (D-0031, D-0032, D-0155, D-0226, D-0227): shared
15
+ * models and services, layouts and partials (views), translation catalogs, mail templates,
16
+ * application settings, feature modules, the browser code several apps and modules share, the
17
+ * input rules several apps and modules share (validation), and the app error catalog.
18
+ * `dokebi check` warns about any other entry (shared-folder).
19
+ */
20
+ export declare const SHARED_FOLDERS: readonly ["browser", "locales", "mail", "models", "modules", "services", "settings", "validation", "views"];
21
+ export declare const SHARED_FILES: readonly ["errors.ts"];
13
22
  /** Rejects plugin files and folders outside the layout with INVALID_MANIFEST. */
14
23
  export declare function assertLayout(plan: Pick<InstallPlan, 'files' | 'directories'> & {
15
24
  entry?: {
package/dist/layout.js CHANGED
@@ -21,6 +21,25 @@ export function layoutAllowed(path, hosts = [], kind = 'file') {
21
21
  return true;
22
22
  return hosts.includes('apps') && (key === 'src/apps' || key.startsWith('src/apps/'));
23
23
  }
24
+ /**
25
+ * What the layout names right under src/shared/ (D-0031, D-0032, D-0155, D-0226, D-0227): shared
26
+ * models and services, layouts and partials (views), translation catalogs, mail templates,
27
+ * application settings, feature modules, the browser code several apps and modules share, the
28
+ * input rules several apps and modules share (validation), and the app error catalog.
29
+ * `dokebi check` warns about any other entry (shared-folder).
30
+ */
31
+ export const SHARED_FOLDERS = Object.freeze([
32
+ 'browser',
33
+ 'locales',
34
+ 'mail',
35
+ 'models',
36
+ 'modules',
37
+ 'services',
38
+ 'settings',
39
+ 'validation',
40
+ 'views',
41
+ ]);
42
+ export const SHARED_FILES = Object.freeze(['errors.ts']);
24
43
  /** Rejects plugin files and folders outside the layout with INVALID_MANIFEST. */
25
44
  export function assertLayout(plan, pluginId, hosts = []) {
26
45
  const targets = [
package/dist/output.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const CLI_VERSION = "0.4.52";
1
+ export declare const CLI_VERSION = "0.4.54";
2
2
  export declare function envelope(command: string, result: unknown, ok?: boolean): object;
3
3
  export declare function failure(command: string, error: unknown, mutationStarted: boolean): object;
package/dist/output.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CliError } from './errors.js';
2
- export const CLI_VERSION = '0.4.52';
2
+ export const CLI_VERSION = '0.4.54';
3
3
  export function envelope(command, result, ok = true) {
4
4
  return { schemaVersion: 1, cliVersion: CLI_VERSION, command, ok, result, error: null };
5
5
  }
@@ -171,7 +171,7 @@ Run the command-line tools installed in this project by their bin names from the
171
171
  - An existing \`.env\` is still passed to the app by \`npx dokebi dev\`, \`start\` and \`verify\`; do not create one for secrets.
172
172
  - Docker infrastructure uses the same YAML password: prepare with \`npx dokebi dev-infra\`, then \`npx dokebi dev-infra up\`. No .env is generated. Use repeated \`--file <path>\` for multiple Compose files; start every required database, Redis, NATS and mail service before the app. Stopping an evaluation's containers makes its saved app unusable until those services are started again. Preserve the database password and volumes on migration. A MongoDB from \`dev-infra\` is a single-node replica set (\`rs0\`), so multi-document transactions work; never hand-edit compose.yaml to get one, and when \`dev-infra\` warns \`DEV_INFRA_STANDALONE\` (a compose.yaml written before), follow its \`hint\` to switch.
173
173
  - **To see what the app has, run \`npx dokebi describe --json\`**: every route (with \`id\`, schema and the login rule of @dokebi/auth), the pages (EJS views, Inertia components), jobs, schedules, the error codes of \`src/shared/errors.ts\`, the option keys and the environment variable names, never a value. It loads the app without serving or connecting; read it before you change code you did not write. Before you write a migration, run \`npx dokebi describe --with-db --json\` to see the current tables (it connects to each database); \`npx dokebi describe --openapi\` gives an OpenAPI 3.1 document per app.
174
- - **Applied migrations are never reformatted or edited** (D-0145): their contents are recorded when they run. Keep code formatters (prettier, biome, eslint --fix) out of the migrations folder; \`npx dokebi add\` writes the ignore entry for prettier and biome, and \`npx dokebi check\` warns (\`formatter-migrations\`) when a formatter would still format it. The same goes for \`src/dokebi.generated.ts\`, which the CLI writes and refuses once it changed (\`formatter-generated\`, doctor \`MODIFIED_REGISTRATION\`). Change the schema with a new migration; never pass \`--accept-changed\` to make a run pass.
174
+ - **Applied migrations are never reformatted or edited** (D-0145): their contents are recorded when they run. Keep code formatters (prettier, biome, eslint --fix) out of the migrations folder; \`npx dokebi add\` writes the ignore entry for prettier and biome, and \`npx dokebi check\` warns (\`formatter-migrations\`) when a formatter would still format it. The same goes for \`src/dokebi.generated.ts\` and \`src/dokebi.modules.generated.ts\`, which the CLI writes and refuses once they changed (\`formatter-generated\`, doctor \`MODIFIED_REGISTRATION\` and \`MODULE_LIST_MODIFIED\`). Change the schema with a new migration; never pass \`--accept-changed\` to make a run pass.
175
175
 
176
176
  ## 3. Before you say it is done
177
177
 
@@ -189,8 +189,8 @@ Run the command-line tools installed in this project by their bin names from the
189
189
  - \`src/main.ts\` is the user entry point, \`dokebi.yaml\` holds the real settings of this machine (kept out of Git), and \`dokebi.example.yaml\` is a sample without secrets.
190
190
  - Folders and file names (D-0031, D-0032, D-0092): follow the **Files and folders** rule in \`### Integration rules\` below, which \`npx dokebi guide --sync\` keeps current: apps in \`src/apps/<app>\`, shared code in \`src/shared/{models,services,modules,views,locales,mail}\` and \`src/shared/errors.ts\`, plugin code in \`src/infra/<name>\`, tests in \`tests/unit\`, \`tests/integration\` and \`tests/support\`, tools in \`scripts/\`. App-specific business code lives in apps; reusable features live in shared/modules and cross-app services in shared/services. Shared services must not import app-specific code.
191
191
  - App roots contain \`app.ts\` and \`routes.ts\`; module roots contain \`module.ts\` and \`routes.ts\`. Registration files compose dependencies and routes. Use Controller -> Service -> Model for application data. Controllers handle HTTP, services provide data through models and own workflows, models own persistence, validation owns input rules, and jobs invoke services. Services accept explicit inputs and return DTOs without HTTP or template objects. Add these folders only when needed. Route groups may live in \`routes/\` and contain only bindings and access policies. Stateless controllers may be instantiated once by their route group; resource-owning controllers use \`defineController\` and app/module registration.
192
- - Replace or remove unused scaffold controllers, models and views when implementing the real feature; do not keep an inactive parallel implementation. Inertia pages belong to the mounting app's \`views/<template>/Pages\`, components to its \`components/\`, reusable browser/SSR integration to \`views/runtime/\` (keep the generated \`views/app.js\` and \`views/ssr.js\` entries; moving them also requires updating Vite inputs and manifest/SSR paths), and shared translation data to \`src/shared/locales/<language>/<namespace>.json\`.
193
- - **CLI-owned generated files** include \`src/dokebi.generated.ts\`, \`.dokebi/state.json\`, \`.dokebi/recipe.json\` and the parts of this file between the \`dokebi:installed\` and \`dokebi:capabilities\` markers. Commands also update YAML and package metadata transactionally; this is not an exhaustive list of files a command may write. Refresh the maintained guidance with \`npx dokebi guide --sync\`. Never edit them by hand; change them with commands (\`dokebi check\` reports \`generated-file\`). The block between the \`dokebi:project\` markers is the project's: the CLI never changes it; add the project's own rules there when the user asks you to record one.
192
+ - Replace or remove unused scaffold controllers, models and views when implementing the real feature; do not keep an inactive parallel implementation. Inertia pages belong to the app that renders them (its \`views/<template>/Pages\`) or to the module whose pages they are (the module's \`views/<template>/Pages\`, D-0218), components to its \`components/\`, reusable browser/SSR integration to \`views/runtime/\` (keep the generated \`views/app.js\` and \`views/ssr.js\` entries; moving them also requires updating Vite inputs and manifest/SSR paths), and shared translation data to \`src/shared/locales/<language>/<namespace>.json\`.
193
+ - **CLI-owned generated files** include \`src/dokebi.generated.ts\`, \`src/dokebi.modules.generated.ts\` (the registered modules: import \`registeredModules\` from it instead of a module list of your own), \`.dokebi/state.json\`, \`.dokebi/recipe.json\` and the parts of this file between the \`dokebi:installed\` and \`dokebi:capabilities\` markers. Commands also update YAML and package metadata transactionally; this is not an exhaustive list of files a command may write. Refresh the maintained guidance with \`npx dokebi guide --sync\`. Never edit them by hand; change them with commands (\`dokebi check\` reports \`generated-file\`). The block between the \`dokebi:project\` markers is the project's: the CLI never changes it; add the project's own rules there when the user asks you to record one.
194
194
  - **Scaffold source files declared owner: user are user code**: the shared layout and views (\`src/shared/views/layouts/main.ejs\` and others), entry files (for example \`src/infra/db/connections.ts\`, \`src/infra/web/extension.ts\`), and the app and module files \`app add\` and \`module add\` create (app.ts, routes.ts, controllers, models, views and the examples \`items.ts\`, \`summary.ts\`, \`site.ts\`). **Maintain them as user code.** When the user requests structural changes, move them within their app/module and update all imports, resource paths and registration; do not copy them into a second implementation. Never move or hand-edit CLI-owned generated files. doctor does not warn about them, and upgrade does not overwrite an edited one (the new template location is in \`preservedDetails\`).
195
195
  - Node runs the .ts files in \`src\` by stripping their types. Do not use syntax that cannot be stripped, such as constructor parameter properties, enum or namespace (\`npm run typecheck\` reports it). Do not run \`npx tsc\` (the npm package named tsc is not TypeScript).
196
196
  - doctor repairs nothing. Never delete the lock (\`.dokebi/lock\`) or a backup, and never blindly re-run a failed command.
@@ -11,9 +11,11 @@ import { ENV_FILE, envFileWarnings } from './env-file.js';
11
11
  import { CliError } from './errors.js';
12
12
  import { exists, fingerprint, hash, json, parseObject, securePath } from './filesystem.js';
13
13
  import { adminSections } from './first-admin.js';
14
+ import { MODULE_LIST_FILE } from './formatter-ignore.js';
15
+ import { generateModuleList } from './generator.js';
14
16
  import { legacyLayout, MOVED_RECIPE_FILES } from './layout.js';
15
17
  import { loggingDiagnostics } from './logging-config.js';
16
- import { optionsKey, orderPlugins, readManifest } from './manifest.js';
18
+ import { findHost, optionsKey, orderPlugins, readManifest, } from './manifest.js';
17
19
  import { dependencyMap, validateProjectPackage } from './npm-client.js';
18
20
  import { optionsFix } from './option-fixes.js';
19
21
  import { checkPlugin, checkPluginsOptions } from './plugin-lifecycle.js';
@@ -404,6 +406,37 @@ export class ProjectInspector {
404
406
  severity: 'error',
405
407
  hint: 'a hand edit or a code formatter (prettier, biome) changed it: restore it (git checkout -- src/dokebi.generated.ts) and keep formatters out of it (the file in .prettierignore, "!src/dokebi.generated.ts" in biome files.includes; npx dokebi check warns formatter-generated)',
406
408
  });
409
+ // D-0227: the module list beside the registration, while a plugin hosts modules. A project
410
+ // made before cli 0.4.54 has none yet (a warning: nothing imports it there).
411
+ if (state && findHost(state.plugins, 'modules')) {
412
+ const expected = generateModuleList(state.modules ?? []);
413
+ const listed = await check(MODULE_LIST_FILE, async () => {
414
+ try {
415
+ return await read(MODULE_LIST_FILE);
416
+ }
417
+ catch (error) {
418
+ if (isMissing(error))
419
+ return undefined;
420
+ throw error;
421
+ }
422
+ });
423
+ if (listed === undefined)
424
+ result.diagnostics.push({
425
+ code: 'MODULE_LIST_MISSING',
426
+ path: MODULE_LIST_FILE,
427
+ plugin: null,
428
+ severity: 'warning',
429
+ hint: 'npx dokebi module sync writes the registered modules there (D-0227); import registeredModules from it instead of keeping a module list of your own',
430
+ });
431
+ else if (listed !== null && listed !== expected)
432
+ result.diagnostics.push({
433
+ code: 'MODULE_LIST_MODIFIED',
434
+ path: MODULE_LIST_FILE,
435
+ plugin: null,
436
+ severity: 'error',
437
+ hint: `a hand edit or a code formatter changed it, and the next module add, remove or sync writes it again without the edit: run npx dokebi module sync, and keep formatters out of it (the file in .prettierignore, "!${MODULE_LIST_FILE}" in biome files.includes; npx dokebi check warns formatter-generated)`,
438
+ });
439
+ }
407
440
  const control = await check('.dokebi', async () => readdir(await securePath(root, '.dokebi')));
408
441
  // AI-M04 F6: a lock whose command still runs is that command's work in progress (its open
409
442
  // transaction folder included), not an interrupted change that needs recovery.
package/dist/project.d.ts CHANGED
@@ -320,6 +320,12 @@ export declare class Project {
320
320
  }): Promise<OperationResult>;
321
321
  /** `dokebi module remove <name>`: unregisters the module; its folder is user code and stays. */
322
322
  moduleRemove(root: string, name: string, dryRun?: boolean): Promise<OperationResult>;
323
+ /**
324
+ * `dokebi module sync` (D-0227): writes src/dokebi.modules.generated.ts (and the registration)
325
+ * from the registered modules, unchanged otherwise. A project made before cli 0.4.54 gets its
326
+ * module list this way; any later module add or remove keeps it current.
327
+ */
328
+ moduleSync(root: string, dryRun?: boolean): Promise<OperationResult>;
323
329
  /** `dokebi module list`: the registered modules in registration order. */
324
330
  moduleList(root: string): Promise<{
325
331
  modules: {