@webjsdev/cli 0.10.72 → 0.10.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjsdev/cli",
3
- "version": "0.10.72",
3
+ "version": "0.10.73",
4
4
  "type": "module",
5
5
  "description": "The CLI for WebJs, a full-stack JavaScript framework built on web components with server-side rendering and no build step. Runs the dev and production servers, scaffolds apps, validates conventions, and drives the database. Node 24+ or Bun.",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "README.md"
18
18
  ],
19
19
  "dependencies": {
20
- "@webjsdev/mcp": "^0.1.16",
20
+ "@webjsdev/mcp": "^0.1.17",
21
21
  "@webjsdev/server": "^0.8.89",
22
22
  "@webjsdev/ui": "^0.3.15"
23
23
  },
@@ -8,30 +8,12 @@ Read `AGENTS.md` first. Full hosted docs are at https://webjs.dev/docs.
8
8
 
9
9
  ## Grow the app in place (non-negotiable)
10
10
 
11
- - **Study the shipped examples, then clear them and build.** The scaffold is a
12
- starting point with a browsable showcase to learn the real idioms from, plus a
13
- database wired up. A full-stack app ships a UI feature gallery (`app/features/`,
14
- `app/examples/todo`); the api template ships a backend-features showcase
15
- (`app/api/features/`), with logic in `modules/`. Building a real app: study the
16
- parts that match your task (the skill teaches the same and SURVIVES the clear),
17
- run `npm run gallery:clear` to shed the showcase (it keeps the agent skill and
18
- the database wiring, and resets to a clean base), then regenerate the database
19
- and grow the app in place under `app/`, `components/`, and `modules/<feature>/`.
20
- `AGENTS.md` carries the full template-specific build playbook and the order to
21
- follow.
22
- - **Use the wired-up database (Drizzle), never JSON files.** For any data the app
23
- stores, define a Drizzle table in `db/schema.server.ts`, then
24
- `npm run db:generate` and `npm run db:migrate`. Never use a JSON file, a
25
- module-scope array or Map, or localStorage as a database.
26
- - **`app/` is routing-only.** Only routing files live in `app/` (page, layout,
27
- route, middleware, metadata routes). Browser-safe helpers go in `lib/utils/`,
28
- feature logic in `modules/`, server-only code behind `.server.ts`.
29
- - **For a UI app, render and LOOK before calling it done.** Define design tokens
30
- in `app/layout.ts` with a palette that fits the app
31
- (`.agents/skills/webjs/references/styling.md` is the guide), then open every
32
- route you changed in a real browser and play through its states.
33
- `npm run check` and `npm run typecheck` pass even when a layout collapses, so
34
- the browser is the real check.
11
+ Study the shipped showcase (a full-stack app's UI gallery under
12
+ `app/features/` and `app/examples/todo`, the api template's
13
+ `app/api/features/`), run `npm run gallery:clear`, then grow the app in place
14
+ under `app/`, `components/`, and `modules/<feature>/`. `AGENTS.md` carries the
15
+ build order, the data rule (the wired-up Drizzle database, never JSON files),
16
+ and the browser check for a UI app.
35
17
 
36
18
  ## Before starting ANY work
37
19
 
@@ -104,12 +104,12 @@ Common bundles:
104
104
  1. **Classify the change.** Route contract, data model, server mutation, auth, or only UI?
105
105
  2. **Start from the server.** Add the page/route and its server action or query before wiring interactive UI. A page render or a `<form>` POST should already return correct HTML before any component hydrates.
106
106
  3. **Put code in the narrowest owner.** Route-local first (`modules/<feature>/`), promote to `lib/` or `components/` only when reuse is real.
107
- 4. **Keep server-only code behind `.server.ts`.** The DB driver, secrets, and `node:*` never belong in a page, layout, or component.
107
+ 4. **Keep server-only code behind `.server.ts`** (Core WebJs Rules 1 and 2).
108
108
  5. **Add interactivity per behaviour.** Reach for a component (and a signal or `@event`) only where the UI is genuinely interactive. A display-only component is elided from the browser. Then wrap the interactive part and STOP: the static markup around it stays in the page, where it costs nothing.
