@dokebi/cli 0.4.53 → 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.
package/AI.md CHANGED
@@ -91,7 +91,7 @@ The `blog` plan, depending on the answers: `init` (when the folder is not a proj
91
91
  | `dokebi inspect [--verbose]` / `dokebi doctor [--production] [--verbose]` | `--production` (D-0184) adds the checks of a server, on the settings the app reads there (`DOKEBI_CONFIG` merged with `DOKEBI_SECRETS`; the plugins' option checks see the merged options too): `NODE_ENV_NOT_PRODUCTION` (error: run it as the service runs), `STATE_NOT_SHARED` (error: the per-process state D-0161 refuses in production — memory sessions, auth tokens and login counts, OAuth grants, local rate limits, a local WebSocket hub, seal nonces; a warning for local lock or cache backends), `TRANSPORT_NOT_FOR_PRODUCTION` (mail `log`/`capture`), `WEB_PORT_UNSET` (port 0), `TRUST_PROXY_EMPTY` and `WEB_LISTENS_EVERYWHERE` (warnings), `STORAGE_RELATIVE` (warning: a storage folder inside the release), `PLACEHOLDER_LEFT`, `CONFIG_SECRETS_MISSING`/`_UNSAFE`/`_CONFLICT`/`_UNMATCHED` (as the start would fail), `SECRETS_MISSING` (a plugin's generated secret is not set), `SECRET_IN_CONFIG_FILE` (warning), and with @dokebi/migrate `dokebi-migrate status --json` with those settings: `MIGRATIONS_PENDING` (error: pre-deploy files), `MIGRATIONS_POST_DEPLOY_PENDING` and `MIGRATION_FILE_MISSING` (warnings), `MIGRATIONS_UNCHECKED` (error: status could not run). Read-only diagnosis. doctor exits 1 on an error diagnostic. doctor also runs each installed plugin's own option rules once its section passes the schema (D-0162: the cross-field `checks` the schema cannot say, such as `dokebi-app.unknownDomain` must be `reject` or a key of `domains`), in the same permission-restricted child as install modules: a broken rule is `INVALID_PLUGIN_OPTIONS` with `details[{instancePath, keyword, message}]` (no values) and a `hint`, the error the app would stop with; `config set` refuses such a value the same way and writes nothing. All plugins are checked in one child; a plugin whose entry cannot run there is the warning `PLUGIN_OPTIONS_CHECK_FAILED` (`details.code`; start still checks its rules). The default human output is a summary (health, error and warning counts, one line per diagnostic and plugin); `--verbose` prints everything. `--json` is always complete, with `result.summary{healthy, errors, warnings, plugins, codes}` first. **File ownership (D-0065 §11)**: skeletons that plugins and the CLI create (the shared layout `src/shared/views/layouts/main.ejs`, entry files `src/infra/<name>/…`, `src/infra/worker/tasks.ts`, `src/infra/events/types.ts`, app and module files) are `owner: user`, so editing them is no diagnostic (upgrade keeps edited files); only editing a file a manifest declares `owner: "cli"` (a file that is generated again) is a `MODIFIED_TEMPLATE` warning (`hint`). **Locks**: inspect and doctor take no lock. While another command holds `.dokebi/lock` (a `--dry-run` too), `PROJECT_LOCKED` has `details{pid, running, since, transactions}` and a `hint`: with `running: true` that command is still working (its `.dokebi/transaction-*` is not reported as `RECOVERY_REQUIRED`), so run inspect again when it has ended; with `running: false` the change was interrupted (`RECOVERY_REQUIRED` too): ask the user, never delete the lock |
92
92
  | `dokebi app add <name> [--domain <host>]... [--template <name>] [--inertia [--ssr]] [--view <ejs\|none>] [--seal] [--answers-from <user\|defaults>] [--ai-chose view] [--ai-reason view=<why>]` | The app `src/apps/<name>` (D-0030). Its view is a product choice whose default is Inertia + Vue (`--inertia`); without `--inertia` it is EJS, except in a project whose recipe built no browser screens (the api recipe records `view = none`): there the app has no views, only `app.ts` and a `routes.ts` whose `/` answers JSON, no EJS pages and no shared layout, and nothing is recorded for it (tellUser already says the recipe's `view = none`). `--view ejs` gives EJS pages there, `--view none` an app without views anywhere (recorded like EJS: who chose it); `--view` with `--inertia`, or `--view none` with `--template`, is `USAGE`. The result's `appView{value, from}` says what the app got (`ejs`, `none`, `inertia-vue`, `inertia-vue-ssr`; `from: recipe` when the project's recipe chose it). D-0098: the view is recorded in `.dokebi/recipe.json` (`choices`) with who chose it, and verify's `tellUser` says it: `--answers-from user` (the user or the request chose it), `--ai-chose view` with `--ai-reason view=<why>` (the user left it to you; `--answers-from defaults` means the same). An EJS app without either is recorded as unstated, the result warns `VIEW_SOURCE_UNSTATED`, and tellUser says `not the default view (Inertia + Vue), and who chose it was not recorded`; an Inertia app without either records nothing (the default). `--ai-chose` names only `view` (`AI_CHOICE_UNKNOWN`); `AI_REASON_WITHOUT_CHOICE` and `INVALID_AI_REASON` as for recipes. The first app that `add @dokebi/app` creates (`main`, EJS) is recorded as unstated too; for a browser app with the default view use `add @dokebi/app --no-first-app` and then `app add <name> --inertia`. `--inertia` prepares the Vue skeleton, the Vite build and the Vue type check (`typecheck` script, `tsconfig.vue.json`, `typecheck-vue.mjs`, `src/infra/inertia/page.d.ts` for the shared page props), `--ssr` server rendering (D-0039), `--seal` writes `seal: true` on its domains (a domain with dots cannot be a `config set` path; without `@dokebi/seal` the warning `SEAL_PLUGIN_MISSING`). `--ssr` with `--seal` (0.4.34, D-0195; needs @dokebi/template-inertia 0.4.6, an older one fails the start with `SEAL_SSR_CONFLICT`): only the pages a route renders with `{ public: true }` are server rendered there, plain and without the visitor's props; the others stay sealed. An `@dokebi/app` whose Inertia build template predates the Vue type check (0.4.2 and older) refuses `--inertia` before anything is written: `INVALID_MANIFEST` (phase `plan`, `details.missing`, `details.fix`: `npx dokebi upgrade dokebi-app`, then the same `app add`) |
93
93
  | `dokebi app remove <name>` · `app link <app> <domain> [--template] [--seal]` · `app unlink <domain>` · `app list` | Manage apps and domains. `app remove` fails with `APP_IN_USE` while a domain still points to the app (unlink first); it removes the registration and `options.dokebi-app.apps.<name>` (D-0061 per-app settings) from dokebi.yaml and the sample (0.2.5; otherwise the next start fails with `UNKNOWN_APP`) and the app's recorded view from `.dokebi/recipe.json`. The folder stays (user code; the result lists it in `preserved` with the warning `APP_FOLDER_KEPT`) |
94
- | `dokebi module add <name> [--no-views]` · `module remove` · `module list` | Feature modules `src/shared/modules/<name>` (D-0032). `--no-views`: the routes answer JSON |
94
+ | `dokebi module add <name> [--no-views]` · `module remove` · `module list` · `module sync` | Feature modules `src/shared/modules/<name>` (D-0032). `--no-views`: the routes answer JSON. Add and remove rewrite `src/dokebi.modules.generated.ts` (D-0227, §4); `sync` writes it from the registered modules, for a project made before cli 0.4.54 |
95
95
  | `dokebi settings add <section>` · `settings sync` · `settings remove <section>` · `settings list` | The settings of the application itself in `options.<section>` (D-0155): `add` writes `src/shared/settings/<section>.ts` (core's `defineSettings` with a `defineOptions` declaration; an existing one default-exporting it is adopted), its schema `src/shared/settings/<section>.schema.json`, the defaults in dokebi.yaml and the example (with the `# reloadable` marks), and registers it, so the app checks the section at start and `config show/set/unset/secret`, doctor and reloads treat it like a plugin section. Code reads `<name>Settings.read(context.app.config)` (typed, cached per configuration, new after a reload). After changing the declaration run `settings sync` (doctor warns `SETTINGS_SCHEMA_STALE`). A value that is still the default the CLI wrote (the old schema's, such as the `pageSize: 50` and `workers: 2` placeholders of `settings add`) follows a changed default, in dokebi.yaml and the example (`sections[].followed`); a value set by hand stays. Then each section is checked against the new schema as doctor checks it: a missing required value is `configRequired`, anything else (a value set by hand above a lowered maximum, a value of an option the declaration dropped) is `INVALID_PLUGIN_OPTIONS` with `details.paths` and a `fix` (`npx dokebi config unset <paths>` or correct it by hand, then sync again), and nothing is written (AI-M49 D2: sync answered ok on what doctor and the app refuse). A section of a plugin, `logging` or `reload` is `SETTINGS_SECTION_CONFLICT`; `remove` keeps the files and the options. A section nothing declares has one code in every config command: `UNDECLARED_SECTION` (`UNKNOWN_PLUGIN` when the name is a plugin that is not installed); `config set` and `secret` refuse it, `config show` (text values hidden) and `unset` work on what is there and warn with it, and doctor and `dokebi check` (`undeclared-section`) report it |
96
96
  | `dokebi dev` | Development run (in the foreground). The app leads a process group of its own: what it started and left running when it stops (a restart, Ctrl+C) or crashes is ended (SIGTERM, SIGKILL after 2 s) and dev says so, so a restart never meets a port a helper of the old app holds. When `src/` or `.env` change it drains and starts again; when only `dokebi.yaml` changed it first asks the running app to read it again (D-0154): every changed option reloadable → applied without a restart (`dokebi.yaml reloaded without a restart: <paths>`), an invalid file → the app keeps its settings, anything else (an option that needs a restart, an app without reloads) → a restart as before. With a Vite config and template-inertia ≥0.1.2 it serves views from the Vite dev server with `DOKEBI_VITE_DEV=1` for **HMR** (no build needed; `.vue` and `views/` changes need no restart, D-0045). With template-inertia 0.4.0 that Vite is one host process per dev session, shared by every cluster worker and kept across app restarts (`DOKEBI_VITE_DEV_URL`, `DOKEBI_VITE_DEV_KEY`, D-0045 addendum 3); with 0.1.2 to 0.3 it runs inside the app. With an older template-inertia: a watch build and restarts. The app gets `DOKEBI_DEV=1`, so a cluster app runs one worker (`DOKEBI_DEV_WORKERS`, D-0044, D-0045), and the project's `.env`, read again at every restart (§2.2). What dev shows (the app, Vite and its own `[dokebi dev]` lines) is also written to `.dokebi/run/dev.log` (the previous session and one past 16 MB move to `dev.log.1`) and dev writes its pid to `.dokebi/run/dev.pid`, so `dokebi logs [-f]` shows the dev session from another shell (D-0201); with a terminal the app gets `DOKEBI_LOG_COLOR=1`, so the logger keeps its colours through the pipe |
97
97
  | `dokebi reload [--timeout-ms <ms>]` | Makes the background app (`dokebi start`) read dokebi.yaml again (D-0154): SIGHUP to the proven pid (through its log writer when this shell may not signal it), then the outcome the app wrote (`.dokebi/run/reload.json`, whatever its log level). `outcome: applied` (with `paths` and `revision`) or `unchanged`; `RELOAD_RESTART_REQUIRED` (`details.restartRequired`: nothing applied, restart to apply), `RELOAD_INVALID` (the app keeps its settings; `details` names the line or paths), `RELOAD_FAILED`, `RELOAD_UNSUPPORTED` (core older than 0.4.2, or `src/main.ts` gives the app no `configFile` or changed after the start: no signal is sent, it would end the app). Not running: exit 3. A running app also reads the file when it is saved (`options.reload.watch`) |
@@ -103,7 +103,7 @@ The `blog` plan, depending on the answers: `init` (when the folder is not a proj
103
103
  - A failed test, or a non-zero exit, fails verify (`TEST_FAILED`: the message names the failing tests). The tests' stdout and stderr are never copied into the result; error lines are masked with every secret value verify knows (values of `.env`, environment variables named like a secret, secrets of the settings file as `config show` hides them, `user:password@`, `password=…`), and left out when those cannot be read. Processes the tests leave running are killed before the app starts.
104
104
  - The human output adds one `FAIL <name> (<file>): <error>` line per failing test and a `tests: N passed, N failed, N skipped, N todo of N` line under the test check.
105
105
 
106
- Most commands support `--json` (one machine document); interactive `dev`, `logs` and `start --foreground` do not. Only commands listed by help support `--dry-run` (plan only), including init, recipe, add, upgrade, remove, config diff (with `--write`)/set/unset/init/secret, dev-infra, migrate, app add/remove/link/unlink and module add/remove (the first line of `--help` lists them from the usage lines). Any other command refuses `--dry-run` with `USAGE` naming them (`details.dryRunCommands`). `dokebi --help` prints one line per command; `dokebi <command> --help` prints that command with what each flag does and an example (exit 0). An unknown command is `UNKNOWN_COMMAND` (`details.suggestions` names similar commands, for example `help` → `--help`); a known command with wrong arguments is `USAGE` with its usage lines.
106
+ Most commands support `--json` (one machine document); interactive `dev`, `logs` and `start --foreground` do not. Only commands listed by help support `--dry-run` (plan only), including init, recipe, add, upgrade, remove, config diff (with `--write`)/set/unset/init/secret, dev-infra, migrate, app add/remove/link/unlink, module add/remove/sync and settings add/sync/remove (the first line of `--help` lists them from the usage lines). Any other command refuses `--dry-run` with `USAGE` naming them (`details.dryRunCommands`). `dokebi --help` prints one line per command; `dokebi <command> --help` prints that command with what each flag does and an example (exit 0). An unknown command is `UNKNOWN_COMMAND` (`details.suggestions` names similar commands, for example `help` → `--help`); a known command with wrong arguments is `USAGE` with its usage lines.
107
107
 
108
108
  ## 2. Work order (AI, adding one plugin outside a recipe)
109
109
 
@@ -178,16 +178,18 @@ One document on stdout: `{ schemaVersion, cliVersion, command, ok, result?, erro
178
178
  | `dokebi.yaml` | user | The real settings and their secrets (`schemaVersion: 1`, `options.<plugin id>`). 0600, kept out of Git |
179
179
  | `dokebi.example.yaml` | CLI | A sample with the schema descriptions as comments. Never holds secrets |
180
180
  | `src/dokebi.generated.ts` · `.dokebi/state.json` | CLI | **Never edit by hand**. Editing is `MODIFIED_REGISTRATION` |
181
+ | `src/dokebi.modules.generated.ts` | CLI | The registered modules (D-0227, with `@dokebi/module`): `registeredModules` (`{ <name>: module }` in registration order) and the type `RegisteredModuleName`. It imports the modules only, so apps and project files import it where code needs every module (an app that mounts each one, permission keys or menu entries collected from each module's declarations); never keep a module list of your own (D-0032 §5). `module add`, `remove` and `sync` write it; an edited copy is doctor `MODULE_LIST_MODIFIED` (error), a missing one `MODULE_LIST_MISSING` (warning: `npx dokebi module sync`) |
181
182
  | `src/main.ts` | user | The entry point (YAML loading → Application → create and register plugins → start). Every plugin factory checks its options against its own declaration: a wrong value stops the start with `INVALID_PLUGIN_OPTIONS` (`plugin`, `fix`, and the cause `INVALID_OPTIONS` naming `options.<plugin>.<path>`). The generated code carries no JSON Schema validator (D-0070) |
182
183
  | `src/apps/<app>/` | user | One app (app.ts, routes.ts or routes/, controllers, services, models, validation, views) |
183
- | `src/shared/modules/<module>/` | user | Feature modules (module.ts, routes.ts and the same folders); job handlers and event subscriptions are registered in the owning module's setup |
184
+ | `src/shared/modules/<module>/` | user | Feature modules (module.ts, routes.ts and the same folders); job handlers and event subscriptions are registered in the owning module's setup. Declarations the project adds to every module (menu entries, permission keys) are files at the module root named for what they declare (`menu.ts`, `permissions.ts`) that `module.ts` passes on; pages declared but not built yet are routes (`routes.ts`) (D-0227). A pure rule the module's server code and its pages both use (a code check, a rich-text schema) stays in its `validation/`, imports neither Node nor browser APIs, and the pages import it with a relative path |
184
185
  | `src/shared/{models,services,views,locales,mail}/` · `src/shared/errors.ts` | user | Shared models and services, layouts and partials, translation catalogs (`locales/<locale>/<namespace>.json`), mail templates (`mail/<template>/<locale>/`) and the app error catalog |
186
+ | `src/shared/validation/` | user | Input rules several apps or modules share (D-0227): reading a list query (`?page`, `?sort`, `?ids`), a reason field. They take the values (query, body), never import app or module code; the rules of one app or module stay in its own `validation/` |
185
187
  | `src/shared/browser/` | user | Browser code several apps or modules share (D-0226): `components/` (a design system's UI components), `layouts/`, `composables/`, `styles/` (CSS, tokens) and `lib/` (browser modules that are not Vue: a socket client, formatters); a project with two looks puts one folder per look first (`browser/staff/components/`). Pages import it with a relative path and the dev server serves what they import; server code never imports it. Browser code — this folder and the `views/` of apps and modules — is checked by `tsconfig.vue.json` (vue-tsc, Vite's types), not `tsconfig.json`: a project made before cli 0.4.53 adds `"exclude": ["src/apps/*/views/**", "src/shared/modules/*/views/**", "src/shared/browser/**"]` to `tsconfig.json`, and to `tsconfig.vue.json` the include entries `"src/apps/*/views/**/*.ts"`, `"src/shared/modules/*/views/**/*.ts"`, `"src/shared/browser/**/*.ts"` with `"exclude": ["node_modules", "dist"]`. Code one app or module uses stays in its `views/` |
186
- | `src/infra/<name>/` | user | Plugin connection and extension code (for example `db/connections.ts`, `auth/extension.ts`, `worker/tasks.ts`, `events/types.ts`, `runtime/application.ts`); migrations and seeds in `db/migrations/<connection>/` and `db/seeds/<connection>/` |
188
+ | `src/infra/<name>/` | user | Plugin connection and extension code (for example `db/connections.ts`, `auth/extension.ts`, `worker/tasks.ts`, `events/types.ts`, `runtime/application.ts`); migrations and seeds in `db/migrations/<connection>/` and `db/seeds/<connection>/`. The project's wrapper of a plugin (a `defineModule` wrapper that adds the project's declarations, `module/`) and code several apps share that reads a request through a plugin (the viewer from `request.auth` in `auth/`, Inertia props several apps build the same way beside `inertia/shared.ts`) live here too (D-0227); services never take the request |
187
189
  | `tests/{unit,integration,support}/` | user | Tests (`*.test.ts`, run by `npm test`: `node --test "tests/**/*.test.ts"`) and their helpers (never `*.test.ts`) |
188
190
  | `scripts/` | user | Development tools, run with `node scripts/<name>.ts`, never imported by `src` |
189
191
 
190
- Nothing else sits right under `src/shared/`: `dokebi check` warns `shared-folder` for any other entry (D-0226). The maintained form of these rules is the **Files and folders** integration rule in AGENTS.md (refreshed by `guide --sync`). A plugin manifest cannot write files outside `src/shared/{models,services,modules,views,mail,locales}/` and `src/infra/<name>/` (`INVALID_MANIFEST`). The exception is `src/apps/` for a plugin with `apps` in `dokebi.hosts`. Old paths are reported by doctor as `LEGACY_LAYOUT` (warning; they keep working). That includes a file an older recipe wrote where the layout no longer puts it, such as `src/site-worker.ts`; `details.moveTo` names its place now.
192
+ Nothing else sits right under `src/shared/`: `dokebi check` warns `shared-folder` for any other entry (D-0226, D-0227). The maintained form of these rules is the **Files and folders** integration rule in AGENTS.md (refreshed by `guide --sync`). A plugin manifest cannot write files outside `src/shared/{models,services,modules,views,mail,locales}/` and `src/infra/<name>/` (`INVALID_MANIFEST`). The exception is `src/apps/` for a plugin with `apps` in `dokebi.hosts`. Old paths are reported by doctor as `LEGACY_LAYOUT` (warning; they keep working). That includes a file an older recipe wrote where the layout no longer puts it, such as `src/site-worker.ts`; `details.moveTo` names its place now.
191
193
 
192
194
  ## 5. Settings rules
193
195
 
@@ -239,7 +241,7 @@ Every command also works in an npm workspace member folder. Packages are found t
239
241
  - AI entry (D-0065): `ANSWERS_REQUIRED` (exit 2), `ANSWERS_SOURCE_REQUIRED` (applying without `--answers-from user` or `--defaults`), `AI_CHOICE_UNKNOWN`, `AI_CHOICE_FIXED`, `AI_CHOICE_WITHOUT_ANSWER`, `AI_REASON_WITHOUT_CHOICE`, `INVALID_AI_REASON` (D-0095: `--ai-chose`/`--ai-reason` refused), `UNKNOWN_RECIPE`, `INVALID_ANSWER`, `OPTION_ABSENT`, `OPTION_NOT_APPLICABLE` (an answer another answer rules out: `--admin login` with `--db none`), `RECIPE_FILE_CONFLICT` (a file the recipe writes exists with other content; `details.path`, `fix`), `NOT_A_PROJECT`, `PREFLIGHT_FAILED` (details.preflight: `DOCKER_MISSING`, `PORT_IN_USE`), `RECIPE_STEP_FAILED`, `STEP_COMMAND_FAILED`, `NOT_PUBLISHED`, `NO_COMPATIBLE_VERSION`, `UNKNOWN_ADAPTER`, `ADAPTER_TEMPLATE_MISSING`, `DB_PLUGIN_MISSING`, `CONNECTION_MISSING`, `DEV_INFRA_UNSUPPORTED`, `COMPOSE_CONFLICT`, `COMPOSE_PORT_UNKNOWN`, `COMPOSE_INVALID`, `NOT_INSTALLED`, `DOC_MISSING`, `CATALOG_MISSING`, `CATALOG_INVALID`. check (D-0072): `TYPESCRIPT_UNAVAILABLE`, `TSCONFIG_INVALID`. drift (D-0120): `DRIFT_EXPECTED_INVALID`. verify check codes: `DOCTOR_FAILED`, `CHECK_FAILED` (details: `problems`), `TYPECHECK_FAILED`, `BUILD_FAILED`, `ALREADY_RUNNING`, `PORT_IN_USE`, `DB_URL_MISSING`, `NOT_READY`, `URL_UNKNOWN`, `HTTP_FAILED`, `FOREIGN_SERVER` (another server answered), `NOT_STARTED` (the app did not start, so no HTTP), `STOP_FORCED`, `APP_EXITED`, `CHECK_ERROR`, `TEST_FAILED` (details: `failures`, the counts and `exitCode`), `TEST_TIMEOUT` (the tests did not finish within `--test-timeout-ms`). Before any check, verify refuses a folder without `package.json`, `dokebi.yaml` or `.dokebi/state.json` with `NOT_A_PROJECT` (`details.file`, `details.fix`; the state file is the CLI's and belongs in version control, so a copied project needs it). The changing commands (`add`, `upgrade`, `remove`, `migrate`, `app`, `module`, `settings`, `config set`/`unset`/`secret`) and the app, module and settings lists do the same outside a project: `NOT_A_PROJECT` with `details.file` (`.dokebi/state.json`, or `dokebi.yaml` in a folder that has the state) and `details.fix`. For a missing dokebi.yaml the fix is `npx dokebi config init` (D-0163), which answers `CONFIG_EXISTS` when the file is there and `EXAMPLE_MISSING` without dokebi.example.yaml.
240
242
  - Commands: `USAGE`, `UNKNOWN_COMMAND`, `PROJECT_EXISTS`, `UNSUPPORTED_PROJECT`, `INVALID_SPEC`, `INVALID_PACKAGE`, `INVALID_MANIFEST`, `INCOMPATIBLE_VERSION`, `MISSING_DEPENDENCY`, `DEPENDENCY_CYCLE`, `DUPLICATE_PLUGIN`, `UNKNOWN_PLUGIN`, `REVERSE_DEPENDENCY`, `REQUIRED_PLUGIN`, `INVALID_PLUGIN_OPTIONS`, `INVALID_SET`, `PATH_MISMATCH` (config set, unset and secret: the command would change an option path it was not asked for — the plugin id `dokebi-logger` reaching `options.logging`, an old or renamed section; refused before anything is written, a warning with `--dry-run`; `details.outside` and `details.paths` name them; `config show` of such a plugin id names the section in `details.outside` and `fix`), `SAMPLE_SECRET` (`config diff --write`: the copy would leave a secret in dokebi.example.yaml; nothing written), `FILE_CONFLICT`, `PATH_CONFLICT`, `PACKAGE_CONFLICT`, `NPM_FAILED`, `REGISTRY_MISMATCH`, `INTERRUPTED` (a Ctrl+C, SIGTERM or SIGHUP before the commit: nothing applied, no lock left; run the command again), `LOCK_FAILED` (.dokebi/lock cannot be created: not writable), `PROJECT_LOCKED` (`details`: `pid`, `running`, `since` and `fix`, as doctor says it), `INVALID_ENV`, `CONCURRENT_CHANGE`, `COMMIT_FAILED`, `UPGRADE_DOWNGRADE`, `UPGRADE_IDENTITY_CHANGED`, `UPGRADE_ENTRY_MOVED`, `UPGRADE_CONFIG_CONFLICT`, `APP_EXISTS`, `APP_IN_USE`, `APPS_PRESENT`, `APP_PLUGIN_MISSING`, `DOMAIN_IN_USE`, `UNKNOWN_APP`, `UNKNOWN_DOMAIN`, `MODULE_EXISTS`, `MODULE_PLUGIN_MISSING`, `UNKNOWN_MODULE`, `HOST_MISSING`, `HOST_CONFLICT`, and for the server commands `ENTRY_MISSING`, `START_CHECK_FAILED`, `ALREADY_RUNNING`, `START_IN_PROGRESS`, `START_FAILED`, `STOP_TIMEOUT`, `STOP_FAILED` (verify could not signal the pid it started, or stop could not signal the app and its log writer could not be asked), `PROCESS_INFO_FAILED`, `NO_LOG`, `UNSUPPORTED_PLATFORM`; D-0154 `RELOAD_UNSUPPORTED`, `RELOAD_RESTART_REQUIRED`, `RELOAD_INVALID`, `RELOAD_FAILED` (`dokebi reload`); D-0155 `INVALID_SETTINGS`, `SETTINGS_EXISTS`, `SETTINGS_SECTION_CONFLICT`, `UNKNOWN_SETTINGS`, `SETTINGS_SCHEMA_FAILED`, `UNDECLARED_SECTION` (`settings` commands; doctor also `SETTINGS_SCHEMA_MISSING` and the warning `SETTINGS_SCHEMA_STALE`).
241
243
  - `UNSUPPORTED_PROJECT`: a package.json the CLI cannot install for: npm workspaces of its own, `workspace:` or `link:` specs, URLs. A tarball dependency is fine as an absolute path or a path inside the project (`file:vendor/web-0.4.3.tgz`, as npm writes it when installed from the project; it stays relative, so the project can move). `file:~/…` (npm's form of `npm install ~/x.tgz`) is the home folder for npm, not the project, and is refused, as is an absolute path npm reads the same way (`file:/~/…`, `file://~/…`: not the folder `/~`; `dokebi add` or `upgrade --to` of such a path is `INVALID_SPEC`); a listed tarball the folder lacks (an ignored `vendor/`) is npm's `NPM_FAILED` naming the file, as for an absolute path, and a folder at its path is `UNSUPPORTED_PROJECT` with `details.path`. Outside Windows a backslash in a `file:` tarball path (`file:vendor\x.tgz`) is refused too, with `details.path` and a `fix` that writes it with `/` (npm reads it as part of a file name there and saves the path with `/`, another file; `add` or `upgrade --to` of such a path: `INVALID_SPEC`); on Windows it is a separator, as for npm. `dokebi add ./vendor/web-0.4.3.tgz` and `upgrade --to vendor/web-0.4.3.tgz` write a tarball inside the project relative too; one outside it, reached through a symbolic link that leads out, or in a project folder named `~` (npm would read the home folder), is written absolute. `INVALID_OPTIONS_SCHEMA`: a plugin's options schema cannot be checked — with `details.keyword` and `details.config` it uses an `x-dokebi-*` keyword the @dokebi/config of this CLI does not know (a schema of a newer release: run the @dokebi/cli of the same release as the plugins; nothing is damaged), with `details.validator: true` the validator itself cannot load (restore node_modules), otherwise that plugin's schema is broken (reinstall it).
242
- - Diagnostics (inspect, doctor): `ENV_DOKEBI_CONFIG_IGNORED` (warning, R4CC-7: a `.env` line sets `DOKEBI_CONFIG`, which the app never gets from there; `path` `.env:<line>`, `hint`), `MIGRATION_REQUIRED`, `CONFIG_CONFLICT`, `INVALID_CORE`, `PACKAGE_VERSION_MISMATCH`, `MISSING_CORE_DEPENDENCY`, `MISSING_PACKAGE_DEPENDENCY`, `MODIFIED_REGISTRATION`, `MODIFIED_TEMPLATE` (warning: only `owner: "cli"` files), `MANIFEST_CHANGED`, `INVALID_PLUGIN_OPTIONS`, `ENTRY_MISSING`, `LEGACY_ADMIN_SECTION` (warning, D-0115: `options.blog-admin` of an older recipe keeps working; the hint says how to rename it with the seed), `LEGACY_LAYOUT`, `TEMPLATE_FIX_MISSING` (warning: a `src/infra/db/adapters/<id>.ts` — or a copy moved or renamed under `src/`, a file that imports the driver and @dokebi/db's `ResourceAdapter` — copied from @dokebi/db's template before a fix the installed template has — the handling of a socket error of a client in use (@dokebi/db's client failure code), `lazy`, `usage`, pg `failed-connect` (a client whose connect fails ends its socket, else a URL without a password kept the process alive), mariadb `url-query` (a URL query such as `?ssl=true` is refused, not dropped) and `ipv6`, pg and mariadb `lost` (a lost connection takes readiness down at once), mysql2 and mariadb `idle` (idle connections end after `idleTimeoutMs`), pg, mysql2 and mariadb `repeats` (errors of many pooled connections at once are logged once per `logRepeatWindowMs`, the rest counted), mysql2 `connect-cause` (a pool wait that ran out while the caller's own connect was pending names it, so a frozen server takes readiness down) and `queue-leave` (a caller that gave up leaves mysql2's queue instead of counting against `maxWaiting`); and, with @dokebi/template-inertia installed, a `vite.config.*` or `vite.ssr.config.*` without `build.emptyOutDir: false` (`keep-chunks`: a rolling deploy needs the previous build's chunks) or, when the installed apps host's template has it, without `vue({ script: { fs } })` (`vue-type-files`: a page whose props type is imported from another file fails `vite build`, since TypeScript 7 gives the Vue compiler no file access), an Inertia app's `views/app.js` or `views/ssr.js` that does not import `virtual:dokebi/module-pages` while a module under `src/` keeps Vue pages in its views folder (`module-pages`, D-0218: a module page answers "Unknown page"; `details.page` names one) and a Vite config without `dokebiInertia()` while an entry imports it (`module-pages-plugin`: the build cannot resolve the import); and a `src/main.ts` that reads `process.env.DOKEBI_CONFIG ??` (`empty-config-env`, `plugin: null`: an empty `DOKEBI_CONFIG` is taken for a path and the app stops with `CONFIG_READ_FAILED`, while every CLI command reads dokebi.yaml then; the generated main.ts uses `||`; doctor only); `details.missing` and `details.template` name them, `hint` names the file and the change; the copy is yours, compare and bring them over), `RELOAD_NOT_WIRED` (warning: `src/main.ts` passes no `configFile` to `new Application` or `ClusterRunner`, so dokebi.yaml is never read again and `dokebi dev` restarts on every change, saying so; or the cluster workers' `src/infra/runtime/application.ts` builds `new Application` without it, so a worker cannot take the reload its primary asks for), `VUE_TYPECHECK_MISSING` (warning: an Inertia app under `src/apps` and a `typecheck` script without `vue-tsc`, from before `app add --inertia` prepared the Vue check; the hint lists the files and devDependencies to add), `DEV_FILES_UNGUARDED` (D-0129: an Inertia app under `src/apps` and an installed @dokebi/template-inertia without the dev file policy, so `dokebi dev` serves every project file such as `dokebi.yaml?raw`; an error when `options.dokebi-template-inertia.devHosts` is set, a warning otherwise; the hint says to upgrade the package and change secrets that were reachable), `MISSING_REQUIRED_PLUGIN`, `STALE_REQUIREMENTS`, `PLUGIN_CHECK` (details `code`, `optionPath`, and the plugin's `hint`), `GUIDE_BLOCK_MODIFIED` (warning: the installed list in AGENTS.md was edited between its markers by hand, D-0072), `GUIDE_PROJECT_BLOCK_INVALID` (warning: the `dokebi:project` markers of AGENTS.md cannot be read, D-0077), `PROJECT_LOCKED`, `RECOVERY_REQUIRED`, `UNSAFE_PATH`, `INVALID_LOGGING_CONFIG` (error: a level value of `options.logging`, or `options.logging` that is not an object), `LOGGING_PLUGIN_UNKNOWN` (warning: a level for a plugin that is not installed), `LOGGING_OPTIONS_UNUSED` (warning, D-0151: keys other than `level` and `plugins` in `options.logging` without the logger plugin; core warns the same at startup; with @dokebi/logger installed its options schema checks them as `INVALID_PLUGIN_OPTIONS`).
244
+ - Diagnostics (inspect, doctor): `ENV_DOKEBI_CONFIG_IGNORED` (warning, R4CC-7: a `.env` line sets `DOKEBI_CONFIG`, which the app never gets from there; `path` `.env:<line>`, `hint`), `MIGRATION_REQUIRED`, `CONFIG_CONFLICT`, `INVALID_CORE`, `PACKAGE_VERSION_MISMATCH`, `MISSING_CORE_DEPENDENCY`, `MISSING_PACKAGE_DEPENDENCY`, `MODIFIED_REGISTRATION`, `MODULE_LIST_MODIFIED` (D-0227: `src/dokebi.modules.generated.ts` differs from the registered modules), `MODULE_LIST_MISSING` (warning, D-0227: a project with `@dokebi/module` has no module list yet; `npx dokebi module sync`), `MODIFIED_TEMPLATE` (warning: only `owner: "cli"` files), `MANIFEST_CHANGED`, `INVALID_PLUGIN_OPTIONS`, `ENTRY_MISSING`, `LEGACY_ADMIN_SECTION` (warning, D-0115: `options.blog-admin` of an older recipe keeps working; the hint says how to rename it with the seed), `LEGACY_LAYOUT`, `TEMPLATE_FIX_MISSING` (warning: a `src/infra/db/adapters/<id>.ts` — or a copy moved or renamed under `src/`, a file that imports the driver and @dokebi/db's `ResourceAdapter` — copied from @dokebi/db's template before a fix the installed template has — the handling of a socket error of a client in use (@dokebi/db's client failure code), `lazy`, `usage`, pg `failed-connect` (a client whose connect fails ends its socket, else a URL without a password kept the process alive), mariadb `url-query` (a URL query such as `?ssl=true` is refused, not dropped) and `ipv6`, pg and mariadb `lost` (a lost connection takes readiness down at once), mysql2 and mariadb `idle` (idle connections end after `idleTimeoutMs`), pg, mysql2 and mariadb `repeats` (errors of many pooled connections at once are logged once per `logRepeatWindowMs`, the rest counted), mysql2 `connect-cause` (a pool wait that ran out while the caller's own connect was pending names it, so a frozen server takes readiness down) and `queue-leave` (a caller that gave up leaves mysql2's queue instead of counting against `maxWaiting`); and, with @dokebi/template-inertia installed, a `vite.config.*` or `vite.ssr.config.*` without `build.emptyOutDir: false` (`keep-chunks`: a rolling deploy needs the previous build's chunks) or, when the installed apps host's template has it, without `vue({ script: { fs } })` (`vue-type-files`: a page whose props type is imported from another file fails `vite build`, since TypeScript 7 gives the Vue compiler no file access), an Inertia app's `views/app.js` or `views/ssr.js` that does not import `virtual:dokebi/module-pages` while a module under `src/` keeps Vue pages in its views folder (`module-pages`, D-0218: a module page answers "Unknown page"; `details.page` names one) and a Vite config without `dokebiInertia()` while an entry imports it (`module-pages-plugin`: the build cannot resolve the import); and a `src/main.ts` that reads `process.env.DOKEBI_CONFIG ??` (`empty-config-env`, `plugin: null`: an empty `DOKEBI_CONFIG` is taken for a path and the app stops with `CONFIG_READ_FAILED`, while every CLI command reads dokebi.yaml then; the generated main.ts uses `||`; doctor only); `details.missing` and `details.template` name them, `hint` names the file and the change; the copy is yours, compare and bring them over), `RELOAD_NOT_WIRED` (warning: `src/main.ts` passes no `configFile` to `new Application` or `ClusterRunner`, so dokebi.yaml is never read again and `dokebi dev` restarts on every change, saying so; or the cluster workers' `src/infra/runtime/application.ts` builds `new Application` without it, so a worker cannot take the reload its primary asks for), `VUE_TYPECHECK_MISSING` (warning: an Inertia app under `src/apps` and a `typecheck` script without `vue-tsc`, from before `app add --inertia` prepared the Vue check; the hint lists the files and devDependencies to add), `DEV_FILES_UNGUARDED` (D-0129: an Inertia app under `src/apps` and an installed @dokebi/template-inertia without the dev file policy, so `dokebi dev` serves every project file such as `dokebi.yaml?raw`; an error when `options.dokebi-template-inertia.devHosts` is set, a warning otherwise; the hint says to upgrade the package and change secrets that were reachable), `MISSING_REQUIRED_PLUGIN`, `STALE_REQUIREMENTS`, `PLUGIN_CHECK` (details `code`, `optionPath`, and the plugin's `hint`), `GUIDE_BLOCK_MODIFIED` (warning: the installed list in AGENTS.md was edited between its markers by hand, D-0072), `GUIDE_PROJECT_BLOCK_INVALID` (warning: the `dokebi:project` markers of AGENTS.md cannot be read, D-0077), `PROJECT_LOCKED`, `RECOVERY_REQUIRED`, `UNSAFE_PATH`, `INVALID_LOGGING_CONFIG` (error: a level value of `options.logging`, or `options.logging` that is not an object), `LOGGING_PLUGIN_UNKNOWN` (warning: a level for a plugin that is not installed), `LOGGING_OPTIONS_UNUSED` (warning, D-0151: keys other than `level` and `plugins` in `options.logging` without the logger plugin; core warns the same at startup; with @dokebi/logger installed its options schema checks them as `INVALID_PLUGIN_OPTIONS`).
243
245
 
244
246
  ### Logs (D-0047)
245
247
 
@@ -415,7 +417,7 @@ than creating new pools or a service instance on every request. Existing customi
415
417
  remain user-owned and are not silently migrated or overwritten.
416
418
 
417
419
  Shared translation catalogs belong in `src/shared/locales/<language>/<namespace>.json`.
418
- Inertia pages belong to the mounting app. Keep project-specific rules in the
420
+ Inertia pages belong to the app that renders them, or to the module whose pages they are (`views/<template>/Pages/` of the module, D-0218). Keep project-specific rules in the
419
421
  `dokebi:project` block of `AGENTS.md` so future CLI sessions can read them.
420
422
  Instructions guide contributors; they do not mechanically enforce every design decision.
421
423
 
package/catalog.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$comment": "Generated by scripts/catalog/build.ts from package.json dokebiCatalog fields and packages/cli/catalog-src (D-0065). Do not edit; run node scripts/catalog/build.ts.",
3
3
  "schemaVersion": 1,
4
- "cli": "0.4.53",
4
+ "cli": "0.4.54",
5
5
  "core": {
6
6
  "package": "@dokebi/core",
7
7
  "version": "0.4.7"
@@ -446,7 +446,7 @@
446
446
  {
447
447
  "id": "dokebi-app",
448
448
  "package": "@dokebi/app",
449
- "version": "0.4.12",
449
+ "version": "0.4.13",
450
450
  "kind": "plugin",
451
451
  "summary": "Several apps chosen by request domain (src/apps/<app>) with a template each; installs web, controller and template-ejs with it",
452
452
  "description": "Multiple apps per project for Dokebi: pick the app and template by request domain, with EJS and Inertia skeletons.",
@@ -825,7 +825,7 @@
825
825
  {
826
826
  "id": null,
827
827
  "package": "@dokebi/cli",
828
- "version": "0.4.53",
828
+ "version": "0.4.54",
829
829
  "kind": "cli",
830
830
  "summary": "Commands to create a project, browse the plugin catalog, run recipes, install plugins and verify (dokebi)",
831
831
  "description": "Project scaffolding, plugin catalog, recipes, install and verification CLI for Dokebi.",
@@ -2143,7 +2143,7 @@
2143
2143
  {
2144
2144
  "id": "dokebi-module",
2145
2145
  "package": "@dokebi/module",
2146
- "version": "0.4.8",
2146
+ "version": "0.4.9",
2147
2147
  "kind": "plugin",
2148
2148
  "summary": "Modules that hold one feature each (src/shared/modules/<module>); an app attaches them under a prefix",
2149
2149
  "description": "Feature modules for Dokebi apps: controllers, models, views and routes in one folder mounted under a prefix.",
@@ -2691,7 +2691,7 @@
2691
2691
  {
2692
2692
  "id": "dokebi-permissions",
2693
2693
  "package": "@dokebi/permissions",
2694
- "version": "0.1.3",
2694
+ "version": "0.1.4",
2695
2695
  "kind": "plugin",
2696
2696
  "summary": "Roles, grades and scoped permissions: keys declared in code, grants saved in your database in the caller's transaction, can(actor, key, target) from memory over the holding tree (all, subtree, direct, own), list conditions as SQL, every worker refreshed by a revision; plugs into @dokebi/auth's authorize",
2697
2697
  "description": "Roles, grades and scoped permissions for Dokebi: permissions declared in code, grants saved in your database in the caller's transaction, checks from memory over the holding tree (all, subtree, direct, own), list conditions as SQL, every worker refreshed by a revision.",
package/dist/bin.js CHANGED
@@ -1256,7 +1256,10 @@ async function app(input) {
1256
1256
  throw new CliError('USAGE', USAGE_LINES);
1257
1257
  process.stdout.write(JSON.stringify(machine ? envelope(`app ${action}`, result) : result, null, 2) + '\n');
1258
1258
  }
1259
- /** `dokebi module add|remove|list` (D-0032): feature modules in src/shared/modules/<name>. */
1259
+ /**
1260
+ * `dokebi module add|remove|list|sync` (D-0032): feature modules in src/shared/modules/<name>;
1261
+ * `sync` writes the module list src/dokebi.modules.generated.ts (D-0227).
1262
+ */
1260
1263
  async function moduleCommand(input) {
1261
1264
  const action = input.shift();
1262
1265
  const project = await newProject();
@@ -1266,6 +1269,17 @@ async function moduleCommand(input) {
1266
1269
  throw new CliError('USAGE', USAGE_LINES);
1267
1270
  result = await project.moduleList(process.cwd());
1268
1271
  }
1272
+ else if (action === 'sync') {
1273
+ let dryRun = false;
1274
+ for (const arg of input) {
1275
+ if (arg === '--dry-run' && !dryRun)
1276
+ dryRun = true;
1277
+ else
1278
+ throw new CliError('USAGE', USAGE_LINES);
1279
+ }
1280
+ mutationStarted = true;
1281
+ result = await project.moduleSync(process.cwd(), dryRun);
1282
+ }
1269
1283
  else if (action === 'add' || action === 'remove') {
1270
1284
  const name = input.shift();
1271
1285
  if (!name || name.startsWith('-'))
@@ -1287,7 +1301,7 @@ async function moduleCommand(input) {
1287
1301
  : await project.moduleRemove(process.cwd(), name, dryRun);
1288
1302
  }
1289
1303
  else if (action && !action.startsWith('-'))
1290
- throw unknownCommand(action, ['add', 'remove', 'list'], 'module ');
1304
+ throw unknownCommand(action, ['add', 'remove', 'list', 'sync'], 'module ');
1291
1305
  else
1292
1306
  throw new CliError('USAGE', USAGE_LINES);
1293
1307
  process.stdout.write(JSON.stringify(machine ? envelope(`module ${action}`, result) : result, null, 2) + '\n');
@@ -37,7 +37,7 @@ export const INTEGRATION_RULES = [
37
37
  '- Background work (D-0141): deliveries (webhooks, mail, notifications), exports, imports, copies, grace periods and cleanups are work items of @dokebi/outbox, not loops you write. Enqueue with outbox.enqueue(tx, { type, owner, destination, payload, dedupeKey, notBefore }) inside the business transaction and register outbox.handle(type, handler, { onDone }) in the setup of the module that owns the work; its runner claims fair batches across owners through one due-time index, retries with backoff, waits out a destination that is down (a breaker per destination, dead only after a horizon of days), keeps dead items for outbox.resend and removes finished rows after a retention. It derives its own small pool of the main connection (pool.max, default 4), so add nothing but run the migration that npx dokebi add @dokebi/outbox writes, keep handlers idempotent with item.key, query in handlers through context.db (the outbox handler pool, never the main pool: an owner whose handlers wait on a locked row then holds at most runner.maxInFlightPerOwner of them while the other owners keep flowing), and put the arrival and drain per second of npx dokebi-outbox stats in the section 6 table of the final report. Never hand-write a claim loop, a retry or dead-letter table or a timer for such work. A destination is one endpoint (one webhook id or URL, one mailbox provider), never a whole host or a shared name such as database: items of one failing endpoint must not pause the others. Database-only cleanup has no destination, and a batch handler records a failing row and skips it rather than failing the whole item. Best-effort signals after a commit (an SSE change notice, a cache invalidation) are not outbox work: send them directly.',
38
38
  '- Recipe fit: pick the recipe whose scaffold matches the app (npx dokebi recipe list shows each recipe and its match); when you build on a scaffold made for something else, rename or remove its sample names (tables, option keys, routes, view titles) so none of them remains in the finished app.',
39
39
  '- Responsibility boundaries: use Controller -> Service -> Model for application data. Controllers translate HTTP input/output and call services; models own SQL, services provide data and coordinate workflows, and jobs invoke those services. Put app-specific services in src/apps/<app>/services, cross-app services in src/shared/services, and feature-module services in src/shared/modules/<module>/services. Shared services must not import app-specific code. Services accept explicit inputs and return DTOs, never request/reply or template objects; do not expose models or SQL pools through a service for controllers/routes to bypass it. Compose dependencies once during setup. Periodic and background work runs only through the scheduler and job plugins, registered by the module that owns it; never start timers, intervals or background loops in controllers, services or setup code. Keep auth extension wiring separate from reusable member persistence. Audit the final route and registration graph after replacing scaffold flows; remove obsolete unreferenced implementations that duplicate the active behavior, while preserving required engine entries, mail templates and user-owned resources. Split by responsibility, not by arbitrary file counts. When a browser UI is present, keep views/runtime for browser integration and requested reusable editor/upload UI in the template components, and display helpers separate from transport. Use explicit DTO types through services, browser adapters and Vue props; a default any response or any page state defeats SFC checking. Keep readable formatting. Keep original TS/JS/Vue source formatted; minification belongs only to generated build output. Declare a formatter that supports the source formats, include its check in project verification, and inspect the final source rather than claiming readability from build success. Include Vue SFC scripts/templates in type checking; a successful Vite build or server-only tsc is not a Vue type check. dokebi app add --inertia prepares it: npm run typecheck runs tsc and then vue-tsc (typecheck-vue.mjs with tsconfig.vue.json), so keep that step, write pages as <script setup lang="ts">, and type the shared page props in src/infra/inertia/page.d.ts. Preserve the shared error catalog at src/shared/errors.ts.',
40
- '- Files and folders (maintained layout; refreshed by guide --sync like every rule here): src holds only main.ts and dokebi.generated.ts at its root. One app per src/apps/<app>: app.ts, routes.ts (or routes/ for route groups), controllers/, services/, models/, validation/ and views/<template>/ (Inertia pages in views/<template>/Pages, components in components/, browser integration in views/runtime/). Shared code: src/shared/models, src/shared/services, src/shared/views (layouts, partials), src/shared/locales/<locale>/<namespace>.json, src/shared/mail/<template>/<locale>/, application settings in src/shared/settings and the error catalog src/shared/errors.ts. Browser code several apps or modules share (a design system, shared layouts, composables, a socket client) goes in src/shared/browser: components/, layouts/, composables/, styles/ and lib/ (a project with two looks, an operator console and a member site, puts one folder per look first, src/shared/browser/staff/components/); pages import it with a relative path, server code never imports it. Browser code (the views of apps and modules and src/shared/browser) is type-checked by tsconfig.vue.json with vue-tsc, not by tsconfig.json. Code one app or module uses stays in the views/ of that app or module. src/shared holds nothing else (dokebi check warns shared-folder). One feature per module in src/shared/modules/<module> (module.ts, routes.ts and the same controllers/services/models/validation/views folders; create it with npx dokebi module add). Plugin connection and extension code in src/infra/<name> (src/infra/db/connections.ts, src/infra/auth/extension.ts); your own plugins in src/plugins/<name>. Migrations in src/infra/db/migrations/<connection> and seeds in src/infra/db/seeds/<connection> (npx dokebi-migrate make writes the file). Job handlers and event subscriptions are registered in the setup of the module that owns the feature (src/shared/modules/<module>/module.ts) and call its services; schedules are entries of options.dokebi-scheduler.schedules in dokebi.yaml whose job type such a handler takes; CPU tasks go in src/infra/worker/tasks.ts, event payload types in src/infra/events/types.ts and the cluster worker factory in src/infra/runtime/application.ts. Input validation (route schemas and validators) lives in validation/ of the app or module that owns the route; a DTO type is exported by the service that returns it (cross-app DTOs with their service in src/shared/services). Tests: tests/unit (no external service), tests/integration (a real database, HTTP or broker) and tests/support (helpers and fixtures, never named *.test.ts); npm test runs node --test "tests/**/*.test.ts", which covers both test folders, and tsconfig.json includes tests/**/*.ts. Development tools (imports, measurements, one-off maintenance) go in scripts/ at the project root, run with node scripts/<name>.ts and never imported by src. Name .ts files and folders in kebab-case (Vue components and Inertia pages are PascalCase, as Pages/Posts/Show.vue), and give each file one responsibility.',
40
+ '- Files and folders (maintained layout; refreshed by guide --sync like every rule here): src holds only main.ts and the files the CLI writes at its root: dokebi.generated.ts and dokebi.modules.generated.ts (the registered modules; import registeredModules from it where code needs every module, an app that mounts each one or keys collected from each, and never keep a module list of your own). One app per src/apps/<app>: app.ts, routes.ts (or routes/ for route groups), controllers/, services/, models/, validation/ and views/<template>/ (Inertia pages in views/<template>/Pages, components in components/, browser integration in views/runtime/). Shared code: src/shared/models, src/shared/services, src/shared/views (layouts, partials), src/shared/locales/<locale>/<namespace>.json, src/shared/mail/<template>/<locale>/, application settings in src/shared/settings, input rules several apps or modules share (reading a list query, a reason) in src/shared/validation and the error catalog src/shared/errors.ts. Browser code several apps or modules share (a design system, shared layouts, composables, a socket client) goes in src/shared/browser: components/, layouts/, composables/, styles/ and lib/ (a project with two looks, an operator console and a member site, puts one folder per look first, src/shared/browser/staff/components/); pages import it with a relative path, server code never imports it. Browser code (the views of apps and modules and src/shared/browser) is type-checked by tsconfig.vue.json with vue-tsc, not by tsconfig.json. Code one app or module uses stays in the views/ of that app or module. src/shared holds nothing else (dokebi check warns shared-folder). One feature per module in src/shared/modules/<module> (module.ts, routes.ts and the same controllers/services/models/validation/views folders; create it with npx dokebi module add). Declarations the project adds to every module (its menu entries, its permission keys) are files at the module root named for what they declare (menu.ts, permissions.ts) that module.ts passes on; pages declared but not built yet are routes and stay in routes.ts. A feature several apps show is one module, a login of two apps included; when each app needs route ids of its own, each app mounts a set of its own whose routes carry those ids and call the same controllers. Plugin connection and extension code in src/infra/<name> (src/infra/db/connections.ts, src/infra/auth/extension.ts), including the project wrapper of a plugin (a defineModule wrapper in src/infra/module/) and code several apps share that reads a request through a plugin (the viewer from request.auth in src/infra/auth/, Inertia props several apps build the same way beside src/infra/inertia/shared.ts, a gate of every route of an app, a dokebi-web routeHook each app registers in its setup, in src/infra/web/); services never take the request; your own plugins in src/plugins/<name>. Migrations in src/infra/db/migrations/<connection> and seeds in src/infra/db/seeds/<connection> (npx dokebi-migrate make writes the file). Job handlers and event subscriptions are registered in the setup of the module that owns the feature (src/shared/modules/<module>/module.ts) and call its services; schedules are entries of options.dokebi-scheduler.schedules in dokebi.yaml whose job type such a handler takes; CPU tasks go in src/infra/worker/tasks.ts, event payload types in src/infra/events/types.ts and the cluster worker factory in src/infra/runtime/application.ts. Input validation (route schemas and validators) lives in validation/ of the app or module that owns the route; a pure rule both the server and the pages of that app or module use (a code check, a rich-text schema) stays in that validation/ folder, imports neither Node nor browser APIs, and the pages import it with a relative path (one several apps or modules use goes in src/shared/validation); a DTO type is exported by the service that returns it (cross-app DTOs with their service in src/shared/services). Tests: tests/unit (no external service), tests/integration (a real database, HTTP or broker) and tests/support (helpers and fixtures, never named *.test.ts); npm test runs node --test "tests/**/*.test.ts", which covers both test folders, and tsconfig.json includes tests/**/*.ts. Development tools (imports, measurements, one-off maintenance) go in scripts/ at the project root, run with node scripts/<name>.ts and never imported by src. Name .ts files and folders in kebab-case (Vue components and Inertia pages are PascalCase, as Pages/Posts/Show.vue), and give each file one responsibility.',
41
41
  '- Apps split by host (D-0132): with several @dokebi/app apps on different hosts, routes that plugins add answer on every host unless they are bound to apps. Bind each plugin endpoint to its app in dokebi.yaml: dokebi-mcp.app: mcp (the MCP route), dokebi-oauth.app: studio (the authorization server: metadata, authorize with the consent page, token, revoke, register; the issuer origin is a domain of that app) and dokebi-oauth.resources.<id>.app: mcp (the protected resource metadata, on the app of the resource uri host). Every other host then answers the 404 of an unknown route. Put the sign-in page on the issuer app. A route of your own module or plugin on web takes app: <name> or app: [<name>, ...] the same way. Never write an onRequest hook that compares the Host header to hide an endpoint, and never answer 403 on the wrong host. Without @dokebi/app a bound route fails the start (ROUTE_APP_UNAVAILABLE), an unknown app name too (ROUTE_APP_UNKNOWN), and an issuer or resource uri on a domain of another app fails it with INVALID_OPTIONS naming the option to set; health routes stay on every host.',
42
42
  '- Module contributions (D-0130): a feature module that offers values to a plugin point (MCP tools, prompts and resources of @dokebi/mcp, mail template folders) declares the points in defineModule({ contributes: [mcpTools] }) and calls module.contribute(point, value) in its own setup, after it builds its services; the contributed objects (an McpTool subclass) take those services in their constructors. Core sets the module up before the plugin that collects the point, so the services exist when the collector reads them, and contributions close when every setup has finished. A module never collects. Never rebuild module services in a separate definePlugin, and never register an app plugin by hand in src/main.ts or src/infra/runtime/application.ts to reach them: describe, the tests and the other entry do not see such a plugin, and doctor and check do not read it. A second module reaches the services through requires: [workspace] and module.get(workspace). Values that no registered plugin collects are dropped with warn POINT_NOT_COLLECTED, npx dokebi check reports module-point-not-installed when the plugin package of a point is not installed, and npx dokebi describe lists each module point and its collector. MCP tool names are unique across modules and plugins (INVALID_TOOL names both owners).',
43
43
  "- What `npx dokebi check` enforces from these rules (D-0105), so a broken one fails before you report: background-timer (an error, so verify fails) is a setInterval, a setTimeout/setImmediate that reschedules itself, or a loop that sleeps inside a task started in the background (an immediately invoked async function or a function called without await, such as a polling loop in a module start), in server code under src/ (views and tests are not read): move the work to a @dokebi/job handler registered in the owning module's setup and an entry of options.dokebi-scheduler.schedules; one-shot delays, time limits, awaited sleeps of node:timers/promises and timers of one request or socket are fine (a timer a request stores on this or in an outer variable outlives it and is reported). polling-loop (an error no marker silences) is a loop that sleeps inside a task started in the background, or a timer whose callback does database work: move it to an @dokebi/outbox or @dokebi/job handler. private-pool (an error) is a database pool or client made with the driver outside src/infra/db (new pg.Pool, mysql2 createPool, new MongoClient): take connections from @dokebi/db (connection(main), derive('main', { purpose, overrides: { max } }) for a pool of one kind of work, or another connection in dokebi.yaml) so dokebi.yaml sets their size and waitTimeoutMs and a caller past the wait gets 503 with Retry-After. overload-off (an error) is a route config overload: false: keep the overload protection on every API route (a metrics scrape or status page takes a marker). readiness-off (an error) is a route config readiness: false: an API route keeps refusing with 503 NOT_READY while a required dependency is down (a metrics scrape or status page that must answer then takes a marker). Warnings: in-process-queue (the resolve of a new Promise stored in a collection to call later: a queue of one worker without bound or deadline), fixed-owner-cap (a per-owner count of requests in progress compared with a fixed limit: use the owner share of @dokebi/db, share(main).enter(owner), which refuses only while the pool is full, @dokebi/db AI.md 6.4), wait-count-refusal (a comparison of the callers waiting for a pool connection, such as pool.waitingCount, with a number: refuse by the wait deadline, never by how many wait), responsibility-size (a model of 400+ code lines over 8+ tables or collections, a controller with 20+ route handlers or 300+ code lines, a service whose methods mostly only pass their arguments to a model) and memory-filtered-page (rows a query returned, skipped in code by an input such as filter.status and then cut to a page). A warning is still a broken rule: fix it, or keep it with // dokebi-check: allow <rule> <reason> and say why in your final message. An allow marker on background-timer is only for per-process upkeep of in-memory state (a cache of this worker); a loop that reads or writes the database (claiming, folding, polling a queue table) is never a valid reason: move it to a job or an outbox handler. check lists every marker with a reason under allowed, and verify ok asks your final message to list them with their reasons. With @dokebi/db installed, verify ok lists finalReport: the section 6 table your final message must contain.",
@@ -15,7 +15,7 @@ import { stat } from 'node:fs/promises';
15
15
  import { join } from 'node:path';
16
16
  import { debug, isMissing } from '../diagnostics.js';
17
17
  import { CliError } from '../errors.js';
18
- import { formatterFix, formatterUses, GENERATED_FILE, migrationsFolder, } from '../formatter-ignore.js';
18
+ import { formatterFix, formatterUses, GENERATED_FILES, migrationsFolder, } from '../formatter-ignore.js';
19
19
  const RULE = 'formatter-migrations';
20
20
  /** A file or folder that exists under the project. */
21
21
  async function present(root, path) {
@@ -31,19 +31,22 @@ async function present(root, path) {
31
31
  }
32
32
  export async function formatterProblems(root) {
33
33
  const problems = [];
34
- if (await present(root, GENERATED_FILE))
35
- for (const use of await formatterUses(root, GENERATED_FILE)) {
36
- if (use.covered)
37
- continue;
38
- problems.push({
39
- rule: 'formatter-generated',
40
- severity: 'warning',
41
- file: use.config,
42
- line: 0,
43
- message: `${use.tool} would format ${GENERATED_FILE}: the CLI writes it and refuses a project whose copy differs (MODIFIED_REGISTRATION)`,
44
- fix: formatterFix(use, GENERATED_FILE),
45
- });
46
- }
34
+ // The registration and the module list (D-0227): the CLI writes both and doctor refuses a copy
35
+ // that differs.
36
+ for (const file of GENERATED_FILES)
37
+ if (await present(root, file))
38
+ for (const use of await formatterUses(root, file)) {
39
+ if (use.covered)
40
+ continue;
41
+ problems.push({
42
+ rule: 'formatter-generated',
43
+ severity: 'warning',
44
+ file: use.config,
45
+ line: 0,
46
+ message: `${use.tool} would format ${file}: the CLI writes it and refuses a project whose copy differs (MODIFIED_REGISTRATION)`,
47
+ fix: formatterFix(use, file),
48
+ });
49
+ }
47
50
  const folder = await migrationsFolder(root);
48
51
  try {
49
52
  if (!(await stat(join(root, folder))).isDirectory())
@@ -30,7 +30,7 @@ import { openTypeScript } from './typescript.js';
30
30
  import { viteConfigProblems } from './vite-rules.js';
31
31
  export { RULES } from './problems.js';
32
32
  /** CLI-generated TypeScript: judged by doctor (generated-file), not by the source rules. */
33
- const GENERATED_SOURCES = new Set(['src/dokebi.generated.ts']);
33
+ const GENERATED_SOURCES = new Set(['src/dokebi.generated.ts', 'src/dokebi.modules.generated.ts']);
34
34
  export async function check(directory, options = {}) {
35
35
  const began = performance.now();
36
36
  const root = await realpath(directory);
@@ -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',
@@ -1,8 +1,9 @@
1
1
  // The shared-folder rule of `dokebi check` (a warning, D-0226):
2
2
  // shared-folder an entry right under src/shared/ that the layout does not name. src/shared
3
3
  // holds shared code by kind: the folders of SHARED_FOLDERS (models, services,
4
- // views, locales, mail, settings, feature modules, and browser for the browser
5
- // code several apps and modules share) and the app error catalog errors.ts.
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.
6
7
  // Server code of one feature belongs in its module, browser code in
7
8
  // src/shared/browser/. The shop measured a project drifting into folders of
8
9
  // its own (src/shared/shop/, src/shared/browser/ before it was named). Entries
@@ -41,7 +42,7 @@ export async function sharedFolderProblems(root) {
41
42
  file,
42
43
  line: 0,
43
44
  message: `${file} is ${folder ? 'a folder' : 'a file'} the project layout does not name: src/shared/ holds only ${named}`,
44
- 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/, and browser code several apps or modules share into src/shared/browser/ (components, layouts, composables, styles, lib)',
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)',
45
46
  });
46
47
  }
47
48
  debug('check: shared-folder rule done', { entries: entries.length, problems: problems.length });
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";
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';
package/dist/layout.d.ts CHANGED
@@ -11,12 +11,13 @@ import type { InstallPlan } from './install-plan.js';
11
11
  */
12
12
  export declare function layoutAllowed(path: string, hosts?: readonly string[], kind?: 'file' | 'directory'): boolean;
13
13
  /**
14
- * What the layout names right under src/shared/ (D-0031, D-0032, D-0155, D-0226): shared models
15
- * and services, layouts and partials (views), translation catalogs, mail templates, application
16
- * settings, feature modules, the browser code several apps and modules share, and the app error
17
- * catalog. `dokebi check` warns about any other entry (shared-folder).
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).
18
19
  */
19
- export declare const SHARED_FOLDERS: readonly ["browser", "locales", "mail", "models", "modules", "services", "settings", "views"];
20
+ export declare const SHARED_FOLDERS: readonly ["browser", "locales", "mail", "models", "modules", "services", "settings", "validation", "views"];
20
21
  export declare const SHARED_FILES: readonly ["errors.ts"];
21
22
  /** Rejects plugin files and folders outside the layout with INVALID_MANIFEST. */
22
23
  export declare function assertLayout(plan: Pick<InstallPlan, 'files' | 'directories'> & {
package/dist/layout.js CHANGED
@@ -22,10 +22,11 @@ export function layoutAllowed(path, hosts = [], kind = 'file') {
22
22
  return hosts.includes('apps') && (key === 'src/apps' || key.startsWith('src/apps/'));
23
23
  }
24
24
  /**
25
- * What the layout names right under src/shared/ (D-0031, D-0032, D-0155, D-0226): shared models
26
- * and services, layouts and partials (views), translation catalogs, mail templates, application
27
- * settings, feature modules, the browser code several apps and modules share, and the app error
28
- * catalog. `dokebi check` warns about any other entry (shared-folder).
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).
29
30
  */
30
31
  export const SHARED_FOLDERS = Object.freeze([
31
32
  'browser',
@@ -35,6 +36,7 @@ export const SHARED_FOLDERS = Object.freeze([
35
36
  'modules',
36
37
  'services',
37
38
  'settings',
39
+ 'validation',
38
40
  'views',
39
41
  ]);
40
42
  export const SHARED_FILES = Object.freeze(['errors.ts']);
package/dist/output.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const CLI_VERSION = "0.4.53";
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.53';
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: {
package/dist/project.js CHANGED
@@ -27,8 +27,8 @@ import { CliError } from './errors.js';
27
27
  import { markExampleRemoved, syncExample } from './example-config.js';
28
28
  import { exists, fingerprint, hash, json, object, parseObject, securePath, templateTarget, } from './filesystem.js';
29
29
  import { adminSections } from './first-admin.js';
30
- import { biomeConfigText, biomeMajor, formatterFix, formatterUses, GENERATED_FILE, migrationsFolder, PRETTIER_IGNORE, prettierIgnoreText, } from './formatter-ignore.js';
31
- import { generateRegistration, LEGACY_MAIN_SOURCE, MAIN_SOURCE, MAIN_SOURCE_V1, MAIN_SOURCE_V2, MAIN_SOURCE_V3, MAIN_SOURCE_V4, MAIN_SOURCE_V5, PROJECT_DEV_DEPENDENCIES, TEST_SCRIPT, TSCONFIG_SOURCE, TYPECHECK_SCRIPT, } from './generator.js';
30
+ import { biomeConfigText, biomeMajor, formatterFix, formatterUses, GENERATED_FILE, GENERATED_FILES, migrationsFolder, PRETTIER_IGNORE, prettierIgnoreText, } from './formatter-ignore.js';
31
+ import { generateModuleList, generateRegistration, LEGACY_MAIN_SOURCE, MAIN_SOURCE, MAIN_SOURCE_V1, MAIN_SOURCE_V2, MAIN_SOURCE_V3, MAIN_SOURCE_V4, MAIN_SOURCE_V5, MODULE_LIST_FILE, PROJECT_DEV_DEPENDENCIES, TEST_SCRIPT, TSCONFIG_SOURCE, TYPECHECK_SCRIPT, } from './generator.js';
32
32
  import { findHost, HOST_ROLES, missingDependency, optionsKey, orderPlugins, PACKAGE_NAME, readManifest, } from './manifest.js';
33
33
  import { mergeInstallDefaults } from './merge-install-defaults.js';
34
34
  import { dependencyMap, NpmClient, packageSpec, projectTarball, stageNpmConfig, validateProjectPackage, } from './npm-client.js';
@@ -2378,6 +2378,9 @@ export class Project {
2378
2378
  // R1 measurement: the registration the CLI writes, too (a reformatted copy is
2379
2379
  // MODIFIED_REGISTRATION); the migrations folder only in a project with migrations.
2380
2380
  const targets = [GENERATED_FILE];
2381
+ // D-0227: the module list beside it, written while a plugin hosts modules.
2382
+ if (findHost(plugins, 'modules'))
2383
+ targets.push(MODULE_LIST_FILE);
2381
2384
  if (plugins.some((plugin) => plugin.id === 'dokebi-migrate') ||
2382
2385
  (await exists(await securePath(root, migrations))))
2383
2386
  targets.push(migrations);
@@ -2408,7 +2411,7 @@ export class Project {
2408
2411
  }
2409
2412
  }
2410
2413
  warnings.push({
2411
- code: folder === GENERATED_FILE
2414
+ code: GENERATED_FILES.includes(folder)
2412
2415
  ? 'FORMATTER_FORMATS_GENERATED'
2413
2416
  : 'FORMATTER_FORMATS_MIGRATIONS',
2414
2417
  path: use.config,
@@ -4129,6 +4132,23 @@ export class Project {
4129
4132
  await tx.close();
4130
4133
  }
4131
4134
  }
4135
+ /**
4136
+ * `dokebi module sync` (D-0227): writes src/dokebi.modules.generated.ts (and the registration)
4137
+ * from the registered modules, unchanged otherwise. A project made before cli 0.4.54 gets its
4138
+ * module list this way; any later module add or remove keeps it current.
4139
+ */
4140
+ async moduleSync(root, dryRun = false) {
4141
+ const session = await this.#begin(root);
4142
+ const { tx, state } = session;
4143
+ try {
4144
+ await this.#requireHost(state, 'modules');
4145
+ await this.writeConfiguration(tx, state, session.configSource, session.configFile);
4146
+ return await this.#finish(session, { changed: tx.paths, preserved: [] }, dryRun);
4147
+ }
4148
+ finally {
4149
+ await tx.close();
4150
+ }
4151
+ }
4132
4152
  /** `dokebi module list`: the registered modules in registration order. */
4133
4153
  async moduleList(root) {
4134
4154
  const state = readState(parseObject(await projectStateText(root), 'state'));
@@ -4655,6 +4675,12 @@ export class Project {
4655
4675
  const generated = generateRegistration(state.plugins, state.installations, state.apps ?? [], state.modules ?? [], state.settings ?? []);
4656
4676
  state.generatedHash = hash(generated);
4657
4677
  await tx.write(GENERATED, generated);
4678
+ // D-0227: the registered modules as code apps import, while a plugin hosts modules; a list
4679
+ // left by a removed module host goes with it (its modules are no longer registered).
4680
+ if (findHost(state.plugins, 'modules'))
4681
+ await tx.write(MODULE_LIST_FILE, generateModuleList(state.modules ?? []));
4682
+ else if (await exists(await securePath(tx.root, MODULE_LIST_FILE)))
4683
+ await tx.replace(MODULE_LIST_FILE);
4658
4684
  await tx.write(configFile, configSource);
4659
4685
  await tx.write('.dokebi/state.json', json(state));
4660
4686
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/cli",
3
- "version": "0.4.53",
3
+ "version": "0.4.54",
4
4
  "description": "Project scaffolding, plugin catalog, recipes, install and verification CLI for Dokebi.",
5
5
  "keywords": [
6
6
  "dokebi",