@warlock.js/core 5.32.0 → 5.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/esm/application/application-config-types.d.mts +8 -0
  3. package/esm/application/application-config-types.d.mts.map +1 -1
  4. package/esm/application/boot-signal.d.mts +8 -8
  5. package/esm/application/boot-signal.d.mts.map +1 -1
  6. package/esm/application/boot-signal.mjs +15 -9
  7. package/esm/application/boot-signal.mjs.map +1 -1
  8. package/esm/cli/commands/ai/ai-command.action.mjs +140 -0
  9. package/esm/cli/commands/ai/ai-command.action.mjs.map +1 -0
  10. package/esm/cli/commands/ai.command.mjs +50 -0
  11. package/esm/cli/commands/ai.command.mjs.map +1 -0
  12. package/esm/cli/commands/check/check-command.action.mjs +3 -0
  13. package/esm/cli/commands/check/check-command.action.mjs.map +1 -1
  14. package/esm/cli/commands/check.command.mjs +6 -1
  15. package/esm/cli/commands/check.command.mjs.map +1 -1
  16. package/esm/cli/commands/pm2/pm2-command.action.mjs +91 -0
  17. package/esm/cli/commands/pm2/pm2-command.action.mjs.map +1 -0
  18. package/esm/cli/commands/pm2/pm2-config.mjs +115 -0
  19. package/esm/cli/commands/pm2/pm2-config.mjs.map +1 -0
  20. package/esm/cli/commands/pm2.command.mjs +53 -0
  21. package/esm/cli/commands/pm2.command.mjs.map +1 -0
  22. package/esm/cli/framework-cli-commands.mjs +4 -0
  23. package/esm/cli/framework-cli-commands.mjs.map +1 -1
  24. package/esm/connectors/connectors-manager.d.mts.map +1 -1
  25. package/esm/connectors/connectors-manager.mjs +1 -4
  26. package/esm/connectors/connectors-manager.mjs.map +1 -1
  27. package/esm/connectors/shutdown-timeout.mjs +7 -0
  28. package/esm/connectors/shutdown-timeout.mjs.map +1 -0
  29. package/esm/connectors/socket-connector.d.mts.map +1 -1
  30. package/esm/connectors/socket-connector.mjs +8 -1
  31. package/esm/connectors/socket-connector.mjs.map +1 -1
  32. package/esm/dev-server/health-checker/checkers/eslint-health-checker.mjs +6 -8
  33. package/esm/dev-server/health-checker/checkers/eslint-health-checker.mjs.map +1 -1
  34. package/esm/dev-server/health-checker/default-health-checkers.mjs +6 -15
  35. package/esm/dev-server/health-checker/default-health-checkers.mjs.map +1 -1
  36. package/esm/dev-server/health-checker/eslint-support.mjs +27 -0
  37. package/esm/dev-server/health-checker/eslint-support.mjs.map +1 -0
  38. package/esm/dev-server/health-checker/file-health-checker.contract.d.mts +2 -1
  39. package/esm/dev-server/health-checker/file-health-checker.contract.d.mts.map +1 -1
  40. package/esm/dev-server/health-checker/workers/eslint-health.worker.mjs +2 -11
  41. package/esm/dev-server/health-checker/workers/eslint-health.worker.mjs.map +1 -1
  42. package/esm/generations/features/index.mjs +2 -0
  43. package/esm/generations/features/index.mjs.map +1 -1
  44. package/esm/generations/features/process.feature.mjs +65 -0
  45. package/esm/generations/features/process.feature.mjs.map +1 -0
  46. package/esm/http/port-preflight.d.mts.map +1 -1
  47. package/esm/http/port-preflight.mjs +2 -0
  48. package/esm/http/port-preflight.mjs.map +1 -1
  49. package/esm/index.d.mts +7 -2
  50. package/esm/index.mjs +7 -2
  51. package/esm/secrets/errors.d.mts +9 -0
  52. package/esm/secrets/errors.d.mts.map +1 -0
  53. package/esm/secrets/errors.mjs +22 -0
  54. package/esm/secrets/errors.mjs.map +1 -0
  55. package/esm/secrets/file-backend.mjs +167 -0
  56. package/esm/secrets/file-backend.mjs.map +1 -0
  57. package/esm/secrets/index.d.mts +6 -0
  58. package/esm/secrets/index.mjs +6 -0
  59. package/esm/secrets/keyring-backend.mjs +50 -0
  60. package/esm/secrets/keyring-backend.mjs.map +1 -0
  61. package/esm/secrets/memory-backend.d.mts +12 -0
  62. package/esm/secrets/memory-backend.d.mts.map +1 -0
  63. package/esm/secrets/memory-backend.mjs +28 -0
  64. package/esm/secrets/memory-backend.mjs.map +1 -0
  65. package/esm/secrets/secret-store.d.mts +25 -0
  66. package/esm/secrets/secret-store.d.mts.map +1 -0
  67. package/esm/secrets/secret-store.mjs +117 -0
  68. package/esm/secrets/secret-store.mjs.map +1 -0
  69. package/esm/secrets/secrets.d.mts +11 -0
  70. package/esm/secrets/secrets.d.mts.map +1 -0
  71. package/esm/secrets/secrets.mjs +63 -0
  72. package/esm/secrets/secrets.mjs.map +1 -0
  73. package/esm/secrets/types.d.mts +22 -0
  74. package/esm/secrets/types.d.mts.map +1 -0
  75. package/esm/socket/index.d.mts +2 -2
  76. package/esm/socket/index.mjs +2 -2
  77. package/esm/socket/utils.d.mts +7 -0
  78. package/esm/socket/utils.d.mts.map +1 -1
  79. package/esm/socket/utils.mjs +12 -1
  80. package/esm/socket/utils.mjs.map +1 -1
  81. package/esm/tests/fakes/index.d.mts +2 -1
  82. package/esm/tests/fakes/index.mjs +2 -1
  83. package/esm/tests/fakes/secrets-fake.d.mts +13 -0
  84. package/esm/tests/fakes/secrets-fake.d.mts.map +1 -0
  85. package/esm/tests/fakes/secrets-fake.mjs +50 -0
  86. package/esm/tests/fakes/secrets-fake.mjs.map +1 -0
  87. package/esm/tests/fakes/test-fakes.d.mts +2 -2
  88. package/esm/tests/fakes/test-fakes.d.mts.map +1 -1
  89. package/esm/tests/fakes/test-fakes.mjs +5 -2
  90. package/esm/tests/fakes/test-fakes.mjs.map +1 -1
  91. package/esm/tests/index.d.mts +2 -1
  92. package/esm/tests/index.mjs +2 -1
  93. package/esm/tests/vitest-setup.d.mts +1 -1
  94. package/esm/tests/vitest-setup.mjs.map +1 -1
  95. package/esm/tooling/check/lint-step.d.mts +2 -8
  96. package/esm/tooling/check/lint-step.d.mts.map +1 -1
  97. package/esm/tooling/check/lint-step.mjs +14 -11
  98. package/esm/tooling/check/lint-step.mjs.map +1 -1
  99. package/esm/tooling/check/run-check.d.mts +2 -0
  100. package/esm/tooling/check/run-check.d.mts.map +1 -1
  101. package/esm/tooling/check/run-check.mjs +2 -2
  102. package/esm/tooling/check/run-check.mjs.map +1 -1
  103. package/esm/upgrade/codemods/index.mjs +2 -0
  104. package/esm/upgrade/codemods/index.mjs.map +1 -1
  105. package/esm/upgrade/codemods/oxc-toolchain.mjs +142 -0
  106. package/esm/upgrade/codemods/oxc-toolchain.mjs.map +1 -0
  107. package/esm/upgrade/codemods/toolchain-templates.mjs +244 -0
  108. package/esm/upgrade/codemods/toolchain-templates.mjs.map +1 -0
  109. package/esm/upgrade/run-upgrade.mjs +25 -6
  110. package/esm/upgrade/run-upgrade.mjs.map +1 -1
  111. package/esm/warlock-config/types.d.mts +2 -1
  112. package/esm/warlock-config/types.d.mts.map +1 -1
  113. package/llms-full.txt +326 -19
  114. package/llms.txt +3 -2
  115. package/package.json +23 -13
  116. package/skills/README.md +2 -1
  117. package/skills/index.md +1 -1
  118. package/skills/run-app/SKILL.md +114 -5
  119. package/skills/store-secrets/SKILL.md +102 -0
  120. package/skills/test-fakes/SKILL.md +13 -11
  121. package/skills/upgrade-from-5-29/SKILL.md +39 -2
  122. package/skills/warlock-check/SKILL.md +5 -1
  123. package/skills/warlock-doctor/SKILL.md +9 -0
  124. package/skills/wire-socket/SKILL.md +19 -0
  125. package/skills/write-cli-command/SKILL.md +21 -0
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: run-app
3
- description: 'Three operational commands — `warlock dev` (HMR + type-gen + health checks), `warlock build` (esbuild bundle), `warlock start` (spawn the production bundle). All flags, all `warlock.config.ts` knobs that shape them. Triggers: `warlock dev`, `warlock build`, `warlock start`, `devServer`, `--fresh`, `--skip-typings`, `--skip-health`, `outdir`, `outFile`, `sourcemap`, `PortInUseError`, `assertPortIsAvailable`, `EADDRINUSE`, `EsbuildBinaryMissingError`, `detectJavaScriptRuntime`, `assertNodeOnlyCommand`, Bun, Deno, `bun dist/app.js`, `deno run -A`; "start the dev server", "build for production", "run the bundle", "skip type generation", "tune watch globs", "dev server keyboard shortcuts", "press r to restart", "press q to quit", "restart the dev server", "port already in use", "run on Bun", "run on Deno", "supported runtimes"; typical config `warlock.config.ts > devServer / build`. Skip: writing a custom CLI — the `write-cli-command` topic; config shape — the `configure-app` topic; competing tooling `nodemon`, `tsx`, `ts-node-dev`, `esbuild` direct.'
3
+ description: 'Operational commands — `warlock dev` (HMR + type-gen + health checks), `warlock build` (esbuild bundle), `warlock start` (spawn the production bundle), `warlock pm2 init` / `reload` (optional deployment tooling). All flags, all `warlock.config.ts` knobs that shape them. Triggers: `warlock pm2`, `ecosystem.config.cjs`, `wait_ready`, `kill_timeout`, `app.shutdownTimeout`, `warlock dev`, `warlock build`, `warlock start`, `devServer`, `--fresh`, `--skip-typings`, `--skip-health`, `outdir`, `outFile`, `sourcemap`, `PortInUseError`, `assertPortIsAvailable`, `EADDRINUSE`, `EsbuildBinaryMissingError`, `detectJavaScriptRuntime`, `assertNodeOnlyCommand`, Bun, Deno, `bun dist/app.js`, `deno run -A`; "start the dev server", "build for production", "run the bundle", "skip type generation", "tune watch globs", "dev server keyboard shortcuts", "press r to restart", "press q to quit", "restart the dev server", "port already in use", "run on Bun", "run on Deno", "supported runtimes"; typical config `warlock.config.ts > devServer / build`. Skip: writing a custom CLI — the `write-cli-command` topic; config shape — the `configure-app` topic; competing tooling `nodemon`, `tsx`, `ts-node-dev`, `esbuild` direct.'
4
4
  ---