109
109
  6. **Validate input at the boundary.** Declare `export const validate` on an action; the RPC and `route()` boundaries run it.
110
110
  7. **Default mutations to optimistic UI** where the client can predict the result (`optimistic()` from `@webjsdev/core`).
111
- 8. **Type every boundary from its source, never `unknown` or `any`.** The row type comes from the schema (`typeof todos.$inferSelect`), the action's input from a named `interface` and its result from `ActionResult<T>`, the routing files from `PageProps` / `LayoutProps` / `RouteHandlerContext`. `unknown` belongs on a payload nothing has vouched for yet that the next line narrows, and on a parameter of your own helper that forwards into an `html` template hole. Everywhere else, including a layout's `children`, it is a missing type. See `references/typescript.md`.
112
- 9. **Test the narrowest meaningful layer**, and render the app in a real browser for any UI change (static checks do not catch a collapsed layout).
111
+ 8. **Type every boundary from its source, never `unknown` or `any`.** The row type comes from the schema (`typeof todos.$inferSelect`), the action's input from a named `interface` and its result from `ActionResult<T>`, the routing files from `PageProps` / `LayoutProps` / `RouteHandlerContext`. `unknown` belongs on a payload nothing has vouched for yet that the next line narrows, and on a parameter of your own helper that forwards into an `html` template hole. Everywhere else, including a layout's `children`, it is a missing type. Carry a row type into a shipping component with `import type` (erased before the browser sees it). Nothing enforces this (both spellings are valid TypeScript, so `webjs check` and `tsc` pass either way), which is why it is written down. See `references/typescript.md`.
112
+ 9. **Test the narrowest meaningful layer**, and look at any UI change in a real browser (see Testing Defaults).
113
113
 
114
114
  ## Project Layout
115
115
 
