@kerf-js/cli 0.0.0-stage → 0.1.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 (176) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +554 -2
  3. package/bin/kerf.mjs +15 -0
  4. package/docs/async.md +50 -0
  5. package/docs/browser.md +53 -0
  6. package/docs/config.md +127 -0
  7. package/docs/core.md +30 -0
  8. package/docs/deploy.md +108 -0
  9. package/docs/design.md +106 -0
  10. package/docs/entrypoints.md +83 -0
  11. package/docs/fonts.md +118 -0
  12. package/docs/icons.md +108 -0
  13. package/docs/lists.md +25 -0
  14. package/docs/meta.md +92 -0
  15. package/docs/plugins.md +166 -0
  16. package/docs/props.md +88 -0
  17. package/docs/reactivity.md +26 -0
  18. package/docs/rules.md +39 -0
  19. package/docs/rust.md +253 -0
  20. package/docs/start-short.md +10 -0
  21. package/docs/start.md +642 -0
  22. package/docs/state.md +122 -0
  23. package/docs/style.md +82 -0
  24. package/docs/surface.md +158 -0
  25. package/docs/testing.md +81 -0
  26. package/docs/theme.md +263 -0
  27. package/docs/ui-state.md +105 -0
  28. package/docs/verify.md +61 -0
  29. package/package.json +47 -3
  30. package/src/add/config.mjs +93 -0
  31. package/src/add/errors.mjs +2 -0
  32. package/src/add/setup.mjs +88 -0
  33. package/src/add-rust.mjs +178 -0
  34. package/src/add.mjs +392 -0
  35. package/src/agents-md.mjs +240 -0
  36. package/src/alias.mjs +70 -0
  37. package/src/audit/page.mjs +313 -0
  38. package/src/audit/report.mjs +69 -0
  39. package/src/audit/utils.mjs +5 -0
  40. package/src/audit.mjs +319 -0
  41. package/src/browser/cli.mjs +53 -0
  42. package/src/browser/client.mjs +299 -0
  43. package/src/browser/commands.mjs +258 -0
  44. package/src/capture.mjs +21 -0
  45. package/src/catalog/audit.mjs +129 -0
  46. package/src/catalog/auth.mjs +40 -0
  47. package/src/catalog/compiler.mjs +337 -0
  48. package/src/catalog/contracts.mjs +18 -0
  49. package/src/catalog/database.mjs +52 -0
  50. package/src/catalog/deploy.mjs +117 -0
  51. package/src/catalog/design.mjs +159 -0
  52. package/src/catalog/forms.mjs +25 -0
  53. package/src/catalog/hydration.mjs +29 -0
  54. package/src/catalog/icons.mjs +24 -0
  55. package/src/catalog/media.mjs +163 -0
  56. package/src/catalog/metadata.mjs +116 -0
  57. package/src/catalog/plugins.mjs +228 -0
  58. package/src/catalog/realtime.mjs +195 -0
  59. package/src/catalog/rust.mjs +75 -0
  60. package/src/catalog/server-functions.mjs +100 -0
  61. package/src/catalog/state.mjs +39 -0
  62. package/src/catalog/style-groups.mjs +54 -0
  63. package/src/catalog/tests.mjs +127 -0
  64. package/src/catalog/text.mjs +200 -0
  65. package/src/catalog/ui-state.mjs +42 -0
  66. package/src/catalog.mjs +103 -0
  67. package/src/check/runtime.mjs +280 -0
  68. package/src/check.mjs +321 -0
  69. package/src/cli/authoring.mjs +213 -0
  70. package/src/cli/project.mjs +302 -0
  71. package/src/cli.mjs +340 -0
  72. package/src/config.d.ts +1 -0
  73. package/src/config.mjs +5 -0
  74. package/src/contributions.mjs +119 -0
  75. package/src/db-layer.mjs +41 -0
  76. package/src/deploy/cdn.mjs +142 -0
  77. package/src/deploy/files.mjs +266 -0
  78. package/src/deploy/fit.mjs +166 -0
  79. package/src/deploy/hosts.mjs +126 -0
  80. package/src/deploy/index/cli.mjs +20 -0
  81. package/src/deploy/index/environment.mjs +69 -0
  82. package/src/deploy/index/steps.mjs +87 -0
  83. package/src/deploy/index.mjs +387 -0
  84. package/src/deploy/needs.mjs +149 -0
  85. package/src/design-checks/accessible-names.mjs +62 -0
  86. package/src/design-checks/contrast.mjs +43 -0
  87. package/src/design-checks/csp.mjs +60 -0
  88. package/src/design-checks/files.mjs +59 -0
  89. package/src/design-checks/heading-links.mjs +61 -0
  90. package/src/design-checks/interaction.mjs +65 -0
  91. package/src/design-checks/jsx.mjs +67 -0
  92. package/src/design-checks/layout-values.mjs +68 -0
  93. package/src/design-checks/native-controls.mjs +48 -0
  94. package/src/design-checks/outline.mjs +39 -0
  95. package/src/design-checks/reporter.mjs +37 -0
  96. package/src/design-checks/rules.mjs +274 -0
  97. package/src/design-checks/values.mjs +262 -0
  98. package/src/design-checks.mjs +49 -0
  99. package/src/diag.mjs +98 -0
  100. package/src/docs.mjs +228 -0
  101. package/src/doctor.mjs +42 -0
  102. package/src/files.mjs +60 -0
  103. package/src/fix.mjs +48 -0
  104. package/src/gate/after.mjs +40 -0
  105. package/src/gate/before.mjs +54 -0
  106. package/src/gate/classify.mjs +72 -0
  107. package/src/gate/mutation.mjs +209 -0
  108. package/src/gate/resolve-cases.mjs +22 -0
  109. package/src/gate/result.mjs +63 -0
  110. package/src/gate/run.mjs +75 -0
  111. package/src/gate.mjs +178 -0
  112. package/src/index.mjs +9 -0
  113. package/src/infer/box-props.cjs +140 -0
  114. package/src/infer/core-boxes.cjs +46 -0
  115. package/src/infer/derived-writes.cjs +95 -0
  116. package/src/infer/engine/checks.cjs +193 -0
  117. package/src/infer/engine/flow.cjs +293 -0
  118. package/src/infer/engine/report.cjs +158 -0
  119. package/src/infer/engine/utils.cjs +15 -0
  120. package/src/infer/engine.cjs +265 -0
  121. package/src/infer/facts/sites.cjs +114 -0
  122. package/src/infer/facts.cjs +345 -0
  123. package/src/infer/hosts.cjs +161 -0
  124. package/src/infer/lsp.mjs +240 -0
  125. package/src/infer/session.cjs +161 -0
  126. package/src/infer/shadow.cjs +54 -0
  127. package/src/infer/worker.cjs +145 -0
  128. package/src/jsx-scan.mjs +128 -0
  129. package/src/kerf.mjs +98 -0
  130. package/src/load-config/schema.mjs +300 -0
  131. package/src/load-config.mjs +302 -0
  132. package/src/map.mjs +177 -0
  133. package/src/mcp/browser-tools.mjs +155 -0
  134. package/src/mcp.mjs +273 -0
  135. package/src/meta-table.mjs +63 -0
  136. package/src/mutate.mjs +224 -0
  137. package/src/plugin-checks.mjs +118 -0
  138. package/src/plugins.mjs +258 -0
  139. package/src/project.mjs +310 -0
  140. package/src/props-checks.mjs +64 -0
  141. package/src/props-listener.mjs +56 -0
  142. package/src/react-checks.mjs +67 -0
  143. package/src/server-state-checks.mjs +34 -0
  144. package/src/share-checks.mjs +158 -0
  145. package/src/site.mjs +46 -0
  146. package/src/slots.mjs +181 -0
  147. package/src/start/build.mjs +116 -0
  148. package/src/start/routes.mjs +38 -0
  149. package/src/start.mjs +394 -0
  150. package/src/state-checks/core-state.mjs +223 -0
  151. package/src/state-checks/modules.mjs +17 -0
  152. package/src/state-checks/scan.mjs +232 -0
  153. package/src/state-checks/server-graph.mjs +65 -0
  154. package/src/state-checks.mjs +189 -0
  155. package/src/style/find.mjs +121 -0
  156. package/src/style.mjs +327 -0
  157. package/src/surface-checks.mjs +384 -0
  158. package/src/tailwind.mjs +23 -0
  159. package/src/tasks.mjs +261 -0
  160. package/src/test-rules/context.mjs +109 -0
  161. package/src/test-rules/file-rules.mjs +279 -0
  162. package/src/test-rules/rule-helpers.mjs +244 -0
  163. package/src/test-rules/syntax.mjs +223 -0
  164. package/src/test-rules/test-rules.mjs +127 -0
  165. package/src/testdiff.mjs +219 -0
  166. package/src/tests.mjs +120 -0
  167. package/src/text-checks.mjs +332 -0
  168. package/src/tokens.mjs +33 -0
  169. package/src/trust/scan.mjs +95 -0
  170. package/src/trust.mjs +394 -0
  171. package/src/workspace.mjs +182 -0
  172. package/ts-plugin/context.js +57 -0
  173. package/ts-plugin/index.js +17 -0
  174. package/ts-plugin/mapping.js +65 -0
  175. package/ts-plugin/package.json +1 -0
  176. package/ts-plugin/proxy.js +144 -0