5
5
 
6
6
  # Warlock — run the app
@@ -150,13 +150,13 @@ export default defineConfig({
150
150
 
151
151
  - **`watch.include` / `watch.exclude`** — globs piped into the file watcher. Override when you have non-`.ts(x)` files driving reloads (e.g. SQL fixtures), or to exclude a generated folder.
152
152
  - **`generateTypings`** — turn off if you're committing generated typings and don't want them rewritten on every boot. The `--skip-typings` flag is the per-run version.
153
- - **`healthCheckers`** — built-in switches (`{ typescript?, eslint?, oxlint? }`), custom file health checker contracts, or `false` to disable. The `--skip-health` flag disables all checkers for that run. TypeScript runs by default. ESLint uses core's dependency and requires only an app-root flat config; Oxlint requires its package installed in the app plus a config. Both run when configured.
153
+ - **`healthCheckers`** — built-in switches (`{ typescript?, eslint?, oxlint? }`), custom file health checker contracts, or `false` to disable. The `--skip-health` flag disables all checkers for that run. TypeScript runs by default. ESLint uses core's dependency and requires only an app-root flat config; Oxlint requires its package installed in the app plus a config. ESLint is disabled by default; explicitly set `eslint: true` to retain it until removal in 5.34.0. Enabling it prints one deprecation warning and the Oxc migration command.
154
154
  - **`transpileCacheDebug`** — diagnostic only. Names `.warlock/transpile/*.js` files `<slug>.<hash>.js` and appends `// @source <path>` markers so you can eyeball which cache entry came from which source. Leave off in normal use.
155
155
  - **`checkForUpdates`** — on `warlock dev` start, check npm for a newer `@warlock.js/core` and print a one-line notice if one exists. Best-effort and non-blocking; auto-skipped in CI and non-TTY shells. In an interactive terminal the notice arms a **`u` shortcut** that updates every `@warlock.js/*` package, installs, and restarts the server; elsewhere it prints `npx warlock update` instead. The registry answer is cached for 24h in `.warlock/update-check.json`, so a day of restarts costs one lookup. See the `update-packages` topic.
156
156
  - **`restartOnConfigChange`** — restart the dev server when `warlock.config.ts` or any `.env*` changes (default `true`). Set `false` to get a warning instead and restart by hand. Neither file can be hot-reloaded, so without a restart the running services keep the old values.
157
157
  - **`timings`** — print a one-line, per-phase breakdown next to the `hmr update` line on every hot reload: `watcher`, `debounce`, `graph`, `reimport`, `connectors`. `watcher` is the raw-fs-notification-to-stabilised-event gap (chokidar's `awaitWriteFinish` window); `debounce` is the handler's own adaptive wait; the rest are self-explanatory. Opt-in, off by default — a disabled flag costs one boolean check per reload, since the watcher-settle bookkeeping only runs when this is on. Use it to see which phase a slow reload is actually spending time in.
158
158
 
159
- ### Optional Oxlint file checks
159
+ ### Default Oxlint file checks
160
160
 
161
161
  Install `oxlint` in the app (`npm install --save-dev oxlint`) and add `.oxlintrc.json` at the app root:
162
162
 
@@ -178,7 +178,7 @@ export default defineConfig({
178
178
  });
179
179
  ```
180
180
 
181
- Omit the switches to run TypeScript and every installed/configured linter; `true` still requires the linter's config, and Oxlint also requires its app-installed package. Set `oxlint: false` to disable only Oxlint while leaving other defaults intact. A custom checker array replaces the built-in list. Config discovery also accepts `.oxlintrc.jsonc`, `oxlint.config.ts` and `oxlint.config.mts`; use JSON/JSONC on Node 22.15 because current Oxlint TypeScript configs need Node 22.18 or newer.
181
+ Omit the switches to run TypeScript and installed/configured Oxlint; ESLint is off by default and requires `eslint: true`; `true` still requires the linter's config, and Oxlint also requires its app-installed package. Set `oxlint: false` to disable only Oxlint while leaving other defaults intact. A custom checker array replaces the built-in list. Config discovery also accepts `.oxlintrc.jsonc`, `oxlint.config.ts` and `oxlint.config.mts`; use JSON/JSONC on Node 22.15 because current Oxlint TypeScript configs need Node 22.18 or newer.
182
182
 
183
183
  ## `warlock build` — production bundle
184
184
 
@@ -412,11 +412,120 @@ Configured http.port "03999" normalised to 3999.
412
412
  Three consequences worth knowing:
413
413
 
414
414
  1. **A queue worker with no http connector still reports.** Readiness hangs on a completed boot, not on a bound port. `port` is simply absent.
415
- 2. **Running the bundle any other way changes nothing.** `node dist/app.js`, a Docker `CMD`, or pm2 — the signal is a strict no-op without both the IPC channel and the handshake flag, so Warlock never writes into a channel that belongs to another supervisor.
415
+ 2. **PM2 receives its own readiness message (5.33.0+).** With an IPC channel and PM2's `pm_id` present, core sends `"ready"` after completed boot and leaves the channel open. Plain Node/Docker launches without IPC remain silent. `warlock start` takes priority when its handshake is present.
416
416
  3. **A bundle built before 4.11.0 has no signal.** It starts and runs normally, and after ten seconds prints a note on **stderr only** telling you to re-run `warlock build`. An absent signal is never an error, never fails the run, and never kills a slow boot.
417
417
 
418
418
  If you need the same fact inside the app, use `Application.onceBooted()` / `Application.whenBooted()` — the signal and your listeners fire from the same latch.
419
419
 
420
+ ## `warlock pm2 init` / `reload` — optional production supervision
421
+
422
+ PM2 is operator tooling, never a core dependency. Install it separately and
423
+ put `pm2` on `PATH`. Generate from the app root with the target environment:
424
+
425
+ ```bash
426
+ NODE_ENV=production npx warlock build
427
+ NODE_ENV=production npx warlock pm2 init
428
+ # package.json name=store, app.appName=api → store-api-production
429
+ pm2 start ecosystem.config.cjs --only store-api-production
430
+
431
+ # Deploy a fresh successful build, then reload only this app:
432
+ NODE_ENV=production npx warlock pm2 reload
433
+ NODE_ENV=production npx warlock pm2 reload --id 7
434
+ ```
435
+
436
+ `init` reads app/http/socket config and resolved build paths without starting
437
+ connectors, bootstrap or prestart. It creates `ecosystem.config.cjs` exclusively;
438
+ an existing file is an error. It works without PM2 installed or a prior build.
439
+ The file runs the built entry directly, with an absolute `cwd`, Node interpreter
440
+ and source maps matching `build.sourcemap`.
441
+
442
+ The identity is `<project>-<app>-<NODE_ENV>`; project defaults to `package.json`
443
+ name (`@team/store` → `team-store`), app to `app.appName` or `app`, environment
444
+ to `NODE_ENV` or `development`. Use `--project store --app api` to override the
445
+ components, and repeat those overrides on reload. Components accept letters,
446
+ digits, `_` and `-`, starting with a letter/digit. Choose a combination unique
447
+ within the daemon; no patterns or broad selectors are supported.
448
+
449
+ ```bash
450
+ NODE_ENV=production npx warlock pm2 init --project store --app api \
451
+ --cluster --instances 2 --listen-timeout 60000
452
+ NODE_ENV=production npx warlock pm2 reload --project store --app api
453
+ ```
454
+
455
+ Defaults: `exec_mode: "fork"`, `instances: 1`, `wait_ready: true`,
456
+ `listen_timeout: 30000`. `--cluster` opts into two workers by default;
457
+ `--instances` accepts a positive integer or `max`, only with `--cluster`.
458
+ Fork reload falls back to restart and may interrupt traffic. PM2 cluster reload
459
+ can replace workers while others serve, but a boot/readiness timeout can still
460
+ cause downtime. Keep both the PM2 daemon and app on Node 22.15+; cluster uses
461
+ the daemon's runtime.
462
+
463
+ `kill_timeout` equals the existing overall connector budget,
464
+ `app.shutdownTimeout` (default 10000ms), now typed on `AppConfigurations`:
465
+
466
+ ```ts
467
+ import type { AppConfigurations } from "@warlock.js/core";
468
+
469
+ export default {
470
+ appName: "api",
471
+ shutdownTimeout: 20000,
472
+ } satisfies AppConfigurations;
473
+ ```
474
+
475
+ Keep `http.gracefulShutdown.timeout` lower (e.g. 10000ms), with room for other
476
+ connectors, hooks and log flushes. PM2's kill timer covers the whole exit;
477
+ core's connector timer starts after app hooks and finishes before log flushing.
478
+ The generated comment and CLI output show the configured readiness URL (or an
479
+ unavailable notice for no HTTP, disabled health or ephemeral ports). PM2 itself
480
+ does not poll it. Use an external deployment probe.
481
+
482
+ Core emits `process.send("ready")` once at completed boot when PM2's `pm_id`
483
+ and IPC are present, after HTTP and the connectors have started. It never
484
+ disconnects PM2's channel. Socket-only apps also await the listener and reject
485
+ bind failures before completing boot. Rebuild with core 5.33+ before using `wait_ready`.
486
+ `listen_timeout` limits waiting for readiness; `kill_timeout` limits shutdown
487
+ before PM2's forced kill. Core handles PM2's default `SIGINT` gracefully.
488
+
489
+ With sockets enabled, cluster generation/reload refuse a missing
490
+ `socket.adapter` factory and require `socket.options.transports: ["websocket"]`
491
+ with WebSocket-only clients. The adapter handles broadcasts; polling still
492
+ needs sticky routing to each worker, which this generator does not install.
493
+ For polling, use individual fork listeners behind a sticky proxy or a custom
494
+ cluster primary. See the `wire-socket` topic. Avoid duplicating worker jobs
495
+ and in-memory sessions across HTTP workers.
496
+
497
+ `reload` requires a successful build marker, reads `pm2 jlist`, verifies **all**
498
+ exact-name matches against the app's absolute cwd and entry, then calls
499
+ `pm2 reload <numeric-id>` sequentially. `--id` narrows to one verified worker.
500
+ Foreign cwd/script, invalid selectors, offline cluster workers or cluster
501
+ workers without `wait_ready` are refused before reload. Reload uses settings
502
+ already registered in PM2; regenerate/reapply the ecosystem when they change.
503
+
504
+ On shared servers, inspect the current PM2 id and path before stopping:
505
+
506
+ ```bash
507
+ pm2 list
508
+ pm2 show 7
509
+ pm2 stop 7
510
+ ```
511
+
512
+ Repeat for each intended worker id. Never stop by pattern or broad name, and
513
+ avoid daemon-wide operations. PM2 ids are not OS PIDs and can change after an
514
+ app is deleted/recreated.
515
+
516
+ To put logger entries in PM2's captured stdout, configure
517
+ `src/config/log.ts` with `production: { channels: [new ConsoleLog()] }`
518
+ (`ConsoleLog` comes from `@warlock.js/logger`). Keep `time: false` and omit
519
+ `log_date_format` to preserve the logger's timestamp/module/action format.
520
+ Generated `merge_logs: false` keeps worker logs separate. PM2 JSON output wraps
521
+ captured text; it does not recover logger fields. Use `JSONFileLog` with a
522
+ distinct per-worker storage path for structured persistent entries.
523
+
524
+ Official references: [PM2 readiness/shutdown](https://pm2.keymetrics.io/docs/usage/signals-clean-restart/),
525
+ [cluster reload](https://pm2.keymetrics.io/docs/usage/cluster-mode/),
526
+ [Socket.IO multiple nodes](https://socket.io/docs/v4/using-multiple-nodes/).
527
+ Full docs: `docs/src/content/docs/v/latest/core/cli/pm2.mdx`.
528
+
420
529
  ## Runtimes — Node, Bun, Deno
421
530
 
422
531
  | Command | Node.js 22.15+ | Bun 1.4.3 | Deno 2.9.7 |
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: store-secrets
3
+ description: "Store app credentials with secrets.get/set/remove/has and environmentName; lazy optional OS keychain, read-only scoped environment variables, encrypted file fallback, typed SecretStoreError and memory-backed secretsFake. Use for provider keys and OAuth credentials the app must read back. Skip user passwords (hash-password) and encrypted database columns (encrypt-data)."
4
+ ---
5
+
6
+ # Application secret store
7
+
8
+ Use core's facade; there is no separate package or preparation step:
9
+
10
+ ```ts
11
+ import { secrets, SecretStoreError } from "@warlock.js/core";
12
+ // The same API is available from "@warlock.js/core/secrets".
13
+
14
+ await secrets.set("vendor-token", "provider-credential");
15
+ const token = await secrets.get("vendor-token"); // string | undefined
16
+ const exists = await secrets.has("vendor-token"); // boolean; true for ""
17
+ const removed = await secrets.remove("vendor-token"); // boolean
18
+ const variable = secrets.environmentName("vendor-token"); // variable name, not value
19
+
20
+ try {
21
+ await secrets.remove("vendor-token");
22
+ } catch (error) {
23
+ if (error instanceof SecretStoreError && error.code === "READ_ONLY") {
24
+ // Change the deployment environment instead.
25
+ } else {
26
+ throw error;
27
+ }
28
+ }
29
+ ```
30
+
31
+ Names are case-sensitive, nonempty strings of at most 256 UTF-16 code units. Values are strings, including empty strings. Every operation is async, except `environmentName()`.
32
+
33
+ ## Configuration and backend decisions
34
+
35
+ - Default namespace: app name plus the SHA-256 hash of the absolute project root. For changing release directories, configure a stable unique namespace including the deployment environment.
36
+ - Reads: OS keychain → exact scoped environment variable → encrypted file.
37
+ - Optional peer: `npm install @napi-rs/keyring`. Core lazily uses its 2.1.1 `AsyncEntry` API. Linux requires `secret-service` for persistence; it does not use the memory-only keyutils fallback. Sources: [official README](https://github.com/Brooooooklyn/keyring-node#readme), [published declarations](https://www.npmjs.com/package/@napi-rs/keyring?activeTab=code), verified 2026-10-19.
38
+ - One initial read-only probe selects the keychain for that store lifetime. Missing peer/initially unavailable service falls back automatically. A later keychain failure throws `UNAVAILABLE`; do not silently change backends mid-operation. Keep backend availability consistent between deployments; independent backend writes are not reconciled automatically.
39
+ - Environment names are `WARLOCK_SECRET_<namespace UTF-8 uppercase hex>_<name UTF-8 uppercase hex>`; use `environmentName()` to avoid guessing. No unscoped environment fallback. Both mutation methods throw `READ_ONLY` if that variable is present, including `""` and shadowed environment values.
40
+ - File fallback derives a per-namespace HKDF-SHA256 key from `encryption.key` (64 hex characters, conventionally `APP_ENCRYPTION_KEY`) and uses AES-256-GCM with name/namespace authenticated data. It never stores an unencrypted value/key file. Core's global `encrypt()` helper cannot accept a derived key, so the backend uses Node crypto without changing global config. Consult `encrypt-data` for app key provisioning.
41
+ - Default files: `storage/secrets/<namespace hash>/<name hash>.secret`. Directories `0700`, files `0600`, owner checks, no symlinks/hardlinks, synced temporary writes and rename. Parent directories must be trusted. Same-key concurrent writes use last completed rename.
42
+ - File fallback fails closed on Windows because Node modes cannot enforce owner-only ACLs; use keychain/environment. See [Node file modes](https://nodejs.org/docs/latest-v22.x/api/fs.html#file-modes).
43
+ - Keychain writes clear an old file copy; removal clears both writable layers. Retry errors after fixing the backend; a multi-layer operation may partially complete.
44
+
45
+ ```ts title="src/config/secrets.ts"
46
+ import type { SecretsConfigurations } from "@warlock.js/core";
47
+
48
+ export default {
49
+ namespace: "sample-app-production",
50
+ // directory: "/srv/sample-app/private-secrets",
51
+ } satisfies SecretsConfigurations;
52
+ ```
53
+
54
+ Never change namespace or encryption key without a migration. Keep file storage outside publicly served paths, and secure the app key separately from encrypted backups.
55
+
56
+ ## Isolated tests and explicit stores
57
+
58
+ `setupTest()` and the HTTP test harness install `secretsFake` by default. `NODE_ENV=test` alone does not install it. Opt out with `tests.fakes: { secrets: false }` only for real-backend tests. Memory is per process; HTTP server and test worker do not share it.
59
+
60
+ ```ts
61
+ import { secrets } from "@warlock.js/core";
62
+ import { secretsFake } from "@warlock.js/core/tests";
63
+
64
+ secretsFake.install(); // only needed without the standard test harness
65
+ try {
66
+ secretsFake.clear();
67
+ await secrets.set("vendor-token", "test-credential");
68
+ await secretsFake.assertHas("vendor-token");
69
+ await secretsFake.assertStored("vendor-token", "test-credential");
70
+ await secrets.remove("vendor-token");
71
+ await secretsFake.assertMissing("vendor-token");
72
+ const installed = secretsFake.isInstalled();
73
+ } finally {
74
+ secretsFake.restore();
75
+ }
76
+ ```
77
+
78
+ For standalone unit tests or distinct app instances:
79
+
80
+ ```ts
81
+ import { MemorySecretBackend, SecretStore } from "@warlock.js/core/secrets";
82
+ import type { SecretBackend, SecretStoreOptions } from "@warlock.js/core/secrets";
83
+
84
+ const backend: SecretBackend = new MemorySecretBackend();
85
+ const options: SecretStoreOptions = { namespace: "test-app", backend };
86
+ const store = new SecretStore(options);
87
+ await store.set("vendor-token", "test-credential");
88
+ await store.get("vendor-token");
89
+ await store.has("vendor-token");
90
+ await store.remove("vendor-token");
91
+
92
+ const memory = new MemorySecretBackend();
93
+ memory.clear();
94
+ ```
95
+
96
+ Options also allow a `directory` and `encryptionKey` (string or lazy callback); the default key reads `encryption.key` lazily. A custom `SecretBackend` implements async namespace-aware `get`, `set`, and `remove`. Explicit backends bypass keychain, environment and files; the test fake only swaps the shared facade.
97
+
98
+ ## Error and logging contract
99
+
100
+ `SecretStoreError.code` is `INVALID_NAME`, `INVALID_VALUE`, `INVALID_NAMESPACE`, `READ_ONLY`, `KEY_REQUIRED`, `UNAVAILABLE`, `UNSAFE_FILE` or `CORRUPT_FILE`. Errors never include names, values, paths or vendor causes. `KEY_REQUIRED` means provision/fix the app encryption key; `CORRUPT_FILE` means wrong key, invalid format or failed authentication. Never replace an unreadable store with an empty one.
101
+
102
+ The store never logs credentials. It registers encountered names and literal values with `@warlock.js/logger` for process-lifetime masking, including old/removed/failed-write values, interpolated messages, Error text/causes, and channel error reports. Keys and exact values stay protected even with permissive custom censors. Registration retains values in memory. It cannot mask direct console/third-party logging, earlier logs, transformed/encoded values, or credentials never encountered by the store. Keep secrets out of logs even with masking enabled. Fake assertion errors do not print values.
@@ -1,20 +1,21 @@
1
1
  ---
2
2
  name: test-fakes
3
- description: 'The test fakes Warlock installs by default in the test environment — `mailFake`, `queueFake`, `cacheFake`, `storageFake`, `clockFake`, `idsFake` — and their assertions (`assertSent`, `assertPushed`, `assertHas`, `assertExists`, `travel`), plus how to opt out (`tests.fakes`, `setupTest({ fakes })`). Triggers: `mailFake`, `queueFake`, `cacheFake`, `storageFake`, `clockFake`, `idsFake`, `installTestFakes`, `restoreTestFakes`, `tests.fakes`, `FakeAssertionError`, `clock.now`, `ids.uuid`, `setDispatchInterceptor`; "assert an email was sent", "assert a job was dispatched", "freeze time in a test", "deterministic ids", "tests without Redis", "keep the real cache driver in tests". Typical import `import { mailFake, queueFake } from "@warlock.js/core/tests"`. Skip: HTTP request helpers — the `test-http` topic; fixtures — the `model-factories` topic.'
3
+ description: 'The test fakes Warlock installs by default in the test environment — `mailFake`, `queueFake`, `cacheFake`, `storageFake`, `clockFake`, `idsFake`, `secretsFake` — and their assertions (`assertSent`, `assertPushed`, `assertHas`, `assertExists`, `travel`), plus how to opt out (`tests.fakes`, `setupTest({ fakes })`). Triggers: `mailFake`, `queueFake`, `cacheFake`, `storageFake`, `clockFake`, `idsFake`, `secretsFake`, `installTestFakes`, `restoreTestFakes`, `tests.fakes`, `FakeAssertionError`, `clock.now`, `ids.uuid`, `setDispatchInterceptor`; "assert an email was sent", "assert a job was dispatched", "freeze time in a test", "deterministic ids", "tests without Redis", "keep the real cache driver in tests". Typical import `import { mailFake, queueFake } from "@warlock.js/core/tests"`. Skip: HTTP request helpers — the `test-http` topic; fixtures — the `model-factories` topic.'
4
4
  ---
5
5
 
6
6
  # Warlock — test fakes
7
7
 
8
- In the test environment six fakes are installed for you: `setupTest()` installs them in every test file once its connectors are up, `startHttpTestServer()` installs them in the shared server, and teardown restores them. Nothing is delivered, pushed to Redis, uploaded to a bucket, and time and ids are deterministic.
8
+ In the test environment seven fakes are installed for you: `setupTest()` installs them in every test file once its connectors are up, `startHttpTestServer()` installs them in the shared server, and teardown restores them. Nothing is delivered, pushed to Redis, uploaded to a bucket, and time and ids are deterministic.
9
9
 
10
- | Fake | Replaces |
11
- | ------------- | --------------------------------------------------------------- |
12
- | `mailFake` | Mail delivery: `sendMail()` / `Mail` sends are captured |
13
- | `queueFake` | `@warlock.js/queue` dispatch: jobs are recorded, not pushed |
14
- | `cacheFake` | The cache's current driver: a fresh in-memory driver |
15
- | `storageFake` | Every storage driver (local, S3, R2, Spaces): a temp directory |
16
- | `clockFake` | `clock` from `@warlock.js/core`: frozen at 2026-01-01T00:00:00Z |
17
- | `idsFake` | `ids` from `@warlock.js/core`: numbered UUIDs and tokens |
10
+ | Fake | Replaces |
11
+ | ------------- | --------------------------------------------------------------------- |
12
+ | `mailFake` | Mail delivery: `sendMail()` / `Mail` sends are captured |
13
+ | `queueFake` | `@warlock.js/queue` dispatch: jobs are recorded, not pushed |
14
+ | `cacheFake` | The cache's current driver: a fresh in-memory driver |
15
+ | `storageFake` | Every storage driver (local, S3, R2, Spaces): a temp directory |
16
+ | `clockFake` | `clock` from `@warlock.js/core`: frozen at 2026-01-01T00:00:00Z |
17
+ | `idsFake` | `ids` from `@warlock.js/core`: numbered UUIDs and tokens |
18
+ | `secretsFake` | The `secrets` facade: namespace-aware memory, no OS/environment/files |
18
19
 
19
20
  ## Assert what your code did
20
21
 
@@ -42,7 +43,8 @@ it("queues the report, mails the requester and caches the request", async () =>
42
43
  - **queue** — `assertPushed(jobOrName, payloadSubset?)`, `assertNotPushed`, `assertPushedCount(n, job?)`, `assertNothingPushed()`, `pushed(job?, matcher?)`. Each record has `id`, `name`, `queue`, `payload`, `options` (`delay`, `priority`, `jobId`) and `pushedAt`. An explicit `jobId` stays idempotent and `job.find(id)` answers from the record. Jobs are not run — call the handler to test it.
43
44
  - **cache** — `assertHas(key)`, `assertMissing(key)`, `assertStored(key, value)` (deep equality), `driver()`, `clear()`. TTLs, tags, namespaces and locks are the real memory driver's.
44
45
  - **storage** — `assertExists(path, driver?)`, `assertMissing(path, driver?)`, `files(driver?)`, `root()`. Each configured driver name gets a folder under one temp root, shared with the HTTP test server through `WARLOCK_TEST_STORAGE_ROOT`; the process that created it deletes it.
45
- - A failed assertion throws `FakeAssertionError` listing what was recorded.
46
+ - **secrets** — async `assertHas(name)`, `assertMissing(name)`, `assertStored(name, value)`, plus `clear()` and `isInstalled()`. Assertion errors never reveal values. See `store-secrets` for examples and explicit memory stores.
47
+ - A failed assertion throws `FakeAssertionError`; secret assertions omit values. Other fakes list what was recorded.
46
48
 
47
49
  ## Time and ids
48
50
 
@@ -450,5 +450,42 @@ npm install --save-dev --save-exact typescript@6.0.3
450
450
  npx tsc --noEmit
451
451
  ```
452
452
 
453
- The same tsconfig cleanups work with TS6. ESLint mode prints a compatibility
454
- notice and is planned for deprecation in 5.33 and removal in 5.34.
453
+ The same tsconfig cleanups work with TS6. Starting in 5.33, ESLint mode prints
454
+ a deprecation warning naming removal in 5.34.0 and the Oxc migration command.
455
+
456
+ ## 5.32 to 5.33
457
+
458
+ **BREAKING:** ESLint background health checking and automatic ESLint selection
459
+ in `warlock check` are disabled by default. Oxlint/Oxfmt replace ESLint/Prettier
460
+ as the default toolchain. Legacy support is deprecated now and removed in
461
+ 5.34.0. Temporary opt-ins are `devServer.healthCheckers: { eslint: true }`,
462
+ `warlock check --lint eslint`, and `create-warlock --lint=eslint`; each warns
463
+ about removal and migration. The legacy scaffold stays on TypeScript 6.0.3;
464
+ Oxc apps use TypeScript 7.0.2.
465
+
466
+ ESLint + Prettier are deprecated in 5.33.0 and will be removed in **5.34.0**.
467
+ New apps should use `--lint=oxc`. To migrate an existing app, install the new
468
+ core release and `ts-morph`, then run:
469
+
470
+ ```bash
471
+ npx warlock upgrade --from 5.32 --to 5.33.0 --dry-run
472
+ npx warlock upgrade --from 5.32 --to 5.33.0
473
+ npm install
474
+ npm run format
475
+ npm run lint:check
476
+ npx warlock check
477
+ ```
478
+
479
+ Review every reported `file:line`: customized configs are preserved and need
480
+ manual translation before removal. The codemod installs the template's Oxlint
481
+ and Oxfmt versions and pins TypeScript to 7.0.2. It replaces standard lint/format
482
+ scripts, removes legacy dependencies, and deletes only recognized generated
483
+ configs. A generated `.prettierignore` becomes `.oxfmtignore`. Existing Oxc
484
+ configs are preserved. `--dry-run --json` reports the same planned changes
485
+ without writing files.
486
+
487
+ The `oxc-toolchain` codemod also updates generated VS Code settings and literal
488
+ ESLint/Oxlint health-check switches. Custom editor settings, checker arrays,
489
+ computed options and nonstandard scripts require review. Oxc diagnostics keep
490
+ framework conventions in `warlock check`. Re-run the migration after addressing
491
+ manual findings if needed; an app with only Oxc tooling is a no-op for this codemod.
@@ -120,7 +120,7 @@ const types = runTypecheck({ files: ["src/app/posts/services/publish.service.ts"
120
120
  ## Gotchas
121
121
 
122
122
  - `check` boots nothing — no config, no connection, no port — so it runs the same with or without services; only tests that need them fail, and those report `WL8003`/`WL8004`.
123
- - Lint runs only the linters the app configures (`eslint.config.*`; an oxlint config + the `oxlint` package). No config → the step is skipped, not failed.
123
+ - Lint defaults to Oxlint (an app-root config + the app-installed package). No Oxlint config skips lint. A missing package reports `WL8002`. ESLint requires `--lint eslint` (or `runCheck({ lint: "eslint" })`); its flat config alone never enables it. This deprecated selection prints one warning on stderr and is removed in 5.34.0.
124
124
  - Tests use the app's own vitest (`vitest run`, or `vitest related <files> --run` with `--changed`). Test files without vitest installed → `WL8002`.
125
125
  - The typecheck runs in a child `warlock typecheck` process; running out of memory is reported as `WL8007` instead of ending the run.
126
126
  - The convention checks are the framework's own and run the same with ESLint, Oxlint or no linter. A deliberate exception gets `// warlock-check-ignore WL9006 -- why` on the problem's line or the line above (no code = every code on that line).
@@ -131,3 +131,7 @@ const types = runTypecheck({ files: ["src/app/posts/services/publish.service.ts"
131
131
  - The `warlock-doctor` topic — boot-time diagnostics; `doctor --json` uses the same codes and fields.
132
132
  - The `warlock-inspect` topic — the app's routes, models and config as JSON.
133
133
  - The `warlock-conventions` topic — the rules behind `WL9001`–`WL9012`, with the fix for each.
134
+
135
+ Migrate lint and format tooling with
136
+ `npx warlock upgrade --from 5.32 --to 5.33.0 --dry-run`, then remove `--dry-run`
137
+ and work through the manual-review list. Use `--lint=oxc` for new apps.
@@ -169,3 +169,12 @@ A `⚠ routes: 0 routes registered` line is the tell that a route module threw o
169
169
  - The `warlock-conventions` topic — project layout the checks assume.
170
170
  - The `warlock-check` topic — `warlock check` / `typecheck` / `explain` and the error-code registry the findings use.
171
171
  - The `warlock-inspect` topic — `warlock inspect`, the same boot pass printed as a versioned JSON report of the app.
172
+
173
+ ## Lint and format checks
174
+
175
+ `warlock doctor` checks application wiring and HTTP health probes. Use
176
+ `npx warlock check` for source lint diagnostics and `npm run format:check` for
177
+ formatting. In 5.33, Oxlint/Oxfmt are the defaults; ESLint requires
178
+ `warlock check --lint eslint` or `devServer.healthCheckers.eslint: true` for
179
+ background checks. ESLint/Prettier are deprecated and removed in 5.34.0.
180
+ Migrate with `npx warlock upgrade --from 5.32 --to 5.33.0` (preview with `--dry-run`).
@@ -113,6 +113,25 @@ Reading `app.socket` (or `getSocketServer()`) at the top level of `main.ts` retu
113
113
 
114
114
  ## Emitting from a controller or service
115
115
 
116
+ Use `broadcastSocketEvent` when a framework integration should tolerate an
117
+ absent connector and broadcast through the configured adapter:
118
+
119
+ ```ts
120
+ import { broadcastSocketEvent } from "@warlock.js/core";
121
+
122
+ const dispatched = broadcastSocketEvent("inventory:changed", { tags: ["products"] });
123
+ // false without a booted socket server; true means dispatched, not delivered.
124
+ ```
125
+
126
+ This broadcasts to all default-namespace clients, so payloads must be public.
127
+ It uses `io.emit` (not `io.local.emit`), allowing `socket.adapter` to forward to
128
+ other app processes. Each publisher, including a queue/CLI process, must boot
129
+ the socket connector with the same adapter. See Socket.IO's official
130
+ [Redis adapter](https://socket.io/docs/v4/redis-adapter/) and
131
+ [multiple-node guidance](https://socket.io/docs/v4/using-multiple-nodes/).
132
+ Web's `invalidatePageCache(tags)` uses this path for opt-in `config.live` pages;
133
+ shared cache storage is also required when evicting across processes.
134
+
116
135
  Once the server is up, anything with access to `app.socket` can emit:
117
136
 
118
137
  ```ts title="src/app/notifications/services/notify-user.service.ts"
@@ -221,6 +221,7 @@ warlock generate (alias: g) — interactive picker
221
221
  | `postman` | `@warlock.js/postman` |
222
222
  | `herald` | `@warlock.js/herald` + `amqplib` + types; ejects `src/config/communicator.ts` |
223
223
  | `test` | `vitest` + `@mongez/vite` + coverage; drops `test-global-setup.ts` / `test-setup.ts` / `vite.config.ts` |
224
+ | `process` | `@warlock.js/process` pinned to installed Core; typed config, supervisor export, recovery/shutdown lifecycle and optional devtools process panel |
224
225
  | `devtools` | `@warlock.js/devtools` as a dev dependency; `warlock dev` auto-loads its development dashboard at `/__warlock` |
225
226
 
226
227
  Run `warlock add --list` to see what's currently registered. Pass `--packageManager <yarn\|pnpm\|npm>` to override auto-detection (defaults to whichever lockfile is present).
@@ -231,6 +232,10 @@ production install with dev dependencies excluded.
231
232
 
232
233
  The Web starter keeps the page's universal non-component setup in `src/web/index.register.ts`, while `src/web/index.page.tsx` re-exports `register`. Warlock still discovers and runs the hook from the page namespace in both SSR and the browser, but editing the page component remains inside React's Fast Refresh boundary. Do not move the `register()` declaration inline beside the component: React Refresh treats that non-component export as incompatible and reloads the page, losing component state.
233
234
 
235
+ ### AI input measurement
236
+
237
+ `warlock ai measure --model <id> [--tools <module>] [--system <file>] [--skills <dir>] [--json]` loads `@warlock.js/ai` lazily without app bootstrap. Model IDs default to OpenAI Responses or use `openai:`, `anthropic:`, `google:` prefixes and the corresponding installed adapter/environment API key. `--model-module <module>` accepts `model`, `default`, or `resolveModel(id)` for custom providers/prices. Tools modules export a `tools` or default array; paths resolve from cwd. The report breaks down messages, system, skills catalogue, and tools, labels native counts versus estimates, and includes uncached input USD only when priced. CLI reports include an explicit `.` user probe and do not preload skill bodies or add skill tools. JSON stdout contains one report. No CLI config registration is required.
238
+
234
239
  ### Misc
235
240
 
236
241
  | Command | Purpose |
@@ -314,3 +319,19 @@ export default command({
314
319
  - The `run-app` topic — the operational commands (`dev` / `build` / `start`) with all flags and config knobs.
315
320
  - The `configure-app` topic — wiring `defineConfig` and `warlock.config.ts`.
316
321
  - The `warlock-conventions` topic — module layout, canonical imports.
322
+
323
+ ## App-owned processes
324
+
325
+ `npx warlock add process` creates typed `src/config/process.ts` (owner, registry,
326
+ default limits), `src/app/processes/index.ts` (the `processes` supervisor export),
327
+ lifecycle hooks, and a read-only devtools list source. It imports lifecycle from
328
+ `src/app/main.ts`. Startup awaits `recover()` using `Application.onValidateBoot`;
329
+ graceful shutdown awaits `stopAll()` using `Application.onShutdown`. Recovery
330
+ failure aborts boot. Repeated installation preserves existing files.
331
+
332
+ Set a unique owner and registry per app instance, then import `processes` from
333
+ the generated module and await `processes.spawn({ kind: "worker", command,
334
+ args, labels })`. Consume output and await `handle.exited`. Use handle stops or
335
+ label filters; never stop processes by command or name. `spawnPty()` lazily
336
+ loads separately installed optional peer `node-pty`. The `supervise-processes`
337
+ skill in `@warlock.js/process` contains complete working examples.