@@ -137,7 +137,7 @@ App-internal imports use the `#` root alias (`import { db } from '#db/connection
137
137
  ## Core WebJs Rules (invariants)
138
138
 
139
139
  1. Server-only code lives in `.server.ts`, `route.ts`, or `middleware.ts`. Never in a page, layout, or component (it crashes the browser at module load).
140
- 2. `'use server'` exports are `async` functions returning serializer-safe values. Files without `'use server'` are server-only utilities.
140
+ 2. `'use server'` exports are `async` functions returning serializer-safe values, callable from browser code as RPC. Files without `'use server'` are server-only utilities: reach them only from `'use server'` actions, `route.ts`, or middleware. Never add `'use server'` to a file only other server code imports (the DB connection, the schema).
141
141
  3. Custom element tag names contain a hyphen. Pass the tag to `Class.register('tag-name')`.
142
142
  4. Event (`@`), property (`.`), and boolean (`?`) holes in `html` are UNQUOTED: `@click=${fn}`, never `@click="${fn}"`.
143
143
  5. Signals are the default state primitive. Import `signal` / `computed` from `@webjsdev/core`, read via `signal.get()` inside `render()`. The base-class factory `WebComponent({ ... })` is only for values riding an HTML attribute or arriving via SSR hydration.
@@ -147,7 +147,7 @@ App-internal imports use the `#` root alias (`import { db } from '#db/connection
147
147
  9. No backtick characters inside an `html\`...\`` body, even in comments (it closes the literal and 500s).
148
148
  10. TypeScript must be erasable (`erasableSyntaxOnly: true`): no `enum`, no value `namespace`, no constructor parameter properties, no legacy decorators.
149
149
  11. Reactive properties are declared ONLY through the base-class factory `extends WebComponent({ count: Number })`. Never a `static properties` block, never a class-field initializer (it clobbers the reactive accessor).
150
- 12. A form that writes binds its action: `<form action=${importedAction}>`, or a per-button `<button formaction=${importedAction}>`. A bound submitter is SELF-SUFFICIENT (#1307): the renderer puts `formmethod="post"` and `formenctype` on the button itself, so it needs no bound form around it and works inside any form or none. Quoted bindings, non-submit controls, `<input type="submit">` (the identity needs its `value`, which is also its label, so use a `<button>`), submitter `name` / `value` / `form` / static `formaction` attributes, a `.prop` spelling of any of those, `action=${fn}` off a `<form>`, a bound form with `method="get"`, a BOUND submitter's own non-post `formmethod` or unparseable `formenctype`, and a non-action function all throw. A PLAIN button's own `formmethod` / `formenctype` is a legal native override and is left alone. A page has no `action` export, so a bare `<form method="post">` is a 405.
150
+ 12. A form that writes binds its action: `<form action=${importedAction}>`, or a per-button `<button formaction=${importedAction}>`. A bound submitter is SELF-SUFFICIENT (#1307): the renderer puts `formmethod="post"` and `formenctype` on the button itself, so it needs no bound form around it and works inside any form or none. Quoted bindings, non-submit controls, `<input type="submit">` (the identity needs its `value`, which is also its label, so use a `<button>`), submitter `name` / `value` / `form` / static `formaction` attributes (the identity IS the button's name/value pair, so both halves are spoken for), a `.prop` spelling of any of those, `action=${fn}` off a `<form>`, a bound form with `method="get"` (a GET sends no body for the action to read), a BOUND submitter's own non-post `formmethod` or unparseable `formenctype`, and a non-action function all throw. A PLAIN button's own `formmethod` / `formenctype` is a legal native override and is left alone. A page has no `action` export, so a bare `<form method="post">` is a 405.
151
151
 
152
152
  ## Export Map
153
153
 
@@ -272,18 +272,12 @@ Success is a 303 (PRG); failure re-renders the page at 422 with the result on `a
272
272
 
273
273
  ## Common Mistakes To Avoid
274
274
 
275
- - Treating a page or layout like a React component and expecting its markup to hydrate. It runs server-only; put interactivity in a component.
275
+ The invariants above are not repeated here; this list is the mistakes they do not already name.
276
+
276
277
  - Promoting a whole page section to a component so that one control inside it can be interactive. The island should wrap the control and the state it reads. An oversized island ships its own JS AND un-elides every display-only component inside it, so the cost is not linear in what you moved.
277
- - Importing a `.server.ts` utility (no `'use server'`) directly into a shipping component. Its browser stub throws at load; reach it through a `'use server'` action.
278
- - Using a `static properties` block or a class-field initializer for reactive props instead of the `WebComponent({ ... })` factory.
279
- - Quoting an event / property / boolean hole (`@click="${fn}"`).
280
278
  - Writing `fetch()` to call your own server instead of importing the action.
281
- - Writing a bare `<form method="post">` and expecting a page `action` export to catch it. There is no such export; bind the action with `action=${fn}` or the submission is a 405.
282
- - Putting a submitter's `formaction=${fn}` on anything that is not a submit control, or on a button carrying its own `name` / `value`. The identity IS the button's name/value pair, so both halves are spoken for.
283
- - Writing `formmethod="get"` or `formenctype="text/plain"` on a button that BINDS an action. Neither can carry that action's body, so the pair contradicts itself and throws. On a button that binds nothing it is a legal native override and is honoured.
284
279
  - Binding an action whose file declares `export const method = 'GET'`. Form-bound actions strictly require POST (default). Binding a GET action to a form is a 405 at runtime and a `webjs check` error (`form-action-not-a-get-action`).
285
280
  - Leaving read-only RPC server query actions as default `POST`. Always export `export const method = 'GET'` for RPC data queries so arguments ride URL params, ETags/304 caching work, and CSRF is safely bypassed.
286
- - Writing `method="get"` on a bound `<form action=${fn}>`. WebJs supplies `method="post"` and `formenctype` automatically, and a bound form declaring `method="get"` is REFUSED at render (a thrown error, not a warning), because a GET sends no body for the action to read.
287
281
  - Throwing `redirect()` / `notFound()` inside a `route.ts` handler (uncaught 500). Return a `Response` there.
288
282
  - A placeholder first paint that fetches in `connectedCallback`. SSR does not call `connectedCallback`; put first-paint data in the constructor (server-known inputs) or use `async render()`.
289
283
  - A browser global (`window`, `document`, `localStorage`) in the constructor or `render()`. It throws at SSR; do browser-only work in `connectedCallback`.
@@ -34,49 +34,23 @@ This is what separates a working app from a broken one.
34
34
 
35
35
  ## Type everything (all templates)
36
36
 
37
- Full-stack type safety is what the `.server.ts` boundary buys you: a client
38
- component importing a server action resolves to that action's real signature at
39
- type-check time, with no build step and no code generation in between. So
40
- DERIVE the type at every boundary instead of widening it:
37
+ Derive the type at every boundary from its source. Never reach for `any`, and
38
+ never `unknown` where a real type exists. The rule is step 8 of the skill's "Default
39
+ Workflow"; the forms to reach for:
41
40
 
42
- - A database row: `export type Todo = typeof todos.$inferSelect` in
43
- `db/schema.server.ts` (`$inferInsert` for a write), carried into a
44
- browser-shipped component with `import type` (erased before it reaches the
45
- browser, so it does not trip the server-import boundary).
41
+ - A database row: `typeof table.$inferSelect` (`$inferInsert` for a write),
42
+ carried into a shipping component with `import type`.
46
43
  - An action's input: a named `interface`. Its result: `ActionResult<T>`.
47
- Narrow with `if (result.success && result.data)`.
48
44
  - Routing files: `PageProps<'/blog/[slug]'>`, `LayoutProps`,
49
- `RouteHandlerContext`, all from `@webjsdev/core`. Run `npx webjsdev types`
50
- for the typed `Route` union and per-route `params`.
45
+ `RouteHandlerContext`. `npx webjsdev types` writes the typed `Route` union.
51
46
  - A reactive property: `prop<Student>(Object)`, `prop<Tag[]>(Array)`.
52
47
 
53
- Never reach for `any` or a loose `as any` cast, and do not reach for `unknown`
54
- either just because it looks safer. `unknown` is right for a payload nothing
55
- has vouched for yet, narrowed on the very next line (a `route.ts` `await
56
- req.json()`, an action's `export const validate` or a validator it delegates
57
- to, a `catch` binding), and for a parameter of YOUR OWN helper that forwards
58
- into an `html` template hole (a hole renders a string, a number, a
59
- `TemplateResult`, or an array of those, so `TemplateResult` alone is too
60
- narrow). That second case is about a value you accept, never one the framework
61
- already types. Everywhere else it is a missing type, not a safe one: `unknown`
62
- that survives into a return type, a component prop, a layout's `children`, or
63
- an action signature is the shape to fix.
64
- Nothing enforces this (both are valid TypeScript, so `webjs check` and `tsc`
65
- pass either way), which is exactly why it is written down. The full ladder,
66
- with an end-to-end example, is in
48
+ The full ladder, with an end-to-end example, is
67
49
  `.agents/skills/webjs/references/typescript.md`.
68
50
 
69
51
  Keep server-only code (database drivers, secrets, `node:*` builtins) in
70
- `.server.ts` modules. There are exactly two kinds:
71
-
72
- - A `.server.ts` file WITH `'use server';` as its first line is a server
73
- action: WebJs exposes its exported async functions to browser code as RPC
74
- calls, so browser modules may import it directly.
75
- - A `.server.ts` file WITHOUT `'use server'` is a server-only utility:
76
- importing it from a page, layout, or component CRASHES in the browser at
77
- module load. Reach it only from `'use server'` actions, `route.ts` handlers,
78
- or middleware. Never add `'use server'` to a file only other server code
79
- imports (the DB connection, the schema).
52
+ `.server.ts` modules. The two kinds (with and without `'use server'`) are the
53
+ skill's "Core WebJs Rules" 1 and 2.
80
54
 
81
55
  ## Data (all templates)
82
56
 
@@ -9,14 +9,9 @@ is complete, WITHOUT being asked. Do not save all the work for one commit at the
9
9
  end. A finished implementation with zero commits is a mistake here, because git
10
10
  history is the user's revert and cherry-pick safety net.
11
11
 
12
- - After each completed unit whose tests pass, `git add` the related files and
13
- `git commit` with an imperative subject under 72 chars, then push. If 5+ files
14
- span more than one concern, you already waited too long.
15
- - Never commit to `main`. Work on a feature branch (the
16
- `.claude/hooks/guard-branch-context.sh` hook enforces this).
17
- - No AI-attribution trailers (`Co-Authored-By`, `Generated by`).
18
-
19
- See AGENTS.md "Git workflow" for the full contract. Two hooks back this up: the
12
+ The full git contract (branches, commit messages, attribution) is
13
+ `.agents/rules/workflow.md` "Git rules"; the
14
+ `.claude/hooks/guard-branch-context.sh` hook refuses a commit on `main`. Two hooks back this up: the
20
15
  `.claude/hooks/nudge-uncommitted.sh` PostToolUse hook reminds you while
21
16
  uncommitted changes pile up during work, and the
22
17
  `.claude/hooks/commit-before-stop.sh` Stop hook stops you from ending a turn
@@ -3,34 +3,16 @@
3
3
  The conventions for building a WebJs app live in the agent skill. **Read
4
4
  `AGENTS.md` first, then `.agents/skills/webjs/SKILL.md`** (it routes to focused
5
5
  references under `.agents/skills/webjs/references/`, loaded on demand). This file
6
- is the short version.
6
+ only says where each rule lives, so no rule is stated twice.
7
7
 
8
- ## The essentials
9
-
10
- - **`app/` is routing only.** Only routing files live there (page, layout, route,
11
- middleware, metadata routes). Feature logic goes in `modules/<feature>/`
12
- (`actions/`, `queries/`, `components/`, `utils/`); shared UI primitives go in
13
- top-level `components/`; browser-safe helpers in `lib/utils/`.
14
- - **Server-only code goes behind `.server.ts`.** Reach it from a page or component
15
- through a `'use server'` action, never by importing a server-only utility
16
- directly into browser-bound code.
17
- - **Use the wired-up database (Drizzle).** Define real models in
18
- `db/schema.server.ts`, then `npm run db:generate` and `npm run db:migrate`.
19
- Never persist to a JSON file, an in-memory array or Map, or localStorage.
20
- - **The scaffold ships a showcase to learn from.** A full-stack app ships a UI
21
- feature gallery (`app/features/`, `app/examples/todo`); the api template ships
22
- a backend-features showcase (`app/api/features/`), with logic in `modules/`.
23
- When you build a real app, study the parts that match your task (the skill
24
- teaches the same and survives the clear), run `npm run gallery:clear` to shed
25
- the showcase, then grow the app in place. `AGENTS.md` has the full
26
- template-specific playbook.
27
- - **Derive types at every boundary.** Rows from `$inferSelect`, action inputs
28
- from an `interface`, routing files from `PageProps` / `LayoutProps`. Never
29
- `any`, and never `unknown` where a real type exists.
30
- - **Progressive enhancement is the default.** Pages render as HTML, `<a>`
31
- navigates, a `<form action=${importedAction}>` submits, all with JavaScript off; opt into
32
- interactivity per behaviour inside a component.
33
- - **Commit per logical unit** as soon as it is complete, and never push to `main`.
34
-
35
- Everything else (the module architecture, the `ActionResult` envelope, styling,
36
- testing, the client router, optimistic UI) is in the skill's references.
8
+ - **Build order** (study the showcase: a full-stack app's gallery under
9
+ `app/features/` and `app/examples/todo`, the api template's
10
+ `app/api/features/`; then `npm run gallery:clear`, data, UI, verify):
11
+ the playbook in `AGENTS.md`.
12
+ - **Data** (the wired-up Drizzle database, never a JSON file, an in-memory
13
+ array or Map, or localStorage): `AGENTS.md`, "Data".
14
+ - **Layout** (`app/` is routing only, logic in `modules/<feature>/`): the
15
+ skill's "Project Layout".
16
+ - **Server boundary, progressive enhancement, typing**: the skill's "What WebJs
17
+ Is", "Core WebJs Rules", and "Default Workflow".
18
+ - **Git, tests, and `npm run ci`**: `.agents/rules/workflow.md`.
@@ -44,20 +44,12 @@ cross-origin access use the `cors()` middleware from `@webjsdev/server`; with
44
44
 
45
45
  ### 5. Verify before you call it done
46
46
 
47
- Run `npm run ci` and fix what it reports. It is one command for every gate,
48
- the step list declared in `package.json` under `webjs.ci`, with a result line
49
- per step:
50
-
51
- - `webjs check` (correctness: no browser-import or boundary violation).
52
- - `webjs doctor` (project health). It fails on whatever `package.json`
53
- `webjs.doctor.gate` marks `error`, plus the two hard toolchain checks that
54
- are fatal with no gate entry, `NODE_VERSION` and `TSCONFIG_ERASABLE`.
55
- - `webjs typecheck` (zero type errors).
56
- - A dependency audit.
57
- - The test layers for the endpoints and modules you built.
58
-
59
- The GitHub workflow runs the same list, so a green local run predicts CI.
60
- While iterating, `npm run ci -- --only Tests` runs one layer.
47
+ Run `npm run ci` and fix what it reports. It runs every gate declared under
48
+ `webjs.ci` in `package.json` (`webjs check`, `webjs doctor`, `webjs typecheck`,
49
+ a dependency audit, then the test layers for the endpoints and modules you
50
+ built), and the GitHub workflow runs the
51
+ same list; `.agents/rules/workflow.md` has what each gate checks. While
52
+ iterating, `npm run ci -- --only Tests` runs one layer.
61
53
 
62
54
  Then boot `npm run dev` and probe each endpoint for the expected status and JSON
63
55
  shape.
@@ -84,31 +84,21 @@ action without also triggering the row navigation.
84
84
 
85
85
  ### 6. Build components for interactivity
86
86
 
87
- Pages and layouts (`app/**/page.ts`, `app/**/layout.ts`) are server-only HTML
88
- generators, so put every interactive behavior inside a `WebComponent` custom
89
- element. Declare a component's reactive properties in the base-class factory,
90
- never as a class-field initializer (`items = []` clobbers the reactive
91
- accessor). Use the shorthand for primitives
87
+ Pages and layouts never hydrate, so put every interactive behavior inside a
88
+ `WebComponent` custom element, and declare its reactive properties only in the
89
+ base-class factory (the skill's "Core WebJs Rules" 11). Use the shorthand for primitives
92
90
  (`extends WebComponent({ name: String, count: Number, open: Boolean })`) and the
93
91
  `prop<T>()` helper for typed objects and arrays
94
92
  (`extends WebComponent({ items: prop<Item[]>(Array), user: prop<User>(Object) })`).
95
93
 
96
94
  ### 7. Verify before you call it done
97
95
 
98
- Run `npm run ci` and fix what it reports. It is one command for every gate,
99
- the step list declared in `package.json` under `webjs.ci`, with a result line
100
- per step:
101
-
102
- - `webjs check` (correctness: no browser-import or boundary violation).
103
- - `webjs doctor` (project health). It fails on whatever `package.json`
104
- `webjs.doctor.gate` marks `error`, plus the two hard toolchain checks that
105
- are fatal with no gate entry, `NODE_VERSION` and `TSCONFIG_ERASABLE`.
106
- - `webjs typecheck` (zero type errors).
107
- - A dependency audit.
108
- - The server, browser, and e2e test layers for the features you built.
109
-
110
- The GitHub workflow runs the same list, so a green local run predicts CI.
111
- While iterating, `npm run ci -- --only Tests` runs one layer. Then
96
+ Run `npm run ci` and fix what it reports. It runs every gate declared under
97
+ `webjs.ci` in `package.json` (`webjs check`, `webjs doctor`, `webjs typecheck`,
98
+ a dependency audit, then the server, browser, and e2e test layers for the
99
+ features you built), and the GitHub workflow runs the
100
+ same list; `.agents/rules/workflow.md` has what each gate checks. While
101
+ iterating, `npm run ci -- --only Tests` runs one layer. Then
112
102
  `npm run css:build` (compile Tailwind).
113
103
 
114
104
  Then boot `npm run dev`, confirm every page route returns HTTP 200, and open