brustjs 0.1.64-alpha → 0.1.66-alpha

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.
@@ -6,6 +6,7 @@ export type ChangeKind = 'ts' | 'css' | 'component-css' | 'html' | 'islands' | '
6
6
  const IGNORE_DIR_SEGMENTS = new Set(['node_modules', '.git', '.brust', 'dist'])
7
7
  const TS_RE = /\.(tsx?|jsx?)$/
8
8
  const TEST_RE = /\.test\.(tsx?|jsx?)$/
9
+ const KIND_PRIORITY: ChangeKind[] = ['islands', 'ts', 'md', 'html', 'css', 'component-css']
9
10
 
10
11
  /** Classify a changed path. Returns null when the path should be ignored.
11
12
  * `root` is used to compute the relative path for ignore-segment matching.
@@ -83,26 +84,38 @@ export interface Watcher {
83
84
  close(): void
84
85
  }
85
86
 
86
- /** Watch `root` recursively. Emits one `onChange` call per debounce window
87
- * with paths classified by the dominant kind. Mixed-kind windows pick
88
- * by priority: islands > ts > html > css (islands trigger a full restart
89
- * that subsumes the others). */
87
+ /** Internal exposed for deterministic callback-contract tests. */
88
+ export function _testDispatchChanges(
89
+ paths: string[],
90
+ opts: Pick<CreateWatcherOptions, 'root' | 'hasMdRoutes' | 'onChange'>,
91
+ ): void {
92
+ const grouped = new Map<ChangeKind, Set<string>>()
93
+ for (const p of paths) {
94
+ const kind = classifyPath(p, opts.root, opts.hasMdRoutes ?? true)
95
+ if (kind === null) continue
96
+ let group = grouped.get(kind)
97
+ if (!group) {
98
+ group = new Set()
99
+ grouped.set(kind, group)
100
+ }
101
+ group.add(p)
102
+ }
103
+ for (const kind of KIND_PRIORITY) {
104
+ const group = grouped.get(kind)
105
+ if (group && group.size > 0) {
106
+ opts.onChange({ paths: Array.from(group), kind })
107
+ }
108
+ }
109
+ }
110
+
111
+ /** Watch `root` recursively. Emits one `onChange` call for every distinct kind
112
+ * retained in a debounce window. Priority orders delivery; it never discards
113
+ * lower-priority kinds from a mixed window. */
90
114
  export function createWatcher(opts: CreateWatcherOptions): Watcher {
91
115
  const debounceMs = opts.debounceMs ?? 50
92
- const kindPriority: ChangeKind[] = ['islands', 'ts', 'md', 'html', 'css', 'component-css']
93
116
 
94
117
  const coalesce = _testCoalesce(debounceMs, (paths) => {
95
- const kinds = new Set<ChangeKind>()
96
- const keep: string[] = []
97
- for (const p of paths) {
98
- const k = classifyPath(p, opts.root, opts.hasMdRoutes ?? true)
99
- if (k === null) continue
100
- kinds.add(k)
101
- keep.push(p)
102
- }
103
- if (keep.length === 0) return
104
- const dominant = kindPriority.find((k) => kinds.has(k))!
105
- opts.onChange({ paths: keep, kind: dominant })
118
+ _testDispatchChanges(paths, opts)
106
119
  })
107
120
 
108
121
  const fsWatcher: FSWatcher = watch(opts.root, { recursive: true }, (_event, filename) => {
@@ -15,6 +15,20 @@ export interface GeneratorStrings {
15
15
  header: string
16
16
  }
17
17
 
18
+ /** Full browser entry tag for the AI runtime chunk. */
19
+ export function aiScriptTag(): string {
20
+ return '<script type="module" src="/_brust/ai.js"></script>'
21
+ }
22
+
23
+ /** Insert the AI runtime tag immediately before the first `</head>`.
24
+ * Document-only: fragment templates with no head are left unchanged. */
25
+ export function injectAiScriptIntoTemplate(template: string): string {
26
+ const at = template.indexOf('</head>')
27
+ if (at === -1) return template
28
+ const tag = aiScriptTag()
29
+ return template.slice(0, at) + tag + template.slice(at)
30
+ }
31
+
18
32
  /** Build the resolved strings. Version comes from the brustjs package.json
19
33
  * (readVersion never throws — "unknown" degrades to name-only, never a crash).
20
34
  * The version is sanitized to attr/header-safe bytes; semver chars only. */
package/runtime/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('brustjs-android-arm64')
79
79
  const bindingPackageVersion = require('brustjs-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('brustjs-android-arm-eabi')
95
95
  const bindingPackageVersion = require('brustjs-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('brustjs-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('brustjs-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('brustjs-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('brustjs-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('brustjs-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('brustjs-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('brustjs-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('brustjs-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('brustjs-darwin-universal')
184
184
  const bindingPackageVersion = require('brustjs-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('brustjs-darwin-x64')
200
200
  const bindingPackageVersion = require('brustjs-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('brustjs-darwin-arm64')
216
216
  const bindingPackageVersion = require('brustjs-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('brustjs-freebsd-x64')
236
236
  const bindingPackageVersion = require('brustjs-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('brustjs-freebsd-arm64')
252
252
  const bindingPackageVersion = require('brustjs-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('brustjs-linux-x64-musl')
273
273
  const bindingPackageVersion = require('brustjs-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('brustjs-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('brustjs-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('brustjs-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('brustjs-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('brustjs-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('brustjs-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('brustjs-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('brustjs-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('brustjs-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('brustjs-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('brustjs-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('brustjs-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('brustjs-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('brustjs-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('brustjs-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('brustjs-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('brustjs-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('brustjs-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('brustjs-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('brustjs-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('brustjs-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('brustjs-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('brustjs-openharmony-arm64')
478
478
  const bindingPackageVersion = require('brustjs-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('brustjs-openharmony-x64')
494
494
  const bindingPackageVersion = require('brustjs-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('brustjs-openharmony-arm')
510
510
  const bindingPackageVersion = require('brustjs-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '0.1.64-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 0.1.64-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.1.66-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.1.66-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
package/runtime/index.ts CHANGED
@@ -189,6 +189,56 @@ async function readManifestFromPath(
189
189
  return parsed as import('./mcp/manifest.ts').McpManifest
190
190
  }
191
191
 
192
+ function createAiInternalRoutes(paths: {
193
+ manifestPath: string
194
+ runtimePath: string
195
+ }): import('./routes.ts').FlatRoute[] {
196
+ const manifestHandler: import('./routes.ts').Middleware = async () => {
197
+ const file = Bun.file(paths.manifestPath)
198
+ if (!(await file.exists())) {
199
+ return {
200
+ status: 404,
201
+ body: 'not found',
202
+ contentType: 'text/plain; charset=utf-8',
203
+ }
204
+ }
205
+ return {
206
+ status: 200,
207
+ body: await file.text(),
208
+ contentType: 'application/json; charset=utf-8',
209
+ }
210
+ }
211
+ const runtimeHandler: import('./routes.ts').Middleware = async () => {
212
+ const file = Bun.file(paths.runtimePath)
213
+ if (!(await file.exists())) {
214
+ return {
215
+ status: 404,
216
+ body: 'not found',
217
+ contentType: 'text/plain; charset=utf-8',
218
+ }
219
+ }
220
+ return {
221
+ status: 200,
222
+ body: await file.text(),
223
+ contentType: 'text/javascript; charset=utf-8',
224
+ }
225
+ }
226
+ return [
227
+ {
228
+ fullPath: '/_brust/ai/manifest.json',
229
+ chain: [{} as any],
230
+ middleware: [manifestHandler],
231
+ shellId: 'S:ai-manifest',
232
+ } as import('./routes.ts').FlatRoute,
233
+ {
234
+ fullPath: '/_brust/ai.js',
235
+ chain: [{} as any],
236
+ middleware: [runtimeHandler],
237
+ shellId: 'S:ai-runtime',
238
+ } as import('./routes.ts').FlatRoute,
239
+ ]
240
+ }
241
+
192
242
  export const brust = {
193
243
  async serve(opts: ServeOptions): Promise<void> {
194
244
  // Fail fast on a bad CORS config BEFORE touching native state (Rust
@@ -442,6 +492,8 @@ export const brust = {
442
492
  /** Optional global CORS policy — see {@link CorsOptions}. Threaded to
443
493
  * serve() like `actionPrefix`. */
444
494
  cors?: CorsOptions
495
+ /** AI runtime toggle. Dev mode enables it automatically. */
496
+ ai?: boolean
445
497
  /** Overrides merged into the underlying `serve()` call (main thread). */
446
498
  serve?: Partial<Omit<ServeOptions, 'entry' | 'actions' | 'mcp'>>
447
499
  /** Per-worker SAB size in bytes. Default 256 KB. */
@@ -461,6 +513,7 @@ export const brust = {
461
513
  const scanRoot = opts.scanRoot ?? path.dirname(fileURLToPath(opts.entry))
462
514
 
463
515
  const dev = opts.dev === true || process.env.BRUST_DEV === '1'
516
+ const aiEnabled = dev || opts.ai === true || process.env.BRUST_AI === '1'
464
517
  // Unify the `dev: true` option with the BRUST_DEV env signal. The dev
465
518
  // coordinator/watcher (which calls worker-registry spawnAll() on hot reload)
466
519
  // keys off this `dev` variable, but serve()'s registerInitialPool — plus
@@ -472,6 +525,16 @@ export const brust = {
472
525
  // registerInitialPool"). Set it here, before serve() spawns workers, so they
473
526
  // inherit it via baseEnv.
474
527
  if (dev) process.env.BRUST_DEV = '1'
528
+ if (aiEnabled) process.env.BRUST_AI = '1'
529
+ const aiManifestPath = prebuilt
530
+ ? path.join(distDir!, '.brust', 'ai-manifest.json')
531
+ : path.resolve(process.cwd(), '.brust', 'ai-manifest.json')
532
+ const aiRuntimePath = prebuilt
533
+ ? path.join(distDir!, 'islands', 'ai.js')
534
+ : path.resolve(process.cwd(), '.brust', 'islands', 'ai.js')
535
+ const aiInternalRoutes = aiEnabled
536
+ ? createAiInternalRoutes({ manifestPath: aiManifestPath, runtimePath: aiRuntimePath })
537
+ : []
475
538
  let routes = opts.routes
476
539
  if (dev) {
477
540
  const { createDevWsRoute } = await import('./dev/ws-channel.ts')
@@ -484,6 +547,9 @@ export const brust = {
484
547
  ]
485
548
  configureDevClientSnippet(buildDevClientTag())
486
549
  }
550
+ if (aiInternalRoutes.length > 0) {
551
+ routes = [...routes, ...aiInternalRoutes]
552
+ }
487
553
  {
488
554
  const { configureActionPrefixSnippet } = await import('./render/inject-action-prefix.ts')
489
555
  const ap = opts.actionPrefix
@@ -544,6 +610,10 @@ export const brust = {
544
610
  (r.chain[r.chain.length - 1] as { __mdSource?: unknown } | undefined)?.__mdSource !==
545
611
  undefined,
546
612
  )
613
+ if (!prebuilt) {
614
+ const { extractAiManifest, writeManifest } = await import('./ai/manifest.ts')
615
+ await writeManifest(process.cwd(), extractAiManifest(opts.routes))
616
+ }
547
617
 
548
618
  // Component CSS pipeline. Build the manifest + capture the loader plugin
549
619
  // BEFORE buildIslands and pass it EXPLICITLY below (global Bun.plugin()
@@ -627,6 +697,7 @@ export const brust = {
627
697
  flatRoutes: opts.routes,
628
698
  outDir: path.resolve(process.cwd(), '.brust/jinja'),
629
699
  withDevClient: dev,
700
+ aiEnabled,
630
701
  manifestDirs: [path.resolve(process.cwd(), '.brust')],
631
702
  }))
632
703
  } catch (err) {
@@ -644,10 +715,12 @@ export const brust = {
644
715
  const { scanIslandChunks, buildIslands: build } = await import('./islands/build.ts')
645
716
  const islandMap = scanIslandChunks(routesPath, mdIslands)
646
717
  let islandsDir: string | undefined
647
- if (islandMap.size > 0) {
718
+ if (islandMap.size > 0 || aiEnabled) {
648
719
  const islands = await build(islandMap, { plugins: cssBuildPlugins })
649
720
  islandsDir = islands.outDir
650
- console.log(`[brust] main: built ${islands.islandCount} island chunk(s)`)
721
+ console.log(
722
+ `[brust] main: built ${islands.islandCount} island chunk(s)${aiEnabled ? ' + ai runtime' : ''}`,
723
+ )
651
724
  }
652
725
  // Directive runtime bundle (Spec B) — build AFTER islands (buildIslands
653
726
  // rm -rf's its outDir) into the SAME dir so a native page's _directives.js
@@ -662,6 +735,11 @@ export const brust = {
662
735
  console.log(`[brust] main: built directive runtime (${res.count} component(s))`)
663
736
  }
664
737
  if (islandsDir) this.configureIslandsDir(islandsDir)
738
+ } else if (aiEnabled) {
739
+ const { buildIslands: build } = await import('./islands/build.ts')
740
+ const islands = await build(new Map(), { plugins: cssBuildPlugins })
741
+ this.configureIslandsDir(islands.outDir)
742
+ console.log('[brust] main: built 0 island chunk(s) + ai runtime')
665
743
  }
666
744
  }
667
745
 
@@ -791,6 +869,7 @@ export const brust = {
791
869
  ;(native as any).configureDevMode?.(true)
792
870
  const { createWatcher } = await import('./dev/watcher.ts')
793
871
  const { Coordinator } = await import('./dev/coordinator.ts')
872
+ const { validateChangedModules } = await import('./dev/validate-change.ts')
794
873
  const { broadcast } = await import('./dev/ws-channel.ts')
795
874
  const { Tui } = await import('./dev/tui.ts')
796
875
  const { terminateAll: termWorkers, spawnAll: spawnWorkers } = await import(
@@ -831,6 +910,7 @@ export const brust = {
831
910
  },
832
911
  },
833
912
  reEmitJinja,
913
+ validateChanges: validateChangedModules,
834
914
  // Wipe the Rust-side island ISR cache on every render-affecting reload
835
915
  // so a frozen island render never survives a `.tsx` edit in dev.
836
916
  clearIslandCache: () => {
@@ -860,6 +940,7 @@ export const brust = {
860
940
  flatRoutes: opts.routes,
861
941
  outDir: pathModule.resolve(process.cwd(), '.brust/jinja'),
862
942
  withDevClient: true,
943
+ aiEnabled,
863
944
  manifestDirs: [pathModule.resolve(process.cwd(), '.brust')],
864
945
  }))
865
946
  } catch (err) {
@@ -867,7 +948,7 @@ export const brust = {
867
948
  }
868
949
  }
869
950
  const islandMap = scanIslandChunks(routesPath, mdIslands)
870
- if (islandMap.size > 0) {
951
+ if (islandMap.size > 0 || aiEnabled) {
871
952
  await buildIslands(islandMap)
872
953
  }
873
954
  // Spec B: rebuild the directive bundle after islands (which rm -rf's
@@ -879,6 +960,9 @@ export const brust = {
879
960
  outDir: pathModule.join(process.cwd(), '.brust', 'islands'),
880
961
  })
881
962
  }
963
+ } else if (aiEnabled) {
964
+ const { buildIslands } = await import('./islands/build.ts')
965
+ await buildIslands(new Map())
882
966
  }
883
967
  },
884
968
  buildComponentCss: async () => {
@@ -981,6 +1065,9 @@ export const brust = {
981
1065
  ...opts.routes,
982
1066
  ]
983
1067
  }
1068
+ if (aiInternalRoutes.length > 0) {
1069
+ workerRoutes = [...workerRoutes, ...aiInternalRoutes]
1070
+ }
984
1071
  {
985
1072
  const { configureActionPrefixSnippet } = await import('./render/inject-action-prefix.ts')
986
1073
  const ap = opts.actionPrefix
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs'
1
+ import { existsSync, readFileSync } from 'node:fs'
2
2
  import { mkdir, rm, writeFile } from 'node:fs/promises'
3
3
  import { isAbsolute, relative, resolve } from 'node:path'
4
4
  import type { BunPlugin } from 'bun'
@@ -26,6 +26,15 @@ export interface BuildIslandsOptions {
26
26
  plugins?: BunPlugin[]
27
27
  }
28
28
 
29
+ export interface BuildAiRuntimeOptions {
30
+ /** Override the output directory. Default: `<cwd>/.brust/islands`. */
31
+ outDir?: string
32
+ /** Override the browser entry file. Default: `runtime/ai/index.ts`. */
33
+ entryFile?: string
34
+ /** Build plugins passed straight to `Bun.build` for the AI runtime chunk. */
35
+ plugins?: BunPlugin[]
36
+ }
37
+
29
38
  /** Scan a routes entry file for `<Island component={X} />` usage and derive the
30
39
  * island chunk list (componentName → absolute source path). Replaces the old
31
40
  * static config-file lookup — the chunk set is derived from source.
@@ -198,9 +207,41 @@ export async function buildIslands(
198
207
  const bootstrapSrc = resolve(import.meta.dir, 'bootstrap.ts')
199
208
  await buildOne([bootstrapSrc], outDir, '_bootstrap.js', externals)
200
209
 
210
+ // 5. AI browser runtime. The task-owned entry is optional in this worktree;
211
+ // missing source is a soft skip so island-only builds keep working.
212
+ if (process.env.BRUST_AI === '1' || process.env.BRUST_DEV === '1') {
213
+ await buildAiRuntime({ outDir, plugins })
214
+ }
215
+
201
216
  return { outDir, islandCount: count, chunks }
202
217
  }
203
218
 
219
+ export async function buildAiRuntime(options: BuildAiRuntimeOptions = {}): Promise<string | null> {
220
+ const outDir = options.outDir
221
+ ? isAbsolute(options.outDir)
222
+ ? options.outDir
223
+ : resolve(process.cwd(), options.outDir)
224
+ : resolve(process.cwd(), '.brust/islands')
225
+ await mkdir(outDir, { recursive: true })
226
+ const entryFile = options.entryFile
227
+ ? isAbsolute(options.entryFile)
228
+ ? options.entryFile
229
+ : resolve(process.cwd(), options.entryFile)
230
+ : resolve(import.meta.dir, '../ai/index.ts')
231
+ if (!existsSync(entryFile)) {
232
+ console.warn(`[brust] ai runtime skipped (missing ${relative(process.cwd(), entryFile)})`)
233
+ return null
234
+ }
235
+ await buildOne(
236
+ [entryFile],
237
+ outDir,
238
+ 'ai.js',
239
+ ['react', 'react/jsx-runtime', 'react-dom/client'],
240
+ options.plugins ?? [],
241
+ )
242
+ return resolve(outDir, 'ai.js')
243
+ }
244
+
204
245
  export async function buildOne(
205
246
  entrypoints: string[],
206
247
  outdir: string,