@appweaver/skill 0.0.0-stage → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,729 @@
1
+ # CLI
2
+
3
+ All long flags are kebab-case, and an option taking a value requires it (`--types-path <path>`). A flag that turns a
4
+ default behavior off is a `--no-*` negation (`--no-registry`, `--no-skill`), so leaving it out keeps the behavior on.
5
+ The short flags have one meaning in every command: `-h` help, `-v` version, `-o` the output of a command, `-p` the
6
+ TypeScript project, `-w` watch, `-y` yes and `-f` force; every other flag has none. A path flag ends with `-path` for a
7
+ file and `-dir` for a directory (`--prisma-schema-path`, `--client-dir`).
8
+
9
+ Every command printing a report takes `--json` (`config print`, `config check`, `doctor`, `module list`, `routes`,
10
+ `run` without a task), printing the same data as one JSON document on one line of stdout, with the same exit code.
11
+ Anything else, the logs and the errors, goes to stderr, so `weaver doctor --json | jq` reads the report alone.
12
+
13
+ The CLI needs only `@appweaver/core`. `generate`, `seed` and `test setup` load the `@appweaver/data` package of the
14
+ project when they run, and exit with `weaver <command> needs the @appweaver/data package` without it.
15
+
16
+ ## `weaver` — Top-level
17
+
18
+ ```
19
+ weaver <command> [options]
20
+ ```
21
+
22
+ | Option/Command | Alias | Description |
23
+ | ---------------- | ----- | ------------------------------------------------ |
24
+ | `build` | `b` | Build the application |
25
+ | `config` | `cfg` | Inspect the configuration |
26
+ | `doctor` | | Check the project and print what to fix |
27
+ | `openapi` | `oa` | Generate the OpenAPI specification |
28
+ | `resource new` | | Create the files of a new resource |
29
+ | `routes` | | Print the routes, events and tools of the models |
30
+ | `generate` | `g` | Generate the types and the schemas |
31
+ | `migrate` | - | Apply the pending database migrations |
32
+ | `migration` | - | Create the migrations and reset the database |
33
+ | `module` | `mod` | Manage the modules of the project |
34
+ | `run` | `r` | Run a one-shot task, or list the tasks |
35
+ | `seed` | `sd` | Seed the database |
36
+ | `start` | `s` | Start the application |
37
+ | `test` | `t` | Set up, reset and tear down the test environment |
38
+ | `upgrade` | `up` | Upgrade the Appweaver packages |
39
+ | `help [command]` | | Output usage information of a command |
40
+ | `-v, --version` | | Output the current version |
41
+ | `-h, --help` | | Output usage information |
42
+
43
+ ---
44
+
45
+ ## `weaver build`
46
+
47
+ ```
48
+ weaver build|b [options]
49
+ ```
50
+
51
+ Build the application.
52
+
53
+ | Option | Description | Default |
54
+ | ---------------------- | ------------------------------ | --------------------- |
55
+ | `-p, --project <path>` | TypeScript project config file | `tsconfig.build.json` |
56
+ | `-h, --help` | Output usage information | |
57
+
58
+ ---
59
+
60
+ ## `weaver config`
61
+
62
+ ```
63
+ weaver config|cfg <command> [options]
64
+ ```
65
+
66
+ Inspect the configuration of the application. Each subcommand creates the application without starting it, so the
67
+ config sections of the enabled modules (the installed packages and `src/modules/*`) and of the application files are
68
+ all defined.
69
+
70
+ | Command | Description |
71
+ | ------------------ | -------------------------------------------------------------------- |
72
+ | `schema [options]` | Generate the JSON Schema of `appweaver.json` |
73
+ | `print` | Print every config value with its source, the secrets hidden |
74
+ | `check` | Validate the config of every enabled module, exit with 1 on an error |
75
+
76
+ ### `weaver config schema`
77
+
78
+ | Option | Description | Default |
79
+ | -------------------------- | ------------------------------ | ------------------------- |
80
+ | `-o, --output-path <path>` | Output path of the JSON Schema | `./appweaver.schema.json` |
81
+
82
+ Writes the JSON Schema of `appweaver.json`, built from the config sections of the enabled modules: every key under its
83
+ camelCase name in the nested object of its section, with its type and default, for `config` and each
84
+ `environments.<env>`. The `$schema` of `appweaver.json` points to it (`"$schema": "./appweaver.schema.json"`), for the
85
+ completion and validation of the module packages' sections too. `weaver generate` writes the same file from the
86
+ sections the modules list, while this command creates the application, so it also finds a section defined in an
87
+ application file outside a module.
88
+
89
+ ### `weaver config print`
90
+
91
+ Prints the environment, then every flattened key sorted by name, with its source and value:
92
+
93
+ ```
94
+ Environment: dev
95
+
96
+ SECURITY_JWT_SECRET env "********"
97
+ SERVER_PORT json 5000
98
+ STORAGE_PROVIDER default "auto"
99
+ ```
100
+
101
+ The source is `override` (`configOverrides` of a test), `env` (the environment and the `.env` files), `json` (the
102
+ `appweaver*.json` files) or `default` (the schema default), the one `configSource(key)` of `@appweaver/common` returns.
103
+ A value is hidden when its key ends with `PASSWORD`, `SECRET`, `TOKEN`, `PRIVATE_KEY`, `CREDENTIALS` or `API_KEY`, or
104
+ its schema has the `secret: true` option. The errors of the invalid sections are printed after the table, with exit
105
+ code 1. `--json` prints `{ environment, keys: [{ key, value, source }], errors }`.
106
+
107
+ ### `weaver config check`
108
+
109
+ Parses every section and exits with 1, listing the errors, when a value is missing or invalid. An error names only the
110
+ invalid keys, each with its environment variable and JSON path. Run it in CI with the deployed environment, so a bad
111
+ value fails the pipeline instead of the startup:
112
+
113
+ ```sh
114
+ NODE_ENV=prod weaver config check
115
+ ```
116
+
117
+ `--json` prints `{ environment, valid, errors }`.
118
+
119
+ ## `weaver doctor`
120
+
121
+ ```
122
+ weaver doctor [--no-database] [--json]
123
+ ```
124
+
125
+ Checks the project and prints each check as `ok`, `warn` or `FAIL`, with the command fixing it. It exits with 1 when a
126
+ check fails, so an agent or a CI step runs it first:
127
+
128
+ | Check | Fails or warns when |
129
+ | ---------------- | ----------------------------------------------------------------------------------------------------- |
130
+ | `runtime` | Node is older than 24.7 (Bun passes) |
131
+ | `packages` | an `@appweaver/*` package of `package.json` is not installed (fail), or they differ in version |
132
+ | `env` | the project has a `.env.example` but no `.env` |
133
+ | `config` | the application fails to load, or a config section is invalid (fail) |
134
+ | `generated` | with `@appweaver/data`: the types or the Prisma schema are missing (fail) or older than a model file |
135
+ | `migrations` | with `@appweaver/data`: migrations are pending, or the status fails; `--no-database` skips it |
136
+ | `sql-migrations` | with `@appweaver/data`: SQL migrations are pending (warn), or one changed after it was applied (fail) |
137
+ | `skill` | a file of the skill (`SKILL.md`, `GUIDELINES.md`, `references/`) differs from `@appweaver/skill` |
138
+
139
+ `--no-database` skips both migration checks, which connect to the database. `--json` prints the checks as
140
+ `[{ name, status, message, hint }]`.
141
+
142
+ ---
143
+
144
+ ## `weaver openapi`
145
+
146
+ ```
147
+ weaver openapi|oa [options]
148
+ ```
149
+
150
+ Generate the OpenAPI specification of the application.
151
+
152
+ | Option | Description | Default |
153
+ | -------------------------- | ------------------------------------------------------ | ---------------- |
154
+ | `-o, --output-path <path>` | Output path of the OpenAPI specification | `./openapi.json` |
155
+ | `--format <format>` | Format of the OpenAPI specification (`json` or `yaml`) | `json` |
156
+
157
+ When `--format yaml` is used and `--output-path` is left at its default, the output path becomes `./openapi.yaml`.
158
+ Missing output directories are created automatically. The command fails with a message when the `@appweaver/web`
159
+ module is not installed or disabled (`APP_MODULES_DISABLED`).
160
+
161
+ ---
162
+
163
+ ## `weaver routes`
164
+
165
+ ```
166
+ weaver routes [options]
167
+ ```
168
+
169
+ Print every route, realtime event and MCP tool of every model, a section per model and per view of it
170
+ (`Post (view public)`), then the other routes of the application and its modules. Creates the application without
171
+ starting it, like `weaver openapi`, and reads the routes the server registered, so every column is what the server
172
+ enforces:
173
+
174
+ - **Access**: `public`, `authenticated`, or the roles, permissions and auth types the route needs, resolved from its
175
+ own config, the routes it inherits from and the `defaults`. An event or a tool has the access of its action object,
176
+ else of the `events` or `mcp` config, else of the route of its action (`find` for an event). A route of the
177
+ application declaring none of these options shows the security of its OpenAPI schema, or `-` when it has none (its
178
+ own hooks decide).
179
+ - **Cache**: the time-to-live and the scope of a cached route (`cache 60000 ms public`), the `cache.defaultTtl` when
180
+ it sets none, and nothing with `cache.enabled` off.
181
+
182
+ | Option | Description | Default |
183
+ |------------------|-----------------------------------------------------------------|---------|
184
+ | `--model <name>` | Print the ones of a model alone, its views included | - |
185
+ | `--json` | Print the output as JSON on stdout, for scripts and AI agents | false |
186
+
187
+ ```
188
+ Post
189
+ GET /api/posts/:id find public cache 60000 ms public
190
+ POST /api/posts/query query public cache 60000 ms public
191
+ POST /api/posts create roles Admin,User
192
+ event resource:Post.update update roles Admin
193
+ tool post_query query public
194
+
195
+ Post (view public)
196
+ GET /api/public/posts/:id find public cache 60000 ms public
197
+ ```
198
+
199
+ With `--json`, a group is `{ model, view, lines }` and a line `{ kind, method, name, action, access, cache }`, `cache`
200
+ being `{ ttl, scope }`.
201
+
202
+ ---
203
+
204
+ ## `weaver generate`
205
+
206
+ ```
207
+ weaver generate|g [options]
208
+ ```
209
+
210
+ Generate the TypeScript types and the Prisma schema of the models, and the JSON Schema of `appweaver.json`. The flags
211
+ select the outputs; with none, it generates all three, the types and the Prisma schema only when `@appweaver/data` is
212
+ enabled.
213
+
214
+ | Option | Description | Default |
215
+ | ----------------------------- | -------------------------------------------------- | ----------------------------------------------- |
216
+ | `--types` | Generate the TypeScript types | — |
217
+ | `--prisma-schema` | Generate the Prisma schema and client | — |
218
+ | `--config-schema` | Generate the JSON Schema of `appweaver.json` | — |
219
+ | `--no-config-schema` | Leave the config schema out of a run without flags | written |
220
+ | `--model-pattern <pattern>` | Glob pattern of the model files | from config (`RESOURCE_MODEL_PATTERN`) |
221
+ | `--types-path <path>` | Output path of the TypeScript types | from config (`RESOURCE_GENERATED_TYPES_PATH`) |
222
+ | `--prisma-schema-path <path>` | Output path of the Prisma schema | from config (`DATABASE_SCHEMA_PATH`) |
223
+ | `--client-dir <dir>` | Output directory of the Prisma client | from config (`DATABASE_CLIENT_OUTPUT_DIR_PATH`) |
224
+ | `--config-schema-path <path>` | Output path of the JSON Schema of `appweaver.json` | `./appweaver.schema.json` |
225
+ | `--no-registry` | Skip registering the model types | registered |
226
+ | `--no-prune` | Keep the framework models not used | pruned |
227
+ | `--verbose` | Print verbose output | `false` |
228
+
229
+ Per model, the type file holds `<Model>`, `<Model>Single`, `<Model>Multiple`, `<Model>Create`, `<Model>Update`,
230
+ `<Model>RelationCreate`, `<Model>RelationUpdate`, `<Model>RelationInput`, `<Model>Query`, `<Model>Sort`,
231
+ `<Model>Aggregate`, `<Model>Series` (the values of its `series` fields, if any), and last `<Model>ResourceService`, the
232
+ `injectService` type of that model. The file ends by
233
+ registering the types of every model in the `ResourceRegistry` of `@appweaver/common`, which lets the factories and
234
+ `injectService` infer them from a model name. `--no-registry` leaves the registration out. Without any model the file
235
+ holds only `export {};`, so the `export * from './generated'` of the types index still compiles.
236
+
237
+ A model with `series` fields gets the `<Model>Series` table of its points in the Prisma schema (see
238
+ [timeseries](./timeseries.md)), left out when another store holds them: `timeseries.provider` set to `memory`, `none` or a
239
+ module path, or `auto` with a module package of another store enabled. `weaver test setup` follows the
240
+ provider of the `test` environment.
241
+
242
+ A spatial field gets its GeoJSON and bounding box columns, and with the `postgis` provider of `spatial.provider` (the
243
+ default on PostgreSQL) its PostGIS geometry column, a GiST index and the `postgis` extension of the datasource (see
244
+ [spatial](./spatial.md)). The types use the geometry types of `@appweaver/common`, i.e. `GeoPoint`.
245
+
246
+ The models come from the project and from the `resources` of the enabled modules (see [modules](./modules.md)). The
247
+ framework models reach the schema only when the project uses them: `Role`, `Permission`, `ApiKey`, `OneTimeToken` and
248
+ `ConnectedAccount` with an auth model, `File` when a model declares `files`, and `Seeder` when the seeders directory
249
+ exists (or an enabled module declares `seeders`). `--no-prune` keeps all of them.
250
+
251
+ The registry belongs to the application: in a module package (`appweaver.module` in its `package.json`) `weaver
252
+ generate` never writes it, and in an application it leaves out, with a warning, the models of a module package whose
253
+ declaration files register them already, so no model is registered twice.
254
+
255
+ The config schema is `appweaver.schema.json`, the JSON Schema the `$schema` of `appweaver.json` points to, built from
256
+ the config sections the enabled modules list in their manifests, so rerun it after adding a module. `weaver generate
257
+ --config-schema` writes it without loading `@appweaver/data`, so it works in an application without a database too.
258
+
259
+ ---
260
+
261
+ ## `weaver migrate`
262
+
263
+ ```
264
+ weaver migrate [options]
265
+ ```
266
+
267
+ Apply all pending database migrations (`prisma migrate deploy`). It creates no migration and never prompts, which
268
+ makes it the command to run in CI, in containers, and in production. It connects with `database.migrationUrl`, or
269
+ `database.url` when not set (the `url` of `prisma.config.ts` is `migrationUrl()` of `@appweaver/data/config`).
270
+
271
+ On PostgreSQL, it then sets up what the migrations do not hold, with the same URL: the hypertables and policies of the
272
+ `timescale` time series provider and the geometry triggers of the `postgis` spatial provider. The application sets them
273
+ up when it starts too, but only a user owning the tables can, so this lets the application connect as a user that only
274
+ reads and writes the data. The setup loads the models of the build (`./dist/src`), so build before migrating.
275
+
276
+ | Option | Description | Default |
277
+ |-------------------|-------------------------------------------------------------------------|---------|
278
+ | `--no-setup` | Skip the setup of the hypertables and the geometry triggers | set up |
279
+ | `--fix-checksums` | Record the new checksum of a SQL migration changed after it was applied | `false` |
280
+ | `--dry-run` | Print the pending migrations and their SQL without applying them | `false` |
281
+
282
+ After the Prisma migrations it applies the SQL migrations of `database.sqlDirPath` and of the modules
283
+ ([database.md](./database.md#sql-migrations)), then sets up the database.
284
+
285
+ `--dry-run` reads the pending migrations from `prisma migrate status` (Prisma has no dry run of `migrate deploy`) and
286
+ prints the `migration.sql` of each one, without changing the database. It exits with an error when `weaver migrate`
287
+ would apply none: on a failed migration to resolve first, diverged histories or an unreachable database. A database
288
+ without a migration history is named, since Prisma migrates it only when it has no tables. Review what a deployment
289
+ applies before running it:
290
+
291
+ ```sh
292
+ NODE_ENV=prod weaver migrate --dry-run
293
+ ```
294
+
295
+ ---
296
+
297
+ ## `weaver migration`
298
+
299
+ ```
300
+ weaver migration [options] [command]
301
+ ```
302
+
303
+ Create and check the database migrations, and reset the database. They are development commands, run against the
304
+ local database.
305
+
306
+ **Subcommands:**
307
+
308
+ | Command | Description |
309
+ | ----------------- | ------------------------------------------------------------ |
310
+ | `new <name>` | Create a new database migration and apply it |
311
+ | `check [options]` | Check whether the models need a new migration, print its SQL |
312
+ | `reset [options]` | Reset the database |
313
+
314
+ ### `weaver migration new`
315
+
316
+ Runs `prisma migrate dev --name <name>`: creates the migration of the model changes and applies it to the local
317
+ database. With `--create-only`, the migration is created without being applied, so its `migration.sql` can be edited
318
+ first (custom SQL Prisma does not generate: a trigger, a view, an expression or partial index, an extension), then
319
+ applied by `weaver migration new` again or `weaver migrate`. Prisma drops by the next migration what it can model but
320
+ the Prisma schema does not declare (a column, a plain index), so only add objects Prisma cannot model this way, and
321
+ prefer the SQL migrations for custom SQL: `weaver migration new <name> --sql [--database <type>]` creates
322
+ `database/sql/<timestamp>_<name>[.<database>].sql` instead ([database.md](./database.md#sql-migrations)). The command
323
+ fails before creating a Prisma migration that would drop a column or an index a SQL migration created.
324
+
325
+ ### `weaver migration check`
326
+
327
+ Tells whether the models changed without a migration, like `makemigrations --check` of Django. It builds the Prisma
328
+ schema from the model files without writing it, compares it with the local database (`prisma migrate diff`, read-only)
329
+ and prints the SQL `weaver migration new` would create.
330
+
331
+ | Option | Description | Default |
332
+ | --------------------------- | -------------------------------------------------- | ----------- |
333
+ | `--model-pattern <pattern>` | Glob pattern of the model files | from config |
334
+ | `--no-prune` | Keep the framework models the project does not use | pruned |
335
+
336
+ | Exit code | Meaning |
337
+ | --------- | ---------------------------------------------------------------------------------------- |
338
+ | `0` | No migration is needed |
339
+ | `1` | A migration is needed, its SQL is printed |
340
+ | `2` | The check cannot run: pending migrations (run `weaver migrate`), an unreachable database |
341
+
342
+ ```sh
343
+ weaver migration check
344
+ # A migration is needed, it would run:
345
+ #
346
+ # -- AlterTable
347
+ # ALTER TABLE "Category" ADD COLUMN "color" TEXT;
348
+ #
349
+ # Create it with: weaver generate && weaver migration new <name>
350
+ ```
351
+
352
+ - The database must have every migration applied, since it stands for the migrations: a change made to it by hand
353
+ shows up as a difference.
354
+ - The schema comes from the models, so the check also catches a model changed without `weaver generate`, and then
355
+ names `weaver generate` in the command to run.
356
+ - In CI, run it after `weaver migrate` on the database of the job, to fail a change that lacks its migration.
357
+
358
+ ### `weaver migration reset`
359
+
360
+ Drops the database, recreates it, and re-applies every migration (`prisma migrate reset`). **All data is lost.** Prisma
361
+ refuses the reset for an AI agent when `DATABASE_AI_DANGEROUS_ACTIONS_ENABLED` is `false`, like the `prisma migrate dev`
362
+ of `weaver migration new` and `weaver test setup`, see **Run tests** in [SKILL.md](../SKILL.md).
363
+
364
+ | Option | Description | Default |
365
+ | ------------- | --------------------------------------------------------- | ------- |
366
+ | `-y, --yes` | Skip the confirmation prompt | `false` |
367
+ | `-f, --force` | Allow the reset outside the `dev` and `test` environments | `false` |
368
+
369
+ Without `--force` the command runs only when `NODE_ENV` resolves to `dev` or `test`, and aborts otherwise. Either
370
+ `--force` or `--yes` skips the Prisma confirmation prompt.
371
+
372
+ ---
373
+
374
+ ## `weaver module`
375
+
376
+ ```
377
+ weaver module|mod <command> [options]
378
+ ```
379
+
380
+ Add and remove the optional modules of `@appweaver/create` in an existing project, from the templates of the
381
+ installed `@appweaver/cli`, install module packages, and create local modules. A module is enabled when the project
382
+ depends on its packages, `locales` and `docker` when `locales/` and `Dockerfile` exist.
383
+
384
+ | Module | Packages | Requires | Files |
385
+ | ----------- | ----------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
386
+ | `redis` | `@appweaver/redis` | — | The Redis service of `docker-compose.yml` |
387
+ | `queue` | `@appweaver/bullmq` | `redis` | — |
388
+ | `scheduler` | `@appweaver/cron` | — | — |
389
+ | `mailer` | `@appweaver/nodemailer` | — | The email templates of `templates/` (`emails/`, `layouts/email`, `partials/email-button`), the `emails` texts of `locales/en.json` |
390
+ | `templates` | `@appweaver/handlebars` | — | `templates/`, the Dockerfile `COPY` of the templates |
391
+ | `locales` | — | — | `locales/en.json` (empty without the mailer), the Dockerfile `COPY` of the translation files |
392
+ | `docker` | — | — | `Dockerfile`, `.dockerignore`, `docker-compose.yml`, `start.sh`, `database/mariadb-init.sh` (MySQL) |
393
+
394
+ ### `weaver module list`
395
+
396
+ ```
397
+ weaver module list|ls
398
+ ```
399
+
400
+ List the modules, whether the project has them enabled, their packages, requirements and description. `--json`
401
+ prints them as `[{ name, enabled, packages, requires, description }]`.
402
+
403
+ ### `weaver module new`
404
+
405
+ ```
406
+ weaver module new <name> [--dry-run]
407
+ ```
408
+
409
+ Create a local module in `src/modules/<name>/` (under `APP_SOURCE_PATH`), enabled by `APP_MODULES_PATTERN` without any
410
+ config:
411
+
412
+ | File | Holds |
413
+ | ----------- | ---------------------------------------------------------------------------------------------------- |
414
+ | `module.ts` | The manifest: its name, config, `loggers` and `main`, with commented `providers` and `services` |
415
+ | `config.ts` | Its config section, named after the camelCase of the name (`audit-log` → `auditLog`), with `ENABLED` |
416
+ | `main.ts` | The code run at startup: scheduled jobs, queue workers, event listeners |
417
+
418
+ The name must be kebab-case (`billing`, `audit-log`). The command fails, writing nothing, when a file of the module
419
+ exists. `--dry-run` prints the files without writing them.
420
+
421
+ ### `weaver module add`
422
+
423
+ ```
424
+ weaver module add <modules...> [options]
425
+ ```
426
+
427
+ Add the modules, with the modules they require: their packages to `package.json` (at the versions of the release),
428
+ their values to `appweaver.json`, their files, and what they add to the other enabled modules. An existing file that
429
+ differs is skipped and reported. Adding `locales` restores the `t` calls of the scaffolded templates still holding
430
+ the English texts. The dependencies are installed when `package.json` changed. `--database` picks the database of
431
+ the `data` module (`weaver module add data --database postgresql`), SQLite by default; it is refused once `data` is
432
+ enabled, and reported as ignored when `data` is not added.
433
+
434
+ A name that is not a scaffold module, with a scope, a `-` or a `/`, is a module package
435
+ (`weaver module add @acme/appweaver-gcs`), installed with
436
+ `npm install --ignore-scripts <package>` (`bun add` on Bun), so its install scripts never run. The command then
437
+ prints the providers of its manifest, selected in the provider key of their contract, and the modules it requires, or
438
+ that the package is not a module (no `appweaver.module` field in its `package.json`, or no valid manifest). With
439
+ `--dry-run` it prints the install command instead.
440
+
441
+ | Option | Description | Default |
442
+ | ------------------- | ------------------------------------------------ | --------- |
443
+ | `--database <type>` | `sqlite`, `postgresql`, `mysql` or `sqlserver` | `sqlite` |
444
+ | `--no-install` | Skip the installation of the dependencies | installed |
445
+ | `--dry-run` | Print the changes without applying them | `false` |
446
+ | `-f, --force` | Overwrite the existing files instead of skipping | `false` |
447
+ | `--verbose` | Print verbose output | `false` |
448
+
449
+ ### `weaver module remove`
450
+
451
+ ```
452
+ weaver module remove|rm <modules...> [options]
453
+ ```
454
+
455
+ Remove the modules: their packages, their `appweaver.json` values (the ones changed in the project are kept), their
456
+ files (the whole `templates/`, `locales/` and `database/` directories, the Docker files), and what they added to the
457
+ other enabled modules. Removing `locales` writes the English texts of `locales/en.json` into the templates first.
458
+ Removing `mailer` deletes the `emails` texts of `locales/en.json` that still hold their scaffolded value. A module that
459
+ an enabled module requires is removed only along with it. In `src/` and `database/seeders/` only the unchanged files
460
+ of `web` are deleted (the `User` resource and its admin seeder), the changed ones are kept with a warning, and so is a
461
+ changed e2e test of `web`. Removing `data` deletes `database/` with its migrations and seeders, listing the ones written
462
+ in the project in a warning.
463
+
464
+ | Option | Description | Default |
465
+ | -------------- | ----------------------------------------- | --------- |
466
+ | `--no-install` | Skip the installation of the dependencies | installed |
467
+ | `--dry-run` | Print the changes without applying them | `false` |
468
+ | `--verbose` | Print verbose output | `false` |
469
+
470
+ ---
471
+
472
+ ## `weaver resource new`
473
+
474
+ ```
475
+ weaver resource new <name> [--no-service] [--no-routes] [--no-policy] [--dry-run]
476
+ ```
477
+
478
+ Creates a resource in `<sourcePath>/resources/<name>/`, where the default patterns of `resource.modelPattern` and the
479
+ others find it. The name is kebab-case and singular (`blog-post` is the `BlogPost` model, its routes under
480
+ `/blog-posts`, the plural `createRoutes` derives: `person` is served under `/people`). It needs `@appweaver/data`:
481
+
482
+ | File | Holds |
483
+ | ------------ | ------------------------------------------------------------------------------------------------------------------------------- |
484
+ | `model.ts` | `createModel` with one `name` scalar to replace |
485
+ | `service.ts` | `createService` with a `beforeCreate` hook, left out with `--no-service` (which needs `--no-routes`) |
486
+ | `routes.ts` | `createRoutes` with every route for the `Admin` role, left out with `--no-routes` or without `@appweaver/web` |
487
+ | `policy.ts` | `createPolicy`: the admins read every record, a user the ones they created, an anonymous call none, left out with `--no-policy` |
488
+
489
+ It refuses to overwrite an existing file and prints the next commands, `weaver generate` and
490
+ `weaver migration new add_<name>`.
491
+
492
+ ## `weaver run`
493
+
494
+ ```
495
+ weaver run|r
496
+ weaver run|r <task> [args...]
497
+ ```
498
+
499
+ Run a one-shot task with the application by its name or its file, or list the tasks without one (`weaver run --json`
500
+ lists them as `{ tasks: [{ name, description, module, file }], failed: [{ file, error }] }`; after a task, `--json` is
501
+ an option of the task, and before one it is refused). The server, the
502
+ health listener and the scheduled jobs never start (`SERVER_LISTEN`, `HEALTH_CHECK_PORT` and `SCHEDULER_AUTO_START_JOB`
503
+ are forced off), and the command exits with the number the task returns (`0` otherwise, `1` when it throws). Invalid
504
+ arguments and `--help` exit before the application starts. A task logs like the application (`log.level`,
505
+ `log.levels`), on stderr unless `LOG_STREAM` is set, so its stdout holds what the task prints alone
506
+ (`weaver run export > out.csv`), while the other commands keep the framework logs silent behind their own output.
507
+
508
+ A task is the default export of a file in `src/tasks/` (`APP_TASKS_DIR_PATH`), created with `createTask`. Only `run`
509
+ is required, and the values of the arguments and options are typed from their declarations:
510
+
511
+ ```ts
512
+ // src/tasks/orders/count.ts, run with `weaver run orders:count Paid --min 2`
513
+ import { createTask, injectService } from '@appweaver/core';
514
+
515
+ export default createTask({
516
+ description: 'Counts the orders of a status.', // listed by `weaver run`
517
+ arguments: {
518
+ status: { required: true, choices: ['Pending', 'Paid'] } // <status>: 'Pending' | 'Paid'
519
+ },
520
+ options: {
521
+ min: { type: 'number', default: 1 }, // --min <min>: number
522
+ quiet: { type: 'boolean', description: 'Print nothing.' } // --quiet: boolean
523
+ },
524
+ run: async ({ args, options }) => {
525
+ const count = await injectService('Order').count({ status: args.status });
526
+ if (!options.quiet) {
527
+ console.log(`${count} orders`);
528
+ }
529
+ return count >= options.min ? 0 : 1; // the exit code
530
+ }
531
+ });
532
+ ```
533
+
534
+ | Field | Description |
535
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
536
+ | `run` | `({ args, options, argv }) => number \| void`, `argv` holding the arguments as given |
537
+ | `name` | Default: the path in the tasks directory (`orders/count.ts` is `orders:count`) |
538
+ | `description` | Listed by `weaver run`, shown by `--help` |
539
+ | `arguments` | Filled in the order of their keys: `description`, `type` (`string`, `number`), `required`, `variadic`, `default`, `choices` |
540
+ | `options` | A camelCase key is a kebab-case flag: `description`, `type` (`string`, `number`, `boolean`), `required`, `default`, `choices` |
541
+
542
+ The required arguments come before the optional ones and have no `default`, only the last one is `variadic`, and no
543
+ key is an integer, otherwise the task fails to run. A task declaring no `arguments` or `options` takes any, read from
544
+ `argv`.
545
+
546
+ ```sh
547
+ weaver run # list the tasks with their descriptions
548
+ weaver run orders:count --help # the usage of a task
549
+ weaver run orders:count Pending --quiet # run a task by its name
550
+ weaver run src/tasks/orders/count.ts Paid # run the task of a file
551
+ ```
552
+
553
+ The tasks of the enabled modules are listed and run too (see [modules](./modules.md)), a task of the application
554
+ replacing a module task of the same name. A plain default function, `(args: string[]) => number | void`, still works,
555
+ receiving the raw arguments. On Node the tasks run from the build output (`dist/src/tasks/`), so build first.
556
+
557
+ ---
558
+
559
+ ## `weaver seed`
560
+
561
+ ```
562
+ weaver seed|sd [options]
563
+ ```
564
+
565
+ Seed the database.
566
+
567
+ | Option | Description | Default |
568
+ | ---------------------- | ----------------------------------------------------------------------- | ----------------------------------------- |
569
+ | `--build-project` | Build the project before seeding | `false` |
570
+ | `-p, --project <path>` | TypeScript project config file of `--build-project` | `tsconfig.build.json` |
571
+ | `--seeders-dir <dir>` | Directory of the seeders | from config (`DATABASE_SEEDERS_DIR_PATH`) |
572
+ | `--continue-on-error` | Continue running the seeders when one throws an error | `false` |
573
+ | `--fix-warnings` | Fix the seeder warnings, like a wrong checksum or a deleted seeder file | `false` |
574
+ | `--dry-run` | Print the pending seeders and the warnings to fix without running them | `false` |
575
+
576
+ The seeders of the enabled modules (their `seeders` directory) run first, each recorded under its module name
577
+ (`billing/1-plans`), then the seeders of the application. A missing seeders directory is skipped with a warning, and
578
+ its recorded seeders are not reported as deleted; the command fails only when no directory is accessible.
579
+
580
+ With `--dry-run`, the pending seeders are listed but not run, and nothing is recorded: the warnings are still
581
+ reported, and the `--fix-warnings` fixes printed instead of applied. On a database that is not migrated yet, every
582
+ seeder is listed as pending.
583
+
584
+ ---
585
+
586
+ ## `weaver start`
587
+
588
+ ```
589
+ weaver start|s [options]
590
+ ```
591
+
592
+ Start the application.
593
+
594
+ | Option | Description | Default |
595
+ | ---------------------- | ----------------------------------------------------------- | --------------------- |
596
+ | `-w, --watch` | Run in watch mode (recompiles and restarts on file changes) | `false` |
597
+ | `-p, --project <path>` | TypeScript project config file of the watch mode | `tsconfig.build.json` |
598
+
599
+ In watch mode the server also restarts when a file of the template or translation directories (`TEMPLATE_PATH`,
600
+ `LOCALE_PATH`) changes, the Node runtime only while the last build succeeded.
601
+
602
+ ---
603
+
604
+ ## `weaver lint` and `weaver format`
605
+
606
+ ```
607
+ weaver lint [--fix] [patterns...]
608
+ weaver format [--check] [patterns...]
609
+ ```
610
+
611
+ Run the ESLint (default pattern `.`) and the Prettier (default pattern `./**/*.ts`, written unless `--check`) of the
612
+ project's `@appweaver/tooling` dev dependency. Without the package they exit with 1, naming the install command.
613
+
614
+ ---
615
+
616
+ ## `weaver test`
617
+
618
+ ```
619
+ weaver test|t [options] [command]
620
+ ```
621
+
622
+ Run the tests (`weaver test [patterns...]`), or set up, reset and tear down the test environment (the subcommands). The
623
+ tests run with the Jest of `@appweaver/tooling` on Node and `bun test` on Bun, with `NODE_ENV=test` unless the shell
624
+ sets `NODE_ENV` (the `NODE_ENV` of a `.env` file never applies to them).
625
+
626
+ | Option | Description | Default |
627
+ | ------------- | ---------------------------------------------------------- | ------- |
628
+ | `--e2e` | Run the end-to-end tests (`test/e2e/jest.e2e-config.json`) | `false` |
629
+ | `--coverage` | Collect the coverage | `false` |
630
+ | `-w, --watch` | Run the tests again on every change | `false` |
631
+
632
+ **Subcommands:**
633
+
634
+ | Command | Description |
635
+ | -------------------- | ----------------------------------------------------------------------------------------- |
636
+ | `setup [options]` | Set up the temporary test data: the storage directory, the Prisma schema and the database |
637
+ | `reset [options]` | Reset the test database and/or the storage files |
638
+ | `teardown [options]` | Remove the temporary test directory |
639
+
640
+ ### `weaver test setup`
641
+
642
+ Requires `NODE_ENV=test`.
643
+
644
+ | Option | Description | Default |
645
+ | ----------------------------- | ------------------------------------- | ----------------------------------------------- |
646
+ | `--temp-dir <dir>` | Directory of the temporary test data | `./temp` |
647
+ | `--model-pattern <pattern>` | Glob pattern of the model files | from config (`RESOURCE_MODEL_PATTERN`) |
648
+ | `--prisma-schema-path <path>` | Output path of the Prisma schema | from config (`DATABASE_SCHEMA_PATH`) |
649
+ | `--client-dir <dir>` | Output directory of the Prisma client | from config (`DATABASE_CLIENT_OUTPUT_DIR_PATH`) |
650
+ | `--migration-name <name>` | Name of the initial migration | `init_test` |
651
+ | `--verbose` | Print verbose output | `false` |
652
+
653
+ Aborts unless the storage, schema and client paths all resolve inside `--temp-dir`, so a misconfigured test run cannot
654
+ touch the development database or uploads. It resets the test database (`prisma migrate reset --force`) before the
655
+ initial migration, since a PostgreSQL or MySQL test database keeps the tables and migrations of the last run.
656
+
657
+ ### `weaver test reset`
658
+
659
+ Requires `NODE_ENV=test`. With no flags, resets both database and storage. The database is reset with
660
+ `prisma migrate reset`, which Prisma refuses to run for an AI agent when `DATABASE_AI_DANGEROUS_ACTIONS_ENABLED` is
661
+ `false`, see **Run tests** in [SKILL.md](../SKILL.md). An agent never changes it itself. The reset drops the whole
662
+ test database, so the e2e Jest config runs the test files one at a time (`"maxWorkers": 1`).
663
+
664
+ | Option | Description | Default |
665
+ | ------------------ | ------------------------------------ | -------- |
666
+ | `--database` | Reset the database | — |
667
+ | `--storage` | Reset the storage files | — |
668
+ | `--temp-dir <dir>` | Directory of the temporary test data | `./temp` |
669
+ | `--verbose` | Print verbose output | `false` |
670
+
671
+ ### `weaver test teardown`
672
+
673
+ Requires `NODE_ENV=test`.
674
+
675
+ | Option | Description | Default |
676
+ | ------------------ | ------------------------------------ | -------- |
677
+ | `--temp-dir <dir>` | Directory of the temporary test data | `./temp` |
678
+ | `--verbose` | Print verbose output | `false` |
679
+
680
+ The test database of a server (PostgreSQL, MySQL, SQL Server) is kept, since `weaver test setup` resets it.
681
+
682
+ ---
683
+
684
+ ## `weaver skill`
685
+
686
+ ```
687
+ weaver skill sync [--dry-run]
688
+ ```
689
+
690
+ `sync` copies the skill files of the project's `@appweaver/skill` dev dependency into the `skills/appweaver/` of every
691
+ agent directory the project has (`.claude`, `.junie`, `.kiro`, `.pi`, `.github`, `.opencode`, `.agents`), replacing the
692
+ files of the previous version. The project's `AGENTS.md` or `CLAUDE.md` is never touched. It exits with 1 when the
693
+ package is not installed (`npm install --save-dev @appweaver/skill`).
694
+
695
+ | Option | Description | Default |
696
+ | ----------- | ---------------------------------------------------------------------- | ------- |
697
+ | `--dry-run` | Print the skill directories that would be written without writing them | `false` |
698
+
699
+ ---
700
+
701
+ ## `weaver upgrade`
702
+
703
+ ```
704
+ weaver upgrade|up [options] [packages...]
705
+ ```
706
+
707
+ Upgrade the Appweaver packages. The companion packages installed in the project (Prisma and its adapters, TypeBox,
708
+ TypeScript) are bumped along to the exact versions the target release is built with, read from the
709
+ `scaffoldDependencies` of `@appweaver/cli` in the registry. The libraries of the drivers come with their `@appweaver/*`
710
+ packages. Missing packages are never added and newer ones never downgraded. Run `weaver generate` afterward when Prisma
711
+ is upgraded. The skill files are refreshed by `weaver skill sync` after the install.
712
+
713
+ **Arguments:**
714
+
715
+ | Argument | Description | Default |
716
+ | ---------- | ------------------------------------------------------------------------------ | ------------------------------------- |
717
+ | `packages` | The `@appweaver/*` packages to upgrade (i.e. `@appweaver/core @appweaver/cli`) | All installed `@appweaver/*` packages |
718
+
719
+ **Options:**
720
+
721
+ | Option | Description | Default |
722
+ | ---------------------------- | ------------------------------------------------------------------------------- | -------- |
723
+ | `--no-companions` | Skip upgrading the companion packages | upgraded |
724
+ | `--tooling` | Also upgrade the tooling packages outside `@appweaver/tooling` (`@types/bun`) | `false` |
725
+ | `--no-skill` | Skip upgrading the AI agent skill files in agent dirs (`.claude`, `.agents`, …) | upgraded |
726
+ | `--target-version <version>` | Version to upgrade the packages to | `latest` |
727
+ | `--dry-run` | Print the packages that would be upgraded without installing them | `false` |
728
+ | `-f, --force` | Upgrade despite the peerDependency version mismatches | `false` |
729
+ | `--verbose` | Print verbose output | `false` |