@@ -0,0 +1,53 @@
1
+ # Browser values (`@kerf-js/core/browser`)
2
+
3
+ ```tsx
4
+ import { state } from '@kerf-js/core'
5
+ import {
6
+ online,
7
+ visible,
8
+ lifecycle,
9
+ media,
10
+ on,
11
+ interval,
12
+ } from '@kerf-js/core/browser'
13
+
14
+ export function Toolbar() {
15
+ const isOnline = online() // Derived<boolean>; server: true
16
+ const shown = visible() // Derived<boolean>; server: true
17
+ // 'active' | 'passive' | 'hidden' | 'frozen' | 'terminated'
18
+ const page = lifecycle()
19
+ // Server renders `ssr`.
20
+ const dark = media('(prefers-color-scheme: dark)', { ssr: false })
21
+ const open = state(true)
22
+ const now = state(Date.now())
23
+ on(window, 'keydown', e => { // e: KeyboardEvent
24
+ if (e.key === 'Escape') open.value = false
25
+ })
26
+ // Also '500ms', '5m', '1h', or a number of ms.
27
+ interval('1s', () => { now.value = Date.now() })
28
+ return (
29
+ <p hidden={!open.value}>
30
+ {isOnline.value ? 'online' : 'offline'}{', '}
31
+ {dark.value ? 'dark' : 'light'}{', '}
32
+ {shown.value ? page.value : 'hidden'},
33
+ {new Date(now.value).toLocaleTimeString()}
34
+ </p>
35
+ )
36
+ }
37
+ ```
38
+
39
+ - Call them in setup (a component body, a `defineState` setup, or `createRoot`). Their owner removes them; created
40
+ anywhere else (module scope, a timer, a handler, after `await`) they throw in dev and are **W051**.
41
+ - Values subscribe on first read and share one listener per event, however many components read them.
42
+ - On the server a value is its `ssr` value (`online`/`visible`: `true`, `lifecycle`: `'active'`). `media` has no
43
+ default: pass `ssr` in server-rendered components (**W054**). Hydration renders the server value, then the real one.
44
+ - Not `window.addEventListener` / `setInterval` in components (**W050**, with an edit to `on` / `interval`), and not
45
+ `watch(() => live.value, v => { s.value = v })` (**W056**): read `live.value` where you need it.
46
+ - `tabs.channel('cart', schema)` is a validated `BroadcastChannel` between tabs: `.post(msg)`, `.on(fn)`, `.value`.
47
+ `state(init, { persist: 'local', sync: 'tabs' })` in a `defineState` keeps a box the same in every tab (S008 without
48
+ `persist`, or with `session`).
49
+
50
+ In tests (`@kerf-js/core/test`): `await net.offline()`, `net.online()`, `page.hide()`, `page.show()`, `page.blur()`,
51
+ `page.focus()`, `page.freeze()`, `page.resume()`, `page.leave({ persisted })`, `page.restore()`,
52
+ `page.media(query, true)`, `tabs.post(name, msg)`, `tabs.posted(name)`. Each test starts online, visible and focused with every query false. After each test
53
+ @kerf-js/core/test fails if anything is still open (**T012**); `leaks()` lists it.
package/docs/config.md ADDED
@@ -0,0 +1,127 @@
1
+ # kerf.config
2
+
3
+ `kerf.config.ts` is the default. `kerf.config.json` and `kerf.config.yaml` take the same keys, and `kerf check` writes
4
+ `.kerf/config.schema.json` for editor completion. In JSON and YAML a plugin is a package name or `[name, options]`, like
5
+ `["@kerf-js/veneer", { "fields": "classic" }]`; anything that needs a function belongs in `kerf.config.ts`. Keep one file:
6
+ two is P010. `kerf add <plugin>` installs a plugin and adds it to whichever format you use; `kerf add tailwind` sets up Tailwind, `kerf add db mysql --layer native` adds a database, and `kerf add auth` adds Better Auth to it.
7
+
8
+ ```ts
9
+ import { defineConfig } from '@kerf-js/core/config'
10
+ import { dialScript, veneer } from '@kerf-js/veneer/plugin'
11
+
12
+ export default defineConfig({
13
+ scope: { write: ['src/**', 'test/**'], forbid: ['.env*'] },
14
+ tasks: {
15
+ seed: {
16
+ run: 'node scripts/seed.mjs',
17
+ description: 'Load demo products into the dev db',
18
+ sideEffects: ['db'], env: ['dev'],
19
+ },
20
+ },
21
+ environments: { dev: { url: 'http://localhost:5173' } },
22
+ // Metadata defaults: static tags in the first response.
23
+ // See kerf docs meta.
24
+ site: {
25
+ name: 'Acme',
26
+ url: 'https://acme.dev',
27
+ title: '%s · Acme',
28
+ description: 'Tools for builders.',
29
+ locale: 'en_US',
30
+ // Default 'auto': generated card; false: none (kerf docs meta).
31
+ image: { url: '/og.png', width: 1200, height: 630 },
32
+ twitter: { card: 'summary_large_image', site: '@acme' },
33
+ // Default true: first-paint CSS. False keeps plain links,
34
+ // as a strict CSP needs (D012).
35
+ inlineCss: false,
36
+ // Default true: one hashed sheet and first-paint CSS.
37
+ // False splits by chunk and inlines up to 48 KB.
38
+ criticalCss: false,
39
+ // Selector words to keep for classes set by a head script.
40
+ criticalKeep: ['theme-x'],
41
+ // Raw HTML before stylesheets on every page. dialScript from
42
+ // @kerf-js/veneer/plugin restores setDial(…, { persist: true })
43
+ // before the first paint.
44
+ head: dialScript,
45
+ },
46
+ // Plugin factories; plain { name, provides } entries are data.
47
+ plugins: [veneer()],
48
+ // Names the winner when two plugins provide one slot.
49
+ slots: {},
50
+ })
51
+ ```
52
+
53
+ | Key | What it holds, and what `kerf check` reports |
54
+ |---|---|
55
+ | `scope` | `write`, `read` and `forbid` globs. `forbid` is never compiled or written. `write` will bound `kerf fix` (P005, not reported yet) |
56
+ | `tasks` | Project commands for `kerf run` and `kerf tasks`. P003 duplicate name or command, P004 missing `description` or `sideEffects` |
57
+ | `environments` | Named places the app runs, with a `url` |
58
+ | `test` | `include` (default `**/*.{test,spec}.*`), `lanes`, and `gate: { mutationBudgetSec, maxMutants }` for `kerf test --gate` |
59
+ | `check` | `include` and `exclude` globs; `design: false` turns off the D-codes, `routes: false` the route pass (H001–H007, H011–H016, which run the app's loaders once), `props: false` or `'manual'` the prop inference (`kerf docs props`) |
60
+ | `plugins` | P116 duplicate name; P100 two entries provide one `one` slot; P115 bad options; P117 impure `contribute()`; P111 code outside the plugin's namespace; P112 AGENTS section over 1 KB; P113 token-namespace or catalog collision; and the codes plugins report themselves (e.g. veneer's D010) |
61
+ | `slots` | Which plugin wins a slot two provide. P008 unknown slot id, P009 winner not in `plugins` or not providing the slot |
62
+ | `site` | Page metadata defaults and CSS delivery. P007 `url` not absolute http(s), `title` without `%s`, `locale` not `en_US` style; H001 no `url`; H003 no `description`; H004 a title over 60 or a description over 160 (warnings) |
63
+ | `site.card` | The generated share card's colours and fonts. P007 a colour that isn't `#rrggbb`, a font family that isn't a name. `kerf docs meta` has the rest |
64
+ | `site.headers` | Response headers by route pattern |
65
+ | `site.security` | Headers every Start response gets unless it sets its own (`nosniff`, `Referrer-Policy`, `X-Frame-Options: SAMEORIGIN`, COOP, HSTS on https). Name a header to change it, `false` to drop it, or `security: false` for none |
66
+ | `site.trustProxy` | `true` or a number: proxies in front of the server. The client's address comes from that many entries from the right of `X-Forwarded-For`, so auth's rate limit sees real clients. Leave it off with nothing in front |
67
+ | `site.log` | `'text'` (default) or `'json'`: the server log's lines, readable or as JSON objects with `time`, `level`, `code`, `message`, `route` and `requestId` |
68
+ | `site.limits` | `{ body, upload }` in bytes: the largest JSON (1 MB) and multipart (25 MB) request body. Past it, 413 (Q018) |
69
+ | `runtime` | `node`, `bun` or `deno`: what `kerf build` targets (`kerf docs start`) |
70
+ | `hydration` | `'lazy'` (default): islands load when needed; `'partial'`: every island loads with the page; `'full'`: every route hydrates whole |
71
+ | `rust` | `unions` and `services` for Rust bodies (`kerf docs rust`) |
72
+ | `live` | `targets` for a live query's `verify` (`kerf docs start`) |
73
+ | `trust` | `'enforce'` (default) or `'warn'`: see P109 and P110 under Plugins |
74
+ | anything else | P007: unknown key or wrong type, with the path |
75
+
76
+ `package.json` scripts may only alias `kerf …` (P002). Project commands live in `tasks`.
77
+
78
+ ## Plugins
79
+
80
+ A plugin is a factory made with `definePlugin` from `@kerf-js/core/plugin`. Its pure `contribute(options, env)` returns what it
81
+ adds: slot providers, `tokens` (`--<namespace>-*`), one AGENTS.md section (≤ 1 KB), catalog entries and diagnostic
82
+ codes in its namespace. Components stay normal imports.
83
+
84
+ - `kerf plugins --json` lists plugins (sorted by name), the slots they provide and bind, permissions and codes.
85
+ - `kerf plugins explain <slot> --json` shows config → plugin → module → `.kerf/slots/<id>.ts`.
86
+ - `kerf plugins sync` (and `kerf check`) writes `.kerf/slots/<id>.ts`, `.kerf/slots.d.ts` and `.kerf/tokens/<ns>.css`.
87
+ Import a slot as `kerf:slot/<id>`; its provider loads lazily through `load()`. Unbound: `load()` throws P101.
88
+ - Output is the same for any order of `plugins: []`; array order never decides a binding (P100).
89
+
90
+ ### Permissions and the lock
91
+
92
+ A plugin declares `permissions` (`fs: { read, write }`, `net`, `env`, `spawn`, `native`). `.kerf/plugins.lock.json`
93
+ records what you approved, plus a hash of each installed plugin's files. Commit it.
94
+
95
+ - **P109** stops `kerf check`, `kerf dev` and `kerf build` when a plugin asks for a permission the lock doesn't give it,
96
+ or the audit finds it using one it didn't declare.
97
+ - **P110** stops them when an installed plugin's code isn't what the lock recorded, or the lock can't be read.
98
+ - `kerf plugins audit --json` shows every plugin against the lock: permissions added and removed, undeclared use with
99
+ file and line, and the dependencies it didn't read. It exits 1 if anything is blocked.
100
+ - `kerf plugins approve <name…>` records those plugins, and `--all` records every plugin and drops ones you removed.
101
+ With neither it shows what's waiting and writes nothing. If `.gitignore` hides the lock, it fixes that line. In a
102
+ monorepo, check the ignore file at the repository root yourself.
103
+ - `kerf add` never approves. It tells you what the plugin asks for, and the next `kerf check` stops until you do.
104
+ - A plugin that asks for nothing and passes the audit needs no approval, and `approve` pins it if you want that.
105
+ - `npm create kerf` approves the plugins you pick. It can't hash code before the install, so run
106
+ `kerf plugins approve --all` once to pin them.
107
+ - `trust: 'warn'` in the config turns P109 and P110 into warnings, for a project that vets dependencies some other way.
108
+
109
+ This shows you changes; it isn't a sandbox. `contribute()` runs when the config loads, before any of this. The audit
110
+ reads the source of the plugin's own package from its entry and its build and server modules, so it won't see code
111
+ that hides itself or code in dependencies (your package manager's lockfile pins those). A workspace package has no
112
+ fixed code to hash, so it's audited on every check instead. A plugin defined in the config file is your own code:
113
+ only its permissions are compared. A plugin is matched to its package by name, so one that claims another's name is
114
+ hashed as that package.
115
+
116
+
117
+ ## Indexing intent
118
+
119
+ For a site intended for public search, declare
120
+ `build: { audit: { indexing: 'public' } }`. L024 then fails the build or audit if
121
+ robots metadata or an HTTP X-Robots-Tag header says noindex. `private` or the
122
+ backward-compatible `auto` leaves this a warning; neither removes a directive.
123
+ After deployment, run `kerf audit --url https://your-site.example --indexing public`:
124
+ a host or proxy may add a header that a local build cannot see. Preserve intentional
125
+ preview/private exclusions. A noindex finding is an indexing policy issue, not
126
+ chat-agent traffic; use a clean profile before attributing other audit failures
127
+ to application or framework code.
package/docs/core.md ADDED
@@ -0,0 +1,30 @@
1
+ # Core entrypoints
2
+
3
+ Import application APIs such as `state`, `derived`, `watch`, `context` and `createRoot`
4
+ from `@kerf-js/core`. Use the `State<T>` and `Derived<T>` types for boxes.
5
+
6
+ `memo(fn)` returns a cached accessor, `() => T`. Call it to read the current value.
7
+ It tracks the same dependencies as `derived(fn)` and recomputes when they change.
8
+
9
+ ```ts
10
+ import { memo, state } from '@kerf-js/core'
11
+
12
+ const count = state(1)
13
+ const twice = memo(() => count.value * 2)
14
+ console.log(twice()) // 2
15
+ ```
16
+
17
+ Compiler output and framework integrations use `@kerf-js/core/internal`. This
18
+ entrypoint re-exports the runtime's existing implementations and shares its graph,
19
+ box constructors and server state. It does not create another runtime instance.
20
+
21
+ The root no longer exports `DIRTY`, `rt`, `listener`, `read`, `reach`, `clean`,
22
+ `setFlat`, `flat`, `collecting`, `runMounts`, `setKeyed`, `NONE`, `stats`,
23
+ `devComponent` or `Box`. Integrations that require these use the internal entrypoint.
24
+ Applications create boxes with `state` rather than constructing `Box`.
25
+
26
+ `hole`, `localProps` and `restOf` also live under the internal entrypoint. `hole`
27
+ tracks a renderer's child binding. `localProps` implements writable prop locals.
28
+ `restOf` takes the prop snapshot used by a compiled native-element spread. These
29
+ are compiler and renderer contracts, rather than application APIs. The `hole`
30
+ export of `@kerf-js/core/ssr` is a separate server-rendering helper.
package/docs/deploy.md ADDED
@@ -0,0 +1,108 @@
1
+ # Deploy: from `kerf build` to a live URL
2
+
3
+ kerf reads what the app uses and says which hosts can run it, before a build and before an account exists. Then it
4
+ writes the host's files and a workflow, and `kerf deploy` runs the host's own CLI and reports the URL.
5
+
6
+ ```bash
7
+ # Host fit, cost and suggestion
8
+ kerf deploy hosts
9
+ # Host files, GitHub workflow and deploy config
10
+ kerf deploy init
11
+ # Dry run: build and commands that --yes would run
12
+ kerf deploy
13
+ # Preview; add --prod for production
14
+ kerf deploy --yes
15
+ ```
16
+
17
+ `kerf deploy` without `--yes` runs nothing. An agent runs the dry run on its own, and asks before `--yes`: a deploy
18
+ publishes, and a host may bill for it. Nothing in kerf creates a site, an app, a volume or a DNS record; `init` prints the
19
+ one command per host that does, for you to run.
20
+
21
+ ## Which host
22
+
23
+ | The app uses | Netlify / Vercel | Cloudflare | Fly / Render |
24
+ |---|---|---|---|
25
+ | pages, queries, mutations, forms, `stream()` | ✓ | ✓ | ✓ |
26
+ | `channel`, `sharedState`, `realtime({ share })` | ✗ E001 | ✓ (Durable Objects) | ✓ |
27
+ | `.live({ required })`, `remote()` sidecars | ✗ E002 | ✗ E002 | ✓ |
28
+ | a SQLite file, media uploads | ✗ E003 | ✗ E003 | with a volume or disk (billed) |
29
+ | `changes` without an external listener | degraded (R014) | degraded | ✓ |
30
+
31
+ The suggestion: Netlify when nothing needs a server that stays up (a CDN with functions is the cheapest and fastest
32
+ host), Cloudflare when channels are all that need one, Fly when data must last on disk, else Fly or Render.
33
+
34
+ A function host blocked by a channel has a third way, the split: pages on the function host, realtime on a small server.
35
+ It needs a second origin and a cookie both can read, and is designed (research 46 §10), not built.
36
+
37
+ ## `deploy` in kerf.config.ts
38
+
39
+ ```ts
40
+ deploy: {
41
+ // netlify | vercel | cloudflare | fly | render
42
+ target: 'fly',
43
+ fly: {
44
+ app: 'shop',
45
+ region: 'iad',
46
+ volume: { name: 'data', sizeGb: 1 },
47
+ },
48
+ ci: 'github', // the workflow; false for none
49
+ branch: 'main',
50
+ cdn: {
51
+ proxy: 'cloudflare',
52
+ images: { provider: 'cloudinary', cloud: 'shop' },
53
+ },
54
+ }
55
+ ```
56
+
57
+ Names, regions and sizes only. Every token comes from the environment, and one written into the config, a host file or a
58
+ workflow is **E008**. With `deploy.target` set, `kerf build` builds for it, and `kerf check` reports E001–E003 for it.
59
+
60
+ A volume or disk mounts at `/app/.data`: SQLite's default `file:.data/app.db` is already there, and uploads go to
61
+ `.data/media` (`KERF_MEDIA_DIR`).
62
+
63
+ ## What each target writes and runs
64
+
65
+ | Target | Files | `kerf deploy --yes` runs | Reads |
66
+ |---|---|---|---|
67
+ | netlify | `netlify.toml` | `kerf build --preset netlify`, `netlify deploy --dir dist --functions .netlify/functions-internal --json` | `NETLIFY_AUTH_TOKEN`, `NETLIFY_SITE_ID` |
68
+ | vercel | `vercel.json` | `kerf build --preset vercel`, `vercel deploy --prebuilt` | `VERCEL_TOKEN`, `VERCEL_ORG_ID`, `VERCEL_PROJECT_ID` |
69
+ | cloudflare | `wrangler.toml` | `kerf build --preset cloudflare_durable`, `wrangler deploy` in `.output/` | `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID` |
70
+ | fly | `fly.toml`, `Dockerfile`, `.dockerignore` | `flyctl deploy --remote-only` (Fly builds the image) | `FLY_API_TOKEN` |
71
+ | render | `render.yaml`, `Dockerfile`, `.dockerignore` | the deploy hook (Render builds the pushed commit) | `RENDER_DEPLOY_HOOK_URL` |
72
+
73
+ Every target also gets `.github/workflows/kerf-deploy.yml`: on push to `branch`, install, `kerf check`, then `kerf deploy
74
+ --yes --prod`; on a pull request, a preview where the host has them. Add the variables as repository secrets (`gh secret
75
+ set NAME`). Netlify, Vercel and Cloudflare deploy what was built, so build where the host runs: the workflow builds on
76
+ Linux, and a native addon built on a Mac is **E004**.
77
+
78
+ Each written file starts with `# kerf deploy init <target>, sha <hash>`. Change the config and `kerf check` reports the
79
+ file as stale (**E006**); `init` rewrites it. A file you edited keeps its old hash, and `init` leaves it alone unless
80
+ `--force`.
81
+
82
+ ## CDN and media
83
+
84
+ - **Cloudflare in front of a server host** (`cdn.proxy: 'cloudflare'`): proxy the domain to the Fly or Render origin.
85
+ Hashed assets are already `immutable`, and pages are `private` unless a route caches, so the proxy can't serve one
86
+ user's page to another. E010: `site.url` is still the host's own domain. E011: a proxy in front of a CDN host.
87
+ - **Cloudinary for uploads** (`cdn.images`): checked (E012 without `@kerf-js/media`, E013 without a cloud or with
88
+ two), not yet wired: uploads still go to the media server's disk (E014). `?media` imports never need it: the build
89
+ already makes sized AVIF and WebP files that any CDN serves.
90
+
91
+ ## Codes
92
+
93
+ E001 sockets on a function host, E002 a held process or a sidecar, E003 data on a disk that doesn't last, E004 a native
94
+ addon deployed from another OS, E005 no target (with the suggestion), E006 a stale host file, E007 an unset variable,
95
+ E008 a written credential, E009 the memory bus on many instances, E010–E014 CDN and media. `kerf docs E003` explains one.
96
+
97
+
98
+ ## Indexing intent
99
+
100
+ For a site intended for public search, declare
101
+ `build: { audit: { indexing: 'public' } }`. L024 then fails the build or audit if
102
+ robots metadata or an HTTP X-Robots-Tag header says noindex. `private` or the
103
+ backward-compatible `auto` leaves this a warning; neither removes a directive.
104
+ After deployment, run `kerf audit --url https://your-site.example --indexing public`:
105
+ a host or proxy may add a header that a local build cannot see. Preserve intentional
106
+ preview/private exclusions. A noindex finding is an indexing policy issue, not
107
+ chat-agent traffic; use a clean profile before attributing other audit failures
108
+ to application or framework code.
package/docs/design.md ADDED
@@ -0,0 +1,106 @@
1
+ # Design: tokens, primitives, D-codes
2
+
3
+ An app with veneer has one design language: `@kerf-js/veneer`'s primitives and components, on veneer's tokens. Name what a thing
4
+ is, and the look follows the theme, the dials and the density.
5
+
6
+ ```tsx
7
+ import {
8
+ Button,
9
+ Card,
10
+ Heading,
11
+ Input,
12
+ Row,
13
+ Stack,
14
+ Text,
15
+ } from '@kerf-js/veneer'
16
+
17
+ export function Billing() {
18
+ return (
19
+ <Stack as="section" gap="section">
20
+ <Heading level={1} role="title">Billing</Heading>
21
+ <Card title="Card on file">
22
+ <Stack gap="related">
23
+ <Text subtle>Visa ending 4242</Text>
24
+ <Input label="Billing email" type="email" />
25
+ <Row gap="tight" justify="end">
26
+ <Button emphasis="ghost">Cancel</Button>
27
+ <Button>Save</Button>
28
+ </Row>
29
+ </Stack>
30
+ </Card>
31
+ </Stack>
32
+ )
33
+ }
34
+ ```
35
+
36
+ ## Vocabulary
37
+
38
+ | Thing | Use |
39
+ |---|---|
40
+ | Vertical flow | `Stack gap align divided` |
41
+ | Horizontal cluster | `Row gap justify align wrap reflow` (`reflow` stacks it below a width step) |
42
+ | Columns | `Grid min cols gap` |
43
+ | Side + main | `Split side width at gap` |
44
+ | Measured column | `Center max gutter intrinsic` |
45
+ | Full-screen, one centred child | `Cover`, with `data-part="center"` on the child |
46
+ | Media box | `Frame ratio` |
47
+ | Push to the far end | `Spacer` |
48
+ | Sunken region | `Inset pad` |
49
+ | Raised box | `Card` (veneer's surface: `<Surface>` is kerf's canvas) |
50
+ | Heading | `Heading level role`: `level` is the outline and picks the look (`title` for h1, `heading` for h2 and h3, `label` below); `role` overrides it |
51
+ | Text | `Text role tone subtle faint inline` |
52
+ | Link | `Link href subtle external`; a bare `<a>` still gets veneer's colour |
53
+
54
+ `gap`: `none hair tight related group section page`, a relationship and not a size: `related` inside a thing, `group`
55
+ between things, `section` between sections. `as` picks the element: `div section article main header footer nav aside
56
+ form ul ol`. There are no breakpoint props, since boxes answer to their container. `@kerf-js/core/ds` exports these names as
57
+ constants and types.
58
+
59
+ `style={{ … }}` and `class` still work; the D-codes below tell you when they leave the system. For a named look of your
60
+ own, use a style group (`kerf docs style`), not a class list.
61
+
62
+ ## D-codes
63
+
64
+ `kerf check` reports them. `kerf fix` applies the safe autofixes. A fix that changes an element is a suggested edit in
65
+ `fix.edits`; a raw colour has none, since a token follows the theme and the raw value didn't.
66
+
67
+ Where the app has veneer's tokens (`@kerf-js/veneer` in package.json; headless `@kerf-js/veneer-core` ships none):
68
+
69
+ | Code | Catches | Fix |
70
+ |---|---|---|
71
+ | D001 | Raw colour, palette class | A token or `tone` |
72
+ | D002 | Spacing off the scale, or a step by hand | Autofix when exactly a step |
73
+ | D003 | Raw type, radius, shadow | `Heading`, `Text`, radius and elevation tokens; autofix for an exact radius |
74
+ | D004 | Layout spelled out on an element | `Stack`, `Row` (suggested edit) |
75
+ | D040 | The style gate (`data-kerf="styled"`) on main content or an h1 | A secondary part, or no marker |
76
+ | D005 | A browser-painted control: `<button>`, `<select>`, `<textarea>`, an input type such as `date`, `number` or `range`, or a `title` tooltip | The veneer component (suggested edit for a button) |
77
+ | D006 | One heading level at two roles across the app, or a bare `<hN>` beside `<Heading>` | Match the level's main role (suggested edit at each site) |
78
+ | D007 | A bare `<a href>` | `<Link>`, or `Shell`'s `nav` (suggested edit) |
79
+
80
+ In every app:
81
+
82
+ | Code | Catches | Fix |
83
+ |---|---|---|
84
+ | D011 | A literal colour pair below 4.5:1 | Tokens, or better colours |
85
+ | D030 | A form control with no label | `<label>`, `aria-label`, veneer's `label` |
86
+ | D031 | A button or link with no name | Text, `aria-label`, veneer's `label` |
87
+ | D032 | `<img>` with no `alt` | Describe it; `alt=""` for decoration |
88
+ | D033 | `onClick` on a non-interactive element | `<button type="button">` (suggested edit) |
89
+ | D034 | A control inside a control | One control |
90
+ | D035 | A heading level that jumps | The next level |
91
+ | D036 | Focus ring removed | Remove the override, or add a `focus-visible:` style |
92
+ | D037 | Positive `tabindex` | `0` (autofix) |
93
+ | D038 | Two solid Buttons side by side | One primary action per region |
94
+ | D039 | `<html>` with no `lang` | Set it |
95
+
96
+ D010 is veneer's contrast gate on the seed and tokens: `kerf build` stops on it. D012 is a CSP that blocks the inlined CSS. D020–D025 are style groups.
97
+
98
+ `// kerf-allow D001: <reason>` on the line above keeps one site; the reason is required. `check: { design: false }` in
99
+ the config turns these off.
100
+
101
+ ## Tokens
102
+
103
+ The theme is `veneer({ seed, dials, fields, radius, fonts, tokens })`: every value goes through the contrast check. `kerf docs theme`
104
+ has worked looks and the button channels. `kerf tokens`
105
+ writes the resolved tokens to `.kerf/tokens/` as DTCG 2025.10, one file per theme × expression plus a resolver, for
106
+ Figma, Style Dictionary or Terrazzo.
@@ -0,0 +1,83 @@
1
+ # Core and Start entrypoints
2
+
3
+ These paths are retained package exports. Node tooling must not enter a browser bundle.
4
+ The snapshots cover export paths, targets and conditions, not names or signatures.
5
+
6
+ ## @kerf-js/core
7
+
8
+ - `@kerf-js/core`: Application reactive runtime and components.
9
+ - `@kerf-js/core/internal`: Compiler and renderer contract; shares the runtime graph, not an app API.
10
+ - `@kerf-js/core/keyed`: Keyed state helpers.
11
+ - `@kerf-js/core/jsx-runtime`: JSX types for compiler output; types only.
12
+ - `@kerf-js/core/dom`: Browser DOM rendering and hydration; other helpers serve compiler output.
13
+ - `@kerf-js/core/ssr`: Server rendering and compiler helpers.
14
+ - `@kerf-js/core/head`: Browser route metadata updates.
15
+ - `@kerf-js/core/test`: Test utilities; requires the test peers.
16
+ - `@kerf-js/core/test/plugins`: Plugin conformance test suites; browser layout tests need a browser.
17
+ - `@kerf-js/core/persist`: State persistence.
18
+ - `@kerf-js/core/history`: State history.
19
+ - `@kerf-js/core/sync`: State synchronization.
20
+ - `@kerf-js/core/interaction`: Interaction state.
21
+ - `@kerf-js/core/browser`: Browser APIs and browser state.
22
+ - `@kerf-js/core/style`: Style groups and styling helpers.
23
+ - `@kerf-js/core/ds`: Design system primitives.
24
+ - `@kerf-js/core/media`: Media components and helpers.
25
+ - `@kerf-js/core/shape`: Shape components and helpers.
26
+ - `@kerf-js/core/text`: Text components and helpers.
27
+ - `@kerf-js/core/surface`: Surface components and helpers.
28
+ - `@kerf-js/core/media-probe`: Media probing for tooling; Node entry.
29
+ - `@kerf-js/core/client`: Client type declarations only; no runtime condition.
30
+ - `@kerf-js/core/style/matrix`: Style matrix tooling; Node entry.
31
+ - `@kerf-js/core/hydration`: Hydration tooling; Node entry.
32
+ - `@kerf-js/core/markup`: Shared markup helpers and types.
33
+ - `@kerf-js/core/node-purge`: Node cache purge tooling.
34
+ - `@kerf-js/core/hmr`: Compiler-generated development hot updates.
35
+ - `@kerf-js/core/plugin`: Plugin declarations and runtime helpers.
36
+ - `@kerf-js/core/devtools`: Development tools.
37
+ - `@kerf-js/core/agent`: In-page development agent; requires testing peers.
38
+ - `@kerf-js/core/config`: Configuration declarations and runtime helpers.
39
+ - `@kerf-js/core/vite`: Vite plugin; Node tooling.
40
+ - `@kerf-js/core/compiler`: Compiler binding; Node tooling and native or WASM compiler.
41
+
42
+ ## @kerf-js/start
43
+
44
+ - `@kerf-js/start`: Application server functions, forms and routing APIs.
45
+ - `@kerf-js/start/data`: Server function and data primitives.
46
+ - `@kerf-js/start/cache`: The shared query cache's `Store` type and `memoryStore()`, for `src/cache.server.ts`.
47
+ - `@kerf-js/start/cron`: `defineCron()` and the `CronJob` type, for `src/cron.server.ts`.
48
+ - `@kerf-js/start/email`: `sendEmail()` and the Resend, SMTP and dev-log mailers, for `src/email.server.ts`.
49
+ - `@kerf-js/start/jobs`: `defineJobs()`, `job()` and `memoryQueue()`, for `src/jobs.server.ts`.
50
+ - `@kerf-js/start/derive`: Server-side page metadata derivation.
51
+ - `@kerf-js/start/media`: Media schema and asset types.
52
+ - `@kerf-js/start/hub`: Realtime hub and topics; server.
53
+ - `@kerf-js/start/live`: Streams and live queries.
54
+ - `@kerf-js/start/bus`: Realtime bus interfaces.
55
+ - `@kerf-js/start/changes`: Database change feeds; server.
56
+ - `@kerf-js/start/changes-sql`: SQL for database change triggers; server tooling.
57
+ - `@kerf-js/start/live-target`: Live target capability checks; Node tooling.
58
+ - `@kerf-js/start/listen`: Database change listener; server.
59
+ - `@kerf-js/start/verify`: Live verification; server tooling.
60
+ - `@kerf-js/start/bus/postgres`: Postgres realtime bus; server, requires Postgres.
61
+ - `@kerf-js/start/list`: List queries and helpers.
62
+ - `@kerf-js/start/list/drizzle`: Drizzle list integration; requires Drizzle.
63
+ - `@kerf-js/start/channel`: Realtime channels.
64
+ - `@kerf-js/start/share`: Shared state.
65
+ - `@kerf-js/start/db`: Drizzle schema helpers; requires Drizzle.
66
+ - `@kerf-js/start/db/core`: Database interfaces and core helpers.
67
+ - `@kerf-js/start/db/sqlite`: SQLite database adapter.
68
+ - `@kerf-js/start/db/postgres`: Postgres database adapter; requires Postgres driver.
69
+ - `@kerf-js/start/db/mysql`: MySQL database adapter; requires MySQL driver.
70
+ - `@kerf-js/start/auth`: Authentication provider interface.
71
+ - `@kerf-js/start/auth/better-auth`: Better Auth integration; requires Better Auth.
72
+ - `@kerf-js/start/auth/drizzle`: Drizzle authentication integration; requires Drizzle.
73
+ - `@kerf-js/start/extension`: Server extension contract.
74
+ - `@kerf-js/start/client`: Client application bootstrap; browser.
75
+ - `@kerf-js/start/server`: Server application rendering and request handling.
76
+ - `@kerf-js/start/vite`: Start Vite plugin; Node tooling.
77
+ - `@kerf-js/start/routes`: Route manifest tooling.
78
+ - `@kerf-js/start/og`: Open Graph image tooling; server.
79
+ - `@kerf-js/start/app`: Development and build application tooling; Node.
80
+ - `@kerf-js/start/inspect`: Route metadata inspection; Node tooling.
81
+ - `@kerf-js/start/contract`: Server function contract generation; Node tooling.
82
+ - `@kerf-js/start/rust`: Rust remote function support.
83
+ - `@kerf-js/start/sidecar`: Rust sidecar supervisor; Node tooling.
package/docs/fonts.md ADDED
@@ -0,0 +1,118 @@
1
+ # Fonts
2
+
3
+ `@kerf-js/text` is the one place an app's fonts are declared. `kerf add text` installs it; then:
4
+
5
+ ```ts
6
+ import { defineConfig } from '@kerf-js/core/config'
7
+ import { text } from '@kerf-js/text'
8
+
9
+ export default defineConfig({
10
+ plugins: [
11
+ text({
12
+ fonts: {
13
+ body: {
14
+ family: 'Inter',
15
+ src: 'assets/fonts/inter.woff2',
16
+ fallback: 'Arial',
17
+ axes: { wght: [100, 900] },
18
+ },
19
+ display: {
20
+ family: 'Fraunces',
21
+ src: 'assets/fonts/fraunces.woff2',
22
+ fallback: 'Georgia',
23
+ weight: 700,
24
+ },
25
+ },
26
+ }),
27
+ ],
28
+ })
29
+ ```
30
+
31
+ `src` is relative to the project root (woff2, woff, ttf or otf). `fallback` is a system face: Arial, Helvetica, Times New
32
+ Roman, Georgia, Courier New, Verdana. The keys are roles of your choosing; `body` and `display` are preloaded unless a
33
+ face sets `preload: false`, others only with `preload: true`. Other options: `display` (`swap`, `optional`, `fallback`),
34
+ `weight`, `style`, `axes`, and beside `fonts`, `subsets` (default `['latin']`) and `trim` (default `true`).
35
+
36
+ ## What the build does
37
+
38
+ - Subsets each face per `unicode-range` to hashed woff2 files.
39
+ - Writes the `@font-face` rules, and a `"<Family> Fallback"` face matched to the font's metrics, so the swap doesn't shift
40
+ layout.
41
+ - Adds the preload links to the page's head, before the first byte.
42
+ - Trims each face, in a build only. Font bytes are what hold back the largest paint on a text hero, so nothing here needs
43
+ turning on, and neither cut changes how the page looks or which characters it can show:
44
+ - **Axes.** A custom axis (`SOFT`, `WONK`, `GRAD`…) is pinned to the one value your `font-variation-settings` give it, or
45
+ to the font's default if the source never sets it. An axis set to two values stays. A value kerf can't read from the
46
+ source (`var()`, a template, an expression) keeps every axis. `wght`, `wdth`, `opsz`, `slnt` and `ital` are never
47
+ pinned: CSS drives them. A pinned value applies to every use of the face, so a face used both with and without the
48
+ setting needs the axis declared.
49
+ - **Characters.** `latin` becomes two files. The core is preloaded: ASCII, common punctuation, and every other latin
50
+ character in your source. The rest is fetched through `unicode-range` only by a page that shows one of those
51
+ characters, so text from a database still gets the face, after a fallback-matched swap.
52
+
53
+ Keep one axis by naming it in `axes`, such as `axes: { SOFT: [0, 100] }`, for values set at runtime or by a dependency's CSS
54
+ (only your own source is read). `trim: false` turns all of it off. `kerf dev` always serves whole faces, so an axis you are
55
+ editing responds.
56
+
57
+ **There is nothing to import.** `@kerf-js/core/vite` loads the generated CSS in the client entry (Start) or the page (an HTML app).
58
+ `import 'kerf:fonts'` still works and changes nothing. `import { preloads } from 'kerf:fonts/preloads'` gives the preload
59
+ list to a custom server.
60
+
61
+ ## A face for a few characters
62
+
63
+ A face that draws a few letters, such as a script initial, needs only those. `glyphs` lists them: the face becomes one
64
+ small file, and its `unicode-range` leaves every other character to the next face in the stack, so no character goes
65
+ missing and none fetches the file it isn't in. It replaces `subsets` for that face, and applies in `kerf dev` too.
66
+
67
+ ```ts
68
+ text({
69
+ fonts: {
70
+ script: {
71
+ family: 'Mea Culpa',
72
+ src: 'assets/fonts/mea-culpa.ttf',
73
+ fallback: 'Georgia',
74
+ glyphs: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
75
+ preload: true,
76
+ },
77
+ },
78
+ })
79
+ ```
80
+
81
+ `glyphs: { selector }` reads the characters from your markup instead: the text of every element the selector matches
82
+ (`.class`, `[attr="value"]` or a tag; `[data-role="initial"]` also matches `<Text role="initial">`). With
83
+ `first: true` it takes only each one's first letter, as `::first-letter` draws it:
84
+
85
+ ```ts
86
+ script: {
87
+ family: 'Mea Culpa',
88
+ src: 'assets/fonts/mea-culpa.ttf',
89
+ fallback: 'Georgia',
90
+ glyphs: { selector: '.narrative', first: true },
91
+ },
92
+ ```
93
+
94
+ A build reads the scope from your source; `kerf dev` serves the whole face. Text the source holds only as an
95
+ expression (`{copy.intro}`), or a selector that matches nothing, keeps the face whole, and `.kerf/fonts.json` says
96
+ which element. Then list the characters yourself, or build the list from your copy in the config. CSS that changes
97
+ case (`text-transform`) draws characters the source doesn't hold: list those too.
98
+
99
+ ## Using a face
100
+
101
+ The build declares faces; it doesn't apply them. Name one in your CSS, with its fallback second:
102
+
103
+ ```css
104
+ body { font-family: "Inter", "Inter Fallback", sans-serif; }
105
+ h1 { font-family: "Fraunces", "Fraunces Fallback", Georgia, serif; }
106
+ ```
107
+
108
+ ## Diagnostics
109
+
110
+ | Code | Catches |
111
+ |---|---|
112
+ | X020 | A hand-written `@font-face` with no `"<Family> Fallback"` face, so the swap shifts layout: declare it in `text({ fonts })` |
113
+ | X021 | `font-display: block` or `auto`, which hide text while the font loads |
114
+ | X022 | A hand-written `@font-face` with no `unicode-range`, or the font build over budget: 100 KB of preloads or 1.5 KB of font CSS (brotli). Preload fewer faces or use fewer weights |
115
+ | X023 | A preload no `@font-face` uses |
116
+
117
+ The plugin also provides `text.measure`, line breaking for canvas text and exact row heights. It loads only when something
118
+ measures; `measure: 'off'` removes it. See `kerf docs surface`.